1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8class Perms_Check_Fixed implements Perms_Check 9{ 10 private $permissions; 11 private $resolver; 12 13 /* 14 * Initialize internal permissions array and set each permission to true. 15 * @params array $permissions 16 */ 17 function __construct($permissions) 18 { 19 $this->permissions = array_fill_keys($permissions, true); 20 } 21 22 23 /* 24 * Check a specific permission against those given by the constructor for a specific list of groups 25 * This function requires that $this->setResolver($resolver) has been set before. Otherwise it will always return false. 26 * @param Perms_Resolver $resolver - not used 27 * @param array $context - not used 28 * @param string $name - permission name to check 29 * @param array $groups - list of groups to check permission against 30 * @return boolean $hasPermission- true|false 31 */ 32 function check(Perms_Resolver $resolver, array $context, $name, array $groups) 33 { 34 if ($this->resolver && isset($this->permissions[$name])) { 35 return $this->resolver->check($name, $groups); 36 } else { 37 return false; 38 } 39 } 40 41 42 /* 43 * Set the type of resolver to use. Resets the internal cache for applicable groups. 44 * @param Perms_Resolver $resolver 45 */ 46 function setResolver($resolver) 47 { 48 $this->resolver = $resolver; 49 } 50 51 52 /* 53 * Get the applicable groups 54 * This function requires that $this->setResolver($resolver) has been set before. Otherwise it will always return an empty list. 55 * @params Perms_Resolver $resolver - not used 56 * @return array $applicableGroups - List of groups 57 */ 58 function applicableGroups(Perms_Resolver $resolver) 59 { 60 if ($this->resolver) { 61 return $this->resolver->applicableGroups(); 62 } else { 63 return []; 64 } 65 } 66} 67