Ejemplo n.º 1
0
 /**
  * Returns a unique instance of the Singleton object. Use this method instead of the private/protected class constructor.
  * 
  * @param   void
  * @return  Tx_PtExtbase_Registry_Registry      unique instance of the Singleton object
  * @author 	Fabrizio Branca <*****@*****.**>
  */
 public static function getInstance()
 {
     if (self::$uniqueInstance === null) {
         self::$uniqueInstance = new Tx_PtExtbase_Registry_Registry();
     }
     return self::$uniqueInstance;
 }
Ejemplo n.º 2
0
 /**
  * Returns typoscript configuration independent of frontend or backend context and caches it into the registry (with the key: ts_$tsConfigKey) to prevent multiple configuration loading.
  *
  * When calling this method with 'plugin.my_ext.' the whole typoscript configuration under this path is stored into the registry.
  * But: When calling this method with 'plugin.my_ext.anotherkey.' the configuration is loaded again instead of looking for the key 'anotherkey.' in the previously loaded configuration.
  * To improve performance always call the highest level and pick the keys after: $conf = Tx_PtExtbase_Div::typoscriptRegistry('plugin.my_ext.'); $key = $conf['anotherkey.']
  *
  * @example
  *  If being only in frontend context:
  *  - Tx_PtExtbase_Div::typoscriptRegistry('plugin.my_ext.');
  *
  *  For all cases, when already having the page uid from where to load the typscript available (will only be used in non-frontend-context)
  *  - Tx_PtExtbase_Div::typoscriptRegistry('plugin.my_ext.', 1);
  *
  *  For all cases, assuming the pageUid is configured in "tsConfigurationPid" of the extension manager configuration (will only be used in non-frontend-context)
  *  - Tx_PtExtbase_Div::typoscriptRegistry('plugin.my_ext.', NULL, 'my_ext', 'tsConfigurationPid');
  *
  * @param     string    typoscript config key, e.g. "plugin.tx_myext."
  * @param     integer       (optional) pageuid
  * @param     string    (optional) extension key
  * @param     string    (optional) extConfKey, e.g. "tsConfigurationPid"
  * @return    array     typoscript configuation array
  * @author    Fabrizio Branca <*****@*****.**>
  */
 public static function typoscriptRegistry($tsConfigKey, $pageUid = null, $extKey = '', $extConfKey = '')
 {
     Tx_PtExtbase_Assertions_Assert::isNotEmptyString($tsConfigKey, array('message' => 'No "tsConfigKey" defined!'));
     require_once ExtensionManagementUtility::extPath('pt_extbase') . 'Classes/Registry/Registry.php';
     $registry = Tx_PtExtbase_Registry_Registry::getInstance();
     $registryKey = 'ts_' . $tsConfigKey;
     if (!$registry->has($registryKey)) {
         // In frontend context
         if ($GLOBALS['TSFE'] instanceof \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController) {
             $confArray = self::getTS($tsConfigKey);
             // Not in frontend context
         } else {
             if (!is_null($pageUid)) {
                 Tx_PtExtbase_Assertions_Assert::isValidUid($pageUid, false, array('message' => 'No valid pageUid given'));
                 $confArray = self::returnTyposcriptSetup($pageUid, $tsConfigKey);
             } elseif (!empty($extKey) && !empty($extConfKey)) {
                 $tmpExtConfArray = self::returnExtConfArray($extKey);
                 $pageUid = $tmpExtConfArray[$extConfKey];
                 Tx_PtExtbase_Assertions_Assert::isValidUid($pageUid, false, array('message' => 'No valid pageUid found under "' . $extConfKey . '" in extension configuration for extKey "' . $extKey . '"'));
                 $confArray = self::returnTyposcriptSetup($pageUid, $tsConfigKey);
             } else {
                 throw new \PunktDe\PtExtbase\Exception\Exception('You have to define either a "pageUid" or a "extKey" and a "extConfKey" when not in frontend context.');
             }
         }
         $registry->register($registryKey, $confArray);
     }
     return $registry->get($registryKey);
 }