Inheritance: extends Zend\Code\Generator\AbstractGenerator
 /**
  * @interitdoc
  */
 public function __invoke($name, $namespace, $classToExtend, $fileDocBlock = null)
 {
     $interfaces = $this->getImplementedInterfaces();
     $properties = $this->getClassProperties();
     $flags = $this->getClassFlags();
     $methods = $this->getMethods($name);
     $traits = $this->getTraits();
     // getUses() must called at the end to allow other methods to add import namespaces directives
     $uses = $this->getUses();
     $fileDocBlock = new DocBlockGenerator($fileDocBlock);
     if ($classToExtend) {
         $uses[] = ltrim($classToExtend, '\\');
         $classToExtend = substr($classToExtend, strrpos($classToExtend, '\\') + 1);
     }
     switch (get_class($this)) {
         case 'Prooph\\Cli\\Code\\Generator\\CommandHandler':
             $className = $name . 'Handler';
             break;
         case 'Prooph\\Cli\\Code\\Generator\\CommandHandlerFactory':
             $className = $name . 'HandlerFactory';
             break;
         default:
             $className = $name;
             break;
     }
     $class = new ClassGenerator($className, $namespace, $flags, $classToExtend, $interfaces, $properties, $methods, $this->getClassDocBlock($name));
     foreach ($traits as $trait) {
         $class->addTrait($trait);
     }
     return new FileGenerator(['classes' => [$class], 'namespace' => $namespace, 'uses' => $uses, 'docBlock' => $fileDocBlock]);
 }
 /**
  * @param $version
  * @param $api
  *
  * @return string
  */
 private function generateFileContent($version, $api)
 {
     $docBlock = new DocBlockGenerator('SellerCenter SDK Version Class', 'This file is auto generated, please do not edit it manually!!!');
     $properties = [new PropertyGenerator('VERSION_NUMBER', $version, PropertyGenerator::FLAG_CONSTANT), new PropertyGenerator('API', $api, PropertyGenerator::FLAG_CONSTANT)];
     $class = new ClassGenerator('Version', 'SellerCenter\\SDK', null, null, [], $properties, [], $docBlock);
     return $class->generate();
 }
