symphonycms /
symphony-2
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * @package toolkit |
||
| 4 | */ |
||
| 5 | /** |
||
| 6 | * The abstract Extension class contains common methods that most |
||
| 7 | * extensions require to get started in the Symphony environment. They |
||
| 8 | * include the installation updating and uninstallation, as well as a |
||
| 9 | * delegate subscription hook so an extension can perform custom logic |
||
| 10 | * at various times during Symphony execution. |
||
| 11 | */ |
||
| 12 | abstract class Extension |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Determines that a new navigation group is to created in the Symphony backend |
||
| 16 | * @var integer |
||
| 17 | */ |
||
| 18 | const NAV_GROUP = 1; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Determines that a new item is to be added to an existing navigation |
||
| 22 | * group in the Symphony backend |
||
| 23 | * @var integer |
||
| 24 | */ |
||
| 25 | const NAV_CHILD = 0; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Status when an extension is installed and enabled |
||
| 29 | * @var integer |
||
| 30 | */ |
||
| 31 | const EXTENSION_ENABLED = 10; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Status when an extension is disabled |
||
| 35 | * @var integer |
||
| 36 | */ |
||
| 37 | const EXTENSION_DISABLED = 11; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Status when an extension is in the file system, but has not been installed. |
||
| 41 | * @var integer |
||
| 42 | */ |
||
| 43 | const EXTENSION_NOT_INSTALLED = 12; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Status when an extension version in the file system is different to |
||
| 47 | * the version stored in the database for the extension |
||
| 48 | * @var integer |
||
| 49 | */ |
||
| 50 | const EXTENSION_REQUIRES_UPDATE = 13; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Status when the extension is not compatible with the current version of |
||
| 54 | * Symphony |
||
| 55 | * @var integer |
||
| 56 | */ |
||
| 57 | const EXTENSION_NOT_COMPATIBLE = 14; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Holds an associative array of all the objects this extension provides |
||
| 61 | * to Symphony where the key is one of the Provider constants, and the |
||
| 62 | * value is the name of the classname |
||
| 63 | * |
||
| 64 | * @since Symphony 2.5.0 |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected static $provides = array(); |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Default constructor for an Extension, at this time it does nothing |
||
| 71 | */ |
||
| 72 | public function __construct() |
||
| 73 | { |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Any logic that assists this extension in being installed such as |
||
| 78 | * table creation, checking for dependancies etc. |
||
| 79 | * |
||
| 80 | * @see toolkit.ExtensionManager#install() |
||
| 81 | * @return boolean |
||
| 82 | * true if the install completely successfully, false otherwise |
||
| 83 | */ |
||
| 84 | public function install() |
||
| 85 | { |
||
| 86 | return true; |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Logic that should take place when an extension is to be been updated |
||
| 91 | * when a user runs the 'Enable' action from the backend. The currently |
||
| 92 | * installed version of this extension is provided so that it can be |
||
| 93 | * compared to the current version of the extension in the file system. |
||
| 94 | * This is commonly done using PHP's version_compare function. Common |
||
| 95 | * logic done by this method is to update differences between extension |
||
| 96 | * tables. |
||
| 97 | * |
||
| 98 | * @see toolkit.ExtensionManager#update() |
||
| 99 | * @param bool|string $previousVersion |
||
| 100 | * The currently installed version of this extension from the |
||
| 101 | * `tbl_extensions` table. The current version of this extension is |
||
| 102 | * provided by the about() method. |
||
| 103 | * @return boolean |
||
| 104 | */ |
||
| 105 | public function update($previousVersion = false) |
||
|
0 ignored issues
–
show
|
|||
| 106 | { |
||
| 107 | return true; |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Any logic that should be run when an extension is to be uninstalled |
||
| 112 | * such as the removal of database tables. |
||
| 113 | * |
||
| 114 | * @see toolkit.ExtensionManager#uninstall() |
||
| 115 | * @return boolean |
||
| 116 | */ |
||
| 117 | public function uninstall() |
||
| 118 | { |
||
| 119 | return true; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Extensions can be disabled in the backend which stops them from |
||
| 124 | * functioning by removing their delegate subscription information |
||
| 125 | * but keeps their settings intact (usually stored in the database). |
||
| 126 | * This method runs when a user selects Enable from the Symphony |
||
| 127 | * backend. |
||
| 128 | * |
||
| 129 | * @see toolkit.ExtensionManager#enable() |
||
| 130 | * @return boolean |
||
| 131 | */ |
||
| 132 | public function enable() |
||
| 133 | { |
||
| 134 | return true; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * This method runs when a user selects Disable from the Symphony |
||
| 139 | * backend. |
||
| 140 | * |
||
| 141 | * @see toolkit.ExtensionManager#enable() |
||
| 142 | * @return boolean |
||
| 143 | */ |
||
| 144 | public function disable() |
||
| 145 | { |
||
| 146 | return true; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Extensions use delegates to perform logic at certain times |
||
| 151 | * throughout Symphony. This function allows an extension to |
||
| 152 | * subscribe to a delegate which will notify the extension when it |
||
| 153 | * is used so that it can perform it's custom logic. |
||
| 154 | * This method returns an array with the delegate name, delegate |
||
| 155 | * namespace, and then name of the method that should be called. |
||
| 156 | * The method that is called is passed an associative array containing |
||
| 157 | * the current context which is the current page object |
||
| 158 | * and any other variables that is passed via this delegate. eg. |
||
| 159 | * |
||
| 160 | * `array( |
||
| 161 | * array( |
||
| 162 | * 'page' => '/current/path/', |
||
| 163 | * 'delegate' => 'DelegateName', |
||
| 164 | * 'callback' => 'functionToCall' |
||
| 165 | * ) |
||
| 166 | * )` |
||
| 167 | * |
||
| 168 | * @return array |
||
| 169 | */ |
||
| 170 | public function getSubscribedDelegates() |
||
| 171 | { |
||
| 172 | return array(); |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * When the Symphony navigation is being generated, this method will be |
||
| 177 | * called to allow extensions to inject any custom backend pages into the |
||
| 178 | * navigation. |
||
| 179 | * |
||
| 180 | * The extension can also inject link items into existing |
||
| 181 | * group's of the navigation using the 'location' key, which will accept a numeric |
||
| 182 | * index of the existing group, or the handle of an existing group. Navigation items |
||
| 183 | * in Symphony are initially provided from the `ASSETS . /xml/navigation.xml` file |
||
| 184 | * which defines the default Blueprints and System groups. The indexes for these |
||
| 185 | * groups are 100 and 200 respectively. |
||
| 186 | * |
||
| 187 | * A simple case would look like this. |
||
| 188 | * |
||
| 189 | * ``` |
||
| 190 | * return array( |
||
| 191 | * array( |
||
| 192 | * 'name' => 'Extension Name', |
||
| 193 | * 'link' => '/link/relative/to/extension/handle/', |
||
| 194 | * 'location' => 200 |
||
| 195 | * ) |
||
| 196 | * ); |
||
| 197 | * ``` |
||
| 198 | * |
||
| 199 | * If an extension wants to create a new group in the navigation |
||
| 200 | * it is possible by returning an array with the group information and then an |
||
| 201 | * array of links for this group. Groups cannot provide a link, this is done |
||
| 202 | * by the children. An example of a returned navigation |
||
| 203 | * array is provided below. |
||
| 204 | * |
||
| 205 | * ``` |
||
| 206 | * return array( |
||
| 207 | * array( |
||
| 208 | * 'name' => 'New Group', |
||
| 209 | * 'children' => array( |
||
| 210 | * array( |
||
| 211 | * 'name' => 'Extension Name', |
||
| 212 | * 'link' => '/link/relative/to/extension/handle/' |
||
| 213 | * ) |
||
| 214 | * ) |
||
| 215 | * ) |
||
| 216 | * ); |
||
| 217 | * ``` |
||
| 218 | * |
||
| 219 | * All links are relative to the Extension by default |
||
| 220 | * (i.e. `EXTENSIONS . /extension_handle/`. ) |
||
| 221 | * Set the 'relative' key to false to be able to create links |
||
| 222 | * relative to /symphony/. |
||
| 223 | * |
||
| 224 | * ``` |
||
| 225 | * return array( |
||
| 226 | * array( |
||
| 227 | * 'name' => 'Extension Name', |
||
| 228 | * 'link' => '/link/relative/to/symphony/', |
||
| 229 | * 'relative' => false, |
||
| 230 | * 'location' => 200 |
||
| 231 | * ) |
||
| 232 | * ); |
||
| 233 | * ``` |
||
| 234 | * |
||
| 235 | * You can also set the `target` attribute on your links via the 'target' attribute. |
||
| 236 | * This works both on links in standard menus and on child links of groups. |
||
| 237 | * |
||
| 238 | * ``` |
||
| 239 | * return array( |
||
| 240 | * array( |
||
| 241 | * 'name' => 'Extension Name', |
||
| 242 | * 'link' => '/.../', |
||
| 243 | * 'target' => '_blank' |
||
| 244 | * ) |
||
| 245 | * ); |
||
| 246 | * ``` |
||
| 247 | * |
||
| 248 | * Links can also be hidden dynamically using two other keys: |
||
| 249 | * 'visible' and 'limit'. When 'visible' is set to 'no', the link |
||
| 250 | * will not be rendered. Leave unset or set it dynamically in order |
||
| 251 | * to fit your needs |
||
| 252 | * |
||
| 253 | * ``` |
||
| 254 | * return array( |
||
| 255 | * array( |
||
| 256 | * 'name' => 'Extension Name', |
||
| 257 | * 'link' => '/.../', |
||
| 258 | * 'visible' => $this->shouldWeOrNot() ? 'yes' : 'no' |
||
| 259 | * ) |
||
| 260 | * ); |
||
| 261 | * ``` |
||
| 262 | * |
||
| 263 | * The 'limit' key is specifically designed to restrict the rendering process |
||
| 264 | * of a link if the current user does not have access to it based on its role. |
||
| 265 | * Symphony supports four roles which are 'author', 'manager', 'developer' |
||
| 266 | * and 'primary'. |
||
| 267 | * |
||
| 268 | * Note that setting 'visible' to 'no' will hide the link no matter what. |
||
| 269 | * |
||
| 270 | * ``` |
||
| 271 | * return array( |
||
| 272 | * array( |
||
| 273 | * 'name' => 'Developers Only', |
||
| 274 | * 'link' => '/developers-only/', |
||
| 275 | * 'limit' => 'developer' |
||
| 276 | * ) |
||
| 277 | * ); |
||
| 278 | * ``` |
||
| 279 | * |
||
| 280 | * The 'limit' key is also available for navigation groups. |
||
| 281 | * |
||
| 282 | * Note that if an extension wants to edit the current navigation, |
||
| 283 | * this is not possible through this function and rather it should be done using the |
||
| 284 | * `NavigationPreRender` delegate. |
||
| 285 | * |
||
| 286 | * @link http://github.com/symphonycms/symphony-2/blob/master/symphony/assets/xml/navigation.xml |
||
| 287 | * @return array |
||
| 288 | * An associative array of navigation items to add to the Navigation. This function |
||
| 289 | * defaults to returning null, which adds nothing to the Symphony navigation |
||
| 290 | */ |
||
| 291 | public function fetchNavigation() |
||
| 292 | { |
||
| 293 | return null; |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * This function should be implemented by the extension if there are objects |
||
| 298 | * to announce to Symphony. |
||
| 299 | * |
||
| 300 | * @since Symphony 2.5.0 |
||
| 301 | * @return boolean |
||
| 302 | */ |
||
| 303 | public static function registerProviders() |
||
| 304 | { |
||
| 305 | self::$provides = array(); |
||
| 306 | |||
| 307 | return true; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Used by Symphony to ask this extension if it's able to provide any new |
||
| 312 | * objects as defined by `$type` |
||
| 313 | * |
||
| 314 | * @since Symphony 2.5.0 |
||
| 315 | * @param string $type |
||
| 316 | * One of the `iProvider` constants |
||
| 317 | * @return array |
||
| 318 | */ |
||
| 319 | public static function providerOf($type = null) |
||
|
0 ignored issues
–
show
|
|||
| 320 | { |
||
| 321 | static::registerProviders(); |
||
| 322 | |||
| 323 | if (is_null($type)) { |
||
| 324 | return self::$provides; |
||
| 325 | } |
||
| 326 | |||
| 327 | if (!isset(self::$provides[$type])) { |
||
| 328 | return array(); |
||
| 329 | } |
||
| 330 | |||
| 331 | return self::$provides[$type]; |
||
| 332 | } |
||
| 333 | } |
||
| 334 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.