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


PHP ClassNode::addMethod方法代码示例

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


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

示例1: apply

    /**
     * Apply Prophecy functionality to class node.
     *
     * @param ClassNode $node
     */
    public function apply(ClassNode $node)
    {
        $node->addInterface('Prophecy\\Prophecy\\ProphecySubjectInterface');
        $node->addProperty('objectProphecy', 'private');
        foreach ($node->getMethods() as $name => $method) {
            if ('__construct' === strtolower($name)) {
                continue;
            }
            $method->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());');
        }
        $prophecySetter = new MethodNode('setProphecy');
        $prophecyArgument = new ArgumentNode('prophecy');
        $prophecyArgument->setTypeHint('Prophecy\\Prophecy\\ProphecyInterface');
        $prophecySetter->addArgument($prophecyArgument);
        $prophecySetter->setCode('$this->objectProphecy = $prophecy;');
        $prophecyGetter = new MethodNode('getProphecy');
        $prophecyGetter->setCode('return $this->objectProphecy;');
        if ($node->hasMethod('__call')) {
            $__call = $node->getMethod('__call');
        } else {
            $__call = new MethodNode('__call');
            $__call->addArgument(new ArgumentNode('name'));
            $__call->addArgument(new ArgumentNode('arguments'));
            $node->addMethod($__call);
        }
        $__call->setCode(<<<PHP
throw new \\Prophecy\\Exception\\Doubler\\MethodNotFoundException(
    sprintf('Method `%s::%s()` not found.', get_class(\$this), func_get_arg(0)),
    \$this->getProphecy(), func_get_arg(0)
);
PHP
);
        $node->addMethod($prophecySetter);
        $node->addMethod($prophecyGetter);
    }
开发者ID:Ceciceciceci,项目名称:MySJSU-Class-Registration,代码行数:40,代码来源:ProphecySubjectPatch.php

