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


PHP ReflectionMethod::getParameters方法代码示例

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


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

示例1: __call

 public function __call($name, $arguments)
 {
     $store = ucfirst($this->type) . 'Store';
     $clientClass = '\\EDAM\\' . $store . '\\' . $store . 'Client';
     $method = new \ReflectionMethod($clientClass, $name);
     $params = array();
     foreach ($method->getParameters() as $param) {
         $params[] = $param->name;
     }
     $client = $this->getThriftClient();
     if (count($params) == count($arguments)) {
         return call_user_func_array(array($client, $name), $arguments);
     } elseif (in_array('authenticationToken', $params)) {
         $newArgs = array();
         foreach ($method->getParameters() as $idx => $param) {
             if ($param->name == 'authenticationToken') {
                 $newArgs[] = $this->token;
             }
             if ($idx < count($arguments)) {
                 $newArgs[] = $arguments[$idx];
             }
         }
         return call_user_func_array(array($client, $name), $newArgs);
     } else {
         return call_user_func_array(array($client, $name), $arguments);
     }
 }
开发者ID:smallsnailbigdream,项目名称:evernote-cloud-sdk-php,代码行数:27,代码来源:Store.php

示例2: createClassDefinition

 private function createClassDefinition()
 {
     $fullClassName = $this->getClass();
     if (class_exists($fullClassName)) {
         return;
     }
     $parts = explode('\\', $fullClassName);
     $shortName = array_pop($parts);
     $namespace = implode('\\', $parts);
     $properties = [];
     $parameters = [];
     $body = [];
     $getters = [];
     foreach ($this->method->getParameters() as $parameter) {
         $name = $parameter->getName();
         $parameters[] = '$' . $name . ($parameter->isDefaultValueAvailable() ? ' = ' . var_export($parameter->getDefaultValue(), true) : '');
         $body[] = '$this->' . $name . ' = $' . $name . ';';
         $properties[] = 'private $' . $name . ';';
         $hint = null;
         $matches = [];
         if ($parameter->getClass()) {
             $hint = $parameter->getClass()->getName();
         } else {
             if (preg_match('/@param\\s+(\\S+)\\s+\\$' . $name . '/', $this->method->getDocComment(), $matches)) {
                 $hint = $matches[1];
             }
         }
         $getters[] = ($hint ? "/**\n   * @return " . $hint . "\n   */\n  " : '') . 'function get' . ucfirst($name) . '() { return $this->' . $name . '; }';
     }
     $code = ($namespace ? "namespace {$namespace};\n" : '') . "class {$shortName} {\n" . '  ' . implode("\n  ", $properties) . "\n" . '  function __construct(' . implode(', ', $parameters) . ") {\n" . '    ' . implode("\n    ", $body) . "\n" . '  }' . "\n" . '  ' . implode("\n  ", $getters) . "\n" . '}';
     eval($code);
 }
开发者ID:watoki,项目名称:qrator,代码行数:32,代码来源:MethodActionRepresenter.php

示例3: fill

 /**
  * Fills out partially available parameters
  *
  * @param array $parameters Available values indexed by name
  * @return array Filled values indexed by name
  */
 public function fill(array $parameters)
 {
     foreach ($this->method->getParameters() as $parameter) {
         if ($parameter->isDefaultValueAvailable() && !array_key_exists($parameter->name, $parameters)) {
             $parameters[$parameter->name] = $parameter->getDefaultValue();
         }
     }
     return $parameters;
 }
开发者ID:jonfm,项目名称:domin,代码行数:15,代码来源:MethodAction.php

示例4: __construct

 public function __construct(Controller $controller, $action)
 {
     $this->controller = $controller;
     $this->name = $action;
     $this->reflector = new \ReflectionMethod($controller, $action);
     $this->docComment = $this->reflector->getDocComment();
     $this->parameters = $this->reflector->getParameters();
     $this->initializeAttributes();
 }
开发者ID:sanzhumu,项目名称:xaircraft1.1,代码行数:9,代码来源:ActionInfo.php

示例5: collectDependencies

 /**
  * @return DependencyContainer
  */
 private function collectDependencies()
 {
     $dependencies = new DependencyContainer();
     if (!$this->invokableReflection) {
         return $dependencies;
     }
     foreach ($this->invokableReflection->getParameters() as $parameter) {
         $dependencies->addDependency($parameter);
     }
     return $dependencies;
 }
开发者ID:filecage,项目名称:creator,代码行数:14,代码来源:Invokable.php

示例6: exportCode

 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $modifiers = \Reflection::getModifierNames($this->_method->getModifiers());
     $params = array();
     // Export method's parameters
     foreach ($this->_method->getParameters() as $param) {
         $reflection_parameter = new ReflectionParameter($param);
         $params[] = $reflection_parameter->exportCode();
     }
     return sprintf('%s function %s(%s) {}', join(' ', $modifiers), $this->_method->getName(), join(', ', $params));
 }
