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


PHP ParameterGenerator::setDefaultValue方法代码示例

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


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

示例1: testGenerateIsCorrect

 public function testGenerateIsCorrect()
 {
     $parameterGenerator = new ParameterGenerator();
     $parameterGenerator->setType('Foo');
     $parameterGenerator->setName('bar');
     $parameterGenerator->setDefaultValue(15);
     $this->assertEquals('Foo $bar = 15', $parameterGenerator->generate());
     $parameterGenerator->setDefaultValue('foo');
     $this->assertEquals('Foo $bar = \'foo\'', $parameterGenerator->generate());
 }
开发者ID:rikaix,项目名称:zf2,代码行数:10,代码来源:ParameterGeneratorTest.php

示例2: fromReflection

 /**
  * @param  ParameterReflection $reflectionParameter
  * @return ParameterGenerator
  */
 public static function fromReflection(ParameterReflection $reflectionParameter)
 {
     $param = new ParameterGenerator();
     $param->setName($reflectionParameter->getName());
     if ($reflectionParameter->isArray()) {
         $param->setType('array');
     } elseif (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
         $param->setType('callable');
     } else {
         $typeClass = $reflectionParameter->getClass();
         if ($typeClass) {
             $parameterType = $typeClass->getName();
             $currentNamespace = $reflectionParameter->getDeclaringClass()->getNamespaceName();
             if (!empty($currentNamespace) && substr($parameterType, 0, strlen($currentNamespace)) == $currentNamespace) {
                 $parameterType = substr($parameterType, strlen($currentNamespace) + 1);
             } else {
                 $parameterType = '\\' . trim($parameterType, '\\');
             }
             $param->setType($parameterType);
         }
     }
     $param->setPosition($reflectionParameter->getPosition());
     if ($reflectionParameter->isOptional()) {
         $param->setDefaultValue($reflectionParameter->getDefaultValue());
     }
     $param->setPassedByReference($reflectionParameter->isPassedByReference());
     return $param;
 }
开发者ID:CHRISTOPHERVANDOMME,项目名称:zf2complet,代码行数:32,代码来源:ParameterGenerator.php

示例3: __construct

 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\GetParameter}.
  *
  * @param ReflectionClass $originalClass
  * @param ParameterValuesProperty $parameterValueProperty
  * @throws InvalidArgumentException
  */
 public function __construct(ReflectionClass $originalClass, ParameterValuesProperty $parameterValueProperty)
 {
     parent::__construct('getParameter');
     $propertyNameParameter = new ParameterGenerator('propertyName');
     $requiredParameter = new ParameterGenerator('required');
     $requiredParameter->setDefaultValue(true);
     $defaultValueParameter = new ParameterGenerator('defaultValue');
     $defaultValueParameter->setDefaultValue(null);
     $body = '$steps = explode(\'.\', $' . $propertyNameParameter->getName() . ');' . PHP_EOL;
     $body .= '$value = $this->' . $parameterValueProperty->getName() . ';' . PHP_EOL;
     $body .= '$currentPath = [];' . PHP_EOL;
     $body .= 'foreach ($steps as $step) {' . PHP_EOL;
     $body .= '    $currentPath[] = $step;' . PHP_EOL;
     $body .= '    if (isset($value[$step])) {' . PHP_EOL;
     $body .= '        $value = $value[$step];' . PHP_EOL;
     $body .= '    } else {' . PHP_EOL;
     $body .= '        $value = $' . $defaultValueParameter->getName() . ';' . PHP_EOL;
     $body .= '        break;' . PHP_EOL;
     $body .= '    }' . PHP_EOL;
     $body .= '}' . PHP_EOL . PHP_EOL;
     $body .= 'if ($' . $requiredParameter->getName() . ' && (null === $value)) {' . PHP_EOL;
     $body .= '    if (null === $' . $defaultValueParameter->getName() . ') {' . PHP_EOL;
     $body .= '        throw new \\RuntimeException(\'Parameter "\' .$' . $propertyNameParameter->getName() . '. \'" is required but not defined and no default value provided!\');' . PHP_EOL;
     $body .= '    }' . PHP_EOL;
     $body .= '    throw new \\RuntimeException(\'Parameter "\' .$' . $propertyNameParameter->getName() . '. \'" not defined!\');' . PHP_EOL;
     $body .= '}' . PHP_EOL . PHP_EOL;
     $body .= 'return $value;' . PHP_EOL;
     $this->setParameter($propertyNameParameter);
     $this->setParameter($requiredParameter);
     $this->setParameter($defaultValueParameter);
     $this->setVisibility(self::VISIBILITY_PROTECTED);
     $this->setBody($body);
 }
