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


PHP ReflectionMethod::returnsReference方法代码示例

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


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

示例1: writeMethod

 public function writeMethod(\ReflectionMethod $method)
 {
     $args = [];
     foreach ($method->getParameters() as $parameter) {
         $arg = '';
         if ($parameter->isArray()) {
             $arg .= 'array ';
         } else {
             if ($parameter->getClass()) {
                 $arg .= '\\' . $parameter->getClass()->getName() . ' ';
             }
         }
         if ($parameter->isPassedByReference()) {
             $arg .= '&';
         }
         $arg .= '$' . $parameter->getName();
         try {
             $defaultValue = $parameter->getDefaultValue();
             $arg .= ' = ' . var_export($defaultValue, true);
         } catch (ReflectionException $e) {
             if ($parameter->isOptional()) {
                 $arg .= ' = null';
             }
         }
         $args[] = $arg;
     }
     $modifiers = array_diff(\Reflection::getModifierNames($method->getModifiers()), ['abstract']);
     $methodName = ($method->returnsReference() ? '&' : '') . $method->getName();
     $this->code[] = '  ' . implode(' ', $modifiers) . ' function ' . $methodName . '(' . implode(', ', $args) . ') {';
     $this->code[] = '    $result = $this->' . $this->propertyName . '->invoke($this, \'' . $method->getName() . '\', func_get_args());';
     $this->code[] = '    return $result;';
     $this->code[] = '  }';
 }
开发者ID:crashuxx,项目名称:phproxy,代码行数:33,代码来源:DefaultBuilder.php

示例2: returnsReference

 /**
  * Returns whether this method returns a reference
  *
  * @return boolean True if this method returns a reference
  */
 public function returnsReference()
 {
     if ($this->reflectionSource instanceof ReflectionMethod) {
         return $this->reflectionSource->returnsReference();
     } else {
         return parent::returnsReference();
     }
 }
开发者ID:naderman,项目名称:ezc-reflection,代码行数:13,代码来源:method.php

示例3: fromReflection

 public static function fromReflection(\ReflectionMethod $ref)
 {
     $method = new static();
     $method->setFinal($ref->isFinal())->setAbstract($ref->isAbstract())->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE))->setReferenceReturned($ref->returnsReference())->setName($ref->name);
     if ($docComment = $ref->getDocComment()) {
         $method->setDocblock(ReflectionUtils::getUnindentedDocComment($docComment));
     }
     foreach ($ref->getParameters() as $param) {
         $method->addParameter(static::createParameter($param));
     }
     // FIXME: Extract body?
     return $method;
 }
开发者ID:ingeniorweb,项目名称:symfo3cv,代码行数:13,代码来源:PhpMethod.php

示例4: fromReflection

 public static function fromReflection(\ReflectionMethod $ref)
 {
     $method = new static($ref->name);
     $method->setFinal($ref->isFinal())->setAbstract($ref->isAbstract())->setStatic($ref->isStatic())->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE))->setReferenceReturned($ref->returnsReference())->setBody(ReflectionUtils::getFunctionBody($ref));
     $docblock = new Docblock($ref);
     $method->setDocblock($docblock);
     $method->setDescription($docblock->getShortDescription());
     $method->setLongDescription($docblock->getLongDescription());
     foreach ($ref->getParameters() as $param) {
         $method->addParameter(static::createParameter($param));
     }
     return $method;
 }
开发者ID:jmcclell,项目名称:php-code-generator,代码行数:13,代码来源:PhpMethod.php

示例5: assertEqualMethods

 /**
  * @param \ReflectionMethod $reflectionMethod
  * @param \Donquixote\HastyReflectionCommon\Reflection\FunctionLike\MethodReflectionInterface $methodReflection
  */
 private function assertEqualMethods(\ReflectionMethod $reflectionMethod, MethodReflectionInterface $methodReflection)
 {
     $this->assertEquals($reflectionMethod->isAbstract(), $methodReflection->isAbstract());
     $this->assertEquals($reflectionMethod->getDeclaringClass()->getName(), $methodReflection->getDeclaringClassName());
     $this->assertEquals($reflectionMethod->getDocComment(), $methodReflection->getDocComment());
     $this->assertEquals($reflectionMethod->getShortName(), $methodReflection->getName());
     $this->assertEquals($reflectionMethod->getName(), $methodReflection->getName());
     $this->assertEquals($reflectionMethod->class . '::' . $reflectionMethod->getName(), $methodReflection->getQualifiedName());
     $this->assertEquals($reflectionMethod->returnsReference(), $methodReflection->isByReference());
     $this->assertEquals($reflectionMethod->isPrivate(), $methodReflection->isPrivate());
     $this->assertEquals($reflectionMethod->isProtected(), $methodReflection->isProtected());
     $this->assertEquals($reflectionMethod->isPublic(), $methodReflection->isPublic());
     $this->assertEquals($reflectionMethod->isStatic(), $methodReflection->isStatic());
 }
