addPropertyFromGenerator() public method

Add property from PropertyGenerator
public addPropertyFromGenerator ( Zend\Code\Generator\PropertyGenerator $property ) : self
$property Zend\Code\Generator\PropertyGenerator
return self
Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     $interfaces = array('ProxyManager\\Proxy\\GhostObjectInterface');
     $publicProperties = new PublicPropertiesMap($originalClass);
     $publicPropsDefaults = new PublicPropertiesDefaults($originalClass);
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
     $classGenerator->addPropertyFromGenerator($initializationTracker = new InitializationTracker());
     $classGenerator->addPropertyFromGenerator($publicProperties);
     $classGenerator->addPropertyFromGenerator($publicPropsDefaults);
     $init = new CallInitializer($initializer, $publicPropsDefaults, $initializationTracker);
     $classGenerator->addMethodFromGenerator($init);
     foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
         $classGenerator->addMethodFromGenerator(LazyLoadingMethodInterceptor::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $initializer, $init));
     }
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $initializer));
     $classGenerator->addMethodFromGenerator(new MagicGet($originalClass, $initializer, $init, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicSet($originalClass, $initializer, $init, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicIsset($originalClass, $initializer, $init, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicUnset($originalClass, $initializer, $init, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicClone($originalClass, $initializer, $init));
     $classGenerator->addMethodFromGenerator(new MagicSleep($originalClass, $initializer, $init));
     $classGenerator->addMethodFromGenerator(new SetProxyInitializer($initializer));
     $classGenerator->addMethodFromGenerator(new GetProxyInitializer($initializer));
     $classGenerator->addMethodFromGenerator(new InitializeProxy($initializer, $init));
     $classGenerator->addMethodFromGenerator(new IsProxyInitialized($initializer));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     $publicProperties = new PublicPropertiesMap($originalClass);
     $interfaces = array('ProxyManager\\Proxy\\AccessInterceptorInterface', 'ProxyManager\\Proxy\\ValueHolderInterface');
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty());
     $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
     $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodSuffixInterceptors());
     $classGenerator->addPropertyFromGenerator($publicProperties);
     foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
         $classGenerator->addMethodFromGenerator(InterceptedMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $valueHolder, $prefixInterceptors, $suffixInterceptors));
     }
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new GetWrappedValueHolderValue($valueHolder));
     $classGenerator->addMethodFromGenerator(new SetMethodPrefixInterceptor($prefixInterceptors));
     $classGenerator->addMethodFromGenerator(new SetMethodSuffixInterceptor($suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicGet($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicSet($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicIsset($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicUnset($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties));
     $classGenerator->addMethodFromGenerator(new MagicClone($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicSleep($originalClass, $valueHolder));
     $classGenerator->addMethodFromGenerator(new MagicWakeup($originalClass, $valueHolder));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass, false);
     $classGenerator->setExtendedClass($originalClass->getName());
     $classGenerator->setImplementedInterfaces([AccessInterceptorInterface::class]);
     $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
     $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodSuffixInterceptors());
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map($this->buildMethodInterceptor($prefixInterceptors, $suffixInterceptors), ProxiedMethodsFilter::getProxiedMethods($originalClass, ['__get', '__set', '__isset', '__unset', '__clone', '__sleep'])), [new StaticProxyConstructor($originalClass, $prefixInterceptors, $suffixInterceptors), new BindProxyProperties($originalClass, $prefixInterceptors, $suffixInterceptors), new SetMethodPrefixInterceptor($prefixInterceptors), new SetMethodSuffixInterceptor($suffixInterceptors), new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors)]));
 }
