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


PHP ReflectionMethod::getReturnType方法代码示例

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


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

示例1: getReturnType

 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $this->returnType = TypehintHelper::decideType($this->reflection->getReturnType(), $this->phpDocReturnType, $this->declaringClass->getName());
     }
     return $this->returnType;
 }
开发者ID:phpstan,项目名称:phpstan,代码行数:7,代码来源:PhpMethodReflection.php

示例2: updateDefinition

 private function updateDefinition(ContainerBuilder $container, $id, Definition $definition, array $previous = array())
 {
     // circular reference
     if (isset($previous[$id])) {
         return;
     }
     $factory = $definition->getFactory();
     if (null === $factory || null !== $definition->getClass()) {
         return;
     }
     $class = null;
     if (is_string($factory)) {
         try {
             $m = new \ReflectionFunction($factory);
         } catch (\ReflectionException $e) {
             return;
         }
     } else {
         if ($factory[0] instanceof Reference) {
             $previous[$id] = true;
             $factoryDefinition = $container->findDefinition((string) $factory[0]);
             $this->updateDefinition($container, (string) $factory[0], $factoryDefinition, $previous);
             $class = $factoryDefinition->getClass();
         } else {
             $class = $factory[0];
         }
         try {
             $m = new \ReflectionMethod($class, $factory[1]);
         } catch (\ReflectionException $e) {
             return;
         }
     }
     $returnType = $m->getReturnType();
     if (null !== $returnType && !$returnType->isBuiltin()) {
         $returnType = (string) $returnType;
         if (null !== $class) {
             $declaringClass = $m->getDeclaringClass()->getName();
             if ('self' === $returnType) {
                 $returnType = $declaringClass;
             } elseif ('parent' === $returnType) {
                 $returnType = get_parent_class($declaringClass) ?: null;
             }
         }
         $definition->setClass($returnType);
     }
 }
开发者ID:ayoah,项目名称:symfony,代码行数:46,代码来源:FactoryReturnTypePass.php

