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


PHP MethodGenerator::setName方法代碼示例

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


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

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

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

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

示例4: buildFactory

 /**
  * Build method factory
  *
  * @param ClassGenerator  $generator
  * @param \Scaffold\State $state
  */
 public function buildFactory(ClassGenerator $generator, State $state)
 {
     $repository = ucfirst($state->getRepositoryModel()->getClassName());
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new Tag\GenericTag('return', $this->config->getName()));
     $factory = new MethodGenerator();
     $factory->setDocBlock($docBlock);
     $factory->setName('factory');
     $factory->setBody('return $this->get' . $repository . '()->factory();');
     $generator->addMethodFromGenerator($factory);
 }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:17,代碼來源:ServiceBuilder.php

示例5: postRun

    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $table = $part->getTable();
        $tags = array(array('name' => 'return', 'description' => 'array'));
        $docblock = new DocBlockGenerator('Initialize indexes');
        $docblock->setTags($tags);
        $resultIndexList = array();
        $indexList = $table->getIndex();
        foreach ($indexList as $index) {
            $resIndex = $index->toArray();
            $resIndex['column_list'] = array();
            switch ($index->getType()) {
                case AbstractIndex::TYPE_PRIMARY:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_PRIMARY', ValueGenerator::TYPE_CONSTANT);
                    break;
                case AbstractIndex::TYPE_KEY:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_KEY', ValueGenerator::TYPE_CONSTANT);
                    break;
                case AbstractIndex::TYPE_UNIQUE:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_UNIQUE', ValueGenerator::TYPE_CONSTANT);
                    break;
            }
            foreach ($resIndex['columns'] as $col) {
                $resIndex['column_list'][] = $col['column_name'];
            }
            unset($resIndex['columns']);
            $resultIndexList[$index->getName()] = $resIndex;
        }
        $property = new PropertyGenerator('indexList', $resultIndexList, PropertyGenerator::FLAG_PROTECTED);
        $body = preg_replace("#^(\\s*)protected #", "\\1", $property->generate()) . "\n";
        $method = new MethodGenerator();
        $method->setName('initIndexList');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
{$body}
\$this->indexList = \$indexList;
\$this->setupIndexList();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
開發者ID:meniam,項目名稱:model,代碼行數:50,代碼來源:IndexList.php