开发者ID:donquixote,项目名称:hasty-reflection-common,代码行数:18,代码来源:ClassIndexTest.php

示例6: generate

 public final function generate(\ReflectionMethod $method)
 {
     $name = $method->getName();
     $output = ' public function ';
     if ($method->returnsReference()) {
         $output .= '&';
     }
     $output .= $method->getName() . '(';
     $separator = '';
     foreach ($method->getParameters() as $param) {
         $output .= $separator . $this->generateParameterDeclaration($param);
         $separator = ', ';
     }
     $output .= ") { " . $this->generateBody($name) . " }\n";
     return $output;
 }
开发者ID:trismegiste,项目名称:php-is-magic,代码行数:16,代码来源:MethodGenerator.php

示例7: canRedirected

 protected function canRedirected(\ReflectionMethod $source, \ReflectionMethod $target)
 {
     if ($target->isPublic() && !preg_match('#^__#', $source->getName()) && $source->returnsReference() == $target->returnsReference()) {
         $sourceParam = $source->getParameters();
         $targetParam = $target->getParameters();
         // check parameters
         if (count($targetParam) != count($sourceParam)) {
             return false;
         }
         foreach ($targetParam as $idx => $to) {
             $from = $sourceParam[$idx];
             if ($to->isArray() != $from->isArray() || $to->getClass() != $from->getClass() || $to->isCallable() != $from->isCallable() || $to->isPassedByReference() != $from->isPassedByReference()) {
                 return false;
             }
         }
         // all ok returns true
         return true;
     }
     return false;
 }
开发者ID:trismegiste,项目名称:php-is-magic,代码行数:20,代码来源:AdapterGenerator.php

示例8: methodData

function methodData(ReflectionMethod $method)
{
    $details = "";
    $name = $method->getName();
    if ($method->isUserDefined()) {
        $details .= "{$name} is user defined\n";
    }
    if ($method->isInternal()) {
        $details .= "{$name} is built-in\n";
    }
    if ($method->isAbstract()) {
        $details .= "{$name} is abstract\n";
    }
    if ($method->isPublic()) {
        $details .= "{$name} is public\n";
    }
    if ($method->isProtected()) {
        $details .= "{$name} is protected\n";
    }
    if ($method->isPrivate()) {
        $details .= "{$name} is private\n";
    }
    if ($method->isStatic()) {
        $details .= "{$name} is static\n";
    }
    if ($method->isFinal()) {
        $details .= "{$name} is final\n";
    }
    if ($method->isConstructor()) {
        $details .= "{$name} is the constructor\n";
    }
    if ($method->returnsReference()) {
        $details .= "{$name} returns a reference (as opposed to a value)\n";
    }
    return $details;
}
开发者ID:jabouzi,项目名称:projet,代码行数:36,代码来源:listing5.28.php

示例9: getOverriddenMethod

 /**
  * Creates a method code from Reflection
  *
  * @param Method|ParsedMethod $method Reflection for method
  * @param string $body Body of method
  *
  * @return string
  */
 protected function getOverriddenMethod($method, $body)
 {
     $code = preg_replace('/ {4}|\\t/', '', $method->getDocComment()) . "\n" . join(' ', Reflection::getModifierNames($method->getModifiers())) . ' function ' . ($method->returnsReference() ? '&' : '') . $method->name . '(' . join(', ', $this->getParameters($method->getParameters())) . ")\n" . "{\n" . $this->indent($body) . "\n" . "}\n";
     return $code;
 }
开发者ID:quickmobile,项目名称:go-aop-php,代码行数:13,代码来源:ClassProxy.php

示例10: GenerateOverridingMethodTemplate

 private function GenerateOverridingMethodTemplate(\ReflectionMethod $EntityMethod)
 {
     $MethodTemplate = self::OverriddenMethodTemplate;
     $Modifiers = \Reflection::getModifierNames($EntityMethod->getModifiers());
     $Modifiers[] = 'function';
     if ($EntityMethod->returnsReference()) {
         $Modifiers[] = '&';
     }
     $Modifiers = implode(' ', $Modifiers);
     $Name = $EntityMethod->getName();
     $Parameters = [];
     $ParameterVariables = [];
     foreach ($EntityMethod->getParameters() as $Parameter) {
         $ParameterVariables[] = '$' . $Parameter->getName();
         $Parameters[] = $this->GenerateMethodParameter($Parameter);
     }
     $Parameters = implode(', ', $Parameters);
     $ParameterVariables = implode(', ', $ParameterVariables);
     $MethodTemplate = str_replace('<Modifiers>', $Modifiers, $MethodTemplate);
     $MethodTemplate = str_replace('<Name>', $Name, $MethodTemplate);
     $MethodTemplate = str_replace('<Parameters>', $Parameters, $MethodTemplate);
     $MethodTemplate = str_replace('<ParameterVariables>', $ParameterVariables, $MethodTemplate);
     return $MethodTemplate;
 }
