@@ -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() { |
@@ -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; |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | |
| 54 | 54 | $cachedOutput = $this->loadTemplate(); |
| 55 | 55 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 56 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
| 56 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
| 57 | 57 | $valueParser = new Parser\Value($functionSet); |
| 58 | 58 | $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers); |
| 59 | 59 | |
@@ -28,7 +28,9 @@ discard block |
||
| 28 | 28 | $this->cache = new Cache(new \ArrayObject()); |
| 29 | 29 | $this->filePath = new FilePath(); |
| 30 | 30 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
| 31 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
| 31 | + foreach ($modules as $module) { |
|
| 32 | + $this->loadModule(new $module); |
|
| 33 | + } |
|
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -57,7 +59,9 @@ discard block |
||
| 57 | 59 | $valueParser = new Parser\Value($functionSet); |
| 58 | 60 | $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers); |
| 59 | 61 | |
| 60 | - foreach ($this->modules as $module) $module->load($this->config); |
|
| 62 | + foreach ($this->modules as $module) { |
|
| 63 | + $module->load($this->config); |
|
| 64 | + } |
|
| 61 | 65 | |
| 62 | 66 | $this->processRules($template, $this->config); |
| 63 | 67 | |
@@ -71,7 +75,9 @@ discard block |
||
| 71 | 75 | $rules = $this->getRules($template, $config); |
| 72 | 76 | |
| 73 | 77 | foreach ($rules as $rule) { |
| 74 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
| 78 | + if ($rule->shouldRun($this->time)) { |
|
| 79 | + $this->executeTssRule($rule, $template, $config); |
|
| 80 | + } |
|
| 75 | 81 | } |
| 76 | 82 | } |
| 77 | 83 | |
@@ -96,8 +102,9 @@ discard block |
||
| 96 | 102 | if (trim($this->template)[0] !== '<') { |
| 97 | 103 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 98 | 104 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 105 | + } else { |
|
| 106 | + return ['body' => $this->template, 'headers' => []]; |
|
| 99 | 107 | } |
| 100 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 101 | 108 | } |
| 102 | 109 | |
| 103 | 110 | //Load the TSS rules either from a file or as a string |
@@ -117,6 +124,8 @@ discard block |
||
| 117 | 124 | |
| 118 | 125 | public function __destruct() { |
| 119 | 126 | //Required hack as DomXPath can only register static functions clear, the statically stored instance to avoid memory leaks |
| 120 | - if (isset($this->config)) $this->config->getCssToXpath()->cleanup(); |
|
| 127 | + if (isset($this->config)) { |
|
| 128 | + $this->config->getCssToXpath()->cleanup(); |
|
| 129 | + } |
|
| 121 | 130 | } |
| 122 | 131 | } |
@@ -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 | } |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Transphporm; |
| 3 | 3 | class TSSCache { |
| 4 | - private $cache; |
|
| 5 | - private $prefix; |
|
| 4 | + private $cache; |
|
| 5 | + private $prefix; |
|
| 6 | 6 | |
| 7 | - public function __construct(Cache $cache, $prefix) { |
|
| 8 | - $this->cache = $cache; |
|
| 9 | - $this->prefix = $prefix; |
|
| 10 | - } |
|
| 7 | + public function __construct(Cache $cache, $prefix) { |
|
| 8 | + $this->cache = $cache; |
|
| 9 | + $this->prefix = $prefix; |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | 12 | private function getRulesFromCache($file) { |
| 13 | 13 | //The cache for the key: the filename and template prefix |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function load($tss) { |
|
| 32 | - return $this->getRulesFromCache($tss); |
|
| 33 | - } |
|
| 31 | + public function load($tss) { |
|
| 32 | + return $this->getRulesFromCache($tss); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function write($file, $rules, $imports = []) { |
|
| 36 | - if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 37 | - return $rules; |
|
| 38 | - } |
|
| 35 | + public function write($file, $rules, $imports = []) { |
|
| 36 | + if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 37 | + return $rules; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | private function getCacheKey($file) { |
| 28 | - return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR; |
|
| 28 | + return $file.$this->prefix.dirname(realpath($file)).DIRECTORY_SEPARATOR; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public function load($tss) { |
@@ -18,7 +18,9 @@ discard block |
||
| 18 | 18 | $rules = $this->cache->load($key, filemtime($file)); |
| 19 | 19 | if ($rules) { |
| 20 | 20 | foreach ($rules['import'] as $file) { |
| 21 | - if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false; |
|
| 21 | + if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 22 | 24 | } |
| 23 | 25 | } |
| 24 | 26 | return $rules; |
@@ -33,7 +35,9 @@ discard block |
||
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | public function write($file, $rules, $imports = []) { |
| 36 | - if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 38 | + if (is_file($file)) { |
|
| 39 | + $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 40 | + } |
|
| 37 | 41 | return $rules; |
| 38 | 42 | } |
| 39 | 43 | } |
@@ -12,13 +12,13 @@ |
||
| 12 | 12 | |
| 13 | 13 | if ($this->isJsonFile($json)) { |
| 14 | 14 | $path = $this->filePath->getFilePath($json); |
| 15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
| 15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path); |
|
| 16 | 16 | $json = file_get_contents($path); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | $map = json_decode($json, true); |
| 20 | 20 | |
| 21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
| 21 | + if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg()); |
|
| 22 | 22 | |
| 23 | 23 | return $map; |
| 24 | 24 | } |
@@ -1,29 +1,29 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Transphporm\TSSFunction; |
| 3 | 3 | class Json implements \Transphporm\TSSFunction { |
| 4 | - private $filePath; |
|
| 4 | + private $filePath; |
|
| 5 | 5 | |
| 6 | - public function __construct(\Transphporm\FilePath $filePath) { |
|
| 7 | - $this->filePath = $filePath; |
|
| 8 | - } |
|
| 6 | + public function __construct(\Transphporm\FilePath $filePath) { |
|
| 7 | + $this->filePath = $filePath; |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | - public function run(array $args, \DomElement $element = null) { |
|
| 11 | - $json = $args[0]; |
|
| 10 | + public function run(array $args, \DomElement $element = null) { |
|
| 11 | + $json = $args[0]; |
|
| 12 | 12 | |
| 13 | - if ($this->isJsonFile($json)) { |
|
| 14 | - $path = $this->filePath->getFilePath($json); |
|
| 15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
| 16 | - $json = file_get_contents($path); |
|
| 17 | - } |
|
| 13 | + if ($this->isJsonFile($json)) { |
|
| 14 | + $path = $this->filePath->getFilePath($json); |
|
| 15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
| 16 | + $json = file_get_contents($path); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - $map = json_decode($json, true); |
|
| 19 | + $map = json_decode($json, true); |
|
| 20 | 20 | |
| 21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
| 21 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
| 22 | 22 | |
| 23 | - return $map; |
|
| 24 | - } |
|
| 23 | + return $map; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - private function isJsonFile($json) { |
|
| 27 | - return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
| 28 | - } |
|
| 26 | + private function isJsonFile($json) { |
|
| 27 | + return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -12,13 +12,17 @@ |
||
| 12 | 12 | |
| 13 | 13 | if ($this->isJsonFile($json)) { |
| 14 | 14 | $path = $this->filePath->getFilePath($json); |
| 15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
| 15 | + if (!file_exists($path)) { |
|
| 16 | + throw new \Exception('File does not exist at: ' . $path); |
|
| 17 | + } |
|
| 16 | 18 | $json = file_get_contents($path); |
| 17 | 19 | } |
| 18 | 20 | |
| 19 | 21 | $map = json_decode($json, true); |
| 20 | 22 | |
| 21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
| 23 | + if (!is_array($map)) { |
|
| 24 | + throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
| 25 | + } |
|
| 22 | 26 | |
| 23 | 27 | return $map; |
| 24 | 28 | } |
@@ -31,10 +31,11 @@ |
||
| 31 | 31 | ]; |
| 32 | 32 | |
| 33 | 33 | if ($funcs[$this->mode] === 'concat' && is_numeric($newValue) |
| 34 | - && is_numeric($this->result[count($this->result)-1])) |
|
| 35 | - $this->add($newValue); |
|
| 36 | - else |
|
| 37 | - $this->{$funcs[$this->mode]}($newValue); |
|
| 34 | + && is_numeric($this->result[count($this->result)-1])) { |
|
| 35 | + $this->add($newValue); |
|
| 36 | + } else { |
|
| 37 | + $this->{$funcs[$this->mode]}($newValue); |
|
| 38 | + } |
|
| 38 | 39 | } |
| 39 | 40 | |
| 40 | 41 | public function arg($value) { |
@@ -91,6 +91,10 @@ |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | //Postprocessing - replace values with null where allowed, or override a value at position |
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param boolean $allowNull |
|
| 97 | + */ |
|
| 94 | 98 | public function postProcess(ValueData $data, $val, $overrideVal, $allowNull) { |
| 95 | 99 | foreach ($this->getResult() as $i => $value) { |
| 96 | 100 | if (is_scalar($value)) { |
@@ -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(['<template>' . $val . '</template>']); |
| 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(['<template>' . $val . '</template>']); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -8,12 +8,12 @@ |
||
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | public function html($val) { |
| 11 | - return $this->templateFunction->run(['<template>' . $val . '</template>']); |
|
| 11 | + return $this->templateFunction->run(['<template>'.$val.'</template>']); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 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 | } |