Example #3
0
 private function writeParamFile()
 {
     $file = $this->path . DIRECTORY_SEPARATOR . 'Params.php';
     if (file_exists($file) && class_exists($this->namespace . '\\Params')) {
         $class = new ClassReflection($this->namespace . '\\Params');
         $paramsClass = ClassGenerator::fromReflection($class);
     } else {
         $paramsClass = new ClassGenerator('Params', $this->namespace, null, 'OpenStack\\Common\\Api\\AbstractParams');
     }
     foreach ($this->operations as $operation) {
         $params = $operation['params'];
         if (empty($params)) {
             continue;
         }
         foreach ($params as $paramName => $paramVal) {
             $name = $paramName . ucfirst($paramVal['location']);
             if ($paramsClass->hasMethod($name)) {
                 continue;
             }
             $body = sprintf("return %s;", $this->arrayEncoder->encode($paramVal, ['array.align' => true]));
             $body = str_replace("'\$", '$', $body);
             $body = str_replace("()'", '()', $body);
             $docblock = new DocBlockGenerator(sprintf("Returns information about %s parameter", $paramName), null, [new ReturnTag(['array'])]);
             $paramsClass->addMethod($name, [], MethodGenerator::FLAG_PUBLIC, $body, $docblock);
         }
     }
     $output = sprintf("<?php\n\n%s", $paramsClass->generate());
     file_put_contents($file, $output);
 }
 private function updateModuleConfig()
 {
     $dir = getcwd() . '/module/' . ucfirst($this->db) . '/config/';
     $filename = $dir . 'module.config.php';
     $moduleConfigArray = (include $filename);
     $keyCtrl = $this->getModuleName() . '\\' . $this->subDir . '\\' . $this->getClassName();
     if (!array_key_exists($keyCtrl, $moduleConfigArray['controllers']['invokables'])) {
         $moduleConfigArray['controllers']['invokables'][$keyCtrl] = $this->getModuleName() . '\\' . $this->subDir . '\\' . $this->getClassName();
     }
     $keyRoute = $this->tableName;
     if (!array_key_exists($keyRoute, $moduleConfigArray['router']['routes'])) {
         $moduleConfigArray['router']['routes'][$keyRoute] = array('type' => 'segment', 'options' => array('route' => '/' . $keyRoute . '[/:id]', 'defaults' => array('controller' => $keyCtrl)));
     }
     $newContent = '<? return ' . var_export($moduleConfigArray, true) . ';';
     // dir doesn't exist, make it
     if (!is_dir($dir)) {
         mkdir($dir);
         // ** Generate Module.php class ** //
         // Definitions
         $classGenerator = new ClassGenerator();
         $classGenerator->setName('Module');
         $classGenerator->setNamespaceName(ucfirst($this->db));
         // Methods
         $classGenerator->addMethods(array(new MethodGenerator('getConfig', [], MethodGenerator::FLAG_PUBLIC, "return include __DIR__ . '/config/module.config.php';"), new MethodGenerator('getAutoloaderConfig', [], MethodGenerator::FLAG_PUBLIC, "return array(\r                            'Zend\\Loader\\StandardAutoloader' => array(\r                                'namespaces' => array(\r                                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,\r                                ),\r                            ),\r                        );")));
         $this->fileCreate(getcwd() . '/module/' . ucfirst($this->db) . '/Module.php', $classGenerator);
         // ** Generate Module.php class ** //
     }
     file_put_contents($filename, $newContent);
 }
 /**
  * generate
  *
  * @param string $className
  * @param null   $namespace
  *
  * @return ClassGenerator
  */
 protected function generate($className, $namespace = null)
 {
     $exceptionClass = MigrationException::class;
     $class = new ClassGenerator($className, $namespace, null, 'AbstractMigration', [], [], [new MethodGenerator('up', [], 'public', "throw new \\{$exceptionClass}(\"Not implemented.\");", new DocBlockGenerator('Executed when migrating upwards.', 'TODO: replace body.')), new MethodGenerator('down', [], 'public', "throw new \\{$exceptionClass}(\"Not implemented.\");", new DocBlockGenerator('Executed when migrating downwards.', 'TODO: replace body.'))], new DocBlockGenerator("Migration {$className}"));
     $class->addUse(AbstractMigration::class);
     return $class;
 }
 public function getClass()
 {
     $classGenerator = new ClassGenerator($this->collection, $this->namespace);
     $classGenerator->addUse('ArangoOdm\\Document', 'ArangoDoc');
     $classGenerator->setExtendedClass('ArangoDoc');
     $classGenerator->addMethods($this->getMethods());
     return '<?php' . "\n\n" . $classGenerator->generate();
 }
 /**
  * @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);
 }
 private function generate($version)
 {
     $generator = new ClassGenerator();
     $docblock = DocBlockGenerator::fromArray(array('shortDescription' => 'PDO Simple Migration Class', 'longDescription' => 'Add your queries below'));
     $generator->setName('PDOSimpleMigration\\Migrations\\Migration' . $version)->setExtendedClass('AbstractMigration')->addUse('PDOSimpleMigration\\Library\\AbstractMigration')->setDocblock($docblock)->addProperties(array(array('description', 'Migration description', PropertyGenerator::FLAG_STATIC)))->addMethods(array(MethodGenerator::fromArray(array('name' => 'up', 'parameters' => array(), 'body' => '//$this->addSql(/*Sql instruction*/);', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Migrate up', 'longDescription' => null)))), MethodGenerator::fromArray(array('name' => 'down', 'parameters' => array(), 'body' => '//$this->addSql(/*Sql instruction*/);', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Migrate down', 'longDescription' => null))))));
     $file = FileGenerator::fromArray(array('classes' => array($generator)));
     return $file->generate();
 }
 /**
  * Build method factory
  *
  * @param ClassGenerator $generator
  */
 public function buildFactory(ClassGenerator $generator)
 {
     $docBlock = new DocBlockGenerator('@return ' . $this->config->getName());
     $factory = new MethodGenerator();
     $factory->setDocBlock($docBlock);
     $factory->setName('factory');
     $factory->setBody('return new ' . $this->config->getName() . '();');
     $generator->addMethodFromGenerator($factory);
 }
Example #10
0
 /**
  * @param        $name
  * @param        $namespace
  * @param        $uses
  * @param string $extends
  * @param array  $implements
  *
  * @return ClassGenerator
  */
 public static function classGen($name, $namespace, $uses = [], $extends = '', $implements = [])
 {
     $class = new ClassGenerator();
     $class->setName($name)->setNamespaceName($namespace)->setExtendedClass($extends)->setImplementedInterfaces($implements)->setIndentation(Generator::$indentation);
     foreach ($uses as $use) {
         $class->addUse($use);
     }
     return $class;
 }
 /**
  * @param ContextInterface $context
  * @param ClassGenerator   $class
  * @param Property         $property
  *
  * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
  */
 private function implementGetResult(ContextInterface $context, ClassGenerator $class, Property $property)
 {
     $useAssembler = new UseAssembler($this->wrapperClass ?: ResultInterface::class);
     if ($useAssembler->canAssemble($context)) {
         $useAssembler->assemble($context);
     }
     $methodName = 'getResult';
     $class->removeMethod($methodName);
     $class->addMethodFromGenerator(MethodGenerator::fromArray(['name' => $methodName, 'parameters' => [], 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, 'body' => $this->generateGetResultBody($property), 'docblock' => DocBlockGenerator::fromArray(['tags' => [['name' => 'return', 'description' => $this->generateGetResultReturnTag($property)]]])]));
 }
Example #12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $ymlParser = new Parser();
     $config = $ymlParser->parse(file_get_contents($input->getOption('config')));
     $path = $config['path'];
     $name = $input->getArgument('name');
     $classGen = new ClassGenerator();
     $content = $classGen->setName($name)->addMethod('getUpSql', array(), MethodGenerator::FLAG_PUBLIC, 'return \'\';')->addMethod('getDownSql', array(), MethodGenerator::FLAG_PUBLIC, 'return \'\';')->addMethod('preUp')->addMethod('postUp')->addMethod('preDown')->addMethod('postDown')->generate();
     file_put_contents(sprintf('%s/%s_%s.php', $path, date('YmdHis'), $name), sprintf("<?php\n%s", $content));
 }
