Beispiel #1
0
 /**
  * Call all registered trait methods
  *
  * Traits can register methods which will be called here
  *
  * Trait methods are allowed to call the parent trait method
  * that is registered by another trait with a higher sort
  *
  * using next::parent() inside a trait method
  * will call the parent trait method
  *
  * @param string $name
  * @param array $arguments
  *
  * @return mixed
  */
 private function __callTraitMethods($name, $arguments)
 {
     $result = next::caller();
     $traitMethods = $this->getTraitMethods();
     if (!isset($traitMethods[$name])) {
         return $result;
     }
     $method = $this->__reflection()->getMethod($name);
     // don't allow calling private methods unless allowed
     if (!$method->isPublic() && !$this->__enableClassScope) {
         return $result;
     }
     $methods = $traitMethods[$name];
     $methods = array_reverse($methods);
     $scope = $this;
     $level = -1;
     $parent = function ($arguments) use($scope, $methods, &$level) {
         $level++;
         if ($level >= count($methods)) {
             return next::caller();
         }
         $result = call_user_func_array([$scope, $methods[$level]], $arguments);
         $level--;
         return $result;
     };
     next::__registerParentCallback($parent);
     $result = $parent($arguments);
     next::__registerParentCallback(null);
     return $result;
 }