1: <?php
2: /**
3: * ManiaLive - TrackMania dedicated server manager in PHP
4: *
5: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
6: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
7: * @version $Revision: 331 $:
8: * @author $Author: martin.gwendal $:
9: * @date $Date: 2012-01-17 17:54:42 +0100 (mar., 17 janv. 2012) $:
10: */
11: namespace ManiaLive\PluginHandler;
12:
13: /**
14: * Explains a Plugin's dependency.
15: * For instnace if a Plugin uses functionality of another Plugin
16: * you can tell the PluginHandler that it needs it to be loaded as well in order
17: * to run properly. Is the dependency not loaded an Excpetion is thrown which causes
18: * the handler to stop loading of the Plugin.
19: *
20: * @author Florian Schnell
21: */
22: final class Dependency
23: {
24: const NO_LIMIT = null;
25:
26: private $min;
27: private $max;
28: private $pluginId;
29:
30: /**
31: * @param $plugin_name The name of the Plugin that is needed.
32: * @param $min The version which the Plugin at least has to have.
33: * @param $max Maximum version that is known to be supported.
34: */
35: function __construct($pluginId, $min = self::NO_LIMIT, $max = self::NO_LIMIT)
36: {
37: $this->pluginId = $pluginId;
38: $this->min = $min;
39: $this->max = $max;
40: }
41:
42: public function getMaxVersion()
43: {
44: return $this->max;
45: }
46:
47: public function getMinVersion()
48: {
49: return $this->min;
50: }
51:
52: public function getPluginId()
53: {
54: return $this->pluginId;
55: }
56: }
57:
58: class DependencyException extends \Exception {}
59:
60: class DependencyNotFoundException extends DependencyException
61: {
62: /**
63: * @param Plugin $plugin
64: * @param Dependency $dependency
65: */
66: function __construct($plugin, $dependency)
67: {
68: parent::__construct('Plugin "'.$plugin->getId().'" needs "'.$dependency->getPluginId().'" to be installed!');
69: }
70: }
71:
72: class DependencyTooOldException extends DependencyException
73: {
74: /**
75: * @param Plugin $plugin
76: * @param Dependency $dependency
77: */
78: function __construct($plugin, $dependency)
79: {
80: parent::__construct('Plugin "'.$plugin->getId().'" needs "'.$dependency->getPluginId().'" to be at least version '.$dependency->getMinVersion().'!');
81: }
82: }
83:
84: class DependencyTooNewException extends DependencyException
85: {
86: /**
87: * @param Plugin $plugin
88: * @param Dependency $dependency
89: */
90: function __construct($plugin, $dependency)
91: {
92: parent::__construct('Plugin "'.$plugin->getId().'" needs an older version of "'.$dependency->getPluginId().'" to be installed, '.$dependency->getMaxVersion().' at highest!');
93: }
94: }
95: ?>