Exemplo n.º 4
0
 /**
  * @param \Jungle\Syntax $syntax
  * @param \Jungle\SLR\Table $table
  *
  * @return \Zend\Code\Generator\ClassGenerator
  */
 public function build(Syntax $syntax, Table $table)
 {
     $this->class = new ClassGenerator('Test');
     $this->class->setDocBlock(new DocBlockGenerator('SLR parser', 'WARNING! THIS FILE AUTO GENERATED by JUNGLE. DO NOT EDIT IT!'));
     $this->class->addPropertyFromGenerator($this->getActionTableProperty($table));
     $this->class->addPropertyFromGenerator($this->getStackProperty());
     $this->buildParseMethod();
     $this->buildTokenizerMethod($syntax);
     $this->buildGetNextTokenMethod($syntax);
     $this->buildReduces($table->getReduces());
     return $this->class;
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass, false);
     $classGenerator->setExtendedClass($originalClass->getName());
     $classGenerator->setImplementedInterfaces(array('ProxyManager\\Proxy\\AccessInterceptorInterface'));
     $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
     $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodPrefixInterceptors());
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map(function (ReflectionMethod $method) use($prefixInterceptors, $suffixInterceptors) {
         return InterceptedMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $prefixInterceptors, $suffixInterceptors);
     }, ProxiedMethodsFilter::getProxiedMethods($originalClass, array('__get', '__set', '__isset', '__unset', '__clone', '__sleep'))), array(new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors), new SetMethodPrefixInterceptor($prefixInterceptors), new SetMethodSuffixInterceptor($suffixInterceptors), new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors))));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $interfaces = [VirtualProxyInterface::class];
     $publicProperties = new PublicPropertiesMap(Properties::fromReflectionClass($originalClass));
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty());
     $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
     $classGenerator->addPropertyFromGenerator($publicProperties);
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map($this->buildLazyLoadingMethodInterceptor($initializer, $valueHolder), ProxiedMethodsFilter::getProxiedMethods($originalClass)), [new StaticProxyConstructor($initializer, Properties::fromReflectionClass($originalClass)), Constructor::generateMethod($originalClass, $valueHolder), new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties), new MagicUnset($originalClass, $initializer, $valueHolder, $publicProperties), new MagicClone($originalClass, $initializer, $valueHolder), new MagicSleep($originalClass, $initializer, $valueHolder), new MagicWakeup($originalClass), new SetProxyInitializer($initializer), new GetProxyInitializer($initializer), new InitializeProxy($initializer, $valueHolder), new IsProxyInitialized($valueHolder), new GetWrappedValueHolderValue($valueHolder)]));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = [])
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass, false);
     $filteredProperties = Properties::fromReflectionClass($originalClass)->filter(isset($proxyOptions['skippedProperties']) ? $proxyOptions['skippedProperties'] : []);
     $publicProperties = new PublicPropertiesMap($filteredProperties);
     $privateProperties = new PrivatePropertiesMap($filteredProperties);
     $protectedProperties = new ProtectedPropertiesMap($filteredProperties);
     $classGenerator->setExtendedClass($originalClass->getName());
     $classGenerator->setImplementedInterfaces([GhostObjectInterface::class]);
     $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
     $classGenerator->addPropertyFromGenerator($initializationTracker = new InitializationTracker());
     $classGenerator->addPropertyFromGenerator($publicProperties);
     $classGenerator->addPropertyFromGenerator($privateProperties);
     $classGenerator->addPropertyFromGenerator($protectedProperties);
     $init = new CallInitializer($initializer, $initializationTracker, $filteredProperties);
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge($this->getAbstractProxiedMethods($originalClass), [$init, new StaticProxyConstructor($initializer, $filteredProperties), new MagicGet($originalClass, $initializer, $init, $publicProperties, $protectedProperties, $privateProperties, $initializationTracker), new MagicSet($originalClass, $initializer, $init, $publicProperties, $protectedProperties, $privateProperties), new MagicIsset($originalClass, $initializer, $init, $publicProperties, $protectedProperties, $privateProperties), new MagicUnset($originalClass, $initializer, $init, $publicProperties, $protectedProperties, $privateProperties), new MagicClone($originalClass, $initializer, $init, $publicProperties), new MagicSleep($originalClass, $initializer, $init, $publicProperties), new SetProxyInitializer($initializer), new GetProxyInitializer($initializer), new InitializeProxy($initializer, $init), new IsProxyInitialized($initializer)]));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $interfaces = array('ProxyManager\\Proxy\\VirtualProxyInterface');
     $publicProperties = new PublicPropertiesMap($originalClass);
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty());
     $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
     $classGenerator->addPropertyFromGenerator($publicProperties);
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map(function (ReflectionMethod $method) use($initializer, $valueHolder) {
         return LazyLoadingMethodInterceptor::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $initializer, $valueHolder);
     }, ProxiedMethodsFilter::getProxiedMethods($originalClass)), array(new Constructor($originalClass, $initializer), new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties), new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties), new MagicUnset($originalClass, $initializer, $valueHolder, $publicProperties), new MagicClone($originalClass, $initializer, $valueHolder), new MagicSleep($originalClass, $initializer, $valueHolder), new MagicWakeup($originalClass), new SetProxyInitializer($initializer), new GetProxyInitializer($initializer), new InitializeProxy($initializer, $valueHolder), new IsProxyInitialized($valueHolder), new GetWrappedValueHolderValue($valueHolder))));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $publicProperties = new PublicPropertiesMap(Properties::fromReflectionClass($originalClass));
     $interfaces = [AccessInterceptorInterface::class, ValueHolderInterface::class];
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty());
     $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
     $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodSuffixInterceptors());
     $classGenerator->addPropertyFromGenerator($publicProperties);
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map(function (ReflectionMethod $method) use($prefixInterceptors, $suffixInterceptors, $valueHolder) {
         return InterceptedMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $valueHolder, $prefixInterceptors, $suffixInterceptors);
     }, ProxiedMethodsFilter::getProxiedMethods($originalClass)), [Constructor::generateMethod($originalClass, $valueHolder), new StaticProxyConstructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), new GetWrappedValueHolderValue($valueHolder), new SetMethodPrefixInterceptor($prefixInterceptors), new SetMethodSuffixInterceptor($suffixInterceptors), new MagicGet($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties), new MagicSet($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties), new MagicIsset($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties), new MagicUnset($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors, $publicProperties), new MagicClone($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors), new MagicSleep($originalClass, $valueHolder), new MagicWakeup($originalClass, $valueHolder)]));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     if ($originalClass->isInterface()) {
         throw InvalidProxiedClassException::interfaceNotSupported($originalClass);
     }
     $classGenerator->setExtendedClass($originalClass->getName());
     $classGenerator->setImplementedInterfaces(array('ProxyManager\\Proxy\\AccessInterceptorInterface'));
     $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
     $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodPrefixInterceptors());
     $methods = ProxiedMethodsFilter::getProxiedMethods($originalClass, array('__get', '__set', '__isset', '__unset', '__clone', '__sleep'));
     foreach ($methods as $method) {
         $classGenerator->addMethodFromGenerator(InterceptedMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $prefixInterceptors, $suffixInterceptors));
     }
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new SetMethodPrefixInterceptor($prefixInterceptors));
     $classGenerator->addMethodFromGenerator(new SetMethodSuffixInterceptor($suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors));
 }
