ReflectionMethod PHP Class Code Examples

This page contains top rated real world PHP examples of class ReflectionMethod extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: App.class.php Project: www2511550/ECSHOP
0
 /**
  * 运行应用
  * @access private
  */
 private static function start()
 {
     //控制器实例
     $controller = controller(CONTROLLER);
     //控制器不存在
     if (!$controller) {
         //模块检测
         if (!is_dir(MODULE_PATH)) {
             _404('模块' . MODULE . '不存在');
         }
         //空控制器
         $controller = Controller("Empty");
         if (!$controller) {
             _404('控制器' . CONTROLLER . C("CONTROLLER_FIX") . '不存在');
         }
     }
     //执行动作
     try {
         $action = new ReflectionMethod($controller, ACTION);
         if ($action->isPublic()) {
             $action->invoke($controller);
         } else {
             throw new ReflectionException();
         }
     } catch (ReflectionException $e) {
         $action = new ReflectionMethod($controller, '__call');
         $action->invokeArgs($controller, array(ACTION, ''));
     }
 }
Example #2
Show file File: Method.php Project: luminousinfoways/pccfoas
0
 /**
  * @return self
  */
 public static function from($from)
 {
     if (is_string($from) && strpos($from, '::')) {
         $from = new \ReflectionMethod($from);
     } elseif (is_array($from)) {
         $from = new \ReflectionMethod($from[0], $from[1]);
     } elseif (!$from instanceof \ReflectionFunctionAbstract) {
         $from = new \ReflectionFunction($from);
     }
     $method = new static($from->isClosure() ? NULL : $from->getName());
     foreach ($from->getParameters() as $param) {
         $method->parameters[$param->getName()] = Parameter::from($param);
     }
     if ($from instanceof \ReflectionMethod) {
         $method->static = $from->isStatic();
         $method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : NULL);
         $method->final = $from->isFinal();
         $method->abstract = $from->isAbstract() && !$from->getDeclaringClass()->isInterface();
         $method->body = $from->isAbstract() ? FALSE : '';
     }
     $method->returnReference = $from->returnsReference();
     $method->variadic = PHP_VERSION_ID >= 50600 && $from->isVariadic();
     $method->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
     if (PHP_VERSION_ID >= 70000 && $from->hasReturnType()) {
         $method->returnType = (string) $from->getReturnType();
     }
     return $method;
 }
Example #3
Show file File: EventModel.php Project: smotalima/mautic
0
 /**
  * Invoke the event's callback function
  *
  * @param      $event
  * @param      $settings
  * @param null $lead
  * @param null $eventDetails
  * @param bool $systemTriggered
  *
  * @return bool|mixed
  */
 public function invokeEventCallback($event, $settings, $lead = null, $eventDetails = null, $systemTriggered = false)
 {
     $args = array('eventDetails' => $eventDetails, 'event' => $event, 'lead' => $lead, 'factory' => $this->factory, 'systemTriggered' => $systemTriggered, 'config' => $event['properties']);
     if (is_callable($settings['callback'])) {
         if (is_array($settings['callback'])) {
             $reflection = new \ReflectionMethod($settings['callback'][0], $settings['callback'][1]);
         } elseif (strpos($settings['callback'], '::') !== false) {
             $parts = explode('::', $settings['callback']);
             $reflection = new \ReflectionMethod($parts[0], $parts[1]);
         } else {
             $reflection = new \ReflectionMethod(null, $settings['callback']);
         }
         $pass = array();
         foreach ($reflection->getParameters() as $param) {
             if (isset($args[$param->getName()])) {
                 $pass[] = $args[$param->getName()];
             } else {
                 $pass[] = null;
             }
         }
         $result = $reflection->invokeArgs($this, $pass);
         if ($this->dispatcher->hasListeners(CampaignEvents::ON_EVENT_EXECUTION)) {
             $event = new CampaignExecutionEvent($args, $result);
             $this->dispatcher->dispatch(CampaignEvents::ON_EVENT_EXECUTION, $event);
             unset($event);
         }
     } else {
         $result = true;
     }
     // Save some RAM for batch processing
     unset($args, $pass, $reflection, $settings, $lead, $event, $eventDetails);
     return $result;
 }