开发者ID:bitexpert,项目名称:disco,代码行数:40,代码来源:GetParameter.php

示例4: fromReflection

    /**
     * @param  ParameterReflection $reflectionParameter
     * @return ParameterGenerator
     */
    public static function fromReflection(ParameterReflection $reflectionParameter)
    {
        $param = new ParameterGenerator();
        $param->setName($reflectionParameter->getName());

        if ($reflectionParameter->isArray()) {
            $param->setType('array');
        } elseif (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
            $param->setType('callable');
        } else {
            $typeClass = $reflectionParameter->getClass();
            if ($typeClass) {
                $param->setType($typeClass->getName());
            }
        }

        $param->setPosition($reflectionParameter->getPosition());

        if ($reflectionParameter->isOptional()) {
            $param->setDefaultValue($reflectionParameter->getDefaultValue());
        }
        $param->setPassedByReference($reflectionParameter->isPassedByReference());

        return $param;
    }
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:29,代码来源:ParameterGenerator.php

示例5: __construct

 /**
  * Constructor
  *
  * @param PropertyGenerator $initializerProperty
  */
 public function __construct(PropertyGenerator $initializerProperty)
 {
     parent::__construct('setProxyInitializer');
     $initializerParameter = new ParameterGenerator('initializer');
     $initializerParameter->setType(Closure::class);
     $initializerParameter->setDefaultValue(null);
     $this->setParameter($initializerParameter);
     $this->setDocblock('{@inheritDoc}');
     $this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;');
 }
开发者ID:andywooyay,项目名称:ProxyManager,代码行数:15,代码来源:SetProxyInitializer.php

示例6: fromReflection

 /**
  * @param  ParameterReflection $reflectionParameter
  * @return ParameterGenerator
  */
 public static function fromReflection(ParameterReflection $reflectionParameter)
 {
     $param = new ParameterGenerator();
     $param->setName($reflectionParameter->getName());
     if ($type = self::extractFQCNTypeFromReflectionType($reflectionParameter)) {
         $param->setType($type);
     }
     $param->setPosition($reflectionParameter->getPosition());
     $variadic = method_exists($reflectionParameter, 'isVariadic') && $reflectionParameter->isVariadic();
     $param->setVariadic($variadic);
     if (!$variadic && $reflectionParameter->isOptional()) {
         try {
             $param->setDefaultValue($reflectionParameter->getDefaultValue());
         } catch (\ReflectionException $e) {
             $param->setDefaultValue(null);
         }
     }
     $param->setPassedByReference($reflectionParameter->isPassedByReference());
     return $param;
 }
开发者ID:postalservice14,项目名称:zend-code,代码行数:24,代码来源:ParameterGenerator.php

示例7: __construct

 /**
  * Constructor
  *
  * @param PropertyGenerator $suffixInterceptor
  */
 public function __construct(PropertyGenerator $suffixInterceptor)
 {
     parent::__construct('setMethodSuffixInterceptor');
     $interceptor = new ParameterGenerator('suffixInterceptor');
     $interceptor->setType(Closure::class);
     $interceptor->setDefaultValue(null);
     $this->setParameter(new ParameterGenerator('methodName', 'string'));
     $this->setParameter($interceptor);
     $this->setDocblock('{@inheritDoc}');
     $this->setBody('$this->' . $suffixInterceptor->getName() . '[$methodName] = $suffixInterceptor;');
 }
开发者ID:jbafford,项目名称:ProxyManager,代码行数:16,代码来源:SetMethodSuffixInterceptor.php

