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); }
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'); } }
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); }
/** * warm application * @param Application $application * @return mixed */ public function warm(Application $application) { $cache = $application->getCache(); foreach ($this->getAvailableNamespaces() as $namespace) { $this->getClasses($namespace); } $cache->set(get_class($this), $this->cache); }
/** * @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; }
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; } }
/** * 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); } }
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 // )) // ); // } } }
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(); } } }
/** * 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()); }
/** * @param array $difference * @return string */ public function getMigrationCode($difference) { return $this->application->getFenom()->render('migration', array('difference' => $difference)); }
public function get(Application $application) { $application->getCoffee()->build('application'); $application->getFenom()->display('index', array('script' => 'public/js/application.js', 'direct' => $application->getDirect()->getUrl())); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->application->getManager()->get('Scheduler\\Runner'); }
protected function execute(InputInterface $input, OutputInterface $output) { $schema = $this->application->getStorage()->getSchema(); echo json_encode($schema->asArray()); }
function display() { $this->application->getSencha()->getCoffeeCompiler()->validate($this->script); $this->application->getFenom()->display($this->template, array('base' => $this->base, 'direct' => $this->direct, 'script' => 'public/js/' . $this->script . '.js', 'title' => $this->title, 'styles' => $this->styles)); }
public function createModel($name, $config) { $this->models[$name] = $this->application->getManager()->create('\\Project\\Model', array('config' => $config, 'name' => $name)); }
/** * if no method was found you can process request by yourself * chain is url pieces delimited by / * you can inject any parameter (thanks to di) * @param Web $web * @param array $chain */ function processChain(Application $application, Web $web, $chain) { $application->getFenom()->display('url', array('base' => $web->getUrl(), 'request' => $web->getUrl(implode('/', $chain)))); }
/** * warm application * @param Application $application * @return mixed */ public function warm(Application $application) { $application->getConsole()->execute('generate:storage', array('debug' => true)); $application->getConsole()->execute('generate:database', array('debug' => true)); }
public function getCoffeeCompiler() { return $this->application->getManager()->get('Cti\\Sencha\\Coffee\\Compiler'); }