开发者ID:timetoogo,项目名称:penumbra,代码行数:24,代码来源:ConcreteProxyDataGenerator.php

示例11: buildMethod

    /**
     * Generates the string representation of a single method: signature, body.
     *
     * @param \ReflectionMethod $reflection_method
     *   A reflection method for the method.
     *
     * @return string
     */
    protected function buildMethod(\ReflectionMethod $reflection_method)
    {
        $parameters = [];
        foreach ($reflection_method->getParameters() as $parameter) {
            $parameters[] = $this->buildParameter($parameter);
        }
        $function_name = $reflection_method->getName();
        $reference = '';
        if ($reflection_method->returnsReference()) {
            $reference = '&';
        }
        $signature_line = <<<'EOS'
/**
 * {@inheritdoc}
 */

EOS;
        if ($reflection_method->isStatic()) {
            $signature_line .= 'public static function ' . $reference . $function_name . '(';
        } else {
            $signature_line .= 'public function ' . $reference . $function_name . '(';
        }
        $signature_line .= implode(', ', $parameters);
        $signature_line .= ')';
        $output = $signature_line . "\n{\n";
        $output .= $this->buildMethodBody($reflection_method);
        $output .= "\n" . '}';
        return $output;
    }
开发者ID:penguinclub,项目名称:penguinweb_drupal8,代码行数:37,代码来源:ProxyBuilder.php

示例12: 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

示例13: testProxyRespectsMethodsWhichReturnValuesByReference

 /**
  * Test that the proxy behaves in regard to methods like &foo() correctly
  */
 public function testProxyRespectsMethodsWhichReturnValuesByReference()
 {
     $proxy = $this->_proxyFactory->getProxy('Doctrine\\Tests\\Models\\Forum\\ForumEntry', null);
     $method = new \ReflectionMethod(get_class($proxy), 'getTopicByReference');
     $this->assertTrue($method->returnsReference());
 }
开发者ID:r1pp3rj4ck,项目名称:doctrine2,代码行数:9,代码来源:ProxyClassGeneratorTest.php

示例14: ucfirst

 /**
  * __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 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 = Nette\Utils\Callback::closure($_this, $name);
         }
         return $val;
     } else {
         // strict class
         $type = isset($methods['set' . $uname]) ? 'a write-only' : 'an undeclared';
         throw new MemberAccessException("Cannot read {$type} property {$class}::\${$name}.");
     }
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:41,代码来源:ObjectMixin.php

示例15: generateMockedMethodDefinitionFromExisting

 /**
  * @param string           $templateDir
  * @param ReflectionMethod $method
  * @param bool             $cloneArguments
  * @param bool             $callOriginalMethods
  *
  * @return string
  */
 private function generateMockedMethodDefinitionFromExisting($templateDir, ReflectionMethod $method, $cloneArguments, $callOriginalMethods)
 {
     if ($method->isPrivate()) {
         $modifier = 'private';
     } elseif ($method->isProtected()) {
         $modifier = 'protected';
     } else {
         $modifier = 'public';
     }
     if ($method->isStatic()) {
         $modifier .= ' static';
     }
     if ($method->returnsReference()) {
         $reference = '&';
     } else {
         $reference = '';
     }
     if ($this->hasReturnType($method)) {
         $returnType = (string) $method->getReturnType();
     } else {
         $returnType = '';
     }
     if (preg_match('#\\*[ \\t]*+@deprecated[ \\t]*+(.*?)\\r?+\\n[ \\t]*+\\*(?:[ \\t]*+@|/$)#s', $method->getDocComment(), $deprecation)) {
         $deprecation = trim(preg_replace('#[ \\t]*\\r?\\n[ \\t]*+\\*[ \\t]*+#', ' ', $deprecation[1]));
     } else {
         $deprecation = false;
     }
     return $this->generateMockedMethodDefinition($templateDir, $method->getDeclaringClass()->getName(), $method->getName(), $cloneArguments, $modifier, $this->getMethodParameters($method), $this->getMethodParameters($method, true), $returnType, $reference, $callOriginalMethods, $method->isStatic(), $deprecation);
 }
开发者ID:thekabal,项目名称:tki,代码行数:37,代码来源:Generator.php


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