@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function cd($path) |
35 | 35 | { |
36 | - return new self( $this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path) ); |
|
36 | + return new self($this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path)); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | * @param string $path |
43 | 43 | * @return mixed |
44 | 44 | */ |
45 | - public function find($query, $path='') |
|
45 | + public function find($query, $path = '') |
|
46 | 46 | { |
47 | 47 | $path = \arc\path::collapse($path, $this->path); |
48 | 48 | $sql = $this->queryParser->parse($query, $path); |
49 | - return ($this->resultHandler)( $sql, [] ); |
|
49 | + return ($this->resultHandler)($sql, []); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param string $path |
55 | 55 | * @return mixed |
56 | 56 | */ |
57 | - public function get($path='') |
|
57 | + public function get($path = '') |
|
58 | 58 | { |
59 | 59 | $path = \arc\path::collapse($path, $this->path); |
60 | 60 | $parent = ($path=='/' ? '' : \arc\path::parent($path)); |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * @param string $top |
76 | 76 | * @return mixed |
77 | 77 | */ |
78 | - public function parents($path='', $top='/') |
|
78 | + public function parents($path = '', $top = '/') |
|
79 | 79 | { |
80 | - $path = \arc\path::collapse($path, $this->path); |
|
80 | + $path = \arc\path::collapse($path, $this->path); |
|
81 | 81 | return ($this->resultHandler)( |
82 | 82 | /** @lang sql */ |
83 | 83 | 'lower(path)=lower(substring(:path,1,length(path))) ' |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @param string $path |
92 | 92 | * @return mixed |
93 | 93 | */ |
94 | - public function ls($path='') |
|
94 | + public function ls($path = '') |
|
95 | 95 | { |
96 | - $path = \arc\path::collapse($path, $this->path); |
|
96 | + $path = \arc\path::collapse($path, $this->path); |
|
97 | 97 | return ($this->resultHandler)('parent=:path', [':path' => $path]); |
98 | 98 | } |
99 | 99 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param string $path |
103 | 103 | * @return bool |
104 | 104 | */ |
105 | - public function exists($path='') |
|
105 | + public function exists($path = '') |
|
106 | 106 | { |
107 | 107 | $path = \arc\path::collapse($path, $this->path); |
108 | 108 | $query = $this->db->prepare('select count(*) from nodes where path=:path'); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function initialize() { |
118 | 118 | try { |
119 | - if ($result=$this->exists('/')) { |
|
119 | + if ($result = $this->exists('/')) { |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | } catch (\PDOException $e) { |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | SQL; |
152 | 152 | $queries[] = "create index link_from on links(from_id);"; |
153 | 153 | $queries[] = "create index link_to on links(to_id);"; |
154 | - foreach ( $queries as $query ) { |
|
154 | + foreach ($queries as $query) { |
|
155 | 155 | $result = $this->db->exec($query); |
156 | 156 | if ($result===false) { |
157 | 157 | $this->db->exec('rollback;'); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | |
163 | 163 | return $this->save(\arc\prototype::create([ |
164 | 164 | 'name' => 'Root' |
165 | - ]),'/'); |
|
165 | + ]), '/'); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param string $path |
172 | 172 | * @return mixed |
173 | 173 | */ |
174 | - public function save($data, $path='') { |
|
174 | + public function save($data, $path = '') { |
|
175 | 175 | $path = \arc\path::collapse($path, $this->path); |
176 | 176 | $parent = ($path=='/' ? '' : \arc\path::parent($path)); |
177 | 177 | if ($path!='/' && !$this->exists($parent)) { |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | final class PSQLQueryParser { |
6 | 6 | |
7 | - private $tokenizer; |
|
7 | + private $tokenizer; |
|
8 | 8 | |
9 | - public function __construct($tokenizer) { |
|
10 | - $this->tokenizer = $tokenizer; |
|
11 | - } |
|
9 | + public function __construct($tokenizer) { |
|
10 | + $this->tokenizer = $tokenizer; |
|
11 | + } |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param string $query |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | $sql = []; |
22 | 22 | $position = 0; |
23 | 23 | $expect = 'name|parenthesis_open|not'; |
24 | - foreach( call_user_func($this->tokenizer, $query) as $token ) { |
|
24 | + foreach (call_user_func($this->tokenizer, $query) as $token) { |
|
25 | 25 | $tokenType = key($token); |
26 | - list($tokenValue, $offset)=$token[$tokenType]; |
|
27 | - if ( !preg_match("/^$expect$/",$tokenType) ) { |
|
26 | + list($tokenValue, $offset) = $token[$tokenType]; |
|
27 | + if (!preg_match("/^$expect$/", $tokenType)) { |
|
28 | 28 | throw new \LogicException('Parse error at '.$position.': expected '.$expect.', got '.$tokenType.': ' |
29 | - .(substr($query,0, $position)." --> ".substr($query,$position)) ); |
|
29 | + .(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
30 | 30 | } |
31 | - switch($tokenType) { |
|
31 | + switch ($tokenType) { |
|
32 | 32 | case 'number': |
33 | 33 | case 'string': |
34 | 34 | $sql[] = $tokenValue; |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | $sql[] = $tokenValue; |
45 | 45 | break; |
46 | 46 | default: |
47 | - $sql[] = "nodes.data #>> '{".str_replace('.',',',$tokenValue)."}'"; |
|
47 | + $sql[] = "nodes.data #>> '{".str_replace('.', ',', $tokenValue)."}'"; |
|
48 | 48 | break; |
49 | 49 | } |
50 | 50 | $expect = 'compare'; |
51 | 51 | break; |
52 | 52 | case 'compare': |
53 | - switch( $tokenValue ) { |
|
53 | + switch ($tokenValue) { |
|
54 | 54 | case '>': |
55 | 55 | case '>=': |
56 | 56 | case '<': |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | $sql[] = $tokenValue; |
62 | 62 | break; |
63 | 63 | case '?': |
64 | - $part = $sql[count($sql)-1]; |
|
64 | + $part = $sql[count($sql) - 1]; |
|
65 | 65 | $part = str_replace('#>>', '#>', $part); |
66 | - $sql[count($sql)-1] = $part; |
|
66 | + $sql[count($sql) - 1] = $part; |
|
67 | 67 | $sql[] = $tokenValue; |
68 | 68 | break; |
69 | 69 | case '~=': |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | case 'parenthesis_close': |
92 | 92 | $sql[] = $tokenValue; |
93 | 93 | $indent--; |
94 | - if ( $indent>0 ) { |
|
94 | + if ($indent>0) { |
|
95 | 95 | $expect = 'operator|parenthesis_close'; |
96 | 96 | } else { |
97 | 97 | $expect = 'operator'; |
@@ -100,21 +100,21 @@ discard block |
||
100 | 100 | } |
101 | 101 | $position += $offset + strlen($tokenValue); |
102 | 102 | } |
103 | - if ( $indent!=0 ) { |
|
103 | + if ($indent!=0) { |
|
104 | 104 | throw new \LogicException('unbalanced parenthesis'); |
105 | 105 | } |
106 | 106 | if ($position<strlen($query)) { |
107 | 107 | throw new \LogicException('Parse error at '.$position.': unrecognized token: ' |
108 | - .(substr($query,0, $position)." --> ".substr($query,$position)) ); |
|
108 | + .(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
109 | 109 | } |
110 | - foreach(['number','string','compare'] as $tokenType) { |
|
110 | + foreach (['number', 'string', 'compare'] as $tokenType) { |
|
111 | 111 | if (strpos($expect, $tokenType)!==false) { |
112 | 112 | throw new \LogicException('Parse error at '.$position.': expected '.$expect.': ' |
113 | - .(substr($query,0, $position)." --> ".substr($query,$position)) ); |
|
113 | + .(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | } |
117 | - return implode(' ',$sql); |
|
117 | + return implode(' ', $sql); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -6,9 +6,9 @@ |
||
6 | 6 | |
7 | 7 | private $tokenizer; |
8 | 8 | |
9 | - public function __construct($tokenizer) { |
|
10 | - $this->tokenizer = $tokenizer; |
|
11 | - } |
|
9 | + public function __construct($tokenizer) { |
|
10 | + $this->tokenizer = $tokenizer; |
|
11 | + } |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param string $query |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | $position = 0; |
23 | 23 | $expect = 'name|parenthesis_open|not'; |
24 | 24 | |
25 | - foreach( call_user_func($this->tokenizer, $query) as $token ) { |
|
25 | + foreach (call_user_func($this->tokenizer, $query) as $token) { |
|
26 | 26 | $tokenType = key($token); |
27 | - list($tokenValue, $offset)=$token[$tokenType]; |
|
28 | - if ( !preg_match("/^$expect$/",$tokenType) ) { |
|
27 | + list($tokenValue, $offset) = $token[$tokenType]; |
|
28 | + if (!preg_match("/^$expect$/", $tokenType)) { |
|
29 | 29 | throw new \LogicException('Parse error at '.$position.': expected '.$expect.', got '.$tokenType.': ' |
30 | - .(substr($query,0, $position)." --> ".substr($query,$position)) ); |
|
30 | + .(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
31 | 31 | } |
32 | - switch($tokenType) { |
|
32 | + switch ($tokenType) { |
|
33 | 33 | case 'number': |
34 | 34 | case 'string': |
35 | 35 | $sql[] = $tokenValue; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $expect = 'compare'; |
52 | 52 | break; |
53 | 53 | case 'compare': |
54 | - switch( $tokenValue ) { |
|
54 | + switch ($tokenValue) { |
|
55 | 55 | case '>': |
56 | 56 | case '>=': |
57 | 57 | case '<': |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | case '=': |
60 | 60 | case '<>': |
61 | 61 | case '!=': |
62 | - $sql[] =$tokenValue; |
|
62 | + $sql[] = $tokenValue; |
|
63 | 63 | break; |
64 | 64 | case '?': |
65 | - $part = $sql[count($sql)-1]; |
|
65 | + $part = $sql[count($sql) - 1]; |
|
66 | 66 | $part = str_replace('->>', '->', $part); |
67 | - $sql[count($sql)-1] = $part; |
|
67 | + $sql[count($sql) - 1] = $part; |
|
68 | 68 | $sql[] = 'IS NOT NULL'; |
69 | 69 | break; |
70 | 70 | case '~=': |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | case 'parenthesis_close': |
93 | 93 | $sql[] = $tokenValue; |
94 | 94 | $indent--; |
95 | - if ( $indent>0 ) { |
|
95 | + if ($indent>0) { |
|
96 | 96 | $expect = 'operator|parenthesis_close'; |
97 | 97 | } else { |
98 | 98 | $expect = 'operator'; |
@@ -101,21 +101,21 @@ discard block |
||
101 | 101 | } |
102 | 102 | $position += $offset + strlen($tokenValue); |
103 | 103 | } |
104 | - if ( $indent!=0 ) { |
|
104 | + if ($indent!=0) { |
|
105 | 105 | throw new \LogicException('unbalanced parenthesis'); |
106 | 106 | } |
107 | 107 | if ($position<strlen($query)) { |
108 | 108 | throw new \LogicException('Parse error at '.$position.': unrecognized token: ' |
109 | - .(substr($query,0, $position)." --> ".substr($query,$position)) ); |
|
109 | + .(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
110 | 110 | } |
111 | - foreach(['number','string','compare'] as $tokenType) { |
|
111 | + foreach (['number', 'string', 'compare'] as $tokenType) { |
|
112 | 112 | if (strpos($expect, $tokenType)!==false) { |
113 | 113 | throw new \LogicException('Parse error at '.$position.': expected '.$expect.': ' |
114 | - .(substr($query,0, $position)." --> ".substr($query,$position)) ); |
|
114 | + .(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
115 | 115 | |
116 | 116 | } |
117 | 117 | } |
118 | - return implode(' ',$sql); |
|
118 | + return implode(' ', $sql); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | } |
@@ -15,14 +15,14 @@ discard block |
||
15 | 15 | * @param string $path |
16 | 16 | * @return mixed |
17 | 17 | */ |
18 | - public function find($query, $path=''); |
|
18 | + public function find($query, $path = ''); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * get a single object from the store by path |
22 | 22 | * @param string $path |
23 | 23 | * @return mixed |
24 | 24 | */ |
25 | - public function get($path=''); |
|
25 | + public function get($path = ''); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * list all parents, including self, by path, starting from the root |
@@ -30,21 +30,21 @@ discard block |
||
30 | 30 | * @param string $top |
31 | 31 | * @return mixed |
32 | 32 | */ |
33 | - public function parents($path='', $top='/'); |
|
33 | + public function parents($path = '', $top = '/'); |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * list all child objects by path |
37 | 37 | * @param string $path |
38 | 38 | * @return mixed |
39 | 39 | */ |
40 | - public function ls($path=''); |
|
40 | + public function ls($path = ''); |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * returns true if an object with the given path exists |
44 | 44 | * @param string $path |
45 | 45 | * @return bool |
46 | 46 | */ |
47 | - public function exists($path=''); |
|
47 | + public function exists($path = ''); |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * initialize the store, if it wasn't before |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param string $path |
59 | 59 | * @return mixed |
60 | 60 | */ |
61 | - public function save($data, $path=''); |
|
61 | + public function save($data, $path = ''); |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * remove the object with the given path and all its children |
@@ -11,7 +11,7 @@ |
||
11 | 11 | $q = $db->prepare('select * from nodes where '.$query); |
12 | 12 | $result = $q->execute($args); |
13 | 13 | $dataset = []; |
14 | - while ( $data = $q->fetch(\PDO::FETCH_ASSOC) ) { |
|
14 | + while ($data = $q->fetch(\PDO::FETCH_ASSOC)) { |
|
15 | 15 | $value = (object) $data; |
16 | 16 | $value->data = json_decode($value->data); |
17 | 17 | $value->ctime = strtotime($value->ctime); |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | final class TreeQueryParser { |
6 | 6 | |
7 | - private $tokenizer; |
|
7 | + private $tokenizer; |
|
8 | 8 | |
9 | - public function __construct($tokenizer) { |
|
10 | - $this->tokenizer = $tokenizer; |
|
11 | - } |
|
9 | + public function __construct($tokenizer) { |
|
10 | + $this->tokenizer = $tokenizer; |
|
11 | + } |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param string $query |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | $position = 0; |
25 | 25 | $expect = 'name|parenthesis_open|not'; |
26 | 26 | |
27 | - foreach( call_user_func($this->tokenizer, $query) as $token ) { |
|
27 | + foreach (call_user_func($this->tokenizer, $query) as $token) { |
|
28 | 28 | $type = key($token); |
29 | - list($token, $offset)=$token[$type]; |
|
30 | - if ( !preg_match("/^$expect$/",$type) ) { |
|
29 | + list($token, $offset) = $token[$type]; |
|
30 | + if (!preg_match("/^$expect$/", $type)) { |
|
31 | 31 | throw new \LogicException('Parse error at '.$position.': expected '.$expect.', got '.$type.': ' |
32 | - .(substr($query,0, $position)." --> ".substr($query,$position)) ); |
|
32 | + .(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
33 | 33 | } |
34 | - switch($type) { |
|
34 | + switch ($type) { |
|
35 | 35 | case 'number': |
36 | 36 | case 'string': |
37 | 37 | if (strpos($part, '{placeholder}')!==false) { |
@@ -60,28 +60,28 @@ discard block |
||
60 | 60 | $part = '$node->nodeValue->ctime'; |
61 | 61 | break; |
62 | 62 | default: |
63 | - $part = '$node->nodeValue->'.str_replace('.','->',$token); |
|
63 | + $part = '$node->nodeValue->'.str_replace('.', '->', $token); |
|
64 | 64 | break; |
65 | 65 | } |
66 | 66 | $expect = 'compare'; |
67 | 67 | break; |
68 | 68 | case 'compare': |
69 | - switch( $token ) { |
|
69 | + switch ($token) { |
|
70 | 70 | case '>': |
71 | 71 | case '>=': |
72 | 72 | case '<': |
73 | 73 | case '<=': |
74 | 74 | case '!=': |
75 | - $part = '( '.$part. ' ?? null ) '.$token; |
|
75 | + $part = '( '.$part.' ?? null ) '.$token; |
|
76 | 76 | break; |
77 | 77 | case '<>': |
78 | - $part = '( '.$part. ' ?? null ) !='; |
|
78 | + $part = '( '.$part.' ?? null ) !='; |
|
79 | 79 | break; |
80 | 80 | case '=': |
81 | - $part = '( '.$part. ' ?? null ) =='; |
|
81 | + $part = '( '.$part.' ?? null ) =='; |
|
82 | 82 | break; |
83 | 83 | case '?': |
84 | - $part ='property_exists('.$part.' ?? null,{placeholder})'; |
|
84 | + $part = 'property_exists('.$part.' ?? null,{placeholder})'; |
|
85 | 85 | break; |
86 | 86 | case '~=': |
87 | 87 | $part = '$like('.$part.' ?? null,{placeholder})'; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $expect = 'name|parenthesis_open'; |
98 | 98 | break; |
99 | 99 | case 'operator': |
100 | - switch($token) { |
|
100 | + switch ($token) { |
|
101 | 101 | case 'and': |
102 | 102 | $fn[] = '&&'; |
103 | 103 | break; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | case 'parenthesis_close': |
116 | 116 | $fn[] = $token; |
117 | 117 | $indent--; |
118 | - if ( $indent>0 ) { |
|
118 | + if ($indent>0) { |
|
119 | 119 | $expect = 'operator|parenthesis_close'; |
120 | 120 | } else { |
121 | 121 | $expect = 'operator'; |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | } |
125 | 125 | $position += $offset + strlen($token); |
126 | 126 | } |
127 | - if ( $indent!=0 ) { |
|
127 | + if ($indent!=0) { |
|
128 | 128 | throw new \LogicException('unbalanced parenthesis'); |
129 | - } else if ( trim($part) ) { |
|
129 | + } else if (trim($part)) { |
|
130 | 130 | $position -= strlen($token); |
131 | - throw new \LogicException('parse error at '.$position.': '.(substr($query,0, $position)." --> ".substr($query,$position))); |
|
131 | + throw new \LogicException('parse error at '.$position.': '.(substr($query, 0, $position)." --> ".substr($query, $position))); |
|
132 | 132 | } else { |
133 | - $fn = implode(' ',$fn); |
|
133 | + $fn = implode(' ', $fn); |
|
134 | 134 | $like = function($haystack, $needle) { |
135 | 135 | $re = str_replace('%', '.*', $needle); |
136 | 136 | return preg_match('|'.$re.'|i', $haystack); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function cd($path) |
33 | 33 | { |
34 | - return new self( $this->tree, $this->queryParser, $this->resultHandlerFactory, \arc\path::collapse($path, $this->path) ); |
|
34 | + return new self($this->tree, $this->queryParser, $this->resultHandlerFactory, \arc\path::collapse($path, $this->path)); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | * @param string $path |
41 | 41 | * @return mixed |
42 | 42 | */ |
43 | - public function find($query, $path='') |
|
43 | + public function find($query, $path = '') |
|
44 | 44 | { |
45 | 45 | $path = \arc\path::collapse($path, $this->path); |
46 | 46 | $root = $this->tree->cd($path); |
47 | 47 | $f = $this->queryParser->parse($query, $path); |
48 | - return call_user_func($this->resultHandler, $f ); |
|
48 | + return call_user_func($this->resultHandler, $f); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param string $path |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function get($path='') |
|
56 | + public function get($path = '') |
|
57 | 57 | { |
58 | 58 | $path = \arc\path::collapse($path, $this->path); |
59 | 59 | $result = $this->tree->cd($path); |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @param string $top |
67 | 67 | * @return mixed |
68 | 68 | */ |
69 | - public function parents($path='', $top='/') |
|
69 | + public function parents($path = '', $top = '/') |
|
70 | 70 | { |
71 | - $path = \arc\path::collapse($path, $this->path); |
|
71 | + $path = \arc\path::collapse($path, $this->path); |
|
72 | 72 | return ($this->resultHandler)( |
73 | 73 | 'strtolower($node->path)==strtolower(substring("' |
74 | 74 | .$path.'",1,'.sizeof($path) |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | * @param string $path |
82 | 82 | * @return mixed |
83 | 83 | */ |
84 | - public function ls($path='') |
|
84 | + public function ls($path = '') |
|
85 | 85 | { |
86 | - $path = \arc\path::collapse($path, $this->path); |
|
86 | + $path = \arc\path::collapse($path, $this->path); |
|
87 | 87 | return $this->tree->cd($path)->ls(function($node) { |
88 | - return json_decode(json_encode($node->nodeValue),false); |
|
88 | + return json_decode(json_encode($node->nodeValue), false); |
|
89 | 89 | }); |
90 | 90 | } |
91 | 91 | |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @param string $path |
95 | 95 | * @return bool |
96 | 96 | */ |
97 | - public function exists($path='') |
|
97 | + public function exists($path = '') |
|
98 | 98 | { |
99 | - $path = \arc\path::collapse($path, $this->path); |
|
99 | + $path = \arc\path::collapse($path, $this->path); |
|
100 | 100 | if ($path!='/') { |
101 | 101 | $parent = ($path=='/' ? '' : \arc\path::parent($path)); |
102 | 102 | $name = basename($path); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function initialize() { |
113 | 113 | return $this->save(\arc\prototype::create([ |
114 | 114 | 'name' => 'Root' |
115 | - ]),'/'); |
|
115 | + ]), '/'); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param string $path |
122 | 122 | * @return mixed |
123 | 123 | */ |
124 | - public function save($data, $path='') { |
|
124 | + public function save($data, $path = '') { |
|
125 | 125 | $path = \arc\path::collapse($path, $this->path); |
126 | 126 | $parent = ($path=='/' ? '' : \arc\path::parent($path)); |
127 | 127 | if ($path!='/' && !$this->exists($parent)) { |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | { |
157 | 157 | return function($callback) use ($tree) { |
158 | 158 | $dataset = \arc\tree::filter($tree, $callback); |
159 | - foreach($dataset as $path => $node) { |
|
160 | - $node = json_decode(json_encode($node),false); |
|
159 | + foreach ($dataset as $path => $node) { |
|
160 | + $node = json_decode(json_encode($node), false); |
|
161 | 161 | $dataset[$path] = $node; |
162 | 162 | } |
163 | 163 | return $dataset; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param string $resultHandler handler that executes the sql query |
20 | 20 | * @return store\Store the store |
21 | 21 | */ |
22 | - public static function connect($dsn, $resultHandler=null) |
|
22 | + public static function connect($dsn, $resultHandler = null) |
|
23 | 23 | { |
24 | 24 | $db = new \PDO($dsn); |
25 | 25 | $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $className = $storeType.'Store'; |
41 | 41 | $store = new $className( |
42 | 42 | $db, |
43 | - new $queryParserClassName(array('\arc\store','tokenizer')), |
|
43 | + new $queryParserClassName(array('\arc\store', 'tokenizer')), |
|
44 | 44 | $resultHandler($db) |
45 | 45 | ); |
46 | 46 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | ARRAY_FILTER_USE_BOTH |
185 | 185 | ); |
186 | 186 | } |
187 | - } while($result); |
|
188 | - if ( trim($query) ) { |
|
187 | + } while ($result); |
|
188 | + if (trim($query)) { |
|
189 | 189 | throw new \LogicException('Could not parse '.$query); |
190 | 190 | } |
191 | 191 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function __construct($db = null, $queryParser = null, $resultHandler = null, $path = '/') |
22 | 22 | { |
23 | - $this->db = $db; |
|
23 | + $this->db = $db; |
|
24 | 24 | if ($this->db) { |
25 | 25 | $this->db->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); |
26 | 26 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function cd($path) |
38 | 38 | { |
39 | - return new self( $this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path) ); |
|
39 | + return new self($this->db, $this->queryParser, $this->resultHandler, \arc\path::collapse($path, $this->path)); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | * @param string $path |
46 | 46 | * @return mixed |
47 | 47 | */ |
48 | - public function find($query, $path='') |
|
48 | + public function find($query, $path = '') |
|
49 | 49 | { |
50 | 50 | $path = \arc\path::collapse($path, $this->path); |
51 | 51 | $sql = $this->queryParser->parse($query, $path); |
52 | - return ($this->resultHandler)( $sql, [] ); |
|
52 | + return ($this->resultHandler)($sql, []); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param string $path |
58 | 58 | * @return mixed |
59 | 59 | */ |
60 | - public function get($path='') |
|
60 | + public function get($path = '') |
|
61 | 61 | { |
62 | 62 | $path = \arc\path::collapse($path, $this->path); |
63 | 63 | $parent = ($path=='/' ? '' : \arc\path::parent($path)); |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * @param string $top |
79 | 79 | * @return mixed |
80 | 80 | */ |
81 | - public function parents($path='', $top='/') |
|
81 | + public function parents($path = '', $top = '/') |
|
82 | 82 | { |
83 | - $path = \arc\path::collapse($path, $this->path); |
|
83 | + $path = \arc\path::collapse($path, $this->path); |
|
84 | 84 | return ($this->resultHandler)( |
85 | 85 | /** @lang sql */ |
86 | 86 | 'path=substring(:path,1,length(path)) ' |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @param string $path |
95 | 95 | * @return mixed |
96 | 96 | */ |
97 | - public function ls($path='') |
|
97 | + public function ls($path = '') |
|
98 | 98 | { |
99 | - $path = \arc\path::collapse($path, $this->path); |
|
99 | + $path = \arc\path::collapse($path, $this->path); |
|
100 | 100 | return ($this->resultHandler)('parent=:path', [':path' => $path]); |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param string $path |
106 | 106 | * @return bool |
107 | 107 | */ |
108 | - public function exists($path='') |
|
108 | + public function exists($path = '') |
|
109 | 109 | { |
110 | 110 | $path = \arc\path::collapse($path, $this->path); |
111 | 111 | $query = $this->db->prepare('select count(*) from nodes where path=:path'); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function initialize() { |
121 | 121 | try { |
122 | - if ($result=$this->exists('/')) { |
|
122 | + if ($result = $this->exists('/')) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | } catch (\PDOException $e) { |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | SQL; |
144 | 144 | // $queries[] = "create trigger before_insert_node before insert on nodes for each row set new.id = UUID_TO_BIN(uuid());"; |
145 | 145 | $queries[] = "create unique index path on nodes ( path(255) );"; |
146 | - foreach ( $queries as $query ) { |
|
146 | + foreach ($queries as $query) { |
|
147 | 147 | $result = $this->db->exec($query); |
148 | 148 | if ($result===false) { |
149 | 149 | $this->db->exec('rollback;'); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | return $this->save(\arc\prototype::create([ |
156 | 156 | 'name' => 'Root' |
157 | - ]),'/'); |
|
157 | + ]), '/'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param string $path |
164 | 164 | * @return mixed |
165 | 165 | */ |
166 | - public function save($data, $path='') { |
|
166 | + public function save($data, $path = '') { |
|
167 | 167 | $path = \arc\path::collapse($path, $this->path); |
168 | 168 | $parent = ($path=='/' ? '' : \arc\path::parent($path)); |
169 | 169 | if ($path!='/' && !$this->exists($parent)) { |