Example #4
Show file File: Environment.php Project: r0lodex/bookstore
0
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * debug: When set to true, it automatically set "auto_reload" to true as
  *           well (default to false).
  *
  *  * charset: The charset used by the templates (default to UTF-8).
  *
  *  * base_template_class: The base template class to use for generated
  *                         templates (default to Twig_Template).
  *
  *  * cache: An absolute path where to store the compiled templates,
  *           a Twig_Cache_Interface implementation,
  *           or false to disable compilation cache (default).
  *
  *  * auto_reload: Whether to reload the template if the original source changed.
  *                 If you don't provide the auto_reload option, it will be
  *                 determined automatically based on the debug value.
  *
  *  * strict_variables: Whether to ignore invalid variables in templates
  *                      (default to false).
  *
  *  * autoescape: Whether to enable auto-escaping (default to html):
  *                  * false: disable auto-escaping
  *                  * true: equivalent to html
  *                  * html, js: set the autoescaping to one of the supported strategies
  *                  * filename: set the autoescaping strategy based on the template filename extension
  *                  * PHP callback: a PHP callback that returns an escaping strategy based on the template "filename"
  *
  *  * optimizations: A flag that indicates which optimizations to apply
  *                   (default to -1 which means that all optimizations are enabled;
  *                   set it to 0 to disable).
  *
  * @param Twig_LoaderInterface $loader  A Twig_LoaderInterface instance
  * @param array                $options An array of options
  */
 public function __construct(Twig_LoaderInterface $loader = null, $options = array())
 {
     if (null !== $loader) {
         $this->setLoader($loader);
     } else {
         @trigger_error('Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated.', E_USER_DEPRECATED);
     }
     $options = array_merge(array('debug' => false, 'charset' => 'UTF-8', 'base_template_class' => 'Twig_Template', 'strict_variables' => false, 'autoescape' => 'html', 'cache' => false, 'auto_reload' => null, 'optimizations' => -1), $options);
     $this->debug = (bool) $options['debug'];
     $this->charset = strtoupper($options['charset']);
     $this->baseTemplateClass = $options['base_template_class'];
     $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload'];
     $this->strictVariables = (bool) $options['strict_variables'];
     $this->setCache($options['cache']);
     $this->addExtension(new Twig_Extension_Core());
     $this->addExtension(new Twig_Extension_Escaper($options['autoescape']));
     $this->addExtension(new Twig_Extension_Optimizer($options['optimizations']));
     $this->staging = new Twig_Extension_Staging();
     // For BC
     if (is_string($this->originalCache)) {
         $r = new ReflectionMethod($this, 'writeCacheFile');
         if ($r->getDeclaringClass()->getName() !== __CLASS__) {
             @trigger_error('The Twig_Environment::writeCacheFile method is deprecated and will be removed in Twig 2.0.', E_USER_DEPRECATED);
             $this->bcWriteCacheFile = true;
         }
         $r = new ReflectionMethod($this, 'getCacheFilename');
         if ($r->getDeclaringClass()->getName() !== __CLASS__) {
             @trigger_error('The Twig_Environment::getCacheFilename method is deprecated and will be removed in Twig 2.0.', E_USER_DEPRECATED);
             $this->bcGetCacheFilename = true;
         }
     }
 }
Example #5
Show file File: App.php Project: cnzin/think
0
 public static function invokeMethod($method, $vars = [])
 {
     if (empty($vars)) {
         // 自动获取请求变量
         switch (REQUEST_METHOD) {
             case 'POST':
                 $vars = array_merge($_GET, $_POST);
                 break;
             case 'PUT':
                 parse_str(file_get_contents('php://input'), $vars);
                 $vars = array_merge($_GET, $vars);
                 break;
             default:
                 $vars = $_GET;
         }
     }
     if (is_array($method)) {
         $class = is_object($method[0]) ? $method[0] : new $method[0]();
         $reflect = new \ReflectionMethod($class, $method[1]);
     } else {
         // 静态方法
         $reflect = new \ReflectionMethod($method);
     }
     $args = self::bindParams($reflect, $vars);
     // 记录执行信息
     APP_DEBUG && Log::record('[ RUN ] ' . $reflect->getFileName() . '[ ' . var_export($args, true) . ' ]', 'info');
     return $reflect->invokeArgs(isset($class) ? $class : null, $args);
 }
