本文整理汇总了PHP中Zend\Code\Generator\ParameterGenerator类的典型用法代码示例。如果您正苦于以下问题:PHP ParameterGenerator类的具体用法?PHP ParameterGenerator怎么用?PHP ParameterGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParameterGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMethods
protected function getMethods()
{
$methods = [$this->getConstructor()];
foreach ($this->properties as $propertyName) {
$setterParam = new ParameterGenerator($propertyName);
$methodGenerator = new MethodGenerator('set' . ucfirst($propertyName), [$setterParam]);
$methodGenerator->setBody('$this->' . $propertyName . ' = ' . $setterParam->generate() . ';' . PHP_EOL . PHP_EOL . 'return $this;');
$methods[] = $methodGenerator;
$methodGenerator = new MethodGenerator('get' . ucfirst($propertyName));
$methodGenerator->setBody('return $this->' . $propertyName . ';');
$methods[] = $methodGenerator;
}
foreach ($this->edgeProperties as $edgeCollection => $targetCollection) {
$setterParam = new ParameterGenerator(lcfirst($edgeCollection));
$methodGenerator = new MethodGenerator('add' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('$this->lazyAddNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
$methods[] = $methodGenerator;
$setterParam = new ParameterGenerator(lcfirst($edgeCollection));
$methodGenerator = new MethodGenerator('remove' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('$this->lazyRemoveNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
$methods[] = $methodGenerator;
$setterParam = new ParameterGenerator(lcfirst($edgeCollection));
$methodGenerator = new MethodGenerator('set' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('$this->lazySetNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
$methods[] = $methodGenerator;
$defaultValue = new ValueGenerator([], ValueGenerator::TYPE_ARRAY);
$setterParam = new ParameterGenerator('filter', null, $defaultValue);
$methodGenerator = new MethodGenerator('get' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('return $this->lazyGetNeighbor(\'' . $edgeCollection . '\', \'' . $targetCollection . '\', $filter);');
$methods[] = $methodGenerator;
}
return $methods;
}
示例2: __construct
/**
* 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);
}
示例3: generate
public function generate()
{
$modelBuilder = $this->controller->getModelBuilder();
$className = $modelBuilder->getName() . 'Controller';
$class = new ClassGenerator();
$class->setName($className);
$class->setExtendedClass('CrudController');
$param = new ParameterGenerator();
$param->setName('fb')->setType('FormBuilder');
$body = $this->generateFormBuilderBody();
$docblock = '@param FormBuilder $fb';
$class->addMethod('buildForm', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('mb')->setType('ModelBuilder');
$body = '';
$docblock = '@param ModelBuilder $mb';
$class->addMethod('buildModel', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('ob')->setType('OverviewBuilder');
$body = '';
$docblock = '@param OverviewBuilder $ob';
$class->addMethod('buildOverview', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$this->generator->setClass($class);
$this->generator->setUses(array('Boyhagemann\\Crud\\CrudController', 'Boyhagemann\\Form\\FormBuilder', 'Boyhagemann\\Model\\ModelBuilder', 'Boyhagemann\\Overview\\OverviewBuilder'));
return $this->generator->generate();
}
示例4: generate
public function generate()
{
if ($this->controller) {
$modelBuilder = $this->controller->getModelBuilder();
$className = $modelBuilder->getName();
} else {
$className = $this->class;
}
$modelClass = $this->modelClass ? $this->modelClass : $this->class;
$class = new ClassGenerator();
$class->setName($className);
$class->setExtendedClass('CrudController');
$class->addUse('Boyhagemann\\Crud\\CrudController');
$class->addUse('Boyhagemann\\Form\\FormBuilder');
$class->addUse('Boyhagemann\\Model\\ModelBuilder');
$class->addUse('Boyhagemann\\Overview\\OverviewBuilder');
$param = new ParameterGenerator();
$param->setName('fb')->setType('FormBuilder');
$body = $this->generateFormBuilderBody();
$docblock = '@param FormBuilder $fb';
$class->addMethod('buildForm', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('mb')->setType('ModelBuilder');
$body = sprintf('$mb->name(\'%s\')->table(\'%s\');' . PHP_EOL, $modelClass, strtolower(str_replace('\\', '_', $modelClass)));
$docblock = '@param ModelBuilder $mb';
$class->addMethod('buildModel', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('ob')->setType('OverviewBuilder');
$body = '';
$docblock = '@param OverviewBuilder $ob';
$class->addMethod('buildOverview', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$this->generator->setClass($class);
return $this->generator->generate();
}
示例5: __construct
/**
* Constructor
*
* @param PropertyGenerator $initializerProperty
*/
public function __construct(PropertyGenerator $initializerProperty)
{
parent::__construct('setProxyInitializer');
$initializerParameter = new ParameterGenerator('initializer');
$initializerParameter->setType(Closure::class);
$initializerParameter->setDefaultValue(null);
$this->setParameter($initializerParameter);
$this->setDocblock('{@inheritDoc}');
$this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;');
}
示例6: __construct
/**
* 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() . ']);');
}
示例7: fromReflection
/**
* @param ParameterReflection $reflectionParameter
* @return ParameterGenerator
*/
public static function fromReflection(ParameterReflection $reflectionParameter)
{
$param = new ParameterGenerator();
$param->setName($reflectionParameter->getName());
if ($reflectionParameter->isArray()) {
$param->setType('array');
} elseif (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
$param->setType('callable');
} else {
$typeClass = $reflectionParameter->getClass();
if ($typeClass) {
$parameterType = $typeClass->getName();
$currentNamespace = $reflectionParameter->getDeclaringClass()->getNamespaceName();
if (!empty($currentNamespace) && substr($parameterType, 0, strlen($currentNamespace)) == $currentNamespace) {
$parameterType = substr($parameterType, strlen($currentNamespace) + 1);
} else {
$parameterType = '\\' . trim($parameterType, '\\');
}
$param->setType($parameterType);
}
}
$param->setPosition($reflectionParameter->getPosition());
if ($reflectionParameter->isOptional()) {
$param->setDefaultValue($reflectionParameter->getDefaultValue());
}
$param->setPassedByReference($reflectionParameter->isPassedByReference());
return $param;
}
示例8: fromReflection
/**
* @param ParameterReflection $reflectionParameter
* @return ParameterGenerator
*/
public static function fromReflection(ParameterReflection $reflectionParameter)
{
$param = new ParameterGenerator();
$param->setName($reflectionParameter->getName());
if ($reflectionParameter->isArray()) {
$param->setType('array');
} elseif (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
$param->setType('callable');
} else {
$typeClass = $reflectionParameter->getClass();
if ($typeClass) {
$param->setType($typeClass->getName());
}
}
$param->setPosition($reflectionParameter->getPosition());
if ($reflectionParameter->isOptional()) {
$param->setDefaultValue($reflectionParameter->getDefaultValue());
}
$param->setPassedByReference($reflectionParameter->isPassedByReference());
return $param;
}
示例9: __construct
/**
* 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;');
}
示例10: generatePropertyAdder
public function generatePropertyAdder($propertyName)
{
$parameterName = rtrim($propertyName, 's');
$methodName = 'add' . ucfirst($parameterName);
$setterGenerator = clone $this->getPropertySetterGenerator();
$setterGenerator->setName($methodName);
$parameter = new CodeGenerator\ParameterGenerator();
$parameter->setName($parameterName);
$setterGenerator->setParameter($parameter);
$valueParameter = new CodeGenerator\ParameterGenerator();
$valueParameter->setName('value');
$setterGenerator->setParameter($valueParameter);
$setterGenerator->setBody("\$this->{$propertyName}[\${$parameterName}] = \$value;\nreturn \$this;");
return $setterGenerator;
}
示例11: __construct
/**
* 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;');
}
示例12: create
/**
* 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;
}
示例13: __construct
/**
* 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;');
}
示例14: __construct
/**
* 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");
}
示例15: generatePropertyAdder
public function generatePropertyAdder($propertyName, $withIndex = true, $proxyPropertyName = null)
{
$proxyPropertyName = $proxyPropertyName ?: $propertyName;
list($parameterName, $methodName) = $this->generatePropertyAdderName($proxyPropertyName);
$setterGenerator = clone $this->getPropertySetterGenerator();
$setterGenerator->setName($methodName);
if ($withIndex) {
$parameter = new CodeGenerator\ParameterGenerator();
$parameter->setName($parameterName);
$setterGenerator->setParameter($parameter);
}
$valueParameter = new CodeGenerator\ParameterGenerator();
$valueParameter->setName('value');
$setterGenerator->setParameter($valueParameter);
if ($withIndex) {
$setterGenerator->setBody("\$this->{$propertyName}[\${$parameterName}] = \$value;\nreturn \$this;");
} else {
$setterGenerator->setBody("\$this->{$propertyName}[] = \$value;\nreturn \$this;");
}
return $setterGenerator;
}