php Zend-Code-Generator-PropertyGenerator类(方法)实例源码

下面列出了php Zend-Code-Generator-PropertyGenerator 类(方法)源码代码实例,从而了解它的用法。

作者:andywooya    项目:ProxyManage   
/**
  * Static constructor
  *
  * @param PropertyGenerator $initializerProperty
  * @param Properties        $properties
  */
 public function __construct(PropertyGenerator $initializerProperty, Properties $properties)
 {
     parent::__construct('staticProxyConstructor', [], static::FLAG_PUBLIC | static::FLAG_STATIC);
     $this->setParameter(new ParameterGenerator('initializer'));
     $this->setDocblock("Constructor for lazy initialization\n\n@param \\Closure|null \$initializer");
     $this->setBody('static $reflection;' . "\n\n" . '$reflection = $reflection ?: $reflection = new \\ReflectionClass(__CLASS__);' . "\n" . '$instance = (new \\ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . $this->generateUnsetPropertiesCode($properties) . '$instance->' . $initializerProperty->getName() . ' = $initializer;' . "\n\n" . 'return $instance;');
 }

作者:jbaffor    项目:ProxyManage   
/**
  * Constructor
  *
  * @param PropertyGenerator   $initializerProperty
  * @param ZendMethodGenerator $callInitializer
  */
 public function __construct(PropertyGenerator $initializerProperty, ZendMethodGenerator $callInitializer)
 {
     parent::__construct('initializeProxy');
     $this->setDocblock('{@inheritDoc}');
     $this->setReturnType('bool');
     $this->setBody('return $this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() . '(\'initializeProxy\', []);');
 }

作者:FanH    项目:ProxyManage   
/**
     * Constructor
     *
     * @param PropertyGenerator $initializerProperty
     * @param PropertyGenerator $initTracker
     * @param Properties        $properties
     */
    public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $initTracker, Properties $properties)
    {
        $docblock = <<<'DOCBLOCK'
Triggers initialization logic for this ghost object

@param string  $methodName
@param mixed[] $parameters

@return mixed
DOCBLOCK;
        parent::__construct(UniqueIdentifierGenerator::getIdentifier('callInitializer'), [new ParameterGenerator('methodName'), new ParameterGenerator('parameters', 'array')], static::VISIBILITY_PRIVATE, null, $docblock);
        $initializer = $initializerProperty->getName();
        $initialization = $initTracker->getName();
        $bodyTemplate = <<<'PHP'
if ($this->%s || ! $this->%s) {
    return;
}

$this->%s = true;

%s
%s

$result = $this->%s->__invoke($this, $methodName, $parameters, $this->%s, $properties);
$this->%s = false;

return $result;
PHP;
        $this->setBody(sprintf($bodyTemplate, $initialization, $initializer, $initialization, $this->propertiesInitializationCode($properties), $this->propertiesReferenceArrayCode($properties), $initializer, $initializer, $initialization));
    }

作者:FanH    项目:ProxyManage   
/**
  * Constructor
  *
  * @param ReflectionClass   $originalClass
  * @param PropertyGenerator $initializerProperty
  * @param PropertyGenerator $valueHolderProperty
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty)
 {
     parent::__construct($originalClass, '__sleep');
     $initializer = $initializerProperty->getName();
     $valueHolder = $valueHolderProperty->getName();
     $this->setBody('$this->' . $initializer . ' && $this->' . $initializer . '->__invoke($this->' . $valueHolder . ', $this, \'__sleep\', array(), $this->' . $initializer . ');' . "\n\n" . 'return array(' . var_export($valueHolder, true) . ');');
 }

作者:FanH    项目:ProxyManage   
/**
  * Constructor
  *
  * @param ReflectionClass   $originalClass
  * @param PropertyGenerator $initializerProperty
  * @param PropertyGenerator $valueHolderProperty
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty)
 {
     parent::__construct($originalClass, '__clone');
     $initializer = $initializerProperty->getName();
     $valueHolder = $valueHolderProperty->getName();
     $this->setBody('$this->' . $initializer . ' && $this->' . $initializer . '->__invoke($this->' . $valueHolder . ', $this, \'__clone\', array(), $this->' . $initializer . ');' . "\n\n" . '$this->' . $valueHolder . ' = clone $this->' . $valueHolder . ';');
 }

作者:John-Edd    项目:ProjetCasto   
/**
  * Constructor
  */
 public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty)
 {
     parent::__construct('initializeProxy');
     $this->setDocblock('{@inheritDoc}');
     $initializer = $initializerProperty->getName();
     $this->setBody('return $this->' . $initializer . ' && $this->' . $initializer . '->__invoke($this->' . $valueHolderProperty->getName() . ', $this, \'initializeProxy\', array(), $this->' . $initializer . ');');
 }