Example #6
Show file File: AwaitableMethods.php Project: mrxotey/icicle
0
 /**
  * {@inheritdoc}
  */
 public function capture(callable $onRejected) : Awaitable
 {
     return $this->then(null, function (\Throwable $exception) use($onRejected) {
         if ($onRejected instanceof \Closure) {
             // Closure.
             $reflection = new \ReflectionFunction($onRejected);
         } elseif (is_array($onRejected)) {
             // Methods passed as an array.
             $reflection = new \ReflectionMethod($onRejected[0], $onRejected[1]);
         } elseif (is_object($onRejected)) {
             // Callable objects.
             $reflection = new \ReflectionMethod($onRejected, '__invoke');
         } elseif (is_string($onRejected) && strrpos($onRejected, '::', -1)) {
             // ClassName::methodName strings.
             $reflection = new \ReflectionMethod($onRejected);
         } else {
             // Everything else.
             $reflection = new \ReflectionFunction($onRejected);
         }
         $parameters = $reflection->getParameters();
         if (empty($parameters)) {
             // No parameters defined.
             return $onRejected($exception);
             // Providing argument in case func_get_args() is used in function.
         }
         $class = $parameters[0]->getClass();
         if (null === $class || $class->isInstance($exception)) {
             // None or matching type declaration.
             return $onRejected($exception);
         }
         return $this;
         // Type declaration does not match.
     });
 }
Example #7
Show file File: admin.acctexp.php Project: Ibrahim1/aec
0
 public function call($task = 'index')
 {
     if ($task == 'new') {
         $task = 'edit';
     }
     if (empty($task)) {
         $task = 'index';
     }
     if ($task == 'apply') {
         $task = 'save';
         $this->redirect = 'edit';
     }
     $r = new ReflectionMethod(get_class($this), $task);
     $params = $r->getParameters();
     $this->params = array();
     foreach ($params as $k) {
         $this->params[$k->getName()] = aecGetParam($k->getName());
     }
     call_user_func_array(array($this, $task), $this->params);
     if ($task != 'save') {
         return;
     }
     if ($this->redirect) {
         $r = new ReflectionMethod(get_class($this), $this->redirect);
         $params = $r->getParameters();
         $this->params = array();
         foreach ($params as $k) {
             $this->params[$k->getName()] = aecGetParam($k->getName());
         }
         $this->redirect($this->redirect, null, $this->params);
     } elseif ($task != 'index') {
         $this->redirect();
     }
 }
Example #8
Show file File: EventModel.php Project: emtudo/mautic
0
 /**
  * Invoke the event's callback function
  *
  * @param      $event
  * @param      $settings
  * @param null $lead
  * @param null $eventDetails
  * @param bool $systemTriggered
  * @param LeadEventLog $log
  *
  * @return bool|mixed
  */
 public function invokeEventCallback($event, $settings, $lead = null, $eventDetails = null, $systemTriggered = false, LeadEventLog $log = null)
 {
     $args = array('eventSettings' => $settings, 'eventDetails' => $eventDetails, 'event' => $event, 'lead' => $lead, 'factory' => $this->factory, 'systemTriggered' => $systemTriggered, 'config' => $event['properties']);
     if (is_callable($settings['callback'])) {
         if (is_array($settings['callback'])) {
             $reflection = new \ReflectionMethod($settings['callback'][0], $settings['callback'][1]);
         } elseif (strpos($settings['callback'], '::') !== false) {
             $parts = explode('::', $settings['callback']);
             $reflection = new \ReflectionMethod($parts[0], $parts[1]);
         } else {
             $reflection = new \ReflectionMethod(null, $settings['callback']);
         }
         $pass = array();
         foreach ($reflection->getParameters() as $param) {
             if (isset($args[$param->getName()])) {
                 $pass[] = $args[$param->getName()];
             } else {
                 $pass[] = null;
             }
         }
         $result = $reflection->invokeArgs($this, $pass);
         if ('decision' != $event['eventType'] && $this->dispatcher->hasListeners(CampaignEvents::ON_EVENT_EXECUTION)) {
             $executionEvent = $this->dispatcher->dispatch(CampaignEvents::ON_EVENT_EXECUTION, new CampaignExecutionEvent($args, $result, $log));
             if ($executionEvent->wasLogUpdatedByListener()) {
                 $result = $executionEvent->getLogEntry();
             }
         }
     } else {
         $result = true;
     }
     // Save some RAM for batch processing
     unset($args, $pass, $reflection, $settings, $lead, $event, $eventDetails);
     return $result;
 }
