[FEATURE] stdWrap caching
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_mediawizardmanager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Ernesto Baschny <ernst@cron-it.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Manager to register and call registered media wizard providers
30
31 * @author Ernesto Baschny <ernst@cron-it.de>
32 * @static
33 */
34 class tslib_mediaWizardManager {
35
36 protected static $providers = array();
37
38 /**
39 * Allows extensions to register themselves as media wizard providers
40 *
41 * @param string $className A class implementing tslib_mediaWizardProvider
42 * @return void
43 */
44 public static function registerMediaWizardProvider($className) {
45 if (!isset(self::$providers[$className])) {
46 $provider = t3lib_div::makeInstance($className);
47 if (!($provider instanceof tslib_mediaWizardProvider)) {
48 throw new UnexpectedValueException(
49 $className .' is registered as a mediaWizardProvider, so it must implement interface tslib_mediaWizardProvider',
50 1285022360
51 );
52 }
53 self::$providers[$className] = $provider;
54 }
55 }
56
57 /**
58 *
59 * @param string $url
60 * @return a valid mediaWizardProvider that can handle this URL
61 */
62 public static function getValidMediaWizardProvider($url) {
63 // Go through registered providers in reverse order (last one registered wins)
64 $providers = array_reverse(self::$providers, TRUE);
65 foreach (self::$providers as $className => $provider) {
66 /** @var $provider tslib_mediaWizardProvider */
67 if ($provider->canHandle($url)) {
68 return $provider;
69 }
70 }
71 // no provider found
72 return NULL;
73 }
74
75 }
76
77 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_mediawizardmanager.php'])) {
78 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_mediawizardmanager.php']);
79 }
80
81 ?>