Пример #1
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));
    }
Пример #2
0
 /**
  * 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 . ');');
 }
Пример #3
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\', []);');
 }
Пример #4
0
 public function __construct()
 {
     parent::__construct('setIndexOriginalValue');
     $this->setParameter(new ParameterGenerator('name', 'string'));
     $this->setParameter(new ParameterGenerator('value', 'string'));
     $this->setBody('$this->_original_indices[$name] = $value; return $this;');
 }
Пример #5
0
 /**
  * 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);
 }
Пример #6
0
 /**
  * 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() . ';');
 }
Пример #7
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;");
 }
 /**
  * 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;');
 }
 /**
  * @param ReflectionClass $originalClass
  * @param string          $name
  * @param array           $parameters
  */
 public function __construct(ReflectionClass $originalClass, $name, array $parameters = array())
 {
     parent::__construct($name, $parameters, static::FLAG_PUBLIC, null, $originalClass->hasMethod($name) ? '{@inheritDoc}' : null);
     $this->setReturnsReference(strtolower($name) === '__get');
     if ($originalClass->hasMethod($name)) {
         $this->setReturnsReference($originalClass->getMethod($name)->returnsReference());
     }
 }
Пример #11
0
 /**
  * Constructor
  *
  * @param ReflectionClass $originalClass Reflection of the class to proxy
  */
 public function __construct(ReflectionClass $originalClass)
 {
     parent::__construct('staticProxyConstructor', [], static::FLAG_PUBLIC | static::FLAG_STATIC);
     $nullableProperties = array_map(function (ReflectionProperty $publicProperty) {
         return '$instance->' . $publicProperty->getName() . ' = null;';
     }, Properties::fromReflectionClass($originalClass)->getPublicProperties());
     $this->setDocblock("Constructor for null object initialization");
     $this->setBody('static $reflection;' . "\n\n" . '$reflection = $reflection ?: $reflection = new \\ReflectionClass(__CLASS__);' . "\n" . '$instance = (new \\ReflectionClass(get_class()))->newInstanceWithoutConstructor();' . "\n\n" . ($nullableProperties ? implode("\n", $nullableProperties) . "\n\n" : '') . 'return $instance;');
 }
 /**
  * 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;");
 }
Пример #13
0
 /**
  * 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;');
 }
Пример #14
0
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\HasAlias}.
  *
  * @param ReflectionClass $originalClass
  * @param AliasesProperty $aliasesProperty
  * @throws InvalidArgumentException
  */
 public function __construct(ReflectionClass $originalClass, AliasesProperty $aliasesProperty)
 {
     parent::__construct('hasAlias');
     $aliasParameter = new ParameterGenerator('alias');
     $aliasParameter->setType('string');
     $this->setParameter($aliasParameter);
     $this->setVisibility(self::VISIBILITY_PUBLIC);
     $this->setReturnType('bool');
     $this->setBody('return !empty($' . $aliasParameter->getName() . ') && ' . 'isset($this->' . $aliasesProperty->getName() . '[$' . $aliasParameter->getName() . ']);');
 }
 /**
  * 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;');
 }
Пример #16
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;');
 }
Пример #17
0
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\GetAlias}.
  *
  * @param ReflectionClass $originalClass
  * @param AliasesProperty $aliasesProperty
  * @throws InvalidArgumentException
  */
 public function __construct(ReflectionClass $originalClass, AliasesProperty $aliasesProperty)
 {
     parent::__construct('getAlias');
     $aliasParameter = new ParameterGenerator('alias');
     $aliasParameter->setType('string');
     $body = 'if ($this->hasAlias($' . $aliasParameter->getName() . ')) {' . PHP_EOL;
     $body .= '    $methodname = $this->' . $aliasesProperty->getName() . '[$' . $aliasParameter->getName() . '];' . PHP_EOL;
     $body .= '    return $this->$methodname();' . PHP_EOL;
     $body .= '}' . PHP_EOL . PHP_EOL;
     $body .= 'throw new ' . BeanNotFoundException::class . '(sprintf(\'Alias "%s" is not defined!\', $' . $aliasParameter->getName() . '));' . PHP_EOL;
     $this->setParameter($aliasParameter);
     $this->setVisibility(self::VISIBILITY_PUBLIC);
     $this->setBody($body);
 }