Example #9
Show file File: ~boot.php Project: jyht/v5
0
 private static function start()
 {
     $control = control(CONTROL);
     if (!$control) {
         if (IS_GROUP and !is_dir(GROUP_PATH . GROUP_NAME)) {
             _404('应用组' . GROUP_PATH . GROUP_NAME . '不存在');
         }
         if (!is_dir(APP_PATH)) {
             _404('应用' . APP . '不存在');
         }
         $control = Control("Empty");
         if (!$control) {
             _404('模块' . CONTROL . C("CONTROL_FIX") . '不存在');
         }
     }
     try {
         $method = new ReflectionMethod($control, METHOD);
         if ($method->isPublic()) {
             $method->invoke($control);
         } else {
             throw new ReflectionException();
         }
     } catch (ReflectionException $e) {
         $method = new ReflectionMethod($control, '__call');
         $method->invokeArgs($control, array(METHOD, ''));
     }
 }
Example #10
Show file File: pramda.php Project: kapolos/pramda
0
 /**
  * How many arguments the provided callable expects (arity)
  *
  * @param callable $callable
  *
  * @return int
  * @throws \Exception
  */
 private static function _getArity($callable)
 {
     $r = FALSE;
     if (is_array($callable)) {
         $r = new ReflectionMethod($callable[0], $callable[1]);
     } else {
         if (is_string($callable)) {
             if (stripos($callable, '::') !== FALSE) {
                 $tmp = explode('::', $callable);
                 $r = new ReflectionMethod($tmp[0], $tmp[1]);
             } else {
                 $r = new ReflectionFunction($callable);
             }
         } else {
             if (is_a($callable, 'Closure')) {
                 $objR = new ReflectionObject($callable);
                 $r = $objR->getMethod('__invoke');
             }
         }
     }
     if (!$r) {
         throw new Exception("Could not examine callback");
     }
     return count($r->getParameters());
 }
