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


PHP MethodGenerator::setParameter方法代碼示例

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


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

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

示例2: buildCreateService

    public function buildCreateService(ClassGenerator $generator, State $state)
    {
        $method = new MethodGenerator('createService');
        $method->setDocBlock(new DocBlockGenerator());
        $method->getDocBlock()->setShortDescription('{@inheritdoc}');
        $method->setParameter(new ParameterGenerator('serviceLocator', 'ServiceLocatorInterface'));
        $name = lcfirst($state->getEntityModel()->getClassName());
        $entity = $state->getEntityModel()->getName();
        $method->setBody(<<<EOF
            \$form = new Form('{$name}');

\$submit = new Element\\Submit('submit');
\$submit->setValue('Submit');
\$form->add(\$submit);

\$form->setInputFilter(\$this->getInputFilter());

/** @var EntityManager \$entityManager */
\$entityManager = \$serviceLocator->get('entity_manager');
\$form->setHydrator(new DoctrineObject(\$entityManager, '{$entity}'));

return \$form;
EOF
);
        $generator->addMethodFromGenerator($method);
    }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:26,代碼來源:FormFactoryBuilder.php

示例3: build

 /**
  * Build generators
  *
  * @param  State|\Scaffold\State $state
  * @return \Scaffold\State|void
  */
 public function build(State $state)
 {
     $model = $this->model;
     $generator = new ClassGenerator($model->getName());
     $generator->addUse('Zend\\ServiceManager\\FactoryInterface');
     $generator->addUse('Zend\\ServiceManager\\ServiceLocatorInterface');
     $generator->addUse('Zend\\ServiceManager\\ServiceManager');
     $generator->addUse($state->getServiceModel()->getName());
     $generator->setImplementedInterfaces(['FactoryInterface']);
     $method = new MethodGenerator('createService');
     $method->setParameter(new ParameterGenerator('serviceLocator', 'ServiceLocatorInterface'));
     $method->setBody('return new ' . $state->getServiceModel()->getClassName() . '($serviceLocator);');
     $doc = new DocBlockGenerator('Create service');
     $doc->setTag(new Tag\GenericTag('param', 'ServiceLocatorInterface|ServiceManager $serviceLocator'));
     $doc->setTag(new Tag\GenericTag('return', $state->getServiceModel()->getClassName()));
     $method->setDocBlock($doc);
     $generator->addMethodFromGenerator($method);
     $model->setGenerator($generator);
 }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:25,代碼來源:ServiceFactoryBuilder.php

示例4: fixPathParameters

 public function fixPathParameters($classGenerator, $method, $newParameters)
 {
     $oldMethod = $classGenerator->getMethod($method);
     $newMethod = new CodeGenerator\MethodGenerator();
     $newMethod->setName($oldMethod->getName());
     $docblock = $oldMethod->getDocBlock();
     $parameters = $oldMethod->getParameters();
     $body = $oldMethod->getBody();
     $newParameterSpec = array();
     foreach ($newParameters as $name => $type) {
         $docblock->setTag((new CodeGenerator\DocBlock\Tag\ParamTag())->setParamName($name)->setDataType($type));
         $newParameter = new CodeGenerator\ParameterGenerator();
         $newParameter->setName($name);
         $newMethod->setParameter($newParameter);
         $newParameterSpec[$name] = $newParameter;
     }
     $newMethod->setParameters(array_merge($newParameterSpec, array($method => $parameters[$method])));
     $body = str_replace('array()', 'array($' . implode(', $', array_keys($newParameters)) . ')', $body);
     $newMethod->setDocBlock($docblock);
     $newMethod->setBody($body);
     $classGenerator->removeMethod($method);
     $classGenerator->addMethodFromGenerator($newMethod);
 }
開發者ID:vmalinovskiy,項目名稱:CallFire-PHP-SDK,代碼行數:23,代碼來源:AbstractTransform.php

