@@ -6,29 +6,29 @@ |
||
6 | 6 | * @version 1.2 */ |
7 | 7 | namespace Transphporm\TSSFunction; |
8 | 8 | class Json implements \Transphporm\TSSFunction { |
9 | - private $filePath; |
|
9 | + private $filePath; |
|
10 | 10 | |
11 | - public function __construct(\Transphporm\FilePath $filePath) { |
|
12 | - $this->filePath = $filePath; |
|
13 | - } |
|
11 | + public function __construct(\Transphporm\FilePath $filePath) { |
|
12 | + $this->filePath = $filePath; |
|
13 | + } |
|
14 | 14 | |
15 | - public function run(array $args, \DomElement $element = null) { |
|
16 | - $json = $args[0]; |
|
15 | + public function run(array $args, \DomElement $element = null) { |
|
16 | + $json = $args[0]; |
|
17 | 17 | |
18 | - if ($this->isJsonFile($json)) { |
|
19 | - $path = $this->filePath->getFilePath($json); |
|
20 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
21 | - $json = file_get_contents($path); |
|
22 | - } |
|
18 | + if ($this->isJsonFile($json)) { |
|
19 | + $path = $this->filePath->getFilePath($json); |
|
20 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
21 | + $json = file_get_contents($path); |
|
22 | + } |
|
23 | 23 | |
24 | - $map = json_decode($json, true); |
|
24 | + $map = json_decode($json, true); |
|
25 | 25 | |
26 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
26 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
27 | 27 | |
28 | - return $map; |
|
29 | - } |
|
28 | + return $map; |
|
29 | + } |
|
30 | 30 | |
31 | - private function isJsonFile($json) { |
|
32 | - return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
33 | - } |
|
31 | + private function isJsonFile($json) { |
|
32 | + return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
33 | + } |
|
34 | 34 | } |
@@ -6,13 +6,13 @@ discard block |
||
6 | 6 | * @version 1.2 */ |
7 | 7 | namespace Transphporm; |
8 | 8 | class TSSCache { |
9 | - private $cache; |
|
10 | - private $prefix; |
|
9 | + private $cache; |
|
10 | + private $prefix; |
|
11 | 11 | |
12 | - public function __construct(Cache $cache, $prefix) { |
|
13 | - $this->cache = $cache; |
|
14 | - $this->prefix = $prefix; |
|
15 | - } |
|
12 | + public function __construct(Cache $cache, $prefix) { |
|
13 | + $this->cache = $cache; |
|
14 | + $this->prefix = $prefix; |
|
15 | + } |
|
16 | 16 | |
17 | 17 | private function getRulesFromCache($file) { |
18 | 18 | //The cache for the key: the filename and template prefix |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR; |
34 | 34 | } |
35 | 35 | |
36 | - public function load($tss) { |
|
37 | - return $this->getRulesFromCache($tss); |
|
38 | - } |
|
36 | + public function load($tss) { |
|
37 | + return $this->getRulesFromCache($tss); |
|
38 | + } |
|
39 | 39 | |
40 | - public function write($file, $rules, $imports = []) { |
|
41 | - if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
42 | - return $rules; |
|
43 | - } |
|
40 | + public function write($file, $rules, $imports = []) { |
|
41 | + if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
42 | + return $rules; |
|
43 | + } |
|
44 | 44 | } |
@@ -6,14 +6,14 @@ |
||
6 | 6 | * @version 1.2 */ |
7 | 7 | namespace Transphporm; |
8 | 8 | class Exception extends \Exception { |
9 | - const PROPERTY = 'property'; |
|
10 | - const TSS_FUNCTION = 'function'; |
|
11 | - const PSEUDO = 'pseudo'; |
|
12 | - const FORMATTER = 'formatter'; |
|
9 | + const PROPERTY = 'property'; |
|
10 | + const TSS_FUNCTION = 'function'; |
|
11 | + const PSEUDO = 'pseudo'; |
|
12 | + const FORMATTER = 'formatter'; |
|
13 | 13 | |
14 | - public function __construct(RunException $runException, $file, $line) { |
|
15 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
14 | + public function __construct(RunException $runException, $file, $line) { |
|
15 | + $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
16 | 16 | |
17 | - parent::__construct($message, 0, $runException->getPrevious()); |
|
18 | - } |
|
17 | + parent::__construct($message, 0, $runException->getPrevious()); |
|
18 | + } |
|
19 | 19 | } |
@@ -7,48 +7,48 @@ |
||
7 | 7 | namespace Transphporm; |
8 | 8 | use Transphporm\Parser\Tokenizer; |
9 | 9 | class TSSValidator { |
10 | - private $error; |
|
10 | + private $error; |
|
11 | 11 | |
12 | - public function validate($tss) { |
|
13 | - $this->error = null; |
|
14 | - $tokens = $this->tokenize($tss); |
|
12 | + public function validate($tss) { |
|
13 | + $this->error = null; |
|
14 | + $tokens = $this->tokenize($tss); |
|
15 | 15 | |
16 | - foreach ($tokens as $token) |
|
17 | - if (!$this->validateRule($token)) return false; |
|
16 | + foreach ($tokens as $token) |
|
17 | + if (!$this->validateRule($token)) return false; |
|
18 | 18 | |
19 | - return true; |
|
20 | - } |
|
19 | + return true; |
|
20 | + } |
|
21 | 21 | |
22 | - public function getLastError() { |
|
23 | - return $this->error; |
|
24 | - } |
|
22 | + public function getLastError() { |
|
23 | + return $this->error; |
|
24 | + } |
|
25 | 25 | |
26 | - private function validateRule($token) { |
|
27 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
26 | + private function validateRule($token) { |
|
27 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
28 | 28 | |
29 | - return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
30 | - && $this->checkParenthesis($token); |
|
31 | - } |
|
29 | + return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
30 | + && $this->checkParenthesis($token); |
|
31 | + } |
|
32 | 32 | |
33 | - private function checkBraces($token) { |
|
34 | - return strpos($token['string'], '{') === false; |
|
35 | - } |
|
33 | + private function checkBraces($token) { |
|
34 | + return strpos($token['string'], '{') === false; |
|
35 | + } |
|
36 | 36 | |
37 | - private function checkSemicolons($braceToken) { |
|
38 | - $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
39 | - array_shift($splitTokens); array_pop($splitTokens); |
|
40 | - foreach ($splitTokens as $tokens) |
|
41 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
37 | + private function checkSemicolons($braceToken) { |
|
38 | + $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
39 | + array_shift($splitTokens); array_pop($splitTokens); |
|
40 | + foreach ($splitTokens as $tokens) |
|
41 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
42 | 42 | |
43 | - return true; |
|
44 | - } |
|
43 | + return true; |
|
44 | + } |
|
45 | 45 | |
46 | - private function checkParenthesis($token) { |
|
47 | - return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
48 | - } |
|
46 | + private function checkParenthesis($token) { |
|
47 | + return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
48 | + } |
|
49 | 49 | |
50 | - private function tokenize($tss) { |
|
51 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
52 | - return (new Parser\Tokenizer($tss))->getTokens(); |
|
53 | - } |
|
50 | + private function tokenize($tss) { |
|
51 | + if (is_file($tss)) $tss = file_get_contents($tss); |
|
52 | + return (new Parser\Tokenizer($tss))->getTokens(); |
|
53 | + } |
|
54 | 54 | } |
@@ -6,39 +6,39 @@ |
||
6 | 6 | * @version 1.2 */ |
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 | } |
@@ -6,9 +6,9 @@ |
||
6 | 6 | * @version 1.2 */ |
7 | 7 | namespace Transphporm; |
8 | 8 | class RunException extends \Exception { |
9 | - public function __construct($operationType, $operationName, \Exception $previous) { |
|
10 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
9 | + public function __construct($operationType, $operationName, \Exception $previous) { |
|
10 | + $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
11 | 11 | |
12 | - parent::__construct($message, 0, $previous); |
|
13 | - } |
|
12 | + parent::__construct($message, 0, $previous); |
|
13 | + } |
|
14 | 14 | } |
@@ -6,13 +6,13 @@ |
||
6 | 6 | * @version 1.2 */ |
7 | 7 | namespace Transphporm\Formatter; |
8 | 8 | class HTMLFormatter { |
9 | - private $templateFunction; |
|
9 | + private $templateFunction; |
|
10 | 10 | |
11 | - public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
12 | - $this->templateFunction = $templateFunction; |
|
13 | - } |
|
11 | + public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
12 | + $this->templateFunction = $templateFunction; |
|
13 | + } |
|
14 | 14 | |
15 | - public function html($val) { |
|
15 | + public function html($val) { |
|
16 | 16 | return $this->templateFunction->run(['<template>' . $val . '</template>']); |
17 | 17 | } |
18 | 18 |
@@ -7,5 +7,5 @@ |
||
7 | 7 | namespace Transphporm\Property; |
8 | 8 | |
9 | 9 | interface ContentPseudo { |
10 | - public function run($value, $pseudoArgs, $element, \Transphporm\Hook\PseudoMatcher $pseudoMatcher); |
|
10 | + public function run($value, $pseudoArgs, $element, \Transphporm\Hook\PseudoMatcher $pseudoMatcher); |
|
11 | 11 | } |