Use object manager to create object instances
authorstan <stan@735d13b6-9817-0410-8766-e36946ffe9aa>
Wed, 13 Feb 2013 20:33:51 +0000 (20:33 +0000)
committerstan <stan@735d13b6-9817-0410-8766-e36946ffe9aa>
Wed, 13 Feb 2013 20:33:51 +0000 (20:33 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/sr_freecap/trunk@71179 735d13b6-9817-0410-8766-e36946ffe9aa

ChangeLog
Classes/Controller/AudioPlayerController.php
Classes/Controller/FontMakerController.php
Classes/Controller/ImageGeneratorController.php
Classes/Domain/Repository/WordRepository.php
Classes/PiBaseApi.php
Classes/Utility/FontMakingUtility.php
Classes/Validation/Validator/CaptchaValidator.php
Classes/View/ImageGenerator/ShowPng.php
Classes/ViewHelpers/AudioViewHelper.php
Classes/ViewHelpers/ImageViewHelper.php

index 47910cb..4a1caa0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
        * Add option to configure the encryption algorithm in Extension Manager
        * Disable the audio feature on iOS devices
+       * Use object manager to create object instances
 
 2013-02-12  Stanislas Rolland  <typo3@sjbr.ca>
 
index b8715d7..e16176a 100644 (file)
@@ -49,7 +49,7 @@ class AudioPlayerController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionCont
         */
        public function initializeAction() {
                // Get an instance of the word repository
-               $this->wordRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\SrFreecap\Domain\Repository\WordRepository');
+               $this->wordRepository = $this->objectManager->get('SJBR\SrFreecap\Domain\Repository\WordRepository');
        }
 
        /**
index 87eba12..ff2018b 100644 (file)
@@ -3,7 +3,7 @@ namespace SJBR\SrFreecap\Controller;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2012 Stanislas Rolland <typo3@sjbr.ca>
+ *  (c) 2012-2013 Stanislas Rolland <typo3@sjbr.ca>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -25,7 +25,6 @@ namespace SJBR\SrFreecap\Controller;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
-
 /**
  * Font Maker controller
  *
@@ -46,7 +45,7 @@ class FontMakerController  extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContr
         */
        public function newAction(\SJBR\SrFreecap\Domain\Model\Font $font = NULL) {
                if (!is_object($font)) {
-                       $font = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\SrFreecap\Domain\Model\Font');
+                       $font = $this->objectManager->create('SJBR\SrFreecap\Domain\Model\Font');
                }
                $this->view->assign('font', $font);
        }       
@@ -61,7 +60,7 @@ class FontMakerController  extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContr
                // Create the font data
                $font->createGdFontFile();
                // Store the GD font file
-               $fontRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\SrFreecap\Domain\Repository\FontRepository');
+               $fontRepository = $this->objectManager->get('SJBR\SrFreecap\Domain\Repository\FontRepository');
                $fontRepository->writeFontFile($font);
                $this->view->assign('font', $font);
        }
index 08f0010..2c7b1c2 100644 (file)
@@ -54,7 +54,7 @@ class ImageGeneratorController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionC
         */
        public function initializeAction() {
                // Get an instance of the word repository
-               $this->wordRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
+               $this->wordRepository = $this->objectManager->get('SJBR\SrFreecap\Domain\Repository\WordRepository');
        }
 
        /**
index c3b4ce4..96c56c4 100644 (file)
@@ -42,12 +42,12 @@ class WordRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
        /**
         * Constructor
         *
-        * @return \SJBR\SrFreecap\Domain\Repository\WordRepository
+        * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
         */