示例5: addInitMethod

 /**
  * Generate the init() method
  */
 protected function addInitMethod()
 {
     // set action body
     $bodyContent = ['if (!defined(\'' . $this->moduleRootConstant . '\')) {', '    define(\'' . $this->moduleRootConstant . '\', realpath(__DIR__));', '}'];
     $bodyContent = implode(AbstractGenerator::LINE_FEED, $bodyContent);
     // create method body
     $body = new BodyGenerator();
     $body->setContent($bodyContent);
     // create method
     $method = new MethodGenerator();
     $method->setName('init');
     $method->setBody($body->generate());
     $method->setParameter(new ParameterGenerator('manager', 'ModuleManagerInterface'));
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Init module', 'Initialize module on loading', [new ParamTag('manager', ['ModuleManagerInterface'])]));
     }
     // add method
     $this->addMethodFromGenerator($method);
     $this->addUse('Zend\\ModuleManager\\Feature\\InitProviderInterface');
     $this->addUse('Zend\\ModuleManager\\ModuleManagerInterface');
     $this->setImplementedInterfaces(array_merge($this->getImplementedInterfaces(), ['InitProviderInterface']));
 }
開發者ID:pgiacometto,項目名稱:zf2rapid,代碼行數:26,代碼來源:ModuleClassGenerator.php

示例6: addOptionsSetter

 /**
  * @param string           $columnName
  * @param ConstraintObject $foreignKey
  */
 protected function addOptionsSetter($columnName, ConstraintObject $foreignKey)
 {
     $body = '$this->' . $columnName . 'Options = $' . $columnName . 'Options;';
     $parameter = new ParameterGenerator($columnName . 'Options', 'array');
     $setMethodName = 'set' . ucfirst($columnName) . 'Options';
     $setMethod = new MethodGenerator($setMethodName);
     $setMethod->addFlag(MethodGenerator::FLAG_PUBLIC);
     $setMethod->setParameter($parameter);
     $setMethod->setDocBlock(new DocBlockGenerator('Set ' . $columnName . ' options', null, [['name' => 'param', 'description' => 'array $' . $columnName . 'Options']]));
     $setMethod->setBody($body);
     $this->addMethodFromGenerator($setMethod);
 }
開發者ID:pgiacometto,項目名稱:zf2rapid,代碼行數:16,代碼來源:InputFilterClassGenerator.php

示例7: buildDelete

 protected function buildDelete(ClassGenerator $generator, State $state)
 {
     $body = '$this->getEntityManager()->remove($model);';
     $method = new MethodGenerator('delete');
     $method->setParameter(new ParameterGenerator('model', $state->getEntityModel()->getClassName()));
     $method->setDocBlock(new DocBlockGenerator());
     $method->getDocBlock()->setTag(new Tag\GenericTag('param', $state->getEntityModel()->getClassName() . ' $model'));
     $method->setBody($body);
     $generator->addMethodFromGenerator($method);
 }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:10,代碼來源:ServiceBuilder.php

示例8: generateCreateServiceMethod

 /**
  * @param $objectClass
  * @param $serviceManagerClass
  *
  * @return MethodGenerator
  */
 protected function generateCreateServiceMethod($objectClass, $serviceManagerClass, $instanceName)
 {
     // init body
     $methodBody = array();
     // add service locator if needed
     if ($serviceManagerClass !== 'serviceLocator') {
         $methodBody[] = '// get service locator to fetch other services';
         $methodBody[] = '$serviceLocator = $' . $serviceManagerClass . '->getServiceLocator();';
         $methodBody[] = '';
     }
     // add class instantiation
     $methodBody[] = '// get all services that need to be injected';
     $methodBody[] = ';';
     $methodBody[] = '';
     $methodBody[] = '// instantiate class';
     $methodBody[] = '$' . $instanceName . ' = new ' . $objectClass . '();';
     $methodBody[] = '';
     $methodBody[] = '// inject all services ';
     $methodBody[] = ';';
     $methodBody[] = '';
     $methodBody[] = '// return instance of class';
     $methodBody[] = 'return $' . $instanceName . ';';
     // create method
     $method = new MethodGenerator();
     $method->setName('createService');
     $method->setParameter(new ParameterGenerator($serviceManagerClass, 'ServiceLocatorInterface'));
     $method->setBody(implode(AbstractGenerator::LINE_FEED, $methodBody));
     // add optional doc block
     if ($this->flagCreateApiDocs) {
         $method->setDocBlock(new DocBlockGenerator('Create service', 'Please add a proper description for this method', array($this->generateParamTag('ServiceLocatorInterface $' . $serviceManagerClass), $this->generateReturnTag($objectClass))));
     }
     return $method;
 }
開發者ID:ralfeggert,項目名稱:zftool,代碼行數:39,代碼來源:ModuleGenerator.php