示例6: addInvokeMethod

 /**
  * Generate an __invoke method
  */
 protected function addInvokeMethod()
 {
     // set action body
     $body = ['// add view helper code here', '$output = \'\';', '', 'return $output;'];
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('__invoke');
     $method->setBody($body);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Called when view helper is executed', null, [new ReturnTag(['string'])]));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:zfrapid,項目名稱:zf2rapid,代碼行數:19,代碼來源:ViewHelperClassGenerator.php

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

示例8: addInvokeMethod

 /**
  * Generate an __invoke method
  */
 protected function addInvokeMethod()
 {
     // set action body
     $body = ['// add controller plugin code here'];
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('__invoke');
     $method->setBody($body);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Called when controller plugin is executed', null, [new ReturnTag(['mixed'])]));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:zfrapid,項目名稱:zf2rapid,代碼行數:19,代碼來源:ControllerPluginClassGenerator.php

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

示例10: postRun

    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $table = $part->getTable();
        $tags = array(array('name' => 'var', 'description' => 'array значения по-умолчанию для полей'));
        $docblock = new \Zend\Code\Generator\DocBlockGenerator('Значения по-умолчанию для полей');
        $docblock->setTags($tags);
        $columnCollection = $table->getColumn();
        if (!$columnCollection) {
            return;
        }
        $defaults = '';
        /** @var $column Column */
        foreach ($columnCollection as $column) {
            $columnName = $column->getName();
            $defaultValue = $column->getColumnDefault();
            if (substr($columnName, -5) == '_date') {
                $defaults .= "\$this->setDefaultRule('" . $columnName . "', date('Y-m-d H:i:s'));\n    ";
            } elseif ($defaultValue == 'CURRENT_TIMESTAMP') {
                $defaults .= "\$this->setDefaultRule('" . $columnName . "', date('Y-m-d H:i:s'));\n    ";
            } elseif (!empty($defaultValue)) {
                $defaults .= '$this->setDefaultRule(\'' . $columnName . '\', \'' . (string) $defaultValue . '\');' . "\n    ";
            } elseif (is_null($defaultValue) && $column->isNullable()) {
                $defaults .= '$this->setDefaultRule(\'' . $columnName . '\', null);' . "\n    ";
            }
        }
        $tags = array(array('name' => 'return', 'description' => 'void'));
        $docblock = new DocBlockGenerator('Инициализация значений по-умолчанию');
        $docblock->setTags($tags);
        $method = new MethodGenerator();
        $method->setName('initDefaultsRules');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
    {$defaults}
\$this->setupDefaultsRules();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
開發者ID:meniam,項目名稱:model,代碼行數:47,代碼來源:InitDefaults.php

示例11: addFilterMethod

 /**
  * Generate a filter method
  */
 protected function addFilterMethod()
 {
     // set action body
     $body = ['// add filter code here', 'return $value;'];
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('filter');
     $method->setBody($body);
     $method->setParameters([new ParameterGenerator('value', 'mixed')]);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Called when filter is executed', null, [new ParamTag('value', ['mixed']), new ReturnTag(['mixed'])]));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:zfrapid,項目名稱:zf2rapid,代碼行數:20,代碼來源:FilterClassGenerator.php

示例12: addCreateServiceMethod

 /**
  * Generate the create service method
  *
  * @param string $className
  * @param string $managerName
  */
 protected function addCreateServiceMethod($className, $managerName)
 {
     // set action body
     $body = array('/** @var ServiceLocatorAwareInterface $' . $managerName . ' */', '$serviceLocator = $' . $managerName . '->getServiceLocator();', '', '$instance = new ' . $className . '();', '', 'return $instance;');
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('createService');
     $method->setBody($body);
     $method->setParameters(array(new ParameterGenerator($managerName, 'ServiceLocatorInterface')));
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Create service', null, array(new ParamTag($managerName, array('ServiceLocatorInterface')), new ReturnTag(array($className)))));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:nomaanp,項目名稱:zf2rapid,代碼行數:23,代碼來源:FactoryGenerator.php

示例13: addIsValidMethod

 /**
  * Generate a isValid method
  */
 protected function addIsValidMethod()
 {
     // set action body
     $body = ['$this->setValue((string) $value);', '', '// add validation code here', '$isValid = true;', '', 'if (!$isValid) {', '    $this->error(self::INVALID);', '    return false;', '}', '', 'return true;'];
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('isValid');
     $method->setBody($body);
     $method->setParameters([new ParameterGenerator('value', 'mixed')]);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Called when validator is executed', null, [new ParamTag('value', ['mixed']), new ReturnTag(['mixed'])]));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:zfrapid,項目名稱:zf2rapid,代碼行數:20,代碼來源:ValidatorClassGenerator.php

示例14: addCreateServiceMethod

 /**
  * Generate the create service method
  *
  * @param string $className
  * @param string $moduleName
  * @param string $tableName
  */
 protected function addCreateServiceMethod($className, $moduleName, $tableName)
 {
     $managerName = 'serviceLocator';
     $tableGatewayName = ucfirst($tableName) . 'TableGateway';
     $tableGatewayService = $moduleName . '\\' . $this->config['namespaceTableGateway'] . '\\' . ucfirst($tableName);
     // set action body
     $body = ['/** @var ' . $tableGatewayName . ' $tableGateway */', '$tableGateway = $serviceLocator->get(\'' . $tableGatewayService . '\');', '', '$instance = new ' . $className . '($tableGateway);', '', 'return $instance;'];
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // create method
     $method = new MethodGenerator();
     $method->setName('createService');
     $method->setBody($body);
     $method->setParameters([new ParameterGenerator($managerName, 'ServiceLocatorInterface')]);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Create service', null, [new ParamTag($managerName, ['ServiceLocatorInterface']), new ReturnTag([$className])]));
     }
     // add method
     $this->addMethodFromGenerator($method);
 }
開發者ID:pgiacometto,項目名稱:zf2rapid,代碼行數:27,代碼來源:RepositoryFactoryGenerator.php

示例15: transform

 public function transform()
 {
     $classGenerator = $this->getService()->getClassGenerator();
     if ($createContactBatch = $classGenerator->getMethod('CreateContactBatch')) {
         $newMethod = new CodeGenerator\MethodGenerator();
         $newMethod->setName($createContactBatch->getName());
         $docblock = $createContactBatch->getDocBlock();
         $docblock->setTag((new CodeGenerator\DocBlock\Tag\ParamTag())->setParamName('id')->setDataType('int'));
         $newMethod->setDocBlock($docblock);
         $parameters = $createContactBatch->getParameters();
         $idParameter = new CodeGenerator\ParameterGenerator();
         $idParameter->setName('id');
         $createContactBatch->setParameter($idParameter);
         $newMethod->setParameters(array("id" => $idParameter, "CreateContactBatch" => $parameters['CreateContactBatch']));
         $body = $createContactBatch->getBody();
         $body = str_replace('array()', 'array($id)', $body);
         $newMethod->setBody($body);
         $classGenerator->removeMethod('CreateContactBatch');
         $classGenerator->addMethodFromGenerator($newMethod);
     }
 }
開發者ID:vmalinovskiy,項目名稱:CallFire-PHP-SDK,代碼行數:21,代碼來源:Broadcast.php


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