/**
  * 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;');
 }
示例#2
0
 /**
  * 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\', []);');
 }
示例#3
0
    /**
     * 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));
    }
示例#4
0
 /**
  * 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) . ');');
 }
示例#5
0
 /**
  * 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 . ';');
 }
 /**
  * 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 . ');');
 }
 /**
  * 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() . ';');
 }
示例#8
0
 /**
  * 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;");
 }
 /**
  * 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;");
 }
示例#10
0
 /**
  * @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;
 }
示例#11
0
 /**
  * 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);
 }
示例#12
0
 /**
  * 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" . "}");
 }
 /**
  * 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;');
 }
 /**
  * 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;");
 }
示例#15
0
 /**
  * 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;
 }
示例#16
0
 /**
  * {@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'));
 }
示例#17
0
 /**
  * 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);
 }
示例#18
0
 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())) . ');';
 }
 /**
  * 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;');
 }
示例#20
0
 /**
  * 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));
 }
示例#21
0
文件: PhpClass.php 项目: nfx/pugooroo
 /**
  * @param type $name
  * @param type $type
  * @param type $docString
  * @return PhpProperty
  */
 public function addProperty($name, $type, $docString)
 {
     $property = new PropertyGenerator();
     $docblock = new DocBlockGenerator();
     $property->setName($name);
     $property->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
     $docblock->setShortDescription($docString);
     $docblock->setTag(new Tag(array('name' => 'var', 'description' => $type)));
     $property->setDocblock($docblock);
     $this->addPropertyFromGenerator($property);
     return $property;
 }
示例#22
0
 /**
  * @param \Zend\Code\Reflection\MethodReflection $originalMethod
  * @param \Zend\Code\Generator\PropertyGenerator $adapterProperty
  * @param \ReflectionClass                       $originalClass
  *
  * @return RemoteObjectMethod|static
  */
 public static function generateMethod(MethodReflection $originalMethod, PropertyGenerator $adapterProperty, ReflectionClass $originalClass)
 {
     /* @var $method self */
     $method = static::fromReflection($originalMethod);
     $parameters = $originalMethod->getParameters();
     $list = array();
     foreach ($parameters as $parameter) {
         $list[] = '$' . $parameter->getName();
     }
     $method->setBody('$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true) . ', ' . var_export($originalMethod->getName(), true) . ', array(' . implode(', ', $list) . '));' . "\n\n" . 'return $return;');
     return $method;
 }
示例#23
0
 /**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty)
 {
     parent::__construct('__construct');
     $this->setParameter(new ParameterGenerator('initializer'));
     /* @var $publicProperties \ReflectionProperty[] */
     $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
     $unsetProperties = array();
     foreach ($publicProperties as $publicProperty) {
         $unsetProperties[] = '$this->' . $publicProperty->getName();
     }
     $this->setDocblock("@override constructor for lazy initialization\n\n@param \\Closure|null \$initializer");
     $this->setBody(($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') . '$this->' . $initializerProperty->getName() . ' = $initializer;');
 }
示例#24
0
 /**
  * Constructor
  *
  * @param ReflectionClass     $originalClass
  * @param PropertyGenerator   $initializerProperty
  * @param PropertyGenerator   $valueHolderProperty
  * @param PublicPropertiesMap $publicProperties
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty, PublicPropertiesMap $publicProperties)
 {
     parent::__construct($originalClass, '__set', [new ParameterGenerator('name'), new ParameterGenerator('value')]);
     $initializer = $initializerProperty->getName();
     $valueHolder = $valueHolderProperty->getName();
     $callParent = '';
     $this->setDocblock(($originalClass->hasMethod('__set') ? "{@inheritDoc}\n" : '') . "@param string \$name\n@param mixed \$value");
     if (!$publicProperties->isEmpty()) {
         $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" . '    return ($this->' . $valueHolder . '->$name = $value);' . "\n}\n\n";
     }
     $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_SET, 'name', 'value', $valueHolderProperty);
     $this->setBody('$this->' . $initializer . ' && $this->' . $initializer . '->__invoke($this->' . $valueHolder . ', $this, ' . '\'__set\', array(\'name\' => $name, \'value\' => $value), $this->' . $initializer . ');' . "\n\n" . $callParent);
 }
示例#25
0
    public function postRun(PartInterface $part)
    {
        /**
         * @var $part \Model\Generator\Part\Entity
         */
        /**
         * @var $file \Model\Code\Generator\FileGenerator
         */
        $file = $part->getFile();
        $table = $part->getTable();
        $tags = array(array('name' => 'return', 'description' => 'array'));
        $docblock = new DocBlockGenerator('Initialize indexes');
        $docblock->setTags($tags);
        $resultIndexList = array();
        $indexList = $table->getIndex();
        foreach ($indexList as $index) {
            $resIndex = $index->toArray();
            $resIndex['column_list'] = array();
            switch ($index->getType()) {
                case AbstractIndex::TYPE_PRIMARY:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_PRIMARY', ValueGenerator::TYPE_CONSTANT);
                    break;
                case AbstractIndex::TYPE_KEY:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_KEY', ValueGenerator::TYPE_CONSTANT);
                    break;
                case AbstractIndex::TYPE_UNIQUE:
                    $resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_UNIQUE', ValueGenerator::TYPE_CONSTANT);
                    break;
            }
            foreach ($resIndex['columns'] as $col) {
                $resIndex['column_list'][] = $col['column_name'];
            }
            unset($resIndex['columns']);
            $resultIndexList[$index->getName()] = $resIndex;
        }
        $property = new PropertyGenerator('indexList', $resultIndexList, PropertyGenerator::FLAG_PROTECTED);
        $body = preg_replace("#^(\\s*)protected #", "\\1", $property->generate()) . "\n";
        $method = new MethodGenerator();
        $method->setName('initIndexList');
        $method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
        $method->setFinal(true);
        $method->setDocBlock($docblock);
        $method->setBody(<<<EOS
{$body}
\$this->indexList = \$indexList;
\$this->setupIndexList();
EOS
);
        $file->getClass()->addMethodFromGenerator($method);
    }