示例9: buildClass

 private function buildClass($replacement)
 {
     $type = $this->splitNsandClass($replacement['originalFullyQualifiedType']);
     $class = new ClassGenerator();
     $class->setName($type['class']);
     $class->setNamespaceName($type['ns']);
     $class->setExtendedClass('\\Brads\\Ppm\\Proxy');
     $properties = [];
     $methods = [];
     $implementedInterfaces = [];
     foreach ($versions as $version => $info) {
         foreach ($info['files'] as $file) {
             echo "Parsing: " . $this->vendorDir . '/' . $package . '/' . $version . '/' . $file . "\n";
             $parsedFile = new ReflectionFile($this->vendorDir . '/' . $package . '/' . $version . '/' . $file);
             $parsedClass = $parsedFile->getFileNamespace($info['toNs'])->getClass($info['toNs'] . '\\' . $type['class']);
             if ($parsedClass->getInterfaceNames() != null) {
                 $implementedInterfaces = array_merge($implementedInterfaces, $parsedClass->getInterfaceNames());
             }
             foreach ($parsedClass->getMethods() as $method) {
                 if ($method->isPublic()) {
                     $generatedMethod = new MethodGenerator();
                     $generatedMethod->setName($method->name);
                     $generatedMethod->setBody('echo "Hello world!";');
                     $generatedMethod->setAbstract($method->isAbstract());
                     $generatedMethod->setFinal($method->isFinal());
                     $generatedMethod->setStatic($method->isStatic());
                     $generatedMethod->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
                     foreach ($method->getParameters() as $param) {
                         $generatedParam = new ParameterGenerator();
                         $generatedParam->setName($param->name);
                         if ($param->hasType()) {
                             $generatedParam->setType($param->getType());
                         }
                         //$generatedParam->setDefaultValue($param->getDefaultValue());
                         $generatedParam->setPosition($param->getPosition());
                         $generatedParam->setVariadic($param->isVariadic());
                         $generatedParam->setPassedByReference($param->isPassedByReference());
                         $generatedMethod->setParameter($generatedParam);
                     }
                     $existingMethod = Linq::from($methods)->firstOrDefault(null, function (MethodGenerator $v) use($method) {
                         return $v->getName() == $method->name;
                     });
                     if ($existingMethod != null) {
                         $existingParams = $existingMethod->getParameters();
                         foreach ($generatedMethod->getParameters() as $newParam) {
                             $existingParam = Linq::from($existingParams)->firstOrDefault(function (ParameterGenerator $v) {
                                 return $v->getName() == $newParam->getName();
                             });
                             if ($existingParam == null) {
                                 $existingMethod->setParameter($newParam);
                             }
                         }
                     } else {
                         $methods[] = $generatedMethod;
                     }
                 }
             }
             foreach ($parsedClass->getProperties() as $prop) {
                 //$properties[] = PropertyGenerator::fromReflection($prop);
             }
         }
     }
     $class->setImplementedInterfaces($implementedInterfaces);
     $class->addMethods($methods);
     $class->addProperties($properties);
     return (new FileGenerator(['classes' => [$class]]))->generate();
 }
開發者ID:brad-jones,項目名稱:ppm,代碼行數:67,代碼來源:ProxyGenerator.php

示例10: getServiceCode

 private function getServiceCode()
 {
     $code = new ClassGenerator($this->service->getName(), $this->namespace, null, '\\SoapClient');
     $doc = $this->service->getDoc();
     if ($doc) {
         $docBlock = new DocBlockGenerator($doc);
         $code->setDocBlock($docBlock);
     }
     foreach ($this->service->getFunctions() as $function) {
         $method = new MethodGenerator($function->getMethod());
         $docBlock = new DocBlockGenerator($function->getDoc());
         foreach ($function->getParams() as $param) {
             $methodParam = new ParameterGenerator($param->getName());
             if (false === $param->isPrimitive()) {
                 $methodParam->setType('\\' . $this->getFullNamespace($param->getType()));
             }
             $method->setParameter($methodParam);
             $tag = new Tag();
             $tag->setName('property');
             $type = $param->getType();
             if (false === $param->isPrimitive()) {
                 $type = '\\' . $this->getFullNamespace($param->getType());
             }
             $tag->setDescription(sprintf('%s $%s', $type, $param->getName()));
             $docBlock->setTag($tag);
         }
         $tag = new Tag();
         $tag->setName('returns');
         $tag->setDescription("\\" . $this->getFullNamespace($function->getReturns()));
         $docBlock->setTag($tag);
         $method->setBody(sprintf('return $this->__soapCall("%s", func_get_args());', $function->getName()));
         $method->setDocBlock($docBlock);
         $code->addMethodFromGenerator($method);
     }
     return $code;
 }