Exemplo n.º 11
0
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $interfaces = [RemoteObjectInterface::class];
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($adapter = new AdapterProperty());
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map(function (ReflectionMethod $method) use($adapter, $originalClass) : RemoteObjectMethod {
         return RemoteObjectMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $adapter, $originalClass);
     }, ProxiedMethodsFilter::getProxiedMethods($originalClass, ['__get', '__set', '__isset', '__unset'])), [new StaticProxyConstructor($originalClass, $adapter), new MagicGet($originalClass, $adapter), new MagicSet($originalClass, $adapter), new MagicIsset($originalClass, $adapter), new MagicUnset($originalClass, $adapter)]));
 }
Exemplo n.º 12
0
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     $interfaces = array('ProxyManager\\Proxy\\RemoteObjectInterface');
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($adapter = new AdapterProperty());
     $methods = ProxiedMethodsFilter::getProxiedMethods($originalClass, array('__get', '__set', '__isset', '__unset'));
     foreach ($methods as $method) {
         $classGenerator->addMethodFromGenerator(RemoteObjectMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $adapter, $originalClass));
     }
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $adapter));
     $classGenerator->addMethodFromGenerator(new MagicGet($originalClass, $adapter));
     $classGenerator->addMethodFromGenerator(new MagicSet($originalClass, $adapter));
     $classGenerator->addMethodFromGenerator(new MagicIsset($originalClass, $adapter));
     $classGenerator->addMethodFromGenerator(new MagicUnset($originalClass, $adapter));
 }
Exemplo n.º 13
0
 /**
  * Append Properties, Getter and Setter to Model class
  *
  * @param Generator\ClassGenerator $class
  * @param array                    $properties
  * @param array                    $hydratorStrategy
  */
 protected function addProperties(Generator\ClassGenerator &$class, array $properties)
 {
     foreach ($properties as $metadata) {
         $propertyInfos = $this->getNormalizedFilterOrProperty($metadata);
         $name = $propertyInfos['name'];
         $required = $propertyInfos['required'];
         $lazyLoading = $propertyInfos['lazyLoading'];
         $dataType = $propertyInfos['dataType'];
         $defaultValue = $propertyInfos['defaultValue'];
         $description = $propertyInfos['description'];
         $flags = Generator\PropertyGenerator::FLAG_PROTECTED;
         foreach ($propertyInfos['uses'] as $use) {
             $class->addUse($use);
         }
         $property = new Generator\PropertyGenerator($name);
         $property->setFlags($flags);
         if (!empty($defaultValue) or 'bool' === $dataType) {
             $property->setDefaultValue($defaultValue, $dataType);
         }
         $property->setDocBlock(new Generator\DocBlockGenerator($description));
         $class->addPropertyFromGenerator($property);
         // Add Setter method
         $setterParam = new Generator\ParameterGenerator($name, true === $lazyLoading ? null : $dataType);
         if (!$required) {
             $setterParam->setDefaultValue(null);
         }
         $setterBody = '';
         if (true === $lazyLoading) {
             if ($dataType == "ResultSet") {
                 $class->addUse('Mailjet\\Api\\ResultSet\\Exception');
                 $setterBody .= sprintf('if (! ($%s instanceof \\Closure || $%s instanceof %s)) {' . PHP_EOL . '   throw new Exception\\InvalidArgumentException("%s must be an instance of \'%s\' or \\Closure");' . PHP_EOL . '}' . PHP_EOL . PHP_EOL, $name, $name, $dataType, $name, $dataType);
             } else {
                 $setterBody .= sprintf('if (! ($%s instanceof \\Closure || $%s instanceof %s)) {' . PHP_EOL . '   throw new Exception\\InvalidArgumentException("$%s must be an instance of \'%s\' or \\Closure");' . PHP_EOL . '}' . PHP_EOL . PHP_EOL, $name, $name, $dataType, $name, $dataType);
             }
         }
         $setterBody .= sprintf('$this->%s = $%s;' . PHP_EOL . 'return $this;' . PHP_EOL, $name, $name);
         $class->addMethod('set' . ucfirst($name), array($setterParam), Generator\MethodGenerator::FLAG_PUBLIC, $setterBody, new Generator\DocBlockGenerator("Sets the " . $property->getDocBlock()->getShortDescription(), '', array(new ParamTag(array('name' => $name, 'datatype' => $dataType)), new ReturnTag(array('datatype' => $class->getName())))));
         // Add Getter method
         $getterBody = '';
         if (true === $lazyLoading) {
             $getterBody .= sprintf('if ($this->%s instanceof \\Closure) {' . PHP_EOL . '   $this->%s = call_user_func($this->%s);' . PHP_EOL . '}' . PHP_EOL . 'if (! $this->%s instanceof %s) {' . PHP_EOL . '    $this->%s = new %s();' . PHP_EOL . '}' . PHP_EOL . PHP_EOL, $name, $name, $name, $name, $dataType, $name, $dataType);
         }
         $getterBody .= sprintf('return $this->%s;', $name);
         $class->addMethod('get' . ucfirst($name), array(), Generator\MethodGenerator::FLAG_PUBLIC, $getterBody, new Generator\DocBlockGenerator('Gets the ' . $property->getDocBlock()->getShortDescription(), '', array(new ReturnTag(array('datatype' => $dataType)))));
         // If DataType Resulset => add/remove methods
         if ('ResultSet' === $dataType) {
             $class->addMethod('add' . ucfirst($name) . 'Item', array(new Generator\ParameterGenerator('item', $propertyInfos['model'])), Generator\MethodGenerator::FLAG_PUBLIC, sprintf('return $this->get%s()->add($item);' . PHP_EOL, ucfirst($name)), new Generator\DocBlockGenerator('Add new item to ' . ucfirst($name), '', array(new ReturnTag(array('datatype' => 'bool')))));
             $class->addMethod('remove' . ucfirst($name) . 'Item', array(new Generator\ParameterGenerator('item', $propertyInfos['model'])), Generator\MethodGenerator::FLAG_PUBLIC, sprintf('return $this->get%s()->remove($item);' . PHP_EOL, ucfirst($name)), new Generator\DocBlockGenerator('Remove $item from ' . ucfirst($name), '', array(new ReturnTag(array('datatype' => 'bool')))));
         }
     }
 }
Exemplo n.º 14
0
 /**
  * @param ClassGenerator $class
  * @param Tag $tagItem
  */
 protected function addPropertyFlags(ClassGenerator $class, Tag $tagItem)
 {
     $flags = [];
     foreach ($tagItem->getAttributes() as $tagAttribute) {
         if ($tagAttribute->isFlag()) {
             $flags[] = $tagAttribute->getName();
         }
     }
     sort($flags);
     $property = new PropertyGenerator('flags', [], PropertyGenerator::FLAG_PROTECTED);
     $property->setDefaultValue($flags);
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new GenericTag('var', 'array'));
     $property->setDocBlock($docBlock);
     $class->addPropertyFromGenerator($property);
 }
Exemplo n.º 15
0
 protected function handleSecondClassElements(CodeGenerator\ClassGenerator $classGenerator, array &$map, DOMNodeList $secondClassElements, DOMNode $element, DOMXPath $xpath)
 {
     foreach ($secondClassElements as $secondClassElement) {
         $maxOccursNode = $xpath->query('@maxOccurs', $secondClassElement)->item(0);
         $maxOccurs = $maxOccursNode ? $maxOccursNode->textContent : null;
         $unbounded = $maxOccurs == 'unbounded';
         $hydrationModifier = '#';
         $secondClassElementName = null;
         $secondClassElementNameNode = $xpath->query('@name', $secondClassElement)->item(0);
         if ($secondClassElementNameNode) {
             $secondClassElementName = $secondClassElementNameNode->textContent;
             $this->generateResource($secondClassElement);
         } else {
             $secondClassElementNameNode = $xpath->query('@ref', $secondClassElement)->item(0);
             if ($secondClassElementNameNode) {
                 if (substr($secondClassElementNameNode->textContent, 0, 4) == "tns:") {
                     $secondClassElementName = substr($secondClassElementNameNode->textContent, 4);
                 } elseif (substr($secondClassElementNameNode->textContent, 0, 5) == "data:") {
                     $secondClassElementName = substr($secondClassElementNameNode->textContent, 5);
                 }
             }
         }
         if (!$secondClassElementName) {
             continue;
         }
         $secondClassElementType = $secondClassElementName;
         if ($unbounded) {
             $secondClassElementType .= "[]";
         }
         $propertyName = lcfirst($secondClassElementName);
         if ($unbounded) {
             $propertyName .= 's';
         }
         $secondClassElementProperty = clone $this->getPropertyGenerator();
         $secondClassElementProperty->setName($propertyName);
         if ($unbounded) {
             $secondClassElementProperty->setDefaultValue(new CodeGenerator\PropertyValueGenerator(array()));
             $hydrationModifier .= '@';
             $mapKeyName = "{$secondClassElementName}s";
         } else {
             $mapKeyName = $secondClassElementName;
         }
         if ($secondClassElementType) {
             $secondClassElementPropertyDocblock = clone $this->getPropertyDocblockGenerator();
             $secondClassElementProperty->setDocBlock($secondClassElementPropertyDocblock);
             $typeTag = new CodeGenerator\DocBlock\Tag();
             $typeTag->setName('var');
             $typeTag->setDescription($secondClassElementType);
             $secondClassElementPropertyDocblock->setTag($typeTag);
         }
         $classGenerator->addPropertyFromGenerator($secondClassElementProperty);
         $getterGenerator = $this->generatePropertyGetter($propertyName);
         $setterGenerator = $this->generatePropertySetter($propertyName);
         $classGenerator->addMethods(array($getterGenerator, $setterGenerator));
         $map["{$hydrationModifier}{$mapKeyName}"] = "_:{$secondClassElementName}";
     }
 }
