Acl\Adapter\Utility\PhpAro::resolve PHP Method

resolve() public method

resolve an ARO identifier to an internal ARO string using the internal mapping information.
public resolve ( string | array $aro ) : string
$aro string | array ARO identifier (Users.jeff, ['Users' => ...], etc)
return string internal aro string (e.g. Users/jeff, Role/default)
    public function resolve($aro)
    {
        foreach ($this->map as $aroGroup => $map) {
            list($model, $field) = explode('/', $map, 2);
            $mapped = '';
            if (is_array($aro)) {
                if (isset($aro['model']) && isset($aro['foreign_key']) && $aro['model'] === $aroGroup) {
                    $mapped = $aroGroup . '/' . $aro['foreign_key'];
                } elseif (isset($aro[$model][$field])) {
                    $mapped = $aroGroup . '/' . $aro[$model][$field];
                } elseif (isset($aro[$field])) {
                    $mapped = $aroGroup . '/' . $aro[$field];
                }
            } elseif (is_string($aro)) {
                $aro = ltrim($aro, '/');
                if (strpos($aro, '/') === false) {
                    $mapped = $aroGroup . '/' . $aro;
                } else {
                    list($aroModel, $aroValue) = explode('/', $aro, 2);
                    $aroModel = Inflector::camelize($aroModel);
                    if ($aroModel === $model || $aroModel === $aroGroup) {
                        $mapped = $aroGroup . '/' . $aroValue;
                    }
                }
            }
            if (isset($this->_tree[$mapped])) {
                return $mapped;
            }
            // is there a matching alias defined (e.g. Role/1 => Role/admin)?
            if (!empty($this->aliases[$mapped])) {
                return $this->aliases[$mapped];
            }
        }
        return static::DEFAULT_ROLE;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * deny ARO access to ACO
  *
  * @param string $aro ARO The requesting object identifier.
  * @param string $aco ACO The controlled object identifier.
  * @param string $action Action (defaults to *)
  * @return bool Success
  */
 public function deny($aro, $aco, $action = "*")
 {
     return $this->Aco->access($this->Aro->resolve($aro), $aco, $action, 'deny');
 }