1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Stencil Installable package |
4
|
|
|
* |
5
|
|
|
* @package Stencil |
6
|
|
|
* @subpackage Upgrader |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Stencil_Installable |
11
|
|
|
*/ |
12
|
|
|
class Stencil_Installables { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* List of registered installables. |
16
|
|
|
* |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private $installables = array(); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Register all installable items. |
23
|
|
|
*/ |
24
|
|
|
public function __construct() { |
25
|
|
|
$this->add_installable( new Stencil_Installable_Plugin( 'stencil-dwoo2', 'Dwoo 2', '5.4.0' ) ); |
26
|
|
|
$this->add_installable( new Stencil_Installable_Plugin( 'stencil-mustache', 'Mustache' ) ); |
27
|
|
|
$this->add_installable( new Stencil_Installable_Plugin( 'stencil-savant3', 'Savant 3' ) ); |
28
|
|
|
$this->add_installable( new Stencil_Installable_Plugin( 'stencil-smarty2', 'Smarty 2.x' ) ); |
29
|
|
|
$this->add_installable( new Stencil_Installable_Plugin( 'stencil-smarty3', 'Smarty 3.x' ) ); |
30
|
|
|
$this->add_installable( new Stencil_Installable_Plugin( 'stencil-twig', 'Twig' ) ); |
31
|
|
|
|
32
|
|
|
$this->add_installable( new Stencil_Installable_Theme( 'dwoo2', 'Dwoo' ) ); |
33
|
|
|
$this->add_installable( new Stencil_Installable_Theme( 'mustache', 'Mustache' ) ); |
34
|
|
|
$this->add_installable( new Stencil_Installable_Theme( 'smarty', 'Smarty' ) ); |
35
|
|
|
$this->add_installable( new Stencil_Installable_Theme( 'twig', 'Twig' ) ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Add an installable to the list. |
40
|
|
|
* |
41
|
|
|
* @param Stencil_Installable_Interface $installable Installable to add. |
42
|
|
|
*/ |
43
|
|
|
public function add_installable( Stencil_Installable_Interface $installable ) { |
44
|
|
|
$this->installables[] = $installable; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get Installable by slug. |
49
|
|
|
* |
50
|
|
|
* @param string $slug Slug to find. |
51
|
|
|
* |
52
|
|
|
* @return mixed|null |
53
|
|
|
*/ |
54
|
|
|
public function get_by_slug( $slug ) { |
55
|
|
|
foreach ( $this->installables as $installable ) { |
56
|
|
|
if ( $installable->get_slug() === $slug ) { |
57
|
|
|
return $installable; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Retrieve all plugins |
66
|
|
|
* |
67
|
|
|
* @return Iterator list of Plugins. |
68
|
|
|
*/ |
69
|
|
|
public function get_plugins() { |
70
|
|
|
return $this->get_installable_filtered( 'Stencil_Installable_Plugin' ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get all registered themes. |
75
|
|
|
* |
76
|
|
|
* @return Iterator list of Themes. |
77
|
|
|
*/ |
78
|
|
|
public function get_themes() { |
79
|
|
|
return $this->get_installable_filtered( 'Stencil_Installable_Theme' ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get upgradable installables |
84
|
|
|
* |
85
|
|
|
* @return array of upgradable installables. |
86
|
|
|
*/ |
87
|
|
|
public function get_upgradable() { |
88
|
|
|
$output = array(); |
89
|
|
|
|
90
|
|
|
foreach ( $this->installables as $installable ) { |
91
|
|
|
if ( $installable->has_upgrade() ) { |
92
|
|
|
$output[] = $installable; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $output; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get specific installables. |
101
|
|
|
* |
102
|
|
|
* @param string $class Class to get objects of. |
103
|
|
|
* |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
private function get_installable_filtered( $class ) { |
107
|
|
|
|
108
|
|
|
$output = array(); |
109
|
|
|
foreach ( $this->installables as $installable ) { |
110
|
|
|
if ( is_a( $installable, $class ) ) { |
111
|
|
|
$output[] = $installable; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $output; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|