示例8: handleValueMethod

 private function handleValueMethod(Generator\ClassGenerator $generator, PHPProperty $prop, PHPClass $class, $all = true)
 {
     $type = $prop->getType();
     $docblock = new DocBlockGenerator('Construct');
     $paramTag = new ParamTag("value", "mixed");
     $paramTag->setTypes($type ? $this->getPhpType($type) : "mixed");
     $docblock->setTag($paramTag);
     $param = new ParameterGenerator("value");
     if ($type && !$this->isNativeType($type)) {
         $param->setType($this->getPhpType($type));
     }
     $method = new MethodGenerator("__construct", [$param]);
     $method->setDocBlock($docblock);
     $method->setBody("\$this->value(\$value);");
     $generator->addMethodFromGenerator($method);
     $docblock = new DocBlockGenerator('Gets or sets the inner value');
     $paramTag = new ParamTag("value", "mixed");
     if ($type && $type instanceof PHPClassOf) {
         $paramTag->setTypes($this->getPhpType($type->getArg()->getType()) . "[]");
     } elseif ($type) {
         $paramTag->setTypes($this->getPhpType($prop->getType()));
     }
     $docblock->setTag($paramTag);
     $returnTag = new ReturnTag("mixed");
     if ($type && $type instanceof PHPClassOf) {
         $returnTag->setTypes($this->getPhpType($type->getArg()->getType()) . "[]");
     } elseif ($type) {
         $returnTag->setTypes($this->getPhpType($type));
     }
     $docblock->setTag($returnTag);
     $param = new ParameterGenerator("value");
     $param->setDefaultValue(null);
     if ($type && !$this->isNativeType($type)) {
         $param->setType($this->getPhpType($type));
     }
     $method = new MethodGenerator("value", []);
     $method->setDocBlock($docblock);
     $methodBody = "if (\$args = func_get_args()) {" . PHP_EOL;
     $methodBody .= "    \$this->" . $prop->getName() . " = \$args[0];" . PHP_EOL;
     $methodBody .= "}" . PHP_EOL;
     $methodBody .= "return \$this->" . $prop->getName() . ";" . PHP_EOL;
     $method->setBody($methodBody);
     $generator->addMethodFromGenerator($method);
     $docblock = new DocBlockGenerator('Gets a string value');
     $docblock->setTag(new ReturnTag("string"));
     $method = new MethodGenerator("__toString");
     $method->setDocBlock($docblock);
     $method->setBody("return strval(\$this->" . $prop->getName() . ");");
     $generator->addMethodFromGenerator($method);
 }
开发者ID:josedasilva,项目名称:xsd2php,代码行数:50,代码来源:ClassGenerator.php

示例9: __construct

 /**
  * Constructor
  *
  * @param ReflectionClass   $originalClass
  * @param PropertyGenerator $valueHolder
  * @param PropertyGenerator $prefixInterceptors
  * @param PropertyGenerator $suffixInterceptors
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolder, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct('staticProxyConstructor', [], static::FLAG_PUBLIC | static::FLAG_STATIC);
     $prefix = new ParameterGenerator('prefixInterceptors');
     $suffix = new ParameterGenerator('suffixInterceptors');
     $prefix->setDefaultValue([]);
     $suffix->setDefaultValue([]);
     $prefix->setType('array');
     $suffix->setType('array');
     $this->setParameter(new ParameterGenerator('wrappedObject'));
     $this->setParameter($prefix);
     $this->setParameter($suffix);
     $this->setReturnType($originalClass->getName());
     $this->setDocblock("Constructor to setup interceptors\n\n" . "@param \\" . $originalClass->getName() . " \$wrappedObject\n" . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n" . "@return self");
     $this->setBody('static $reflection;' . "\n\n" . '$reflection = $reflection ?: $reflection = new \\ReflectionClass(__CLASS__);' . "\n" . '$instance = (new \\ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . UnsetPropertiesGenerator::generateSnippet(Properties::fromReflectionClass($originalClass), 'instance') . '$instance->' . $valueHolder->getName() . " = \$wrappedObject;\n" . '$instance->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" . '$instance->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;\n\n" . 'return $instance;');
 }
开发者ID:jbafford,项目名称:ProxyManager,代码行数:24,代码来源:StaticProxyConstructor.php

示例10: __construct

 /**
  * Constructor
  *
  * @param ReflectionClass $originalClass
  */
 public function __construct(ReflectionClass $originalClass)
 {
     parent::__construct('staticProxyConstructor', [], static::FLAG_PUBLIC | static::FLAG_STATIC);
     $localizedObject = new ParameterGenerator('localizedObject');
     $prefix = new ParameterGenerator('prefixInterceptors');
     $suffix = new ParameterGenerator('suffixInterceptors');
     $localizedObject->setType($originalClass->getName());
     $prefix->setDefaultValue([]);
     $suffix->setDefaultValue([]);
     $prefix->setType('array');
     $suffix->setType('array');
     $this->setParameter($localizedObject);
     $this->setParameter($prefix);
     $this->setParameter($suffix);
     $this->setDocblock("Constructor to setup interceptors\n\n" . "@param \\" . $originalClass->getName() . " \$localizedObject\n" . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n" . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n" . "@return self");
     $this->setBody('static $reflection;' . "\n\n" . '$reflection = $reflection ?: $reflection = new \\ReflectionClass(__CLASS__);' . "\n" . '$instance   = $reflection->newInstanceWithoutConstructor();' . "\n\n" . '$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors);' . "\n\n" . 'return $instance;');
 }
