當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Generator\MethodGenerator類代碼示例

本文整理匯總了PHP中Zend\Code\Generator\MethodGenerator的典型用法代碼示例。如果您正苦於以下問題:PHP MethodGenerator類的具體用法?PHP MethodGenerator怎麽用?PHP MethodGenerator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MethodGenerator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * Constructor
  *
  * @param PropertyGenerator   $initializerProperty
  * @param ZendMethodGenerator $callInitializer
  */
 public function __construct(PropertyGenerator $initializerProperty, ZendMethodGenerator $callInitializer)
 {
     parent::__construct('initializeProxy');
     $this->setDocblock('{@inheritDoc}');
     $this->setReturnType('bool');
     $this->setBody('return $this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() . '(\'initializeProxy\', []);');
 }
開發者ID:jbafford,項目名稱:ProxyManager,代碼行數:13,代碼來源:InitializeProxy.php

示例2: build

    /**
     * @param  State|\Scaffold\State $state
     * @return State|void
     */
    public function build(State $state)
    {
        $model = $state->getModel('options-factory');
        $generator = new ClassGenerator($model->getName());
        $generator->setImplementedInterfaces(['FactoryInterface']);
        $model->setGenerator($generator);
        $generator->addUse('Zend\\ServiceManager\\FactoryInterface');
        $generator->addUse('Zend\\ServiceManager\\ServiceLocatorInterface');
        $options = $state->getModel('options');
        $key = $options->getServiceName();
        $key = substr($key, 0, -7);
        $body = <<<EOF
\$config = \$serviceLocator->get('Config');
return new {$options->getClassName()}(
    isset(\$config['{$key}'])
        ? \$config['{$key}']
        : []
);
EOF;
        $method = new MethodGenerator('createService');
        $method->setParameter(new ParameterGenerator('serviceLocator', 'ServiceLocatorInterface'));
        $method->setBody($body);
        $doc = new DocBlockGenerator('');
        $doc->setTag(new Tag(['name' => 'inhertidoc']));
        $method->setDocBlock($doc);
        $generator->addMethodFromGenerator($method);
    }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:31,代碼來源:OptionsFactoryBuilder.php

示例3: addToString

    public function addToString()
    {
        $classGenerator = $this->getClassGenerator();
        $methodGenerator = new CodeGenerator\MethodGenerator();
        $methodGenerator->setName('__toString');
        $idAttribute = 'id';
        $body = <<<METHODBODY
\$attributes = array(\$this->{$idAttribute});

METHODBODY;
        foreach (static::$secondaryProperties as $attributeName => $propertyName) {
            $body .= <<<METHODBODY
if (!empty(\$this->{$propertyName})) {
    \$attributes[] = "{$attributeName}={\$this->{$propertyName}}";
}

METHODBODY;
        }
        $body .= <<<METHODBODY
foreach (\$this->attributes as \$attributeName => \$value) {
    if (!empty(\$value)) {
        \$attributes[] = "{\$attributeName}={\$value}";
    }
}
return implode('!', \$attributes);
METHODBODY;
        $methodGenerator->setBody($body);
        $classGenerator->addMethodFromGenerator($methodGenerator);
    }
開發者ID:vmalinovskiy,項目名稱:CallFire-PHP-SDK,代碼行數:29,代碼來源:Contact.php

示例4: getConstructor

 protected function getConstructor()
 {
     $defaultValue = new ValueGenerator([], ValueGenerator::TYPE_ARRAY);
     $setterParam = new ParameterGenerator('properties', 'array', $defaultValue);
     $methodGenerator = new MethodGenerator('__construct', [$setterParam]);
     $methodGenerator->setBody('$this->properties = $properties;');
     return $methodGenerator;
 }
開發者ID:cyberrebell,項目名稱:arango-odm,代碼行數:8,代碼來源:DocumentGenerator.php

示例5: addMethodIfNotFinal

 /**
  * @param ReflectionClass  $originalClass
  * @param ClassGenerator   $classGenerator
  * @param MethodGenerator  $generatedMethod
  *
  * @return void|false
  */
 public static function addMethodIfNotFinal(ReflectionClass $originalClass, ClassGenerator $classGenerator, MethodGenerator $generatedMethod)
 {
     $methodName = $generatedMethod->getName();
     if ($originalClass->hasMethod($methodName) && $originalClass->getMethod($methodName)->isFinal()) {
         return false;
     }
     $classGenerator->addMethodFromGenerator($generatedMethod);
 }
開發者ID:John-Eddy,項目名稱:ProjetCastor,代碼行數:15,代碼來源:ClassGeneratorUtils.php

示例6: buildFactory

 /**
  * Build method factory
  *
  * @param ClassGenerator $generator
  */
 public function buildFactory(ClassGenerator $generator)
 {
     $docBlock = new DocBlockGenerator('@return ' . $this->config->getName());
     $factory = new MethodGenerator();
     $factory->setDocBlock($docBlock);
     $factory->setName('factory');
     $factory->setBody('return new ' . $this->config->getName() . '();');
     $generator->addMethodFromGenerator($factory);
 }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:14,代碼來源:RepositoryBuilder.php

示例7: setUp

 /**
  * {@inheritDoc}
  */
 protected function setUp()
 {
     $this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
     $this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
     $this->publicProperties = $this->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')->disableOriginalConstructor()->getMock();
     $this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz'));
     $this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
     $this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
 }
開發者ID:Clon450,項目名稱:batata,代碼行數:13,代碼來源:MagicGetTest.php

示例8: addMethod

 /**
  * @param string $name
  * @param Code $code
  * @return PhpMethod
  */
 public function addMethod($name, Code $code)
 {
     $this->code[$name] = $code;
     $method = new MethodGenerator();
     $method->setName($name);
     $method->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
     // $code remains object until turning to string
     $method->setBody($code);
     $this->addMethodFromGenerator($method);
     return $method;
 }
開發者ID:nfx,項目名稱:pugooroo,代碼行數:16,代碼來源:PhpClass.php

示例9: addTestIdMethod

    public function addTestIdMethod(ClassGenerator $generator, State $state)
    {
        $method = new MethodGenerator('testGetSetId');
        $class = $state->getEntityModel()->getClassName();
        $code = <<<EOF
\$object = new {$class}();
\$object->setId(123);
\$this->assertEquals(123, \$object->getId());
EOF;
        $method->setBody($code);
        $generator->addMethodFromGenerator($method);
    }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:12,代碼來源:EntityTestBuilder.php

示例10: addInitMethod

 /**
  * Generate an init method
  */
 protected function addInitMethod()
 {
     // set action body
     $body = ['// add form elements and form configuration here'];
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('init');
     $method->setBody($body);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Generate form by adding elements'));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:pgiacometto,項目名稱:zf2rapid,代碼行數:19,代碼來源:FormClassGenerator.php

示例11: generateClearMethod

 /**
  * @param \Protobuf\Compiler\Entity $entity
  *
  * @return \Zend\Code\Generator\GeneratorInterface
  */
 protected function generateClearMethod(Entity $entity)
 {
     $lines = $this->generateBody($entity);
     $body = implode(PHP_EOL, $lines);
     $method = MethodGenerator::fromArray(['name' => 'clear', 'body' => $body, 'docblock' => ['shortDescription' => "{@inheritdoc}"]]);
     return $method;
 }
開發者ID:protobuf-php,項目名稱:protobuf-plugin,代碼行數:12,代碼來源:ClearGenerator.php

示例12: generateMethod

 /**
  * @param \Protobuf\Compiler\Entity $entity
  *
  * @return string
  */
 protected function generateMethod(Entity $entity)
 {
     $lines = $this->generateBody($entity);
     $body = implode(PHP_EOL, $lines);
     $method = MethodGenerator::fromArray(['name' => 'fromArray', 'body' => $body, 'static' => true, 'parameters' => [['name' => 'values', 'type' => 'array']], 'docblock' => ['shortDescription' => "{@inheritdoc}"]]);
     return $method;
 }
開發者ID:protobuf-php,項目名稱:protobuf-plugin,代碼行數:12,代碼來源:FromArrayGenerator.php

示例13: generateConstructorMethod

 /**
  * @param \Protobuf\Compiler\Entity $entity
  *
  * @return \Zend\Code\Generator\GeneratorInterface
  */
 protected function generateConstructorMethod(Entity $entity)
 {
     $lines = $this->generateBody($entity);
     $body = implode(PHP_EOL, $lines);
     $method = MethodGenerator::fromArray(['name' => '__construct', 'body' => $body, 'parameters' => [['name' => 'stream', 'type' => 'mixed', 'defaultValue' => null], ['name' => 'configuration', 'type' => '\\Protobuf\\Configuration', 'defaultValue' => null]], 'docblock' => ['shortDescription' => '{@inheritdoc}']]);
     return $method;
 }
開發者ID:protobuf-php,項目名稱:protobuf-plugin,代碼行數:12,代碼來源:ConstructGenerator.php

示例14: fromReflection

 /**
  * Build a Code Generation Php Object from a Class Reflection
  *
  * @param  ClassReflection $classReflection
  * @return TraitGenerator
  */
 public static function fromReflection(ClassReflection $classReflection)
 {
     // class generator
     $cg = new static($classReflection->getName());
     $cg->setSourceContent($cg->getSourceContent());
     $cg->setSourceDirty(false);
     if ($classReflection->getDocComment() != '') {
         $cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock()));
     }
     // set the namespace
     if ($classReflection->inNamespace()) {
         $cg->setNamespaceName($classReflection->getNamespaceName());
     }
     $properties = array();
     foreach ($classReflection->getProperties() as $reflectionProperty) {
         if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
             $properties[] = PropertyGenerator::fromReflection($reflectionProperty);
         }
     }
     $cg->addProperties($properties);
     $methods = array();
     foreach ($classReflection->getMethods() as $reflectionMethod) {
         $className = $cg->getNamespaceName() ? $cg->getNamespaceName() . '\\' . $cg->getName() : $cg->getName();
         if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
             $methods[] = MethodGenerator::fromReflection($reflectionMethod);
         }
     }
     $cg->addMethods($methods);
     return $cg;
 }
開發者ID:Flesh192,項目名稱:magento,代碼行數:36,代碼來源:TraitGenerator.php

示例15: addInitMethod

 /**
  * Generate an init method
  */
 protected function addInitMethod()
 {
     // set action body
     $body = array('// add input objects here');
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('init');
     $method->setBody($body);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Generate input filter by adding inputs'));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:nomaanp,項目名稱:zf2rapid,代碼行數:19,代碼來源:InputFilterClassGenerator.php


注:本文中的Zend\Code\Generator\MethodGenerator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。