Переделка для composer autoload
This commit is contained in:
parent
ad69746347
commit
b5641db607
100 changed files with 14 additions and 325 deletions
79
src/controller/state.php
Normal file
79
src/controller/state.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
class Controller_State
|
||||
{
|
||||
public $action = '';
|
||||
public $states = array();
|
||||
public $titles = array();
|
||||
|
||||
public function __construct($action)
|
||||
{
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
static function make($action)
|
||||
{
|
||||
return new State($action);
|
||||
}
|
||||
|
||||
public function addTitle($name, $url = array())
|
||||
{
|
||||
$this->titles [] = array($name, $url);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addState(State $state)
|
||||
{
|
||||
$this->states [$state->getAction()] = $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
function checkAction($action, &$list)
|
||||
{
|
||||
if ($this->action == $action) {
|
||||
array_push($list, $this);
|
||||
return true;
|
||||
} else {
|
||||
foreach ($this->states as $state) {
|
||||
if ($state->checkAction($action, $list)) {
|
||||
array_push($list, $this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function makeTitle($module)
|
||||
{
|
||||
foreach ($this->titles as $item) {
|
||||
$module->path->addMenuItem($module->nUrl($this->action, $item[1]), $item[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function getPath($module, $action)
|
||||
{
|
||||
$list = array();
|
||||
if ($this->checkAction($action, $list)) {
|
||||
foreach (array_reverse($list) as $item) {
|
||||
$item->makeTitle($module);
|
||||
}
|
||||
} else {
|
||||
$this->makeTitle($module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
$path = State::make('index')
|
||||
->addState(State::make('form'))
|
||||
->addState(State::make('view'));
|
||||
|
||||
$path->getPath(0, 'form');
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue