Hoa central
Dispatcher.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Dispatcher;
38 
39 use Hoa\Core;
40 use Hoa\Router;
41 use Hoa\View;
42 
51 abstract class Dispatcher implements Core\Parameter\Parameterizable
52 {
58  protected $_parameters = null;
59 
65  protected $_currentView = null;
66 
72  protected $_kit = 'Hoa\Dispatcher\Kit';
73 
74 
75 
82  public function __construct(Array $parameters = [])
83  {
84  $this->_parameters = new Core\Parameter(
85  __CLASS__,
86  [
87  'call' => 'main',
88  'able' => 'main'
89  ],
90  [
91  'synchronous.call' => '(:call:U:)',
92  'synchronous.able' => '(:able:U:)',
93 
94  'asynchronous.call' => '(:%synchronous.call:)',
95  'asynchronous.able' => '(:%synchronous.able:)Async',
96 
102  ]
103  );
104  $this->_parameters->setParameters($parameters);
105 
106  return;
107  }
108 
114  public function getParameters()
115  {
116  return $this->_parameters;
117  }
118 
127  public function dispatch(Router $router, View\Viewable $view = null)
128  {
129  $rule = $router->getTheRule();
130 
131  if (null === $rule) {
132  $router->route();
133  $rule = $router->getTheRule();
134  }
135 
136  if (null === $view) {
137  $view = $this->_currentView;
138  } else {
139  $this->_currentView = $view;
140  }
141 
142  $parameters = $this->_parameters;
143  $this->_parameters = clone $this->_parameters;
144 
145  foreach ($rule[Router::RULE_VARIABLES] as $key => $value) {
146  $this->_parameters->setParameter('variables.' . $key, $value);
147  }
148 
149  $out = $this->resolve($rule, $router, $view);
150  unset($this->_parameters);
151  $this->_parameters = $parameters;
152 
153  return $out;
154  }
155 
165  abstract protected function resolve(
166  Array $rule,
167  Router $router,
168  View\Viewable $view = null
169  );
170 
178  public function setKitName($kit)
179  {
180  $old = $this->_kit;
181  $this->_kit = $kit;
182 
183  return $old;
184  }
185 
191  public function getKitName()
192  {
193  return $this->_kit;
194  }
195 }
196 
200 Core\Consistency::flexEntity('Hoa\Dispatcher\Dispatcher');
const RULE_VARIABLES
Definition: Router.php:112
__construct(Array $parameters=[])
Definition: Dispatcher.php:82
resolve(Array $rule, Router $router, View\Viewable $view=null)
dispatch(Router $router, View\Viewable $view=null)
Definition: Dispatcher.php:127