Exemplo n.º 16
0
 /**
  * {@inheritDoc}
  * @throws InvalidProxiedClassException
  * @throws InvalidArgumentException
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass, false);
     $annotation = null;
     $forceLazyInitProperty = new ForceLazyInitProperty();
     $sessionBeansProperty = new SessionBeansProperty();
     $postProcessorsProperty = new BeanPostProcessorsProperty();
     $parameterValuesProperty = new ParameterValuesProperty();
     $beanFactoryConfigurationProperty = new BeanFactoryConfigurationProperty();
     $aliasesProperty = new AliasesProperty();
     $getParameterMethod = new GetParameter($originalClass, $parameterValuesProperty);
     $wrapBeanAsLazyMethod = new WrapBeanAsLazy($originalClass, $beanFactoryConfigurationProperty);
     try {
         $reader = new AnnotationReader();
         $annotation = $reader->getClassAnnotation($originalClass, Configuration::class);
     } catch (Exception $e) {
         throw new InvalidProxiedClassException($e->getMessage(), $e->getCode(), $e);
     }
     if (null === $annotation) {
         throw new InvalidProxiedClassException(sprintf('"%s" seems not to be a valid configuration class. @Configuration annotation missing!', $originalClass->getName()));
     }
     $classGenerator->setExtendedClass($originalClass->getName());
     $classGenerator->setImplementedInterfaces([AliasContainerInterface::class]);
     $classGenerator->addPropertyFromGenerator($forceLazyInitProperty);
     $classGenerator->addPropertyFromGenerator($sessionBeansProperty);
     $classGenerator->addPropertyFromGenerator($postProcessorsProperty);
     $classGenerator->addPropertyFromGenerator($parameterValuesProperty);
     $classGenerator->addPropertyFromGenerator($beanFactoryConfigurationProperty);
     $classGenerator->addPropertyFromGenerator($aliasesProperty);
     $postProcessorMethods = [];
     $aliases = [];
     $methods = $originalClass->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED);
     foreach ($methods as $method) {
         if (null !== $reader->getMethodAnnotation($method, BeanPostProcessor::class)) {
             $postProcessorMethods[] = $method->getName();
             continue;
         }
         /* @var \bitExpert\Disco\Annotations\Bean $beanAnnotation */
         $beanAnnotation = $reader->getMethodAnnotation($method, Bean::class);
         if (null === $beanAnnotation) {
             throw new InvalidProxiedClassException(sprintf('Method "%s" on "%s" is missing the @Bean annotation!', $method->getName(), $originalClass->getName()));
         }
         // if alias is defined append it to the aliases list
         if ($beanAnnotation->getAlias() !== '' && !isset($aliases[$beanAnnotation->getAlias()])) {
             $aliases[$beanAnnotation->getAlias()] = $method->getName();
         }
         /* @var \bitExpert\Disco\Annotations\Parameters $parametersAnnotation */
         $parametersAnnotation = $reader->getMethodAnnotation($method, Parameters::class);
         if (null === $parametersAnnotation) {
             $parametersAnnotation = new Parameters();
         }
         $beanType = $method->getReturnType();
         if (null === $beanType) {
             throw new InvalidProxiedClassException(sprintf('Method "%s" on "%s" is missing the return typehint!', $method->getName(), $originalClass->getName()));
         }
         $beanType = (string) $beanType;
         if (!in_array($beanType, ['array', 'callable', 'bool', 'float', 'int', 'string']) && !class_exists($beanType) && !interface_exists($beanType)) {
             throw new InvalidProxiedClassException(sprintf('Return type of method "%s" on "%s" cannot be found! Did you use the full qualified name?', $method->getName(), $originalClass->getName()));
         }
         $methodReflection = new MethodReflection($method->class, $method->getName());
         $proxyMethod = BeanMethod::generateMethod($methodReflection, $beanAnnotation, $parametersAnnotation, $beanType, $forceLazyInitProperty, $sessionBeansProperty, $postProcessorsProperty, $beanFactoryConfigurationProperty, $getParameterMethod, $wrapBeanAsLazyMethod);
         $classGenerator->addMethodFromGenerator($proxyMethod);
     }
     $aliasesProperty->setDefaultValue($aliases);
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $parameterValuesProperty, $sessionBeansProperty, $beanFactoryConfigurationProperty, $postProcessorsProperty, $postProcessorMethods));
     $classGenerator->addMethodFromGenerator($wrapBeanAsLazyMethod);
     $classGenerator->addMethodFromGenerator($getParameterMethod);
     $classGenerator->addMethodFromGenerator(new MagicSleep($originalClass, $sessionBeansProperty));
     $classGenerator->addMethodFromGenerator(new GetAlias($originalClass, $aliasesProperty));
     $classGenerator->addMethodFromGenerator(new HasAlias($originalClass, $aliasesProperty));
 }
