Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * @var $schema Schema
      */
     $schema = $this->application->getStorage()->getSchema();
     $debug = $input->getArgument('debug') == true;
     $fs = new Filesystem();
     $fs->dumpFile($this->application->getProject()->getPath('build php Storage Master.php'), $this->fenom->render("master", array('schema' => $schema)));
     if ($debug) {
         echo '- master' . PHP_EOL;
     }
     foreach ($schema->getModels() as $model) {
         $modelGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Model', array('model' => $model));
         $modelSource = $modelGenerator->getCode();
         $path = $this->application->getProject()->getPath('build php Storage Model ' . $model->getClassName() . 'Base.php');
         $fs->dumpFile($path, $modelSource);
         $repositoryGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Repository', array('model' => $model));
         $repositorySource = $repositoryGenerator->getCode();
         $path = $this->application->getProject()->getPath('build php Storage Repository ' . $model->getClassName() . 'Repository.php');
         $fs->dumpFile($path, $repositorySource);
         if ($debug) {
             echo '- generate ' . $model->getClassName() . PHP_EOL;
         }
         //            if($model->hasOwnQuery()) {
         //                $fs->dumpFile(
         //                    $this->application->getPath('build php Storage Query ' . $model->class_name . 'Select.php'),
         //                    $this->application->getManager()->create('Cti\Storage\Generator\Select', array(
         //                        'model' => $model
         //                    ))
         //                );
         //            }
     }
 }
Exemple #2
0
 function init()
 {
     $this->name_many = String::pluralize($this->name);
     $this->class_name = String::convertToCamelCase($this->name);
     $this->class_name_many = String::pluralize($this->class_name);
     $this->repository_class = 'Storage\\Repository\\' . $this->class_name . 'Repository';
     $this->model_class = 'Storage\\Model\\' . $this->class_name . 'Base';
     $model_file = $this->application->getProject()->getPath('src php Model ' . $this->class_name . '.php');
     if (file_exists($model_file)) {
         $this->model_class = 'Model\\' . $this->class_name;
     }
     $repository_file = $this->application->getProject()->getPath('src php Repository ' . $this->class_name . '.php');
     if (file_exists($repository_file)) {
         $this->repository_class = 'Repository\\' . $this->class_name;
     }
     if (count($this->properties)) {
         $properties = $this->properties;
         $this->properties = array();
         foreach ($properties as $key => $config) {
             if ($config instanceof Model) {
                 $reference = $this->hasOne($config);
                 if (is_string($key)) {
                     $reference->usingAlias($key);
                 }
             } else {
                 $this->addProperty($key, $config);
             }
         }
     }
     if (!$this->getPk()) {
         $this->addBehaviour('id');
     }
 }
Exemple #3
0
 public function add($data)
 {
     $path = dirname($this->application->getProject()->getPath('')) . DIRECTORY_SEPARATOR . $data->path;
     if (!$this->manager->validProject($path)) {
         throw new \Exception("No valid project in path {$path}");
     }
     return $this->manager->addProject($data->nick, $path);
 }
Exemple #4
0
 public function warm(Application $application)
 {
     parent::warm($application);
     $fs = new Filesystem();
     $schema = $application->getStorage()->getSchema();
     $entities = array();
     foreach ($this->getClasses('Generator') as $class) {
         $reflection = Reflection::getReflectionClass($class);
         if (!$reflection->isAbstract() && $reflection->isSubclassOf('Cti\\Sencha\\Generator\\Generator')) {
             $entities[] = $reflection->getShortName();
         }
     }
     foreach ($schema->getModels() as $model) {
         foreach ($entities as $entity) {
             if ($model->hasBehaviour('link') && $entity != 'Model' && $entity != 'Editor' || !$model->hasBehaviour('link') && $entity == 'Editor') {
                 continue;
             }
             $generator = $this->application->getManager()->create('Cti\\Sencha\\Generator\\' . $entity, array('model' => $model, 'schema' => $schema));
             $path = $this->application->getProject()->getPath('build coffee Generated ' . $entity . ' ' . $model->getClassName() . '.coffee');
             $code = $generator->getGeneratedCode();
             if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
                 $fs->dumpFile($path, $code);
             }
             $path = $this->application->getProject()->getPath('build coffee ' . $entity . ' ' . $model->getClassName() . '.coffee');
             $code = $generator->getFinalCode();
             if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
                 $fs->dumpFile($path, $code);
             }
         }
         echo '- generate ' . $model->getClassName() . PHP_EOL;
     }
     $generator = $this->application->getManager()->create('Cti\\Sencha\\Generator\\Master', array('model' => $model));
     $path = $this->application->getProject()->getPath('build coffee Generated Master.coffee');
     $code = $generator->getGeneratedCode();
     if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
         $fs->dumpFile($path, $code);
     }
     $path = $this->application->getProject()->getPath('build coffee Master.coffee');
     $code = $generator->getFinalCode();
     if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
         $fs->dumpFile($path, $code);
     }
     $finder = new Finder();
     $this->getCoffeeCompiler()->setDebug(true);
     $source = $application->getProject()->getPath('resources coffee');
     if (is_dir($source)) {
         $finder->files()->name("*.coffee")->in($source);
         foreach ($finder as $file) {
             $script = substr($file, strlen($source) + 1, -7);
             echo '- processing ' . $script . '.coffee' . PHP_EOL;
             $this->getCoffeeCompiler()->build($script);
         }
     }
 }