Example #11
Show file File: ResolvedFormType.php Project: RuntyCybin/csymfony
0
 /**
  * Returns the configured options resolver used for this type.
  *
  * @return \Symfony\Component\OptionsResolver\OptionsResolverInterface The options resolver.
  */
 public function getOptionsResolver()
 {
     if (null === $this->optionsResolver) {
         if (null !== $this->parent) {
             $this->optionsResolver = clone $this->parent->getOptionsResolver();
         } else {
             $this->optionsResolver = new OptionsResolver();
         }
         $this->innerType->setDefaultOptions($this->optionsResolver);
         $reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions');
         $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractType';
         $reflector = new \ReflectionMethod($this->innerType, 'configureOptions');
         $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractType';
         if ($isOldOverwritten && !$isNewOverwritten) {
             trigger_error('The FormTypeInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED);
         }
         foreach ($this->typeExtensions as $extension) {
             $extension->setDefaultOptions($this->optionsResolver);
             $reflector = new \ReflectionMethod($extension, 'setDefaultOptions');
             $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractTypeExtension';
             $reflector = new \ReflectionMethod($extension, 'configureOptions');
             $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractTypeExtension';
             if ($isOldOverwritten && !$isNewOverwritten) {
                 trigger_error('The FormTypeExtensionInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeExtensionInterface with Symfony 3.0.', E_USER_DEPRECATED);
             }
         }
     }
     return $this->optionsResolver;
 }
Example #12
Show file File: App.class.php Project: sxau-web-team/wish-web
0
 /**
  * 运行应用
  * @access private
  */
 private static function start()
 {
     //控制器实例
     $control = control(CONTROL);
     //控制器不存在
     if (!$control) {
         //空控制器
         $control = Control("Empty");
         if (!$control) {
             _404('模块' . CONTROL . '不存在');
         }
     }
     //执行动作
     try {
         $method = new ReflectionMethod($control, METHOD);
         if ($method->isPublic()) {
             $method->invoke($control);
         } else {
             throw new ReflectionException();
         }
     } catch (ReflectionException $e) {
         $method = new ReflectionMethod($control, '__call');
         $method->invokeArgs($control, array(METHOD, ''));
     }
 }
Example #13
Show file File: TbActiveFormTest.php Project: zhaoyan158567/YiiBooster
0
 public function testInlineGroup()
 {
     $model = new FakeModel();
     $fieldData = 'here_will_be_field';
     $attribute = 'login';
     $model->addError($attribute, 'simple error text');
     $form = $this->makeWidget();
     $method = new ReflectionMethod($form, 'inlineGroup');
     $method->setAccessible(true);
     $rowOptions = [];
     $methodInitGroupOptions = new ReflectionMethod($form, 'initOptions');
     $methodInitGroupOptions->setAccessible(true);
     $methodInitGroupOptions->invokeArgs($form, array(&$rowOptions));
     $rowOptions['prepend'] = 'before';
     $rowOptions['prependOptions'] = array('class' => 'bar');
     $rowOptions['append'] = 'after';
     $rowOptions['appendOptions'] = array('class' => 'apple');
     ob_start();
     $method->invokeArgs($form, array(&$fieldData, &$model, &$attribute, &$rowOptions));
     $data = ob_get_clean();
     $doc = new DOMDocument();
     $doc->loadHTML($data);
     $actual = new DOMXPath($doc);
     $matches = $actual->query('//div[contains(@class, "input-group") and contains(@class, "input-group") and text()="' . $fieldData . '"]' . '/span[contains(@class,"input-group-addon") and contains(@class, "' . $rowOptions['prependOptions']['class'] . '") and text()="' . $rowOptions['prepend'] . '"]' . '/following-sibling::span[contains(@class,"input-group-addon") and contains(@class, "' . $rowOptions['appendOptions']['class'] . '") and text()="' . $rowOptions['append'] . '"]');
     $this->assertEquals(1, $matches->length);
 }
Example #14
Show file File: SubCommandCommandTest.php Project: ocubom/GitElephant
0
 /**
  * verify SubCommandCommands behavior, which is slightly
  * different that BaseCommand, for more sophisticated needs
  */
 public function testGetCommand()
 {
     $cmdName = 'foo';
     $subOne = 'bar';
     $subTwo = 'baz';
     $subThree = 'blurg';
     $argOne = '--opt1';
     $argTwo = '--opt2';
     $argTwoValue = 'val2';
     $expected = "foo '{$argOne}' '{$argTwo}' '{$argTwoValue}' '{$subOne}' '{$subTwo}' '{$subThree}'";
     $subcmd = new SubCommandCommand();
     $rmeth = new \ReflectionMethod($subcmd, 'addCommandName');
     $rmeth->setAccessible(true);
     $rmeth->invoke($subcmd, $cmdName);
     $rmeth = new \ReflectionMethod($subcmd, 'addCommandSubject');
     $rmeth->setAccessible(true);
     $rmeth->invoke($subcmd, $subOne);
     $rmeth = new \ReflectionMethod($subcmd, 'addCommandSubject');
     $rmeth->setAccessible(true);
     $rmeth->invoke($subcmd, $subTwo);
     $rmeth = new \ReflectionMethod($subcmd, 'addCommandSubject');
     $rmeth->setAccessible(true);
     $rmeth->invoke($subcmd, $subThree);
     $rmeth = new \ReflectionMethod($subcmd, 'addCommandArgument');
     $rmeth->setAccessible(true);
     $rmeth->invoke($subcmd, $argOne);
     $rmeth = new \ReflectionMethod($subcmd, 'addCommandArgument');
     $rmeth->setAccessible(true);
     $rmeth->invoke($subcmd, array($argTwo, $argTwoValue));
     $actual = $subcmd->getCommand();
     $this->assertEquals($expected, $actual, 'getCommand() produces string made from subject stact and extracted args');
 }
Example #15
Show file File: ObjectMixin.php Project: xamiro-dev/xamiro
0
 /**
  * __get() implementation.
  * @param  object
  * @param  string  property name
  * @return mixed   property value
  * @throws MemberAccessException if the property is not defined.
  */
 public static function &get($_this, $name)
 {
     $class = get_class($_this);
     $uname = ucfirst($name);
     $methods =& self::getMethods($class);
     if ($name === '') {
         throw new XApp_MemberAccessException("Cannot read a class '{$class}' property without name.");
     } elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
         // property getter
         if ($methods[$m] === 0) {
             $rm = new ReflectionMethod($class, $m);
             $methods[$m] = $rm->returnsReference();
         }
         if ($methods[$m] === TRUE) {
             return $_this->{$m}();
         } else {
             $val = $_this->{$m}();
             return $val;
         }
     } elseif (isset($methods[$name])) {
         // public method as closure getter
         if (PHP_VERSION_ID >= 50400) {
             $rm = new ReflectionMethod($class, $name);
             $val = $rm->getClosure($_this);
         } else {
             $val = XApp_Utils_Callback::closure($_this, $name);
         }
         return $val;
     } else {
         // strict class
         $type = isset($methods['set' . $uname]) ? 'a write-only' : 'an undeclared';
         throw new XApp_MemberAccessException("Cannot read {$type} property {$class}::\${$name}.");
     }
 }
