-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathPlugin.php
More file actions
119 lines (98 loc) · 3.5 KB
/
Plugin.php
File metadata and controls
119 lines (98 loc) · 3.5 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace Foolz\Plugin;
/**
* Holds data on a plugin package
*
* @author Foolz <support@foolz.us>
* @package Foolz\Plugin
* @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License 2.0
*/
class Plugin extends \Foolz\Package\Package
{
/**
* Returns an AssetManager object to deal with the assets
*
* @return \Foolz\Plugin\AssetManager A new instance of the AssetManager
*/
public function getAssetManager()
{
if ($this->asset_manager !== null) {
return $this->asset_manager;
}
return $this->asset_manager = new AssetManager($this);
}
/**
* Runs the execution block
*
* @return \Foolz\Plugin\Plugin
*/
public function execute()
{
// clear the hook since we might have an old one
\Foolz\Plugin\Event::clear(get_class().'::execute.'.$this->getConfig('name'));
$this->bootstrap();
\Foolz\Plugin\Hook::forge(get_class().'::execute.'.$this->getConfig('name'))
->setObject($this)
->execute();
return $this;
}
/**
* Triggers the install methods for the plugin
*
* @return \Foolz\Plugin\Plugin
*/
public function install()
{
// clear the hook since we might have an old one
\Foolz\Plugin\Event::clear(get_class().'::install.'.$this->getJsonConfig('name'));
// execute the bootstrap to get the events instantiated
$this->bootstrap();
\Foolz\Plugin\Hook::forge(get_class().'::install.'.$this->getJsonConfig('name'))
->setObject($this)
->execute();
return $this;
}
/**
* Triggers the remove methods for the plugin. Doesn't remove the files.
*
* @return \Foolz\Plugin\Plugin
*/
public function uninstall()
{
// clear the hook since we might have an old one
\Foolz\Plugin\Event::clear(get_class().'::uninstall.'.$this->getJsonConfig('name'));
// execute the bootstrap to get the events instantiated
$this->bootstrap();
\Foolz\Plugin\Hook::forge(get_class().'::uninstall.'.$this->getJsonConfig('name'))
->setObject($this)
->execute();
return $this;
}
/**
* Triggers the upgrade methods for the plugin. At this point the files MUST have changed.
* It will give two parameters to the Event: old_revision and new_revision, which are previous and new value
* for extra.revision in the composer.json. These can be used to determine which actions to undertake.
*
* @return \Foolz\Plugin\Plugin
*/
public function upgrade()
{
// clear the json data so we use the latest
$this->clearJsonConfig();
// clear the hook since we for sure have an old one
\Foolz\Plugin\Event::clear(get_class().'::upgrade.'.$this->getJsonConfig('name'));
// execute the bootstrap to get the events re-instantiated
$this->bootstrap();
// run the event
\Foolz\Plugin\Hook::forge(get_class().'::upgrade.'.$this->getJsonConfig('name'))
->setObject($this)
// the PHP config holds the old revision
->setParam('old_revision', $this->getConfig('extra.revision', 0))
// the JSON config holds the new revision
->setParam('new_revision', $this->getJsonConfig('extra.revision', 0))
->execute();
// update the PHP config file so it has the new revision
$this->refreshConfig();
return $this;
}
}