[TASK] Prevent Inclusion of MediaWizardProvider* in Base Bootstrap 46/28046/7
authorBenjamin Mack <benni@b13.de>
Fri, 25 Jul 2014 18:32:29 +0000 (20:32 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 13 Aug 2014 19:00:51 +0000 (21:00 +0200)
On every Frontend request, the original media wizard
provider of EXT:cms is loaded, by fetching the
MediaWizardProviderManager and then
an object of MediaWizardProvider is loaded and held
in memory, as this is not needed, but only on pages
where a media is used.

This change moves the instantiation of the providers to
the time when it is needed.

Further modification would be to add the registered
wizards to TYPO3_CONF_VARS[FE][mediaProviders] and
use them directly in the MEDIA object, so the
MediaWizardProviderManager class could be deprecated.

Releases: 6.3
Resolves: #56336
Change-Id: Id466d41fef019449d820b6faec3946ec1c951488
Reviewed-on: http://review.typo3.org/28046
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/frontend/Classes/MediaWizard/MediaWizardProviderManager.php

index 3e52444..47bcce3 100644 (file)
@@ -22,11 +22,16 @@ namespace TYPO3\CMS\Frontend\MediaWizard;
 class MediaWizardProviderManager {
 
        /**
-        * @var array
+        * @var array All class names of registered providers
         */
        static protected $providers = array();
 
        /**
+        * @var array Instances of registered providers, set up on first call of getValidMediaWizardProvider()
+        */
+       static protected $providerObjects = array();
+
+       /**
         * Allows extensions to register themselves as media wizard providers
         *
         * @param string $className A class implementing MediaWizardProviderInterface
@@ -34,22 +39,37 @@ class MediaWizardProviderManager {
         * @return void
         */
        static public function registerMediaWizardProvider($className) {
-               if (!isset(self::$providers[$className])) {
-                       $provider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
-                       if (!$provider instanceof MediaWizardProviderInterface) {
-                               throw new \UnexpectedValueException($className . ' is registered as a mediaWizardProvider, so it must implement interface TYPO3\\CMS\\Frontend\\MediaWizard\\MediaWizardProviderInterface', 1285022360);
+               self::$providers[] = $className;
+       }
+
+       /**
+        * Instantiate all registered media wizard providers
+        *
+        * @throws \UnexpectedValueException
+        */
+       static protected function instantiateMediaWizardProviders() {
+               $providerClassNames = array_unique(self::$providers);
+               foreach ($providerClassNames as $className) {
+                       if (!isset(self::$providerObjects[$className])) {
+                               $provider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
+                               if (!$provider instanceof MediaWizardProviderInterface) {
+                                       throw new \UnexpectedValueException($className . ' is registered as a mediaWizardProvider, so it must implement interface TYPO3\\CMS\\Frontend\\MediaWizard\\MediaWizardProviderInterface', 1285022360);
+                               }
+                               self::$providerObjects[$className] = $provider;
                        }
-                       self::$providers[$className] = $provider;
                }
        }
 
        /**
+        * Return a media wizard provider that can handle given URL
+        *
         * @param string $url
         * @return MediaWizardProviderInterface|NULL A valid mediaWizardProvider that can handle this URL
         */
        static public function getValidMediaWizardProvider($url) {
+               self::instantiateMediaWizardProviders();
                // Go through registered providers in reverse order (last one registered wins)
-               $providers = array_reverse(self::$providers, TRUE);
+               $providers = array_reverse(self::$providerObjects, TRUE);
                foreach ($providers as $provider) {
                        /** @var $provider MediaWizardProviderInterface */
                        if ($provider->canHandle($url)) {