@@ -67,12 +67,16 @@ |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function loadProperties(Hook\PropertyHook $hook) { |
| 70 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
| 70 | + foreach ($this->properties as $name => $property) { |
|
| 71 | + $hook->registerProperty($name, $property); |
|
| 72 | + } |
|
| 71 | 73 | } |
| 72 | 74 | |
| 73 | 75 | public function createPseudoMatcher($pseudo) { |
| 74 | 76 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser); |
| 75 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
| 77 | + foreach ($this->pseudo as $pseudoFunction) { |
|
| 78 | + $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
| 79 | + } |
|
| 76 | 80 | return $pseudoMatcher; |
| 77 | 81 | } |
| 78 | 82 | |
@@ -6,39 +6,39 @@ |
||
| 6 | 6 | * @version 1.0 */ |
| 7 | 7 | namespace Transphporm\Parser; |
| 8 | 8 | class TokenFilterIterator implements \Iterator { |
| 9 | - private $ignore; |
|
| 10 | - private $tokens; |
|
| 9 | + private $ignore; |
|
| 10 | + private $tokens; |
|
| 11 | 11 | |
| 12 | - public function __construct(Tokens $tokens, array $ignore) { |
|
| 13 | - $this->ignore = $ignore; |
|
| 14 | - $this->tokens = $tokens; |
|
| 15 | - } |
|
| 12 | + public function __construct(Tokens $tokens, array $ignore) { |
|
| 13 | + $this->ignore = $ignore; |
|
| 14 | + $this->tokens = $tokens; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function current() { |
|
| 18 | - return $this->tokens->current(); |
|
| 19 | - } |
|
| 17 | + public function current() { |
|
| 18 | + return $this->tokens->current(); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function key() { |
|
| 22 | - return $this->tokens->key(); |
|
| 23 | - } |
|
| 21 | + public function key() { |
|
| 22 | + return $this->tokens->key(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function valid() { |
|
| 26 | - return $this->tokens->valid(); |
|
| 27 | - } |
|
| 25 | + public function valid() { |
|
| 26 | + return $this->tokens->valid(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function next() { |
|
| 30 | - do { |
|
| 31 | - $this->tokens->next(); |
|
| 32 | - } |
|
| 33 | - while ($this->shouldContinue()); |
|
| 34 | - } |
|
| 29 | + public function next() { |
|
| 30 | + do { |
|
| 31 | + $this->tokens->next(); |
|
| 32 | + } |
|
| 33 | + while ($this->shouldContinue()); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function rewind() { |
|
| 37 | - $this->tokens->rewind(); |
|
| 38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
| 39 | - } |
|
| 36 | + public function rewind() { |
|
| 37 | + $this->tokens->rewind(); |
|
| 38 | + while ($this->shouldContinue()) $this->tokens->next(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - private function shouldContinue() { |
|
| 42 | - return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
| 43 | - } |
|
| 41 | + private function shouldContinue() { |
|
| 42 | + return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -35,7 +35,9 @@ |
||
| 35 | 35 | |
| 36 | 36 | public function rewind() { |
| 37 | 37 | $this->tokens->rewind(); |
| 38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
| 38 | + while ($this->shouldContinue()) { |
|
| 39 | + $this->tokens->next(); |
|
| 40 | + } |
|
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | private function shouldContinue() { |
@@ -7,6 +7,9 @@ |
||
| 7 | 7 | $this->templateFunction = $templateFunction; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | + /** |
|
| 11 | + * @param string $val |
|
| 12 | + */ |
|
| 10 | 13 | public function html($val) { |
| 11 | 14 | return $this->templateFunction->run([$val]); |
| 12 | 15 | } |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Transphporm\Formatter; |
| 3 | 3 | class HTMLFormatter { |
| 4 | - private $templateFunction; |
|
| 4 | + private $templateFunction; |
|
| 5 | 5 | |
| 6 | - public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
| 7 | - $this->templateFunction = $templateFunction; |
|
| 8 | - } |
|
| 6 | + public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
| 7 | + $this->templateFunction = $templateFunction; |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | - public function html($val) { |
|
| 10 | + public function html($val) { |
|
| 11 | 11 | return $this->templateFunction->run([$val]); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | public function debug($val) { |
| 15 | 15 | ob_start(); |
| 16 | 16 | var_dump($val); |
| 17 | - return $this->html('<pre>' . ob_get_clean() . '</pre>'); |
|
| 17 | + return $this->html('<pre>'.ob_get_clean().'</pre>'); |
|
| 18 | 18 | } |
| 19 | 19 | } |
@@ -26,9 +26,9 @@ |
||
| 26 | 26 | $tss = $this->readArray($args, 2); |
| 27 | 27 | |
| 28 | 28 | if (trim($args[0])[0] === '<') $xml = $args[0]; |
| 29 | - else $xml = $this->baseDir . $args[0]; |
|
| 29 | + else $xml = $this->baseDir.$args[0]; |
|
| 30 | 30 | |
| 31 | - $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->baseDir . $tss : null); |
|
| 31 | + $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->baseDir.$tss : null); |
|
| 32 | 32 | |
| 33 | 33 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
| 34 | 34 | if ($selector != '') return $this->templateSubsection($doc, $selector); |
@@ -25,13 +25,18 @@ discard block |
||
| 25 | 25 | $selector = $this->readArray($args, 1); |
| 26 | 26 | $tss = $this->readArray($args, 2); |
| 27 | 27 | |
| 28 | - if (trim($args[0])[0] === '<') $xml = $args[0]; |
|
| 29 | - else $xml = $this->baseDir . $args[0]; |
|
| 28 | + if (trim($args[0])[0] === '<') { |
|
| 29 | + $xml = $args[0]; |
|
| 30 | + } else { |
|
| 31 | + $xml = $this->baseDir . $args[0]; |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->baseDir . $tss : null); |
| 32 | 35 | |
| 33 | 36 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
| 34 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
| 37 | + if ($selector != '') { |
|
| 38 | + return $this->templateSubsection($doc, $selector); |
|
| 39 | + } |
|
| 35 | 40 | |
| 36 | 41 | return $this->getTemplateContent($doc, $tss); |
| 37 | 42 | |
@@ -62,7 +67,9 @@ discard block |
||
| 62 | 67 | |
| 63 | 68 | private function getClonedElement($node, $tss) { |
| 64 | 69 | $clone = $node->cloneNode(true); |
| 65 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 70 | + if ($tss != null && $clone instanceof \DomElement) { |
|
| 71 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 72 | + } |
|
| 66 | 73 | return $clone; |
| 67 | 74 | } |
| 68 | 75 | } |
@@ -62,6 +62,10 @@ discard block |
||
| 62 | 62 | return (object) $result; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + /** |
|
| 66 | + * @param Template $template |
|
| 67 | + * @param Config $config |
|
| 68 | + */ |
|
| 65 | 69 | private function processRules($template, $config) { |
| 66 | 70 | $rules = $this->getRules($template, $config); |
| 67 | 71 | |
@@ -71,6 +75,10 @@ discard block |
||
| 71 | 75 | } |
| 72 | 76 | |
| 73 | 77 | //Add a postprocessing hook. This cleans up anything transphporm has added to the markup which needs to be removed |
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param Template $template |
|
| 81 | + */ |
|
| 74 | 82 | private function doPostProcessing($template) { |
| 75 | 83 | $template->addHook('//*[@transphporm]', new Hook\PostProcess()); |
| 76 | 84 | return $template; |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | |
| 48 | 48 | $cachedOutput = $this->loadTemplate(); |
| 49 | 49 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 50 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
| 50 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
| 51 | 51 | $valueParser = new Parser\Value($data); |
| 52 | 52 | $config = new Config($data, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($data, $template->getPrefix()), $headers, $this->baseDir); |
| 53 | 53 | |
@@ -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($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 | |
@@ -91,8 +97,9 @@ discard block |
||
| 91 | 97 | if (trim($this->template)[0] !== '<') { |
| 92 | 98 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 93 | 99 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 100 | + } else { |
|
| 101 | + return ['body' => $this->template, 'headers' => []]; |
|
| 94 | 102 | } |
| 95 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 96 | 103 | } |
| 97 | 104 | |
| 98 | 105 | //Load the TSS rules either from a file or as a string |
@@ -21,15 +21,13 @@ |
||
| 21 | 21 | $tokens = $args[0]; |
| 22 | 22 | $parser = new \Transphporm\Parser\Value($this); |
| 23 | 23 | $args[0] = $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
| 24 | - } |
|
| 25 | - else if ($args[0] instanceof Parser\Tokens) { |
|
| 24 | + } else if ($args[0] instanceof Parser\Tokens) { |
|
| 26 | 25 | $args[0] = iterator_to_array($args[0]); |
| 27 | 26 | } |
| 28 | 27 | if (isset($this->functions[$name])) { |
| 29 | 28 | return $this->functions[$name]->run($args[0], $this->element); |
| 30 | 29 | } |
| 31 | - } |
|
| 32 | - catch (\Exception $e) { |
|
| 30 | + } catch (\Exception $e) { |
|
| 33 | 31 | throw new RunException(Exception::TSS_FUNCTION, $name, $e); |
| 34 | 32 | } |
| 35 | 33 | return true; |
@@ -1,9 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Transphporm; |
| 3 | 3 | class RunException extends \Exception { |
| 4 | - public function __construct($operationType, $operationName, \Exception $previous) { |
|
| 5 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
| 4 | + public function __construct($operationType, $operationName, \Exception $previous) { |
|
| 5 | + $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
| 6 | 6 | |
| 7 | - parent::__construct($message, 0, $previous); |
|
| 8 | - } |
|
| 7 | + parent::__construct($message, 0, $previous); |
|
| 8 | + } |
|
| 9 | 9 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | namespace Transphporm; |
| 3 | 3 | class RunException extends \Exception { |
| 4 | 4 | public function __construct($operationType, $operationName, \Exception $previous) { |
| 5 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
| 5 | + $message = 'TSS Error: Problem carrying out '.$operationType.' \''.$operationName.'\''; |
|
| 6 | 6 | |
| 7 | 7 | parent::__construct($message, 0, $previous); |
| 8 | 8 | } |
@@ -1,14 +1,14 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Transphporm; |
| 3 | 3 | class Exception extends \Exception { |
| 4 | - const PROPERTY = 'property'; |
|
| 5 | - const TSS_FUNCTION = 'function'; |
|
| 6 | - const PSEUDO = 'pseudo'; |
|
| 7 | - const FORMATTER = 'formatter'; |
|
| 4 | + const PROPERTY = 'property'; |
|
| 5 | + const TSS_FUNCTION = 'function'; |
|
| 6 | + const PSEUDO = 'pseudo'; |
|
| 7 | + const FORMATTER = 'formatter'; |
|
| 8 | 8 | |
| 9 | - public function __construct(RunException $runException, $file, $line) { |
|
| 10 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 9 | + public function __construct(RunException $runException, $file, $line) { |
|
| 10 | + $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 11 | 11 | |
| 12 | - parent::__construct($message, 0, $runException->getPrevious()); |
|
| 13 | - } |
|
| 12 | + parent::__construct($message, 0, $runException->getPrevious()); |
|
| 13 | + } |
|
| 14 | 14 | } |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | const FORMATTER = 'formatter'; |
| 8 | 8 | |
| 9 | 9 | public function __construct(RunException $runException, $file, $line) { |
| 10 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 10 | + $message = $runException->getMessage().' on Line '.$line.' of '.($file === null ? 'tss' : $file); |
|
| 11 | 11 | |
| 12 | 12 | parent::__construct($message, 0, $runException->getPrevious()); |
| 13 | 13 | } |
@@ -28,8 +28,7 @@ discard block |
||
| 28 | 28 | try { |
| 29 | 29 | $parts = $this->getFuncParts($tokens); |
| 30 | 30 | $matches = $matches && $function->match($parts['name'], $parts['args'], $element); |
| 31 | - } |
|
| 32 | - catch (\Exception $e) { |
|
| 31 | + } catch (\Exception $e) { |
|
| 33 | 32 | throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e); |
| 34 | 33 | } |
| 35 | 34 | } |
@@ -42,31 +41,37 @@ discard block |
||
| 42 | 41 | $parts['name'] = $this->getFuncName($tokens); |
| 43 | 42 | if ($parts['name'] === null || in_array($parts['name'], ['data', 'iteration', 'root'])) { |
| 44 | 43 | $parts['args'] = $this->valueParser->parseTokens($tokens); |
| 45 | - } |
|
| 46 | - else if (count($tokens) > 1) { |
|
| 44 | + } else if (count($tokens) > 1) { |
|
| 47 | 45 | $tokens->rewind(); |
| 48 | 46 | $tokens->next(); |
| 49 | 47 | $parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']); |
| 48 | + } else { |
|
| 49 | + $parts['args'] = [['']]; |
|
| 50 | 50 | } |
| 51 | - else $parts['args'] = [['']]; |
|
| 52 | 51 | return $parts; |
| 53 | 52 | } |
| 54 | 53 | |
| 55 | 54 | private function getFuncName($tokens) { |
| 56 | - if ($tokens->type() === Tokenizer::NAME) return $tokens->read(); |
|
| 55 | + if ($tokens->type() === Tokenizer::NAME) { |
|
| 56 | + return $tokens->read(); |
|
| 57 | + } |
|
| 57 | 58 | return null; |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | public function hasFunction($name) { |
| 61 | 62 | foreach ($this->pseudo as $tokens) { |
| 62 | - if ($name === $this->getFuncName($tokens)) return true; |
|
| 63 | + if ($name === $this->getFuncName($tokens)) { |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 63 | 66 | } |
| 64 | 67 | } |
| 65 | 68 | |
| 66 | 69 | public function getFuncArgs($name) { |
| 67 | 70 | foreach ($this->pseudo as $tokens) { |
| 68 | 71 | $parts = $this->getFuncParts($tokens); |
| 69 | - if ($name === $parts['name']) return $parts['args']; |
|
| 72 | + if ($name === $parts['name']) { |
|
| 73 | + return $parts['args']; |
|
| 74 | + } |
|
| 70 | 75 | } |
| 71 | 76 | } |
| 72 | 77 | } |