开发者ID:andywooyay,项目名称:ProxyManager,代码行数:22,代码来源:StaticProxyConstructor.php

示例11: create

 /**
  * Process and create code/files
  */
 public function create()
 {
     $class = ClassGen::classGen($this->name, $this->namespace, ['Phrest\\SDK\\Request\\AbstractRequest', 'Phrest\\SDK\\Request\\RequestOptions', 'Phrest\\SDK\\PhrestSDK'], 'AbstractRequest');
     // Path
     $path = '/' . $this->version . '/' . strtolower($this->entityName) . $this->getPlaceholderUriFromUrl($this->action->url);
     $property = ClassGen::property('path', 'private', $path, 'string');
     $class->addPropertyFromGenerator($property);
     // Properties and constructor parameters
     /** @var ParameterGenerator[] $parameters */
     $parameters = [];
     // Get properties
     $getParams = $this->generateGetParamsFromUrl($this->action->url);
     if (!empty($getParams)) {
         foreach ($getParams as $getParam) {
             $class->addPropertyFromGenerator(ClassGen::property($getParam, 'public', null));
             $parameter = new ParameterGenerator($getParam);
             $parameter->setDefaultValue(null);
             $parameters[$getParam] = $parameter;
         }
     }
     // Post properties
     if (!empty($this->action->postParams)) {
         foreach ($this->action->postParams as $name => $type) {
             if ($class->hasProperty($name)) {
                 continue;
             }
             $class->addPropertyFromGenerator(ClassGen::property($name, 'public', null, $type));
             $parameter = new ParameterGenerator($name, $type);
             $parameter->setDefaultValue(null);
             $parameters[$name] = $parameter;
         }
     }
     // Constructor
     if (!empty($parameters)) {
         $constructor = ClassGen::constructor($parameters);
         $class->addMethodFromGenerator($constructor);
     }
     // Create method
     $create = ClassGen::method('create', [], 'public', $this->getCreateBody());
     $class->addMethodFromGenerator($create);
     // Setters
     foreach ($parameters as $parameter) {
         $class->addMethodFromGenerator(ClassGen::setter($parameter->getName(), $parameter->getType()));
     }
     return $class;
 }
开发者ID:spuy767,项目名称:sdk,代码行数:49,代码来源:RequestGenerator.php

示例12: __construct

 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\Constructor}.
  *
  * @param ReflectionClass $originalClass
  * @param ParameterValuesProperty $parameterValuesProperty
  * @param SessionBeansProperty $sessionBeansProperty
  * @param BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty
  * @param BeanPostProcessorsProperty $beanPostProcessorsProperty
  * @param string[] $beanPostProcessorMethodNames
  */
 public function __construct(ReflectionClass $originalClass, ParameterValuesProperty $parameterValuesProperty, SessionBeansProperty $sessionBeansProperty, BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty, BeanPostProcessorsProperty $beanPostProcessorsProperty, array $beanPostProcessorMethodNames)
 {
     parent::__construct('__construct');
     $beanFactoryConfigurationParameter = new ParameterGenerator('config');
     $beanFactoryConfigurationParameter->setType(BeanFactoryConfiguration::class);
     $parametersParameter = new ParameterGenerator('params');
     $parametersParameter->setDefaultValue([]);
     $body = '$this->' . $parameterValuesProperty->getName() . ' = $' . $parametersParameter->getName() . ';' . PHP_EOL;
     $body .= '$this->' . $beanFactoryConfigurationProperty->getName() . ' = $' . $beanFactoryConfigurationParameter->getName() . ';' . PHP_EOL;
     $body .= '$this->' . $sessionBeansProperty->getName() . ' = $' . $beanFactoryConfigurationParameter->getName() . '->getSessionBeanStore();' . PHP_EOL;
     $body .= '// register {@link \\bitExpert\\Disco\\BeanPostProcessor} instances' . PHP_EOL;
     $body .= '$this->' . $beanPostProcessorsProperty->getName() . '[] = new \\bitExpert\\Disco\\BeanFactoryPostProcessor();' . PHP_EOL;
     foreach ($beanPostProcessorMethodNames as $methodName) {
         $body .= '$this->' . $beanPostProcessorsProperty->getName() . '[] = $this->' . $methodName . '(); ';
         $body .= PHP_EOL;
     }
     $this->setParameter($beanFactoryConfigurationParameter);
     $this->setParameter($parametersParameter);
     $this->setBody($body);
     $this->setDocBlock("@override constructor");
 }