開發者ID:mlebkowski,項目名稱:wsdl-generator,代碼行數:36,代碼來源:WSDLGenerator.php

示例11: generateSetMethod

 /**
  * @param $columnName
  * @param $columnType
  *
  * @return MethodGenerator
  */
 protected function generateSetMethod($columnName, $columnType)
 {
     if (in_array($columnType, ['string', 'integer'])) {
         $body = '$this->' . $columnName . ' = (' . $columnType . ') $' . $columnName . ';';
         $parameter = new ParameterGenerator($columnName);
     } else {
         $body = '$this->' . $columnName . ' = $' . $columnName . ';';
         $parameter = new ParameterGenerator($columnName, $columnType);
     }
     $setMethodName = 'set' . ucfirst($columnName);
     $setMethod = new MethodGenerator($setMethodName);
     $setMethod->addFlag(MethodGenerator::FLAG_PROTECTED);
     $setMethod->setParameter($parameter);
     $setMethod->setDocBlock(new DocBlockGenerator('Set ' . $columnName, null, [['name' => 'param', 'description' => $columnType . ' $' . $columnName]]));
     $setMethod->setBody($body);
     return $setMethod;
 }
開發者ID:pgiacometto,項目名稱:zf2rapid,代碼行數:23,代碼來源:EntityClassGenerator.php

示例12: buildController

 public function buildController($model)
 {
     $class = new ClassGenerator($model->config->name . 'sController');
     $class->setExtendedClass('\\lithium\\action\\Controller');
     $class->setNamespaceName('app\\controllers');
     $publicActions = new PropertyGenerator('publicActions', array(), PropertyGenerator::FLAG_PUBLIC);
     $class->setProperty($publicActions);
     $messageMethod = new MethodGenerator('message');
     $messageMethod->setParameter('value');
     $messageMethod->setBody("\\lithium\\storage\\Session::write('message', \$value);");
     $class->setMethod($messageMethod);
     foreach (array('index', 'create', 'edit', 'view', 'delete') as $action) {
         $method = new MethodGenerator($action);
         $single = strtolower("{$model->config->name}");
         $plurals = $single . "s";
         switch ($action) {
             case 'index':
                 $body = "\${$plurals} = {$model->config->name}::findAll();\n\n";
                 $body .= "return compact('{$plurals}');";
                 $method->setBody($body);
                 break;
             case 'create':
                 $body = "if (\$this->request->data) {\n\n";
                 $body .= "\t\${$single} = new {$model->config->name}(\$this->request->data);\n\n";
                 $body .= "\tif(\${$single}->save()) {\n";
                 $body .= "\t\t\$this->message('Successfully to create {$model->config->name}');\n";
                 $body .= "\t\t\$this->redirect('{$model->config->name}s::index');\n";
                 $body .= "\t} else {\n";
                 $body .= "\t\t\$this->message('Failed to create {$model->config->name}, please check the error');\n";
                 $body .= "\t\t\$errors = \${$single}->getErrors();\n";
                 $body .= "\t}\n\n";
                 $body .= "}\n\n";
                 $body .= "return compact('{$single}', 'errors');";
                 $method->setBody($body);
                 break;
             case 'edit':
                 $body = "if (\$this->request->id) {\n\n";
                 $body .= "\t\${$single} = {$model->config->name}::get(\$this->request->id);\n";
                 $body .= "\t\${$single}->properties = \$this->request->data;\n\n";
                 $body .= "\tif(\${$single}->save()) {\n";
                 $body .= "\t\t\$this->message('Successfully to update {$model->config->name}');\n";
                 $body .= "\t\t\$this->redirect('{$model->config->name}s::index');\n";
                 $body .= "\t} else {\n";
                 $body .= "\t\t\$this->message('Failed to update {$model->config->name}, please check the error');\n";
                 $body .= "\t\t\$errors = \${$single}->getErrors();\n";
                 $body .= "\t}\n\n";
                 $body .= "}\n\n";
                 $body .= "return compact('{$single}', 'errors');";
                 $method->setBody($body);
                 break;
             case 'view':
                 $body = "if (\$this->request->id) {\n";
                 $body .= "\t\${$single} = {$model->config->name}::get(\$this->request->id);\n";
                 $body .= "}\n\n";
                 $body .= "return compact('{$single}');";
                 $method->setBody($body);
                 break;
             case 'delete':
                 $body = "if (\$this->request->id) {\n";
                 $body .= "\t\${$single} = {$model->config->name}::get(\$this->request->id);\n";
                 $body .= "\t\${$single}->delete();\n";
                 $body .= "\t\$this->message('Success to delete {$model->config->name}');\n";
                 $body .= "\t\$this->redirect('{$model->config->name}s::index');\n";
                 $body .= "\treturn true;\n";
                 $body .= "}\n\n";
                 $body .= "\$this->message('{$model->config->name} id cannot be empty');\n";
                 $body .= "\$this->redirect(\$this->request->referer());\n";
                 $body .= "return false;";
                 $method->setBody($body);
                 break;
         }
         $class->setMethod($method);
     }
     return $class;
 }
