Skip to content

Commit

Permalink
Adding Plugin.loaded event
Browse files Browse the repository at this point in the history
  • Loading branch information
burzum authored and markstory committed Feb 13, 2018
1 parent d88c0e4 commit dbe6a06
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Core/PluginApp.php
Expand Up @@ -163,6 +163,6 @@ public function middleware($middleware)
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
{
return $next($request, $response)
return $next($request, $response);
}
}
21 changes: 21 additions & 0 deletions src/Core/PluginRegistry.php
Expand Up @@ -13,6 +13,8 @@
*/
namespace Cake\Core;

use Cake\Event\Event;
use Cake\Event\EventManager;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use RuntimeException;
Expand All @@ -23,6 +25,25 @@
class PluginRegistry extends ObjectRegistry implements PluginRegistryInterface
{

/**
* @inheritDoc
*/
public function load($objectName, $config = [])
{
$plugin = parent::load($objectName, $config);

if (class_exists('\Cake\Event\Event')) {
$event = new Event('Plugin.loaded', $this, [
'name' => $objectName,
'plugin' => $plugin,
'config' => $config
]);
EventManager::instance()->dispatch($event);
};

return $plugin;
}

/**
* Should resolve the classname for a given object type.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Http/BaseApplication.php
Expand Up @@ -120,8 +120,6 @@ public function routes($routes)
if (!Router::$initialized) {
require $this->configDir . '/routes.php';
// Prevent routes from being loaded again

$this->pluginRegistry()->routes($routes);
Router::$initialized = true;
}
}
Expand Down

0 comments on commit dbe6a06

Please sign in to comment.