-       public function __construct() {
-               parent::__construct();
+       public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager = NULL) {
+               parent::__construct($objectManager);
                // Get an instance of the session storage handler
-               $this->sessionStorage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\Domain\\Session\\SessionStorage');
+               $this->sessionStorage = $this->objectManager->get('SJBR\\SrFreecap\\Domain\\Session\\SessionStorage');
        }
  
        /**
@@ -59,7 +59,7 @@ class WordRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
                $word = $this->sessionStorage->restoreFromSession();
                // If no Word object is found in session data, initialize a new one
                if (!is_object($word)) {
-                       $word = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\Domain\\Model\\Word');
+                       $word = $this->objectManager->create('SJBR\\SrFreecap\\Domain\\Model\\Word');
                }
                return $word;
        }
index 5fea061..35031e1 100644 (file)
@@ -62,32 +62,41 @@ class PiBaseApi {
        public $extKey = 'sr_freecap';
 
        /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
+        */
+       protected $objectManager = NULL;
+
+       /**
         * This function generates an array of markers used to render the captcha element
         *
         * @return array marker array containing the captcha markers to be sustituted in the html template
         */     
        public function makeCaptcha() {
 
-               // Get the translation view helper
-               $configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
-               $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
-               $configurationManager->injectObjectManager($objectManager);
+               // Get the object manager
+               if ($this->objectManager === NULL) {
+                       $this->objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+               }
+               
+               // Get the configuration manager
+               $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
+               $configurationManager->injectObjectManager($this->objectManager);
                
                // Get translation view helper
-               $translator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
+               $translator = $this->objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
                $translator->injectConfigurationManager($configurationManager);
 
                $markerArray = array();
                $markerArray['###'. strtoupper($this->extKey) . '_NOTICE###'] = $translator->render('notice') . ' ' . $translator->render('explain');
 
                // Get the captcha image view helper
-               $imageViewHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\ViewHelpers\\ImageViewHelper');
+               $imageViewHelper = $this->objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\ImageViewHelper');
                $imageViewHelper->injectConfigurationManager($configurationManager);
                $markerArray['###'. strtoupper($this->extKey) . '_IMAGE###'] = $imageViewHelper->render('pi1');
                $markerArray['###'. strtoupper($this->extKey) . '_CANT_READ###'] = '';
 
                // Get the audio icon view helper
-               $audioViewHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\ViewHelpers\\AudioViewHelper');
+               $audioViewHelper = $this->objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\AudioViewHelper');
                $audioViewHelper->injectConfigurationManager($configurationManager);
                $markerArray['###'. strtoupper($this->extKey) . '_ACCESSIBLE###'] = $audioViewHelper->render('pi1');
 
@@ -101,8 +110,12 @@ class PiBaseApi {
         * @return      boolean         true, if the word entered matches the hashes value
         */
        public function checkWord ($word) {
-               // Get validator
-               $validator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\Validation\\Validator\\CaptchaValidator');
+               // Get the object manager
+               if ($this->objectManager === NULL) {
+                       $this->objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+               }
+               // Get the validator
+               $validator = $this->objectManager->get('SJBR\\SrFreecap\\Validation\\Validator\\CaptchaValidator');
                // Check word
                return $validator->isValid($word);
        }
index 572963a..deafa90 100644 (file)
@@ -3,7 +3,7 @@ namespace SJBR\SrFreecap\Utility;
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2012 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2012-2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -76,8 +76,8 @@ class FontMakingUtility {
                        $gifObjArray[$ic . '0.']['maxWidth'] = $width;
                        $gifObjArray[$ic . '0.']['offset'] = (($ic-1) * $width + $hOffset) . ',' . $vertOffset;
                }
-               
-               $gifCreator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\SrFreecap\Utility\GifBuilderUtility');
+               $objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+               $gifCreator = $objectManager->create('SJBR\SrFreecap\Utility\GifBuilderUtility');
                $gifCreator->init();
                if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
                        $gifCreator->start($gifObjArray, array());
index 8364924..290d5fc 100644 (file)
@@ -3,7 +3,7 @@ namespace SJBR\SrFreecap\Validation\Validator;
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2012 Stanislas Rolland <typo3@sjbr.ca>
+*  (c) 2012-2013 Stanislas Rolland <typo3@sjbr.ca>
 *  All rights reserved
 *
 *  This class is a backport of the corresponding class of FLOW3. 
@@ -46,7 +46,8 @@ class CaptchaValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractV
                $isValid = FALSE;
                $this->errors = array();
                // Get session data
-               $wordRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
+               $objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+               $wordRepository = $objectManager->get('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
                $wordObject = $wordRepository->getWord();
                $wordHash = $wordObject->getWordHash();
                // Check the word hash against the stored hash value
index 92aa971..5e408c9 100644 (file)
@@ -171,7 +171,8 @@ class ShowPng implements \TYPO3\CMS\Extbase\MVC\View\ViewInterface {
                                $this->word->setWordCypher(array());
                                $this->word->setHashFunction('');
                                // Get an instance of the word repository
-                               $wordRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
+                               $objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+                               $wordRepository = $objectManager->get('SJBR\\SrFreecap\\Domain\\Repository\\WordRepository');
                                // Reset the word
                                $wordRepository->setWord($this->word);
                                $string = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('max_attempts', $this->extensionName);
index 3089ee3..3be2686 100644 (file)
@@ -61,7 +61,8 @@ class AudioViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
                // Get the plugin configuration
                $settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->extensionName, $this->pluginName);
                // Get the translation view helper
-               $translator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
+               $objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+               $translator = $objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
                $translator->injectConfigurationManager($this->configurationManager);
                // Get browser info (as of iOS 6, audio rendering does not work)
                $browserInfo = \TYPO3\CMS\Core\Utility\ClientUtility::getBrowserInfo(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_USER_AGENT'));
index 3a49c7d..c95c215 100644 (file)
@@ -75,7 +75,8 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
                $settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->extensionName, $this->pluginName);
 
                // Get the translation view helper
-               $translator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
+               $objectManager = new \TYPO3\CMS\Extbase\Object\ObjectManager();
+               $translator = $objectManager->get('SJBR\\SrFreecap\\ViewHelpers\\TranslateViewHelper');
                $translator->injectConfigurationManager($this->configurationManager);
 
                // Generate the image url