作者:jbaffor    项目:ProxyManage   
/**
  * Constructor
  *
  * @param PropertyGenerator $valueHolderProperty
  */
 public function __construct(PropertyGenerator $valueHolderProperty)
 {
     parent::__construct('isProxyInitialized');
     $this->setDocblock('{@inheritDoc}');
     $this->setReturnType('bool');
     $this->setBody('return null !== $this->' . $valueHolderProperty->getName() . ';');
 }

作者:John-Edd    项目:ProjetCasto   
/**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct('__construct');
     $localizedObject = new ParameterGenerator('localizedObject');
     $prefix = new ParameterGenerator('prefixInterceptors');
     $suffix = new ParameterGenerator('suffixInterceptors');
     $localizedObject->setType($originalClass->getName());
     $prefix->setDefaultValue(array());
     $suffix->setDefaultValue(array());
     $prefix->setType('array');
     $suffix->setType('array');
     $this->setParameter($localizedObject);
     $this->setParameter($prefix);
     $this->setParameter($suffix);
     $localizedProperties = array();
     foreach ($originalClass->getProperties() as $originalProperty) {
         if (!method_exists('Closure', 'bind') && $originalProperty->isPrivate()) {
             // @codeCoverageIgnoreStart
             throw UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty($originalProperty);
             // @codeCoverageIgnoreEnd
         }
         $propertyName = $originalProperty->getName();
         if ($originalProperty->isPrivate()) {
             $localizedProperties[] = "\\Closure::bind(function () use (\$localizedObject) {\n    " . '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";\n" . '}, $this, ' . var_export($originalProperty->getDeclaringClass()->getName(), true) . ')->__invoke();';
         } else {
             $localizedProperties[] = '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";";
         }
     }
     $this->setDocblock("@override 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");
     $this->setBody((empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;");
 }

作者:jbaffor    项目:ProxyManage   
/**
  * Constructor
  *
  * @param ReflectionClass   $originalClass Reflection of the class to proxy
  * @param PropertyGenerator $adapter       Adapter property
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapter)
 {
     $adapterName = $adapter->getName();
     parent::__construct('staticProxyConstructor', [new ParameterGenerator($adapterName, AdapterInterface::class)], MethodGenerator::FLAG_PUBLIC | MethodGenerator::FLAG_STATIC, null, 'Constructor for remote object control\\n\\n' . '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \\$adapter');
     $body = 'static $reflection;' . "\n\n" . '$reflection = $reflection ?: $reflection = new \\ReflectionClass(__CLASS__);' . "\n" . '$instance = (new \\ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . '$instance->' . $adapterName . ' = $' . $adapterName . ";\n\n" . UnsetPropertiesGenerator::generateSnippet(Properties::fromReflectionClass($originalClass), 'instance');
     $this->setBody($body . "\n\nreturn \$instance;");
 }

作者:enlitepr    项目:zf2-scaffol   
/**
  * @param  string            $name
  * @param  string            $type
  * @return PropertyGenerator
  */
 protected function getProperty($name, $type)
 {
     $property = new PropertyGenerator($name, null, PropertyGenerator::FLAG_PROTECTED);
     $property->setDocBlock(new DocBlockGenerator());
     $property->getDocBlock()->setTag(new Tag\GenericTag('var', $type));
     return $property;
 }