開發者ID:ncud,項目名稱:sagalaya,代碼行數:75,代碼來源:Generator.php

示例13: getDeleteLinkMethodWithoutLinkTable

    /**
     * @param AbstractLink $link
     * @return MethodGenerator
     */
    protected function getDeleteLinkMethodWithoutLinkTable(AbstractLink $link)
    {
        $localEntity = $link->getLocalEntity();
        $localEntityAsVar = $link->getLocalEntityAsVar();
        $localEntityAsCamelCase = $link->getLocalEntityAsCamelCase();
        $foreignTableAsCamelCase = $link->getForeignTable()->getNameAsCamelCase();
        $foreignEntity = $link->getForeignEntity();
        $foreignEntityAsVar = $link->getForeignEntityAsVar();
        $foreignEntityAsCamelCase = $link->getForeignEntityAsCamelCase();
        $localColumn = $link->getLocalColumn()->getName();
        $foreignColumn = $link->getForeignColumn()->getName();
        $tags = array(array('name' => 'param', 'description' => 'mixed $' . $localEntityAsVar), array('name' => 'param', 'description' => 'mixed $' . $foreignEntityAsVar), array('name' => 'return', 'description' => '\\Model\\Result\\Result'));
        $docblock = new DocBlockGenerator('Отвязать ' . $localEntityAsCamelCase . ' от ' . $foreignEntityAsCamelCase);
        $docblock->setTags($tags);
        $nullValue = new ValueGenerator('array()', ValueGenerator::TYPE_CONSTANT);
        $method = new MethodGenerator();
        $method->setName('deleteLink' . $localEntityAsCamelCase . 'To' . $foreignEntityAsCamelCase);
        $method->setParameter(new ParameterGenerator($localEntityAsVar, 'mixed', $nullValue));
        $method->setParameter(new ParameterGenerator($foreignEntityAsVar, 'mixed', $nullValue));
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setDocBlock($docblock);
        if ($link->isDirect()) {
            $method->setBody(<<<EOS
\${$localEntityAsVar}Ids = array_unique(\$this->getIdsFromMixed(\${$localEntityAsVar}));
\${$foreignEntityAsVar}Ids = array_unique({$foreignTableAsCamelCase}Model::getInstance()->getIdsFromMixed(\${$foreignEntityAsVar}));

\$result = new Result();
\$result->setResult(true);

if (count(\${$localEntityAsVar}Ids) == 0 && count(\${$foreignEntityAsVar}Ids) == 0) {
    return \$result;
}

\$cond = array();
if (count(\${$localEntityAsVar}Ids) != 0) {
    \$cond['{$foreignColumn}'] = \${$localEntityAsVar}Ids;
}

if (count(\${$foreignEntityAsVar}Ids) != 0) {
    \$cond['{$localColumn}'] = \${$foreignEntityAsVar}Ids;
}

try {
    \$this->getDb()->update(\$this->getRawName(), array('{$localColumn}' => null), \$cond);
} catch (\\Exception \$e) {
    \$result->setResult(false);
    \$result->addError("Delete link {$localEntity} to {$foreignEntity} failed", 'delete_link_failed');
}

return \$result;
EOS
);
        } else {
            $method->setBody(<<<EOS
return {$foreignTableAsCamelCase}Model::getInstance()->deleteLink{$foreignEntityAsCamelCase}To{$localEntityAsCamelCase}(\${$foreignEntityAsVar}, \${$localEntityAsVar});
EOS
);
        }
        return $method;
    }