示例3: __construct

 /**
  * Initializes method prophecy.
  *
  * @param ObjectProphecy                        $objectProphecy
  * @param string                                $methodName
  * @param null|Argument\ArgumentsWildcard|array $arguments
  *
  * @throws \Prophecy\Exception\Doubler\MethodNotFoundException If method not found
  */
 public function __construct(ObjectProphecy $objectProphecy, $methodName, $arguments = null)
 {
     $double = $objectProphecy->reveal();
     if (!method_exists($double, $methodName)) {
         throw new MethodNotFoundException(sprintf('Method `%s::%s()` is not defined.', get_class($double), $methodName), get_class($double), $methodName, $arguments);
     }
     $this->objectProphecy = $objectProphecy;
     $this->methodName = $methodName;
     $reflectedMethod = new \ReflectionMethod($double, $methodName);
     if ($reflectedMethod->isFinal()) {
         throw new MethodProphecyException(sprintf("Can not add prophecy for a method `%s::%s()`\n" . "as it is a final method.", get_class($double), $methodName), $this);
     }
     if (null !== $arguments) {
         $this->withArguments($arguments);
     }
     if (version_compare(PHP_VERSION, '7.0', '>=') && true === $reflectedMethod->hasReturnType()) {
         $type = (string) $reflectedMethod->getReturnType();
         $this->will(function () use($type) {
             switch ($type) {
                 case 'string':
                     return '';
                 case 'float':
                     return 0.0;
                 case 'int':
                     return 0;
                 case 'bool':
                     return false;
                 case 'array':
                     return array();
                 case 'callable':
                 case 'Closure':
                     return function () {
                     };
                 case 'Traversable':
                 case 'Generator':
                     // Remove eval() when minimum version >=5.5
                     /** @var callable $generator */
                     $generator = eval('return function () { yield; };');
                     return $generator();
                 default:
                     $prophet = new Prophet();
                     return $prophet->prophesize($type)->reveal();
             }
         });
     }
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:55,代码来源:MethodProphecy.php

示例4: methodToTypeInfoMember

 /**
  * @param \ReflectionMethod $method
  *
  * @return TypeInfoMember|null
  */
 protected function methodToTypeInfoMember(\ReflectionMethod $method)
 {
     if (substr($method->name, 0, 2) === '__') {
         return;
     }
     $docb = new DocBlock($method);
     $hint = $docb->getComment() ?: '';
     $link = $docb->getTag('link', '') ?: '';
     if (is_array($link)) {
         $link = $link[0];
     }
     if ($docb->tagExists('param')) {
         // detect return from docblock
         $return = explode(' ', $docb->getTag('return', 'void'), 2)[0];
     } else {
         // detect return from reflection
         $return = $this->canInspectReflectionReturnType ? $method->getReturnType() : '';
     }
     if ($docb->tagExists('param')) {
         // detect params from docblock
         $params = array_map([$this, 'parseDocBlockPropOrParam'], $docb->getTag('param', [], true));
     } else {
         // detect params from reflection
         $params = array_map([$this, 'parseReflectedParams'], $method->getParameters());
     }
     $signature = sprintf('<div class="cm-signature">' . '<span class="type">%s</span> <span class="name">%s</span>' . '(<span class="args">%s</span>)</span>' . '</div>', $return, $method->name, implode(', ', array_map(function ($param) {
         $result = '???';
         if ($param) {
             $result = sprintf('<span class="%s" title="%s"><span class="type">%s</span>$%s</span>', $param['hint'] ? 'arg hint' : 'arg', $param['hint'], count($param['types']) ? implode('|', $param['types']) . ' ' : '', $param['name']);
         }
         return $result;
     }, $params)));
     return new TypeInfoMember($method->name, ['method'], $signature . $hint, $link);
 }
开发者ID:uuf6429,项目名称:rune,代码行数:39,代码来源:TypeAnalyser.php

示例5: function

<?php

$f = function (stdClass $x) : stdClass {
};
$r = new ReflectionMethod($f, '__invoke');
var_dump($r->getParameters()[0]->getName());
var_dump($r->getParameters()[0]->getClass());
echo $r->getParameters()[0], "\n";
echo $r->getReturnType(), "\n";
echo $r, "\n";
开发者ID:zaky-92,项目名称:php-1,代码行数:10,代码来源:Zend_tests_bug69802.php

示例6: describeMethod

 /**
  * @param $methodMirror
  *
  * @return string
  */
 protected function describeMethod(ReflectionMethod $methodMirror) : string
 {
     if ($methodMirror->isProtected() || $methodMirror->isPrivate()) {
         return '';
     }
     $this->parseDocComment($methodMirror->getDocComment(), 2);
     $output = "\t.. php:method:: " . $methodMirror->name . " ( ";
     $output .= $this->buildParameterList($methodMirror->getParameters()) . " )\n\n";
     $output .= $this->describeParameters($methodMirror->getParameters());
     if ($methodMirror->hasReturnType()) {
         $output .= "\t\t:returns: \n\t\t:rtype: {$methodMirror->getReturnType()}";
     }
     $output .= "\n\n";
     $output .= $this->currentDocString . "\n\n";
     return $output;
 }
开发者ID:titounnes,项目名称:CodeIgniter4,代码行数:21,代码来源:autodoc.php

示例7: function

<?php

$closure = function (Test $x) : Test2 {
    return new Test2($x);
};
$rm = new ReflectionMethod($closure, '__invoke');
$rp = $rm->getParameters()[0];
$rt = $rp->getType();
$rrt = $rm->getReturnType();
unset($rm, $rp);
var_dump((string) $rt, (string) $rrt);
开发者ID:gleamingthecube,项目名称:php,代码行数:11,代码来源:ext_reflection_tests_ReflectionType_002.php

示例8: buildMethodSignature

 protected function buildMethodSignature(\ReflectionMethod $method, bool $skipAbstract = false, bool $skipDefaultValues = false) : string
 {
     if ($method->isProtected()) {
         $code = 'protected ';
     } elseif ($method->isPrivate()) {
         $code = 'private ';
     } else {
         $code = 'public ';
     }
     if ($method->isAbstract()) {
         if (!$skipAbstract) {
             $code .= 'abstract ';
         }
     } elseif ($method->isFinal()) {
         $code .= 'final ';
     }
     if ($method->isStatic()) {
         $code .= 'static ';
     }
     $code .= 'function ';
     if ($method->returnsReference()) {
         $code .= '& ';
     }
     $code .= $method->getName() . '(';
     foreach ($method->getParameters() as $i => $param) {
         if ($i > 0) {
             $code .= ', ';
         }
         $code .= $this->buildParameterSignature($param, $skipDefaultValues);
     }
     $code .= ')';
     if ($method->hasReturnType()) {
         $type = $method->getReturnType();
         if ($type->isBuiltin) {
             $code .= ': ' . $type;
         } else {
             $code .= ': \\' . $type;
         }
     }
     return $code;
 }
开发者ID:koolkode,项目名称:util,代码行数:41,代码来源:ReflectionTrait.php

示例9: allowsReturnNull

 /**
  * @param ReflectionMethod $method
  *
  * @return bool
  */
 private function allowsReturnNull(ReflectionMethod $method)
 {
     return method_exists(ReflectionMethod::class, 'getReturnType') && method_exists(ReflectionType::class, 'allowsNull') && $method->hasReturnType() && $method->getReturnType()->allowsNull();
 }
开发者ID:baardbaard,项目名称:bb-twitterfeed,代码行数:9,代码来源:Generator.php


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