示例#26
0
 /**
  * Constructor
  *
  * @param ReflectionClass   $originalClass Reflection of the class to proxy
  * @param PropertyGenerator $adapter       Adapter property
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapter)
 {
     parent::__construct('__construct');
     $adapterName = $adapter->getName();
     $this->setParameter(new ParameterGenerator($adapterName, 'ProxyManager\\Factory\\RemoteObject\\AdapterInterface'));
     $this->setDocblock('@override constructor for remote object control\\n\\n' . '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \\$adapter');
     $body = '$this->' . $adapterName . ' = $' . $adapterName . ';';
     foreach ($originalClass->getProperties() as $property) {
         if ($property->isPublic() && !$property->isStatic()) {
             $body .= "\nunset(\$this->" . $property->getName() . ');';
         }
     }
     $this->setBody($body);
 }
 /**
  * Constructor
  *
  * @param ReflectionClass   $originalClass
  * @param PropertyGenerator $prefixInterceptors
  * @param PropertyGenerator $suffixInterceptors
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct('bindProxyProperties', [new ParameterGenerator('localizedObject', $originalClass->getName()), new ParameterGenerator('prefixInterceptors', 'array', []), new ParameterGenerator('suffixInterceptors', 'array', [])], static::FLAG_PRIVATE, null, "@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");
     $localizedProperties = [];
     $properties = Properties::fromReflectionClass($originalClass);
     foreach ($properties->getAccessibleProperties() as $property) {
         $propertyName = $property->getName();
         $localizedProperties[] = '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";";
     }
     foreach ($properties->getPrivateProperties() as $property) {
         $propertyName = $property->getName();
         $localizedProperties[] = "\\Closure::bind(function () use (\$localizedObject) {\n    " . '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";\n" . '}, $this, ' . var_export($property->getDeclaringClass()->getName(), true) . ')->__invoke();';
     }
     $this->setBody((empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n") . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;");
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('methodPrefixInterceptors'));
     $this->setDefaultValue(array());
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocblock('@var \\Closure[] map of interceptors to be called per-method before execution');
 }
示例#29
0
 /**
  * @param \ReflectionClass                                                   $originalClass
  * @param \Zend\Code\Generator\PropertyGenerator                             $initializerProperty
  * @param \Zend\Code\Generator\MethodGenerator                               $callInitializer
  * @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, MethodGenerator $callInitializer, PublicPropertiesMap $publicProperties)
 {
     parent::__construct($originalClass, '__get', array(new ParameterGenerator('name')));
     $override = $originalClass->hasMethod('__get');
     $callParent = '';
     $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
     if (!$publicProperties->isEmpty()) {
         $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" . '    return $this->$name;' . "\n}\n\n";
     }
     if ($override) {
         $callParent .= 'return parent::__get($name);';
     } else {
         $callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_GET, 'name');
     }
     $this->setBody('$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() . '(\'__get\', array(\'name\' => $name));' . "\n\n" . $callParent);
 }
示例#30
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializationTracker'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocblock('@var bool tracks initialization status - true while the object is initializing');
     $this->setDefaultValue(false);
 }