@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | { |
| 6 | 6 | |
| 7 | 7 | protected $viewPath=''; |
| 8 | - protected $title = ''; |
|
| 8 | + protected $title=''; |
|
| 9 | 9 | private $twig; |
| 10 | 10 | private $tVar=array(); |
| 11 | 11 | |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * @param string $name |
| 52 | 52 | */ |
| 53 | - protected function assign($name, $value = '') { |
|
| 53 | + protected function assign($name, $value='') { |
|
| 54 | 54 | if (is_array($name)) { |
| 55 | - $this->tVar = array_merge($this->tVar, $name); |
|
| 55 | + $this->tVar=array_merge($this->tVar, $name); |
|
| 56 | 56 | } else { |
| 57 | - $this->tVar[$name] = $value; |
|
| 57 | + $this->tVar[$name]=$value; |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - protected function model($modelName, $vars = []) { |
|
| 62 | - return app($modelName . '_model', $vars); |
|
| 61 | + protected function model($modelName, $vars=[]) { |
|
| 62 | + return app($modelName.'_model', $vars); |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @var array |
| 17 | 17 | */ |
| 18 | - protected $loadedConfigurations = []; |
|
| 18 | + protected $loadedConfigurations=[]; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * 应用的根目录. |
@@ -30,17 +30,17 @@ discard block |
||
| 30 | 30 | $this->initConfig(); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - private function initEnv(){ |
|
| 34 | - try{ |
|
| 35 | - $dotEnv = new Dotenv($this->basePath); |
|
| 33 | + private function initEnv() { |
|
| 34 | + try { |
|
| 35 | + $dotEnv=new Dotenv($this->basePath); |
|
| 36 | 36 | $dotEnv->load(); |
| 37 | 37 | } |
| 38 | - catch (\Dotenv\Exception\InvalidPathException $e){ |
|
| 38 | + catch (\Dotenv\Exception\InvalidPathException $e) { |
|
| 39 | 39 | die("环境配置文件`.env`没有被找到."); |
| 40 | 40 | } |
| 41 | 41 | date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai')); |
| 42 | 42 | define('IS_CLI', $this->runningInConsole()); |
| 43 | - define('IS_DEBUG',env('DEBUG',false)); |
|
| 43 | + define('IS_DEBUG', env('DEBUG', false)); |
|
| 44 | 44 | if (IS_DEBUG) { |
| 45 | 45 | error_reporting(E_ALL); |
| 46 | 46 | @ini_set('display_errors', 'On'); |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | private function initContainer() { |
| 70 | 70 | static::setInstance($this); |
| 71 | - $this->instance('app',$this); |
|
| 72 | - $this->instance('config',new Config()); |
|
| 73 | - $this->instance('request',new Request($this->config)); |
|
| 74 | - $this->instance('route',new Route($this->request)); |
|
| 71 | + $this->instance('app', $this); |
|
| 72 | + $this->instance('config', new Config()); |
|
| 73 | + $this->instance('request', new Request($this->config)); |
|
| 74 | + $this->instance('route', new Route($this->request)); |
|
| 75 | 75 | $this->regexBind('#^(\w+)_model$#', "\\tests\\app\\models\\\\$1"); |
| 76 | - $this->bind('pinyin','\puck\helpers\PinYin'); |
|
| 77 | - $this->bind('curl','\puck\helpers\Curl'); |
|
| 76 | + $this->bind('pinyin', '\puck\helpers\PinYin'); |
|
| 77 | + $this->bind('curl', '\puck\helpers\Curl'); |
|
| 78 | 78 | $this->bind('dom', '\puck\helpers\Dom'); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | 96 | //标记为已加载 |
| 97 | - $this->loadedConfigurations[$name] = true; |
|
| 98 | - $path = $this->getConfigurationPath($name); |
|
| 97 | + $this->loadedConfigurations[$name]=true; |
|
| 98 | + $path=$this->getConfigurationPath($name); |
|
| 99 | 99 | if ($path) { |
| 100 | 100 | $this->make('config')->set($name, require $path); |
| 101 | 101 | } |
@@ -111,21 +111,21 @@ discard block |
||
| 111 | 111 | * @param string|null $name |
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | - public function getConfigurationPath($name = null) |
|
| 114 | + public function getConfigurationPath($name=null) |
|
| 115 | 115 | { |
| 116 | - if (! $name) { |
|
| 117 | - $appConfigDir = $this->basePath('configs').'/'; |
|
| 116 | + if (!$name) { |
|
| 117 | + $appConfigDir=$this->basePath('configs').'/'; |
|
| 118 | 118 | |
| 119 | 119 | if (file_exists($appConfigDir)) { |
| 120 | 120 | return $appConfigDir; |
| 121 | - } elseif (file_exists($path = __DIR__.'/configs/')) { |
|
| 121 | + } elseif (file_exists($path=__DIR__.'/configs/')) { |
|
| 122 | 122 | return $path; |
| 123 | 123 | } |
| 124 | 124 | } else { |
| 125 | - $appConfigPath = $this->basePath('configs').'/'.$name.'.php'; |
|
| 125 | + $appConfigPath=$this->basePath('configs').'/'.$name.'.php'; |
|
| 126 | 126 | if (file_exists($appConfigPath)) { |
| 127 | 127 | return $appConfigPath; |
| 128 | - } elseif (file_exists($path = __DIR__.'/configs/'.$name.'.php')) { |
|
| 128 | + } elseif (file_exists($path=__DIR__.'/configs/'.$name.'.php')) { |
|
| 129 | 129 | return $path; |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -137,15 +137,15 @@ discard block |
||
| 137 | 137 | * @param string|null $path |
| 138 | 138 | * @return string |
| 139 | 139 | */ |
| 140 | - public function basePath($path = null) { |
|
| 140 | + public function basePath($path=null) { |
|
| 141 | 141 | if (isset($this->basePath)) { |
| 142 | - return $this->basePath . ($path ? '/' . $path : $path); |
|
| 142 | + return $this->basePath.($path ? '/'.$path : $path); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | if ($this->runningInConsole()) { |
| 146 | - $this->basePath = getcwd(); |
|
| 146 | + $this->basePath=getcwd(); |
|
| 147 | 147 | } else { |
| 148 | - $this->basePath = realpath(getcwd() . '/../'); |
|
| 148 | + $this->basePath=realpath(getcwd().'/../'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | return $this->basePath($path); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | // 容器中绑定的对象标识 |
| 20 | 20 | protected $bind=[]; |
| 21 | 21 | // 正则绑定 |
| 22 | - protected $regexBind = []; |
|
| 22 | + protected $regexBind=[]; |
|
| 23 | 23 | /** |
| 24 | 24 | * 获取当前容器的实例(单例) |
| 25 | 25 | * @access public |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | public function regexBind($regex, $class) { |
| 50 | - $this->regexBind[$regex] = $class; |
|
| 50 | + $this->regexBind[$regex]=$class; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | * @param array $vars 变量 |
| 87 | 87 | * @return mixed |
| 88 | 88 | */ |
| 89 | - public function invokeFunction($function, $vars = []) |
|
| 89 | + public function invokeFunction($function, $vars=[]) |
|
| 90 | 90 | { |
| 91 | - $reflect = new \ReflectionFunction($function); |
|
| 92 | - $args = $this->bindParams($reflect, $vars); |
|
| 91 | + $reflect=new \ReflectionFunction($function); |
|
| 92 | + $args=$this->bindParams($reflect, $vars); |
|
| 93 | 93 | return $reflect->invokeArgs($args); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -134,36 +134,36 @@ discard block |
||
| 134 | 134 | * @param array $vars 变量 |
| 135 | 135 | * @return object |
| 136 | 136 | */ |
| 137 | - public function make($abstract, $vars = [], $newInstance = false) { |
|
| 137 | + public function make($abstract, $vars=[], $newInstance=false) { |
|
| 138 | 138 | if (isset($this->instances[$abstract])) { |
| 139 | - $object = $this->instances[$abstract]; |
|
| 139 | + $object=$this->instances[$abstract]; |
|
| 140 | 140 | } else { |
| 141 | 141 | if (isset($this->bind[$abstract])) { |
| 142 | - $concrete = $this->bind[$abstract]; |
|
| 143 | - $object = $this->makeObject($concrete, $vars); |
|
| 142 | + $concrete=$this->bind[$abstract]; |
|
| 143 | + $object=$this->makeObject($concrete, $vars); |
|
| 144 | 144 | } else { |
| 145 | 145 | //正则绑定 |
| 146 | - $result = preg_filter(array_keys($this->regexBind), array_values($this->regexBind), $abstract); |
|
| 146 | + $result=preg_filter(array_keys($this->regexBind), array_values($this->regexBind), $abstract); |
|
| 147 | 147 | if ($result) { |
| 148 | - $concrete = is_array($result) ? end($result) : $result; |
|
| 149 | - $object = $this->makeObject($concrete, $vars); |
|
| 148 | + $concrete=is_array($result) ? end($result) : $result; |
|
| 149 | + $object=$this->makeObject($concrete, $vars); |
|
| 150 | 150 | } else { |
| 151 | - $object = $this->invokeClass($abstract, $vars); |
|
| 151 | + $object=$this->invokeClass($abstract, $vars); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if (!$newInstance) { |
| 156 | - $this->instances[$abstract] = $object; |
|
| 156 | + $this->instances[$abstract]=$object; |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | return $object; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - private function makeObject($concrete, $vars = []) { |
|
| 162 | + private function makeObject($concrete, $vars=[]) { |
|
| 163 | 163 | if ($concrete instanceof \Closure) { |
| 164 | - $object = $this->invokeFunction($concrete, $vars); |
|
| 164 | + $object=$this->invokeFunction($concrete, $vars); |
|
| 165 | 165 | } else { |
| 166 | - $object = $this->make($concrete, $vars); |
|
| 166 | + $object=$this->make($concrete, $vars); |
|
| 167 | 167 | } |
| 168 | 168 | return $object; |
| 169 | 169 | } |
@@ -175,23 +175,23 @@ discard block |
||
| 175 | 175 | * @param array $vars 变量 |
| 176 | 176 | * @return mixed |
| 177 | 177 | */ |
| 178 | - public function invokeClass($class, $vars = []) { |
|
| 178 | + public function invokeClass($class, $vars=[]) { |
|
| 179 | 179 | try { |
| 180 | - $reflect = new \ReflectionClass($class); |
|
| 180 | + $reflect=new \ReflectionClass($class); |
|
| 181 | 181 | } catch (\ReflectionException $e) { |
| 182 | - $classArray = explode("\\", $class); |
|
| 183 | - $classSelf = array_pop($classArray); |
|
| 184 | - $classSelf = Str::studly($classSelf); |
|
| 182 | + $classArray=explode("\\", $class); |
|
| 183 | + $classSelf=array_pop($classArray); |
|
| 184 | + $classSelf=Str::studly($classSelf); |
|
| 185 | 185 | array_push($classArray, $classSelf); |
| 186 | - $class = implode("\\", $classArray); |
|
| 187 | - $reflect = new \ReflectionClass($class); |
|
| 186 | + $class=implode("\\", $classArray); |
|
| 187 | + $reflect=new \ReflectionClass($class); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $constructor = $reflect->getConstructor(); |
|
| 190 | + $constructor=$reflect->getConstructor(); |
|
| 191 | 191 | if ($constructor) { |
| 192 | - $args = $this->bindParams($constructor, $vars); |
|
| 192 | + $args=$this->bindParams($constructor, $vars); |
|
| 193 | 193 | } else { |
| 194 | - $args = []; |
|
| 194 | + $args=[]; |
|
| 195 | 195 | } |
| 196 | 196 | return $reflect->newInstanceArgs($args); |
| 197 | 197 | } |
@@ -203,15 +203,15 @@ discard block |
||
| 203 | 203 | * @param array $vars 变量 |
| 204 | 204 | * @return mixed |
| 205 | 205 | */ |
| 206 | - public function invokeMethod($method, $vars = []) { |
|
| 206 | + public function invokeMethod($method, $vars=[]) { |
|
| 207 | 207 | if (is_array($method)) { |
| 208 | - $class = is_object($method[0]) ? $method[0] : $this->invokeClass($method[0]); |
|
| 209 | - $reflect = new \ReflectionMethod($class, $method[1]); |
|
| 208 | + $class=is_object($method[0]) ? $method[0] : $this->invokeClass($method[0]); |
|
| 209 | + $reflect=new \ReflectionMethod($class, $method[1]); |
|
| 210 | 210 | } else { |
| 211 | 211 | // 静态方法 |
| 212 | - $reflect = new \ReflectionMethod($method); |
|
| 212 | + $reflect=new \ReflectionMethod($method); |
|
| 213 | 213 | } |
| 214 | - $args = $this->bindParams($reflect, $vars); |
|
| 214 | + $args=$this->bindParams($reflect, $vars); |
|
| 215 | 215 | return $reflect->invokeArgs(isset($class) ? $class : null, $args); |
| 216 | 216 | } |
| 217 | 217 | |
@@ -247,11 +247,11 @@ discard block |
||
| 247 | 247 | * @param string|\Closure $concrete 要绑定的类或者闭包 |
| 248 | 248 | * @return void |
| 249 | 249 | */ |
| 250 | - public function bind($abstract, $concrete = null) { |
|
| 250 | + public function bind($abstract, $concrete=null) { |
|
| 251 | 251 | if (is_array($abstract)) { |
| 252 | - $this->bind = array_merge($this->bind, $abstract); |
|
| 252 | + $this->bind=array_merge($this->bind, $abstract); |
|
| 253 | 253 | } else { |
| 254 | - $this->bind[$abstract] = $concrete; |
|
| 254 | + $this->bind[$abstract]=$concrete; |
|
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
@@ -12,19 +12,19 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @var array |
| 14 | 14 | */ |
| 15 | - protected static $snakeCache = []; |
|
| 15 | + protected static $snakeCache=[]; |
|
| 16 | 16 | /** |
| 17 | 17 | * The cache of camel-cased words. |
| 18 | 18 | * |
| 19 | 19 | * @var array |
| 20 | 20 | */ |
| 21 | - protected static $camelCache = []; |
|
| 21 | + protected static $camelCache=[]; |
|
| 22 | 22 | /** |
| 23 | 23 | * The cache of studly-cased words. |
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected static $studlyCache = []; |
|
| 27 | + protected static $studlyCache=[]; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * 判断一个字符串是否以给定字符串开始 |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | return static::$camelCache[$value]; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - return static::$camelCache[$value] = lcfirst(static::studly($value)); |
|
| 74 | + return static::$camelCache[$value]=lcfirst(static::studly($value)); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -81,15 +81,15 @@ discard block |
||
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | 83 | public static function studly($value) { |
| 84 | - $key = $value; |
|
| 84 | + $key=$value; |
|
| 85 | 85 | |
| 86 | 86 | if (isset(static::$studlyCache[$key])) { |
| 87 | 87 | return static::$studlyCache[$key]; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
| 90 | + $value=ucwords(str_replace(['-', '_'], ' ', $value)); |
|
| 91 | 91 | |
| 92 | - return static::$studlyCache[$key] = str_replace(' ', '', $value); |
|
| 92 | + return static::$studlyCache[$key]=str_replace(' ', '', $value); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @return string |
| 101 | 101 | */ |
| 102 | 102 | public static function finish($value, $cap) { |
| 103 | - $quoted = preg_quote($cap, '/'); |
|
| 103 | + $quoted=preg_quote($cap, '/'); |
|
| 104 | 104 | |
| 105 | - return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap; |
|
| 105 | + return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | return true; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $pattern = preg_quote($pattern, '#'); |
|
| 120 | + $pattern=preg_quote($pattern, '#'); |
|
| 121 | 121 | |
| 122 | 122 | // Asterisks are translated into zero-or-more regular expression wildcards |
| 123 | 123 | // to make it convenient to check if the strings starts with the given |
| 124 | 124 | // pattern such as "library/*", making any string check convenient. |
| 125 | - $pattern = str_replace('\*', '.*', $pattern); |
|
| 125 | + $pattern=str_replace('\*', '.*', $pattern); |
|
| 126 | 126 | |
| 127 | - return (bool)preg_match('#^' . $pattern . '\z#u', $value); |
|
| 127 | + return (bool) preg_match('#^'.$pattern.'\z#u', $value); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -144,20 +144,20 @@ discard block |
||
| 144 | 144 | * @param string $delimiter |
| 145 | 145 | * @return string |
| 146 | 146 | */ |
| 147 | - public static function snake($value, $delimiter = '_') { |
|
| 148 | - $key = $value; |
|
| 147 | + public static function snake($value, $delimiter='_') { |
|
| 148 | + $key=$value; |
|
| 149 | 149 | |
| 150 | 150 | if (isset(static::$snakeCache[$key][$delimiter])) { |
| 151 | 151 | return static::$snakeCache[$key][$delimiter]; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if (!ctype_lower($value)) { |
| 155 | - $value = preg_replace('/\s+/u', '', $value); |
|
| 155 | + $value=preg_replace('/\s+/u', '', $value); |
|
| 156 | 156 | |
| 157 | - $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); |
|
| 157 | + $value=static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - return static::$snakeCache[$key][$delimiter] = $value; |
|
| 160 | + return static::$snakeCache[$key][$delimiter]=$value; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | * @param string $end |
| 179 | 179 | * @return string |
| 180 | 180 | */ |
| 181 | - public static function limit($value, $limit = 100, $end = '...') { |
|
| 181 | + public static function limit($value, $limit=100, $end='...') { |
|
| 182 | 182 | if (mb_strwidth($value, 'UTF-8') <= $limit) { |
| 183 | 183 | return $value; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end; |
|
| 186 | + return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -194,14 +194,14 @@ discard block |
||
| 194 | 194 | * @param string $end |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - public static function words($value, $words = 100, $end = '...') { |
|
| 198 | - preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $value, $matches); |
|
| 197 | + public static function words($value, $words=100, $end='...') { |
|
| 198 | + preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); |
|
| 199 | 199 | |
| 200 | 200 | if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
| 201 | 201 | return $value; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - return rtrim($matches[0]) . $end; |
|
| 204 | + return rtrim($matches[0]).$end; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @param string|null $default |
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | - public static function parseCallback($callback, $default = null) { |
|
| 224 | + public static function parseCallback($callback, $default=null) { |
|
| 225 | 225 | return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @return bool |
| 234 | 234 | */ |
| 235 | 235 | public static function contains($haystack, $needles) { |
| 236 | - foreach ((array)$needles as $needle) { |
|
| 236 | + foreach ((array) $needles as $needle) { |
|
| 237 | 237 | if ($needle != '' && mb_strpos($haystack, $needle) !== false) { |
| 238 | 238 | return true; |
| 239 | 239 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * @param int $count |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | - public static function plural($value, $count = 2) { |
|
| 251 | + public static function plural($value, $count=2) { |
|
| 252 | 252 | return Pluralizer::plural($value, $count); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -262,12 +262,12 @@ discard block |
||
| 262 | 262 | * @param int $length |
| 263 | 263 | * @return string |
| 264 | 264 | */ |
| 265 | - public static function quickRandom($length = 16) { |
|
| 265 | + public static function quickRandom($length=16) { |
|
| 266 | 266 | if (PHP_MAJOR_VERSION > 5) { |
| 267 | 267 | return static::random($length); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
| 270 | + $pool='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
| 271 | 271 | |
| 272 | 272 | return substr(str_shuffle(str_repeat($pool, $length)), 0, $length); |
| 273 | 273 | } |
@@ -278,15 +278,15 @@ discard block |
||
| 278 | 278 | * @param int $length |
| 279 | 279 | * @return string |
| 280 | 280 | */ |
| 281 | - public static function random($length = 16) { |
|
| 282 | - $string = ''; |
|
| 281 | + public static function random($length=16) { |
|
| 282 | + $string=''; |
|
| 283 | 283 | |
| 284 | - while (($len = strlen($string)) < $length) { |
|
| 285 | - $size = $length - $len; |
|
| 284 | + while (($len=strlen($string)) < $length) { |
|
| 285 | + $size=$length - $len; |
|
| 286 | 286 | |
| 287 | - $bytes = random_bytes($size); |
|
| 287 | + $bytes=random_bytes($size); |
|
| 288 | 288 | |
| 289 | - $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
|
| 289 | + $string.=substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | return $string; |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | public static function replaceArray($search, array $replace, $subject) { |
| 304 | 304 | foreach ($replace as $value) { |
| 305 | - $subject = static::replaceFirst($search, $value, $subject); |
|
| 305 | + $subject=static::replaceFirst($search, $value, $subject); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | return $subject; |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @return string |
| 318 | 318 | */ |
| 319 | 319 | public static function replaceFirst($search, $replace, $subject) { |
| 320 | - $position = strpos($subject, $search); |
|
| 320 | + $position=strpos($subject, $search); |
|
| 321 | 321 | |
| 322 | 322 | if ($position !== false) { |
| 323 | 323 | return substr_replace($subject, $replace, $position, strlen($search)); |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * @return string |
| 336 | 336 | */ |
| 337 | 337 | public static function replaceLast($search, $replace, $subject) { |
| 338 | - $position = strrpos($subject, $search); |
|
| 338 | + $position=strrpos($subject, $search); |
|
| 339 | 339 | |
| 340 | 340 | if ($position !== false) { |
| 341 | 341 | return substr_replace($subject, $replace, $position, strlen($search)); |
@@ -371,19 +371,19 @@ discard block |
||
| 371 | 371 | * @param string $separator |
| 372 | 372 | * @return string |
| 373 | 373 | */ |
| 374 | - public static function slug($title, $separator = '-') { |
|
| 375 | - $title = static::ascii($title); |
|
| 374 | + public static function slug($title, $separator='-') { |
|
| 375 | + $title=static::ascii($title); |
|
| 376 | 376 | |
| 377 | 377 | // Convert all dashes/underscores into separator |
| 378 | - $flip = $separator == '-' ? '_' : '-'; |
|
| 378 | + $flip=$separator == '-' ? '_' : '-'; |
|
| 379 | 379 | |
| 380 | - $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); |
|
| 380 | + $title=preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); |
|
| 381 | 381 | |
| 382 | 382 | // Remove all characters that are not the separator, letters, numbers, or whitespace. |
| 383 | - $title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', mb_strtolower($title)); |
|
| 383 | + $title=preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title)); |
|
| 384 | 384 | |
| 385 | 385 | // Replace all separator characters and whitespace by a single separator |
| 386 | - $title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title); |
|
| 386 | + $title=preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); |
|
| 387 | 387 | |
| 388 | 388 | return trim($title, $separator); |
| 389 | 389 | } |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | */ |
| 397 | 397 | public static function ascii($value) { |
| 398 | 398 | foreach (static::charsArray() as $key => $val) { |
| 399 | - $value = str_replace($val, $key, $value); |
|
| 399 | + $value=str_replace($val, $key, $value); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | return preg_replace('/[^\x20-\x7E]/u', '', $value); |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | return $charsArray; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | - return $charsArray = [ |
|
| 421 | + return $charsArray=[ |
|
| 422 | 422 | '0' => ['°', '₀', '۰'], |
| 423 | 423 | '1' => ['¹', '₁', '۱'], |
| 424 | 424 | '2' => ['²', '₂', '۲'], |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @return string |
| 543 | 543 | */ |
| 544 | 544 | public static function ucfirst($string) { |
| 545 | - return static::upper(static::substr($string, 0, 1)) . static::substr($string, 1); |
|
| 545 | + return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | * @param int|null $length |
| 564 | 564 | * @return string |
| 565 | 565 | */ |
| 566 | - public static function substr($string, $start, $length = null) { |
|
| 566 | + public static function substr($string, $start, $length=null) { |
|
| 567 | 567 | return mb_substr($string, $start, $length, 'UTF-8'); |
| 568 | 568 | } |
| 569 | 569 | } |
| 570 | 570 | \ No newline at end of file |