getName() public method

public getName ( ) : string
return string
Esempio n. 1
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);
 }
Esempio n. 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);
 }
Esempio n. 3
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");
 }
Esempio n. 4
0
 /**
  * @param  ParameterGenerator|string $parameter
  * @throws Exception\InvalidArgumentException
  * @return MethodGenerator
  */
 public function setParameter($parameter)
 {
     if (is_string($parameter)) {
         $parameter = new ParameterGenerator($parameter);
     } elseif (!$parameter instanceof ParameterGenerator) {
         throw new Exception\InvalidArgumentException(sprintf('%s is expecting either a string, array or an instance of %s\\ParameterGenerator', __METHOD__, __NAMESPACE__));
     }
     $parameterName = $parameter->getName();
     $this->parameters[$parameterName] = $parameter;
     return $this;
 }
Esempio n. 5
0
 /**
  * setParameter()
  *
  * @param ParameterGenerator|string $parameter
  * @return MethodGenerator
  */
 public function setParameter($parameter)
 {
     if (is_string($parameter)) {
         $parameter = new ParameterGenerator($parameter);
     } elseif (!$parameter instanceof ParameterGenerator) {
         throw new Exception\InvalidArgumentException('setParameter() is expecting either a string, array or an instance of Zend\\Code\\Generator\\ParameterGenerator');
     }
     $parameterName = $parameter->getName();
     $this->parameters[$parameterName] = $parameter;
     return $this;
 }
Esempio n. 6
0
 public function testNameGetterAndSetterPersistValue()
 {
     $parameterGenerator = new ParameterGenerator();
     $parameterGenerator->setName('Foo');
     $this->assertEquals('Foo', $parameterGenerator->getName());
 }
Esempio n. 7
0
 /**
  * setParameter()
  *
  * @param ParameterGenerator|string $parameter
  * @return \MethodGenerator\Code\Generator\PhpMethod
  */
 public function setParameter($parameter)
 {
     if (is_string($parameter)) {
         $parameter = new ParameterGenerator($parameter);
     } elseif (!$parameter instanceof ParameterGenerator) {
         throw new Exception\InvalidArgumentException('setParameter() expects either an array of method options or an instance of Zend_CodeGenerator_Php_Parameter');
     }
     $parameterName = $parameter->getName();
     $this->parameters[$parameterName] = $parameter;
     return $this;
 }
Esempio n. 8
0
 /**
  * Process and create code/files
  */
 public function create()
 {
     $class = ClassGen::classGen($this->name, $this->namespace, ['Phrest\\SDK\\Request\\AbstractRequest', 'Phrest\\SDK\\Request\\RequestOptions', 'Phrest\\SDK\\PhrestSDK'], 'AbstractRequest');
     // Path
     $path = '/' . $this->version . '/' . strtolower($this->entityName) . $this->getPlaceholderUriFromUrl($this->action->url);
     $property = ClassGen::property('path', 'private', $path, 'string');
     $class->addPropertyFromGenerator($property);
     // Properties and constructor parameters
     /** @var ParameterGenerator[] $parameters */
     $parameters = [];
     // Get properties
     $getParams = $this->generateGetParamsFromUrl($this->action->url);
     if (!empty($getParams)) {
         foreach ($getParams as $getParam) {
             $class->addPropertyFromGenerator(ClassGen::property($getParam, 'public', null));
             $parameter = new ParameterGenerator($getParam);
             $parameter->setDefaultValue(null);
             $parameters[$getParam] = $parameter;
         }
     }
     // Post properties
     if (!empty($this->action->postParams)) {
         foreach ($this->action->postParams as $name => $type) {
             if ($class->hasProperty($name)) {
                 continue;
             }
             $class->addPropertyFromGenerator(ClassGen::property($name, 'public', null, $type));
             $parameter = new ParameterGenerator($name, $type);
             $parameter->setDefaultValue(null);
             $parameters[$name] = $parameter;
         }
     }
     // Constructor
     if (!empty($parameters)) {
         $constructor = ClassGen::constructor($parameters);
         $class->addMethodFromGenerator($constructor);
     }
     // Create method
     $create = ClassGen::method('create', [], 'public', $this->getCreateBody());
     $class->addMethodFromGenerator($create);
     // Setters
     foreach ($parameters as $parameter) {
         $class->addMethodFromGenerator(ClassGen::setter($parameter->getName(), $parameter->getType()));
     }
     return $class;
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function createService(SimpleXMLElement $service)
 {
     // read the service name
     $serviceName = (string) $service['name'];
     $serviceClassName = $serviceName;
     $serviceClassName = filter_var($serviceClassName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName')));
     $serviceClassName = filter_var($serviceClassName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeConstantName')));
     /*
      * CLASS CREATION
      */
     // create the class
     $class = ClassGenerator::fromReflection(new ClassReflection('\\Sapone\\Template\\ServiceTemplate'));
     $class->setName($serviceClassName);
     $class->setNamespaceName($this->namespaceInflector->inflectNamespace($service));
     // set the correct inheritance
     if ($this->config->isBesimpleClient()) {
         $class->setExtendedClass('BeSimpleSoapClient');
         $class->addUse('BeSimple\\SoapClient\\SoapClient');
     } else {
         $class->setExtendedClass('\\SoapClient');
     }
     // read the service documentation
     $serviceDoc = new DocBlockGenerator();
     $serviceDoc->setTag(new GenericTag('xmlns', '@todo'));
     $documentation = new Html2Text((string) current($service->xpath('./wsdl:documentation')));
     if ($documentation->getText()) {
         $serviceDoc->setShortDescription($documentation->getText());
     }
     $class->setDocBlock($serviceDoc);
     /*
      * METHODS CREATION
      */
     foreach ($service->xpath('.//wsdl:operation') as $operation) {
         $operationName = (string) $operation['name'];
         $operationName = filter_var($operationName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName')));
         $operationName = filter_var($operationName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeConstantName')));
         $inputMessageType = $this->getTypeFromQualifiedString((string) current($operation->xpath('.//wsdl:input/@message')), $operation);
         $outputMessageType = $this->getTypeFromQualifiedString((string) current($operation->xpath('.//wsdl:output/@message')), $operation);
         // read the service documentation
         $messageDoc = new DocBlockGenerator();
         $documentation = new Html2Text((string) current($operation->xpath('./wsdl:documentation')));
         $param = new ParameterGenerator('parameters', $inputMessageType);
         $messageDoc->setTag(new ParamTag($param->getName(), $this->namespaceInflector->inflectDocBlockQualifiedName($inputMessageType)));
         $messageDoc->setTag(new ReturnTag($this->namespaceInflector->inflectDocBlockQualifiedName($outputMessageType)));
         if ($documentation->getText()) {
             $messageDoc->setShortDescription($documentation->getText());
         }
         // create the method
         $method = new MethodGenerator($operationName);
         $method->setDocBlock($messageDoc);
         $method->setParameter($param);
         $method->setBody("return \$this->__soapCall('{$operation['name']}', array(\$parameters));");
         $class->addMethodFromGenerator($method);
     }
     $this->serializeClass($class);
     // register the class in the classmap
     $this->classmap[$class->getName()] = $class->getNamespaceName() . '\\' . $class->getName();
     return $class->getName();
 }