|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Godbout\Alfred\Workflow; |
|
4
|
|
|
|
|
5
|
|
|
use ReflectionClass; |
|
6
|
|
|
use Godbout\Alfred\Workflow\Contracts\Workflow; |
|
7
|
|
|
|
|
8
|
|
|
abstract class BaseWorkflow implements Workflow |
|
9
|
|
|
{ |
|
10
|
|
|
protected static $instance = null; |
|
11
|
|
|
protected $scriptFilter = null; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
12 |
|
protected function __construct() |
|
15
|
|
|
{ |
|
16
|
12 |
|
$this->scriptFilter = ScriptFilter::create(); |
|
17
|
12 |
|
} |
|
18
|
|
|
|
|
19
|
24 |
|
final public static function getInstance() |
|
20
|
|
|
{ |
|
21
|
24 |
|
if (is_null(self::$instance)) { |
|
22
|
12 |
|
self::$instance = new static(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
24 |
|
return self::$instance; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
6 |
|
public static function currentMenu() |
|
29
|
|
|
{ |
|
30
|
6 |
|
static::getCurrentMenuClass()::scriptFilter(); |
|
31
|
|
|
|
|
32
|
6 |
|
return static::getInstance()->scriptFilter->output(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
6 |
|
private static function getCurrentMenuClass() |
|
36
|
|
|
{ |
|
37
|
6 |
|
$menu = static::getMenuClassName(getenv('next')) ?: 'Entrance'; |
|
38
|
|
|
|
|
39
|
6 |
|
return (new ReflectionClass(static::class))->getNamespaceName() . "\\Menus\\" . $menu; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
6 |
|
private static function getMenuClassName($action) |
|
43
|
|
|
{ |
|
44
|
6 |
|
return str_replace('_', '', ucwords($action === false ? 'entrance' : $action, '_')); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
12 |
|
public static function do() |
|
48
|
|
|
{ |
|
49
|
12 |
|
$action = getenv('action'); |
|
50
|
|
|
|
|
51
|
12 |
|
if (method_exists(static::class, $action)) { |
|
52
|
6 |
|
return static::$action(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
6 |
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
6 |
|
public static function notify($result = false) |
|
59
|
|
|
{ |
|
60
|
6 |
|
$action = getenv('action'); |
|
61
|
|
|
|
|
62
|
6 |
|
if ($result === false) { |
|
63
|
6 |
|
return "Oops... cannot $action."; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
6 |
|
return "$action is done!"; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
6 |
|
public static function destroy() |
|
70
|
|
|
{ |
|
71
|
6 |
|
ScriptFilter::destroy(); |
|
72
|
|
|
|
|
73
|
6 |
|
self::$instance = null; |
|
74
|
6 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function __clone() |
|
77
|
|
|
{ |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|