Example #13
0
 public function generate()
 {
     $gen = new ClassGenerator($this->name);
     $fnGetter = $this->fnGetter;
     foreach ($this->options["properties"] as $prop => $type) {
         $c = ucfirst($prop);
         $gen->addProperty($prop, null, PropertyGenerator::FLAG_PRIVATE);
         $gen->addMethod("get" . $c, [], MethodGenerator::FLAG_PUBLIC, $fnGetter($prop, $type), "???");
     }
     return $gen->generate();
 }
 /**
  * Write generated code to disk and return the class code
  *
  * {@inheritDoc}
  */
 public function generate(ClassGenerator $classGenerator)
 {
     $className = trim($classGenerator->getNamespaceName(), '\\') . '\\' . trim($classGenerator->getName(), '\\');
     $generatedCode = $classGenerator->generate();
     $fileName = $this->fileLocator->getProxyFileName($className);
     $tmpFileName = $fileName . '.' . uniqid('', true);
     // renaming files is necessary to avoid race conditions when the same file is written multiple times
     // in a short time period
     file_put_contents($tmpFileName, "<?php\n\n" . $generatedCode);
     rename($tmpFileName, $fileName);
     return $generatedCode;
 }
Example #15
0
 /**
  * @param \ReflectionClass $originalClass
  * @param ClassGenerator $classGenerator
  */
 public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     $classGenerator->setExtendedClass('\\' . $originalClass->getName());
     if ($originalClass->isSubclassOf(Collection::class)) {
         $reflectionMethod = new \ReflectionMethod($originalClass->getName(), 'getMetadata');
         $className = $originalClass->getName();
         $metadata = $reflectionMethod->invoke(new $className());
         foreach ($metadata as $fieldName => $mappingClass) {
             $classGenerator->addMethod('get' . ucfirst($fieldName), [], MethodGenerator::FLAG_PUBLIC, '$this->mapProperty(\'' . $fieldName . '\');' . "\n" . 'return parent::get' . ucfirst($fieldName) . '();', '@return ' . $mappingClass);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $interfaces = array('ProxyManager\\Proxy\\NullObjectInterface');
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
         $classGenerator->addMethodFromGenerator(NullObjectMethodInterceptor::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())));
     }
     ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, new Constructor($originalClass));
 }
 /**
  * Write generated code to disk and return the class code
  *
  * {@inheritDoc}
  */
 public function generate(ClassGenerator $classGenerator)
 {
     $className = trim($classGenerator->getNamespaceName(), '\\') . '\\' . trim($classGenerator->getName(), '\\');
     $generatedCode = $classGenerator->generate();
     $fileName = $this->fileLocator->getProxyFileName($className);
     set_error_handler($this->emptyErrorHandler);
     try {
         $this->writeFile("<?php\n\n" . $generatedCode, $fileName);
     } catch (FileNotWritableException $fileNotWritable) {
         restore_error_handler();
         throw $fileNotWritable;
     }
     restore_error_handler();
     return $generatedCode;
 }
 /**
  * Evaluates the generated code before returning it
  *
  * {@inheritDoc}
  */
 public function generate(ClassGenerator $classGenerator)
 {
     $code = $classGenerator->generate();
     if (!$this->canEval) {
         // @codeCoverageIgnoreStart
         $fileName = sys_get_temp_dir() . '/EvaluatingGeneratorStrategy.php.tmp.' . uniqid('', true);
         file_put_contents($fileName, "<?php\n" . $code);
         require $fileName;
         unlink($fileName);
         return $code;
         // @codeCoverageIgnoreEnd
     }
     eval($code);
     return $code;
 }