開發者ID:meniam,項目名稱:model,代碼行數:64,代碼來源:Link.php

示例14: generateMethodsByRelated

    public function generateMethodsByRelated($part)
    {
        /** @var $part \Model\Generator\Part\Model */
        /** @var $file \Model\Code\Generator\FileGenerator */
        $file = $part->getFile();
        $table = $part->getTable();
        $linkList = $table->getLink();
        foreach ($linkList as $link) {
            $localColumnName = $link->getLocalColumn()->getName();
            $localColumnNameAsVar = $link->getLocalColumn()->getNameAsVar();
            $localColumnNameAsCamelCase = $link->getLocalColumn()->getNameAsCamelCase();
            $localEntityName = $link->getLocalEntity();
            $localEntityNameAsCamelCase = $link->getLocalEntityAsCamelCase();
            $localEntityNameAsVar = $link->getLocalEntityAsVar();
            $localTableName = $link->getLocalTable()->getName();
            $localTableNameAsVar = $link->getLocalTable()->getNameAsVar();
            $localTableNameAsCamelCase = $link->getLocalTable()->getNameAsCamelCase();
            $foreignEntityName = $link->getForeignEntity();
            $foreignEntityNameAsCamelCase = $link->getForeignEntityAsCamelCase();
            $foreignEntityNameAsVar = $link->getForeignEntityAsVar();
            $foreignColumnName = $link->getForeignColumn()->getName();
            $foreignColumnNameAsVar = $link->getForeignColumn()->getNameAsVar();
            $foreignColumnNameAsCamelCase = $link->getForeignColumn()->getNameAsCamelCase();
            $foreignTableName = $link->getForeignTable()->getName();
            $foreignTableNameAsVar = $link->getForeignTable()->getNameAsVar();
            $foreignTableNameAsCamelCase = $link->getForeignTable()->getNameAsCamelCase();
            $linkTableName = $link->getLinkTable() ? $link->getLinkTable()->getName() : '';
            $linkTableLocalColumnName = $link->getLinkTableLocalColumn() ? $link->getLinkTableLocalColumn()->getName() : '';
            $linkTableForeignColumnName = $link->getLinkTableForeignColumn() ? $link->getLinkTableForeignColumn()->getName() : '';
            $tags = array(array('name' => 'param', 'description' => "{$foreignTableNameAsCamelCase}Entity|\\Model\\Collection\\{$foreignTableNameAsCamelCase}Collection|int|string|array \$" . $foreignEntityNameAsVar), array('name' => 'param', 'description' => $localTableNameAsCamelCase . 'Cond' . ' $cond Дядя Кондиций :-)'), array('name' => 'return', 'description' => $localTableNameAsCamelCase . 'Entity'));
            $file->addUse('\\Model\\Entity\\' . $foreignTableNameAsCamelCase . 'Entity');
            $file->addUse('\\Model\\Cond\\' . $foreignTableNameAsCamelCase . 'Cond');
            $file->addUse('\\Model\\Collection\\' . $foreignTableNameAsCamelCase . 'Collection');
            $docblock = new DocBlockGenerator("Получить запись {$localEntityName} по {$foreignEntityNameAsVar}");
            $docblock->setTags($tags);
            $params = array(new ParameterGenerator($foreignEntityNameAsVar));
            $methodName = 'get';
            if ($localEntityNameAsCamelCase == $localTableNameAsCamelCase) {
                $methodName .= 'By' . $foreignEntityNameAsCamelCase;
            } else {
                $methodName .= $localEntityNameAsCamelCase . 'By' . $foreignEntityNameAsCamelCase;
            }
            $nullValue = new \Zend\Code\Generator\ValueGenerator('null', \Zend\Code\Generator\ValueGenerator::TYPE_CONSTANT);
            $method = new \Zend\Code\Generator\MethodGenerator();
            $method->setName($methodName);
            $method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
            $method->setDocBlock($docblock);
            $method->setParameters($params);
            $method->setParameter(new \Zend\Code\Generator\ParameterGenerator('cond', $localTableNameAsCamelCase . 'Cond', $nullValue));
            // Только прямая связь
            if (($link->getLinkType() == AbstractLink::LINK_TYPE_MANY_TO_ONE || $link->getLinkType() == AbstractLink::LINK_TYPE_ONE_TO_ONE) && !$link->getLinkTable() && $link->isDirect()) {
                $method->setBody(<<<EOS
\$cond = \$this->prepareCond(\$cond);

\${$foreignTableNameAsVar}Ids = {$foreignTableNameAsCamelCase}Model::getInstance()->getIdsFromMixed(\${$foreignEntityNameAsVar});

if (!\${$foreignTableNameAsVar}Ids) {
    return \$cond->getEmptySelectResult();
}

\$cond->where(array('`{$localTableName}`.`{$localColumnName}`' => \${$foreignTableNameAsVar}Ids));

return \$this->get(\$cond);
EOS
);
            } elseif (($link->getLinkType() == AbstractLink::LINK_TYPE_ONE_TO_ONE || $link->getLinkType() == AbstractLink::LINK_TYPE_ONE_TO_MANY) && !$link->getLinkTable()) {
                if ($localColumnName == $foreignColumnName && $link->getLinkType() == AbstractLink::LINK_TYPE_ONE_TO_ONE) {
                    $method->setBody(<<<EOS
\$cond = \$this->prepareCond(\$cond);

\${$localEntityNameAsVar}Ids = \$this->getIdsFromMixed(\${$foreignTableNameAsVar});

if (!\${$localEntityNameAsVar}Ids) {
    return \$cond->getEmptySelectResult();
}

\$cond->where(array('`{$localTableName}`.`{$localColumnName}`' => \${$localEntityNameAsVar}Ids));

return \$this->get(\$cond);
EOS
);
                } else {
                    $method->setBody(<<<EOS
\$cond = \$this->prepareCond(\$cond);

\${$foreignTableNameAsVar}CollectionCond = {$foreignTableNameAsCamelCase}Cond::init()->columns(array('id', '{$foreignColumnName}'));
/** @var {$foreignTableNameAsCamelCase}Collection|{$foreignTableNameAsCamelCase}Entity[] \${$foreignTableNameAsCamelCase}Collection */
\${$foreignTableNameAsVar}Collection = {$foreignTableNameAsCamelCase}Model::getInstance()->getCollectionById(\${$foreignEntityNameAsVar}, \${$foreignTableNameAsVar}CollectionCond);

\${$localEntityNameAsVar}Ids = array();
foreach (\${$foreignTableNameAsVar}Collection as \${$foreignTableNameAsVar}) {
    \${$localEntityNameAsVar}Ids[] = \${$foreignTableNameAsVar}->get{$localEntityNameAsCamelCase}Id();
}
\${$localEntityNameAsVar}Ids = \$this->getIdsFromMixed(\${$localEntityNameAsVar}Ids);

if (!\${$localEntityNameAsVar}Ids) {
    return \$cond->getEmptySelectResult();
}

\$cond->where(array('`{$localTableName}`.`{$localColumnName}`' => \${$localEntityNameAsVar}Ids));
//.........這裏部分代碼省略.........
開發者ID:meniam,項目名稱:model,代碼行數:101,代碼來源:Getter.php

示例15: addGetObject

    /**
     * @param ClassGenerator $generator
     * @param State          $state
     */
    public function addGetObject(ClassGenerator $generator, State $state)
    {
        $className = $state->getServiceModel()->getClassName();
        $doc = "@param array \$methods\n@return \\PHPUnit_Framework_MockObject_MockObject|" . $className;
        $class = $state->getServiceModel()->getName();
        $repository = ucfirst($state->getRepositoryModel()->getClassName());
        $body = <<<EOF
if (count(\$methods)) {
    \$object = \$this->getMockBuilder('{$class}')
        ->disableOriginalConstructor()
        ->setMethods(\$methods)
        ->getMock();
} else {
    \$object = new {$className}(\$this->getServiceManager());
}

\$object->set{$repository}(\$this->getRepository());
\$object->setEntityManager(\$this->getEntityManager());

return \$object;
EOF;
        $method = new MethodGenerator('getObject', [], MethodGenerator::FLAG_PUBLIC, $body, $doc);
        $method->setParameter(new ParameterGenerator('methods', 'array', []));
        $generator->addMethodFromGenerator($method);
    }
開發者ID:enlitepro,項目名稱:zf2-scaffold,代碼行數:29,代碼來源:ServiceTestBuilder.php


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