Example #16
Show file File: ProviderDashboardController.php Project: dragonlet/clearhealth
0
 public function renderPhpDashboardComponentAction()
 {
     try {
         $dashcom = $this->getDashComContentAction($this->_getParam('dashboardComponentId'));
         $action = $this->_getParam('actionn');
         if (!$action && $action != 'refresh' && $action != 'render') {
             $action = "render";
         }
         //default value
         $personId = (int) $this->_getParam('personId');
         $classname = $dashcom['systemName'] . "PHPDashboardComponent";
         eval($dashcom['content']);
         if ($action == 'render') {
             $ref = new ReflectionClass($classname);
             $methods = $ref->getMethods();
             $mtdRender = new ReflectionMethod($classname, 'render');
             $mtdRefresh = new ReflectionMethod($classname, 'refresh');
         }
         $ob = new $classname();
         if ($action == 'render') {
             $ob->render();
         } else {
             if ($action == 'refresh') {
                 $ob->refresh($personId);
             }
         }
         $ob = NULL;
     } catch (ReflectionException $e) {
         echo "ProviderDashboardController->renderPhpDashboardComponentAction: " . $e->getMessage();
     } catch (Zend_Exception $e) {
         echo "Caught exception: " . get_class($e) . "\n";
         echo "Message: " . $e->getMessage() . "\n";
     }
 }
Example #17
Show file File: EventModel.php Project: woakes070048/mautic
0
 /**
  * Invoke the event's callback function
  *
  * @param $event
  * @param $settings
  * @param $lead
  * @param $eventDetails
  *
  * @return bool|mixed
  */
 public function invokeEventCallback($event, $settings, $lead = null, $eventDetails = null, $systemTriggered = false)
 {
     $args = array('eventDetails' => $eventDetails, 'event' => $event, 'lead' => $lead, 'factory' => $this->factory, 'systemTriggered' => $systemTriggered, 'config' => $event['properties']);
     if (is_callable($settings['callback'])) {
         if (is_array($settings['callback'])) {
             $reflection = new \ReflectionMethod($settings['callback'][0], $settings['callback'][1]);
         } elseif (strpos($settings['callback'], '::') !== false) {
             $parts = explode('::', $settings['callback']);
             $reflection = new \ReflectionMethod($parts[0], $parts[1]);
         } else {
             $reflection = new \ReflectionMethod(null, $settings['callback']);
         }
         $pass = array();
         foreach ($reflection->getParameters() as $param) {
             if (isset($args[$param->getName()])) {
                 $pass[] = $args[$param->getName()];
             } else {
                 $pass[] = null;
             }
         }
         $result = $reflection->invokeArgs($this, $pass);
     } else {
         $result = true;
     }
     // Save some RAM for batch processing
     unset($args, $pass, $reflection, $settings, $lead, $event, $eventDetails);
     return $result;
 }