Example #19
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // output message
     $this->console->writeTaskLine('task_delete_action_method_deleting');
     // set controller file and action method
     $controllerFile = $this->params->controllerDir . '/' . $this->params->paramController . 'Controller.php';
     // get file and class reflection
     $fileReflection = new FileReflection($controllerFile, true);
     $classReflection = $fileReflection->getClass($this->params->paramModule . '\\' . $this->params->config['namespaceController'] . '\\' . $this->params->paramController . 'Controller');
     // setup class generator with reflected class
     $class = ClassGenerator::fromReflection($classReflection);
     // set method to check
     $actionMethod = strtolower($this->params->paramAction) . 'action';
     // check for action method
     if (!$class->hasMethod($actionMethod)) {
         $this->console->writeFailLine('task_delete_action_method_not_exists', [$this->console->colorize($this->params->paramAction, Color::GREEN), $this->console->colorize($this->params->paramController, Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]);
         return 1;
     }
     // fix namespace usage
     $class->addUse('Zend\\Mvc\\Controller\\AbstractActionController');
     $class->addUse('Zend\\View\\Model\\ViewModel');
     $class->setExtendedClass('AbstractActionController');
     $class->removeMethod($actionMethod);
     // create file
     $file = new ClassFileGenerator($class->generate(), $this->params->config);
     // write file
     file_put_contents($controllerFile, $file->generate());
     return 0;
 }
Example #20
0
 /**
  * @param ClassGenerator $classGenerator
  * @return string
  * @throws FileNotWritableException
  */
 public function generate(ClassGenerator $classGenerator)
 {
     $className = trim($classGenerator->getNamespaceName(), '\\') . '\\' . trim($classGenerator->getName(), '\\');
     $generatedCode = $classGenerator->generate();
     $fileName = $this->file->getProxyFileName($className);
     set_error_handler(function () {
     });
     try {
         $this->write("<?php\n\n" . $generatedCode, $fileName);
     } catch (FileNotWritableException $exception) {
         throw $exception;
     } finally {
         restore_error_handler();
     }
     return $fileName;
 }
