상속: extends Zend\Code\Generator\PropertyGenerator
예제 #1
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() . ']);');
 }
예제 #2
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);
 }