开发者ID:michalkoslab,项目名称:Helpers,代码行数:16,代码来源:ReflectionMethod.php

示例7: setUp

 public function setUp()
 {
     $class = DummyService::class;
     $method = 'dummyMethod';
     $this->method = new \ReflectionMethod($class, $method);
     $this->params = $this->method->getParameters();
     $this->normalizer = new ParamsDenormalizer();
     $propertyNormalizer = new PropertyNormalizer();
     $mixedDenormalizer = new MixedDenormalizer();
     $serializer = new Serializer([$this->normalizer, $propertyNormalizer, $mixedDenormalizer]);
     $this->normalizer->setSerializer($serializer);
 }
开发者ID:mihai-stancu,项目名称:serializer,代码行数:12,代码来源:ParamsDenormalizerTest.php

示例8: getOptions

 public function getOptions()
 {
     $params = $this->reflection->getParameters();
     if (empty($params)) {
         return [];
     }
     $param = end($params);
     if (!$param->isDefaultValueAvailable()) {
         return [];
     }
     if (!$this->isAssoc($param->getDefaultValue())) {
         return [];
     }
     return $param->getDefaultValue();
 }
开发者ID:sliver,项目名称:Robo,代码行数:15,代码来源:TaskInfo.php

示例9: reflect

 /**
  * @param object $object an object or classname
  * @param string $method the method which we want to inspect
  */
 public function reflect($object, $method)
 {
     $reflection = new \ReflectionMethod($object, $method);
     $docs = $reflection->getDocComment();
     // extract everything prefixed by @ and first letter uppercase
     preg_match_all('/@([A-Z]\\w+)/', $docs, $matches);
     $this->annotations = $matches[1];
     // extract type parameter information
     preg_match_all('/@param\\h+(?P<type>\\w+)\\h+\\$(?P<var>\\w+)/', $docs, $matches);
     $this->types = array_combine($matches['var'], $matches['type']);
     foreach ($reflection->getParameters() as $param) {
         // extract type information from PHP 7 scalar types and prefer them
         // over phpdoc annotations
         if (method_exists($param, 'getType')) {
             $type = $param->getType();
             if ($type !== null) {
                 $this->types[$param->getName()] = (string) $type;
             }
         }
         if ($param->isOptional()) {
             $default = $param->getDefaultValue();
         } else {
             $default = null;
         }
         $this->parameters[$param->name] = $default;
     }
 }
开发者ID:kenwi,项目名称:core,代码行数:31,代码来源:controllermethodreflector.php

示例10: build

 /**
  * @param \ReflectionMethod $method
  * @return mixed|string
  */
 public function build(\ReflectionMethod $method)
 {
     $functionDefinition = file_get_contents(__DIR__ . '/template/Function.php.template');
     $functionDefinition = str_replace('%name%', $method->getName(), $functionDefinition);
     $arguments = '';
     // TODO I guess this won't cut it
     if (substr($method->getName(), 0, 2) !== '__') {
         foreach ($method->getParameters() as $parameter) {
             $type = '';
             if ($parameter->getClass() !== null) {
                 $type = $parameter->getClass()->getName();
             } elseif ($parameter->isArray()) {
                 $type = 'array';
             }
             $default = '';
             if ($parameter->isDefaultValueAvailable()) {
                 if (null === $parameter->getDefaultValue()) {
                     $default = '= NULL';
                 } else {
                     $default = sprintf("='%s'", $parameter->getDefaultValue());
                 }
             } elseif ($parameter->isOptional()) {
                 // Workaround for optional parameters of internal methods
                 $default = '= NULL';
             }
             $arguments .= sprintf('%s $%s %s ,', $type, $parameter->getName(), $default);
         }
         $arguments = rtrim($arguments, ',');
     }
     $functionDefinition = str_replace('%arguments%', $arguments, $functionDefinition);
     return $functionDefinition;
 }
开发者ID:belanur,项目名称:mokka,代码行数:36,代码来源:FunctionDefinitionBuilder.php

示例11: testopen_archive

 /**
  * @covers gzip_file::open_archive
  * @todo   Implement testopen_archive().
  */
 public function testopen_archive()
 {
     $methods = get_class_methods($this->object);
     $this->assertTrue(in_array('open_archive', $methods), 'exists method open_archive');
     $r = new ReflectionMethod('gzip_file', 'open_archive');
     $params = $r->getParameters();
 }
开发者ID:emildev35,项目名称:processmaker,代码行数:11,代码来源:classgzip_fileTest.php

示例12: runWithParamsInternal

 /**
  * Executes a method of an object with the supplied named parameters.
  * This method is internally used.
  * @param mixed $object the object whose method is to be executed
  * @param ReflectionMethod $method the method reflection
  * @param array $params the named parameters
  * @return boolean whether the named parameters are valid
  * @since 1.1.7
  */
 protected function runWithParamsInternal($object, $method, $params)
 {
     $ps = array();
     foreach ($method->getParameters() as $i => $param) {
         $name = $param->getName();
         if (isset($params[$name])) {
             if ($param->isArray()) {
                 $ps[] = is_array($params[$name]) ? $params[$name] : array($params[$name]);
             } else {
                 if (!is_array($params[$name])) {
                     $ps[] = $params[$name];
                 } else {
                     return false;
                 }
             }
         } else {
             if ($param->isDefaultValueAvailable()) {
                 $ps[] = $param->getDefaultValue();
             } else {
                 return false;
             }
         }
     }
     $method->invokeArgs($object, $ps);
     return true;
 }
