Skip to content

Commit

Permalink
Merge pull request #513 from nedvajz/master
Browse files Browse the repository at this point in the history
Use cakephp to load plugin
  • Loading branch information
markstory authored Apr 13, 2019
2 parents ec975a5 + b19fad6 commit 8a93a88
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions src/Shell/Task/PluginTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
*/
class PluginTask extends BakeTask
{
/**
* Path to the bootstrap file. Changed in tests.
*
* @var string
*/
public $bootstrap = null;

/**
* Tasks this task uses.
*
Expand All @@ -59,7 +52,6 @@ class PluginTask extends BakeTask
public function initialize()
{
$this->path = current(App::path('Plugin'));
$this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php';
}

/**
Expand Down Expand Up @@ -117,8 +109,8 @@ public function bake($plugin)

$this->_generateFiles($plugin, $this->path);

$hasAutoloader = $this->_modifyAutoloader($plugin, $this->path);
$this->_modifyBootstrap($plugin, $hasAutoloader);
$this->_modifyAutoloader($plugin, $this->path);
$this->_modifyApplication($plugin);

$this->hr();
$this->out(sprintf('<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
Expand All @@ -130,32 +122,22 @@ public function bake($plugin)
}

/**
* Update the app's bootstrap.php file.
* Modify the application class
*
* @param string $plugin Name of plugin
* @param bool $hasAutoloader Whether or not there is an autoloader configured for
* the plugin
* @return void
*/
protected function _modifyBootstrap($plugin, $hasAutoloader)
protected function _modifyApplication($plugin)
{
$bootstrap = new File($this->bootstrap, false);
if (!$bootstrap->exists()) {
$this->err('<warning>Could not update application bootstrap.php file, as it could not be found.</warning>');
$application = new File(ROOT . DS . 'src' . DS . 'Application.php', false);
if (!$application->exists()) {
$this->err('<warning>Could not update application Application.php file, as it could not be found.</warning>');

return;
}
$contents = $bootstrap->read();
if (!preg_match("@\n\s*Plugin::loadAll@", $contents)) {
$autoload = $hasAutoloader ? null : "'autoload' => true, ";
$bootstrap->append(sprintf(
"\nPlugin::load('%s', [%s'bootstrap' => false, 'routes' => true]);\n",
$plugin,
$autoload
));
$this->out('');
$this->out(sprintf('%s modified', $this->bootstrap));
}

$this->dispatchShell('plugin', 'load', $plugin);
}

/**
Expand Down

0 comments on commit 8a93a88

Please sign in to comment.