作者:bitexper    项目:disc   
/**
  * Creates a new {@link \bitExpert\Disco\Proxy\MethodGenerator\MagicWakeup}.
  *
  * @param ReflectionClass $originalClass
  * @param PropertyGenerator $valueHolderProperty
  * @param PropertyGenerator $valueHolderBeanIdProperty
  * @throws InvalidArgumentException
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolderProperty, PropertyGenerator $valueHolderBeanIdProperty)
 {
     parent::__construct($originalClass, '__wakeup');
     $valueHolder = $valueHolderProperty->getName();
     $valueHolderBeanId = $valueHolderBeanIdProperty->getName();
     $this->setBody('$beanFactory = \\' . BeanFactoryRegistry::class . '::getInstance();' . PHP_EOL . PHP_EOL . '$this->' . $valueHolder . ' = $beanFactory->get($this->' . $valueHolderBeanId . ');' . PHP_EOL . 'if ($this->' . $valueHolder . ' instanceof \\' . VirtualProxyInterface::class . ') {' . PHP_EOL . '    $this->' . $valueHolder . ' = $this->' . $valueHolder . '->getWrappedValueHolderValue();' . PHP_EOL . '}' . PHP_EOL);
 }

作者:till    项目:vufin   
/**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolderProperty, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct($originalClass, '__clone');
     $valueHolder = $valueHolderProperty->getName();
     $prefix = $prefixInterceptors->getName();
     $suffix = $suffixInterceptors->getName();
     $this->setBody("\$this->{$valueHolder} = clone \$this->{$valueHolder};\n\n" . "foreach (\$this->{$prefix} as \$key => \$value) {\n" . "    \$this->{$prefix}" . "[\$key] = clone \$value;\n" . "}\n\n" . "foreach (\$this->{$suffix} as \$key => \$value) {\n" . "    \$this->{$suffix}" . "[\$key] = clone \$value;\n" . "}");
 }

作者:John-Edd    项目:ProjetCasto   
/**
  * Constructor
  */
 public function __construct(PropertyGenerator $initializerProperty)
 {
     parent::__construct('setProxyInitializer');
     $initializerParameter = new ParameterGenerator('initializer');
     $initializerParameter->setType('Closure');
     $initializerParameter->setDefaultValue(null);
     $this->setParameter($initializerParameter);
     $this->setDocblock('{@inheritDoc}');
     $this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;');
 }

作者:brookinsconsultin    项目:ezecosyste   
/**
  * Constructor
  */
 public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $publicPropertiesDefaults, PropertyGenerator $initializationTracker)
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('callInitializer'));
     $this->setDocblock("Triggers initialization logic for this ghost object");
     $this->setParameters(array(new ParameterGenerator('methodName'), new ParameterGenerator('parameters', 'array')));
     $this->setVisibility(static::VISIBILITY_PRIVATE);
     $initializer = $initializerProperty->getName();
     $initialization = $initializationTracker->getName();
     $this->setBody('if ($this->' . $initialization . ' || ! $this->' . $initializer . ') {' . "\n    return;\n}\n\n" . "\$this->" . $initialization . " = true;\n\n" . "foreach (self::\$" . $publicPropertiesDefaults->getName() . " as \$key => \$default) {\n" . "    \$this->\$key = \$default;\n" . "}\n\n" . '$this->' . $initializer . '->__invoke' . '($this, $methodName, $parameters, $this->' . $initializer . ');' . "\n\n" . "\$this->" . $initialization . " = false;");
 }