开发者ID:alsvader,项目名称:hackbanero,代码行数:35,代码来源:CAction.php

示例13: run

 /**
  * Runs the action.
  * The action method defined in the controller is invoked.
  * This method is required by {@link CAction}.
  */
 public function run()
 {
     $controller = $this->getController();
     $methodName = 'action' . $this->getId();
     $method = new ReflectionMethod($controller, $methodName);
     if (($n = $method->getNumberOfParameters()) > 0) {
         $params = array();
         foreach ($method->getParameters() as $i => $param) {
             $name = $param->getName();
             if (isset($_GET[$name])) {
                 if ($param->isArray()) {
                     $params[] = is_array($_GET[$name]) ? $_GET[$name] : array($_GET[$name]);
                 } else {
                     if (!is_array($_GET[$name])) {
                         $params[] = $_GET[$name];
                     } else {
                         throw new CHttpException(400, Yii::t('yii', 'Your request is invalid.'));
                     }
                 }
             } else {
                 if ($param->isDefaultValueAvailable()) {
                     $params[] = $param->getDefaultValue();
                 } else {
                     throw new CHttpException(400, Yii::t('yii', 'Your request is invalid.'));
                 }
             }
         }
         $method->invokeArgs($controller, $params);
     } else {
         $controller->{$methodName}();
     }
 }
开发者ID:IuriiP,项目名称:yii-tracker,代码行数:37,代码来源:CInlineAction.php

示例14: _extractActionParameters

 /**
  * @param Action  $action
  * @param Request $request
  * @return array
  * @throws \Exception
  */
 protected function _extractActionParameters(Action $action, Request $request)
 {
     $reflectionMethod = new \ReflectionMethod($action->getControllerName(), $action->getMethodName());
     $parameters = [];
     foreach ($reflectionMethod->getParameters() as $parameter) {
         $parameterClass = $parameter->getClass();
         if ($parameterClass) {
             if (is_a($parameterClass->getName(), '\\Wrestler\\Http\\Request\\RouteParams', true)) {
                 $parameters[] = $parameterClass->newInstance($action->getRouteParams());
                 continue;
             }
             if (is_a($parameterClass->getName(), '\\Wrestler\\Http\\Request\\PostData', true)) {
                 $parameters[] = $parameterClass->newInstance($request->getPostData());
                 continue;
             }
             if (is_a($parameterClass->getName(), '\\Wrestler\\Http\\Request\\Query', true)) {
                 $parameters[] = $parameterClass->newInstance($request->getQuery());
                 continue;
             }
             if (is_a($parameterClass->getName(), '\\Wrestler\\Http\\Request\\Headers', true)) {
                 $parameters[] = $parameterClass->newInstance($request->getHeaders());
                 continue;
             }
         }
         $variable = $parameter->getName();
         if ($parameterClass) {
             $variable = $parameterClass->getName() . ' ' . $variable;
         }
         throw new \Exception("Cannot map `{$variable}`");
     }
     return $parameters;
 }
开发者ID:codespot,项目名称:wrestler,代码行数:38,代码来源:Handler.php

示例15: dumpMethodParameters

 private function dumpMethodParameters($className, MethodInjection $methodInjection)
 {
     $methodReflection = new \ReflectionMethod($className, $methodInjection->getMethodName());
     $args = [];
     $definitionParameters = $methodInjection->getParameters();
     foreach ($methodReflection->getParameters() as $index => $parameter) {
         if (array_key_exists($index, $definitionParameters)) {
             $value = $definitionParameters[$index];
             if ($value instanceof EntryReference) {
                 $args[] = sprintf('$%s = get(%s)', $parameter->getName(), $value->getName());
             } else {
                 $args[] = sprintf('$%s = %s', $parameter->getName(), var_export($value, true));
             }
             continue;
         }
         // If the parameter is optional and wasn't specified, we take its default value
         if ($parameter->isOptional()) {
             try {
                 $value = $parameter->getDefaultValue();
                 $args[] = sprintf('$%s = (default value) %s', $parameter->getName(), var_export($value, true));
                 continue;
             } catch (ReflectionException $e) {
                 // The default value can't be read through Reflection because it is a PHP internal class
             }
         }
         $args[] = sprintf('$%s = #UNDEFINED#', $parameter->getName());
     }
     return implode(PHP_EOL . '        ', $args);
 }
开发者ID:mnapoli,项目名称:php-di,代码行数:29,代码来源:ObjectDefinitionDumper.php


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