Exemplo n.º 1
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\', []);');
 }
 /**
  * @param ReflectionClass  $originalClass
  * @param ClassGenerator   $classGenerator
  * @param MethodGenerator  $generatedMethod
  *
  * @return void|false
  */
 public static function addMethodIfNotFinal(ReflectionClass $originalClass, ClassGenerator $classGenerator, MethodGenerator $generatedMethod)
 {
     $methodName = $generatedMethod->getName();
     if ($originalClass->hasMethod($methodName) && $originalClass->getMethod($methodName)->isFinal()) {
         return false;
     }
     $classGenerator->addMethodFromGenerator($generatedMethod);
 }
Exemplo n.º 3
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);
 }
 /**
  * @param \Zend\Code\Reflection\MethodReflection $originalMethod
  * @param \Zend\Code\Generator\PropertyGenerator $initializerProperty
  * @param \Zend\Code\Generator\MethodGenerator   $callInitializer
  *
  * @return LazyLoadingMethodInterceptor|static
  */
 public static function generateMethod(MethodReflection $originalMethod, PropertyGenerator $initializerProperty, ZendMethodGenerator $callInitializer)
 {
     /* @var $method self */
     $method = static::fromReflection($originalMethod);
     $parameters = $originalMethod->getParameters();
     $methodName = $originalMethod->getName();
     $initializerParams = array();
     $forwardedParams = array();
     foreach ($parameters as $parameter) {
         $parameterName = $parameter->getName();
         $initializerParams[] = var_export($parameterName, true) . ' => $' . $parameterName;
         $forwardedParams[] = '$' . $parameterName;
     }
     $method->setBody('$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() . '(' . var_export($methodName, true) . ', array(' . implode(', ', $initializerParams) . "));\n\n" . 'return parent::' . $methodName . '(' . implode(', ', $forwardedParams) . ');');
     $method->setDocblock('{@inheritDoc}');
     return $method;
 }
Exemplo n.º 5
0
 /**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, MethodGenerator $callInitializer)
 {
     parent::__construct($originalClass, '__sleep');
     $this->setBody('$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() . '(\'__sleep\', array());' . "\n\n" . ($originalClass->hasMethod('__sleep') ? 'return parent::__sleep();' : 'return array_keys((array) $this);'));
 }
Exemplo n.º 6
0
 /**
  * @param ReflectionClass        $originalClass
  * @param PropertyGenerator      $initializerProperty
  * @param MethodGenerator        $callInitializer
  * @param PublicPropertiesMap    $publicProperties
  * @param ProtectedPropertiesMap $protectedProperties
  * @param PrivatePropertiesMap   $privateProperties
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, MethodGenerator $callInitializer, PublicPropertiesMap $publicProperties, ProtectedPropertiesMap $protectedProperties, PrivatePropertiesMap $privateProperties)
 {
     parent::__construct($originalClass, '__set', [new ParameterGenerator('name'), new ParameterGenerator('value')]);
     $override = $originalClass->hasMethod('__set');
     $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
     $parentAccess = 'return parent::__set($name, $value);';
     if (!$override) {
         $parentAccess = PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_SET, 'name', 'value');
     }
     $this->setBody(sprintf($this->callParentTemplate, '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() . '(\'__set\', array(\'name\' => $name, \'value\' => $value));', $publicProperties->getName(), $protectedProperties->getName(), $protectedProperties->getName(), $privateProperties->getName(), $privateProperties->getName(), $privateProperties->getName(), $parentAccess));
 }
Exemplo n.º 7
0
 /**
  * setMethod()
  *
  * @param  string|MethodGenerator $method
  * @return ClassGenerator
  */
 public function setMethod($method)
 {
     if (is_string($method)) {
         $method = new MethodGenerator($method);
     }
     if (!$method instanceof MethodGenerator) {
         throw new Exception\InvalidArgumentException('setMethod() expects either a string method name or an instance of Zend\\Code\\Generator\\MethodGenerator');
     }
     $methodName = $method->getName();
     if (isset($this->methods[$methodName])) {
         throw new Exception\InvalidArgumentException('A method by name ' . $methodName . ' already exists in this class.');
     }
     $this->methods[$methodName] = $method;
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Constructor
  *
  * @param ReflectionClass   $originalClass
  * @param PropertyGenerator $initializerProperty
  * @param MethodGenerator   $callInitializer
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty, MethodGenerator $callInitializer)
 {
     parent::__construct($originalClass, '__clone');
     $this->setBody('$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName() . '(\'__clone\', []);' . ($originalClass->hasMethod('__clone') ? "\n\nparent::__clone();" : ''));
 }
Exemplo n.º 9
0
    /**
     * Add Method from MethodGenerator
     *
     * @param  MethodGenerator $method
     * @throws Exception\InvalidArgumentException
     * @return ClassGenerator
     */
    public function addMethodFromGenerator(MethodGenerator $method)
    {
        $methodName = $method->getName();

        if (isset($this->methods[$methodName])) {
            throw new Exception\InvalidArgumentException('A method by name ' . $methodName . ' already exists in this class.');
        }

        $this->methods[$methodName] = $method;
        return $this;
    }
Exemplo n.º 10
0
 /**
  * Add Method from MethodGenerator
  *
  * @param  MethodGenerator                    $method
  * @throws Exception\InvalidArgumentException
  * @return ClassGenerator
  */
 public function addMethodFromGenerator(MethodGenerator $method)
 {
     $methodName = $method->getName();
     if ($this->hasMethod($methodName)) {
         throw new Exception\InvalidArgumentException(sprintf('A method by name %s already exists in this class.', $methodName));
     }
     $this->methods[strtolower($methodName)] = $method;
     return $this;
 }
Exemplo n.º 11
0
 /**
  * Add method from MethodGenerator
  *
  * @param  MethodGenerator $method
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function addMethodFromGenerator(MethodGenerator $method)
 {
     if (!is_string($method->getName())) {
         throw new \InvalidArgumentException('addMethodFromGenerator() expects string for name');
     }
     return parent::addMethodFromGenerator($method);
 }