Example #21
0
 /**
  * {@inheritDoc}
  */
 public function setImplementedInterfaces(array $interfaces) : self
 {
     foreach ($interfaces as &$interface) {
         $interface = '\\' . trim($interface, '\\');
     }
     return parent::setImplementedInterfaces($interfaces);
 }
 /**
  * @param string $className
  * @param string $moduleName
  * @param string $entityModule
  * @param string $entityClass
  * @param array  $loadedTables
  * @param array  $config
  */
 public function __construct($className, $moduleName, $entityModule, $entityClass, array $loadedTables = [], array $config = [])
 {
     // set config data
     $this->config = $config;
     $tableName = $this->filterCamelCaseToUnderscore(str_replace('Entity', '', $entityClass));
     $loadedTable = $loadedTables[$tableName];
     $this->foreignKeys = [];
     /** @var ConstraintObject $foreignKey */
     foreach ($loadedTable['foreignKeys'] as $foreignKey) {
         foreach ($foreignKey->getColumns() as $column) {
             $this->foreignKeys[$column] = $foreignKey;
         }
     }
     // call parent constructor
     parent::__construct($className . 'Factory', $moduleName . '\\' . $this->config['namespaceForm']);
     // add namespace for hydrator
     $this->addUse($entityModule . '\\' . $this->config['namespaceHydrator'] . '\\' . $this->filterUnderscoreToCamelCase($tableName) . 'Hydrator');
     // add namespace for input filter
     $this->addUse($entityModule . '\\' . $this->config['namespaceInputFilter'] . '\\' . $this->filterUnderscoreToCamelCase($tableName) . 'InputFilter');
     // add namespaces for foreign key tables
     foreach ($this->foreignKeys as $foreignKey) {
         $this->addUse($entityModule . '\\' . $this->config['namespaceStorage'] . '\\' . $this->filterUnderscoreToCamelCase($foreignKey->getReferencedTableName()) . 'Storage');
     }
     // add used namespaces and extended classes
     $this->addUse('Zend\\InputFilter\\InputFilterPluginManager');
     $this->addUse('Zend\\ServiceManager\\FactoryInterface');
     $this->addUse('Zend\\ServiceManager\\ServiceLocatorAwareInterface');
     $this->addUse('Zend\\ServiceManager\\ServiceLocatorInterface');
     $this->addUse('Zend\\Hydrator\\HydratorPluginManager');
     $this->setImplementedInterfaces(['FactoryInterface']);
     // add methods
     $this->addCreateServiceMethod($className, $moduleName, $entityModule, $entityClass);
     $this->addClassDocBlock($className);
 }
 /**
  * @param string $className
  * @param string $moduleName
  * @param string $namespaceName
  * @param string $tableName
  * @param array  $loadedTable
  * @param array  $config
  */
 public function __construct($className, $moduleName, $namespaceName, $tableName, array $loadedTable = [], array $config = [])
 {
     // set config data
     $this->config = $config;
     $this->loadedTable = $loadedTable;
     $this->foreignKeys = [];
     /** @var ConstraintObject $foreignKey */
     foreach ($this->loadedTable['foreignKeys'] as $foreignKey) {
         foreach ($foreignKey->getColumns() as $column) {
             $this->foreignKeys[$column] = $foreignKey;
         }
     }
     // call parent constructor
     parent::__construct($className . 'Factory', $moduleName . '\\' . $namespaceName);
     // add namespaces for foreign key tables
     foreach ($this->foreignKeys as $foreignKey) {
         $this->addUse($moduleName . '\\' . $this->config['namespaceStorage'] . '\\' . StaticFilter::execute($foreignKey->getReferencedTableName(), 'Word\\UnderscoreToCamelCase') . 'Storage');
     }
     // add used namespaces and extended classes
     $this->addUse('Zend\\ServiceManager\\FactoryInterface');
     $this->addUse('Zend\\ServiceManager\\ServiceLocatorAwareInterface');
     $this->addUse('Zend\\ServiceManager\\ServiceLocatorInterface');
     $this->setImplementedInterfaces(['FactoryInterface']);
     // add methods
     $this->addCreateServiceMethod($className, $moduleName);
     $this->addClassDocBlock($className);
 }
 /**
  * @inherit Zend\Code\Generator\GeneratorInterface
  */
 public function generate()
 {
     $output = '';
     $indent = $this->getIndentation();
     $traits = $this->getTraits();
     if (empty($traits)) {
         return $output;
     }
     $output .= $indent . 'use ' . implode(', ', $traits);
     $aliases = $this->getTraitAliases();
     $overrides = $this->getTraitOverrides();
     if (empty($aliases) && empty($overrides)) {
         $output .= ";" . self::LINE_FEED . self::LINE_FEED;
         return $output;
     }
     $output .= ' {' . self::LINE_FEED;
     foreach ($aliases as $method => $alias) {
         $visibility = null !== $alias['visibility'] ? current(Reflection::getModifierNames($alias['visibility'])) . ' ' : '';
         // validation check
         if ($this->classGenerator->hasMethod($alias['alias'])) {
             throw new Exception\RuntimeException(sprintf('Generation Error: Aliased method %s already exists on this class', $alias['alias']));
         }
         $output .= $indent . $indent . $method . ' as ' . $visibility . $alias['alias'] . ';' . self::LINE_FEED;
     }
     foreach ($overrides as $method => $insteadofTraits) {
         foreach ($insteadofTraits as $insteadofTrait) {
             $output .= $indent . $indent . $method . ' insteadof ' . $insteadofTrait . ';' . self::LINE_FEED;
         }
     }
     $output .= self::LINE_FEED . $indent . '}' . self::LINE_FEED . self::LINE_FEED;
     return $output;
 }
