作者:cyberrebel
项目:arango-od
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;
}
作者:bitexper
项目:disc
/**
* 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);
}
作者:boyhageman
项目:framewor
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();
}
作者:boyhageman
项目:cru
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();
}
作者:andywooya
项目:ProxyManage
/**
* 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;');
}
作者:bitexper
项目:disc
/**
* 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() . ']);');
}
作者:CHRISTOPHERVANDOMM
项目:zf2comple
/**
* @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;
}
作者:Robert-Xi
项目:php-framework-benchmar
/**
* @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;
}
作者:jbaffor
项目:ProxyManage
/**
* 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;');
}
作者:vmalinovski
项目:CallFire-PHP-SD
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;
}
作者:jbaffor
项目:ProxyManage
/**
* 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;');
}
作者:spuy76
项目:sd
/**
* 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;
}
作者:andywooya
项目:ProxyManage
/**
* 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;');
}
作者:bitExper
项目:disc
/**
* 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");
}
作者:vmalinovski
项目:CallFire-PHP-SD
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;
}
作者:vmalinovski
项目:CallFire-PHP-SD
public function transform()
{
$classGenerator = $this->getService()->getClassGenerator();
if ($createContactBatch = $classGenerator->getMethod('CreateContactBatch')) {
$newMethod = new CodeGenerator\MethodGenerator();
$newMethod->setName($createContactBatch->getName());
$docblock = $createContactBatch->getDocBlock();
$docblock->setTag((new CodeGenerator\DocBlock\Tag\ParamTag())->setParamName('id')->setDataType('int'));
$newMethod->setDocBlock($docblock);
$parameters = $createContactBatch->getParameters();
$idParameter = new CodeGenerator\ParameterGenerator();
$idParameter->setName('id');
$createContactBatch->setParameter($idParameter);
$newMethod->setParameters(array("id" => $idParameter, "CreateContactBatch" => $parameters['CreateContactBatch']));
$body = $createContactBatch->getBody();
$body = str_replace('array()', 'array($id)', $body);
$newMethod->setBody($body);
$classGenerator->removeMethod('CreateContactBatch');
$classGenerator->addMethodFromGenerator($newMethod);
}
}
作者:postalservice1
项目:zend-cod
/**
* @param ParameterReflection $reflectionParameter
* @return ParameterGenerator
*/
public static function fromReflection(ParameterReflection $reflectionParameter)
{
$param = new ParameterGenerator();
$param->setName($reflectionParameter->getName());
if ($type = self::extractFQCNTypeFromReflectionType($reflectionParameter)) {
$param->setType($type);
}
$param->setPosition($reflectionParameter->getPosition());
$variadic = method_exists($reflectionParameter, 'isVariadic') && $reflectionParameter->isVariadic();
$param->setVariadic($variadic);
if (!$variadic && $reflectionParameter->isOptional()) {
try {
$param->setDefaultValue($reflectionParameter->getDefaultValue());
} catch (\ReflectionException $e) {
$param->setDefaultValue(null);
}
}
$param->setPassedByReference($reflectionParameter->isPassedByReference());
return $param;
}
作者:bitexper
项目:disc
/**
* 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);
}
作者:sizra
项目:weez-commo
public function getClassArrayRepresentation()
{
$this->data = $this->getData();
return array('name' => 'Manager', 'namespacename' => $this->data['_namespace'] . '\\Table', 'extendedclass' => $this->tableGatewayClass, 'flags' => ClassGenerator::FLAG_ABSTRACT, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Application Model DbTables', 'longDescription' => null, 'tags' => array(array('name' => 'package', 'description' => $this->data['_namespace']), array('name' => 'author', 'description' => $this->data['_author']), array('name' => 'copyright', 'description' => $this->data['_copyright']), array('name' => 'license', 'description' => $this->data['_license'])))), 'properties' => array(array('entity', null, PropertyGenerator::FLAG_PROTECTED), array('container', null, PropertyGenerator::FLAG_PROTECTED), PropertyGenerator::fromArray(array('name' => 'wasInTransaction', 'defaultvalue' => false, 'flags' => PropertyGenerator::FLAG_PROTECTED, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'True if we were already in a transaction when try to start a new one', 'longDescription' => '', 'tags' => array(new GenericTag('var', 'bool'))))))), 'methods' => array(array('name' => '__construct', 'parameters' => array(ParameterGenerator::fromArray(array('name' => 'adapter')), ParameterGenerator::fromArray(array('name' => 'entity', 'type' => 'Entity'))), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => '$this->adapter = $adapter;' . "\n" . '$this->entity = $entity;' . "\n" . '$this->featureSet = new Feature\\FeatureSet();' . "\n" . '$this->initialize();', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Constructor', 'longDescription' => null, 'tags' => array(new ParamTag('adapter', array('Adapter')), new ParamTag('entity', array('Entity')))))), array('name' => 'setContainer', 'parameters' => array(ParameterGenerator::fromArray(array('name' => 'c', 'type' => 'Container'))), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => '$this->container = $c;' . "\n" . 'return $this;', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Inject container', 'longDescription' => null, 'tags' => array(new ParamTag('c', array('Container')), new ReturnTag(array('datatype' => 'self')))))), array('name' => 'getContainer', 'parameters' => array(), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => 'return $this->container;', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => '', 'longDescription' => null, 'tags' => array(new ReturnTag(array('datatype' => 'Container')))))), array('name' => 'all', 'parameters' => array(), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => '$select = $this->select();' . '$result = array();' . PHP_EOL . 'foreach ($select as $v) {' . PHP_EOL . ' $result[] = $v->getArrayCopy();' . PHP_EOL . '}' . PHP_EOL . 'return $result;', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => '', 'longDescription' => null, 'tags' => array(new ReturnTag(array('datatype' => 'self')))))), array('name' => 'getPrimaryKeyName', 'parameters' => array(), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => 'return $this->id;', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => '', 'longDescription' => null, 'tags' => array(new ReturnTag(array('datatype' => 'array|string')))))), array('name' => 'getTableName', 'parameters' => array(), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => 'return $this->table;', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => '', 'longDescription' => null, 'tags' => array(new ReturnTag(array('datatype' => 'array|string')))))), array('name' => 'findBy', 'parameters' => array(ParameterGenerator::fromArray(array('name' => 'criteria', 'defaultvalue' => array(), 'type' => 'array')), ParameterGenerator::fromArray(array('name' => 'order', 'defaultvalue' => null)), ParameterGenerator::fromArray(array('name' => 'limit', 'defaultvalue' => null)), ParameterGenerator::fromArray(array('name' => 'offset', 'defaultvalue' => null)), ParameterGenerator::fromArray(array('name' => 'toEntity', 'defaultvalue' => false))), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => '$r = $this->sql->select()->where($criteria);' . PHP_EOL . 'if ($order) {' . PHP_EOL . ' $r->order($order);' . PHP_EOL . '}' . PHP_EOL . 'if ($limit) {' . PHP_EOL . ' $r->limit($limit);' . PHP_EOL . '}' . PHP_EOL . 'if ($offset) {' . PHP_EOL . ' $r->offset($offset);' . PHP_EOL . '}' . PHP_EOL . '$result = $this->selectWith($r)->toArray();' . PHP_EOL . 'if ($toEntity) {' . PHP_EOL . ' foreach($result as &$v){' . PHP_EOL . ' $entity = clone $this->entity;' . PHP_EOL . ' $v = $entity->exchangeArray($v);' . PHP_EOL . ' }' . PHP_EOL . '}' . PHP_EOL . 'return $result;' . PHP_EOL, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Find by criteria', 'longDescription' => null, 'tags' => array(new ParamTag('criteria', array('array'), 'Search criteria'), new ParamTag('order', array('string'), 'sorting option'), new ParamTag('limit', array('int'), 'limit option'), new ParamTag('offset', array('int'), 'offset option'), new ParamTag('toEntity', array('boolean'), 'return entity result'), new ReturnTag(array('array'), ''))))), array('name' => 'countBy', 'parameters' => array(ParameterGenerator::fromArray(array('name' => 'criteria', 'defaultvalue' => array(), 'type' => 'array'))), 'flags' => MethodGenerator::FLAG_PUBLIC, 'body' => '$r = $this->sql->select()->columns(array("count" => new Expression("count(*)")))->where($criteria);' . PHP_EOL . 'return (int)current($this->selectWith($r)->toArray())["count"];' . PHP_EOL, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Count by criteria', 'longDescription' => null, 'tags' => array(new ParamTag('criteria', array('array'), 'Criteria'), new ReturnTag(array('int'), ''))))), array('name' => 'deleteEntity', 'parameters' => array(ParameterGenerator::fromArray(array('name' => 'entity', 'type' => 'Entity')), 'useTransaction = true'), 'flags' => array(MethodGenerator::FLAG_PUBLIC, MethodGenerator::FLAG_ABSTRACT), 'body' => null, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Converts database column name to php setter/getter function name', 'longDescription' => null, 'tags' => array(new ParamTag('entity', array('Entity')), new ParamTag('useTransaction', array('boolean')), new ReturnTag(array('datatype' => 'int')))))), array('name' => 'beginTransaction', 'parameters' => array(), 'flags' => MethodGenerator::FLAG_PROTECTED, 'body' => <<<'BODY'
if ($this->adapter->getDriver()->getConnection()->inTransaction()) {
$this->wasInTransaction = true;
return;
}
$this->adapter->getDriver()->getConnection()->beginTransaction();
BODY
, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Begin a transaction', 'longDescription' => null, 'tags' => array()))), array('name' => 'rollback', 'parameters' => array(), 'flags' => MethodGenerator::FLAG_PROTECTED, 'body' => <<<'BODY'
if ($this->wasInTransaction) {
throw new \Exception('Inside transaction rollback call');
}
$this->adapter->getDriver()->getConnection()->rollback();
BODY
, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Rollback a transaction', 'longDescription' => null, 'tags' => array()))), array('name' => 'commit', 'parameters' => array(), 'flags' => MethodGenerator::FLAG_PROTECTED, 'body' => <<<'BODY'
if (!$this->wasInTransaction) {
$this->adapter->getDriver()->getConnection()->commit();
}
BODY
, 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => ' Commit a transaction', 'longDescription' => null, 'tags' => array())))));
}
作者:vmalinovski
项目:CallFire-PHP-SD
public function generatePropertySetter($property)
{
$property = lcfirst($property);
$methodName = 'set' . ucfirst($property);
$setterGenerator = clone $this->getPropertySetterGenerator();
$setterGenerator->setName($methodName);
$parameter = new CodeGenerator\ParameterGenerator();
$parameter->setName($property);
$setterGenerator->setParameter($parameter);
$setterGenerator->setBody("\$this->{$property} = \${$property};\nreturn \$this;");
return $setterGenerator;
}