1: <?php
2:
3: App::uses('PluginManager', 'PluginManager.Lib');
4:
5: class Plugin {
6:
7: /**
8: *
9: * @var string
10: */
11: private $name;
12:
13: /**
14: *
15: * @var string[]
16: */
17: private $dependencies = array();
18:
19: public function __construct($name, $dependencies) {
20: $this->name = $name;
21: $this->dependencies = $dependencies;
22: }
23:
24: public function getName() {
25: return $this->name;
26: }
27:
28: public function dependencies() {
29: return $this->dependencies;
30: }
31:
32: public function load() {
33: foreach ($this->dependencies as $pluginName) {
34: self::_loadPlugin($pluginName);
35: }
36: }
37:
38: private static function _loadPlugin($name) {
39: CakePlugin::load($name, array('bootstrap' => self::_pluginHasBootstrapFile($name)));
40: }
41:
42: private static function _pluginHasBootstrapFile($name) {
43: return is_file(self::_pluginPath($name) . DS . 'Config' . DS . 'bootstrap.php');
44: }
45:
46: private static function _pluginPath($name) {
47: if (CakePlugin::loaded($name)) {
48: return CakePlugin::path($name);
49: }
50:
51: foreach (App::path('plugins') as $path) {
52: if (is_dir($path . $name)) {
53: return $path . $name . DS;
54: }
55: }
56:
57: throw new Exception("Was not possible to determinate the location of plugin \"$name\"");
58: }
59:
60: }