-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.php
64 lines (53 loc) · 1.17 KB
/
Core.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once 'Lazyto/Command/Abstract.php';
require_once 'Lazyto/Result/Abstract.php';
require_once 'Lazyto/Dispatcher/Interface.php';
class Lazyto_Core
{
/**
*
* @var Lazyto_Dispatcher_Interface
*/
private $_dispatcher = null;
private static $_instance = null;
private static $_isInit = false;
private function __construct()
{
}
public static function getInstance()
{
if (!self::$_isInit) {
throw new Lazyto_Exception('Lazyto is not initialized.');
}
if (null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
public static function init()
{
}
/**
*
* @param Lazyto_Command_Interface $cmd
* @return Lazyto_Result_Abstract
*/
public function exec(Lazyto_Command_Abstract $cmd)
{
$executor = $this->getDispatcher()->dispatch($cmd);
$result = $executor->exec($cmd);
return $result;
}
public function setDispatcher(Lazyto_Dispatcher_Interface $dispatcher)
{
$this->_dispatcher = $dispatcher;
return $this;
}
public function getDispatcher()
{
if (null === $this->_dispatcher) {
$this->setDispatcher(new Lazyto_Dispatcher_Default());
}
return $this->_dispatcher;
}
}