当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionMethod::getNumberOfRequiredParameters方法代码示例

本文整理汇总了PHP中ReflectionMethod::getNumberOfRequiredParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getNumberOfRequiredParameters方法的具体用法?PHP ReflectionMethod::getNumberOfRequiredParameters怎么用?PHP ReflectionMethod::getNumberOfRequiredParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionMethod的用法示例。


在下文中一共展示了ReflectionMethod::getNumberOfRequiredParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: methodListFromReflectionClassAndMethod

 /**
  * @return Method[]
  */
 public static function methodListFromReflectionClassAndMethod(Context $context, CodeBase $code_base, \ReflectionClass $class, \ReflectionMethod $reflection_method) : array
 {
     $reflection_method = new \ReflectionMethod($class->getName(), $reflection_method->name);
     $method = new Method($context, $reflection_method->name, new UnionType(), $reflection_method->getModifiers());
     $method->setNumberOfRequiredParameters($reflection_method->getNumberOfRequiredParameters());
     $method->setNumberOfOptionalParameters($reflection_method->getNumberOfParameters() - $reflection_method->getNumberOfRequiredParameters());
     $method->setFQSEN(FullyQualifiedMethodName::fromStringInContext($method->getName(), $context));
     return self::functionListFromFunction($method, $code_base);
 }
开发者ID:black-silence,项目名称:phan,代码行数:12,代码来源:FunctionFactory.php

示例2: dispatch

 /**
  *  Dispatch the request, return the response
  *
  *  @return Response The returned response
  */
 public function dispatch()
 {
     $service = $this->request->getService();
     $method = $this->request->getMethod();
     $params = (array) $this->request->getParams();
     try {
         $handlerClass = sprintf('Handler_%s', ucfirst($service));
         $handler = new $handlerClass($this->request);
     } catch (Exception $e) {
         $this->jsonError(JSONRPC_ERROR_METHOD_NOT_FOUND, 'Requested service unknown');
     }
     if (!method_exists($handler, $method)) {
         $this->jsonError(JSONRPC_ERROR_METHOD_NOT_FOUND, 'Requested method unknown');
     }
     $ref = new ReflectionMethod($handler, $method);
     $handlerParams = $ref->getParameters();
     foreach ($handlerParams as $handlerParam) {
         if (!array_key_exists($handlerParam->name, $params)) {
             $this->jsonError(JSONRPC_ERROR_INVALID_PARAMS, sprintf('Missing parameter "%s"', $handlerParam->name));
         }
     }
     if (count($params) !== $ref->getNumberOfRequiredParameters()) {
         $this->jsonError(JSONRPC_ERROR_INVALID_PARAMS, 'Wrong number of parameters');
     }
     Context::getInstance()->getLogger()->info(sprintf('Executing method "%s" in service "%s" with parameters "%s"', $method, $handlerClass, json_encode($params)));
     return call_user_func_array(array($handler, $method), $params);
 }
开发者ID:fica990,项目名称:jsonapi,代码行数:32,代码来源:Dispatcher.php

示例3: executeControllerAction

 static function executeControllerAction($controller, $action, $args)
 {
     if (self::controllerExists($controller)) {
         if (!method_exists($controller, $action)) {
             if (method_exists($controller, self::$method_unknown)) {
                 array_unshift($args, $action);
                 $action = self::$method_unknown;
             } else {
                 throw new ErrorNotFound("Method " . $action . " could not be found in Controller " . $controller);
             }
         }
     } else {
         //fallback to unkown controller method in main
         if (self::controllerExists("main") && method_exists("main", self::$method_unknown)) {
             array_unshift($args, $controller, $action);
             $controller = "main";
             $action = self::$method_unknown;
         } else {
             throw new ErrorNotFound("Controller " . $controller . " can not be loaded.");
         }
     }
     #check for parameter-count
     $method = new ReflectionMethod($controller, $action);
     $parametercount = $method->getNumberOfRequiredParameters();
     if (count($args) < $parametercount) {
         throw new ErrorNotAllowed("Can't call " . $controller . "." . $action . ".\n" . "Got " . count($args) . " arguments but at least " . $parametercount . " are required.");
     }
     #call it
     $instance = new $controller($controller);
     call_user_func_array(array($instance, $action), $args);
 }
