public function testGetPath()
 {
     $config = new Config();
     $config->setModule('User');
     $configWriter = new ConfigWriter($config);
     $this->assertEquals('module/User/config/service.config.php', $configWriter->getPath());
 }
 public function getConfig()
 {
     $config = new Config();
     $config->setModule('User');
     $config->setName('Group');
     return $config;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = new Config();
     $config->setBasePath(getcwd());
     $config->setFromArray($input->getArguments());
     $config->setFromArray(array('bare' => $input->getOption('bare')));
     $moduleConfig = new ConfigWriter($config);
     $state = new State($moduleConfig);
     $builder = new FullContainer($config);
     $builder->prepare($state);
     $builder->build($state);
     $writeState = new State($moduleConfig);
     $models = array('service' => $state->getServiceModel(), 'factory' => $state->getModel('service-factory'), 'trait' => $state->getModel('service-trait'), 'test' => $state->getModel('service-test'));
     foreach (array_keys($models) as $key) {
         if ($input->getOption('no-' . $key)) {
             $models[$key] = false;
         }
         if ($input->getOption('only-' . $key)) {
             foreach (array_keys($models) as $index) {
                 if ($key != $index) {
                     $models[$index] = false;
                 }
             }
         }
     }
     foreach ($models as $model) {
         if ($model) {
             $writeState->addModel($model);
         }
     }
     $writer = new ModelWriter($config);
     $writer->write($writeState, $output);
     $moduleConfig->save($output);
 }
Example #4
0
 /**
  * Build generators
  *
  * @param State|State $state
  */
 public function build(State $state)
 {
     $model = $state->getModel($this->name);
     $data = file_get_contents(SCAFFOLD_ROOT . "/data/template/" . $this->name);
     $data = str_replace('__NAMESPACE_PLACEHOLDER__', ucfirst($this->config->getModule()), $data);
     $model->setGenerator(new BinGenerator($data));
 }
Example #5
0
 protected function getClassDocBlock(State $state)
 {
     $repository = $state->getRepositoryModel()->getName();
     $doc = new DocBlockGenerator();
     $doc->setTag(new Tag\GenericTag('ORM\\Entity(repositoryClass="' . $repository . '")'));
     $doc->setTag(new Tag\GenericTag('ORM\\Table(name="' . strtolower($this->config->getName()) . '")'));
     return $doc;
 }
 /**
  * Prepare config
  *
  * @param InputInterface $input
  */
 protected function prepareConfig(InputInterface $input)
 {
     $this->config = new Config();
     $this->config->setBasePath(getcwd());
     $this->config->setFromArray($input->getArguments());
     $this->config->setFromArray($input->getOptions());
     $this->configWriter = new ConfigWriter($this->config);
 }
Example #7
0
 /**
  * @return string
  */
 public function getPath()
 {
     $builder = new PathBuilder($this->config);
     $builder->setModule($this->config->getModule());
     $builder->addPart('config');
     $builder->addPart('service.config');
     return $builder->getRawPath();
 }
 public function testGetModuleBaseOnBare()
 {
     $config = new Config();
     $config->setBare(true);
     $builder = new PathBuilder($config);
     $builder->setModule('user');
     $this->assertSame('', $builder->getModuleBase());
 }
 /**
  * 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);
 }
 /**
  * Prepare models
  *
  * @param State|\Scaffold\State $state
  */
 public function prepare(State $state)
 {
     $model = new Model();
     $name = $this->buildNamespace()->addPart($this->config->getModule())->addPart('Repository')->addPart($this->config->getName() . 'RepositoryTrait')->getNamespace();
     $path = $this->buildPath()->setModule($this->config->getModule())->addPart('Repository')->addPart($this->config->getName() . 'RepositoryTrait')->getSourcePath();
     $model->setName($name);
     $model->setPath($path);
     $state->addModel($model, 'repository-trait');
     $this->model = $model;
 }
 /**
  * @param State|State $state
  */
 public function prepare(State $state)
 {
     $model = new Model();
     $name = $this->buildNamespace()->addPart($this->config->getModule() . 'Test')->addPart('Service')->addPart($this->config->getName() . 'ServiceTest')->getNamespace();
     $path = $this->buildPath()->setModule($this->config->getModule())->addPart('Service')->addPart($this->config->getName() . 'Service')->getTestPath();
     $model->setName($name);
     $model->setPath($path);
     $state->addModel($model, 'service-test');
     $this->model = $model;
 }
 /**
  * Prepare models
  *
  * @param State|\Scaffold\State $state
  */
 public function prepare(State $state)
 {
     $model = new Model();
     $name = $this->buildNamespace()->addPart($this->config->getModule())->addPart('Form')->addPart($this->config->getName() . 'FormFactory')->getNamespace();
     $path = $this->buildPath()->setModule($this->config->getModule())->addPart('Form')->addPart($this->config->getName() . 'FormFactory')->getSourcePath();
     $model->setName($name);
     $model->setPath($path);
     $config = array('service_manager' => array('factories' => array($model->getServiceName() => $name)));
     $model->setServiceConfig($config);
     $state->addModel($model, 'form-factory');
 }
