@@ -2,16 +2,16 @@ |
||
2 | 2 | namespace Transphporm; |
3 | 3 | |
4 | 4 | class FilePath { |
5 | - private $baseDir; |
|
6 | - private $customBase; |
|
5 | + private $baseDir; |
|
6 | + private $customBase; |
|
7 | 7 | |
8 | - public function __construct(&$baseDir, $customBase = null) { |
|
9 | - $this->baseDir = &$baseDir; |
|
10 | - if ($customBase === null) $this->customBase = getcwd(); |
|
11 | - else $this->customBase = rtrim($customBase, '/'); |
|
12 | - } |
|
8 | + public function __construct(&$baseDir, $customBase = null) { |
|
9 | + $this->baseDir = &$baseDir; |
|
10 | + if ($customBase === null) $this->customBase = getcwd(); |
|
11 | + else $this->customBase = rtrim($customBase, '/'); |
|
12 | + } |
|
13 | 13 | |
14 | - public function getFilePath($filePath = "") { |
|
14 | + public function getFilePath($filePath = "") { |
|
15 | 15 | if (isset($filePath[0]) && $filePath[0] == "/") return $this->customBase . $filePath; |
16 | 16 | else return $this->baseDir . $filePath; |
17 | 17 | } |
@@ -3,40 +3,40 @@ |
||
3 | 3 | namespace Transphporm\TSSFunction; |
4 | 4 | |
5 | 5 | class Math implements \Transphporm\TSSFunction { |
6 | - private $mode; |
|
7 | - |
|
8 | - const ADD = 'add'; |
|
9 | - const SUBTRACT = 'sub'; |
|
10 | - const MULTIPLY = 'mult'; |
|
11 | - const DIVIDE = 'div'; |
|
12 | - |
|
13 | - public function __construct($mode) { |
|
14 | - $this->mode = $mode; |
|
15 | - } |
|
16 | - |
|
17 | - public function run(array $args, \DomElement $element) { |
|
18 | - $result = $args[0]; |
|
19 | - for ($i = 1; $i < count($args); $i++) $result = $this->getModeResult($args[$i], $result); |
|
20 | - return $result; |
|
21 | - } |
|
22 | - |
|
23 | - private function getModeResult($val, $prev) { |
|
24 | - return $this->{$this->mode}($val, $prev); |
|
25 | - } |
|
26 | - |
|
27 | - private function add($val, $prev) { |
|
28 | - return $prev+$val; |
|
29 | - } |
|
30 | - |
|
31 | - private function sub($val, $prev) { |
|
32 | - return $prev-$val; |
|
33 | - } |
|
34 | - |
|
35 | - private function mult($val, $prev) { |
|
36 | - return $prev*$val; |
|
37 | - } |
|
38 | - |
|
39 | - private function div($val, $prev) { |
|
40 | - return $prev/$val; |
|
41 | - } |
|
6 | + private $mode; |
|
7 | + |
|
8 | + const ADD = 'add'; |
|
9 | + const SUBTRACT = 'sub'; |
|
10 | + const MULTIPLY = 'mult'; |
|
11 | + const DIVIDE = 'div'; |
|
12 | + |
|
13 | + public function __construct($mode) { |
|
14 | + $this->mode = $mode; |
|
15 | + } |
|
16 | + |
|
17 | + public function run(array $args, \DomElement $element) { |
|
18 | + $result = $args[0]; |
|
19 | + for ($i = 1; $i < count($args); $i++) $result = $this->getModeResult($args[$i], $result); |
|
20 | + return $result; |
|
21 | + } |
|
22 | + |
|
23 | + private function getModeResult($val, $prev) { |
|
24 | + return $this->{$this->mode}($val, $prev); |
|
25 | + } |
|
26 | + |
|
27 | + private function add($val, $prev) { |
|
28 | + return $prev+$val; |
|
29 | + } |
|
30 | + |
|
31 | + private function sub($val, $prev) { |
|
32 | + return $prev-$val; |
|
33 | + } |
|
34 | + |
|
35 | + private function mult($val, $prev) { |
|
36 | + return $prev*$val; |
|
37 | + } |
|
38 | + |
|
39 | + private function div($val, $prev) { |
|
40 | + return $prev/$val; |
|
41 | + } |
|
42 | 42 | } |
@@ -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 | } |