开发者ID:x17x2a,项目名称:ff,代码行数:31,代码来源:dispatch.php

示例4: isAutoloadMethod

 /**
  * @param \ReflectionMethod $method
  * @return bool
  */
 private function isAutoloadMethod(\ReflectionMethod $method)
 {
     if (strpos($method->getName(), KnotConsts::AUTOLOAD_METHOD_PREFIX) !== 0 || $method->getNumberOfParameters() != 1 || $method->getNumberOfRequiredParameters() != 1 || $method->isStatic() || $method->isAbstract() || !Extractor::instance()->has($method, KnotConsts::AUTOLOAD_ANNOTATIONS)) {
         return false;
     }
     return true;
 }
开发者ID:oktopost,项目名称:skeleton,代码行数:11,代码来源:MethodConnector.php

示例5: checarParametros

 /**
  * Método para verificar se os parâmetros informados são pelo menos o total
  * exigido na classe do módulo.
  * Adicionada a chamada __call() caso a classe tenha
  *
  * @throws ControleException
  */
 private static function checarParametros()
 {
     // Se o total de parâmetros não suprir o número requerido
     if (self::$metodo->getName() != '__call' && count(self::$dadosUrl) < self::$metodo->getNumberOfRequiredParameters()) {
         throw new ControleException(ControleException::PARAMETROS_INSUFICIENTES, ucfirst(self::$modulo) . "::" . self::$acao);
     }
 }
开发者ID:jjaferson,项目名称:ourives,代码行数:14,代码来源:Facil.php

示例6: GetTransport

 /**
  * Return Transport. example: TransportFactory::GetTransport('SSH', $ssh_host, $ssh_port, $ssh_user, $ssh_pass);
  *
  * @static 
  * @param string $transportname
  * @return Object
  */
 public static function GetTransport($transportname)
 {
     $path_to_transports = dirname(__FILE__) . "/Transports";
     if (file_exists("{$path_to_transports}/class.{$transportname}Transport.php")) {
         Core::Load("class.{$transportname}Transport.php", $path_to_transports);
         if (class_exists("{$transportname}Transport") && self::IsTransport("{$transportname}Transport")) {
             // Get Constructor Reflection
             if (is_callable(array("{$transportname}Transport", "__construct"))) {
                 $reflect = new ReflectionMethod("{$transportname}Transport", "__construct");
             }
             // Delete $objectname from arguments
             $num_args = func_num_args() - 1;
             $args = func_get_args();
             array_shift($args);
             if ($reflect) {
                 $required_params = $reflect->getNumberOfRequiredParameters();
                 if ($required_params > $num_args) {
                     $params = $reflect->getParameters();
                     //TODO: Show what params are missing in error
                     Core::RaiseError(sprintf(_("Missing some required arguments for %s Transport constructor. Passed: %s, expected: %s."), $transportname, $num_args, $required_params));
                 }
             }
             $reflect = new ReflectionClass("{$transportname}Transport");
             if (count($args) > 0) {
                 return $reflect->newInstanceArgs($args);
             } else {
                 return $reflect->newInstance(true);
             }
         } else {
             Core::RaiseError(sprintf(_("Class '%s' not found or doesn't implements ITransport interface"), "{$transportname}Transport"));
         }
     }
 }
开发者ID:jasherai,项目名称:libwebta,代码行数:40,代码来源:class.TransportFactory.php

示例7: execute

 public function execute($argv)
 {
     if (!is_array($argv)) {
         $argv = array($argv);
     }
     $argc = count($argv);
     if (empty($this->action)) {
         throw new \Jolt\Exception('controller_action_not_set');
     }
     try {
         $action = new \ReflectionMethod($this, $this->action);
     } catch (\ReflectionException $e) {
         throw new \Jolt\Exception('controller_action_not_part_of_class');
     }
     $paramCount = $action->getNumberOfRequiredParameters();
     if ($paramCount != $argc && $paramCount > $argc) {
         $argv = array_pad($argv, $paramCount, NULL);
     }
     ob_start();
     if ($action->isPublic()) {
         if ($action->isStatic()) {
             $action->invokeArgs(NULL, $argv);
         } else {
             $action->invokeArgs($this, $argv);
         }
     }
     $renderedController = ob_get_clean();
     if (!empty($renderedController)) {
         $this->renderedController = $renderedController;
     } else {
         $this->renderedController = $this->renderedView;
     }
     return $this->renderedController;
 }