Example #25
0
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     $interfaces = array('ProxyManager\\Proxy\\NullObjectInterface');
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         foreach ($originalClass->getInterfaceNames() as $name) {
             $interfaces[] = $name;
         }
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
         $classGenerator->addMethodFromGenerator(NullObjectMethodInterceptor::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())));
     }
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass));
 }
 /**
  * @param string $controllerName
  * @param string $moduleName
  * @param string $entityModule
  * @param string $entityClass
  * @param array  $config
  */
 public function __construct($controllerName, $moduleName, $entityModule, $entityClass, array $config = [])
 {
     // set config data
     $this->config = $config;
     // call parent constructor
     parent::__construct($controllerName . 'Factory', $moduleName . '\\' . $this->config['namespaceController']);
     // prepare repository params
     $repositoryClass = str_replace('Entity', '', $entityClass) . 'Repository';
     $repositoryNamespace = $entityModule . '\\' . $this->config['namespaceRepository'] . '\\' . $repositoryClass;
     // prepare form params
     if (in_array($controllerName, ['CreateController', 'UpdateController'])) {
         $formClass = str_replace('Entity', '', $entityClass) . 'DataForm';
         $formNamespace = $moduleName . '\\' . $this->config['namespaceForm'] . '\\' . $formClass;
         $this->addUse($formNamespace);
     } elseif (in_array($controllerName, ['DeleteController'])) {
         $formClass = str_replace('Entity', '', $entityClass) . 'DeleteForm';
         $formNamespace = $moduleName . '\\' . $this->config['namespaceForm'] . '\\' . $formClass;
         $this->addUse($formNamespace);
     }
     // add used namespaces and extended classes
     $this->addUse($repositoryNamespace);
     $this->addUse('Zend\\ServiceManager\\FactoryInterface');
     $this->addUse('Zend\\ServiceManager\\ServiceLocatorAwareInterface');
     $this->addUse('Zend\\ServiceManager\\ServiceLocatorInterface');
     $this->setImplementedInterfaces(['FactoryInterface']);
     // add methods
     $this->addCreateServiceMethod($controllerName, $moduleName, $entityModule, $entityClass);
     $this->addClassDocBlock($controllerName);
 }
Example #27
0
 /**
  * @param array $config
  */
 public function __construct(array $config = [])
 {
     // set config data
     $this->config = $config;
     // call parent constructor
     parent::__construct();
 }
 /**
  * {@inheritDoc}
  */
 public function __invoke(Identifier $identifier)
 {
     if (!($name = $this->getInternalReflectionClassName($identifier))) {
         return null;
     }
     return new EvaledLocatedSource("<?php\n\n" . ClassGenerator::fromReflection(new ClassReflection($name))->generate());
 }
 /**
  * @param array  $config
  * @param string $baseHydrator
  */
 public function __construct(array $config = [], $baseHydrator = 'ClassMethods')
 {
     // set config data and base hydrator
     $this->config = $config;
     $this->baseHydrator = $baseHydrator;
     // call parent constructor
     parent::__construct();
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $interfaces = [RemoteObjectInterface::class];
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         $classGenerator->setExtendedClass($originalClass->getName());
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     $classGenerator->addPropertyFromGenerator($adapter = new AdapterProperty());
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map(function (ReflectionMethod $method) use($adapter, $originalClass) : RemoteObjectMethod {
         return RemoteObjectMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $adapter, $originalClass);
     }, ProxiedMethodsFilter::getProxiedMethods($originalClass, ['__get', '__set', '__isset', '__unset'])), [new StaticProxyConstructor($originalClass, $adapter), new MagicGet($originalClass, $adapter), new MagicSet($originalClass, $adapter), new MagicIsset($originalClass, $adapter), new MagicUnset($originalClass, $adapter)]));
 }