Exemple #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = implode('_', $input->getArgument('name'));
     $class = String::convertToCamelCase($id);
     $timestamp = time();
     $filename = $this->application->getProject()->getPath('resources php migrations ' . date('Ymd_His', $timestamp) . '_' . $id . '.php');
     $migration = $this->application->getManager()->create('Cti\\Storage\\Generator\\Migration', array('class' => $class, 'timestamp' => $timestamp));
     $fs = new Filesystem();
     $fs->dumpFile($filename, $migration);
     if (!defined('TEST_ENVIRONMENT')) {
         echo 'Migration created. ' . $filename . PHP_EOL;
     }
 }
Exemple #6
0
 /**
  * process migrations from filesystem
  */
 function processMigrations()
 {
     $filesystem = new Filesystem();
     $project = $this->application->getProject();
     $migrations = $project->getPath('build php Storage Migration');
     if ($filesystem->exists($migrations)) {
         $filesystem->remove($migrations);
     }
     $filesystem->mkdir($migrations);
     $finder = new Finder();
     if (!is_dir($project->getPath('resources php migrations'))) {
         return true;
     }
     $finder->files()->name("*.php")->in($project->getPath('resources php migrations'));
     foreach ($finder as $file) {
         $date = substr($file->getFileName(), 0, 8);
         $time = substr($file->getFileName(), 9, 6);
         $index = substr($file->getBasename('.php'), 16);
         $name = String::convertToCamelCase($index);
         $class_name = $name . '_' . $date . '_' . $time;
         $class = 'Storage\\Migration\\' . $class_name;
         $filesystem->copy($file->getRealPath(), $migrations . DIRECTORY_SEPARATOR . $class_name . '.php');
         if (!class_exists($class)) {
             include $file->getRealPath();
         }
         $this->application->getManager()->get($class)->process($this);
         $this->setNamespace(null);
     }
 }
Exemple #7
0
 public function __construct(Application $application)
 {
     $this->application = $application;
     $this->configurationPath = $application->getProject()->getPath('resources php projects.php');
     if (file_exists($this->configurationPath)) {
         $this->configuration = (include $this->configurationPath);
     } else {
         $this->configuration = array();
     }
 }
Exemple #8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fs = new Filesystem();
     $schema = $this->application->getStorage()->getSchema();
     // create.sql
     $dbalToSchema = $this->dbalConverter->convert($schema);
     $dbalFromSchema = $schema = new \Doctrine\DBAL\Schema\Schema();
     $this->generator->setToSchema($dbalToSchema);
     $this->generator->setFromSchema($dbalFromSchema);
     $queries = $this->generator->migrate();
     $debug = $input->getArgument('debug') == true;
     $create = $this->application->getProject()->getPath('build sql create.sql');
     if ($debug) {
         echo "- build create.sql" . PHP_EOL;
     }
     $output->writeln('Create ' . $create);
     $fs->dumpFile($create, implode(";\n", $queries) . ';');
     // migrate.sql
     $dbalFromSchema = $this->dbal->getSchemaManager()->createSchema();
     $this->generator->setFromSchema($dbalFromSchema);
     $queries = $this->generator->migrate();
     $migrate = $this->application->getProject()->getPath('build sql migrate.sql');
     if ($debug) {
         echo "- build migrate.sql" . PHP_EOL;
     }
     $output->writeln('Create ' . $migrate);
     $fs->dumpFile($migrate, implode(";\n", $queries) . (count($queries) ? ';' : ''));
     if (!$debug) {
         echo implode(";\n", $queries) . ';';
     }
     if ($input->getOption('test') != true) {
         foreach ($queries as $query) {
             $this->dbal->executeQuery($query);
         }
         if ($input->getOption('commit') == true) {
             $this->dbal->commit();
         }
     }
 }
Exemple #9
0
 /**
  * warm application
  * @param Application $application
  * @return mixed
  */
 public function warm(Application $application)
 {
     // define available classes
     $coreSource = dirname(__DIR__);
     $buildSource = $application->getProject()->getPath('build php');
     $source = $application->getProject()->getPath('src php');
     $path = array($coreSource, $source);
     if (is_dir($buildSource)) {
         $path[] = $buildSource;
     }
     $finder = new Finder();
     $finder->in($path)->files();
     $inspector = $application->getManager()->getInspector();
     // warm inspector
     foreach ($finder as $file) {
         $path = $file->getPath();
         if (strpos($path, $coreSource) === 0) {
             $namespace = 'Cti\\Core' . substr($path, strlen($coreSource));
         } elseif (strpos($path, $buildSource) === 0) {
             $namespace = substr($path, strlen($buildSource) + 1);
         } elseif (strpos($path, $source) === 0) {
             $namespace = substr($path, strlen($source) + 1);
         }
         $class = str_replace(DIRECTORY_SEPARATOR, '\\', $namespace) . '\\' . $file->getBasename('.php');
         if (!class_exists($class)) {
             continue;
         }
         $inspector->getPublicMethods($class);
         $inspector->getClassInjection($class);
         $inspector->getClassProperties($class);
         foreach (Reflection::getReflectionClass($class)->getMethods() as $method) {
             if ($method->getDeclaringClass()->getName() == $class) {
                 $inspector->getMethodArguments($class, $method->getName());
                 $inspector->getMethodRequiredCount($class, $method->getName());
             }
         }
     }
     $application->getCache()->set(__CLASS__, $this->get('Cti\\Di\\Cache')->getData());
 }