Esempio n. 1
0
 /**
  * Adds one item to the collection
  *
  * @param	object	object to add
  * @param	mixed	array key / label (use namespaces here to avoid conflicts!)
  * @param	bool	(optional) overwrite existing object, default is false
  * @return	void
  * @throws	Exception	if the given label already exists and overwrite if false
  */
 public function addItem($object, $label, $overwrite = false)
 {
     Tx_PtExtbase_Assertions_Assert::isNotEmpty($label, array('message' => 'Registry keys cannot be empty!'));
     if (!$this->hasItem($label) || $overwrite == true) {
         // add object to the collection
         parent::addItem($object, $label);
     } else {
         throw new Exception('There is already an element stored with the label "' . $label . '" (and overwriting not permitted)!');
     }
 }
Esempio n. 2
0
 /**
  * Get Typoscript from array
  *
  * @example To get an array: Tx_PtExtbase_Div::getTS('plugin.my_ext.');
  * @example To get a single value: Tx_PtExtbase_Div::getTS('plugin.my_ext.my_key');
  * @param   string      typoscript path
  * @param   array       (optional) typoscript array, if empty using $GLOBALS['TSFE']->tmpl->setup
  * @return  mixed       typoscript array or single value
  * @throws    Tx_PtExtbase_Exception_Assertion     if no tsArray is given and not being in a frontend context
  * @throws    Tx_PtExtbase_Exception_Assertion     if tsPath is not valid
  * @throws    \PunktDe\PtExtbase\Exception\Exception            if subKey was not found
  * @author  Rainer Kuhn , Fabrizio Branca <*****@*****.**>
  */
 public static function getTS($tsPath, array $tsArray = array())
 {
     Tx_PtExtbase_Assertions_Assert::isNotEmptyString($tsPath, array('message' => '"tsPath" is empty!'));
     // TODO: improve pattern, so that ".blub" or "plugin..test" are not matched
     if (empty($tsArray)) {
         Tx_PtExtbase_Assertions_Assert::isInstanceOf($GLOBALS['TSFE'], 'tslib_fe', array('message' => 'No TSFE available!'));
         $tsArray = $GLOBALS['TSFE']->tmpl->setup;
     }
     Tx_PtExtbase_Assertions_Assert::isNotEmpty($tsArray);
     $lastKeyIsArray = false;
     if (substr($tsPath, -1) == '.') {
         $lastKeyIsArray = true;
     }
     $keyPartsArray = explode('.', $tsPath);
     for ($i = 0; $i < count($keyPartsArray); $i++) {
         if (!empty($keyPartsArray[$i])) {
             $newSubKey = $keyPartsArray[$i] . ($i < count($keyPartsArray) - 1 || $lastKeyIsArray == true ? '.' : '');
             $tsArray = $tsArray[$newSubKey];
         }
     }
     return $tsArray;
 }