Esempio n. 1
0
 /**
  * Generates set of code based on data.
  *
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     $columnFields = ['name', 'description', 'label'];
     $table = $this->describe->getTable($this->data['name']);
     foreach ($table as $column) {
         if ($column->isAutoIncrement()) {
             continue;
         }
         $field = strtolower($column->getField());
         $method = 'set_' . $field;
         $this->data['camel'][$field] = lcfirst(camelize($method));
         $this->data['underscore'][$field] = underscore($method);
         array_push($this->data['columns'], $field);
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = $referencedTable;
             array_push($this->data['models'], $referencedTable);
             $dropdown = ['list' => plural($referencedTable), 'table' => $referencedTable, 'field' => $field];
             if (!in_array($field, $columnFields)) {
                 $field = $this->describe->getPrimaryKey($referencedTable);
                 $dropdown['field'] = $field;
             }
             array_push($this->data['dropdowns'], $dropdown);
         }
     }
     return $this->data;
 }
Esempio n. 2
0
 /**
  * Executes the command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return object|\Symfony\Component\Console\Output\OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = Tools::stripTableSchema(plural($input->getArgument('name')));
     if ($input->getOption('keep')) {
         $name = Tools::stripTableSchema($input->getArgument('name'));
     }
     $validator = new ViewValidator($name);
     if ($validator->fails()) {
         $message = $validator->getMessage();
         return $output->writeln('<error>' . $message . '</error>');
     }
     $data = ['isBootstrap' => $input->getOption('bootstrap'), 'isCamel' => $input->getOption('camel'), 'name' => $input->getArgument('name')];
     $generator = new ViewGenerator($this->describe, $data);
     $result = $generator->generate();
     $results = ['create' => $this->renderer->render('Views/create.tpl', $result), 'edit' => $this->renderer->render('Views/edit.tpl', $result), 'index' => $this->renderer->render('Views/index.tpl', $result), 'show' => $this->renderer->render('Views/show.tpl', $result)];
     $filePath = APPPATH . 'views/' . $name;
     $create = new File($filePath . '/create.php');
     $edit = new File($filePath . '/edit.php');
     $index = new File($filePath . '/index.php');
     $show = new File($filePath . '/show.php');
     $create->putContents($results['create']);
     $edit->putContents($results['edit']);
     $index->putContents($results['index']);
     $show->putContents($results['show']);
     $create->close();
     $edit->close();
     $index->close();
     $show->close();
     $message = 'The views folder "' . $name . '" has been created successfully!';
     return $output->writeln('<info>' . $message . '</info>');
 }
 /**
  * Executes the command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface   $input
  * @param  \Symfony\Component\Console\Output\OutputInterface $output
  * @return object|\Symfony\Component\Console\Output\OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->addLibrary('wildfire');
     $template = $this->renderer->render('Libraries/Wildfire.tpl');
     $wildfire = new File(APPPATH . 'libraries/Wildfire.php');
     $wildfire->putContents($template);
     $wildfire->close();
     Tools::ignite();
     $message = 'Wildfire is now installed successfully!';
     return $output->writeln('<info>' . $message . '</info>');
 }
Esempio n. 4
0
 /**
  * Generates set of code based on data.
  *
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     foreach ($this->data['columns'] as $column) {
         $field = strtolower($column->getField());
         $this->data['camel'][$field] = $this->transformField($field, 'camelize');
         $this->data['underscore'][$field] = $this->transformField($field, 'underscore');
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = plural($referencedTable);
             $singular = $field . '_singular';
             $this->data['foreignKeys'][$singular] = singular($referencedTable);
             $this->data = $this->getPrimaryKey($this->data, $field, $referencedTable);
         }
     }
     return $this->data;
 }
Esempio n. 5
0
 /**
  * Generates set of code based on data.
  *
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     foreach ($this->data['columns'] as $column) {
         $field = strtolower($column->getField());
         $this->data['camel'][$field] = $this->transformField($field, 'camelize');
         $this->data['underscore'][$field] = $this->transformField($field, 'underscore');
         if ($column->isForeignKey()) {
             $field = $column->getField();
             $referencedTable = $column->getReferencedTable();
             array_push($this->data['indexes'], $field);
             $this->data = $this->getPrimaryKey($this->data, $field, $referencedTable);
         }
         $column->setReferencedTable(Tools::stripTableSchema($column->getReferencedTable()));
     }
     return $this->data;
 }
Esempio n. 6
0
 /**
  * Generates set of code based on data.
  * 
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     foreach ($this->data['columns'] as $column) {
         $field = strtolower($column->getField());
         $accessor = 'get_' . $field;
         $mutator = 'set_' . $field;
         $this->data['camel'][$field] = ['field' => lcfirst(camelize($field)), 'accessor' => lcfirst(camelize($accessor)), 'mutator' => lcfirst(camelize($mutator))];
         $this->data['underscore'][$field] = ['field' => lcfirst(underscore($field)), 'accessor' => lcfirst(underscore($accessor)), 'mutator' => lcfirst(underscore($mutator))];
         if ($column->isForeignKey()) {
             $field = $column->getField();
             array_push($this->data['indexes'], $field);
             $this->data['primaryKeys'][$field] = 'get_' . $this->describe->getPrimaryKey($column->getReferencedTable());
             if ($this->data['isCamel']) {
                 $this->data['primaryKeys'][$field] = camelize($this->data['primaryKeys'][$field]);
             }
         }
         $column->setReferencedTable(Tools::stripTableSchema($column->getReferencedTable()));
     }
     return $this->data;
 }
Esempio n. 7
0
 /**
  * Generates set of code based on data.
  * 
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     foreach ($this->data['columns'] as $column) {
         $field = strtolower($column->getField());
         $accessor = 'get_' . $field;
         $mutator = 'set_' . $field;
         $this->data['camel'][$field] = ['field' => lcfirst(camelize($field)), 'accessor' => lcfirst(camelize($accessor)), 'mutator' => lcfirst(camelize($mutator))];
         $this->data['underscore'][$field] = ['field' => lcfirst(underscore($field)), 'accessor' => lcfirst(underscore($accessor)), 'mutator' => lcfirst(underscore($mutator))];
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = plural($referencedTable);
             $singular = $field . '_singular';
             $this->data['foreignKeys'][$singular] = singular($referencedTable);
             $this->data['primaryKeys'][$field] = 'get_' . $this->describe->getPrimaryKey($referencedTable);
             if ($this->data['isCamel']) {
                 $this->data['primaryKeys'][$field] = camelize($this->data['primaryKeys'][$field]);
             }
         }
     }
     return $this->data;
 }
 /**
  * Executes the command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return object|\Symfony\Component\Console\Output\OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     system('composer require doctrine/orm');
     $cli = $this->renderer->render('DoctrineCLI.tpl');
     $doctrine = new File(APPPATH . 'libraries/Doctrine.php');
     $template = $this->renderer->render('Libraries/Doctrine.tpl');
     $vendor = realpath('vendor');
     // Modifies the contents of vendor/bin/doctrine.php, creates the
     // Doctrine library and creates a "proxies" directory for lazy loading.
     file_put_contents($vendor . '/bin/doctrine.php', $cli);
     file_put_contents($vendor . '/doctrine/orm/bin/doctrine.php', $cli);
     $doctrine->putContents($template);
     $doctrine->close();
     $this->addLibrary('doctrine');
     if (!is_dir(APPPATH . 'models/proxies')) {
         mkdir(APPPATH . 'models/proxies');
         chmod(APPPATH . 'models/proxies', 0777);
     }
     $abstractCommandPath = $vendor . '/doctrine/orm/lib/Doctrine/ORM/' . 'Tools/Console/Command/SchemaTool/AbstractCommand.php';
     // Includes the Base Model class in Doctrine CLI
     $abstractCommand = file_get_contents($abstractCommandPath);
     $search = 'use Doctrine\\ORM\\Tools\\SchemaTool;';
     $replace = $search . "\n" . 'include BASEPATH . \'core/Model.php\';';
     $contents = $abstractCommand;
     $schemaTool = 'use Doctrine\\ORM\\Tools\\SchemaTool;';
     $coreModel = 'include BASEPATH . \'core/Model.php\';';
     if (strpos($abstractCommand, $schemaTool) !== false) {
         if (strpos($abstractCommand, $coreModel) === false) {
             $contents = str_replace($search, $replace, $abstractCommand);
         }
     }
     file_put_contents($abstractCommandPath, $contents);
     Tools::ignite();
     $message = 'Doctrine ORM is now installed successfully!';
     return $output->writeln('<info>' . $message . '</info>');
 }
 /**
  * Executes the command.
  * 
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return object|OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * Add Wildfire.php to the "libraries" directory
      */
     $autoload = file_get_contents(APPPATH . 'config/autoload.php');
     preg_match_all('/\\$autoload\\[\'libraries\'\\] = array\\((.*?)\\)/', $autoload, $match);
     $libraries = explode(', ', end($match[1]));
     if (!in_array('\'wildfire\'', $libraries)) {
         array_push($libraries, '\'wildfire\'');
         $libraries = array_filter($libraries);
         $autoload = preg_replace('/\\$autoload\\[\'libraries\'\\] = array\\([^)]*\\);/', '$autoload[\'libraries\'] = array(' . implode(', ', $libraries) . ');', $autoload);
         $file = fopen(APPPATH . 'config/autoload.php', 'wb');
         file_put_contents(APPPATH . 'config/autoload.php', $autoload);
         fclose($file);
     }
     $file = fopen(APPPATH . 'libraries/Wildfire.php', 'wb');
     $wildfire = $this->renderer->render('Libraries/Wildfire.template');
     file_put_contents(APPPATH . 'libraries/Wildfire.php', $wildfire);
     fclose($file);
     Tools::ignite();
     $message = 'Wildfire is now installed successfully!';
     return $output->writeln('<info>' . $message . '</info>');
 }
 /**
  * Executes the command.
  * 
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $message = Tools::removeLibrary('wildfire');
     return $output->writeln('<info>' . $message . '</info>');
 }
Esempio n. 11
0
 /**
  * Checks whether the command is enabled or not in the current environment.
  *
  * Override this to check for x or y and return false if the command can not
  * run properly under the current conditions.
  *
  * @return bool
  */
 public function isEnabled()
 {
     return !Tools::hasLayout();
 }
 /**
  * Executes the command.
  * 
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return object|OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     system('composer require doctrine/orm');
     $cli = $this->renderer->render('DoctrineCLI.template');
     $library = $this->renderer->render('Libraries/Doctrine.template');
     /**
      * Modify the contents of vendor/bin/doctrine.php,
      * create the Doctrine library and create a "proxies"
      * directory for lazy loading
      */
     file_put_contents(VENDOR . 'bin/doctrine.php', $cli);
     file_put_contents(VENDOR . 'doctrine/orm/bin/doctrine.php', $cli);
     $file = fopen(APPPATH . 'libraries/Doctrine.php', 'wb');
     file_put_contents(APPPATH . 'libraries/Doctrine.php', $library);
     fclose($file);
     $autoload = file_get_contents(APPPATH . 'config/autoload.php');
     preg_match_all('/\\$autoload\\[\'libraries\'\\] = array\\((.*?)\\)/', $autoload, $match);
     $libraries = explode(', ', end($match[1]));
     if (!in_array('\'doctrine\'', $libraries)) {
         array_push($libraries, '\'doctrine\'');
         if (in_array('\'database\'', $libraries)) {
             $position = array_search('\'database\'', $libraries);
             unset($libraries[$position]);
         }
         $libraries = array_filter($libraries);
         $autoload = preg_replace('/\\$autoload\\[\'libraries\'\\] = array\\([^)]*\\);/', '$autoload[\'libraries\'] = array(' . implode(', ', $libraries) . ');', $autoload);
         $file = fopen(APPPATH . 'config/autoload.php', 'wb');
         file_put_contents(APPPATH . 'config/autoload.php', $autoload);
         fclose($file);
     }
     if (!is_dir(APPPATH . 'models/proxies')) {
         mkdir(APPPATH . 'models/proxies');
         chmod(APPPATH . 'models/proxies', 0777);
     }
     /*
      * Include the Base Model class in Doctrine CLI
      */
     $abstractCommand = file_get_contents(VENDOR . 'doctrine/orm/lib/Doctrine/' . 'ORM/Tools/Console/Command/' . 'SchemaTool/AbstractCommand.php');
     $search = 'use Doctrine\\ORM\\Tools\\SchemaTool;';
     $replace = $search . "\n" . 'include BASEPATH . \'core/Model.php\';';
     $contents = $abstractCommand;
     $schemaTool = 'use Doctrine\\ORM\\Tools\\SchemaTool;';
     $coreModel = 'include BASEPATH . \'core/Model.php\';';
     if (strpos($abstractCommand, $schemaTool) !== false) {
         if (strpos($abstractCommand, $coreModel) === false) {
             $contents = str_replace($search, $replace, $abstractCommand);
         }
     }
     file_put_contents(VENDOR . 'doctrine/orm/lib/Doctrine/' . 'ORM/Tools/Console/Command/' . 'SchemaTool/AbstractCommand.php', $contents);
     Tools::ignite();
     $message = 'Doctrine ORM is now installed successfully!';
     return $output->writeln('<info>' . $message . '</info>');
 }
 /**
  * Checks whether the command is enabled or not in the current environment.
  *
  * Override this to check for x or y and return false if the command can not
  * run properly under the current conditions.
  *
  * @return bool
  */
 public function isEnabled()
 {
     return Tools::isCommandEnabled();
 }