示例#1
0
 /**
  * @param  mixed   class, object, callable
  * @param  string  method
  * @return Closure
  */
 public static function closure($callable, $m = NULL)
 {
     if ($m !== NULL) {
         $callable = array($callable, $m);
     } elseif ($callable instanceof Closure) {
         return $callable;
     }
     self::check($callable, TRUE);
     $_callable_ = $callable;
     return function () use($_callable_) {
         XApp_Utils_Callback::check($_callable_);
         return call_user_func_array($_callable_, func_get_args());
     };
 }
示例#2
0
 /**
  * Returns the rule type associated with the specified Resource, Role, and privilege.
  * @param  string|Permission::ALL
  * @param  string|Permission::ALL
  * @param  string|Permission::ALL
  * @return mixed  NULL if a rule does not exist or assertion fails, otherwise returns ALLOW or DENY
  */
 private function getRuleType($resource, $role, $privilege)
 {
     if (!($rules = $this->getRules($resource, $role))) {
         return NULL;
     }
     if ($privilege === self::ALL) {
         if (isset($rules['allPrivileges'])) {
             $rule = $rules['allPrivileges'];
         } else {
             return NULL;
         }
     } elseif (!isset($rules['byPrivilege'][$privilege])) {
         return NULL;
     } else {
         $rule = $rules['byPrivilege'][$privilege];
     }
     if ($rule['assert'] === NULL || XApp_Utils_Callback::invoke($rule['assert'], $this, $role, $resource, $privilege)) {
         return $rule['type'];
     } elseif ($resource !== self::ALL || $role !== self::ALL || $privilege !== self::ALL) {
         return NULL;
     } elseif (self::ALLOW === $rule['type']) {
         return self::DENY;
     } else {
         return self::ALLOW;
     }
 }
示例#3
0
 /**
  * Adds a method to class.
  * @param  string
  * @param  string
  * @param  mixed   callable
  * @return void
  */
 public static function setExtensionMethod($class, $name, $callback)
 {
     $name = strtolower($name);
     self::$extMethods[$name][$class] = XApp_Utils_Callback::closure($callback);
     self::$extMethods[$name][''] = NULL;
 }