本文整理汇总了PHP中ReflectionFunction::getParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::getParameters方法的具体用法?PHP ReflectionFunction::getParameters怎么用?PHP ReflectionFunction::getParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunction
的用法示例。
在下文中一共展示了ReflectionFunction::getParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* (non-PHPdoc)
* @see \PHPFluent\EventManager\Listener::execute()
*/
public function execute(Event $event, array $context = array())
{
$arguments = array($event, $context);
$parameters = $this->reflection->getParameters();
$firstParameter = array_shift($parameters);
if ($firstParameter instanceof \ReflectionParameter && $firstParameter->isArray()) {
$arguments = array_reverse($arguments);
}
return $this->reflection->invokeArgs($arguments);
}
示例2: getParameterList
/**
* @return IParameterReflection[]
*/
public function getParameterList()
{
if ($this->parameterList === null) {
$this->parameterList = [];
foreach ($this->reflectionFunction->getParameters() as $reflectionParameter) {
$this->parameterList[$reflectionParameter->getName()] = new ParameterReflection($reflectionParameter);
}
}
return $this->parameterList;
}
示例3: main
function main()
{
$rc = new ReflectionClass("Foo\\Bar\\A");
var_dump($rc->isInterface());
var_dump($rc->getMethod('set')->getParameters()[0]->getDefaultValue());
var_dump($rc->getMethod('set')->getParameters()[0]->getDefaultValueConstantName());
$rc = new \ReflectionFunction("Foo\\Bar\\foo");
var_dump($rc->getParameters()[0]->getDefaultValue());
var_dump($rc->getParameters()[0]->getDefaultValueConstantName());
Foo\Bar\foo();
}
示例4: 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;
}
示例5: getParameters
/**
* @return \PHPStan\Reflection\ParameterReflection[]
*/
public function getParameters() : array
{
if ($this->parameters === null) {
$this->parameters = array_map(function (\ReflectionParameter $reflection) {
return new PhpParameterReflection($reflection);
}, $this->reflection->getParameters());
if ($this->reflection->getName() === 'array_unique' && count($this->parameters) === 1) {
// PHP bug #70960
$this->parameters[] = new DummyOptionalParameter('sort_flags', new IntegerType(false));
}
}
return $this->parameters;
}
示例6: send
public function send(StreamInterface $stream)
{
if (!$stream->isWritable()) {
throw new \InvalidArgumentException('Output stream must be writable');
}
if (is_array($this->callback)) {
$ref = (new \ReflectionClass(is_object($this->callback[0]) ? get_class($this->callback[0]) : $this->callback[0]))->getMethod($this->callback[1]);
} elseif (is_object($this->callback) && !$this->callback instanceof \Closure) {
$ref = new \ReflectionMethod(get_class($this->callback), '__invoke');
} else {
$ref = new \ReflectionFunction($this->callback);
}
if ($ref->isGenerator()) {
foreach (call_user_func($this->callback) as $chunk) {
$stream->write($chunk);
}
return;
}
foreach ($ref->getParameters() as $param) {
if (NULL !== ($type = $param->getClass())) {
if ($type->name === StreamInterface::class || $type->implementsInterface(StreamInterface::class)) {
call_user_func($this->callback, $stream);
return;
}
}
break;
}
$stream->write((string) call_user_func($this->callback));
}
示例7: test
function test()
{
$x = new ReflectionFunction('array_filter');
$params = $x->getParameters();
$p1 = $params[1];
var_dump($p1->getDefaultValueText());
}
示例8: onKernelController
/**
* Modifies the ParamConverterManager instance.
*
* @param FilterControllerEvent $event A FilterControllerEvent instance
*/
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
$request = $event->getRequest();
$configurations = array();
if ($configuration = $request->attributes->get('_converters')) {
foreach (is_array($configuration) ? $configuration : array($configuration) as $configuration) {
$configurations[$configuration->getName()] = $configuration;
}
}
if (is_array($controller)) {
$r = new \ReflectionMethod($controller[0], $controller[1]);
} else {
$r = new \ReflectionFunction($controller);
}
// automatically apply conversion for non-configured objects
foreach ($r->getParameters() as $param) {
if (!$param->getClass() || $param->getClass()->isInstance($request)) {
continue;
}
$name = $param->getName();
if (!isset($configurations[$name])) {
$configuration = new ParamConverter(array());
$configuration->setName($name);
$configuration->setClass($param->getClass()->getName());
$configurations[$name] = $configuration;
} elseif (null === $configurations[$name]->getClass()) {
$configurations[$name]->setClass($param->getClass()->getName());
}
$configurations[$name]->setIsOptional($param->isOptional());
}
$this->manager->apply($request, $configurations);
}
示例9: ReflectionFunction
/**
* get Closure info
* @param Closure $c
* @return array
*/
function closure_dump(Closure $c)
{
$str = 'function (';
$r = new ReflectionFunction($c);
$params = array();
foreach ($r->getParameters() as $p) {
$s = '';
if ($p->isArray()) {
$s .= 'array ';
} else {
if ($p->getClass()) {
$s .= $p->getClass()->name . ' ';
}
}
if ($p->isPassedByReference()) {
$s .= '&';
}
$s .= '$' . $p->name;
if ($p->isOptional()) {
$s .= ' = ' . var_export($p->getDefaultValue(), TRUE);
}
$params[] = $s;
}
$str .= implode(', ', $params);
$str .= '){' . PHP_EOL;
$lines = file($r->getFileName());
for ($l = $r->getStartLine(); $l < $r->getEndLine(); $l++) {
$str .= $lines[$l];
}
$arr = ['file' => $r->getFileName(), 'line' => $r->getStartLine() . '-' . $r->getEndLine(), 'source' => $str];
return $arr;
}
示例10: getParameters
/**
* @return Parameter[]
*/
public function getParameters()
{
foreach ($res = parent::getParameters() as $key => $val) {
$res[$key] = new Parameter($this->value, $val->getName());
}
return $res;
}
示例11: castClosure
static function castClosure($c)
{
$a = array();
if (!class_exists('ReflectionFunction', false)) {
return $a;
}
$c = new \ReflectionFunction($c);
foreach ($c->getParameters() as $p) {
$n = ($p->isPassedByReference() ? '&$' : '$') . $p->getName();
if ($p->isDefaultValueAvailable()) {
$a[$n] = $p->getDefaultValue();
} else {
$a[] = $n;
}
}
$m = self::META_PREFIX;
$a = array($m . 'returnsRef' => true, $m . 'args' => $a);
if (!$c->returnsReference()) {
unset($a[$m . 'returnsRef']);
}
$a[$m . 'use'] = array();
if (false === ($a[$m . 'file'] = $c->getFileName())) {
unset($a[$m . 'file']);
} else {
$a[$m . 'lines'] = $c->getStartLine() . '-' . $c->getEndLine();
}
if (!($c = $c->getStaticVariables())) {
unset($a[$m . 'use']);
} else {
foreach ($c as $p => &$c) {
$a[$m . 'use']['$' . $p] =& $c;
}
}
return $a;
}
示例12: runMiddlewares
/**
* Runs all the middlewares of given type.
*/
public static function runMiddlewares($type = self::BEFORE_REQUEST)
{
$apricot = static::getInstance();
$middlewares = $apricot->middlewares;
/** @var \Exception */
$error = null;
foreach ($middlewares as $key => $middleware) {
$hasNextMiddleware = array_key_exists($key + 1, $middlewares);
if ($type !== $middleware['type']) {
continue;
}
$r = new \ReflectionFunction($middleware['callback']);
$parameters = $r->getParameters();
$next = $hasNextMiddleware ? $middlewares[$key + 1] : function () {
};
try {
$r->invokeArgs(array($error, $next));
} catch (\Exception $e) {
// If there is no more middleware to run, throw the exception.
if (!$hasNextMiddleware) {
throw $e;
}
$error = $e;
}
}
}
示例13: getNamedArgs
public static function getNamedArgs()
{
$bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
$frame = $bt[1];
if ($frame['function'] == '{closure}') {
throw new \LogicException("This can't work inside a closure, sadly");
}
if (isset($frame['class'])) {
$rc = new \ReflectionClass($frame['class']);
$rf = $rc->getMethod($frame['function']);
} else {
$rf = new \ReflectionFunction($frame['function']);
}
$named = [];
$args = $frame['args'];
foreach ($rf->getParameters() as $idx => $param) {
$name = $param->getName();
if (!array_key_exists($idx, $args)) {
if ($param->isDefaultValueAvailable()) {
$named[$name] = $param->getDefaultValue();
} else {
break;
}
} else {
$named[$name] = $args[$idx];
}
}
return $named;
}
示例14: shouldRun
private function shouldRun($callback, $controllerResult)
{
if (is_array($callback)) {
$callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
$callbackReflection = new \ReflectionObject($callback);
$callbackReflection = $callbackReflection->getMethod('__invoke');
} else {
$callbackReflection = new \ReflectionFunction($callback);
}
if ($callbackReflection->getNumberOfParameters() > 0) {
$parameters = $callbackReflection->getParameters();
$expectedControllerResult = $parameters[0];
if ($expectedControllerResult->getClass() && (!is_object($controllerResult) || !$expectedControllerResult->getClass()->isInstance($controllerResult))) {
return false;
}
if ($expectedControllerResult->isArray() && !is_array($controllerResult)) {
return false;
}
if (method_exists($expectedControllerResult, 'isCallable') && $expectedControllerResult->isCallable() && !is_callable($controllerResult)) {
return false;
}
}
return true;
}
示例15: call_closure
/**
* Call closure.
*
* @param mixed $closure
* @param array $parameters
*
* @return Closure
*/
protected function call_closure($closure, array $parameters = [])
{
if ($closure instanceof Closure) {
$rc = new ReflectionFunction($closure);
$args = $rc->getParameters();
$params = $parameters;
$classes = [$this->get_class_prefix(get_class($this)), get_class($this), get_parent_class($this)];
foreach ($args as $index => $arg) {
if ($arg->getClass() === null) {
continue;
}
if (in_array($arg->getClass()->name, $classes)) {
$parameters[$index] = $this;
} else {
if ($this->exists($arg->getClass()->name)) {
$parameters[$index] = $this->make($arg->getClass()->name);
}
}
}
if (!empty($args) && empty($parameters)) {
$parameters[0] = $this;
}
if (count($args) > count($parameters)) {
$parameters = array_merge($parameters, $params);
}
return $this->call_closure(call_user_func_array($closure, $parameters), $parameters);
}
return $closure;
}