@@ -13,15 +13,15 @@ |
||
| 13 | 13 | $data = $config->getFunctionSet(); |
| 14 | 14 | $headers = &$config->getHeaders(); |
| 15 | 15 | |
| 16 | - $content = new \Transphporm\Property\Content($config->getFormatter()); |
|
| 16 | + $content = new \Transphporm\Property\Content($config->getFormatter()); |
|
| 17 | 17 | $config->registerProperty('content', $content); |
| 18 | 18 | $config->registerProperty('repeat', new \Transphporm\Property\Repeat($data, $config->getElementData(), $config->getLine(), $config->getFilePath())); |
| 19 | 19 | $config->registerProperty('display', new \Transphporm\Property\Display); |
| 20 | 20 | $config->registerProperty('bind', new \Transphporm\Property\Bind($config->getElementData())); |
| 21 | 21 | |
| 22 | - $content->addContentPseudo("before", new \Transphporm\Property\ContentPseudo\BeforeAfter("before", $content)); |
|
| 23 | - $content->addContentPseudo("after", new \Transphporm\Property\ContentPseudo\BeforeAfter("after", $content)); |
|
| 24 | - $content->addContentPseudo("attr", new \Transphporm\Property\ContentPseudo\Attr()); |
|
| 25 | - $content->addContentPseudo("header", new \Transphporm\Property\ContentPseudo\Headers($headers)); |
|
| 22 | + $content->addContentPseudo("before", new \Transphporm\Property\ContentPseudo\BeforeAfter("before", $content)); |
|
| 23 | + $content->addContentPseudo("after", new \Transphporm\Property\ContentPseudo\BeforeAfter("after", $content)); |
|
| 24 | + $content->addContentPseudo("attr", new \Transphporm\Property\ContentPseudo\Attr()); |
|
| 25 | + $content->addContentPseudo("header", new \Transphporm\Property\ContentPseudo\Headers($headers)); |
|
| 26 | 26 | } |
| 27 | 27 | } |
@@ -68,7 +68,9 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
| 71 | - if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 71 | + if (isset($this->properties['content'])) { |
|
| 72 | + $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 73 | + } |
|
| 72 | 74 | } |
| 73 | 75 | |
| 74 | 76 | public function registerPseudo(Pseudo $pseudo) { |
@@ -76,12 +78,16 @@ discard block |
||
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | public function loadProperties(Hook\PropertyHook $hook) { |
| 79 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
| 81 | + foreach ($this->properties as $name => $property) { |
|
| 82 | + $hook->registerProperty($name, $property); |
|
| 83 | + } |
|
| 80 | 84 | } |
| 81 | 85 | |
| 82 | 86 | public function createPseudoMatcher($pseudo) { |
| 83 | 87 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser); |
| 84 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
| 88 | + foreach ($this->pseudo as $pseudoFunction) { |
|
| 89 | + $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
| 90 | + } |
|
| 85 | 91 | return $pseudoMatcher; |
| 86 | 92 | } |
| 87 | 93 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function &getLine() { |
| 43 | - $line = &$this->line; |
|
| 43 | + $line = &$this->line; |
|
| 44 | 44 | return $line; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | $this->properties[$name] = $property; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
|
| 72 | - if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 73 | - } |
|
| 71 | + public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
|
| 72 | + if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | public function registerPseudo(Pseudo $pseudo) { |
| 76 | 76 | $this->pseudo[] = $pseudo; |
@@ -2,48 +2,48 @@ |
||
| 2 | 2 | namespace Transphporm; |
| 3 | 3 | use Transphporm\Parser\Tokenizer; |
| 4 | 4 | class TSSValidator { |
| 5 | - private $error; |
|
| 5 | + private $error; |
|
| 6 | 6 | |
| 7 | - public function validate($tss) { |
|
| 8 | - $this->error = null; |
|
| 9 | - $tokens = $this->tokenize($tss); |
|
| 7 | + public function validate($tss) { |
|
| 8 | + $this->error = null; |
|
| 9 | + $tokens = $this->tokenize($tss); |
|
| 10 | 10 | |
| 11 | - foreach ($tokens as $token) |
|
| 12 | - if (!$this->validateRule($token)) return false; |
|
| 11 | + foreach ($tokens as $token) |
|
| 12 | + if (!$this->validateRule($token)) return false; |
|
| 13 | 13 | |
| 14 | - return true; |
|
| 15 | - } |
|
| 14 | + return true; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function getLastError() { |
|
| 18 | - return $this->error; |
|
| 19 | - } |
|
| 17 | + public function getLastError() { |
|
| 18 | + return $this->error; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - private function validateRule($token) { |
|
| 22 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
| 21 | + private function validateRule($token) { |
|
| 22 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
| 23 | 23 | |
| 24 | - return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
| 25 | - && $this->checkParenthesis($token); |
|
| 26 | - } |
|
| 24 | + return $this->checkBraces($token) && $this->checkSemicolons($token) |
|
| 25 | + && $this->checkParenthesis($token); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - private function checkBraces($token) { |
|
| 29 | - return strpos($token['string'], '{') === false; |
|
| 30 | - } |
|
| 28 | + private function checkBraces($token) { |
|
| 29 | + return strpos($token['string'], '{') === false; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - private function checkSemicolons($braceToken) { |
|
| 33 | - $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
| 34 | - array_shift($splitTokens); array_pop($splitTokens); |
|
| 35 | - foreach ($splitTokens as $tokens) |
|
| 36 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
| 32 | + private function checkSemicolons($braceToken) { |
|
| 33 | + $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
|
| 34 | + array_shift($splitTokens); array_pop($splitTokens); |
|
| 35 | + foreach ($splitTokens as $tokens) |
|
| 36 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
| 37 | 37 | |
| 38 | - return true; |
|
| 39 | - } |
|
| 38 | + return true; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - private function checkParenthesis($token) { |
|
| 42 | - return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
| 43 | - } |
|
| 41 | + private function checkParenthesis($token) { |
|
| 42 | + return substr_count($token['string'], '(') === substr_count($token['string'], ')'); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - private function tokenize($tss) { |
|
| 46 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
| 47 | - return (new Parser\SheetTokenizer($tss))->getTokens(); |
|
| 48 | - } |
|
| 45 | + private function tokenize($tss) { |
|
| 46 | + if (is_file($tss)) $tss = file_get_contents($tss); |
|
| 47 | + return (new Parser\SheetTokenizer($tss))->getTokens(); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -8,8 +8,9 @@ discard block |
||
| 8 | 8 | $this->error = null; |
| 9 | 9 | $tokens = $this->tokenize($tss); |
| 10 | 10 | |
| 11 | - foreach ($tokens as $token) |
|
| 12 | - if (!$this->validateRule($token)) return false; |
|
| 11 | + foreach ($tokens as $token) { |
|
| 12 | + if (!$this->validateRule($token)) return false; |
|
| 13 | + } |
|
| 13 | 14 | |
| 14 | 15 | return true; |
| 15 | 16 | } |
@@ -19,7 +20,9 @@ discard block |
||
| 19 | 20 | } |
| 20 | 21 | |
| 21 | 22 | private function validateRule($token) { |
| 22 | - if ($token['type'] !== Tokenizer::OPEN_BRACE) return true; |
|
| 23 | + if ($token['type'] !== Tokenizer::OPEN_BRACE) { |
|
| 24 | + return true; |
|
| 25 | + } |
|
| 23 | 26 | |
| 24 | 27 | return $this->checkBraces($token) && $this->checkSemicolons($token) |
| 25 | 28 | && $this->checkParenthesis($token); |
@@ -32,8 +35,9 @@ discard block |
||
| 32 | 35 | private function checkSemicolons($braceToken) { |
| 33 | 36 | $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON); |
| 34 | 37 | array_shift($splitTokens); array_pop($splitTokens); |
| 35 | - foreach ($splitTokens as $tokens) |
|
| 36 | - if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
| 38 | + foreach ($splitTokens as $tokens) { |
|
| 39 | + if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false; |
|
| 40 | + } |
|
| 37 | 41 | |
| 38 | 42 | return true; |
| 39 | 43 | } |
@@ -43,7 +47,9 @@ discard block |
||
| 43 | 47 | } |
| 44 | 48 | |
| 45 | 49 | private function tokenize($tss) { |
| 46 | - if (is_file($tss)) $tss = file_get_contents($tss); |
|
| 50 | + if (is_file($tss)) { |
|
| 51 | + $tss = file_get_contents($tss); |
|
| 52 | + } |
|
| 47 | 53 | return (new Parser\SheetTokenizer($tss))->getTokens(); |
| 48 | 54 | } |
| 49 | 55 | } |
@@ -1,19 +1,19 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Transphporm\Parser; |
| 3 | 3 | class SheetTokenizer { |
| 4 | - private $tokenizer; |
|
| 4 | + private $tokenizer; |
|
| 5 | 5 | |
| 6 | - public function __construct($tss) { |
|
| 7 | - $tss = $this->stripComments($tss, '//', "\n"); |
|
| 6 | + public function __construct($tss) { |
|
| 7 | + $tss = $this->stripComments($tss, '//', "\n"); |
|
| 8 | 8 | $tss = $this->stripComments($tss, '/*', '*/'); |
| 9 | 9 | $this->tokenizer = new Tokenizer($tss); |
| 10 | - } |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public function getTokens() { |
|
| 12 | + public function getTokens() { |
|
| 13 | 13 | return $this->tokenizer->getTokens(); |
| 14 | - } |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - private function stripComments($str, $open, $close) { |
|
| 16 | + private function stripComments($str, $open, $close) { |
|
| 17 | 17 | $pos = 0; |
| 18 | 18 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 19 | 19 | $end = strpos($str, $close, $pos); |
@@ -17,7 +17,9 @@ |
||
| 17 | 17 | $pos = 0; |
| 18 | 18 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 19 | 19 | $end = strpos($str, $close, $pos); |
| 20 | - if ($end === false) break; |
|
| 20 | + if ($end === false) { |
|
| 21 | + break; |
|
| 22 | + } |
|
| 21 | 23 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
| 22 | 24 | } |
| 23 | 25 | |