コード例 #1
0
 public function doCalculation($oTemplateIdentifier, &$iFlags)
 {
     if (self::$CALCULATOR === null) {
         self::$CALCULATOR = new NXP\MathExecutor();
     }
     return self::$CALCULATOR->execute($oTemplateIdentifier->getValue());
 }
コード例 #2
0
ファイル: Template.php プロジェクト: rapila/cms-base
 /**
  * Replaces all special identifiers that are supposed to be replaced on either start or end of a page's lifecycle depending on the value of the parameter bIsLast.
  * Special identifiers that are replaced on start usually have their values cached with the template caching mechanisms where as the other template identifiers are left alone. The default is for special template identifiers to be rendered on start. Exceptions are writeParameterizedString and writeFlashValue and are stored in the array returned by {@link SpecialTemplateIdentifierActions::getAlwaysLastNames()}. You can force an identifier to be rendered on end by appending the parameter <code>;position=last</code>. Note, however, that you cannot use <code>;position=first</code> to override the behaviour of the special template identifiers that are always rendered on end.
  */
 private function replaceSpecialIdentifiers($bIsLast)
 {
     $sNotPosition = $bIsLast ? "first" : "last";
     $aIdentifierNames = array_fill_keys(SpecialTemplateIdentifierActions::getSpecialIdentifierNames(), 1);
     $aAlwaysLastNames = array_fill_keys(SpecialTemplateIdentifierActions::getAlwaysLastNames(), 1);
     foreach ($this->allIdentifiers() as $oIdentifier) {
         $sIdentifierName = $oIdentifier->getName();
         if (!$bIsLast && isset($aAlwaysLastNames[$sIdentifierName]) || $oIdentifier->getParameter('position') === $sNotPosition) {
             continue;
         }
         if (!isset($aIdentifierNames[$sIdentifierName])) {
             continue;
         }
         if ($oIdentifier->hasParameter('position')) {
             $oIdentifier->unsetParameter('position');
         }
         if ($aIdentifierNames[$sIdentifierName] === 1) {
             $aIdentifierNames[$sIdentifierName] = array();
         }
         $aIdentifierNames[$sIdentifierName][] = $oIdentifier;
     }
     // We need to iterate identifiers in the order they appear in $aIdentifierNames due to dependencies
     foreach ($aIdentifierNames as $sIdentifierName => $aIdentifiers) {
         if (!is_array($aIdentifiers)) {
             continue;
         }
         foreach ($aIdentifiers as $oIdentifier) {
             $iFlags = $oIdentifier->iFlags;
             $mReplacement = $this->oSpecialTemplateIdentifierActions->{$sIdentifierName}($oIdentifier, $iFlags);
             if ($mReplacement !== null) {
                 $this->replaceAt($oIdentifier, $this->getTextForReplaceIdentifier($mReplacement, $iFlags));
             }
         }
     }
 }