Пример #18
0
 /**
  * Constructor
  *
  * @param ReflectionClass $originalClass Reflection of the class to proxy
  */
 public function __construct(ReflectionClass $originalClass)
 {
     parent::__construct('__construct');
     /* @var $publicProperties \ReflectionProperty[] */
     $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
     $nullableProperties = array();
     foreach ($publicProperties as $publicProperty) {
         $nullableProperties[] = '$this->' . $publicProperty->getName() . ' = null;';
     }
     $this->setDocblock("@override constructor for null object initialization");
     if ($nullableProperties) {
         $this->setBody(implode("\n", $nullableProperties));
     }
 }
Пример #19
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);
 }
Пример #20
0
 /**
  * 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
  *
  * @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;');
 }
Пример #22
0
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\LazyBean\MethodGenerator\Constructor}.
  *
  * @param ReflectionClass $originalClass
  * @param BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty
  */
 public function __construct(ReflectionClass $originalClass, BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty)
 {
     parent::__construct('wrapBeanAsLazy');
     $this->setParameter(new ParameterGenerator('beanId'));
     $this->setParameter(new ParameterGenerator('beanType'));
     $this->setParameter(new ParameterGenerator('instance'));
     $content = '$factory = new \\' . \bitExpert\Disco\Proxy\LazyBean\LazyBeanFactory::class . '($beanId, $this->' . $beanFactoryConfigurationProperty->getName() . '->getProxyManagerConfiguration());' . PHP_EOL;
     $content .= '$initializer = function (&$wrappedObject, \\' . \ProxyManager\Proxy\LazyLoadingInterface::class . ' $proxy, $method, array $parameters, &$initializer) use($instance) {' . PHP_EOL;
     $content .= '    $initializer = null;' . PHP_EOL;
     $content .= '    $wrappedObject = $instance;' . PHP_EOL;
     $content .= '    return true;' . PHP_EOL;
     $content .= '};' . PHP_EOL;
     $content .= PHP_EOL;
     $content .= '$initializer->bindTo($this);' . PHP_EOL;
     $content .= 'return $factory->createProxy($beanType, $initializer);' . PHP_EOL;
     $this->setBody($content);
 }
Пример #23
0
 /**
  * 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;');
 }
Пример #24
0
 /**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolder, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct('__construct');
     $prefix = new ParameterGenerator('prefixInterceptors');
     $suffix = new ParameterGenerator('suffixInterceptors');
     $prefix->setDefaultValue(array());
     $suffix->setDefaultValue(array());
     $prefix->setType('array');
     $suffix->setType('array');
     $this->setParameter(new ParameterGenerator('wrappedObject'));
     $this->setParameter($prefix);
     $this->setParameter($suffix);
     /* @var $publicProperties \ReflectionProperty[] */
     $publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
     $unsetProperties = array();
     foreach ($publicProperties as $publicProperty) {
         $unsetProperties[] = '$this->' . $publicProperty->getName();
     }
     $this->setDocblock("@override 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");
     $this->setBody(($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '') . '$this->' . $valueHolder->getName() . " = \$wrappedObject;\n" . '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n" . '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;");
 }
Пример #25
0
 /**
  * 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");
 }
Пример #26
0
 public function __construct()
 {
     parent::__construct('getIndexOriginalValue');
     $this->setParameter(new ParameterGenerator('name', 'string'));
     $this->setBody('return isset($this->_original_indices[$name]) ? $this->_original_indices[$name] : null;');
 }
Пример #27
0
 /**
  * Constructor
  *
  * @param PropertyGenerator $initializerProperty
  */
 public function __construct(PropertyGenerator $initializerProperty)
 {
     parent::__construct('getProxyInitializer');
     $this->setDocblock('{@inheritDoc}');
     $this->setBody('return $this->' . $initializerProperty->getName() . ';');
 }
 /**
  * Constructor
  *
  * @param PropertyGenerator $initializerProperty
  */
 public function __construct(PropertyGenerator $initializerProperty)
 {
     parent::__construct('setProxyInitializer', [(new ParameterGenerator('initializer', 'Closure'))->setDefaultValue(null)], self::FLAG_PUBLIC, '$this->' . $initializerProperty->getName() . ' = $initializer;', '{@inheritDoc}');
 }
Пример #29
0
 public function __construct()
 {
     parent::__construct('setRelativeModified');
     $this->setParameter(new ParameterGenerator('name', 'string'));
     $this->setBody('$this->_modified_relatives[$name] = true; return $this;');
 }
Пример #30
0
 public function __construct()
 {
     parent::__construct('setOriginalId');
     $this->setParameter(new ParameterGenerator('value', 'string'));
     $this->setBody('$this->_original_id = $value; return $this;');
 }