开发者ID:kennyma,项目名称:Jolt,代码行数:34,代码来源:Controller.php

示例8: invokeMethod

 public function invokeMethod($method, $params)
 {
     // for named parameters, convert from object to assoc array
     if (is_object($params)) {
         $array = array();
         foreach ($params as $key => $val) {
             $array[$key] = $val;
         }
         $params = array($array);
     }
     // for no params, pass in empty array
     if ($params === null) {
         $params = array();
     }
     $reflection = new \ReflectionMethod($this->exposed_instance, $method);
     // only allow calls to public functions
     if (!$reflection->isPublic()) {
         throw new Serverside\Exception("Called method is not publically accessible.");
     }
     // enforce correct number of arguments
     $num_required_params = $reflection->getNumberOfRequiredParameters();
     if ($num_required_params > count($params)) {
         throw new Serverside\Exception("Too few parameters passed.");
     }
     return $reflection->invokeArgs($this->exposed_instance, $params);
 }
开发者ID:evilscott,项目名称:junior,代码行数:26,代码来源:Server.php

示例9: getControllerObject

 private function getControllerObject(\ReflectionClass $rc, \ReflectionMethod $ra, array $params)
 {
     if ($ra->getNumberOfRequiredParameters() > count($params)) {
         throw new NotFoundException("Wrong number of parameters.");
     }
     return $rc->newInstance($this);
 }
开发者ID:Endymion1977,项目名称:phonebook,代码行数:7,代码来源:RequestHandler.php

示例10: callQueueMethod

 public function callQueueMethod(Queue $queue, $method)
 {
     $r = new \ReflectionMethod($queue, $method);
     if ($num = $r->getNumberOfRequiredParameters()) {
         return call_user_func_array([$queue, $method], array_fill(0, $num, 'foo'));
     }
     return $queue->{$method}();
 }
开发者ID:schedulee,项目名称:queue,代码行数:8,代码来源:Utils.php

示例11: getNumberOfRequiredParameters

 /**
  * Returns the number of required parameters
  *
  * @return integer The number of required parameters
  * @since PHP 5.0.3
  */
 public function getNumberOfRequiredParameters()
 {
     if ($this->reflectionSource instanceof ReflectionMethod) {
         return $this->reflectionSource->getNumberOfRequiredParameters();
     } else {
         return parent::getNumberOfRequiredParameters();
     }
 }
开发者ID:naderman,项目名称:ezc-reflection,代码行数:14,代码来源:method.php

示例12: __construct

 public function __construct(\ReflectionMethod $reflector)
 {
     $this->name = $reflector->name;
     $this->class = $reflector->class;
     $this->export = preg_match('/@Export\\s/', $reflector->getDocComment()) > 0;
     $this->reqParamCount = $reflector->getNumberOfRequiredParameters();
     $this->isPublic = $reflector->isPublic();
     $this->isStatic = $reflector->isStatic();
 }
开发者ID:echobot,项目名称:angularphp,代码行数:9,代码来源:Method.php

示例13: testExecute_ParamCount

 public function testExecute_ParamCount()
 {
     $action = 'paramAction';
     $controller = new Index();
     $controller->setAction($action);
     $reflectionAction = new \ReflectionMethod($controller, $action);
     $expectedParamCount = $reflectionAction->getNumberOfRequiredParameters();
     $actualParamCount = $controller->execute(array(10));
     $this->assertEquals($expectedParamCount, $actualParamCount);
 }
开发者ID:kennyma,项目名称:Jolt,代码行数:10,代码来源:ControllerTest.php

