[TASK] Add more fixers for php-cs-fixer
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Rendering / RendererRegistry.php
index 59a1a7a..6186508 100644 (file)
@@ -20,113 +20,119 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 /**
  * Class RendererRegistry
  */
-class RendererRegistry implements \TYPO3\CMS\Core\SingletonInterface {
+class RendererRegistry implements \TYPO3\CMS\Core\SingletonInterface
+{
+    /**
+     * Registered class names
+     *
+     * @var array
+     */
+    protected $classNames = [];
 
-       /**
-        * Registered class names
-        *
-        * @var array
-        */
-       protected $classNames = array();
+    /**
+     * Instance cache for renderer classes
+     *
+     * @var FileRendererInterface[]
+     */
+    protected $instances = null;
 
-       /**
-        * Instance cache for renderer classes
-        *
-        * @var FileRendererInterface[]
-        */
-       protected $instances = NULL;
+    /**
+     * Returns an instance of this class
+     *
+     * @return RendererRegistry
+     */
+    public static function getInstance()
+    {
+        return GeneralUtility::makeInstance(self::class);
+    }
 
-       /**
-        * Returns an instance of this class
-        *
-        * @return RendererRegistry
-        */
-       static public function getInstance() {
-               return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class);
-       }
+    /**
+     * Allows to register a Renderer class
+     *
+     * @param string $className
+     * @throws \InvalidArgumentException
+     */
+    public function registerRendererClass($className)
+    {
+        if (!class_exists($className)) {
+            throw new \InvalidArgumentException('The class "' . $className . '" you are trying to register is not available', 1411840171);
+        } elseif (!in_array(FileRendererInterface::class, class_implements($className), true)) {
+            throw new \InvalidArgumentException('The renderer needs to implement the FileRendererInterface', 1411840172);
+        } else {
+            $this->classNames[] = $className;
+        }
+    }
 
-       /**
-        * Allows to register a Renderer class
-        *
-        * @param string $className
-        * @throws \InvalidArgumentException
-        */
-       public function registerRendererClass($className) {
-               if (!class_exists($className)) {
-                       throw new \InvalidArgumentException('The class you are registering is not available', 1411840171);
-               } elseif (!in_array(\TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface::class, class_implements($className), TRUE)) {
-                       throw new \InvalidArgumentException('The renderer needs to implement the FileRendererInterface', 1411840172);
-               } else {
-                       $this->classNames[] = $className;
-               }
-       }
+    /**
+     * Get all registered renderer instances
+     *
+     * @return FileRendererInterface[]
+     */
+    public function getRendererInstances()
+    {
+        if ($this->instances === null) {
+            $this->instances = [];
 
-       /**
-        * Get all registered renderer instances
-        *
-        * @return FileRendererInterface[]
-        */
-       public function getRendererInstances() {
-               if ($this->instances === NULL) {
-                       $this->instances = array();
+            // As the result is in reverse order we need to reverse
+            // the array before processing to keep the items with same
+            // priority in the same order as they were added to the registry.
+            $classNames = array_reverse($this->classNames);
+            foreach ($classNames as $className) {
+                /** @var FileRendererInterface $object */
+                $object = $this->createRendererInstance($className);
+                $this->instances[] = $object;
+            }
 
-                       // As the result is in reverse order we need to reverse
-                       // the array before processing to keep the items with same
-                       // priority in the same order as they were added to the registry.
-                       $classNames = array_reverse($this->classNames);
-                       foreach ($classNames as $className) {
-                               /** @var FileRendererInterface $object */
-                               $object = $this->createRendererInstance($className);
-                               $this->instances[] = $object;
-                       }
+            if (count($this->instances) > 1) {
+                usort($this->instances, [$this, 'compareRendererPriority']);
+            }
+        }
+        return $this->instances;
+    }
 
-                       if (count($this->instances) > 1) {
-                               usort($this->instances, array($this, 'compareRendererPriority'));
-                       }
-               }
-               return $this->instances;
-       }
+    /**
+     * Create an instance of a certain renderer class
+     *
+     * @param string $className
+     * @return FileRendererInterface
+     */
+    protected function createRendererInstance($className)
+    {
+        return GeneralUtility::makeInstance($className);
+    }
 
-       /**
-        * Create an instance of a certain renderer class
-        *
-        * @param string $className
-        * @return FileRendererInterface
-        */
-       protected function createRendererInstance($className) {
-               return GeneralUtility::makeInstance($className);
-       }
+    /**
+     * Compare the priority of two renderer classes
+     * Is used for sorting array of Renderer instances by priority
+     * We want the result to be ordered from high to low so a higher
+     * priority comes before a lower.
+     *
+     * @param FileRendererInterface $rendererA
+     * @param FileRendererInterface $rendererB
+     * @return int -1 a > b, 0 a == b, 1 a < b
+     */
+    protected function compareRendererPriority(FileRendererInterface $rendererA, FileRendererInterface $rendererB)
+    {
+        return $rendererB->getPriority() - $rendererA->getPriority();
+    }
 
-       /**
-        * Compare the priority of two renderer classes
-        * Is used for sorting array of Renderer instances by priority
-        * We want the result to be ordered from high to low so a higher
-        * priority comes before a lower.
-        *
-        * @param FileRendererInterface $rendererA
-        * @param FileRendererInterface $rendererB
-        * @return int -1 a > b, 0 a == b, 1 a < b
-        */
-       protected function compareRendererPriority(FileRendererInterface $rendererA, FileRendererInterface $rendererB) {
-               return $rendererB->getPriority() - $rendererA->getPriority();
-       }
+    /**
+     * Get matching renderer with highest priority
+     *
+     * @param FileInterface $file
+     * @return NULL|FileRendererInterface
+     */
+    public function getRenderer(FileInterface $file)
+    {
+        $matchingFileRenderer = null;
 
-       /**
-        * Get matching renderer with highest priority
-        *
-        * @param FileInterface $file
-        * @return NULL|FileRendererInterface
-        */
-       public function getRenderer(FileInterface $file) {
-               $matchingFileRenderer = NULL;
-
-               /** @var FileRendererInterface $fileRenderer */
-               foreach ($this->getRendererInstances() as $fileRenderer) {
-                       if ($fileRenderer->canRender($file)) {
-                               $matchingFileRenderer = $fileRenderer;
-                               break;
-                       }
-               }
-               return $matchingFileRenderer;
-       }
-}
\ No newline at end of file
+        /** @var FileRendererInterface $fileRenderer */
+        foreach ($this->getRendererInstances() as $fileRenderer) {
+            if ($fileRenderer->canRender($file)) {
+                $matchingFileRenderer = $fileRenderer;
+                break;
+            }
+        }
+        return $matchingFileRenderer;
+    }
+}