Exemplo n.º 17
0
 /**
  * @return ClassGenerator[]
  */
 private function getTypesCode()
 {
     $generator = $this;
     return array_map(function (Structure\TypeStructure $type) use($generator) {
         $code = new ClassGenerator($type->getClassName());
         $code->setNamespaceName($generator->getFullNamespace($type->getClassName(), true));
         foreach ($type->getMembers() as $member) {
             $tag = new Tag();
             $tag->setName('var');
             if ($member->isPrimitive()) {
                 $tag->setDescription($member->getType());
             } else {
                 $tag->setDescription("\\" . $generator->getFullNamespace($member->getType()));
             }
             $docBlock = new DocBlockGenerator(null, null, [$tag]);
             $property = new PropertyGenerator();
             $property->setName($member->getName());
             $property->setDocBlock($docBlock);
             $code->addPropertyFromGenerator($property);
         }
         return $code;
     }, $this->service->getTypes()->getArrayCopy());
 }
Exemplo n.º 18
0
 /**
  * Add property from PropertyGenerator
  *
  * @param  PropertyGenerator $property
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function addPropertyFromGenerator(PropertyGenerator $property)
 {
     if (!is_string($property->getName())) {
         throw new \InvalidArgumentException('addPropertyFromGenerator() expects string for name');
     }
     return parent::addPropertyFromGenerator($property);
 }
 /**
  * generates propertiy, getter, setter and other methods...
  *
  * @param \Zend\Code\Generator\ClassGenerator $class
  * @param FieldDescriptorInterface $column
  */
 protected function generateColumnRelatedElements(ClassGenerator $class, FieldDescriptorInterface $column)
 {
     $name = preg_replace("/[^a-z0-9_]/i", "_", $column->getName());
     $name = $this->underscoreToCamelCase->filter($name);
     $property = $this->createProperty($column, $name);
     $class->addPropertyFromGenerator($property);
     $getMethod = $this->createGetMethod($column, $name);
     $class->addMethodFromGenerator($getMethod);
     $setMethod = $this->createSetMethod($column, $name);
     $class->addMethodFromGenerator($setMethod);
 }
Exemplo n.º 20
0
 /**
  * @param ClassGenerator $generator
  * @param string         $name
  * @param string         $type
  */
 protected function addProperty(ClassGenerator $generator, $name, $type)
 {
     $generator->addPropertyFromGenerator($this->getProperty($name, $type));
 }