示例2: MethodNode

 /**
  *
  * @param \Prophecy\Doubler\Generator\Node\ClassNode $node        	
  */
 function it_ignores_existing_methods($node)
 {
     $node->getParentClass()->willReturn('spec\\Prophecy\\Doubler\\ClassPatch\\MagicalApiExtended');
     $node->addMethod(new MethodNode('undefinedMethod'))->shouldBeCalled();
     $node->addMethod(new MethodNode('definedMethod'))->shouldNotBeCalled();
     $this->apply($node);
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:11,代码来源:MagicCallPatchSpec.php

示例3: apply

 /**
  * Forces class to implement Iterator interface.
  *
  * @param ClassNode $node
  */
 public function apply(ClassNode $node)
 {
     $node->addInterface('Iterator');
     $node->addMethod(new MethodNode('current'));
     $node->addMethod(new MethodNode('key'));
     $node->addMethod(new MethodNode('next'));
     $node->addMethod(new MethodNode('rewind'));
     $node->addMethod(new MethodNode('valid'));
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:14,代码来源:TraversablePatch.php

示例4:

 /**
  * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  */
 function it_adds_a_method_to_node_if_not_exists($node)
 {
     $node->hasMethod('__construct')->willReturn(false);
     $node->addMethod(Argument::any())->shouldBeCalled();
     $node->getParentClass()->shouldBeCalled();
     $this->apply($node);
 }
开发者ID:saj696,项目名称:pipe,代码行数:10,代码来源:SplFileInfoPatchSpec.php

示例5: MethodNode

 /**
  * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  */
 function it_discovers_api_using_phpdoc_from_extended_parent_interfaces($node)
 {
     $node->getParentClass()->willReturn('spec\\Prophecy\\Doubler\\ClassPatch\\MagicalApiImplementedExtended');
     $node->getInterfaces()->willReturn(array());
     $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
     $this->apply($node);
 }
开发者ID:phpspec,项目名称:prophecy,代码行数:10,代码来源:MagicCallPatchSpec.php

示例6:

 /**
  * @param \Prophecy\Doubler\Generator\Node\ClassNode  $node
  * @param \Prophecy\Doubler\Generator\Node\MethodNode $constructor
  * @param \Prophecy\Doubler\Generator\Node\MethodNode $method1
  * @param \Prophecy\Doubler\Generator\Node\MethodNode $method2
  * @param \Prophecy\Doubler\Generator\Node\MethodNode $method3
  */
 function it_forces_all_class_methods_except_constructor_to_proxy_calls_into_prophecy_makeCall($node, $constructor, $method1, $method2, $method3)
 {
     $node->addInterface('Prophecy\\Prophecy\\ProphecySubjectInterface')->willReturn(NULL);
     $node->addProperty('objectProphecy', 'private')->willReturn(NULL);
     $node->hasMethod(Argument::any())->willReturn(FALSE);
     $node->addMethod(Argument::type('Prophecy\\Doubler\\Generator\\Node\\MethodNode'))->willReturn(NULL);
     $node->addMethod(Argument::type('Prophecy\\Doubler\\Generator\\Node\\MethodNode'))->willReturn(NULL);
     $constructor->getName()->willReturn('__construct');
     $method1->getName()->willReturn('method1');
     $method2->getName()->willReturn('method2');
     $method3->getName()->willReturn('method3');
     $node->getMethods()->willReturn(array('method1' => $method1, 'method2' => $method2, 'method3' => $method3));
     $constructor->setCode(Argument::any())->shouldNotBeCalled();
     $method1->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')->shouldBeCalled();
     $method2->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')->shouldBeCalled();
     $method3->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')->shouldBeCalled();
     $this->apply($node);
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:25,代码来源:ProphecySubjectPatchSpec.php

示例7: apply

 /**
  * Updated constructor code to call parent one with dummy file argument.
  *
  * @param ClassNode $node
  */
 public function apply(ClassNode $node)
 {
     if ($node->hasMethod('__construct')) {
         $constructor = $node->getMethod('__construct');
     } else {
         $constructor = new MethodNode('__construct');
         $node->addMethod($constructor);
     }
     $constructor->setCode('return parent::__construct("' . __FILE__ . '");');
 }
开发者ID:burimshala,项目名称:numbertowords,代码行数:15,代码来源:SplFileInfoPatch.php

示例8: apply

 /**
  * Discover Magical API
  *
  * @param ClassNode $node
  */
 public function apply(ClassNode $node)
 {
     $parentClass = $node->getParentClass();
     $reflectionClass = new \ReflectionClass($parentClass);
     $phpdoc = new DocBlock($reflectionClass->getDocComment());
     $tagList = $phpdoc->getTagsByName('method');
     foreach ($tagList as $tag) {
         $methodNode = new MethodNode($tag->getMethodName());
         $methodNode->setStatic($tag->isStatic());
         $node->addMethod($methodNode);
     }
 }
开发者ID:mawaha,项目名称:tracker,代码行数:17,代码来源:MagicCallPatch.php

示例9: apply

 /**
  * Updated constructor code to call parent one with dummy file argument.
  *
  * @param ClassNode $node
  */
 public function apply(ClassNode $node)
 {
     if ($node->hasMethod('__construct')) {
         $constructor = $node->getMethod('__construct');
     } else {
         $constructor = new MethodNode('__construct');
         $node->addMethod($constructor);
     }
     if ($this->nodeIsDirectoryIterator($node)) {
         $constructor->setCode('return parent::__construct("' . __DIR__ . '");');
         return;
     }
     $constructor->useParentCode();
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:19,代码来源:SplFileInfoPatch.php

示例10: apply

 /**
  * Discover Magical API
  *
  * @param ClassNode $node
  */
 public function apply(ClassNode $node)
 {
     $parentClass = $node->getParentClass();
     $reflectionClass = new \ReflectionClass($parentClass);
     $tagList = $this->tagRetriever->getTagList($reflectionClass);
     foreach ($tagList as $tag) {
         $methodName = $tag->getMethodName();
         if (empty($methodName)) {
             continue;
         }
         if (!$reflectionClass->hasMethod($methodName)) {
             $methodNode = new MethodNode($methodName);
             $methodNode->setStatic($tag->isStatic());
             $node->addMethod($methodNode);
         }
     }
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:22,代码来源:MagicCallPatch.php

示例11: apply

    /**
     * Makes all class constructor arguments optional.
     *
     * @param ClassNode $node
     */
    public function apply(ClassNode $node)
    {
        if (!$node->hasMethod('__construct')) {
            $node->addMethod(new MethodNode('__construct', ''));
            return;
        }
        $constructor = $node->getMethod('__construct');
        foreach ($constructor->getArguments() as $argument) {
            $argument->setDefault(null);
        }
        $constructor->setCode(<<<PHP
if (0 < func_num_args()) {
    call_user_func_array(array('parent', '__construct'), func_get_args());
}
PHP
);
    }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:22,代码来源:DisableConstructorPatch.php

示例12: apply

 /**
  * Discover Magical API
  *
  * @param ClassNode $node
  */
 public function apply(ClassNode $node)
 {
     $parentClass = $node->getParentClass();
     $reflectionClass = new \ReflectionClass($parentClass);
     $phpdoc = new DocBlock($reflectionClass->getDocComment());
     $tagList = $phpdoc->getTagsByName('method');
     $interfaces = $reflectionClass->getInterfaces();
     foreach ($interfaces as $interface) {
         $phpdoc = new DocBlock($interface);
         $tagList = array_merge($tagList, $phpdoc->getTagsByName('method'));
     }
     foreach ($tagList as $tag) {
         $methodName = $tag->getMethodName();
         if (!$reflectionClass->hasMethod($methodName)) {
             $methodNode = new MethodNode($tag->getMethodName());
             $methodNode->setStatic($tag->isStatic());
             $node->addMethod($methodNode);
         }
     }
 }
开发者ID:phantsang,项目名称:8csfOIjOaJSlDG2Y3x992O,代码行数:25,代码来源:MagicCallPatch.php

示例13: apply

 /**
  * Discover Magical API
  *
  * @param ClassNode $node
  */
 public function apply(ClassNode $node)
 {
     $types = array_filter($node->getInterfaces(), function ($interface) {
         return 0 !== strpos($interface, 'Prophecy\\');
     });
     $types[] = $node->getParentClass();
     foreach ($types as $type) {
         $reflectionClass = new \ReflectionClass($type);
         $tagList = $this->tagRetriever->getTagList($reflectionClass);
         foreach ($tagList as $tag) {
             $methodName = $tag->getMethodName();
             if (empty($methodName)) {
                 continue;
             }
             if (!$reflectionClass->hasMethod($methodName)) {
                 $methodNode = new MethodNode($methodName);
                 $methodNode->setStatic($tag->isStatic());
                 $node->addMethod($methodNode);
             }
         }
     }
 }
开发者ID:phpspec,项目名称:prophecy,代码行数:27,代码来源:MagicCallPatch.php

示例14:

 /**
  * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  */
 function it_forces_node_to_implement_IteratorAggregate($node)
 {
     $node->addInterface('Iterator')->shouldBeCalled();
     $node->addMethod(Argument::type('Prophecy\\Doubler\\Generator\\Node\\MethodNode'))->willReturn(null);
     $this->apply($node);
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:9,代码来源:TraversablePatchSpec.php

示例15: reflectMethodToNode

 private function reflectMethodToNode(ReflectionMethod $method, Node\ClassNode $classNode)
 {
     $node = new Node\MethodNode($method->getName());
     if (true === $method->isProtected()) {
         $node->setVisibility('protected');
     }
     if (true === $method->isStatic()) {
         $node->setStatic();
     }
     if (is_array($params = $method->getParameters()) && count($params)) {
         foreach ($params as $param) {
             $this->reflectArgumentToNode($param, $node);
         }
     }
     $classNode->addMethod($node);
 }
开发者ID:jamilalidrus,项目名称:Jamil,代码行数:16,代码来源:ClassMirror.php


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