@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | /** Converts $val into a \DateTime object if it's not already */ |
| 12 | 12 | private function getDate($val) { |
| 13 | 13 | $tz = new \DateTimeZone($this->locale['timezone']); |
| 14 | - $date = $val instanceof \DateTime ? $val : new \DateTime($val, $tz); |
|
| 14 | + $date = $val instanceof \DateTime ? $val : new \DateTime($val, $tz); |
|
| 15 | 15 | $date->setTimeZone($tz); |
| 16 | 16 | return $date; |
| 17 | 17 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | /** Formats \DateTime as Date and Time using formats from $locale */ |
| 32 | 32 | public function dateTime($val) { |
| 33 | - return $this->date($val, $this->locale['date_format'] . ' ' . $this->locale['time_format']); |
|
| 33 | + return $this->date($val, $this->locale['date_format'].' '.$this->locale['time_format']); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** Generates relative time offsets based on system clock. e.g "10 minutes ago" or "In 6 months" |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $diff = $now->diff($date); |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
|
| 45 | + $diffDays = $diff->invert === 1 ? $diff->days : 0-$diff->days; |
|
| 46 | 46 | |
| 47 | 47 | if ($diffDays !== 0) return $this->dayOffset($diffDays); |
| 48 | 48 | else return $this->timeOffset($diff); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | /** Gets date ranges to represent uses of weeks/months/days/etc */ |
| 70 | 70 | private function getRanges($strings) { |
| 71 | - $ranges = [ |
|
| 71 | + $ranges = [ |
|
| 72 | 72 | [1, 1, $strings['yesterday'], 1, ''], |
| 73 | 73 | [1, 13, $strings['past'], 1, 'days'], |
| 74 | 74 | [13, 28, $strings['past'], 7, 'weeks'], |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
| 89 | 89 | private function getPlural($strings, $num, $interval) { |
| 90 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
| 90 | + if ($interval !== '') return $num == 1 ? $strings[$interval.'_singular'] : $strings[$interval.'_plural']; |
|
| 91 | 91 | else return ''; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -44,8 +44,11 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days; |
| 46 | 46 | |
| 47 | - if ($diffDays !== 0) return $this->dayOffset($diffDays); |
|
| 48 | - else return $this->timeOffset($diff); |
|
| 47 | + if ($diffDays !== 0) { |
|
| 48 | + return $this->dayOffset($diffDays); |
|
| 49 | + } else { |
|
| 50 | + return $this->timeOffset($diff); |
|
| 51 | + } |
|
| 49 | 52 | } |
| 50 | 53 | |
| 51 | 54 | /** Calculates offset in hours/minutes/seconds */ |
@@ -80,15 +83,22 @@ discard block |
||
| 80 | 83 | [-365, -28, $strings['future'], 28, 'months'], |
| 81 | 84 | [-999999, -365, $strings['future'], 365, 'years'], |
| 82 | 85 | ]; |
| 83 | - if (isset($strings['day_before_yesterday'])) array_unshift($ranges, [2, 2, $strings['day_before_yesterday'], 1, '']); |
|
| 84 | - if (isset($strings['day_after_tomorrow'])) array_unshift($ranges, [-2, -2, $strings['day_after_tomorrow'], 1, '']); |
|
| 86 | + if (isset($strings['day_before_yesterday'])) { |
|
| 87 | + array_unshift($ranges, [2, 2, $strings['day_before_yesterday'], 1, '']); |
|
| 88 | + } |
|
| 89 | + if (isset($strings['day_after_tomorrow'])) { |
|
| 90 | + array_unshift($ranges, [-2, -2, $strings['day_after_tomorrow'], 1, '']); |
|
| 91 | + } |
|
| 85 | 92 | return $ranges; |
| 86 | 93 | } |
| 87 | 94 | |
| 88 | 95 | /** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */ |
| 89 | 96 | private function getPlural($strings, $num, $interval) { |
| 90 | - if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
| 91 | - else return ''; |
|
| 97 | + if ($interval !== '') { |
|
| 98 | + return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural']; |
|
| 99 | + } else { |
|
| 100 | + return ''; |
|
| 101 | + } |
|
| 92 | 102 | } |
| 93 | 103 | |
| 94 | 104 | /** Calculates offset in days/weeks/month/years */ |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function currency($num) { |
| 15 | 15 | $num = $this->decimal($num, $this->locale['currency_decimals']); |
| 16 | - if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num; |
|
| 17 | - else return $num . $this->locale['currency']; |
|
| 16 | + if ($this->locale['currency_position'] === 'before') return $this->locale['currency'].$num; |
|
| 17 | + else return $num.$this->locale['currency']; |
|
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | \ No newline at end of file |
@@ -13,7 +13,10 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function currency($num) { |
| 15 | 15 | $num = $this->decimal($num, $this->locale['currency_decimals']); |
| 16 | - if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num; |
|
| 17 | - else return $num . $this->locale['currency']; |
|
| 16 | + if ($this->locale['currency_position'] === 'before') { |
|
| 17 | + return $this->locale['currency'] . $num; |
|
| 18 | + } else { |
|
| 19 | + return $num . $this->locale['currency']; |
|
| 20 | + } |
|
| 18 | 21 | } |
| 19 | 22 | } |
| 20 | 23 | \ No newline at end of file |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | if ($document) return $this->document; |
| 56 | 56 | |
| 57 | 57 | |
| 58 | - $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
|
| 58 | + $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype)."\n" : ''; |
|
| 59 | 59 | |
| 60 | 60 | if ($this->document->documentElement->tagName !== 'template') $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
| 61 | 61 | else $output = $this->printDocument($this->document); |
@@ -33,14 +33,18 @@ discard block |
||
| 33 | 33 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
| 34 | 34 | private function processHooks() { |
| 35 | 35 | foreach ($this->hooks as list($query, $hook)) { |
| 36 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
| 36 | + foreach ($this->xpath->query($query) as $element) { |
|
| 37 | + $hook->run($element); |
|
| 38 | + } |
|
| 37 | 39 | } |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | /** Prints out the current DomDocument as HTML */ |
| 41 | 43 | private function printDocument(\DomDocument $doc) { |
| 42 | 44 | $output = ''; |
| 43 | - foreach ($doc->documentElement->childNodes as $node) $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
| 45 | + foreach ($doc->documentElement->childNodes as $node) { |
|
| 46 | + $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
| 47 | + } |
|
| 44 | 48 | return $output; |
| 45 | 49 | } |
| 46 | 50 | |
@@ -52,13 +56,18 @@ discard block |
||
| 52 | 56 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
| 53 | 57 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
| 54 | 58 | //Either return a whole DomDocument or return the output HTML |
| 55 | - if ($document) return $this->document; |
|
| 59 | + if ($document) { |
|
| 60 | + return $this->document; |
|
| 61 | + } |
|
| 56 | 62 | |
| 57 | 63 | |
| 58 | 64 | $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
| 59 | 65 | |
| 60 | - if ($this->document->documentElement->tagName !== 'template') $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
| 61 | - else $output = $this->printDocument($this->document); |
|
| 66 | + if ($this->document->documentElement->tagName !== 'template') { |
|
| 67 | + $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
| 68 | + } else { |
|
| 69 | + $output = $this->printDocument($this->document); |
|
| 70 | + } |
|
| 62 | 71 | |
| 63 | 72 | //repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them |
| 64 | 73 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |
@@ -20,7 +20,8 @@ |
||
| 20 | 20 | public function load($key, $modified = 0) { |
| 21 | 21 | if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) { |
| 22 | 22 | return $this->cache[$key]['content']; |
| 23 | + } else { |
|
| 24 | + return false; |
|
| 23 | 25 | } |
| 24 | - else return false; |
|
| 25 | 26 | } |
| 26 | 27 | } |
| 27 | 28 | \ No newline at end of file |
@@ -39,9 +39,9 @@ |
||
| 39 | 39 | $num = (int) $frequency; |
| 40 | 40 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 41 | 41 | |
| 42 | - $offset = $num * constant(self::class . '::' . $unit); |
|
| 42 | + $offset = $num * constant(self::class.'::'.$unit); |
|
| 43 | 43 | |
| 44 | - if ($time > $this->lastRun + $offset) return true; |
|
| 44 | + if ($time > $this->lastRun+$offset) return true; |
|
| 45 | 45 | else return false; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | private $pseudo; |
| 11 | 11 | private $depth; |
| 12 | 12 | private $index; |
| 13 | - private $baseDir; |
|
| 13 | + private $baseDir; |
|
| 14 | 14 | private $properties = []; |
| 15 | 15 | private $lastRun = 0; |
| 16 | 16 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | $this->pseudo = $pseudo; |
| 26 | 26 | $this->depth = $depth; |
| 27 | 27 | $this->index = $index; |
| 28 | - $this->baseDir = $baseDir; |
|
| 28 | + $this->baseDir = $baseDir; |
|
| 29 | 29 | $this->properties = $properties; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -42,23 +42,32 @@ |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | private function timeFrequency($frequency, $time = null) { |
| 45 | - if ($time === null) $time = time(); |
|
| 45 | + if ($time === null) { |
|
| 46 | + $time = time(); |
|
| 47 | + } |
|
| 46 | 48 | $num = (int) $frequency; |
| 47 | 49 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 48 | 50 | |
| 49 | 51 | $offset = $num * constant(self::class . '::' . $unit); |
| 50 | 52 | |
| 51 | - if ($time > $this->lastRun + $offset) return true; |
|
| 52 | - else return false; |
|
| 53 | + if ($time > $this->lastRun + $offset) { |
|
| 54 | + return true; |
|
| 55 | + } else { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 53 | 58 | } |
| 54 | 59 | |
| 55 | 60 | public function shouldRun($time = null) { |
| 56 | 61 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
| 57 | 62 | $frequency = $this->properties['update-frequency']; |
| 58 | 63 | $static = ['always' => true, 'never' => false]; |
| 59 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
| 60 | - else return $this->timeFrequency($frequency, $time); |
|
| 64 | + if (isset($static[$frequency])) { |
|
| 65 | + return $static[$frequency]; |
|
| 66 | + } else { |
|
| 67 | + return $this->timeFrequency($frequency, $time); |
|
| 68 | + } |
|
| 69 | + } else { |
|
| 70 | + return true; |
|
| 61 | 71 | } |
| 62 | - else return true; |
|
| 63 | 72 | } |
| 64 | 73 | } |
@@ -9,9 +9,13 @@ |
||
| 9 | 9 | class PostProcess implements \Transphporm\Hook { |
| 10 | 10 | public function run(\DomElement $element) { |
| 11 | 11 | $transphporm = $element->getAttribute('transphporm'); |
| 12 | - if ($transphporm === 'remove') $element->parentNode->removeChild($element); |
|
| 13 | - else if ($transphporm === 'text') $element->parentNode->replaceChild($element->firstChild, $element); |
|
| 14 | - else $element->removeAttribute('transphporm'); |
|
| 12 | + if ($transphporm === 'remove') { |
|
| 13 | + $element->parentNode->removeChild($element); |
|
| 14 | + } else if ($transphporm === 'text') { |
|
| 15 | + $element->parentNode->replaceChild($element->firstChild, $element); |
|
| 16 | + } else { |
|
| 17 | + $element->removeAttribute('transphporm'); |
|
| 18 | + } |
|
| 15 | 19 | } |
| 16 | 20 | |
| 17 | 21 | } |
| 18 | 22 | \ No newline at end of file |
@@ -12,6 +12,9 @@ discard block |
||
| 12 | 12 | private $prefix; |
| 13 | 13 | private $valueParser; |
| 14 | 14 | |
| 15 | + /** |
|
| 16 | + * @param string $tss |
|
| 17 | + */ |
|
| 15 | 18 | public function __construct($tss, $baseDir, Value $valueParser, $prefix = '') { |
| 16 | 19 | $this->tss = $this->stripComments($tss, '/*', '*/'); |
| 17 | 20 | $this->tss = $this->stripComments($this->tss, '//', "\n"); |
@@ -38,6 +41,10 @@ discard block |
||
| 38 | 41 | return $rules; |
| 39 | 42 | } |
| 40 | 43 | |
| 44 | + /** |
|
| 45 | + * @param string $selector |
|
| 46 | + * @param integer $index |
|
| 47 | + */ |
|
| 41 | 48 | private function CssToRules($selector, $index, $properties) { |
| 42 | 49 | $parts = explode(',', $selector); |
| 43 | 50 | $rules = []; |
@@ -60,6 +67,11 @@ discard block |
||
| 60 | 67 | return $rules; |
| 61 | 68 | } |
| 62 | 69 | |
| 70 | + /** |
|
| 71 | + * @param integer $pos |
|
| 72 | + * @param integer $next |
|
| 73 | + * @param integer $indexStart |
|
| 74 | + */ |
|
| 63 | 75 | private function processingInstructions($tss, $pos, $next, $indexStart) { |
| 64 | 76 | $rules = []; |
| 65 | 77 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
@@ -90,6 +102,10 @@ discard block |
||
| 90 | 102 | return ($a->depth < $b->depth) ? -1 : 1; |
| 91 | 103 | } |
| 92 | 104 | |
| 105 | + /** |
|
| 106 | + * @param string $open |
|
| 107 | + * @param string $close |
|
| 108 | + */ |
|
| 93 | 109 | private function stripComments($str, $open, $close) { |
| 94 | 110 | $pos = 0; |
| 95 | 111 | while (($pos = strpos($str, $open, $pos)) !== false) { |
@@ -100,6 +116,9 @@ discard block |
||
| 100 | 116 | return $str; |
| 101 | 117 | } |
| 102 | 118 | |
| 119 | + /** |
|
| 120 | + * @param string $str |
|
| 121 | + */ |
|
| 103 | 122 | private function getProperties($str) { |
| 104 | 123 | $stringExtractor = new StringExtractor($str); |
| 105 | 124 | $rules = explode(';', $stringExtractor); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | $selector = trim(substr($this->tss, $pos, $next-$pos)); |
| 31 | - $pos = strpos($this->tss, '}', $next)+1; |
|
| 31 | + $pos = strpos($this->tss, '}', $next)+1; |
|
| 32 | 32 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties(trim(substr($this->tss, $next+1, $pos-2-$next)))); |
| 33 | 33 | $rules = $this->writeRule($rules, $newRules); |
| 34 | 34 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | private function processingInstructions($tss, $pos, $next, $indexStart) { |
| 63 | 63 | $rules = []; |
| 64 | 64 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
| 65 | - if ($atPos <= (int) $next) { |
|
| 65 | + if ($atPos <= (int) $next) { |
|
| 66 | 66 | $spacePos = strpos($tss, ' ', $atPos); |
| 67 | 67 | $funcName = substr($tss, $atPos+1, $spacePos-$atPos-1); |
| 68 | 68 | $pos = strpos($tss, ';', $spacePos); |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | private function import($args, $indexStart) { |
| 81 | - if (is_file(trim($args,'\'" '))) $fileName = trim($args,'\'" '); |
|
| 81 | + if (is_file(trim($args, '\'" '))) $fileName = trim($args, '\'" '); |
|
| 82 | 82 | else $fileName = $this->valueParser->parse($args)[0]; |
| 83 | - $sheet = new Sheet(file_get_contents($this->baseDir . $fileName), dirname(realpath($this->baseDir . $fileName)) . DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
| 83 | + $sheet = new Sheet(file_get_contents($this->baseDir.$fileName), dirname(realpath($this->baseDir.$fileName)).DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
| 84 | 84 | return $sheet->parse(0, [], $indexStart); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -33,9 +33,13 @@ discard block |
||
| 33 | 33 | $rules = $this->writeRule($rules, $newRules); |
| 34 | 34 | } |
| 35 | 35 | //there may be processing instructions at the end |
| 36 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) $rules = array_merge($rules, $processing['rules']); |
|
| 36 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) { |
|
| 37 | + $rules = array_merge($rules, $processing['rules']); |
|
| 38 | + } |
|
| 37 | 39 | usort($rules, [$this, 'sortRules']); |
| 38 | - if (empty($rules) && !empty($this->tss)) throw new \Exception("No TSS rules parsed"); |
|
| 40 | + if (empty($rules) && !empty($this->tss)) { |
|
| 41 | + throw new \Exception("No TSS rules parsed"); |
|
| 42 | + } |
|
| 39 | 43 | return $rules; |
| 40 | 44 | } |
| 41 | 45 | |
@@ -69,8 +73,7 @@ discard block |
||
| 69 | 73 | $pos = strpos($tss, ';', $spacePos); |
| 70 | 74 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
| 71 | 75 | $rules = array_merge($rules, $this->$funcName($args, $indexStart)); |
| 72 | - } |
|
| 73 | - else { |
|
| 76 | + } else { |
|
| 74 | 77 | break; |
| 75 | 78 | } |
| 76 | 79 | } |
@@ -79,15 +82,20 @@ discard block |
||
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | private function import($args, $indexStart) { |
| 82 | - if (is_file(trim($args,'\'" '))) $fileName = trim($args,'\'" '); |
|
| 83 | - else $fileName = $this->valueParser->parse($args)[0]; |
|
| 85 | + if (is_file(trim($args,'\'" '))) { |
|
| 86 | + $fileName = trim($args,'\'" '); |
|
| 87 | + } else { |
|
| 88 | + $fileName = $this->valueParser->parse($args)[0]; |
|
| 89 | + } |
|
| 84 | 90 | $sheet = new Sheet(file_get_contents($this->baseDir . $fileName), dirname(realpath($this->baseDir . $fileName)) . DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
| 85 | 91 | return $sheet->parse(0, [], $indexStart); |
| 86 | 92 | } |
| 87 | 93 | |
| 88 | 94 | private function sortRules($a, $b) { |
| 89 | 95 | //If they have the same depth, compare on index |
| 90 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
| 96 | + if ($a->depth === $b->depth) { |
|
| 97 | + return $a->index < $b->index ? -1 : 1; |
|
| 98 | + } |
|
| 91 | 99 | |
| 92 | 100 | return ($a->depth < $b->depth) ? -1 : 1; |
| 93 | 101 | } |
@@ -96,7 +104,9 @@ discard block |
||
| 96 | 104 | $pos = 0; |
| 97 | 105 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 98 | 106 | $end = strpos($str, $close, $pos); |
| 99 | - if ($end === false) break; |
|
| 107 | + if ($end === false) { |
|
| 108 | + break; |
|
| 109 | + } |
|
| 100 | 110 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
| 101 | 111 | } |
| 102 | 112 | |
@@ -110,13 +120,18 @@ discard block |
||
| 110 | 120 | $rules = []; |
| 111 | 121 | $i = 0; |
| 112 | 122 | foreach ($tokens as $token) { |
| 113 | - if ($token['type'] === Tokenizer::SEMI_COLON) $i++; |
|
| 114 | - else if ($token['type'] !== Tokenizer::WHITESPACE) $rules[$i][] = $token; |
|
| 123 | + if ($token['type'] === Tokenizer::SEMI_COLON) { |
|
| 124 | + $i++; |
|
| 125 | + } else if ($token['type'] !== Tokenizer::WHITESPACE) { |
|
| 126 | + $rules[$i][] = $token; |
|
| 127 | + } |
|
| 115 | 128 | } |
| 116 | 129 | |
| 117 | 130 | $return = []; |
| 118 | 131 | foreach ($rules as $rule) { |
| 119 | - if ($rule[1]['type'] === Tokenizer::COLON) $return[$rule[0]['value']] = array_slice($rule, 2); |
|
| 132 | + if ($rule[1]['type'] === Tokenizer::COLON) { |
|
| 133 | + $return[$rule[0]['value']] = array_slice($rule, 2); |
|
| 134 | + } |
|
| 120 | 135 | } |
| 121 | 136 | |
| 122 | 137 | return $return; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $cachedOutput = $this->loadTemplate(); |
| 51 | 51 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 52 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
| 52 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
| 53 | 53 | |
| 54 | 54 | $this->processRules($template, $data, $featureSet); |
| 55 | 55 | |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | //N.b. only files can be cached |
| 99 | 99 | private function getRules($template, $valueParser) { |
| 100 | 100 | if (is_file($this->tss)) { |
| 101 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
| 101 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
| 102 | 102 | //The cache for the key: the filename and template prefix |
| 103 | 103 | //Each template may have a different prefix which changes the parsed TSS, |
| 104 | 104 | //Because of this the cache needs to be generated for each template prefix. |
| 105 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
| 105 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
| 106 | 106 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
| 107 | 107 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 108 | 108 | if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | $this->cache = new Cache(new \ArrayObject()); |
| 27 | 27 | |
| 28 | 28 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
| 29 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
| 29 | + foreach ($modules as $module) { |
|
| 30 | + $this->loadModule(new $module); |
|
| 31 | + } |
|
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -51,7 +53,9 @@ discard block |
||
| 51 | 53 | $valueParser = new Parser\Value($data); |
| 52 | 54 | $config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($valueParser, $data, $template->getPrefix()), $headers, $this->baseDir); |
| 53 | 55 | |
| 54 | - foreach ($this->modules as $module) $module->load($config); |
|
| 56 | + foreach ($this->modules as $module) { |
|
| 57 | + $module->load($config); |
|
| 58 | + } |
|
| 55 | 59 | |
| 56 | 60 | $this->processRules($template, $config); |
| 57 | 61 | |
@@ -66,7 +70,9 @@ discard block |
||
| 66 | 70 | $rules = $this->getRules($template, $config); |
| 67 | 71 | |
| 68 | 72 | foreach ($rules as $rule) { |
| 69 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
| 73 | + if ($rule->shouldRun($this->time)) { |
|
| 74 | + $this->executeTssRule($rule, $template, $config); |
|
| 75 | + } |
|
| 70 | 76 | } |
| 71 | 77 | } |
| 72 | 78 | |
@@ -82,7 +88,9 @@ discard block |
||
| 82 | 88 | |
| 83 | 89 | // TODO: Once `Sheet` uses tokens this can be removed |
| 84 | 90 | $pseudo = []; |
| 85 | - foreach ($rule->pseudo as $pseudoString) $pseudo[] = (new \Transphporm\Parser\Tokenizer($pseudoString))->getTokens(); |
|
| 91 | + foreach ($rule->pseudo as $pseudoString) { |
|
| 92 | + $pseudo[] = (new \Transphporm\Parser\Tokenizer($pseudoString))->getTokens(); |
|
| 93 | + } |
|
| 86 | 94 | |
| 87 | 95 | $pseudoMatcher = $config->createPseudoMatcher($pseudo); |
| 88 | 96 | |
@@ -96,8 +104,9 @@ discard block |
||
| 96 | 104 | if (trim($this->template)[0] !== '<') { |
| 97 | 105 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 98 | 106 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 107 | + } else { |
|
| 108 | + return ['body' => $this->template, 'headers' => []]; |
|
| 99 | 109 | } |
| 100 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 101 | 110 | } |
| 102 | 111 | |
| 103 | 112 | //Load the TSS rules either from a file or as a string |
@@ -112,10 +121,14 @@ discard block |
||
| 112 | 121 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
| 113 | 122 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 114 | 123 | |
| 115 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse()); |
|
| 116 | - else return $rules; |
|
| 124 | + if (!$rules) { |
|
| 125 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse()); |
|
| 126 | + } else { |
|
| 127 | + return $rules; |
|
| 128 | + } |
|
| 129 | + } else { |
|
| 130 | + return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse(); |
|
| 117 | 131 | } |
| 118 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $config->getCssToXpath(), $config->getValueParser()))->parse(); |
|
| 119 | 132 | } |
| 120 | 133 | |
| 121 | 134 | public function setCache(\ArrayAccess $cache) { |
@@ -14,8 +14,8 @@ |
||
| 14 | 14 | |
| 15 | 15 | private function getLocale() { |
| 16 | 16 | if (is_array($this->locale)) return $this->locale; |
| 17 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 17 | + else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.$this->locale.'.json'), true); |
|
| 18 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function load(\Transphporm\FeatureSet $featureSet) { |
@@ -13,9 +13,13 @@ |
||
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | private function getLocale() { |
| 16 | - if (is_array($this->locale)) return $this->locale; |
|
| 17 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 16 | + if (is_array($this->locale)) { |
|
| 17 | + return $this->locale; |
|
| 18 | + } else if (strlen($this->locale) > 0) { |
|
| 19 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 20 | + } else { |
|
| 21 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 22 | + } |
|
| 19 | 23 | } |
| 20 | 24 | |
| 21 | 25 | public function load(\Transphporm\FeatureSet $featureSet) { |