@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | public function setRules($rules) |
| 46 | 46 | { |
| 47 | - if(empty($rules)) { |
|
| 48 | - $this->_rules = [ 'none' => Validator::CONTEXT_IN_ONE_OF ]; |
|
| 47 | + if (empty($rules)) { |
|
| 48 | + $this->_rules = ['none' => Validator::CONTEXT_IN_ONE_OF]; |
|
| 49 | 49 | } else { |
| 50 | 50 | foreach ($rules as $key => $rule) { |
| 51 | - list($plain, $type) = $this->_parse($rule); |
|
| 51 | + list($plain, $type) = $this->_parse($rule); |
|
| 52 | 52 | $this->_rules[$plain] = $type; |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | private function _clean($rule, &$required) |
| 58 | 58 | { |
| 59 | 59 | if (strpos($rule, '.') !== false) { |
| 60 | - foreach (array_filter(array_keys($required), function ($key) use ($rule) { |
|
| 61 | - return fnmatch($key . '.*', $rule); |
|
| 60 | + foreach (array_filter(array_keys($required), function($key) use ($rule) { |
|
| 61 | + return fnmatch($key.'.*', $rule); |
|
| 62 | 62 | }) as $remove) { |
| 63 | 63 | unset($required[$remove]); |
| 64 | 64 | } |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | protected function _validate($context, $rules, $result = false) { |
| 69 | - if(empty($context)) { |
|
| 69 | + if (empty($context)) { |
|
| 70 | 70 | $context = ['none']; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - while(list($rule, $type) = each($rules)) { |
|
| 73 | + while (list($rule, $type) = each($rules)) { |
|
| 74 | 74 | $matched = $this->_matches($context, $rule, $type); |
| 75 | 75 | |
| 76 | 76 | if ($type & Validator::CONTEXT_NOT_IN) { |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $rule = substr($rule, $pos); |
| 125 | 125 | |
| 126 | - if($type & self::CONTEXT_REGEX) { |
|
| 126 | + if ($type & self::CONTEXT_REGEX) { |
|
| 127 | 127 | $rule = "/^$rule(\\.\\w+)?/i"; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -131,22 +131,22 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | private function _matches($context, $rule, $type) { |
| 134 | - if($type & self::CONTEXT_EXACTLY) { |
|
| 134 | + if ($type & self::CONTEXT_EXACTLY) { |
|
| 135 | 135 | return in_array($rule, $context, true); |
| 136 | - } elseif($type & self::CONTEXT_REGEX) { |
|
| 137 | - foreach($context as $item) { |
|
| 138 | - if(preg_match($rule, $item)) { |
|
| 136 | + } elseif ($type & self::CONTEXT_REGEX) { |
|
| 137 | + foreach ($context as $item) { |
|
| 138 | + if (preg_match($rule, $item)) { |
|
| 139 | 139 | return true; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | return false; |
| 143 | 143 | } else { |
| 144 | - if(in_array($rule, $context, true)) { |
|
| 144 | + if (in_array($rule, $context, true)) { |
|
| 145 | 145 | return true; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - foreach($context as $item) { |
|
| 149 | - if(fnmatch("$rule.*", $item)) { |
|
| 148 | + foreach ($context as $item) { |
|
| 149 | + if (fnmatch("$rule.*", $item)) { |
|
| 150 | 150 | return true; |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | static $validator; |
| 160 | 160 | if (!$validator) { |
| 161 | - $validator = new DelegateValidator(function () { |
|
| 161 | + $validator = new DelegateValidator(function() { |
|
| 162 | 162 | return true; |
| 163 | 163 | }); |
| 164 | 164 | } |
@@ -69,21 +69,19 @@ discard block |
||
| 69 | 69 | public function languageByName($name, $params = []) |
| 70 | 70 | { |
| 71 | 71 | return isset($this->_languages['name'][$name]) ? |
| 72 | - $this->_languages['name'][$name]($params) : |
|
| 73 | - new PlainText($params); |
|
| 72 | + $this->_languages['name'][$name]($params) : new PlainText($params); |
|
| 74 | 73 | } |
| 75 | 74 | |
| 76 | 75 | public function languageByMime($mime, $params = []) |
| 77 | 76 | { |
| 78 | 77 | return isset($this->_languages['mime'][$mime]) ? |
| 79 | - $this->_languages['mime'][$mime]($params) : |
|
| 80 | - new PlainText($params); |
|
| 78 | + $this->_languages['mime'][$mime]($params) : new PlainText($params); |
|
| 81 | 79 | } |
| 82 | 80 | |
| 83 | 81 | public function languageByExt($filename, $params = []) |
| 84 | 82 | { |
| 85 | - foreach($this->_languages['extension'] as $mask => $class) { |
|
| 86 | - if(fnmatch($mask, $filename)) { |
|
| 83 | + foreach ($this->_languages['extension'] as $mask => $class) { |
|
| 84 | + if (fnmatch($mask, $filename)) { |
|
| 87 | 85 | return $class($params); |
| 88 | 86 | } |
| 89 | 87 | } |
@@ -109,7 +107,7 @@ discard block |
||
| 109 | 107 | |
| 110 | 108 | public function registeredLanguages($by = 'name') |
| 111 | 109 | { |
| 112 | - return array_map(function ($e) { |
|
| 110 | + return array_map(function($e) { |
|
| 113 | 111 | return get_class($e()); |
| 114 | 112 | }, $this->_languages[$by]); |
| 115 | 113 | } |
@@ -139,7 +137,7 @@ discard block |
||
| 139 | 137 | |
| 140 | 138 | public function init() |
| 141 | 139 | { |
| 142 | - foreach(include __DIR__.'/Config/aliases.php' as $alias) { |
|
| 140 | + foreach (include __DIR__.'/Config/aliases.php' as $alias) { |
|
| 143 | 141 | $class = $alias[0]; |
| 144 | 142 | unset($alias[0]); |
| 145 | 143 | |
@@ -153,13 +151,13 @@ discard block |
||
| 153 | 151 | */ |
| 154 | 152 | public function register($class, array $options) |
| 155 | 153 | { |
| 156 | - if(!is_callable($class) && is_subclass_of($class, Language::class)) { |
|
| 154 | + if (!is_callable($class) && is_subclass_of($class, Language::class)) { |
|
| 157 | 155 | $class = function($arguments = []) use ($class) { |
| 158 | 156 | return new $class($arguments); |
| 159 | 157 | }; |
| 160 | 158 | } |
| 161 | 159 | |
| 162 | - foreach($options as $name => $values) { |
|
| 160 | + foreach ($options as $name => $values) { |
|
| 163 | 161 | $this->_languages[$name] = array_merge($this->_languages[$name], array_fill_keys($values, $class)); |
| 164 | 162 | } |
| 165 | 163 | } |
@@ -18,7 +18,6 @@ |
||
| 18 | 18 | use Kadet\Highlighter\Formatter\CliFormatter; |
| 19 | 19 | use Kadet\Highlighter\Formatter\FormatterInterface; |
| 20 | 20 | use Kadet\Highlighter\Formatter\HtmlFormatter; |
| 21 | -use Kadet\Highlighter\Language\GreedyLanguage; |
|
| 22 | 21 | use Kadet\Highlighter\Language\Language; |
| 23 | 22 | use Kadet\Highlighter\Language\PlainText; |
| 24 | 23 | use Kadet\Highlighter\Utils\Singleton; |
@@ -54,8 +54,8 @@ |
||
| 54 | 54 | $split = explode("\r\n\r\n", $source); |
| 55 | 55 | |
| 56 | 56 | $http = $split[0]; |
| 57 | - if(isset($split[1]) && $payload = $split[1]) { |
|
| 58 | - if(preg_match('/Content-Type: ([^;]*)/', $http, $matches)) { |
|
| 57 | + if (isset($split[1]) && $payload = $split[1]) { |
|
| 58 | + if (preg_match('/Content-Type: ([^;]*)/', $http, $matches)) { |
|
| 59 | 59 | $mime = $matches[1]; |
| 60 | 60 | } else { |
| 61 | 61 | $mime = 'text/plain'; |