Example #18
Show file File: App.class.php Project: jyht/v5
0
 /**
  * 运行应用
  * @access private
  */
 private static function start()
 {
     //控制器实例
     $control = control(CONTROL);
     //控制器不存在
     if (!$control) {
         //应用组检测
         if (IS_GROUP and !is_dir(GROUP_PATH . GROUP_NAME)) {
             _404('应用组' . GROUP_PATH . GROUP_NAME . '不存在');
         }
         //应用检测
         if (!is_dir(APP_PATH)) {
             _404('应用' . APP . '不存在');
         }
         //空控制器
         $control = Control("Empty");
         if (!$control) {
             _404('模块' . CONTROL . C("CONTROL_FIX") . '不存在');
         }
     }
     //执行动作
     try {
         $method = new ReflectionMethod($control, METHOD);
         if ($method->isPublic()) {
             $method->invoke($control);
         } else {
             throw new ReflectionException();
         }
     } catch (ReflectionException $e) {
         $method = new ReflectionMethod($control, '__call');
         $method->invokeArgs($control, array(METHOD, ''));
     }
 }
Example #19
Show file File: Utils.php Project: fabiocarneiro/zend-stratigility
0
 /**
  * Get the arity of a handler
  *
  * @param string|callable|object $callable
  * @return int
  */
 public static function getArity($callable)
 {
     if (is_object($callable)) {
         foreach (['__invoke', 'handle'] as $method) {
             if (!method_exists($callable, $method)) {
                 continue;
             }
             $r = new ReflectionMethod($callable, $method);
             return $r->getNumberOfRequiredParameters();
         }
         return 0;
     }
     if (!is_callable($callable)) {
         return 0;
     }
     // Handle static methods passed in Class::method format by re-casting
     // as an array callable.
     if (is_string($callable) && preg_match('/^(?P<class>[^:]+)::(?P<method>.*)$/', $callable, $matches)) {
         $callable = [$matches['class'], $matches['method']];
     }
     if (is_array($callable)) {
         list($class, $method) = $callable;
         $r = new ReflectionMethod($class, $method);
         return $r->getNumberOfRequiredParameters();
     }
     $r = new ReflectionFunction($callable);
     return $r->getNumberOfRequiredParameters();
 }
Example #20
Show file File: GroupTest.php Project: ivoba/silverstripe-framework
0
 public function testValidatesPrivilegeLevelOfParent()
 {
     $nonAdminUser = $this->objFromFixture('GroupTest_Member', 'childgroupuser');
     $adminUser = $this->objFromFixture('GroupTest_Member', 'admin');
     $nonAdminGroup = $this->objFromFixture('Group', 'childgroup');
     $adminGroup = $this->objFromFixture('Group', 'admingroup');
     $nonAdminValidateMethod = new ReflectionMethod($nonAdminGroup, 'validate');
     $nonAdminValidateMethod->setAccessible(true);
     // Making admin group parent of a non-admin group, effectively expanding is privileges
     $nonAdminGroup->ParentID = $adminGroup->ID;
     $this->logInWithPermission('APPLY_ROLES');
     $result = $nonAdminValidateMethod->invoke($nonAdminGroup);
     $this->assertFalse($result->valid(), 'Members with only APPLY_ROLES can\'t assign parent groups with direct ADMIN permissions');
     $this->logInWithPermission('ADMIN');
     $result = $nonAdminValidateMethod->invoke($nonAdminGroup);
     $this->assertTrue($result->valid(), 'Members with ADMIN can assign parent groups with direct ADMIN permissions');
     $nonAdminGroup->write();
     $newlyAdminGroup = $nonAdminGroup;
     $this->logInWithPermission('ADMIN');
     $inheritedAdminGroup = $this->objFromFixture('Group', 'group1');
     $inheritedAdminMethod = new ReflectionMethod($inheritedAdminGroup, 'validate');
     $inheritedAdminMethod->setAccessible(true);
     $inheritedAdminGroup->ParentID = $adminGroup->ID;
     $inheritedAdminGroup->write();
     // only works with ADMIN login
     $this->logInWithPermission('APPLY_ROLES');
     $result = $inheritedAdminMethod->invoke($nonAdminGroup);
     $this->assertFalse($result->valid(), 'Members with only APPLY_ROLES can\'t assign parent groups with inherited ADMIN permission');
 }