Example #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
         //                    ))
         //                );
         //            }
     }
 }
Example #2
0
 public function saveSchema($config)
 {
     $schema = $this->getSchema();
     $newSchema = $this->application->getManager()->create("\\Project\\Schema", $config);
     /**
      * @var \Migration\Diff $diff
      */
     $diff = $this->application->getManager()->create("\\Migration\\Diff", array('from' => $schema, 'to' => $newSchema));
     $migrationCode = $diff->getMigrationCode();
     /**
      * Execute console generate migration
      * Inject migration code in method of created migrtion class
      * @todo make migration names
      */
     $output = $this->executeConsole('generate:migration migrationName');
     $regexp = "/resources\\" . DIRECTORY_SEPARATOR . "php\\" . DIRECTORY_SEPARATOR . "migrations\\" . DIRECTORY_SEPARATOR . "([0-9]+_[0-9]+_[A-Za-z]+.php)/";
     preg_match($regexp, $output, $matches);
     if (!$matches || count($matches) == 0) {
         throw new \Exception("Migration file not found");
     }
     $fileName = $matches[1];
     $fullMigrationPath = $this->getPath('resources php migrations ' . $fileName);
     $content = file_get_contents($fullMigrationPath);
     $modifiedContent = $this->modifyMigration($content, $migrationCode);
     file_put_contents($fullMigrationPath, $modifiedContent);
 }
Example #3
0
 /**
  * @param $nick
  * @return \Project\Project
  * @throws \Exception
  */
 public function getProject($nick)
 {
     if (!isset($this->configuration[$nick])) {
         throw new \Exception("No project {$nick} found");
     }
     $project = $this->application->getManager()->create('\\Project\\Project', $this->configuration[$nick]);
     return $project;
 }
Example #4
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;
     }
 }
Example #5
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);
     }
 }
Example #6
0
File: Manager.php Project: cti/core
 /**
  * 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());
 }
Example #7
0
 /**
  * bootstrap application
  * @param Application $application
  * @return mixed
  */
 public function boot(Application $application)
 {
     $initializer = $application->getManager()->getInitializer();
     $initializer->after('Cti\\Core\\Module\\Console', array($this, 'registerCommands'));
     $application->getFenom()->addSource($this->getPath('resources fenom'));
 }
Example #8
0
 public function createModel($name, $config)
 {
     $this->models[$name] = $this->application->getManager()->create('\\Project\\Model', array('config' => $config, 'name' => $name));
 }
Example #9
0
 public function getCoffeeCompiler()
 {
     return $this->application->getManager()->get('Cti\\Sencha\\Coffee\\Compiler');
 }
Example #10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->application->getManager()->get('Scheduler\\Runner');
 }