Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Plugin Classes #11564

Merged
merged 42 commits into from Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5d12b92
Started working on a new plugin loading system
burzum Dec 11, 2017
e01065e
Allow plugins to disable / enable bootstrap and routes
burzum Dec 12, 2017
7367598
Refining the PluginRegistry
burzum Dec 13, 2017
7e5eba9
Refactored the way plugins are initialized
burzum Dec 20, 2017
384f6a0
Corrections to the plugin loading process
burzum Dec 22, 2017
31319c2
Some stickler and phpcs fixes
burzum Dec 22, 2017
d88c0e4
Minor fixes to Plugins
burzum Jan 3, 2018
dbe6a06
Adding Plugin.loaded event
burzum Feb 2, 2018
22b4ca7
Convert PluginRegistry into a Collection.
markstory Feb 9, 2018
d3f8b55
Add names to plugins & remove middleware interfaces.
markstory Feb 10, 2018
bf8e83c
Integrate new plugin hooks into the console runner
markstory Feb 11, 2018
bc07da1
Add interface for applications using plugins
markstory Feb 11, 2018
e5322b0
Integrate plugin hooks in http & routing
markstory Feb 11, 2018
740f80b
Implement addPlugin()
markstory Feb 12, 2018
685a40e
Implement option passing for PluginApp
markstory Feb 12, 2018
0b661f8
Add remaining hook methods to PluginApp and PluginInterface
markstory Feb 12, 2018
4ebf10b
Use constant.
markstory Feb 13, 2018
4efb602
Add getPath() to plugins.
markstory Feb 13, 2018
7be7aa3
Make exceptions raised by PluginCollection better.
markstory Feb 13, 2018
d3844d4
Add class & config path.
markstory Feb 13, 2018
6f09ad6
Make plugin names an option.
markstory Feb 13, 2018
dc8e17d
Integrate new & old style plugins.
markstory Feb 13, 2018
44fa5e2
Fix use of undeclared property.
markstory Feb 13, 2018
978a903
Add missing methods to PluginInterface and make it narrower
markstory Feb 15, 2018
44e8676
Fixing style errors.
stickler-ci Feb 15, 2018
8b33c9f
Fix issues reported by PHPStan
robertpustulka Feb 15, 2018
d4a4887
Fix more issues reported by PHPStan
robertpustulka Feb 15, 2018
1e59a8d
Merge branch '3.next' into 3.next-plugins
markstory Feb 19, 2018
0cbab2a
Add events hook to plugins.
markstory Feb 19, 2018
6b4b114
Make plugins need to return the event manager
markstory Feb 21, 2018
c6a7aea
Add more tests around PluginApplication methods.
markstory Feb 21, 2018
a3522fb
Rename PluginApp -> BasePlugin
markstory Feb 22, 2018
a855b7d
Allow plugins to be loaded by short plugin names.
markstory Feb 22, 2018
0a84784
Simpler/faster short classname check.
markstory Feb 22, 2018
680b96c
Merge branch '3.next' into 3.next-plugins
markstory Feb 22, 2018
9740c18
Require files more than once.
markstory Feb 22, 2018
afd1fd6
Add missing file header.
markstory Feb 22, 2018
7f56814
Merge the EventApplication and PluginApplication interfaces.
markstory Feb 23, 2018
e4cf40d
Make Server/CommandRunner proxy event managers.
markstory Feb 23, 2018
7b059d4
Add missing typehint.
markstory Feb 23, 2018
bda7b35
Remove events hooks.
markstory Feb 24, 2018
40fe576
Fix phpstan warnings and actual mistakes.
markstory Feb 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 76 additions & 23 deletions src/Console/CommandRunner.php
Expand Up @@ -22,18 +22,27 @@
use Cake\Console\Exception\StopException;
use Cake\Console\Shell;
use Cake\Core\ConsoleApplicationInterface;
use Cake\Event\EventApplicationInterface;
use Cake\Core\PluginApplicationInterface;
use Cake\Event\EventDispatcherInterface;
use Cake\Event\EventDispatcherTrait;
use Cake\Event\EventManager;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use RuntimeException;

/**
* Run CLI commands for the provided application.
*/
class CommandRunner implements EventDispatcherInterface
{
use EventDispatcherTrait;
/**
* Alias methods away so we can implement proxying methods.
*/
use EventDispatcherTrait {
eventManager as private _eventManager;
getEventManager as private _getEventManager;
setEventManager as private _setEventManager;
}

/**
* The application console commands are being run for.
Expand Down Expand Up @@ -64,7 +73,7 @@ class CommandRunner implements EventDispatcherInterface
*/
public function __construct(ConsoleApplicationInterface $app, $root = 'cake')
{
$this->setApp($app);
$this->app = $app;
$this->root = $root;
$this->aliases = [
'--version' => 'version',
Expand Down Expand Up @@ -96,23 +105,6 @@ public function setAliases(array $aliases)
return $this;
}

/**
* Set the application.
*
* @param \Cake\Core\ConsoleApplicationInterface $app The application to run CLI commands for.
* @return $this
*/
public function setApp(ConsoleApplicationInterface $app)
{
$this->app = $app;

if ($app instanceof EventDispatcherInterface) {
$this->setEventManager($app->getEventManager());
}

return $this;
}

/**
* Run the command contained in $argv.
*
Expand All @@ -137,6 +129,10 @@ public function run(array $argv, ConsoleIo $io = null)
'help' => HelpCommand::class,
]);
$commands = $this->app->console($commands);
if ($this->app instanceof PluginApplicationInterface) {
$commands = $this->app->pluginConsole($commands);
}

if (!($commands instanceof CommandCollection)) {
$type = getTypeName($commands);
throw new RuntimeException(
Expand Down Expand Up @@ -178,18 +174,75 @@ public function run(array $argv, ConsoleIo $io = null)
* Application bootstrap wrapper.
*
* Calls `bootstrap()` and `events()` if application implements `EventApplicationInterface`.
* After the application is bootstrapped and events are attached, plugins are bootstrapped
* and have their events attached.
*
* @return void
*/
protected function bootstrap()
{
$this->app->bootstrap();
if ($this->app instanceof EventApplicationInterface) {
$eventManager = $this->app->events($this->getEventManager());
$this->setEventManager($eventManager);
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginBootstrap();

$events = $this->app->getEventManager();
$events = $this->app->events($events);
$events = $this->app->pluginEvents($events);
$this->app->setEventManager($events);
}
}

/**
* Get the application's event manager or the global one.
*
* @return \Cake\Event\EventManagerInterface
*/
public function getEventManager()
{
if ($this->app instanceof PluginApplicationInterface) {
return $this->app->getEventManager();
}

return EventManager::instance();
}

/**
* Get/set the application's event manager.
*
* If the application does not support events and this method is used as
* a setter, an exception will be raised.
*
* @param \Cake\Event\EventManagerInterface $events The event manager to set.
* @return \Cake\Event\EventManagerInterface|$this
* @deprecated Will be removed in 4.0
*/
public function eventManager(EventManager $events = null)
{
if ($eventManager === null) {
return $this->getEventManager();
}

return $this->setEventManager($events);
}

/**
* Get/set the application's event manager.
*
* If the application does not support events and this method is used as
* a setter, an exception will be raised.
*
* @param \Cake\Event\EventManagerInterface $events The event manager to set.
* @return $this
*/
public function setEventManager(EventManager $events)
{
if ($this->app instanceof PluginApplicationInterface) {
return $this->app->setEventManager($events);
}

throw new InvalidArgumentException('Cannot set the event manager, the application does not support events.');
}

/**
* Get the shell instance for a given command name
*
Expand Down