diff --git a/composer.json b/composer.json index 250913a..58565ac 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,8 @@ "require": { "php": ">=5.3.0", "rougin/blueprint": "*", - "rougin/describe": "*" + "rougin/describe": "*", + "rougin/spark-plug": "*" }, "license": "MIT", "authors": [ diff --git a/src/Commands/InstallDoctrineCommand.php b/src/Commands/InstallDoctrineCommand.php index 0180c5c..9a28b7b 100644 --- a/src/Commands/InstallDoctrineCommand.php +++ b/src/Commands/InstallDoctrineCommand.php @@ -57,39 +57,9 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $composer = str_replace( - array(' ', "\n", "\r"), - array('', '', ''), - file_get_contents('composer.json') - ); - - preg_match_all('/"require": \{(.*?)\}/', $composer, $match); - $requiredLibraries = explode(',', end($match[1])); - - preg_match_all('/"require-dev": \{(.*?)\}/', $composer, $match); - $requiredDevLibraries = explode(',', end($match[1])); - - if ( ! in_array('"doctrine/orm": "2.4.*"', $requiredLibraries)) { - array_push($requiredLibraries, '"doctrine/orm": "2.4.*"'); - - $composer = -'{ - "description" : "The CodeIgniter framework", - "name" : "codeigniter/framework", - "license": "MIT", - "require": {' . "\n " . implode(',' . "\n ", $requiredLibraries) . "\n " . '}, - "require-dev": {' . "\n " . implode(',' . "\n ", $requiredDevLibraries) . "\n " . '} -}'; - - $file = fopen('composer.json', 'wb'); - - file_put_contents('composer.json', $composer); - fclose($file); - } - - system('composer update'); + system('composer require doctrine/orm'); - $cli = file_get_contents(__DIR__ . '/Templates/Cli.txt'); + $cli = $this->renderer->render('DoctrineCLI.php'); $library = $this->renderer->render('Libraries/Doctrine.php'); /** diff --git a/src/Templates/DoctrineCLI.php b/src/Templates/DoctrineCLI.php new file mode 100644 index 0000000..a53178e --- /dev/null +++ b/src/Templates/DoctrineCLI.php @@ -0,0 +1,62 @@ +. + */ + +use Symfony\Component\Console\Helper\HelperSet; +use Doctrine\ORM\Tools\Console\ConsoleRunner; + +(@include_once __DIR__ . '/../vendor/autoload.php') || @include_once __DIR__ . '/../../../autoload.php'; + +/** + * Path to the root folder + */ + +define('ROOT', __DIR__ . '/../../../../'); + +/** + * Path to the "system" folder + */ + +define('BASEPATH', str_replace('\\\\', '/', ROOT . 'system/')); + +/** + * The path to the "application" folder + */ + +define('APPPATH', ROOT . 'application/'); + +/** + * Load the Doctrine Library + */ + +require APPPATH . '/libraries/Doctrine.php'; + +$doctrine = new Doctrine(); + +$helperSet = require $doctrine->cli(); + +if ( ! ($helperSet instanceof HelperSet)) { + foreach ($GLOBALS as $helperSetCandidate) { + if ($helperSetCandidate instanceof HelperSet) { + $helperSet = $helperSetCandidate; + break; + } + } +} + +\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands); \ No newline at end of file