@@ -67,11 +67,11 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public function setContext($context) { |
70 | - if(is_array($context)) { |
|
70 | + if (is_array($context)) { |
|
71 | 71 | $this->_validator = new Validator($context); |
72 | - } elseif(is_callable($context)) { |
|
72 | + } elseif (is_callable($context)) { |
|
73 | 73 | $this->_validator = new DelegateValidator($context); |
74 | - }elseif($context instanceof Validator) { |
|
74 | + }elseif ($context instanceof Validator) { |
|
75 | 75 | $this->_validator = $context; |
76 | 76 | } else { |
77 | 77 | throw new \InvalidArgumentException('$context must be valid Validator'); |
@@ -71,7 +71,7 @@ |
||
71 | 71 | $this->_validator = new Validator($context); |
72 | 72 | } elseif(is_callable($context)) { |
73 | 73 | $this->_validator = new DelegateValidator($context); |
74 | - }elseif($context instanceof Validator) { |
|
74 | + } elseif($context instanceof Validator) { |
|
75 | 75 | $this->_validator = $context; |
76 | 76 | } else { |
77 | 77 | throw new \InvalidArgumentException('$context must be valid Validator'); |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | public function validate(array $context, $additional = []) { |
40 | - if(empty($this->_rules) && empty($additional)) { |
|
40 | + if (empty($this->_rules) && empty($additional)) { |
|
41 | 41 | return true; |
42 | 42 | } |
43 | 43 | |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | |
47 | 47 | public function setRules($rules) |
48 | 48 | { |
49 | - if(empty($rules)) { |
|
50 | - $this->_rules = [ 'none' => Validator::CONTEXT_IN_ONE_OF ]; |
|
49 | + if (empty($rules)) { |
|
50 | + $this->_rules = ['none' => Validator::CONTEXT_IN_ONE_OF]; |
|
51 | 51 | } else { |
52 | 52 | foreach ($rules as $key => $rule) { |
53 | - list($plain, $type) = $this->_parse($rule); |
|
53 | + list($plain, $type) = $this->_parse($rule); |
|
54 | 54 | $this->_rules[$plain] = $type; |
55 | 55 | } |
56 | 56 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | private function _clean($rule, &$required) |
60 | 60 | { |
61 | 61 | if (strpos($rule, '.') !== false) { |
62 | - foreach (array_filter(array_keys($required), function ($key) use ($rule) { |
|
62 | + foreach (array_filter(array_keys($required), function($key) use ($rule) { |
|
63 | 63 | return fnmatch($key . '.*', $rule); |
64 | 64 | }) as $remove) { |
65 | 65 | unset($required[$remove]); |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | protected function _validate($context, $rules, $result = false) { |
71 | - if(empty($context)) { |
|
71 | + if (empty($context)) { |
|
72 | 72 | $context = ['none']; |
73 | 73 | } |
74 | 74 | |
75 | - while(list($rule, $type) = each($rules)) { |
|
75 | + while (list($rule, $type) = each($rules)) { |
|
76 | 76 | $matched = $this->_matches($context, $rule, $type); |
77 | 77 | |
78 | 78 | if ($type & Validator::CONTEXT_NOT_IN) { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | $rule = substr($rule, $pos); |
127 | 127 | |
128 | - if($type & self::CONTEXT_REGEX) { |
|
128 | + if ($type & self::CONTEXT_REGEX) { |
|
129 | 129 | $rule = "/^$rule(\\.\\w+)?/i"; |
130 | 130 | } |
131 | 131 | |
@@ -133,22 +133,22 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | private function _matches($context, $rule, $type) { |
136 | - if($type & self::CONTEXT_EXACTLY) { |
|
136 | + if ($type & self::CONTEXT_EXACTLY) { |
|
137 | 137 | return in_array($rule, $context, true); |
138 | - } elseif($type & self::CONTEXT_REGEX) { |
|
139 | - foreach($context as $item) { |
|
140 | - if(preg_match($rule, $item)) { |
|
138 | + } elseif ($type & self::CONTEXT_REGEX) { |
|
139 | + foreach ($context as $item) { |
|
140 | + if (preg_match($rule, $item)) { |
|
141 | 141 | return true; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | return false; |
145 | 145 | } else { |
146 | - if(in_array($rule, $context, true)) { |
|
146 | + if (in_array($rule, $context, true)) { |
|
147 | 147 | return true; |
148 | 148 | } |
149 | 149 | |
150 | - foreach($context as $item) { |
|
151 | - if(fnmatch("$rule.*", $item)) { |
|
150 | + foreach ($context as $item) { |
|
151 | + if (fnmatch("$rule.*", $item)) { |
|
152 | 152 | return true; |
153 | 153 | } |
154 | 154 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | { |
161 | 161 | static $validator; |
162 | 162 | if (!$validator) { |
163 | - $validator = new DelegateValidator(function () { |
|
163 | + $validator = new DelegateValidator(function() { |
|
164 | 164 | return true; |
165 | 165 | }); |
166 | 166 | } |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -108,6 +108,9 @@ discard block |
||
108 | 108 | return $this->_parser->process($tokens); |
109 | 109 | } |
110 | 110 | |
111 | + /** |
|
112 | + * @param string $source |
|
113 | + */ |
|
111 | 114 | public function tokenize($source, $additional = [], $offset = 0, $embedded = false) |
112 | 115 | { |
113 | 116 | return new TokenIterator( |
@@ -145,7 +148,7 @@ discard block |
||
145 | 148 | /** |
146 | 149 | * @param bool $embedded |
147 | 150 | * |
148 | - * @return Rule[] |
|
151 | + * @return \Generator |
|
149 | 152 | */ |
150 | 153 | private function _rules($embedded = false) |
151 | 154 | { |
@@ -177,7 +180,7 @@ discard block |
||
177 | 180 | * |
178 | 181 | * @param $embedded |
179 | 182 | * |
180 | - * @return Rule|\Kadet\Highlighter\Parser\Rule[] |
|
183 | + * @return Rule |
|
181 | 184 | */ |
182 | 185 | public function getEnds($embedded = false) |
183 | 186 | { |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | ]); |
100 | 100 | |
101 | 101 | for ($tokens->next(); $tokens->valid(); $tokens->next()) { |
102 | - if(!$tokens->current()->process($context, $this, $result, $tokens)) { |
|
102 | + if (!$tokens->current()->process($context, $this, $result, $tokens)) { |
|
103 | 103 | break; |
104 | 104 | } |
105 | 105 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | private function _rules($embedded = false) |
150 | 150 | { |
151 | 151 | $rules = clone $this->rules; |
152 | - if(is_bool($embedded)) { |
|
153 | - $rules->addMany(['language.'.$this->getIdentifier() => $this->getEnds($embedded)]); |
|
152 | + if (is_bool($embedded)) { |
|
153 | + $rules->addMany(['language.' . $this->getIdentifier() => $this->getEnds($embedded)]); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | foreach ($rules->all() as $rule) { |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |
@@ -107,7 +107,7 @@ |
||
107 | 107 | public function all() |
108 | 108 | { |
109 | 109 | $items = $this->getArrayCopy(); |
110 | - if(empty($items)) return []; |
|
110 | + if (empty($items)) return []; |
|
111 | 111 | |
112 | 112 | return call_user_func_array('array_merge', $items); |
113 | 113 | } |
@@ -107,7 +107,9 @@ |
||
107 | 107 | public function all() |
108 | 108 | { |
109 | 109 | $items = $this->getArrayCopy(); |
110 | - if(empty($items)) return []; |
|
110 | + if(empty($items)) { |
|
111 | + return []; |
|
112 | + } |
|
111 | 113 | |
112 | 114 | return call_user_func_array('array_merge', $items); |
113 | 115 | } |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Highlighter |
|
4 | - * |
|
5 | - * Copyright (C) 2016, Some right reserved. |
|
6 | - * |
|
7 | - * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | - * |
|
9 | - * Contact with author: |
|
10 | - * Xmpp: [email protected] |
|
11 | - * E-mail: [email protected] |
|
12 | - * |
|
13 | - * From Kadet with love. |
|
14 | - */ |
|
3 | + * Highlighter |
|
4 | + * |
|
5 | + * Copyright (C) 2016, Some right reserved. |
|
6 | + * |
|
7 | + * @author Kacper "Kadet" Donat <[email protected]> |
|
8 | + * |
|
9 | + * Contact with author: |
|
10 | + * Xmpp: [email protected] |
|
11 | + * E-mail: [email protected] |
|
12 | + * |
|
13 | + * From Kadet with love. |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | namespace Kadet\Highlighter\Language; |
17 | 17 |