开发者ID:bitExpert,项目名称:disco,代码行数:31,代码来源:Constructor.php

示例13: viewStub

    protected function viewStub($part)
    {
        /**
         * @var $part \Model\Generator\Part\Model
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $table = $part->getTable();
        $tableNameAsCamelCase = $table->getNameAsCamelCase();
        $entity = $tableNameAsCamelCase . 'Entity';
        $collection = $tableNameAsCamelCase . 'Collection';
        $p = new \Zend\Code\Generator\ParameterGenerator('cond');
        $p->setType('Cond');
        $p->setDefaultValue(null);
        $params[] = $p;
        $docblock = new DocBlockGenerator('Получить объект условий в виде представления \'Extended\'

$param Cond $cond
$return Cond
        ');
        $method = new MethodGenerator();
        $method->setName('getCondAsExtendedView');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(false);
        $method->setDocBlock($docblock);
        $method->setParameters($params);
        $method->setBody(<<<EOS
\$cond = \$this->prepareCond(\$cond);
\$cond->where(array('status' => 'active'));
return \$cond;
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
        $p = new \Zend\Code\Generator\ParameterGenerator('cond');
        $p->setType('Cond');
        $p->setDefaultValue(null);
        $params[] = $p;
        $docblock = new DocBlockGenerator('Получить элемент в виде представления \'Extended\'

@param Cond $cond
@return ' . $entity);
        $method = new MethodGenerator();
        $method->setName('getAsExtendedView');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(false);
        $method->setDocBlock($docblock);
        $method->setParameters($params);
        $method->setBody(<<<EOS
\$cond = \$this->getCondAsExtendedView(\$cond);
return \$this->get(\$cond);
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
        $p = new \Zend\Code\Generator\ParameterGenerator('cond');
        $p->setType('Cond');
        $p->setDefaultValue(null);
        $params[] = $p;
        $docblock = new DocBlockGenerator('Получить коллекцию в виде представления \'Extended\'

@param Cond $cond
@return ' . $collection);
        $method = new MethodGenerator();
        $method->setName('getCollectionAsExtendedView');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(false);
        $method->setDocBlock($docblock);
        $method->setParameters($params);
        $method->setBody(<<<EOS
\$cond = \$this->getCondAsExtendedView(\$cond);
return \$this->getCollection(\$cond);
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
开发者ID:meniam,项目名称:model,代码行数:76,代码来源:Stubs.php

示例14: createDTO

 /**
  * {@inheritdoc}
  */
 public function createDTO(Type $type)
 {
     $class = $this->createClassFromType($type);
     $parentType = $type->getParent();
     // set the parent class
     if ($parentType) {
         $parentType = $parentType->getBase();
         if ($parentType->getSchema()->getTargetNamespace() !== SchemaReader::XSD_NS) {
             $class->setExtendedClass($parentType->getName());
         }
     }
     // check if the type is abstract
     $class->setAbstract($type->isAbstract());
     // create the constructor
     $constructor = new MethodGenerator('__construct');
     $constructorDoc = new DocBlockGenerator();
     $constructorBody = '';
     $constructor->setDocBlock($constructorDoc);
     $class->addMethodFromGenerator($constructor);
     /* @var \Goetas\XML\XSDReader\Schema\Type\ComplexType $type */
     foreach ($type->getElements() as $element) {
         /* @var \Goetas\XML\XSDReader\Schema\Element\Element $element */
         $docElementType = $this->namespaceInflector->inflectDocBlockQualifiedName($element->getType());
         $elementName = $element->getName();
         // create a param and a param tag used in constructor and setter docs
         $param = new ParameterGenerator($elementName, $this->namespaceInflector->inflectName($element->getType()));
         $paramTag = new ParamTag($elementName, $docElementType);
         // if the param type is not a PHP primitive type and its namespace is different that the class namespace
         if ($type->getSchema()->getTargetNamespace() === SchemaReader::XSD_NS and $class->getNamespaceName() !== $this->namespaceInflector->inflectNamespace($element->getType())) {
             $class->addUse($this->namespaceInflector->inflectQualifiedName($element->getType()));
         }
         // set the parameter nullability
         if ($element->isNil() or $this->config->isNullConstructorArguments()) {
             $param->setDefaultValue(new ValueGenerator(null, ValueGenerator::TYPE_NULL));
         }
         /*
          * PROPERTY CREATION
          */
         $docDescription = new Html2Text($type->getDoc());
         $doc = new DocBlockGenerator();
         $doc->setShortDescription($docDescription->getText());
         $doc->setTag(new GenericTag('var', $docElementType));
         $property = new PropertyGenerator();
         $property->setDocBlock($doc);
         $property->setName(filter_var($elementName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName'))));
         $property->setVisibility($this->config->isAccessors() ? AbstractMemberGenerator::VISIBILITY_PROTECTED : AbstractMemberGenerator::VISIBILITY_PUBLIC);
         $class->addPropertyFromGenerator($property);
         /*
          * IMPORTS
          */
         if ($element->getType()->getSchema()->getTargetNamespace() !== SchemaReader::XSD_NS and $this->namespaceInflector->inflectNamespace($element->getType()) !== $class->getNamespaceName()) {
             $class->addUse($this->namespaceInflector->inflectQualifiedName($element->getType()));
         }
         /*
          * CONSTRUCTOR PARAM CREATION
          */
         $constructorDoc->setTag($paramTag);
         $constructorBody .= "\$this->{$elementName} = \${$elementName};" . AbstractGenerator::LINE_FEED;
         $constructor->setParameter($param);
         /*
          * ACCESSORS CREATION
          */
         if ($this->config->isAccessors()) {
             // create the setter
             $setterDoc = new DocBlockGenerator();
             $setterDoc->setTag($paramTag);
             $setter = new MethodGenerator('set' . ucfirst($elementName));
             $setter->setParameter($param);
             $setter->setDocBlock($setterDoc);
             $setter->setBody("\$this->{$elementName} = \${$elementName};");
             $class->addMethodFromGenerator($setter);
             // create the getter
             $getterDoc = new DocBlockGenerator();
             $getterDoc->setTag(new ReturnTag($docElementType));
             $getter = new MethodGenerator('get' . ucfirst($elementName));
             $getter->setDocBlock($getterDoc);
             $getter->setBody("return \$this->{$elementName};");
             $class->addMethodFromGenerator($getter);
         }
     }
     // finalize the constructor body
     $constructor->setBody($constructorBody);
     $this->serializeClass($class);
     // register the class in the classmap
     $this->classmap[$class->getName()] = $class->getNamespaceName() . '\\' . $class->getName();
     return $class->getName();
 }
开发者ID:xstefanox,项目名称:sapone,代码行数:90,代码来源:ClassFactory.php

示例15: ParameterGenerator

            }
            continue;
        }
        $requiredParameters[] = new ParameterGenerator($fieldName, Collection::class);
    }
    foreach ($metadataClass->getFieldNames() as $fieldName) {
        if (in_array($fieldName, $metadataClass->getIdentifierFieldNames(), true) && $metadataClass->isIdGeneratorIdentity()) {
            // auto-incremental identifier, skip it.
            continue;
        }
        $fieldMapping = $metadataClass->getFieldMapping($fieldName);
        $type = null;
        if ('datetime' === $fieldMapping['type']) {
            $type = 'DateTime';
        }
        $parameter = new ParameterGenerator($fieldName, $type);
        if (isset($fieldMapping['nullable']) && $fieldMapping['nullable']) {
            $parameter->setDefaultValue(null);
            $optionalParameters[] = $parameter;
        } else {
            $requiredParameters[] = $parameter;
        }
    }
    $classGenerator = ClassGenerator::fromReflection(new ClassReflection($metadataClass->getName()));
    $classGenerator->removeMethod('__construct');
    $classGenerator->addMethodFromGenerator(new MethodGenerator('__construct', array_merge($requiredParameters, $optionalParameters), MethodGenerator::FLAG_PUBLIC, implode("\n", array_map(function (ParameterGenerator $parameterGenerator) {
        $name = $parameterGenerator->getName();
        return '$this->' . $name . ' = $' . $name . ';';
    }, array_merge($requiredParameters, $optionalParameters)))));
    file_put_contents($metadataClass->getReflectionClass()->getFileName(), preg_replace('/private \\$([A-Za-z0-9]+) = null;/i', 'private \\$${1};', "<?php\n\n\n" . $classGenerator->generate()));
}
开发者ID:jkhaled,项目名称:OpenCartDoctrineSchema,代码行数:31,代码来源:entity-regenerator.php


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