10 defined(
'JPATH_PLATFORM') or die;
27 protected $data = array();
39 public function __construct($input =
'')
42 if (is_string($input))
44 $input = json_decode($input,
true);
46 elseif (is_object($input))
48 $input = (array) $input;
54 foreach ($input as $action => $identities)
56 $this->mergeAction($action, $identities);
68 public function getData()
82 public function mergeCollection($input)
87 foreach ($input as $actions)
89 $this->merge($actions);
103 public function merge($actions)
105 if (is_string($actions))
107 $actions = json_decode($actions,
true);
110 if (is_array($actions))
112 foreach ($actions as $action => $identities)
114 $this->mergeAction($action, $identities);
117 elseif ($actions instanceof JAccessRules)
119 $data = $actions->getData();
121 foreach ($data as $name => $identities)
123 $this->mergeAction($name, $identities);
138 public function mergeAction($action, $identities)
140 if (isset($this->data[$action]))
143 $this->data[$action]->mergeIdentities($identities);
148 $this->data[$action] =
new JAccessRule($identities);
165 public function allow($action, $identity)
168 if (isset($this->data[$action]))
170 return $this->data[$action]->allow($identity);
185 public function getAllowed($identity)
190 foreach ($this->data as $name => &$action)
192 if ($action->allow($identity))
194 $allowed->
set($name,
true);
207 public function __toString()
211 foreach ($this->data as $name => $rule)
215 $temp[$name] = json_decode((
string) $rule);
218 return json_encode($temp);