示例14: elseif

 function resolve2($context, array $path)
 {
     $original_path = $path;
     $head = array_shift($path);
     $args = $path;
     $head = $this->translate($head);
     // If the head is empty, then the URL ended in a slash (/), assume
     // the index is implied
     if (!$head) {
         $head = 'index';
     }
     try {
         $method = new \ReflectionMethod($context, $head);
         // Ensure that the method is visible
         if (!$method->isPublic()) {
             return false;
         }
         // Check if argument count matches the rest of the URL
         if (count($args) < $method->getNumberOfRequiredParameters()) {
             // Not enough parameters in the URL
             return false;
         }
         if (count($args) > ($C = $method->getNumberOfParameters())) {
             // Too many parameters in the URL — pass as many as possible to the function
             $path = array_slice($args, $C);
             $args = array_slice($args, 0, $C);
         }
         // Try to call the method and see what kind of response we get
         $result = $method->invokeArgs($context, $args);
         if ($result instanceof View\BaseView) {
             return $result;
         } elseif (is_callable($result)) {
             // We have a callable to be considered the view. We're done.
             return new View\BoundView($result, $args);
         } elseif ($result instanceof Dispatcher) {
             // Delegate to a sub dispatcher
             return $result->resolve(implode('/', $path));
         } elseif (is_object($result)) {
             // Recurse forward with the remainder of the path
             return $this->resolve2($result, $path);
         }
         // From here, we assume that the call failed
     } catch (\ReflectionException $ex) {
         // No such method, try def() or recurse backwards
     } catch (Exception\ConditionFailed $ex) {
         // The matched method refused the request — recurse backwards
     }
     // Not able to dispatch the method. Try def()
     if ($head != 'def') {
         $path = array_merge(['def'], $original_path);
         return $this->resolve2($context, $path);
     }
     // Unable to dispatch the request
     return false;
 }
开发者ID:iHunt101,项目名称:phlite,代码行数:55,代码来源:MethodDispatcher.php

示例15: __construct

 /**
  * "Start" the application:
  * Analyze the URL elements and calls the according controller/method or the fallback
  */
 public function __construct()
 {
     // create array with URL parts in $url
     $this->splitUrl();
     // check for controller: no controller given ? then load start-page
     if (!$this->controllerName) {
         require CONTROLLER_PATH . 'home_ctrl.php';
         $page = new HomeCtrl();
         $page->index();
     } elseif ($this->controllerName == 'public') {
         return;
     } elseif (!file_exists(CONTROLLER_PATH . $this->controllerName . '_ctrl.php')) {
         require CONTROLLER_PATH . 'error_ctrl.php';
         $page = new ErrorCtrl();
         $page->notFound();
     } else {
         // here we did check for controller: does such a controller exist ?
         // if so, then load this file and create this controller
         // example: if controller would be "car", then this line would translate into: $this->car = new car();
         $controllerFile = $this->controllerName . '_ctrl.php';
         $controllerName = $this->controllerName . 'Ctrl';
         require CONTROLLER_PATH . $controllerFile;
         $this->controller = new $controllerName();
         // check for method: does such a method exist in the controller ?
         if (!method_exists($this->controller, $this->actionName)) {
             if (strlen($this->actionName) == 0) {
                 // no action defined: call the default index() method of a selected controller
                 $this->controller->index();
             } else {
                 require CONTROLLER_PATH . 'error_ctrl.php';
                 $page = new ErrorCtrl();
                 $page->notFound();
             }
         } else {
             $reflectionMethod = new \ReflectionMethod($this->controller, $this->actionName);
             $numberOfRequiredParameters = $reflectionMethod->getNumberOfRequiredParameters();
             if (sizeof($this->params) < $numberOfRequiredParameters) {
                 require CONTROLLER_PATH . 'error_ctrl.php';
                 $page = new ErrorCtrl();
                 $page->notFound();
             } else {
                 if (!empty($this->params)) {
                     // Call the method and pass arguments to it
                     call_user_func_array(array($this->controller, $this->actionName), $this->params);
                 } else {
                     // If no parameters are given, just call the method without parameters, like $this->home->method();
                     $this->controller->{$this->actionName}();
                 }
             }
         }
     }
 }
开发者ID:khanhdnhut,项目名称:tours,代码行数:56,代码来源:application.php


注:本文中的ReflectionMethod::getNumberOfRequiredParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。