96 |
96 |
*/
|
97 |
97 |
public static $SPLIT_PATTERN_SHORTHANDSYNTAX = '/
|
98 |
98 |
(
|
99 |
|
{ # Start of shorthand syntax
|
|
99 |
SHORTHAND_OPEN # Start of shorthand syntax
|
100 |
100 |
(?: # Shorthand syntax is either composed of...
|
101 |
101 |
[a-zA-Z0-9\->_:,.()] # Various characters
|
102 |
102 |
|"(?:\\\"|[^"])*" # Double-quoted strings
|
... | ... | |
104 |
104 |
|(?R) # Other shorthand syntaxes inside, albeit not in a quoted string
|
105 |
105 |
|\s+ # Spaces
|
106 |
106 |
)+
|
107 |
|
} # End of shorthand syntax
|
|
107 |
SHORTHAND_CLOSE # End of shorthand syntax
|
108 |
108 |
)/x';
|
109 |
109 |
|
110 |
110 |
/**
|
... | ... | |
118 |
118 |
* @author Sebastian Kurfürst <sebastian@typo3.org>
|
119 |
119 |
*/
|
120 |
120 |
public static $SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS = '/
|
121 |
|
^{ # Start of shorthand syntax
|
|
121 |
^SHORTHAND_OPEN # Start of shorthand syntax
|
122 |
122 |
# A shorthand syntax is either...
|
123 |
123 |
(?P<Object>[a-zA-Z0-9\-_.]*) # ... an object accessor
|
124 |
124 |
\s*(?P<Delimiter>(?:->)?)\s*
|
... | ... | |
136 |
136 |
"(?:\\\"|[^"])*" # Double qouoted string
|
137 |
137 |
|\'(?:\\\\\'|[^\'])*\' # Single quoted string
|
138 |
138 |
|[a-zA-Z0-9\-_.]+ # variable identifiers
|
139 |
|
|{(?P>ViewHelperArguments)} # Another sub-array
|
|
139 |
|SHORTHAND_OPEN(?P>ViewHelperArguments)SHORTHAND_CLOSE # Another sub-array
|
140 |
140 |
) # END possible value options
|
141 |
141 |
\s*,? # There might be a , to seperate different parts of the array
|
142 |
142 |
)* # The above cycle is repeated for all array elements
|
... | ... | |
149 |
149 |
(?P>ViewHelper)
|
150 |
150 |
)*
|
151 |
151 |
)
|
152 |
|
}$/x';
|
|
152 |
SHORTHAND_CLOSE$/x';
|
153 |
153 |
|
154 |
154 |
/**
|
155 |
155 |
* THIS IS ALMOST THE SAME AS $SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS
|
... | ... | |
170 |
170 |
"(?:\\\"|[^"])*" # Double qouoted string
|
171 |
171 |
|\'(?:\\\\\'|[^\'])*\' # Single quoted string
|
172 |
172 |
|[a-zA-Z0-9\-_.]+ # variable identifiers
|
173 |
|
|{(?P>ViewHelperArguments)} # Another sub-array
|
|
173 |
|SHORTHAND_OPEN(?P>ViewHelperArguments)SHORTHAND_CLOSE # Another sub-array
|
174 |
174 |
) # END possible value options
|
175 |
175 |
\s*,? # There might be a , to seperate different parts of the array
|
176 |
176 |
)* # The above cycle is repeated for all array elements
|
... | ... | |
189 |
189 |
*/
|
190 |
190 |
public static $SCAN_PATTERN_SHORTHANDSYNTAX_ARRAYS = '/^
|
191 |
191 |
(?P<Recursion> # Start the recursive part of the regular expression - describing the array syntax
|
192 |
|
{ # Each array needs to start with {
|
|
192 |
SHORTHAND_OPEN # Each array needs to start with {
|
193 |
193 |
(?P<Array> # Start submatch
|
194 |
194 |
(?:
|
195 |
195 |
\s*[a-zA-Z0-9\-_]+ # The keys of the array
|
... | ... | |
203 |
203 |
\s*,? # There might be a , to seperate different parts of the array
|
204 |
204 |
)* # The above cycle is repeated for all array elements
|
205 |
205 |
) # End array submatch
|
206 |
|
} # Each array ends with }
|
|
206 |
SHORTHAND_CLOSE # Each array ends with }
|
207 |
207 |
)$/x';
|
208 |
208 |
|
209 |
209 |
/**
|
... | ... | |
223 |
223 |
)
|
224 |
224 |
|(?P<VariableIdentifier>[a-zA-Z][a-zA-Z0-9\-_.]*) # variable identifiers have to start with a letter
|
225 |
225 |
|(?P<Number>[0-9.]+) # Number
|
226 |
|
|{\s*(?P<Subarray>(?:(?P>ArrayPart)\s*,?\s*)+)\s*} # Another sub-array
|
|
226 |
|SHORTHAND_OPEN\s*(?P<Subarray>(?:(?P>ArrayPart)\s*,?\s*)+)\s*SHORTHAND_CLOSE # Another sub-array
|
227 |
227 |
) # END possible value options
|
228 |
228 |
) # End array part submatch
|
229 |
229 |
/x';
|
... | ... | |
564 |
564 |
|
565 |
565 |
// ViewHelpers
|
566 |
566 |
$matches = array();
|
567 |
|
if (strlen($viewHelperString) > 0 && preg_match_all(self::$SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER, $viewHelperString, $matches, PREG_SET_ORDER) > 0) {
|
|
567 |
if (strlen($viewHelperString) > 0 && preg_match_all($this->prepareTemplateRegularExpression(self::$SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER), $viewHelperString, $matches, PREG_SET_ORDER) > 0) {
|
568 |
568 |
// The last ViewHelper has to be added first for correct chaining.
|
569 |
569 |
foreach (array_reverse($matches) as $singleMatch) {
|
570 |
570 |
if (strlen($singleMatch['ViewHelperArguments']) > 0) {
|
... | ... | |
707 |
707 |
|
708 |
708 |
/**
|
709 |
709 |
* Takes a regular expression template and replaces "NAMESPACE" with the
|
710 |
|
* currently registered namespace identifiers. Returns a regular expression
|
711 |
|
* which is ready to use.
|
|
710 |
* currently registered namespace identifiers. It further replaces
|
|
711 |
* "SHORTHAND_OPEN" with the configured short hand opening symbol and
|
|
712 |
* "SHORTHAND_CLOSE" with the configured short hand closing symbol.Returns
|
|
713 |
* a regular expression which is ready to use.
|
712 |
714 |
*
|
713 |
715 |
* @param string $regularExpression Regular expression template
|
714 |
716 |
* @return string Regular expression ready to be used
|
715 |
717 |
* @author Sebastian Kurfürst <sebastian@typo3.org>
|
|
718 |
* @author Lienhart Woitok <lienhart.woitok@netlogix.de>
|
716 |
719 |
*/
|
717 |
720 |
protected function prepareTemplateRegularExpression($regularExpression) {
|
718 |
|
return str_replace('NAMESPACE', implode('|', array_keys($this->namespaces)), $regularExpression);
|
|
721 |
$preparedRegularExpression = str_replace('NAMESPACE', implode('|', array_keys($this->namespaces)), $regularExpression);
|
|
722 |
|
|
723 |
$shortHandOpenSymbol = '{';
|
|
724 |
$shortHandCloseSymbol = '}';
|
|
725 |
if ($this->configuration !== NULL) {
|
|
726 |
$shortHandOpenSymbol = $this->configuration->getShortHandOpenSymbol();
|
|
727 |
$shortHandCloseSymbol = $this->configuration->getShortHandCloseSymbol();
|
|
728 |
}
|
|
729 |
$preparedRegularExpression = str_replace('SHORTHAND_OPEN', $shortHandOpenSymbol, $preparedRegularExpression);
|
|
730 |
$preparedRegularExpression = str_replace('SHORTHAND_CLOSE', $shortHandCloseSymbol, $preparedRegularExpression);
|
|
731 |
|
|
732 |
return $preparedRegularExpression;
|
719 |
733 |
}
|
720 |
734 |
|
721 |
735 |
/**
|
... | ... | |
733 |
747 |
|
734 |
748 |
foreach ($sections as $section) {
|
735 |
749 |
$matchedVariables = array();
|
736 |
|
if (preg_match(self::$SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS, $section, $matchedVariables) > 0) {
|
|
750 |
if (preg_match($this->prepareTemplateRegularExpression(self::$SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS), $section, $matchedVariables) > 0) {
|
737 |
751 |
$this->objectAccessorHandler($state, $matchedVariables['Object'], $matchedVariables['Delimiter'], (isset($matchedVariables['ViewHelper'])?$matchedVariables['ViewHelper']:''), (isset($matchedVariables['AdditionalViewHelpers'])?$matchedVariables['AdditionalViewHelpers']:''));
|
738 |
|
} elseif (preg_match(self::$SCAN_PATTERN_SHORTHANDSYNTAX_ARRAYS, $section, $matchedVariables) > 0) {
|
|
752 |
} elseif (preg_match($this->prepareTemplateRegularExpression(self::$SCAN_PATTERN_SHORTHANDSYNTAX_ARRAYS), $section, $matchedVariables) > 0) {
|
739 |
753 |
$this->arrayHandler($state, $matchedVariables['Array']);
|
740 |
754 |
} else {
|
741 |
755 |
$this->textHandler($state, $section);
|
... | ... | |
774 |
788 |
*/
|
775 |
789 |
protected function recursiveArrayHandler($arrayText) {
|
776 |
790 |
$matches = array();
|
777 |
|
if (preg_match_all(self::$SPLIT_PATTERN_SHORTHANDSYNTAX_ARRAY_PARTS, $arrayText, $matches, PREG_SET_ORDER) > 0) {
|
|
791 |
if (preg_match_all($this->prepareTemplateRegularExpression(self::$SPLIT_PATTERN_SHORTHANDSYNTAX_ARRAY_PARTS), $arrayText, $matches, PREG_SET_ORDER) > 0) {
|
778 |
792 |
$arrayToBuild = array();
|
779 |
793 |
foreach ($matches as $singleMatch) {
|
780 |
794 |
$arrayKey = $singleMatch['Key'];
|