Skip to content

Commit

Permalink
update accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
easy-system committed Jun 15, 2016
1 parent cedc67b commit d99823d
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 142 deletions.
21 changes: 4 additions & 17 deletions src/Listener/ConfigurePluginsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@

use Es\Modules\ModulesEvent;
use Es\Mvc\ControllerPluginsInterface;
use Es\Services\ServicesTrait;
use Es\Services\Provider;
use Es\System\ConfigTrait;

/**
* Configures the controller plugins.
*/
class ConfigurePluginsListener
{
use ConfigTrait, ServicesTrait;

/**
* The controller plugins.
*
* @var \Es\Mvc\ControllerPluginsInterface
*/
protected $plugins;
use ConfigTrait;

/**
* Sets the plugins.
Expand All @@ -35,7 +28,7 @@ class ConfigurePluginsListener
*/
public function setPlugins(ControllerPluginsInterface $plugins)
{
$this->plugins = $plugins;
Provider::getServices()->set('ControllerPlugins', $plugins);
}

/**
Expand All @@ -45,13 +38,7 @@ public function setPlugins(ControllerPluginsInterface $plugins)
*/
public function getPlugins()
{
if (! $this->plugins) {
$services = $this->getServices();
$plugins = $services->get('ControllerPlugins');
$this->setPlugins($plugins);
}

return $this->plugins;
return Provider::getServices()->get('ControllerPlugins');
}

/**
Expand Down
24 changes: 5 additions & 19 deletions src/Plugin/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,17 @@
namespace Es\ControllerPlugins\Plugin;

use Es\Dispatcher\DispatchEvent;
use Es\Events\EventsInterface;
use Es\Events\EventsTrait;
use Es\Mvc\ControllersInterface;
use Es\Services\ServicesTrait;
use Es\Services\Provider;
use InvalidArgumentException;
use Es\Events\EventsTrait;

/**
* Dispatch another controller.
*/
class Forward
{
use EventsTrait, ServicesTrait;

/**
* The system controllers.
*
* @var \Es\Mvc\ControllersInterface
*/
protected $controllers;
use EventsTrait;

/**
* Sets the controllers.
Expand All @@ -37,7 +29,7 @@ class Forward
*/
public function setControllers(ControllersInterface $controllers)
{
$this->controllers = $controllers;
Provider::getServices()->set('Controllers', $controllers);
}

/**
Expand All @@ -47,13 +39,7 @@ public function setControllers(ControllersInterface $controllers)
*/
public function getControllers()
{
if (! $this->controllers) {
$services = $this->getServices();
$controllers = $services->get('Controllers');
$this->setControllers($controllers);
}

return $this->controllers;
return Provider::getServices()->get('Controllers');
}

/**
Expand Down
21 changes: 3 additions & 18 deletions src/Plugin/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,22 @@
namespace Es\ControllerPlugins\Plugin;

use Es\Http\ServerInterface;
use Es\Services\ServicesTrait;
use Es\Services\Provider;
use RuntimeException;

/**
* The plugin implements the JSON data-interchange format.
*/
class Json
{
use ServicesTrait;

/**
* The server.
*
* @var \Es\Http\ServerInterface
*/
protected $server;

/**
* Sets the server.
*
* @param \Es\Http\ServerInterface $server The server
*/
public function setServer(ServerInterface $server)
{
$this->server = $server;
Provider::getServices()->set('Server', $server);
}

/**
Expand All @@ -44,13 +35,7 @@ public function setServer(ServerInterface $server)
*/
public function getServer()
{
if (! $this->server) {
$services = $this->getServices();
$server = $services->get('Server');
$this->setServer($server);
}

return $this->server;
return Provider::getServices()->get('Server');
}

/**
Expand Down
21 changes: 3 additions & 18 deletions src/Plugin/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Es\ControllerPlugins\Plugin;

use Es\Mvc\ViewInterface;
use Es\Services\ServicesTrait;
use Es\Services\Provider;

/**
* Allows to change the layout parameters.
Expand All @@ -19,15 +19,6 @@
*/
class Layout
{
use ServicesTrait;

/**
* The view.
*
* @var \Es\Mvc\ViewInterface
*/
protected $view;

/**
* Sets the view.
*
Expand All @@ -37,7 +28,7 @@ class Layout
*/
public function setView(ViewInterface $view)
{
$this->view = $view;
Provider::getServices()->set('View', $view);

return $this;
}
Expand All @@ -49,13 +40,7 @@ public function setView(ViewInterface $view)
*/
public function getView()
{
if (! $this->view) {
$services = $this->getServices();
$view = $services->get('View');
$this->setView($view);
}

return $this->view;
return Provider::getServices()->get('View');
}

/**
Expand Down
49 changes: 15 additions & 34 deletions src/Plugin/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,13 @@
namespace Es\ControllerPlugins\Plugin;

use Es\Http\Server;
use Es\Services\ServicesTrait;
use Es\Services\Provider;

/**
* Generates redirection by given route or url.
*/
class Redirect
{
use ServicesTrait;

/**
* The server.
*
* @var \Es\Http\Server
*/
protected $server;

/**
* Url plugin.
*
* @var Url
*/
protected $url;

/**
* Sets the server.
*
Expand All @@ -42,7 +26,7 @@ class Redirect
*/
public function setServer(Server $server)
{
$this->server = $server;
Provider::getServices()->set('Server', $server);

return $this;
}
Expand All @@ -54,13 +38,7 @@ public function setServer(Server $server)
*/
public function getServer()
{
if (! $this->server) {
$services = $this->getServices();
$server = $services->get('Server');
$this->setServer($server);
}

return $this->server;
return Provider::getServices()->get('Server');
}

/**
Expand All @@ -72,7 +50,7 @@ public function getServer()
*/
public function setUrl(Url $plugin)
{
$this->url = $plugin;
$this->getPlugins()->set('url', $plugin);

return $this;
}
Expand All @@ -84,14 +62,7 @@ public function setUrl(Url $plugin)
*/
public function getUrl()
{
if (! $this->url) {
$services = $this->getServices();
$plugins = $services->get('ControllerPlugins');
$url = $plugins->get('url');
$this->setUrl($url);
}

return $this->url;
return $this->getPlugins()->get('url');
}

/**
Expand Down Expand Up @@ -127,4 +98,14 @@ public function toUrl($url, $statusCode = 302)

return $response;
}

/**
* Gets controller plugins.
*
* @return \Es\ControllerPlugins\ControllerPlugins The plugins
*/
protected function getPlugins()
{
return Provider::getServices()->get('ControllerPlugins');
}
}
21 changes: 3 additions & 18 deletions src/Plugin/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,13 @@
namespace Es\ControllerPlugins\Plugin;

use Es\Router\RouterInterface;
use Es\Services\ServicesTrait;
use Es\Services\Provider;

/**
* Generate URLs from route definitions.
*/
class Url
{
use ServicesTrait;

/**
* The router.
*
* @var \Es\Router\RouterInterface
*/
protected $router;

/**
* Sets router.
*
Expand All @@ -35,7 +26,7 @@ class Url
*/
public function setRouter(RouterInterface $router)
{
$this->router = $router;
Provider::getServices()->set('Router', $router);

return $this;
}
Expand All @@ -47,13 +38,7 @@ public function setRouter(RouterInterface $router)
*/
public function getRouter()
{
if (! $this->router) {
$services = $this->getServices();
$router = $services->get('Router');
$this->setRouter($router);
}

return $this->router;
return Provider::getServices()->get('Router');
}

/**
Expand Down
9 changes: 7 additions & 2 deletions test/Listener/ConfigurePluginsListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Es\ControllerPlugins\ControllerPlugins;
use Es\ControllerPlugins\Listener\ConfigurePluginsListener;
use Es\Modules\ModulesEvent;
use Es\Services\Provider;
use Es\Services\Services;
use Es\System\SystemConfig;

Expand All @@ -22,17 +23,21 @@ public function testGetPlugins()
$plugins = new ControllerPlugins();
$services = new Services();
$services->set('ControllerPlugins', $plugins);

Provider::setServices($services);
$listener = new ConfigurePluginsListener();
$listener->setServices($services);
$this->assertSame($plugins, $listener->getPlugins());
}

public function testSetPlugins()
{
$services = new Services();
Provider::setServices($services);

$plugins = new ControllerPlugins();
$listener = new ConfigurePluginsListener();
$listener->setPlugins($plugins);
$this->assertSame($plugins, $listener->getPlugins());
$this->assertSame($plugins, $services->get('ControllerPlugins'));
}

public function testInvoke()
Expand Down
Loading

0 comments on commit d99823d

Please sign in to comment.