Example #13
0
 /**
  * Build method factory
  *
  * @param ClassGenerator  $generator
  * @param \Scaffold\State $state
  */
 public function buildFactory(ClassGenerator $generator, State $state)
 {
     $repository = ucfirst($state->getRepositoryModel()->getClassName());
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new Tag\GenericTag('return', $this->config->getName()));
     $factory = new MethodGenerator();
     $factory->setDocBlock($docBlock);
     $factory->setName('factory');
     $factory->setBody('return $this->get' . $repository . '()->factory();');
     $generator->addMethodFromGenerator($factory);
 }
Example #14
0
 /**
  * Build generators
  *
  * @param State|State $state
  */
 public function build(State $state)
 {
     $model = $state->getModel('module');
     if ($this->config->getBare()) {
         $data = file_get_contents(SCAFFOLD_ROOT . "/data/template/src/Module.bare.php");
     } else {
         $data = file_get_contents(SCAFFOLD_ROOT . "/data/template/src/Module.php");
     }
     $data = str_replace('__NAMESPACE_PLACEHOLDER__', ucfirst($this->config->getModule()), $data);
     $data = substr($data, 7);
     $model->setGenerator(new RawGenerator($data));
 }
 /**
  * Prepare models
  *
  * @param State|State $state
  */
 public function prepare(State $state)
 {
     $filename = $this->config->getName() . 'Controller';
     $model = new Model();
     $name = $this->buildNamespace()->addPart($this->config->getModule())->addPart('Controller')->addPart($filename)->getNamespace();
     $path = $this->buildPath()->setModule($this->config->getModule())->addPart('Controller')->addPart($filename)->getSourcePath();
     $model->setName($name);
     $model->setPath($path);
     $config = array('controllers' => array('invokables' => array($model->getServiceName() => $model->getName())));
     $model->setServiceConfig($config);
     $state->addModel($model, 'controller');
 }
Example #16
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = new Config();
     $config->setBasePath(getcwd());
     $config->setFromArray($input->getArguments());
     $config->setFromArray($input->getOptions());
     $moduleConfig = new ConfigWriter($config);
     $state = new State($moduleConfig);
     $builder = new ModuleContainer($config);
     $builder->prepare($state);
     $builder->build($state);
     $writer = new ModelWriter($config);
     $writer->write($state, $output);
 }
Example #17
0
 /**
  * @param Config $config
  */
 public function __construct(Config $config)
 {
     $this->addBuilder(new Service\ServiceBuilder($config));
     $this->addBuilder(new Service\ServiceFactoryBuilder($config));
     $this->addBuilder(new Service\ServiceTraitBuilder($config));
     $this->addBuilder(new Service\ServiceTestBuilder($config));
     $this->addBuilder(new Entity\EntityBuilder($config));
     $this->addBuilder(new Entity\EntityTestBuilder($config));
     $this->addBuilder(new Repository\RepositoryBuilder($config));
     $this->addBuilder(new Repository\RepositoryTraitBuilder($config));
     $this->addBuilder(new Form\FormFactoryBuilder($config));
     $this->addBuilder(new ExceptionContainer($config));
     if ($config->getRest()) {
         $this->addBuilder(new Controller\RESTControllerBuilder($config));
     } else {
         $this->addBuilder(new Controller\ControllerBuilder($config));
     }
 }
 /**
  * @param Config $config
  */
 public function __construct(Config $config)
 {
     $this->addBuilder(new Module\ModuleBuilder($config));
     $this->addBuilder(new Module\ConfigBuilder($config, 'config/module.config.php'));
     $this->addBuilder(new Module\ConfigBuilder($config, 'config/service.config.php'));
     $this->addBuilder(new Module\ConfigBuilder($config, 'config/router.config.php'));
     $this->addBuilder(new Module\ConfigBuilder($config, 'config/navigation.config.php'));
     $this->addBuilder(new Module\ConfigBuilder($config, 'config/auth.config.php'));
     $this->addBuilder(new Module\ConfigBuilder($config, 'config/assetic.config.php'));
     $this->addBuilder(new Module\TestBuilder($config, 'test/bootstrap.php'));
     $this->addBuilder(new Module\TestBuilder($config, 'test/TestConfig.php.dist'));
     if ($config->getBare()) {
         $this->addBuilder(new Module\RootBuilder($config, 'Module.php'));
         $this->addBuilder(new Module\RootBuilder($config, 'phpunit.xml'));
         $this->addBuilder(new Module\RootBuilder($config, 'composer.json'));
         $this->addBuilder(new Module\RootBuilder($config, '.gitignore'));
     } else {
         $this->addBuilder(new Module\TestBuilder($config, 'test/phpunit.xml'));
     }
 }
Example #19
0
 /**
  * @param $pathToWrite
  * @param  string            $data
  * @param  OutputInterface   $output
  * @throws \RuntimeException
  */
 protected function writeData($pathToWrite, $data, OutputInterface $output)
 {
     $path = realpath($this->config->getBasePath());
     if (!$path) {
         throw new \RuntimeException('Base path not specify');
     }
     $path .= '/' . $pathToWrite;
     $directory = dirname($path);
     if (!file_exists($directory)) {
         if (!mkdir($directory, 0777, true)) {
             throw new \RuntimeException('Can\'t create directory "' . $directory . '"');
         }
     }
     if (!is_writable($directory)) {
         throw new \RuntimeException('Can\'t write to directory "' . $directory . '"');
     }
     if (file_put_contents($path, $data) === false) {
         throw new \RuntimeException('Can\'t write to file "' . $path . '"');
     }
     $output->writeln('<info>write</info>: ' . $path);
 }