rougin /
combustor
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Rougin\Combustor\Commands; |
||
| 4 | |||
| 5 | use Symfony\Component\Console\Input\InputInterface; |
||
| 6 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 7 | |||
| 8 | use Rougin\Combustor\Common\File; |
||
| 9 | use Rougin\Combustor\Common\Tools; |
||
| 10 | use Rougin\Combustor\Common\Commands\InstallCommand; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Install Doctrine Command |
||
| 14 | * |
||
| 15 | * Installs Doctrine for CodeIgniter |
||
| 16 | * |
||
| 17 | * @package Combustor |
||
| 18 | * @author Rougin Gutib <[email protected]> |
||
| 19 | */ |
||
| 20 | class InstallDoctrineCommand extends InstallCommand |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $library = 'doctrine'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Executes the command. |
||
| 29 | * |
||
| 30 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
| 31 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
| 32 | * @return object|\Symfony\Component\Console\Output\OutputInterface |
||
| 33 | */ |
||
| 34 | 12 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 35 | { |
||
| 36 | 12 | system('composer require doctrine/orm'); |
|
| 37 | |||
| 38 | 12 | $cli = $this->renderer->render('DoctrineCLI.tpl'); |
|
| 39 | 12 | $doctrine = new File(APPPATH . 'libraries/Doctrine.php'); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 40 | 12 | $template = $this->renderer->render('Libraries/Doctrine.tpl'); |
|
| 41 | 12 | $vendor = realpath('vendor'); |
|
| 42 | |||
| 43 | // Modifies the contents of vendor/bin/doctrine.php, creates the |
||
| 44 | // Doctrine library and creates a "proxies" directory for lazy loading. |
||
| 45 | 12 | file_put_contents($vendor . '/bin/doctrine.php', $cli); |
|
| 46 | 12 | file_put_contents($vendor . '/doctrine/orm/bin/doctrine.php', $cli); |
|
| 47 | |||
| 48 | 12 | $doctrine->putContents($template); |
|
| 49 | 12 | $doctrine->close(); |
|
| 50 | |||
| 51 | 12 | $this->addLibrary('doctrine'); |
|
| 52 | |||
| 53 | 12 | if (! is_dir(APPPATH . 'models/proxies')) { |
|
| 54 | 12 | mkdir(APPPATH . 'models/proxies'); |
|
| 55 | 12 | chmod(APPPATH . 'models/proxies', 0777); |
|
| 56 | 8 | } |
|
| 57 | |||
| 58 | 12 | $abstractCommandPath = $vendor . '/doctrine/orm/lib/Doctrine/ORM/' . |
|
| 59 | 12 | 'Tools/Console/Command/SchemaTool/AbstractCommand.php'; |
|
| 60 | |||
| 61 | // Includes the Base Model class in Doctrine CLI |
||
| 62 | 12 | $abstractCommand = file_get_contents($abstractCommandPath); |
|
| 63 | |||
| 64 | 12 | $search = 'use Doctrine\ORM\Tools\SchemaTool;'; |
|
| 65 | 12 | $replace = $search . "\n" . 'include BASEPATH . \'core/Model.php\';'; |
|
| 66 | |||
| 67 | 12 | $contents = $abstractCommand; |
|
| 68 | 12 | $schemaTool = 'use Doctrine\ORM\Tools\SchemaTool;'; |
|
| 69 | 12 | $coreModel = 'include BASEPATH . \'core/Model.php\';'; |
|
| 70 | |||
| 71 | 12 | if (strpos($abstractCommand, $schemaTool) !== false) { |
|
| 72 | 12 | if (strpos($abstractCommand, $coreModel) === false) { |
|
| 73 | 12 | $contents = str_replace($search, $replace, $abstractCommand); |
|
| 74 | 8 | } |
|
| 75 | 8 | } |
|
| 76 | |||
| 77 | 12 | file_put_contents($abstractCommandPath, $contents); |
|
| 78 | |||
| 79 | 12 | Tools::ignite(); |
|
| 80 | |||
| 81 | 12 | $message = 'Doctrine ORM is now installed successfully!'; |
|
| 82 | |||
| 83 | 12 | return $output->writeln('<info>' . $message . '</info>'); |
|
| 84 | } |
||
| 85 | } |
||
| 86 |