Exemplo n.º 21
0
 private function handleProperty(Generator\ClassGenerator $class, PHPProperty $prop)
 {
     $generatedProp = new PropertyGenerator($prop->getName());
     $generatedProp->setVisibility(PropertyGenerator::VISIBILITY_PRIVATE);
     $class->addPropertyFromGenerator($generatedProp);
     if ($prop->getType() && (!$prop->getType()->getNamespace() && $prop->getType()->getName() == "array")) {
         // $generatedProp->setDefaultValue(array(), PropertyValueGenerator::TYPE_AUTO, PropertyValueGenerator::OUTPUT_SINGLE_LINE);
     }
     $docBlock = new DocBlockGenerator();
     $generatedProp->setDocBlock($docBlock);
     if ($prop->getDoc()) {
         $docBlock->setLongDescription($prop->getDoc());
     }
     $tag = new PropertyTag($prop->getName(), 'mixed');
     $type = $prop->getType();
     if ($type && $type instanceof PHPClassOf) {
         $tt = $type->getArg()->getType();
         $tag->setTypes($this->getPhpType($tt) . "[]");
         if ($p = $this->isOneType($tt)) {
             if ($t = $p->getType()) {
                 $tag->setTypes($this->getPhpType($t) . "[]");
             }
         }
     } elseif ($type) {
         if ($this->isNativeType($type)) {
             $tag->setTypes($this->getPhpType($type));
         } elseif (($p = $this->isOneType($type)) && ($t = $p->getType())) {
             $tag->setTypes($this->getPhpType($t));
         } else {
             $tag->setTypes($this->getPhpType($prop->getType()));
         }
     }
     $docBlock->setTag($tag);
 }
 /**
  * generates headers
  *
  * @param \Zend\Code\Generator\ClassGenerator $class
  * @param DataSetDescriptorInterface $dataSet
  */
 protected function generateHeaderProperty(ClassGenerator $class, DataSetDescriptorInterface $dataSet)
 {
     $property = new \Zend\Code\Generator\PropertyGenerator("headers");
     $property->setFlags(\Zend\Code\Generator\PropertyGenerator::FLAG_PROTECTED);
     $value = array();
     foreach ($dataSet->listGenerator() as $field) {
         $value[$field->getName()] = array('title' => ucfirst(preg_replace("/[^a-z0-9]/i", " ", $field->getName())), 'width' => '100', 'filters' => $this->getFieldType($field) == 'bool' ? array(null => 'All', 1 => 'True', 0 => 'False') : "text");
     }
     $value['edit'] = array('title' => 'Edit', 'width' => '100');
     $value['delete'] = array('title' => 'Delete', 'width' => '100');
     $property->setDefaultValue($value);
     $class->addPropertyFromGenerator($property);
 }
Exemplo n.º 23
0
 protected function handleProperty(Generator\ClassGenerator $class, PHPProperty $prop)
 {
     $generatedProp = new PropertyGenerator($prop->getName());
     $generatedProp->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
     if (!$class->hasProperty($prop->getName())) {
         $class->addPropertyFromGenerator($generatedProp);
     } else {
         $generatedProp = $class->getProperty($prop->getName());
     }
     $docBlock = new DocBlockGenerator();
     $generatedProp->setDocBlock($docBlock);
     if ($prop->getDoc()) {
         $docBlock->setLongDescription($prop->getDoc());
     }
     $tag = new Generator\DocBlock\Tag();
     $tag->setName("@var {$this->getPropertyType($prop)}");
     $docBlock->setTag($tag);
     $type = $prop->getType();
     if ($type->type && $this->isTypeMapped($type->type->getName())) {
         if (!$class->hasProperty('_typeMap')) {
             $generatedProp = new PropertyGenerator('_typeMap');
             $generatedProp->setDefaultValue([]);
             $generatedProp->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
             $class->addPropertyFromGenerator($generatedProp);
         }
         $property = $class->getProperty('_typeMap');
         $defaultValue = $property->getDefaultValue()->getValue();
         $defaultValue[$prop->getName()] = $type->type->getName();
         $property->setDefaultValue($defaultValue);
     }
 }
 /**
  * {@inheritDoc}
  *
  * @throws \Zend\Code\Exception\InvalidArgumentException
  */
 public function addSignature(ClassGenerator $classGenerator, array $parameters) : ClassGenerator
 {
     $classGenerator->addPropertyFromGenerator(new PropertyGenerator('signature' . $this->signatureGenerator->generateSignatureKey($parameters), $this->signatureGenerator->generateSignature($parameters), PropertyGenerator::FLAG_STATIC | PropertyGenerator::FLAG_PRIVATE));
     return $classGenerator;
 }