作者:andywooya    项目:ProxyManage   
/**
  * Constructor
  *
  * @param ReflectionClass   $originalClass
  * @param PropertyGenerator $valueHolder
  *
  * @return MethodGenerator
  */
 public static function generateMethod(ReflectionClass $originalClass, PropertyGenerator $valueHolder)
 {
     $originalConstructor = self::getConstructor($originalClass);
     $constructor = $originalConstructor ? self::fromReflection($originalConstructor) : new self('__construct');
     $constructor->setDocblock('{@inheritDoc}');
     $constructor->setBody('static $reflection;' . "\n\n" . 'if (! $this->' . $valueHolder->getName() . ') {' . "\n" . '    $reflection = $reflection ?: new \\ReflectionClass(' . var_export($originalClass->getName(), true) . ");\n" . '    $this->' . $valueHolder->getName() . ' = $reflection->newInstanceWithoutConstructor();' . "\n" . self::getUnsetPropertiesString($originalClass) . "}\n\n" . '$this->' . $valueHolder->getName() . '->' . $constructor->getName() . '(' . implode(', ', array_map(function (ParameterGenerator $parameter) {
         return ($parameter->getVariadic() ? '...' : '') . '$' . $parameter->getName();
     }, $constructor->getParameters())) . ');');
     return $constructor;
 }

作者:Clon45    项目:batat   
/**
  * {@inheritDoc}
  */
 protected function setUp()
 {
     $this->initializer = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
     $this->initMethod = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
     $this->publicProperties = $this->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')->disableOriginalConstructor()->getMock();
     $this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz'));
     $this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
     $this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
 }

作者:John-Edd    项目:ProjetCasto   
/**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty, PublicPropertiesMap $publicProperties)
 {
     parent::__construct($originalClass, '__get', array(new ParameterGenerator('name')));
     $this->setDocblock(($originalClass->hasMethod('__get') ? "{@inheritDoc}\n" : '') . '@param string $name');
     $initializer = $initializerProperty->getName();
     $valueHolder = $valueHolderProperty->getName();
     $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" . '    return $this->' . $valueHolder . '->$name;' . "\n}\n\n";
     $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_GET, 'name', null, $valueHolderProperty);
     $this->setBody('$this->' . $initializer . ' && $this->' . $initializer . '->__invoke($this->' . $valueHolder . ', $this, \'__get\', array(\'name\' => $name), $this->' . $initializer . ');' . "\n\n" . $callParent);
 }

作者:jbaffor    项目:ProxyManage   
private static function generateOriginalConstructorCall(ReflectionClass $class, PropertyGenerator $valueHolder) : string
 {
     $originalConstructor = self::getConstructor($class);
     if (!$originalConstructor) {
         return '';
     }
     $constructor = self::fromReflection($originalConstructor);
     return "\n\n" . '$this->' . $valueHolder->getName() . '->' . $constructor->getName() . '(' . implode(', ', array_map(function (ParameterGenerator $parameter) : string {
         return ($parameter->getVariadic() ? '...' : '') . '$' . $parameter->getName();
     }, $constructor->getParameters())) . ');';
 }

作者:jbaffor    项目:ProxyManage   
/**
  * 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;');
 }

作者:anhph    项目:report   
/**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolder, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors, PublicPropertiesMap $publicProperties)
 {
     parent::__construct($originalClass, '__set', array(new ParameterGenerator('name'), new ParameterGenerator('value')));
     $override = $originalClass->hasMethod('__set');
     $valueHolderName = $valueHolder->getName();
     $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
     $callParent = PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_SET, 'name', 'value', $valueHolder, 'returnValue');
     if (!$publicProperties->isEmpty()) {
         $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" . '    $returnValue = ($this->' . $valueHolderName . '->$name = $value);' . "\n} else {\n    {$callParent}\n}\n\n";
     }
     $this->setBody(InterceptorGenerator::createInterceptedMethodBody($callParent, $this, $valueHolder, $prefixInterceptors, $suffixInterceptors));
 }


问题


面经


文章

微信
公众号

扫码关注公众号