diff --git a/composer.json b/composer.json index eba42bd..c75622c 100644 --- a/composer.json +++ b/composer.json @@ -18,42 +18,15 @@ ], "require": { "php": ">7.1.0", - "psr/container": "^1.0" + "psr/container": "^1.0", + "toolkit/stdlib": "^1.0" }, "require-dev": { "inhere/console": "dev-master" }, - "replace": { - "toolkit/arr-utils": "self.version", - "toolkit/collection": "self.version", - "toolkit/cli-utils": "self.version", - "toolkit/data-parser": "self.version", - "toolkit/di": "self.version", - "toolkit/file-utils": "self.version", - "toolkit/file-parse": "self.version", - "toolkit/obj-utils": "self.version", - "toolkit/php-utils": "self.version", - "toolkit/str-utils": "self.version", - "toolkit/sys-utils": "self.version", - "toolkit/helper-utils": "self.version" - }, "autoload": { "psr-4": { - "Toolkit\\Dev\\": "libs/dev-helper/", - "Toolkit\\ArrUtil\\": "libs/arr-utils/src/", - "Toolkit\\Collection\\": "libs/collection/src/", - "Toolkit\\Cli\\": "libs/cli-utils/src/", - "Toolkit\\DI\\": "libs/di/src/", - "Toolkit\\DataParser\\": "libs/data-parser/src/", - "Toolkit\\File\\": "libs/file-utils/src/", - "Toolkit\\File\\Parse\\": "libs/file-parse/src/", - "Toolkit\\ObjUtil\\": "libs/obj-utils/src/", - "Toolkit\\PhpUtil\\": "libs/php-utils/src/", - "Toolkit\\StrUtil\\": "libs/str-utils/src/", - "Toolkit\\Sys\\": "libs/sys-utils/src/", - "Toolkit\\Util\\": "libs/helper-utils/src/Util", - "Toolkit\\Helper\\": "libs/helper-utils/src/Helper", - "Toolkit\\Traits\\": "libs/helper-utils/src/Traits" + "Toolkit\\Dev\\": "src/" } }, "scripts": { diff --git a/libs/arr-utils/README.md b/libs/arr-utils/README.md deleted file mode 100644 index c7a50b7..0000000 --- a/libs/arr-utils/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# array utils - -[![License](https://img.shields.io/packagist/l/toolkit/arr-utils.svg?style=flat-square)](LICENSE) -[![Php Version](https://img.shields.io/badge/php-%3E=7.1.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/toolkit/arr-utils) -[![Latest Stable Version](http://img.shields.io/packagist/v/toolkit/arr-utils.svg)](https://packagist.org/packages/toolkit/arr-utils) - -Some useful array utils for php - -## Install - -```bash -composer require toolkit/arr-utils -``` - -## License - -MIT diff --git a/libs/arr-utils/composer.json b/libs/arr-utils/composer.json deleted file mode 100644 index 92e1e00..0000000 --- a/libs/arr-utils/composer.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "toolkit/arr-utils", - "type": "library", - "description": "some array tool library of the php", - "keywords": [ - "library", - "tool", - "php" - ], - "homepage": "https://github.com/php-toolkit/arr-utils", - "license": "MIT", - "authors": [ - { - "name": "inhere", - "email": "in.798@qq.com", - "homepage": "http://www.yzone.net/" - } - ], - "require": { - "php": ">7.1.0" - }, - "autoload": { - "psr-4": { - "Toolkit\\ArrUtil\\": "src/" - } - }, - "suggest": { - "inhere/php-validate": "Very lightweight data validate tool", - "inhere/console": "a lightweight php console application library." - } -} diff --git a/libs/arr-utils/src/Arr.php b/libs/arr-utils/src/Arr.php deleted file mode 100644 index 5cd13cb..0000000 --- a/libs/arr-utils/src/Arr.php +++ /dev/null @@ -1,19 +0,0 @@ -body[] = $content; - } - } - - /** - * @param string $content - */ - public function write(string $content): void - { - $this->body[] = $content; - } - - /** - * @param string $content - */ - public function append(string $content): void - { - $this->write($content); - } - - /** - * @param string $content - */ - public function prepend(string $content): void - { - array_unshift($this->body, $content); - } - - /** - * clear - */ - public function clear(): void - { - $this->body = []; - } - - /** - * @return string[] - */ - public function getBody(): array - { - return $this->body; - } - - /** - * @param string[] $body - */ - public function setBody(array $body): void - { - $this->body = $body; - } - - /** - * @return string - */ - public function toString(): string - { - return implode($this->delimiter, $this->body); - } - - /** - * @return string - */ - public function __toString() - { - return $this->toString(); - } - - /** - * @return string - */ - public function getDelimiter(): string - { - return $this->delimiter; - } - - /** - * @param string $delimiter - */ - public function setDelimiter(string $delimiter): void - { - $this->delimiter = $delimiter; - } -} diff --git a/libs/arr-utils/src/ArrayHelper.php b/libs/arr-utils/src/ArrayHelper.php deleted file mode 100644 index 51c8bae..0000000 --- a/libs/arr-utils/src/ArrayHelper.php +++ /dev/null @@ -1,1105 +0,0 @@ - $value) { - $name = trim($name); - - if (!$name || is_numeric($name)) { - continue; - } - - $object->$name = is_array($value) ? self::toObject($value) : $value; - } - - return $object; - } - - /** - * Get Multi - 获取多个, 可以设置默认值 - * - * @param array $data array data - * @param array $needKeys - * $needKeys = [ - * 'name', - * 'password', - * 'status' => '1' - * ] - * @param bool|false $unsetKey - * - * @return array - */ - public static function gets(array &$data, array $needKeys = [], $unsetKey = false): array - { - $needed = []; - - foreach ($needKeys as $key => $default) { - if (is_int($key)) { - $key = $default; - $default = null; - } - - if (isset($data[$key])) { - $value = $data[$key]; - - if (is_int($default)) { - $value = (int)$value; - } elseif (is_string($default)) { - $value = trim($value); - } elseif (is_array($default)) { - $value = (array)$value; - } - - $needed[$key] = $value; - - if ($unsetKey) { - unset($data[$key]); - } - } else { - $needed[$key] = $default; - } - } - - return $needed; - } - - /** - * 递归合并两个多维数组,后面的值将会递归覆盖原来的值 - * - * @param array|null $src - * @param array $new - * - * @return array - */ - public static function merge($src, array $new): array - { - if (!$src || !is_array($src)) { - return $new; - } - - if (!$new) { - return $src; - } - - foreach ($new as $key => $value) { - if (is_int($key)) { - if (isset($src[$key])) { - $src[] = $value; - } else { - $src[$key] = $value; - } - } elseif (array_key_exists($key, $src) && is_array($value)) { - $src[$key] = self::merge($src[$key], $new[$key]); - } else { - $src[$key] = $value; - } - } - - return $src; - } - - /** - * 递归合并多个多维数组, - * - * @from yii2 - * Merges two or more arrays into one recursively. - * - * @param array $args - * - * @return array the merged array (the original arrays are not changed.) - */ - public static function merge2(...$args): array - { - /** @var array[] $args */ - $res = array_shift($args); - - while (!empty($args)) { - /** @var array $next */ - $next = array_shift($args); - - foreach ($next as $k => $v) { - if (is_int($k)) { - if (isset($res[$k])) { - $res[] = $v; - } else { - $res[$k] = $v; - } - } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) { - $res[$k] = self::merge2($res[$k], $v); - } else { - $res[$k] = $v; - } - } - } - - return $res; - } - - /** - * 清理数组值的空白 - * - * @param array $data - * - * @return array|string - */ - public static function valueTrim(array $data) - { - if (is_scalar($data)) { - return trim($data); - } - - array_walk_recursive($data, function (&$value) { - $value = trim($value); - }); - - return $data; - } - - /** - * 不区分大小写检测数据键名是否存在 - * - * @param int|string $key - * @param array $arr - * - * @return bool - */ - public static function keyExists($key, array $arr): bool - { - return array_key_exists(strtolower($key), array_change_key_case($arr)); - } - - /** - * @param array $arr - * - * @return array - */ - public static function valueToLower(array $arr): array - { - return self::changeValueCase($arr, 0); - } - - /** - * @param array $arr - * - * @return array - */ - public static function valueToUpper(array $arr): array - { - return self::changeValueCase($arr); - } - - /** - * 将数组中的值全部转为大写或小写 - * - * @param array $arr - * @param int $toUpper 1 值大写 0 值小写 - * - * @return array - */ - public static function changeValueCase($arr, $toUpper = 1): array - { - $function = $toUpper ? 'strtoupper' : 'strtolower'; - $newArr = []; //格式化后的数组 - - foreach ($arr as $k => $v) { - if (is_array($v)) { - $newArr[$k] = self::changeValueCase($v, $toUpper); - } else { - $v = trim($v); - $newArr[$k] = $function($v); - } - } - - return $newArr; - } - - /** - * ******* 检查 一个或多个值是否全部存在数组中 ******* - * 有一个不存在即返回 false - * - * @param string|array $check - * @param array $sampleArr 只能检查一维数组 - * 注: 不分类型, 区分大小写 2 == '2' ‘a' != 'A' - * - * @return bool - */ - public static function valueExistsAll($check, array $sampleArr): bool - { - // 以逗号分隔的会被拆开,组成数组 - if (is_string($check)) { - $check = trim($check, ', '); - $check = strpos($check, ',') !== false ? explode(',', $check) : [$check]; - } - - return !array_diff((array)$check, $sampleArr); - } - - /** - * ******* 检查 一个或多个值是否存在数组中 ******* - * 有一个存在就返回 true 都不存在 return false - * - * @param string|array $check - * @param array $sampleArr 只能检查一维数组 - * - * @return bool - */ - public static function valueExistsOne($check, array $sampleArr): bool - { - // 以逗号分隔的会被拆开,组成数组 - if (is_string($check)) { - $check = trim($check, ', '); - $check = strpos($check, ',') !== false ? explode(',', $check) : [$check]; - } - - return (bool)array_intersect((array)$check, $sampleArr); - } - - /** - * ******* 不区分大小写,检查 一个或多个值是否 全存在数组中 ******* - * 有一个不存在即返回 false - * - * @param string|array $need - * @param array $arr 只能检查一维数组 - * @param bool $type 是否同时验证类型 - * - * @return bool | string 不存在的会返回 检查到的 字段,判断时 请使用 ArrHelper::existsAll($need,$arr)===true 来验证是否全存在 - */ - public static function existsAll($need, $arr, $type = false) - { - if (is_array($need)) { - foreach ((array)$need as $v) { - self::existsAll($v, $arr, $type); - } - - } elseif (strpos($need, ',') !== false) { - $need = explode(',', $need); - self::existsAll($need, $arr, $type); - } else { - $arr = self::valueToLower($arr);//小写 - $need = strtolower(trim($need));//小写 - - if (!in_array($need, $arr, $type)) { - return $need; - } - } - - return true; - } - - /** - * ******* 不区分大小写,检查 一个或多个值是否存在数组中 ******* - * 有一个存在就返回 true 都不存在 return false - * - * @param string|array $need - * @param array $arr 只能检查一维数组 - * @param bool $type 是否同时验证类型 - * - * @return bool - */ - public static function existsOne($need, $arr, $type = false): bool - { - if (is_array($need)) { - foreach ((array)$need as $v) { - $result = self::existsOne($v, $arr, $type); - if ($result) { - return true; - } - } - } else { - if (strpos($need, ',') !== false) { - $need = explode(',', $need); - - return self::existsOne($need, $arr, $type); - } - - $arr = self::changeValueCase($arr);//小写 - $need = strtolower($need);//小写 - - if (in_array($need, $arr, $type)) { - return true; - } - } - - return false; - } - - /** - * get key Max Width - * - * @param array $data - * [ - * 'key1' => 'value1', - * 'key2-test' => 'value2', - * ] - * @param bool $expectInt - * - * @return int - */ - public static function getKeyMaxWidth(array $data, $expectInt = true): int - { - $keyMaxWidth = 0; - - foreach ($data as $key => $value) { - // key is not a integer - if (!$expectInt || !is_numeric($key)) { - $width = mb_strlen($key, 'UTF-8'); - $keyMaxWidth = $width > $keyMaxWidth ? $width : $keyMaxWidth; - } - } - - return $keyMaxWidth; - } - - - /** - * Get data from array or object by path. - * Example: `DataCollector::getByPath($array, 'foo.bar.yoo')` equals to $array['foo']['bar']['yoo']. - * - * @param array|ArrayAccess $data An array or object to get value. - * @param mixed $path The key path. - * @param mixed $default - * @param string $separator Separator of paths. - * - * @return mixed Found value, null if not exists. - */ - public static function getByPath($data, string $path, $default = null, string $separator = '.') - { - if (isset($data[$path])) { - return $data[$path]; - } - - // Error: will clear '0'. eg 'some-key.0' - // if (!$nodes = array_filter(explode($separator, $path))) { - if (!$nodes = explode($separator, $path)) { - return $default; - } - - $dataTmp = $data; - - foreach ($nodes as $arg) { - if (is_object($dataTmp) && isset($dataTmp->$arg)) { - $dataTmp = $dataTmp->$arg; - } elseif ((is_array($dataTmp) || $dataTmp instanceof ArrayAccess) && isset($dataTmp[$arg])) { - $dataTmp = $dataTmp[$arg]; - } else { - return $default; - } - } - - return $dataTmp; - } - - /** - * findValueByNodes - * - * @param array $data - * @param array $nodes - * @param mixed $default - * - * @return mixed - */ - public static function getValueByNodes(array $data, array $nodes, $default = null) - { - $temp = $data; - - foreach ($nodes as $name) { - if (isset($temp[$name])) { - $temp = $temp[$name]; - } else { - $temp = $default; - break; - } - } - - return $temp; - } - - /** - * setByPath - * - * @param array|ArrayAccess &$data - * @param string $path - * @param mixed $value - * @param string $separator - */ - public static function setByPath(&$data, string $path, $value, string $separator = '.'): void - { - if (false === strpos($path, $separator)) { - $data[$path] = $value; - return; - } - - if (!$nodes = array_filter(explode($separator, $path))) { - return; - } - - $dataTmp = &$data; - - foreach ($nodes as $node) { - if (is_array($dataTmp)) { - if (empty($dataTmp[$node])) { - $dataTmp[$node] = []; - } - - $dataTmp = &$dataTmp[$node]; - } else { - // If a node is value but path is not go to the end, we replace this value as a new store. - // Then next node can insert new value to this store. - $dataTmp = []; - } - } - - // Now, path go to the end, means we get latest node, set value to this node. - $dataTmp = $value; - } - - //////////////////////////////////////////////////////////// - /// from laravel - //////////////////////////////////////////////////////////// - - /** - * Collapse an array of arrays into a single array. - * - * @param array $array - * - * @return array - */ - public static function collapse(array $array): array - { - $results = []; - - foreach ($array as $values) { - if ($values instanceof CollectionInterface) { - $values = $values->all(); - } elseif (!is_array($values)) { - continue; - } - - // $results = \array_merge($results, $values); - $results[] = $values; - } - - return array_merge(...$results); - } - - /** - * Cross join the given arrays, returning all possible permutations. - * - * @param array ...$arrays - * - * @return array - */ - public static function crossJoin(...$arrays): array - { - return array_reduce($arrays, function ($results, $array) { - return static::collapse(array_map(function ($parent) use ($array) { - return array_map(function ($item) use ($parent) { - return array_merge($parent, [$item]); - }, $array); - }, $results)); - }, [[]]); - } - - /** - * Divide an array into two arrays. One with keys and the other with values. - * - * @param array $array - * - * @return array - */ - public static function divide($array): array - { - return [array_keys($array), array_values($array)]; - } - - /** - * Flatten a multi-dimensional associative array with dots. - * - * @param array $array - * @param string $prepend - * - * @return array - */ - public static function dot(array $array, string $prepend = ''): array - { - $results = []; - - foreach ($array as $key => $value) { - if (is_array($value) && !empty($value)) { - $results = array_merge($results, static::dot($value, $prepend . $key . '.')); - } else { - $results[$prepend . $key] = $value; - } - } - - return $results; - } - - /** - * Get all of the given array except for a specified array of items. - * - * @param array $array - * @param array|string $keys - * - * @return array - */ - public static function except(array $array, $keys): array - { - static::forget($array, $keys); - - return $array; - } - - /** - * Determine if the given key exists in the provided array. - * - * @param ArrayAccess|array $array - * @param string|int $key - * - * @return bool - */ - public static function exists(array $array, $key): bool - { - if ($array instanceof ArrayAccess) { - return $array->offsetExists($key); - } - - return array_key_exists($key, $array); - } - - /** - * Add an element to an array using "dot" notation if it doesn't exist. - * - * @param array $array - * @param string $key - * @param mixed $value - * - * @return array - */ - public static function add(array $array, $key, $value): array - { - if (static::has($array, $key)) { - static::set($array, $key, $value); - } - - return $array; - } - - /** - * Get an item from an array using "dot" notation. - * - * @param ArrayAccess|array $array - * @param string $key - * @param mixed $default - * - * @return mixed - */ - public static function get($array, $key, $default = null) - { - if (!static::accessible($array)) { - return value($default); - } - - if (null === $key) { - return $array; - } - - if (static::exists($array, $key)) { - return $array[$key]; - } - - foreach (explode('.', $key) as $segment) { - if (static::accessible($array) && static::exists($array, $segment)) { - $array = $array[$segment]; - } else { - return value($default); - } - } - - return $array; - } - - /** - * Set an array item to a given value using "dot" notation. - * If no key is given to the method, the entire array will be replaced. - * - * @param array $array - * @param string $key - * @param mixed $value - * - * @return array - */ - public static function set(array &$array, $key, $value): array - { - if (null === $key) { - return ($array = $value); - } - - $keys = explode('.', $key); - - while (count($keys) > 1) { - $key = array_shift($keys); - // If the key doesn't exist at this depth, we will just create an empty array - // to hold the next value, allowing us to create the arrays to hold final - // values at the correct depth. Then we'll keep digging into the array. - if (!isset($array[$key]) || !is_array($array[$key])) { - $array[$key] = []; - } - - $array = &$array[$key]; - } - - $array[array_shift($keys)] = $value; - - return $array; - } - - /** - * Flatten a multi-dimensional array into a single level. - * - * @param array $array - * @param int $depth - * - * @return array - */ - public static function flatten($array, $depth = INF): array - { - return array_reduce($array, function ($result, $item) use ($depth) { - $item = $item instanceof CollectionInterface ? $item->all() : $item; - - if (!is_array($item)) { - return array_merge($result, [$item]); - } - - if ($depth === 1) { - return array_merge($result, array_values($item)); - } - - return array_merge($result, static::flatten($item, $depth - 1)); - }, []); - } - - /** - * Remove one or many array items from a given array using "dot" notation. - * - * @param array $array - * @param array|string $keys - * - * @return void - */ - public static function forget(&$array, $keys): void - { - $original = &$array; - $keys = (array)$keys; - - if (count($keys) === 0) { - return; - } - - foreach ($keys as $key) { - - // if the exact key exists in the top-level, remove it - if (static::exists($array, $key)) { - unset($array[$key]); - continue; - } - - $parts = explode('.', $key); - - // clean up before each pass - $array = &$original; - - while (count($parts) > 1) { - $part = array_shift($parts); - - if (isset($array[$part]) && is_array($array[$part])) { - $array = &$array[$part]; - } else { - continue 2; - } - } - - unset($array[array_shift($parts)]); - } - } - - /** - * Check if an item or items exist in an array using "dot" notation. - * - * @param ArrayAccess|array $array - * @param string|array $keys - * - * @return bool - */ - public static function has($array, $keys): bool - { - if (null === $keys) { - return false; - } - - $keys = (array)$keys; - - if (!$array) { - return false; - } - - if ($keys === []) { - return false; - } - - foreach ($keys as $key) { - $subKeyArray = $array; - - if (static::exists($array, $key)) { - continue; - } - - foreach (explode('.', $key) as $segment) { - if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) { - $subKeyArray = $subKeyArray[$segment]; - } else { - - return false; - } - } - } - - return true; - } - - /** - * Push an item onto the beginning of an array. - * - * @param array $array - * @param mixed $value - * @param mixed $key - * - * @return array - */ - public static function prepend($array, $value, $key = null): array - { - if (null === $key) { - array_unshift($array, $value); - } else { - $array = [$key => $value] + $array; - } - - return $array; - } - - /** - * remove the $key of the $arr, and return value. - * - * @param string $key - * @param array $arr - * @param mixed $default - * - * @return mixed - */ - public static function remove(&$arr, $key, $default = null) - { - if (isset($arr[$key])) { - $value = $arr[$key]; - unset($arr[$key]); - } else { - $value = $default; - } - - return $value; - } - - /** - * Get a value from the array, and remove it. - * - * @param array $array - * @param string $key - * @param mixed $default - * - * @return mixed - */ - public static function pull(&$array, $key, $default = null) - { - $value = static::get($array, $key, $default); - - static::forget($array, $key); - - return $value; - } - - /** - * Get a subset of the items from the given array. - * - * @param array $array - * @param array|string $keys - * - * @return array - */ - public static function only($array, $keys): array - { - return array_intersect_key($array, array_flip((array)$keys)); - } - - /** - * Shuffle the given array and return the result. - * - * @param array $array - * - * @return array - */ - public static function shuffle($array): array - { - shuffle($array); - - return $array; - } - - /** - * Filter the array using the given callback. - * - * @param array $array - * @param callable $callback - * - * @return array - */ - public static function where($array, callable $callback): array - { - return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH); - } - - /** - * If the given value is not an array, wrap it in one. - * - * @param mixed $value - * - * @return array - */ - public static function wrap($value): array - { - return !is_array($value) ? (array)$value : $value; - } - - //////////////////////////////////////////////////////////// - /// other - //////////////////////////////////////////////////////////// - - /** - * array 递归 转换成 字符串 - * - * @param array $array [大于1200字符 strlen($string)>1200 - * @param int $length - * @param array|int $cycles [至多循环六次 $num >= 6 - * @param bool $showKey - * @param bool $addMark - * @param string $separator - * @param string $string - * - * @return string - */ - public static function toString( - $array, - $length = 800, - $cycles = 6, - $showKey = true, - $addMark = false, - $separator = ', ', - $string = '' - ): string { - if (!is_array($array) || empty($array)) { - return ''; - } - - $mark = $addMark ? '\'' : ''; - $num = 0; - - foreach ($array as $key => $value) { - $num++; - - if ($num >= $cycles || strlen($string) > (int)$length) { - $string .= '... ...'; - break; - } - - $keyStr = $showKey ? $key . '=>' : ''; - - if (is_array($value)) { - $string .= $keyStr . 'Array(' . self::toString($value, $length, $cycles, $showKey, $addMark, $separator, - $string) . ')' . $separator; - } elseif (is_object($value)) { - $string .= $keyStr . 'Object(' . get_class($value) . ')' . $separator; - } elseif (is_resource($value)) { - $string .= $keyStr . 'Resource(' . get_resource_type($value) . ')' . $separator; - } else { - $value = strlen($value) > 150 ? substr($value, 0, 150) : $value; - $string .= $mark . $keyStr . trim(htmlspecialchars($value)) . $mark . $separator; - } - } - - return trim($string, $separator); - } - - public static function toStringNoKey( - $array, - $length = 800, - $cycles = 6, - $showKey = false, - $addMark = true, - $separator = ', ' - ): string { - return static::toString($array, $length, $cycles, $showKey, $addMark, $separator); - } - - /** - * @param array $array - * @param int $length - * - * @return mixed|null|string|string[] - */ - public static function toFormatString($array, $length = 400) - { - $string = var_export($array, true); - - # 将非空格替换为一个空格 - $string = preg_replace('/[\n\r\t]/', ' ', $string); - # 去掉两个空格以上的 - $string = preg_replace('/\s(?=\s)/', '', $string); - $string = trim($string); - - if (strlen($string) > $length) { - $string = substr($string, 0, $length) . '...'; - } - - return $string; - } - - public static function toLimitOut($array): array - { - if (!is_array($array)) { - return $array; - } - - // static $num = 1; - - foreach ($array as $key => $value) { - // if ( $num >= $cycles) { - // break; - // } - - if (is_array($value) || is_object($value)) { - $value = gettype($value) . '(...)'; - } elseif (is_string($value) || is_numeric($value)) { - $value = strlen(trim($value)); - } else { - $value = gettype($value) . "($value)"; - } - - $array[$key] = $value; - } - - // $num++; - - return $array; - } - -} diff --git a/libs/arr-utils/src/FixedArray.php b/libs/arr-utils/src/FixedArray.php deleted file mode 100644 index 67aa6d1..0000000 --- a/libs/arr-utils/src/FixedArray.php +++ /dev/null @@ -1,219 +0,0 @@ - 'int:value index' - * ] - */ - protected $keys; - - /** - * @var SplFixedArray - */ - protected $values; - - /** - * FixedArray constructor. - * - * @param int $size - */ - public function __construct(int $size = 0) - { - $this->keys = []; - $this->values = new SplFixedArray($size); - } - - /** - * reset - * - * @param int $size - */ - public function reset(int $size = 0) - { - $this->keys = []; - $this->values = new SplFixedArray($size); - } - - /** - * @param string $key - * - * @return bool - */ - public function __isset(string $key) - { - return $this->offsetExists($key); - } - - /** - * @param string $key - * @param mixed $value - */ - public function __set(string $key, $value) - { - $this->offsetSet($key, $value); - } - - /** - * @param string $key - * - * @return mixed - */ - public function __get(string $key) - { - return $this->offsetGet($key); - } - - /** - * @return int - */ - public function getSize(): int - { - return $this->values->getSize(); - } - - /** - * @param $key - * - * @return int - */ - public function getKeyIndex($key): int - { - return $this->keys[$key] ?? -1; - } - - /** - * @return array - */ - public function getKeys(): array - { - return $this->keys; - } - - /** - * @param array $keys - */ - public function setKeys(array $keys) - { - $this->keys = $keys; - } - - /** - * @return SplFixedArray - */ - public function getValues(): SplFixedArray - { - return $this->values; - } - - /** - * @param SplFixedArray $values - */ - public function setValues(SplFixedArray $values) - { - $this->values = $values; - } - - /** - * Defined by IteratorAggregate interface - * Returns an iterator for this object, for use with foreach - * - * @return SplFixedArray - */ - public function getIterator(): SplFixedArray - { - return $this->values; - } - - /** - * Checks whether an offset exists in the iterator. - * - * @param mixed $offset The array offset. - * - * @return boolean True if the offset exists, false otherwise. - */ - public function offsetExists($offset): bool - { - return isset($this->keys[$offset]); - } - - /** - * Gets an offset in the iterator. - * - * @param mixed $offset The array offset. - * - * @return mixed The array value if it exists, null otherwise. - */ - public function offsetGet($offset) - { - $index = $this->getKeyIndex($offset); - - if ($index >= 0) { - return $this->values[$index]; - } - - return null; - } - - /** - * Sets an offset in the iterator. - * - * @param mixed $offset The array offset. - * @param mixed $value The array value. - * - * @return void - */ - public function offsetSet($offset, $value): void - { - $index = $this->getSize(); - - // change size. - if ($index <= count($this->keys)) { - $this->values->setSize($index + 10); - } - - $this->values[$index] = $value; - $this->keys[$offset] = $index; - } - - /** - * Unset an offset in the iterator. - * - * @param mixed $offset The array offset. - * - * @return void - */ - public function offsetUnset($offset): void - { - $index = $this->getKeyIndex($offset); - - if ($index >= 0) { - // change size. - $this->values->setSize($index - 1); - - unset($this->keys[$offset], $this->values[$index]); - } - } -} diff --git a/libs/arr-utils/test/boot.php b/libs/arr-utils/test/boot.php deleted file mode 100644 index 96a1e68..0000000 --- a/libs/arr-utils/test/boot.php +++ /dev/null @@ -1,27 +0,0 @@ -highlight(file_get_contents(__FILE__)); - -\Toolkit\Cli\Cli::write($rendered); -``` - -![colors](./example/cli-php-file-highlight.jpg) - -## Console color - -![colors](./example/all-color-style.jpg) - -## Cli downloader - -```php -use Toolkit\Cli\Download; - -$url = 'http://no2.php.net/distributions/php-7.2.5.tar.bz2'; -$down = Download::file($url, ''); - -// $down->setShowType('bar'); -$down->start(); -``` - -### progress bar output: - -```text -Connected... -Mime-type: text/html; charset=utf-8 -Being redirected to: http://no2.php.net/distributions/php-7.2.5.tar.bz2 -Connected... -FileSize: 14280 kb -Mime-type: application/octet-stream -[========================================> ] 40% (3076/7590 kb) -``` - -### progress text output: - -```text -Download: http://no2.php.net/distributions/php-7.2.5.tar.bz2 -Save As: /path/to/php-7.2.5.tar.bz2 - -Connected ... -Got the file size: 14280 kb -Found the mime-type: application/octet-stream -Made some progress, downloaded 641 kb so far -``` - -## License - -MIT diff --git a/libs/cli-utils/composer.json b/libs/cli-utils/composer.json deleted file mode 100644 index 9b49241..0000000 --- a/libs/cli-utils/composer.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "toolkit/cli-utils", - "type": "library", - "description": "some cli tool library of the php", - "keywords": [ - "library", - "tool", - "php" - ], - "homepage": "https://github.com/php-toolkit/cli-utils", - "license": "MIT", - "authors": [ - { - "name": "inhere", - "email": "in.798@qq.com", - "homepage": "http://www.yzone.net/" - } - ], - "require": { - "php": ">7.1.0" - }, - "autoload": { - "psr-4": { - "Toolkit\\Cli\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Toolkit\\CliTest\\": "src/" - } - }, - "suggest": { - "inhere/php-validate": "Very lightweight data validate tool", - "inhere/console": "a lightweight php console application library." - } -} diff --git a/libs/cli-utils/example/all-color-style.jpg b/libs/cli-utils/example/all-color-style.jpg deleted file mode 100644 index 850acae..0000000 Binary files a/libs/cli-utils/example/all-color-style.jpg and /dev/null differ diff --git a/libs/cli-utils/example/cli-php-file-highlight.jpg b/libs/cli-utils/example/cli-php-file-highlight.jpg deleted file mode 100644 index 4084e44..0000000 Binary files a/libs/cli-utils/example/cli-php-file-highlight.jpg and /dev/null differ diff --git a/libs/cli-utils/example/color.php b/libs/cli-utils/example/color.php deleted file mode 100644 index 0a8058e..0000000 --- a/libs/cli-utils/example/color.php +++ /dev/null @@ -1,15 +0,0 @@ -getOpt('type', 'text'); - -if ($type === 'bar') { - $down->setShowType($type); -} - -$down->start(); diff --git a/libs/cli-utils/example/high.php b/libs/cli-utils/example/high.php deleted file mode 100644 index ae5b5a5..0000000 --- a/libs/cli-utils/example/high.php +++ /dev/null @@ -1,19 +0,0 @@ -highlight(file_get_contents(__FILE__)); - -Cli::write($rendered); diff --git a/libs/cli-utils/example/liteApp b/libs/cli-utils/example/liteApp deleted file mode 100644 index 2855582..0000000 --- a/libs/cli-utils/example/liteApp +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env php -addCommand('test', function ($app) { - echo "args:\n"; - /** @var Toolkit\Cli\App $app */ - print_r($app->getArgs()); - -}, 'the description text for the command: test'); - -$app->addCommand('test1', function () { - echo "hello\n"; -}, 'the description text for the command: test1'); - -// run -$app->run(); diff --git a/libs/cli-utils/src/App.php b/libs/cli-utils/src/App.php deleted file mode 100644 index 97596d5..0000000 --- a/libs/cli-utils/src/App.php +++ /dev/null @@ -1,579 +0,0 @@ - '', - 'usage' => '', - 'help' => '', - ]; - - /** @var string Current dir */ - private $pwd; - - /** - * @var array Parsed from `arg0 name=val var2=val2` - */ - private $args = []; - - /** - * @var array Parsed from `--name=val --var2=val2 -d` - */ - private $opts = []; - - /** - * @var string - */ - private $script; - - /** - * @var string - */ - private $command = ''; - - /** - * @var array User add commands - */ - private $commands = []; - - /** - * @var array Command messages for the commands - */ - private $messages = []; - - /** - * @var int - */ - private $keyWidth = 12; - - /** - * Class constructor. - * - * @param array|null $argv - */ - public function __construct(array $argv = null) - { - // get current dir - $this->pwd = getcwd(); - - // parse cli argv - $argv = $argv ?? (array)$_SERVER['argv']; - - // get script file - $this->script = array_shift($argv); - - // parse flags - [$this->args, $this->opts] = Flags::parseArgv($argv, [ - 'mergeOpts' => true - ]); - } - - /** - * @param bool $exit - * - * @throws InvalidArgumentException - */ - public function run(bool $exit = true): void - { - $this->findCommand(); - - $this->dispatch($exit); - } - - /** - * find command name. it is first argument. - */ - protected function findCommand(): void - { - if (!isset($this->args[0])) { - return; - } - - $newArgs = []; - - foreach ($this->args as $key => $value) { - if ($key === 0) { - $this->command = trim($value); - } elseif (is_int($key)) { - $newArgs[] = $value; - } else { - $newArgs[$key] = $value; - } - } - - $this->args = $newArgs; - } - - /** - * @param bool $exit - * - * @throws InvalidArgumentException - */ - public function dispatch(bool $exit = true): void - { - if (!$command = $this->command) { - $this->displayHelp(); - return; - } - - if (!isset($this->commands[$command])) { - $this->displayHelp("The command '{$command}' is not exists!"); - return; - } - - if (isset($this->opts['h']) || isset($this->opts['help'])) { - $this->displayCommandHelp($command); - return; - } - - try { - $status = $this->runHandler($command, $this->commands[$command]); - } catch (Throwable $e) { - $status = $this->handleException($e); - } - - if ($exit) { - $this->stop($status); - } - } - - /** - * @param int $code - */ - public function stop($code = 0): void - { - exit((int)$code); - } - - /** - * @param string $command - * @param $handler - * - * @return mixed - * @throws InvalidArgumentException - */ - public function runHandler(string $command, $handler) - { - if (is_string($handler)) { - // function name - if (function_exists($handler)) { - return $handler($this); - } - - if (class_exists($handler)) { - $handler = new $handler; - - // $handler->execute() - if (method_exists($handler, 'execute')) { - return $handler->execute($this); - } - } - } - - // a \Closure OR $handler->__invoke() - if (is_object($handler) && method_exists($handler, '__invoke')) { - return $handler($this); - } - - throw new RuntimeException("Invalid handler of the command: $command"); - } - - /** - * @param Throwable $e - * - * @return int - */ - protected function handleException(Throwable $e): int - { - if ($e instanceof InvalidArgumentException) { - Color::println('ERROR: ' . $e->getMessage(), 'error'); - return 0; - } - - $code = $e->getCode() !== 0 ? $e->getCode() : -1; - $eTpl = "Exception(%d): %s\nFile: %s(Line %d)\nTrace:\n%s\n"; - - // print exception message - printf($eTpl, $code, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()); - - return $code; - } - - /** - * @param callable $handler - * @param array $config - */ - public function addByConfig(callable $handler, array $config): void - { - $this->addCommand($config['name'], $handler, $config); - } - - /** - * @param string $command - * @param callable $handler - * @param null|array|string $config - */ - public function add(string $command, callable $handler, $config = null): void - { - $this->addCommand($command, $handler, $config); - } - - /** - * @param string $command - * @param callable $handler - * @param null|array|string $config - */ - public function addCommand(string $command, callable $handler, $config = null): void - { - if (!$command || !$handler) { - throw new InvalidArgumentException('Invalid arguments for add command'); - } - - if (($len = strlen($command)) > $this->keyWidth) { - $this->keyWidth = $len; - } - - $this->commands[$command] = $handler; - - if (is_string($config)) { - $desc = trim($config); - $config = self::COMMAND_CONFIG; - - // append desc - $config['desc'] = $desc; - - // save - $this->messages[$command] = $config; - } elseif (is_array($config)) { - $this->messages[$command] = array_merge(self::COMMAND_CONFIG, $config); - } - } - - /** - * @param array $commands - * - * @throws InvalidArgumentException - */ - public function commands(array $commands): void - { - foreach ($commands as $command => $handler) { - $desc = ''; - - if (is_array($handler)) { - $conf = array_values($handler); - $handler = $conf[0]; - $desc = $conf[1] ?? ''; - } - - $this->addCommand($command, $handler, $desc); - } - } - - /**************************************************************************** - * helper methods - ****************************************************************************/ - - /** - * @param string $err - */ - public function displayHelp(string $err = ''): void - { - if ($err) { - echo Color::render("ERROR: $err\n\n"); - } - - // help - $len = $this->keyWidth; - $help = "Welcome to the Lite Console Application.\n\nAvailable Commands:\n"; - $data = $this->messages; - ksort($data); - - foreach ($data as $command => $item) { - $command = str_pad($command, $len, ' '); - $desc = $item['desc'] ? ucfirst($item['desc']) : 'No description for the command'; - $help .= " $command $desc\n"; - } - - echo Color::render($help) . PHP_EOL; - exit(0); - } - - /** - * @param string $name - */ - public function displayCommandHelp(string $name): void - { - $checkVar = false; - $fullCmd = $this->script . " $name"; - - $config = $this->messages[$name] ?? []; - $usage = "$fullCmd [args ...] [--opts ...]"; - - if (!$config) { - $nodes = [ - 'No description for the command', - "Usage: \n $usage" - ]; - } else { - $checkVar = true; - $userHelp = $config['help']; - - $nodes = [ - ucfirst($config['desc']), - "Usage: \n " . ($config['usage'] ?: $usage), - $userHelp ? $userHelp . "\n" : '' - ]; - } - - $help = implode("\n", $nodes); - - if ($checkVar && strpos($help, '{{')) { - $help = strtr($help, [ - '{{command}}' => $name, - '{{fullCmd}}' => $fullCmd, - '{{workDir}}' => $this->pwd, - '{{pwdDir}}' => $this->pwd, - '{{script}}' => $this->script, - ]); - } - - echo Color::render($help); - } - - /** - * @param string|int $name - * @param mixed $default - * - * @return mixed|null - */ - public function getArg($name, $default = null) - { - return $this->args[$name] ?? $default; - } - - /** - * @param string|int $name - * @param int $default - * - * @return int - */ - public function getIntArg($name, int $default = 0): int - { - return (int)$this->getArg($name, $default); - } - - /** - * @param string|int $name - * @param string $default - * - * @return string - */ - public function getStrArg($name, string $default = ''): string - { - return (string)$this->getArg($name, $default); - } - - /** - * @param string $name - * @param mixed $default - * - * @return mixed|null - */ - public function getOpt(string $name, $default = null) - { - return $this->opts[$name] ?? $default; - } - - /** - * @param string $name - * @param int $default - * - * @return int - */ - public function getIntOpt(string $name, int $default = 0): int - { - return (int)$this->getOpt($name, $default); - } - - /** - * @param string $name - * @param string $default - * - * @return string - */ - public function getStrOpt(string $name, string $default = ''): string - { - return (string)$this->getOpt($name, $default); - } - - /** - * @param string $name - * @param bool $default - * - * @return bool - */ - public function getBoolOpt(string $name, bool $default = false): bool - { - return (bool)$this->getOpt($name, $default); - } - - /**************************************************************************** - * getter/setter methods - ****************************************************************************/ - - /** - * @return array - */ - public function getArgs(): array - { - return $this->args; - } - - /** - * @param array $args - */ - public function setArgs(array $args): void - { - $this->args = $args; - } - - /** - * @return array - */ - public function getOpts(): array - { - return $this->opts; - } - - /** - * @param array $opts - */ - public function setOpts(array $opts): void - { - $this->opts = $opts; - } - - /** - * @return string - */ - public function getScript(): string - { - return $this->script; - } - - /** - * @param string $script - */ - public function setScript(string $script): void - { - $this->script = $script; - } - - /** - * @return string - */ - public function getCommand(): string - { - return $this->command; - } - - /** - * @param string $command - */ - public function setCommand(string $command): void - { - $this->command = $command; - } - - /** - * @return array - */ - public function getCommands(): array - { - return $this->commands; - } - - /** - * @param array $commands - */ - public function setCommands(array $commands): void - { - $this->commands = $commands; - } - - /** - * @return array - */ - public function getMessages(): array - { - return $this->messages; - } - - /** - * @param array $messages - */ - public function setMessages(array $messages): void - { - $this->messages = $messages; - } - - /** - * @return int - */ - public function getKeyWidth(): int - { - return $this->keyWidth; - } - - /** - * @param int $keyWidth - */ - public function setKeyWidth(int $keyWidth): void - { - $this->keyWidth = $keyWidth > 1 ? $keyWidth : 12; - } - - /** - * @return string - */ - public function getPwd(): string - { - return $this->pwd; - } - -} diff --git a/libs/cli-utils/src/Cli.php b/libs/cli-utils/src/Cli.php deleted file mode 100644 index d6ba2d0..0000000 --- a/libs/cli-utils/src/Cli.php +++ /dev/null @@ -1,266 +0,0 @@ - 'info', - 'warn' => 'warning', - 'warning' => 'warning', - 'debug' => 'cyan', - 'notice' => 'notice', - 'error' => 'error', - ]; - - /******************************************************************************* - * read/write message - ******************************************************************************/ - - /** - * @param string $message - * @param bool $nl - * - * @return string - */ - public static function read(string $message = '', bool $nl = false): string - { - if ($message) { - self::write($message, $nl); - } - - return trim(fgets(STDIN)); - } - - /** - * @param string $format - * @param mixed ...$args - */ - public static function writef(string $format, ...$args): void - { - self::write(sprintf($format, ...$args)); - } - - /** - * Write message to console - * - * @param string|array $messages - * @param bool $nl - * @param bool|int $quit - */ - public static function write($messages, bool $nl = true, $quit = false): void - { - if (is_array($messages)) { - $messages = implode($nl ? PHP_EOL : '', $messages); - } - - self::stdout(Color::parseTag($messages), $nl, $quit); - } - - /** - * Logs data to stdout - * - * @param string $message - * @param bool $nl - * @param bool|int $quit - */ - public static function stdout(string $message, bool $nl = true, $quit = false): void - { - fwrite(STDOUT, $message . ($nl ? PHP_EOL : '')); - fflush(STDOUT); - - if (($isTrue = true === $quit) || is_int($quit)) { - $code = $isTrue ? 0 : $quit; - exit($code); - } - } - - /** - * Logs data to stderr - * - * @param string $message - * @param bool $nl - * @param bool|int $quit - */ - public static function stderr(string $message, $nl = true, $quit = -1): void - { - fwrite(STDERR, self::color('[ERROR] ', 'red') . $message . ($nl ? PHP_EOL : '')); - fflush(STDOUT); - - if (($isTrue = true === $quit) || is_int($quit)) { - $code = $isTrue ? 0 : $quit; - exit($code); - } - } - - /******************************************************************************* - * color render - ******************************************************************************/ - - /** - * @param $text - * @param string|int|array $style - * - * @return string - */ - public static function color(string $text, $style = null): string - { - return Color::render($text, $style); - } - - /** - * print log to console - * - * @param string $msg - * @param array $data - * @param string $type - * @param array $opts - * [ - * '_category' => 'application', - * 'process' => 'work', - * 'pid' => 234, - * 'coId' => 12, - * ] - */ - public static function log(string $msg, array $data = [], string $type = 'info', array $opts = []): void - { - if (isset(self::LOG_LEVEL2TAG[$type])) { - $type = ColorTag::add(strtoupper($type), self::LOG_LEVEL2TAG[$type]); - } - - $userOpts = []; - - foreach ($opts as $n => $v) { - if (is_numeric($n) || strpos($n, '_') === 0) { - $userOpts[] = "[$v]"; - } else { - $userOpts[] = "[$n:$v]"; - } - } - - $optString = $userOpts ? ' ' . implode(' ', $userOpts) : ''; - $dataString = $data ? PHP_EOL . json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) : ''; - - self::writef('%s [%s]%s %s %s', date('Y/m/d H:i:s'), $type, $optString, trim($msg), $dataString); - } - - /******************************************************************************* - * some helpers - ******************************************************************************/ - - /** - * @return bool - */ - public static function supportColor(): bool - { - return self::isSupportColor(); - } - - /** - * Returns true if STDOUT supports colorization. - * This code has been copied and adapted from - * \Symfony\Component\Console\Output\OutputStream. - * - * @return boolean - */ - public static function isSupportColor(): bool - { - if (DIRECTORY_SEPARATOR === '\\') { - return '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD || - false !== getenv('ANSICON') || - 'ON' === getenv('ConEmuANSI') || - 'xterm' === getenv('TERM')// || 'cygwin' === getenv('TERM') - ; - } - - if (!defined('STDOUT')) { - return false; - } - - return self::isInteractive(STDOUT); - } - - /** - * @return bool - */ - public static function isSupport256Color(): bool - { - return DIRECTORY_SEPARATOR === '/' && strpos(getenv('TERM'), '256color') !== false; - } - - /** - * @return bool - */ - public static function isAnsiSupport(): bool - { - if (DIRECTORY_SEPARATOR === '\\') { - return getenv('ANSICON') === true || getenv('ConEmuANSI') === 'ON'; - } - - return true; - } - - /** - * Returns if the file descriptor is an interactive terminal or not. - * - * @param int|resource $fileDescriptor - * - * @return boolean - */ - public static function isInteractive($fileDescriptor): bool - { - /** @noinspection PhpComposerExtensionStubsInspection */ - return function_exists('posix_isatty') && @posix_isatty($fileDescriptor); - } - - /** - * clear Ansi Code - * - * @param string $string - * - * @return string - */ - public static function stripAnsiCode(string $string): string - { - return preg_replace('/\033\[[\d;?]*\w/', '', $string); - } -} diff --git a/libs/cli-utils/src/Color.php b/libs/cli-utils/src/Color.php deleted file mode 100644 index c583648..0000000 --- a/libs/cli-utils/src/Color.php +++ /dev/null @@ -1,340 +0,0 @@ - '0;31', - 'blue' => '0;34', - 'cyan' => '0;36', - 'black' => '0;30', - 'green' => '0;32', - 'brown' => '0;33', - 'white' => '1;37', - 'normal' => '39',// no color - 'yellow' => '1;33', - 'magenta' => '1;35', - - // alert - 'suc' => '1;32',// same 'green' and 'bold' - 'success' => '1;32', - 'info' => '0;32',// same 'green' - 'comment' => '0;33',// same 'brown' - 'note' => '36;1', - 'notice' => '36;4', - 'warn' => '0;30;43', - 'warning' => '0;30;43', - 'danger' => '0;31',// same 'red' - 'err' => '97;41', - 'error' => '97;41', - - // more - 'lightRed' => '1;31', - 'light_red' => '1;31', - 'lightGreen' => '1;32', - 'light_green' => '1;32', - 'lightBlue' => '1;34', - 'light_blue' => '1;34', - 'lightCyan' => '1;36', - 'light_cyan' => '1;36', - 'lightDray' => '37', - 'light_gray' => '37', - - 'darkDray' => '90', - 'dark_gray' => '90', - 'lightYellow' => '93', - 'light_yellow' => '93', - 'lightMagenta' => '95', - 'light_magenta' => '95', - - // extra - 'lightRedEx' => '91', - 'light_red_ex' => '91', - 'lightGreenEx' => '92', - 'light_green_ex' => '92', - 'lightBlueEx' => '94', - 'light_blue_ex' => '94', - 'lightCyanEx' => '96', - 'light_cyan_ex' => '96', - 'whiteEx' => '97', - 'white_ex' => '97', - - // option - 'bold' => '1', - 'underscore' => '4', - 'reverse' => '7', - ]; - - // Regex to match color tags - public const COLOR_TAG = '/<([a-z=;]+)>(.*?)<\/\\1>/s'; - - // CLI color template - public const COLOR_TPL = "\033[%sm%s\033[0m"; - - /** - * @param string $method - * @param array $args - * - * @return string - */ - public static function __callStatic(string $method, array $args) - { - if (isset(self::STYLES[$method])) { - return self::render($args[0], $method); - } - - return ''; - } - - /** - * Apply style for text - * - * @param string $style - * @param string $text - * - * @return string - */ - public static function apply(string $style, string $text): string - { - return self::render($text, $style); - } - - /** - * Format and print to STDOUT - * - * @param string $format - * @param mixed ...$args - */ - public static function printf(string $format, ...$args): void - { - echo self::render(sprintf($format, ...$args)); - } - - /** - * Print colored message to STDOUT - * - * @param string|array $messages - * @param string $style - */ - public static function println($messages, string $style = 'info'): void - { - $string = is_array($messages) ? implode("\n", $messages) : (string)$messages; - - echo self::render($string . "\n", $style); - } - - /******************************************************************************* - * color render - ******************************************************************************/ - - /** - * Render text, apply color code - * - * @param string $text - * @param string|array $style - * - string: 'green', 'blue' - * - array: [Color::FG_GREEN, Color::BG_WHITE, Color::UNDERSCORE] - * - * @return string - */ - public static function render(string $text, $style = null): string - { - if (!$text) { - return $text; - } - - if (!Cli::isSupportColor()) { - return self::clearColor($text); - } - - // use defined style: 'green' - if (is_string($style)) { - $color = self::STYLES[$style] ?? '0'; - - // custom style: [self::FG_GREEN, self::BG_WHITE, self::UNDERSCORE] - } elseif (is_array($style)) { - $color = implode(';', $style); - - // user color tag: message - } elseif (strpos($text, ' 0) { - return self::parseTag($text); - } else { - return $text; - } - - // $result = chr(27). "$color{$text}" . chr(27) . chr(27) . "[0m". chr(27); - return sprintf(self::COLOR_TPL, $color, $text); - } - - /** - * parse color tag e.g: message - * - * @param string $text - * - * @return mixed|string - */ - public static function parseTag(string $text) - { - if (!$text || false === strpos($text, ' $m) { - if ($style = self::STYLES[$matches[1][$i]] ?? null) { - $tag = $matches[1][$i]; - $match = $matches[2][$i]; - - $repl = sprintf("\033[%sm%s\033[0m", $style, $match); - $text = str_replace("<$tag>$match", $repl, $text); - } - } - - return $text; - } - - /** - * @param string $text - * @param bool $stripTag - * - * @return string - */ - public static function clearColor(string $text, bool $stripTag = true): string - { - // return preg_replace('/\033\[(?:\d;?)+m/', '' , "\033[0;36mtext\033[0m"); - return preg_replace('/\033\[(?:\d;?)+m/', '', $stripTag ? strip_tags($text) : $text); - } - - /** - * @param string $style - * - * @return bool - */ - public static function hasStyle(string $style): bool - { - return isset(self::STYLES[$style]); - } - - /** - * get all style names - * - * @return array - */ - public static function getStyles(): array - { - return array_filter(array_keys(self::STYLES), function ($style) { - return !strpos($style, '_'); - }); - } -} diff --git a/libs/cli-utils/src/ColorTag.php b/libs/cli-utils/src/ColorTag.php deleted file mode 100644 index bc6f6c1..0000000 --- a/libs/cli-utils/src/ColorTag.php +++ /dev/null @@ -1,117 +0,0 @@ -/'; - - // Regex to match tags/ - public const MATCH_TAG = '/<([a-zA-Z=;_]+)>(.*?)<\/\\1>/s'; - - /** - * Alias of the wrap() - * - * @param string $text - * @param string $tag - * - * @return string - */ - public static function add(string $text, string $tag): string - { - return self::wrap($text, $tag); - } - - /** - * wrap a color style tag - * - * @param string $text - * @param string $tag - * - * @return string - */ - public static function wrap(string $text, string $tag): string - { - if (!$text || !$tag) { - return $text; - } - - return "<$tag>$text"; - } - - /** - * @param string $text - * - * @return array - */ - public static function matchAll(string $text): array - { - if (!preg_match_all(self::MATCH_TAG, $text, $matches)) { - return []; - } - - return $matches; - } - - public static function parse(string $text): string - { - return ''; - } - - /** - * Exists color tags - * - * @param string $text - * - * @return bool - */ - public static function exists(string $text): bool - { - return strpos($text, ' 0; - } - - /** - * Alias of the strip() - * - * @param string $text - * - * @return string - */ - public static function clear(string $text): string - { - return self::strip($text); - } - - /** - * Strip color tags from a string. - * - * @param string $text - * - * @return mixed - */ - public static function strip(string $text): string - { - if (false === strpos($text, ' - * - * @param string $url - * @param string $saveAs - * @param string $type - * - * @return Download - * @throws RuntimeException - */ - public static function file(string $url, string $saveAs = '', string $type = self::PROGRESS_TEXT): Download - { - $d = new self($url, $saveAs, $type); - - return $d->start(); - } - - /** - * Download constructor. - * - * @param string $url - * @param string $saveAs - * @param string $type - */ - public function __construct(string $url, string $saveAs = '', $type = self::PROGRESS_TEXT) - { - $this->setUrl($url); - $this->setSaveAs($saveAs); - - $this->showType = $type === self::PROGRESS_BAR ? self::PROGRESS_BAR : self::PROGRESS_TEXT; - } - - /** - * start download - * - * @return $this - * @throws RuntimeException - */ - public function start(): self - { - if (!$this->url) { - throw new RuntimeException("Please the property 'url' and 'saveAs'.", -1); - } - - // default save to current dir. - if (!$save = $this->saveAs) { - $save = getcwd() . '/' . basename($this->url); - // reset - $this->saveAs = $save; - } - - $ctx = stream_context_create(); - - // register stream notification callback - stream_context_set_params($ctx, [ - 'notification' => [$this, 'progressShow'] - ]); - - Cli::write("Download: {$this->url}\nSave As: {$save}\n"); - - $fp = fopen($this->url, 'rb', false, $ctx); - - if (is_resource($fp) && file_put_contents($save, $fp)) { - Cli::write("\nDone!"); - } else { - $err = error_get_last(); - Cli::stderr("\nErr.rrr..orr...\n {$err['message']}\n", true, -1); - } - - // close resource - if (is_resource($fp)) { - fclose($fp); - } - - $this->fileSize = null; - return $this; - } - - /** - * @param int $notifyCode stream notify code - * @param int $severity severity code - * @param string $message Message text - * @param int $messageCode Message code - * @param int $transferredBytes Have been transferred bytes - * @param int $maxBytes Target max length bytes - */ - public function progressShow($notifyCode, $severity, $message, $messageCode, $transferredBytes, $maxBytes): void - { - $msg = ''; - - switch ($notifyCode) { - case STREAM_NOTIFY_RESOLVE: - case STREAM_NOTIFY_AUTH_REQUIRED: - case STREAM_NOTIFY_COMPLETED: - case STREAM_NOTIFY_FAILURE: - case STREAM_NOTIFY_AUTH_RESULT: - $msg = "NOTIFY: $message(NO: $messageCode, Severity: $severity)"; - /* Ignore */ - break; - - case STREAM_NOTIFY_REDIRECTED: - $msg = "Being redirected to: $message"; - break; - - case STREAM_NOTIFY_CONNECT: - $msg = 'Connected ...'; - break; - - case STREAM_NOTIFY_FILE_SIZE_IS: - $this->fileSize = $maxBytes; - // print size - $size = sprintf('%2d', $maxBytes / 1024); - $msg = "Got the file size: $size kb"; - break; - - case STREAM_NOTIFY_MIME_TYPE_IS: - $msg = "Found the mime-type: $message"; - break; - - case STREAM_NOTIFY_PROGRESS: - if ($transferredBytes > 0) { - $this->showProgressByType($transferredBytes); - } - break; - } - - $msg && Cli::write($msg); - } - - /** - * @param $transferredBytes - * - * @return string - */ - public function showProgressByType($transferredBytes): string - { - if ($transferredBytes <= 0) { - return ''; - } - - $tfKb = $transferredBytes / 1024; - - if ($this->showType === self::PROGRESS_BAR) { - $size = $this->fileSize; - - if ($size === null) { - printf("\rUnknown file size... %2d kb done..", $tfKb); - } else { - $length = ceil(($transferredBytes / $size) * 100); // ■ = - printf("\r[%-100s] %d%% (%2d/%2d kb)", str_repeat('=', $length) . '>', $length, $tfKb, $size / 1024); - } - } else { - printf("\r\rMade some progress, downloaded %2d kb so far", $tfKb); - //$msg = "Made some progress, downloaded $transferredBytes so far"; - } - - return ''; - } - - /** - * @return string - */ - public function getShowType(): string - { - return $this->showType; - } - - /** - * @param string $showType - */ - public function setShowType(string $showType): void - { - $this->showType = $showType; - } - - /** - * @return string - */ - public function getUrl(): string - { - return $this->url; - } - - /** - * @param string $url - */ - public function setUrl(string $url): void - { - $this->url = trim($url); - } - - /** - * @return string - */ - public function getSaveAs(): string - { - return $this->saveAs; - } - - /** - * @param string $saveAs - */ - public function setSaveAs(string $saveAs): void - { - $this->saveAs = trim($saveAs); - } -} diff --git a/libs/cli-utils/src/Flags.php b/libs/cli-utils/src/Flags.php deleted file mode 100644 index c23ef9d..0000000 --- a/libs/cli-utils/src/Flags.php +++ /dev/null @@ -1,327 +0,0 @@ - $value) { - // opts - if (strpos($value, '-') === 0) { - $value = trim($value, '-'); - - // invalid - if (!$value) { - continue; - } - - if (strpos($value, '=')) { - [$n, $v] = explode('=', $value); - $opts[$n] = $v; - } else { - $opts[$value] = true; - } - } elseif (strpos($value, '=')) { - [$n, $v] = explode('=', $value); - $args[$n] = $v; - } else { - $args[] = $value; - } - } - - return [$args, $opts]; - } - - /** - * Parses $GLOBALS['argv'] for parameters and assigns them to an array. - * eg: - * - * ``` - * php cli.php run name=john city=chengdu -s=test --page=23 -d -rf --debug --task=off -y=false -D -e dev -v vvv - * ``` - * - * ```php - * $argv = $_SERVER['argv']; - * // notice: must shift first element. - * $script = \array_shift($argv); - * $result = Flags::parseArgv($argv); - * ``` - * - * Supports args: - * - * arg= - * Supports opts: - * -e - * -e - * -e= - * --long-opt - * --long-opt - * --long-opt= - * - * @link http://php.net/manual/zh/function.getopt.php#83414 - * - * @param array $params - * @param array $config - * - * @return array [args, short-opts, long-opts] - * If 'mergeOpts' is True, will return [args, opts] - */ - public static function parseArgv(array $params, array $config = []): array - { - if (!$params) { - return [[], [], []]; - } - - $config = array_merge([ - // List of parameters without values(bool option keys) - 'boolOpts' => [], // ['debug', 'h'] - // Whether merge short-opts and long-opts - 'mergeOpts' => false, - // want parsed options. if not empty, will ignore no matched - 'wantParsedOpts' => [], - // list of option allow array values. - 'arrayOpts' => [], // ['names', 'status'] - ], $config); - - $args = $sOpts = $lOpts = []; - // config - $boolOpts = array_flip((array)$config['boolOpts']); - $arrayOpts = array_flip((array)$config['arrayOpts']); - - // each() will deprecated at 7.2. so,there use current and next instead it. - // while (list(,$p) = each($params)) { - while (false !== ($p = current($params))) { - next($params); - - // is options - if ($p[0] === '-') { - $value = true; - $option = substr($p, 1); - $isLong = false; - - // long-opt: (--) - if (strpos($option, '-') === 0) { - $option = substr($option, 1); - $isLong = true; - - // long-opt: value specified inline (--=) - if (strpos($option, '=') !== false) { - [$option, $value] = explode('=', $option, 2); - } - - // short-opt: value specified inline (-=) - } elseif (isset($option[1]) && $option[1] === '=') { - [$option, $value] = explode('=', $option, 2); - } - - // check if next parameter is a descriptor or a value - $nxt = current($params); - - // next elem is value. fix: allow empty string '' - if ($value === true && !isset($boolOpts[$option]) && self::nextIsValue($nxt)) { - // list(,$val) = each($params); - $value = $nxt; - next($params); - - // short-opt: bool opts. like -e -abc - } elseif (!$isLong && $value === true) { - foreach (str_split($option) as $char) { - $sOpts[$char] = true; - } - continue; - } - - $value = self::filterBool($value); - $isArray = isset($arrayOpts[$option]); - - if ($isLong) { - if ($isArray) { - $lOpts[$option][] = $value; - } else { - $lOpts[$option] = $value; - } - } elseif ($isArray) { // short - $sOpts[$option][] = $value; - } else { // short - $sOpts[$option] = $value; - } - - continue; - } - - // parse arguments: - // - param doesn't belong to any option, define it is args - - // value specified inline (=) - if (strpos($p, '=') !== false) { - [$name, $value] = explode('=', $p, 2); - $args[$name] = self::filterBool($value); - } else { - $args[] = $p; - } - } - - if ($config['mergeOpts']) { - return [$args, array_merge($sOpts, $lOpts)]; - } - - return [$args, $sOpts, $lOpts]; - } - - /** - * parse custom array params - * ```php - * $result = Flags::parseArray([ - * 'arg' => 'val', - * '--lp' => 'val2', - * '--s' => 'val3', - * '-h' => true, - * ]); - * ``` - * - * @param array $params - * - * @return array - */ - public static function parseArray(array $params): array - { - $args = $sOpts = $lOpts = []; - - foreach ($params as $key => $val) { - if (is_int($key)) { // as argument - $args[$key] = $val; - continue; - } - - $cleanKey = trim((string)$key, '-'); - - if ('' === $cleanKey) { // as argument - $args[] = $val; - continue; - } - - if (0 === strpos($key, '--')) { // long option - $lOpts[$cleanKey] = $val; - } elseif (0 === strpos($key, '-')) { // short option - $sOpts[$cleanKey] = $val; - } else { - $args[$key] = $val; - } - } - - return [$args, $sOpts, $lOpts]; - } - - /** - * parse flags from a string - * - * ```php - * $result = Flags::parseString('foo --bar="foobar"'); - * ``` - * - * @param string $string - * - * @todo ... - */ - public static function parseString(string $string): void - { - - } - - /** - * @param string|bool $val - * @param bool $enable - * - * @return bool|mixed - */ - public static function filterBool($val, $enable = true) - { - if ($enable) { - if (is_bool($val) || is_numeric($val)) { - return $val; - } - - // check it is a bool value. - if (false !== stripos(self::TRUE_WORDS, "|$val|")) { - return true; - } - - if (false !== stripos(self::FALSE_WORDS, "|$val|")) { - return false; - } - } - - return $val; - } - - /** - * @param mixed $val - * - * @return bool - */ - public static function nextIsValue($val): bool - { - // current() fetch error, will return FALSE - if ($val === false) { - return false; - } - - // if is: '', 0 - if (!$val) { - return true; - } - - // it isn't option or named argument - return $val[0] !== '-' && false === strpos($val, '='); - } - - /** - * Escapes a token through escapeshellarg if it contains unsafe chars. - * - * @param string $token - * - * @return string - */ - public static function escapeToken(string $token): string - { - return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token); - } -} diff --git a/libs/cli-utils/src/Highlighter.php b/libs/cli-utils/src/Highlighter.php deleted file mode 100644 index 2dc8f80..0000000 --- a/libs/cli-utils/src/Highlighter.php +++ /dev/null @@ -1,380 +0,0 @@ - 'red', - self::TOKEN_COMMENT => 'yellow', - self::TOKEN_KEYWORD => 'info', - self::TOKEN_DEFAULT => 'normal', - self::TOKEN_HTML => 'cyan', - self::ACTUAL_LINE_MARK => 'red', - self::LINE_NUMBER => 'darkGray', - ]; - - /** @var bool */ - private $hasTokenFunc; - - /** - * @return Highlighter - */ - public static function create(): self - { - if (!self::$instance) { - self::$instance = new self(); - } - - return self::$instance; - } - - public function __construct() - { - $this->hasTokenFunc = function_exists('token_get_all'); - } - - /** - * highlight a full php file content - * - * @param string $source - * @param bool $withLineNumber with line number - * - * @return string - */ - public function highlight(string $source, bool $withLineNumber = false): string - { - $tokenLines = $this->getHighlightedLines($source); - $lines = $this->colorLines($tokenLines); - - if ($withLineNumber) { - return $this->lineNumbers($lines); - } - - return implode(PHP_EOL, $lines); - } - - /** - * @param string $file - * @param bool $withLineNumber - * - * @return string - */ - public function highlightFile(string $file, bool $withLineNumber = false): string - { - if (!file_exists($file)) { - throw new InvalidArgumentException("the target file is not exist! file: $file"); - } - - $source = file_get_contents($file); - - return $this->highlight($source, $withLineNumber); - } - - /** - * @param string $source - * @param int $lineNumber - * @param int $linesBefore - * @param int $linesAfter - * - * @return string - * @throws InvalidArgumentException - */ - public function snippet(string $source, int $lineNumber, int $linesBefore = 2, int $linesAfter = 2): string - { - return $this->highlightSnippet($source, $lineNumber, $linesBefore, $linesAfter); - } - - /** - * @param string $source - * @param int $lineNumber - * @param int $linesBefore - * @param int $linesAfter - * - * @return string - * @throws InvalidArgumentException - */ - public function highlightSnippet($source, $lineNumber, $linesBefore = 2, $linesAfter = 2): string - { - $tokenLines = $this->getHighlightedLines($source); - - $offset = $lineNumber - $linesBefore - 1; - $offset = max($offset, 0); - $length = $linesAfter + $linesBefore + 1; - $tokenLines = array_slice($tokenLines, $offset, $length, $preserveKeys = true); - - $lines = $this->colorLines($tokenLines); - - return $this->lineNumbers($lines, $lineNumber); - } - - /** - * @param string $source - * - * @return array - */ - private function getHighlightedLines(string $source): array - { - $source = str_replace(["\r\n", "\r"], "\n", $source); - - if ($this->hasTokenFunc) { - $tokens = $this->tokenize($source); - return $this->splitToLines($tokens); - } - - // if no func: token_get_all - return explode("\n", $source); - } - - /** - * @param string $source - * - * @return array - */ - private function tokenize(string $source): array - { - $buffer = ''; - $output = []; - $tokens = token_get_all($source); - $newType = $currentType = null; - - foreach ($tokens as $token) { - if (is_array($token)) { - switch ($token[0]) { - case T_INLINE_HTML: - $newType = self::TOKEN_HTML; - break; - case T_COMMENT: - case T_DOC_COMMENT: - $newType = self::TOKEN_COMMENT; - break; - case T_ENCAPSED_AND_WHITESPACE: - case T_CONSTANT_ENCAPSED_STRING: - $newType = self::TOKEN_STRING; - break; - case T_WHITESPACE: - break; - case T_OPEN_TAG: - case T_OPEN_TAG_WITH_ECHO: - case T_CLOSE_TAG: - case T_STRING: - case T_VARIABLE: - // Constants - case T_DIR: - case T_FILE: - case T_METHOD_C: - case T_DNUMBER: - case T_LNUMBER: - case T_NS_C: - case T_LINE: - case T_CLASS_C: - case T_FUNC_C: - //case T_TRAIT_C: - $newType = self::TOKEN_DEFAULT; - break; - default: - // Compatibility with PHP 5.3 - if (defined('T_TRAIT_C') && $token[0] === T_TRAIT_C) { - $newType = self::TOKEN_DEFAULT; - } else { - $newType = self::TOKEN_KEYWORD; - } - } - } else { - $newType = $token === '"' ? self::TOKEN_STRING : self::TOKEN_KEYWORD; - } - - if ($currentType === null) { - $currentType = $newType; - } - - if ($currentType !== $newType) { - $output[] = [$currentType, $buffer]; - $buffer = ''; - $currentType = $newType; - } - - $buffer .= is_array($token) ? $token[1] : $token; - } - - if (null !== $newType) { - $output[] = [$newType, $buffer]; - } - - return $output; - } - - /** - * @param array $tokens - * - * @return array - */ - private function splitToLines(array $tokens): array - { - $lines = $line = []; - - foreach ($tokens as $token) { - foreach (explode("\n", $token[1]) as $count => $tokenLine) { - if ($count > 0) { - $lines[] = $line; - $line = []; - } - if ($tokenLine === '') { - continue; - } - - $line[] = [$token[0], $tokenLine]; - } - } - $lines[] = $line; - - return $lines; - } - - /** - * @param array[] $tokenLines - * - * @return array - * @throws InvalidArgumentException - */ - private function colorLines(array $tokenLines): array - { - if (!$this->hasTokenFunc) { - return $tokenLines; - } - - $lines = []; - - foreach ($tokenLines as $lineCount => $tokenLine) { - $line = ''; - foreach ($tokenLine as [$tokenType, $tokenValue]) { - $style = $this->defaultTheme[$tokenType]; - - if (Color::hasStyle($style)) { - $line .= Color::apply($style, $tokenValue); - } else { - $line .= $tokenValue; - } - } - - $lines[$lineCount] = $line; - } - - return $lines; - } - - /** - * @param array $lines - * @param null|int $markLine - * - * @return string - */ - private function lineNumbers(array $lines, $markLine = null): string - { - end($lines); - - $snippet = ''; - $lineLen = strlen(key($lines) + 1); - $lmStyle = $this->defaultTheme[self::ACTUAL_LINE_MARK]; - $lnStyle = $this->defaultTheme[self::LINE_NUMBER]; - - foreach ($lines as $i => $line) { - if ($markLine !== null) { - $snippet .= ($markLine === $i + 1 ? Color::apply($lmStyle, ' > ') : ' '); - $snippet .= Color::apply($markLine === $i + 1 ? $lmStyle : $lnStyle, - str_pad($i + 1, $lineLen, ' ', STR_PAD_LEFT) . '| '); - } else { - $snippet .= Color::apply($lnStyle, str_pad($i + 1, $lineLen, ' ', STR_PAD_LEFT) . '| '); - } - - $snippet .= $line . PHP_EOL; - } - - return $snippet; - } - - /** - * @return array - */ - public function getDefaultTheme(): array - { - return $this->defaultTheme; - } - - /** - * @param array $defaultTheme - */ - public function setDefaultTheme(array $defaultTheme): void - { - $this->defaultTheme = array_merge($this->defaultTheme, $defaultTheme); - } -} diff --git a/libs/cli-utils/src/Terminal.php b/libs/cli-utils/src/Terminal.php deleted file mode 100644 index f33212d..0000000 --- a/libs/cli-utils/src/Terminal.php +++ /dev/null @@ -1,243 +0,0 @@ - '?25l', - - // Will show a cursor again when it has been hidden by [hide] - 'show' => '?25h', - - // Saves the current cursor position, Position can then be restored with [restorePosition]. - // - 保存当前光标位置,然后可以使用[restorePosition]恢复位置 - 'savePosition' => 's', - - // Restores the cursor position saved with [savePosition] - 恢复[savePosition]保存的光标位置 - 'restorePosition' => 'u', - - // Moves the terminal cursor up - 'up' => '%dA', - - // Moves the terminal cursor down - 'down' => '%B', - - // Moves the terminal cursor forward - 移动终端光标前进多远 - 'forward' => '%dC', - - // Moves the terminal cursor backward - 移动终端光标后退多远 - 'backward' => '%dD', - - // Moves the terminal cursor to the beginning of the previous line - 移动终端光标到前一行的开始 - 'prevLine' => '%dF', - - // Moves the terminal cursor to the beginning of the next line - 移动终端光标到下一行的开始 - 'nextLine' => '%dE', - - // Moves the cursor to an absolute position given as column and row - // $column 1-based column number, 1 is the left edge of the screen. - // $row 1-based row number, 1 is the top edge of the screen. if not set, will move cursor only in current line. - 'coordinate' => '%dG|%d;%dH' // only column: '%dG', column and row: '%d;%dH'. - ]; - - /** - * Control screen code list - * - * @var array - */ - private static $ctrlScreenCodes = [ - // Clears entire screen content - 清除整个屏幕内容 - 'clear' => '2J', // "\033[2J" - - // Clears text from cursor to the beginning of the screen - 从光标清除文本到屏幕的开头 - 'clearBeforeCursor' => '1J', - - // Clears the line - 清除此行 - 'clearLine' => '2K', - - // Clears text from cursor position to the beginning of the line - 清除此行从光标位置开始到开始的字符 - 'clearLineBeforeCursor' => '1K', - - // Clears text from cursor position to the end of the line - 清除此行从光标位置开始到结束的字符 - 'clearLineAfterCursor' => '0K', - - // Scrolls whole page up. e.g "\033[2S" scroll up 2 line. - 上移多少行 - 'scrollUp' => '%dS', - - // Scrolls whole page down.e.g "\033[2T" scroll down 2 line. - 下移多少行 - 'scrollDown' => '%dT', - ]; - - public static function make(): Terminal - { - if (!self::$instance) { - self::$instance = new self; - } - - return self::$instance; - } - - /** - * build ansi code string - * - * ``` - * Terminal::build(null, 'u'); // "\033[s" Saves the current cursor position - * Terminal::build(0); // "\033[0m" Build end char, Resets any ANSI format - * ``` - * - * @param mixed $format - * @param string $type - * - * @return string - */ - public static function build($format, $type = 'm'): string - { - $format = null === $format ? '' : implode(';', (array)$format); - - return "\033[" . implode(';', (array)$format) . $type; - } - - /** - * control cursor - * - * @param string $typeName - * @param int $arg1 - * @param null $arg2 - * - * @return $this - */ - public function cursor($typeName, $arg1 = 1, $arg2 = null): self - { - if (!isset(self::$ctrlCursorCodes[$typeName])) { - Cli::stderr("The [$typeName] is not supported cursor control."); - } - - $code = self::$ctrlCursorCodes[$typeName]; - - // allow argument - if (false !== strpos($code, '%')) { - // The special code: ` 'coordinate' => '%dG|%d;%dH' ` - if ($typeName === self::CUR_COORDINATE) { - $codes = explode('|', $code); - - if (null === $arg2) { - $code = sprintf($codes[0], $arg1); - } else { - $code = sprintf($codes[1], $arg1, $arg2); - } - - } else { - $code = sprintf($code, $arg1); - } - } - - echo self::build($code, ''); - - return $this; - } - - /** - * control screen - * - * @param $typeName - * @param null $arg - * - * @return $this - */ - public function screen(string $typeName, $arg = null): self - { - if (!isset(self::$ctrlScreenCodes[$typeName])) { - Cli::stderr("The [$typeName] is not supported cursor control."); - } - - $code = self::$ctrlScreenCodes[$typeName]; - - // allow argument - if (false !== strpos($code, '%')) { - $code = sprintf($code, $arg); - } - - echo self::build($code, ''); - - return $this; - } - - public function reset(): void - { - echo self::END_CHAR; - } - - /** - * @return array - */ - public static function supportedCursorCtrl(): array - { - return array_keys(self::$ctrlCursorCodes); - } - - /** - * @return array - */ - public static function supportedScreenCtrl(): array - { - return array_keys(self::$ctrlScreenCodes); - } -} diff --git a/libs/cli-utils/test/ColorTagTest.php b/libs/cli-utils/test/ColorTagTest.php deleted file mode 100644 index af9366e..0000000 --- a/libs/cli-utils/test/ColorTagTest.php +++ /dev/null @@ -1,75 +0,0 @@ -text0 or text1'); - $this->assertCount(3, $ret); - // tag - $this->assertSame('tag', $ret[1][0]); - $this->assertSame('info', $ret[1][1]); - // content - $this->assertSame('text0', $ret[2][0]); - - $ret = ColorTag::matchAll('text'); - $this->assertCount(3, $ret); - // tag - $this->assertSame('some_tag', $ret[1][0]); - // content - $this->assertSame('text', $ret[2][0]); - - $ret = ColorTag::matchAll('text'); - $this->assertCount(3, $ret); - // tag - $this->assertSame('someTag', $ret[1][0]); - // content - $this->assertSame('text', $ret[2][0]); - } - - public function testStrip(): void - { - $text = ColorTag::strip('text'); - $this->assertSame('text', $text); - - // no close - $text = ColorTag::clear('text'); - $this->assertSame('text', $text); - } - - public function testWrap(): void - { - $text = ColorTag::wrap('text', 'tag'); - $this->assertSame('text', $text); - - $text = ColorTag::add('text', ''); - $this->assertSame('text', $text); - - $text = ColorTag::add('', 'tag'); - $this->assertSame('', $text); - } - - public function testExists(): void - { - $this->assertTrue(ColorTag::exists('text')); - $this->assertFalse(ColorTag::exists('text')); - $this->assertFalse(ColorTag::exists('text')); - $this->assertFalse(ColorTag::exists('text')); - } -} diff --git a/libs/cli-utils/test/ColorTest.php b/libs/cli-utils/test/ColorTest.php deleted file mode 100644 index 5f5fb3d..0000000 --- a/libs/cli-utils/test/ColorTest.php +++ /dev/null @@ -1,43 +0,0 @@ -assertStringContainsString(Color::STYLES['info'], $text); - - $text = Color::render('text', [Color::RESET, Color::FG_CYAN]); - $this->assertStringContainsString(Color::STYLES['cyan'], $text); - - $text = Color::render('text'); - $this->assertStringContainsString(Color::STYLES['info'], $text); - - $text = Color::render('text'); - $this->assertStringContainsString(Color::STYLES['light_blue'], $text); - - $text = Color::render('text'); - $this->assertStringContainsString(Color::STYLES['lightBlue'], $text); - } - - public function testApply(): void - { - $text = Color::apply('info', 'text'); - $this->assertStringContainsString(Color::STYLES['info'], $text); - - foreach (Color::STYLES as $name => $code) { - $text = Color::apply($name, 'text'); - $this->assertStringContainsString($code, $text); - } - } -} diff --git a/libs/cli-utils/test/FlagsTest.php b/libs/cli-utils/test/FlagsTest.php deleted file mode 100644 index f4d2f9c..0000000 --- a/libs/cli-utils/test/FlagsTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertNotEmpty($args); - $this->assertSame('git:tag', $args[0]); - $this->assertSame('arg0', $args[1]); - - $this->assertSame('../view', $sOpts['d']); - $this->assertTrue($lOpts['only-tag']); - - [$args, $opts] = Flags::parseArgv($rawArgv, ['mergeOpts' => true]); - - $this->assertNotEmpty($args); - $this->assertSame('git:tag', $args[0]); - $this->assertSame('arg0', $args[1]); - - $this->assertSame('../view', $opts['d']); - $this->assertTrue($opts['only-tag']); - } -} diff --git a/libs/cli-utils/test/boot.php b/libs/cli-utils/test/boot.php deleted file mode 100644 index 8afcdc7..0000000 --- a/libs/cli-utils/test/boot.php +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - test/ - - - - - - src - - - diff --git a/libs/di/phpunit.xml.dist b/libs/di/phpunit.xml.dist deleted file mode 100644 index 26bd767..0000000 --- a/libs/di/phpunit.xml.dist +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - test/ - - - - - - src - - - diff --git a/libs/obj-utils/LICENSE b/libs/obj-utils/LICENSE deleted file mode 100644 index d839cdc..0000000 --- a/libs/obj-utils/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 inhere - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/libs/obj-utils/README.md b/libs/obj-utils/README.md deleted file mode 100644 index 1f2a6a2..0000000 --- a/libs/obj-utils/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# object utils - -[![License](https://img.shields.io/packagist/l/toolkit/obj-utils.svg?style=flat-square)](LICENSE) -[![Php Version](https://img.shields.io/badge/php-%3E=7.1.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/toolkit/obj-utils) -[![Latest Stable Version](http://img.shields.io/packagist/v/toolkit/obj-utils.svg)](https://packagist.org/packages/toolkit/obj-utils) - -Some useful object utils for the php. - -## Install - -```bash -composer require toolkit/obj-utils -``` - -## License - -MIT diff --git a/libs/obj-utils/composer.json b/libs/obj-utils/composer.json deleted file mode 100644 index ec77810..0000000 --- a/libs/obj-utils/composer.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "toolkit/obj-utils", - "type": "library", - "description": "some object tool library of the php", - "keywords": [ - "library", - "tool", - "php" - ], - "homepage": "https://github.com/php-toolkit/obj-utils", - "license": "MIT", - "authors": [ - { - "name": "inhere", - "email": "in.798@qq.com", - "homepage": "http://www.yzone.net/" - } - ], - "require": { - "php": ">7.1.0" - }, - "autoload": { - "psr-4": { - "Toolkit\\ObjUtil\\": "src/" - } - }, - "suggest": { - "inhere/php-validate": "Very lightweight data validate tool", - "inhere/console": "a lightweight php console application library." - }, - "scripts": { - "test": "phpunit test" - } -} diff --git a/libs/obj-utils/src/Configurable.php b/libs/obj-utils/src/Configurable.php deleted file mode 100644 index f6d8176..0000000 --- a/libs/obj-utils/src/Configurable.php +++ /dev/null @@ -1,43 +0,0 @@ -init(); - } - - /** - * init - */ - protected function init(): void - { - // init something ... - } -} diff --git a/libs/obj-utils/src/Exception/GetPropertyException.php b/libs/obj-utils/src/Exception/GetPropertyException.php deleted file mode 100644 index b829696..0000000 --- a/libs/obj-utils/src/Exception/GetPropertyException.php +++ /dev/null @@ -1,20 +0,0 @@ - $value) { - if (is_numeric($property)) { - continue; - } - - $setter = 'set' . ucfirst($property); - - // has setter - if (method_exists($object, $setter)) { - $object->$setter($value); - } elseif (property_exists($object, $property)) { - $object->$property = $value; - } - } - - return $object; - } - - /** - * 给对象设置属性值 - * - * @param $object - * @param array $options - */ - public static function configure($object, array $options): void - { - foreach ($options as $property => $value) { - if (property_exists($object, $property)) { - $object->$property = $value; - } - } - } - - /** - * 给对象设置属性值 - * - * @param $object - * @param array $options - */ - public static function setAttrs($object, array $options): void - { - self::configure($object, $options); - } - - /** - * 定义一个用来序列化数据的函数 - * - * @param mixed $obj - * - * @return string - */ - public static function encode($obj): string - { - return base64_encode(gzcompress(serialize($obj))); - } - - /** - * 反序列化 - * - * @param string $txt - * @param bool|array $allowedClasses - * - * @return mixed - */ - public static function decode(string $txt, $allowedClasses = false) - { - return unserialize(gzuncompress(base64_decode($txt)), ['allowed_classes' => $allowedClasses]); - } - - /** - * php对象转换成为数组 - * - * @param iterable|array|Traversable $data - * @param bool $recursive - * - * @return array|bool - */ - public static function toArray($data, bool $recursive = false) - { - $arr = []; - - // Ensure the input data is an array. - if (is_object($data)) { - if ($data instanceof Traversable) { - $arr = iterator_to_array($data); - } elseif (method_exists($data, 'toArray')) { - $arr = $data->toArray(); - } - } else { - $arr = (array)$data; - } - - if ($recursive) { - foreach ($arr as $key => $value) { - if (is_array($value) || is_object($value)) { - $arr[$key] = static::toArray($value, $recursive); - } - } - } - - return $arr; - } - - /** - * @param mixed $object - * @param bool $unique - * - * @return string - */ - public static function hash($object, $unique = true): string - { - if (is_object($object)) { - $hash = spl_object_hash($object); - - if ($unique) { - $hash = md5($hash); - } - - return $hash; - } - - // a class - return is_string($object) ? md5($object) : ''; - } - - /** - * @from https://github.com/ventoviro/windwalker - * Build an array of constructor parameters. - * - * @param ReflectionMethod $method Method for which to build the argument array. - * @param array $extraArgs - * - * @return array - * @throws RuntimeException - * @throws ReflectionException - */ - public static function getMethodArgs(ReflectionMethod $method, array $extraArgs = []): array - { - $methodArgs = []; - - foreach ($method->getParameters() as $idx => $param) { - // if user have been provide arg - if (isset($extraArgs[$idx])) { - $methodArgs[] = $extraArgs[$idx]; - continue; - } - - $dependencyClass = $param->getClass(); - - // If we have a dependency, that means it has been type-hinted. - if ($dependencyClass && ($depClass = $dependencyClass->getName()) !== Closure::class) { - $depClass = $dependencyClass->getName(); - $depObject = self::create($depClass); - - if ($depObject instanceof $depClass) { - $methodArgs[] = $depObject; - continue; - } - } - - // Finally, if there is a default parameter, use it. - if ($param->isOptional()) { - $methodArgs[] = $param->getDefaultValue(); - continue; - } - - // $dependencyVarName = $param->getName(); - // Couldn't resolve dependency, and no default was provided. - throw new RuntimeException(sprintf('Could not resolve dependency: %s for the %dth parameter', - $param->getPosition(), $param->getName())); - } - - return $methodArgs; - } - - /** - * 从类名创建服务实例对象,会尽可能自动补完构造函数依赖 - * - * @from windWalker https://github.com/ventoviro/windwalker - * - * @param string $class a className - * - * @return mixed - * @throws RuntimeException - */ - public static function create(string $class) - { - try { - $reflection = new ReflectionClass($class); - } catch (ReflectionException $e) { - return false; - } - - $constructor = $reflection->getConstructor(); - - // If there are no parameters, just return a new object. - if (null === $constructor) { - return new $class; - } - - $newInstanceArgs = self::getMethodArgs($constructor); - - // Create a callable for the dataStorage - return $reflection->newInstanceArgs($newInstanceArgs); - } - - /** - * @param string|array $config - * - * @return mixed - */ - public static function smartCreate($config) - { - if (is_string($config)) { - return new $config; - } - - if (is_array($config) && !empty($config['class'])) { - $class = $config['class']; - $args = $config[0] ?? []; - - $obj = new $class(...$args); - - unset($config['class'], $config[0]); - return self::init($obj, $config); - } - - return null; - } -} diff --git a/libs/obj-utils/src/Traits/ArrayAccessByGetterSetterTrait.php b/libs/obj-utils/src/Traits/ArrayAccessByGetterSetterTrait.php deleted file mode 100644 index c23bed0..0000000 --- a/libs/obj-utils/src/Traits/ArrayAccessByGetterSetterTrait.php +++ /dev/null @@ -1,83 +0,0 @@ -$getter(); - } - - return null; - } - - /** - * Sets an offset in the iterator. - * - * @param mixed $offset The array offset. - * @param mixed $value The array value. - */ - public function offsetSet($offset, $value): void - { - $setter = 'set' . ucfirst($offset); - - if (method_exists($this, $setter)) { - $this->$setter($value); - } - } - - /** - * Unset an offset in the iterator. - * - * @param mixed $offset The array offset. - * - * @return void - */ - public function offsetUnset($offset): void - { - // unset($this->$offset); - } -} diff --git a/libs/obj-utils/src/Traits/ArrayAccessByPropertyTrait.php b/libs/obj-utils/src/Traits/ArrayAccessByPropertyTrait.php deleted file mode 100644 index dfb8194..0000000 --- a/libs/obj-utils/src/Traits/ArrayAccessByPropertyTrait.php +++ /dev/null @@ -1,74 +0,0 @@ -$offset; - } - - /** - * Sets an offset in the iterator. - * - * @param mixed $offset The array offset. - * @param mixed $value The array value. - * - * @return void - */ - public function offsetSet($offset, $value): void - { - $this->$offset = $value; - } - - /** - * Unset an offset in the iterator. - * - * @param mixed $offset The array offset. - * - * @return void - */ - public function offsetUnset($offset): void - { - // unset($this->$offset); - } -} diff --git a/libs/obj-utils/src/Traits/ObjectPoolTrait.php b/libs/obj-utils/src/Traits/ObjectPoolTrait.php deleted file mode 100644 index d91c041..0000000 --- a/libs/obj-utils/src/Traits/ObjectPoolTrait.php +++ /dev/null @@ -1,128 +0,0 @@ - \SplStack] - */ - private static $pool = []; - - /** - * @param string $class - * - * @return mixed - */ - public static function get(string $class) - { - $stack = self::getStack($class); - - if (!$stack->isEmpty()) { - return $stack->shift(); - } - - return new $class; - } - - /** - * @param stdClass|string $object - */ - public static function put($object): void - { - if (is_string($object)) { - $object = new $object; - } - - self::getStack($object)->push($object); - } - - /** - * @param string $class - * @param Closure $handler - * - * @return mixed - */ - public static function use($class, Closure $handler) - { - $obj = self::get($class); - - $ret = $handler($obj); - - self::put($obj); - - return $ret; - } - - /** - * @param string|stdClass $class - * - * @return SplStack - */ - public static function getStack($class): SplStack - { - $class = is_string($class) ? $class : get_class($class); - - if (!isset(self::$pool[$class])) { - self::$pool[$class] = new SplStack(); - } - - return self::$pool[$class]; - } - - /** - * @param null $class - * - * @return int - * @throws InvalidArgumentException - */ - public static function count($class = null): int - { - if ($class) { - if (!isset(self::$pool[$class])) { - throw new InvalidArgumentException("The object is never created of the class: $class"); - } - - return self::$pool[$class]->count(); - } - - return count(self::$pool); - } - - /** - * @param null $class - * - * @throws InvalidArgumentException - */ - public static function destroy($class = null): void - { - if ($class) { - if (!isset(self::$pool[$class])) { - throw new InvalidArgumentException("The object is never created of the class: $class"); - } - - unset(self::$pool[$class]); - } else { - self::$pool = []; - } - } -} diff --git a/libs/obj-utils/src/Traits/PropertyAccessByGetterSetterTrait.php b/libs/obj-utils/src/Traits/PropertyAccessByGetterSetterTrait.php deleted file mode 100644 index f709109..0000000 --- a/libs/obj-utils/src/Traits/PropertyAccessByGetterSetterTrait.php +++ /dev/null @@ -1,108 +0,0 @@ -$setter($value); - } elseif (method_exists($this, 'get' . ucfirst($name))) { - throw new SetPropertyException('Setting a Read-only property! ' . get_class($this) . "::{$name}"); - } else { - throw new SetPropertyException('Setting a Unknown property! ' . get_class($this) . "::{$name}"); - } - } - - /** - * @reference yii2 yii\base\Object::__set() - * - * @param $name - * - * @return mixed - * @throws GetPropertyException - */ - public function __get($name) - { - $getter = 'get' . ucfirst($name); - - if (method_exists($this, $getter)) { - return $this->$getter(); - } - - if (method_exists($this, 'set' . ucfirst($name))) { - throw new GetPropertyException('Getting a Write-only property! ' . get_class($this) . "::{$name}"); - } - - throw new GetPropertyException('Getting a Unknown property! ' . get_class($this) . "::{$name}"); - } - - /** - * @param $name - * - * @return bool - */ - public function __isset($name) - { - $getter = 'get' . ucfirst($name); - - if (method_exists($this, $getter)) { - return $this->$getter() !== null; - } - - return false; - } - - /** - * @param $name - * - * @throws PropertyException - */ - public function __unset($name) - { - $setter = 'set' . ucfirst($name); - - if (method_exists($this, $setter)) { - $this->$setter(null); - - return; - } - - throw new PropertyException('Unset an unknown or read-only property: ' . get_class($this) . '::' . $name); - } - -} diff --git a/libs/obj-utils/src/Traits/SingletonTrait.php b/libs/obj-utils/src/Traits/SingletonTrait.php deleted file mode 100644 index 68e282a..0000000 --- a/libs/obj-utils/src/Traits/SingletonTrait.php +++ /dev/null @@ -1,31 +0,0 @@ -init(); - } - - /** - * init - */ - protected function init(): void - { - // init something ... - } - - /** - * @param string $method - * @param $args - * - * @return mixed - * @throws InvalidArgumentException - */ - public function __call($method, array $args) - { - // if (method_exists($this, $method) && $this->isAllowCall($method) ) { - // return call_user_func_array( array($this, $method), (array) $args); - // } - - throw new InvalidArgumentException('Called a Unknown method! ' . get_class($this) . "->{$method}()"); - } - - /** - * @param string $method - * @param $args - * - * @return mixed - * @throws InvalidArgumentException - */ - public static function __callStatic(string $method, $args) - { - if (method_exists(self::class, $method)) { - return call_user_func_array([self::class, $method], (array)$args); - } - - throw new InvalidArgumentException('Called a Unknown static method! [ ' . self::class . "::{$method}()]"); - } -} diff --git a/libs/obj-utils/test/boot.php b/libs/obj-utils/test/boot.php deleted file mode 100644 index 01ff8b9..0000000 --- a/libs/obj-utils/test/boot.php +++ /dev/null @@ -1,27 +0,0 @@ -7.1.0", - "ext-mbstring": "*" - }, - "autoload": { - "psr-4": { - "Toolkit\\StrUtil\\": "src/" - } - }, - "suggest": { - "inhere/php-validate": "Very lightweight data validate tool" - } -} diff --git a/libs/str-utils/phpunit.xml.dist b/libs/str-utils/phpunit.xml.dist deleted file mode 100644 index 26bd767..0000000 --- a/libs/str-utils/phpunit.xml.dist +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - test/ - - - - - - src - - - diff --git a/libs/str-utils/src/HtmlHelper.php b/libs/str-utils/src/HtmlHelper.php deleted file mode 100644 index 55da156..0000000 --- a/libs/str-utils/src/HtmlHelper.php +++ /dev/null @@ -1,241 +0,0 @@ - $value) { - if (is_string($key)) { - $key = htmlspecialchars($key, ENT_QUOTES, $charset); - } - - if (is_string($value)) { - $value = htmlspecialchars($value, ENT_QUOTES, $charset); - } elseif (is_array($value)) { - $value = static::encodeArray($value); - } - - $d[$key] = $value; - } - - return $d; - } - - - /** - * html代码转义 - * htmlspecialchars 只转化这几个html [ & ' " < > ] 代码 --> [ & " ], - * 而 htmlentities 却会转化所有的html代码,连同里面的它无法识别的中文字符也会转化。 - * 一般使用 htmlspecialchars 就足够了,要使用 htmlentities 时,要注意为第三个参数传递正确的编码。 - * htmlentities() <--> html_entity_decode() — 将特殊的 HTML 实体转换回普通字符 - * htmlspecialchars() <--> htmlspecialchars_decode() — 将特殊的 HTML 实体转换回普通字符 - * ENT_COMPAT ENT_QUOTES ENT_NOQUOTES ENT_HTML401 ENT_XML1 ENT_XHTML ENT_HTML5 - * - * @param $data - * @param int $type - * @param string $encoding - * - * @return array|mixed|string - */ - public static function escape($data, int $type = 0, $encoding = 'UTF-8') - { - if (is_array($data)) { - foreach ($data as $k => $v) { - $data[$k] = self::escape($data, $type, $encoding); - } - - return $data; - } - - // 默认使用 htmlspecialchars() - if (!$type) { - $data = htmlspecialchars($data, ENT_QUOTES, $encoding); - } else { - $data = htmlentities($data, ENT_QUOTES, $encoding); - } - - //如‘志’这样的16进制的html字符,为了防止这样的字符被错误转译,使用正则进行匹配,把这样的字符又转换回来。 - if (strpos($data, '&#')) { - $data = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $data); - } - - return $data; - } - - /** - * 去掉html转义 - * - * @param $data - * @param int $type - * @param string $encoding - * - * @return array|string - */ - public static function unescap($data, $type = 0, $encoding = 'UTF-8') - { - if (is_array($data)) { - foreach ($data as $k => $v) { - $data[$k] = self::unescap($data, $type, $encoding); - } - - } elseif (!$type) {//默认使用 htmlspecialchars_decode() - $data = htmlspecialchars_decode($data, ENT_QUOTES); - } else { - $data = html_entity_decode($data, ENT_QUOTES, $encoding); - } - - return $data; - } - - /** - * Strip img-tags from string - * - * @param string $string Sting to be cleaned. - * - * @return string Cleaned string - */ - public static function stripImages(string $string): string - { - return preg_replace('#(<[/]?img.*>)#U', '', $string); - } - - /** - * Strip iframe-tags from string - * - * @param string $string Sting to be cleaned. - * - * @return string Cleaned string - */ - public static function stripIframes(string $string): string - { - return preg_replace('#(<[/]?iframe.*>)#U', '', $string); - } - - /** - * stripScript - * - * @param string $string - * - * @return string - */ - public static function stripScript(string $string): string - { - return preg_replace('/]*>.*?/si', '', $string); - } - - /** - * stripStyle - * - * @param string $string - * - * @return string - */ - public static function stripStyle(string $string): string - { - return preg_replace('/]*>.*?/si', '', $string); - } - - /** - * @param string $html - * @param bool|true $onlySrc - * - * @return array - */ - public static function matchImages(string $html, bool $onlySrc = true): array - { - // $preg = '//i'; - $preg = '//i'; - - if (!preg_match_all($preg, trim($html), $images)) { - return []; - } - - if ($onlySrc) { - return array_key_exists(1, $images) ? $images[1] : []; - } - - return $images; - } - - /** - * @param string $html - * - * @return string - */ - public static function minify(string $html): string - { - $search = [ - '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?[^\S ]+/s', - '/[^\S ]+\', '<', '\\1']; - - return preg_replace($search, $replace, $html); - } -} diff --git a/libs/str-utils/src/Json.php b/libs/str-utils/src/Json.php deleted file mode 100644 index fccc524..0000000 --- a/libs/str-utils/src/Json.php +++ /dev/null @@ -1,18 +0,0 @@ - 'min' // 输出数据类型 min 压缩过的 raw 正常的 - * 'file' => 'xx.json' // 输出文件路径;仅是文件名,则会取输入路径 - * ] - * - * @return string | bool - */ - public static function format($input, $output = false, array $options = []) - { - if (!is_string($input)) { - return false; - } - - $data = trim($input); - - if (file_exists($input)) { - $data = file_get_contents($input); - } - - if (!$data) { - return false; - } - - $data = preg_replace([ - // 去掉所有多行注释/* .... */ - '/\/\*.*?\*\/\s*/is', - // 去掉所有单行注释//.... - '/\/\/.*?[\r\n]/is', - // 去掉空白行 - "/(\n[\r])+/is" - ], ['', '', "\n"], $data); - - if (!$output) { - return $data; - } - - $default = ['type' => 'min']; - $options = array_merge($default, $options); - - if (file_exists($input) && (empty($options['file']) || !is_file($options['file']))) { - $dir = dirname($input); - $name = basename($input, '.json'); - $file = $dir . '/' . $name . '.' . $options['type'] . '.json'; - // save to options - $options['file'] = $file; - } - - static::saveAs($data, $options['file'], $options['type']); - return $data; - } - - /** - * @param string $data - * @param string $output - * @param array $options - * - * @return bool|int - */ - public static function saveAs(string $data, string $output, array $options = []) - { - $default = ['type' => 'min', 'file' => '']; - $options = array_merge($default, $options); - $saveDir = dirname($output); - - if (!file_exists($saveDir)) { - throw new RuntimeException('设置的json文件输出' . $saveDir . '目录不存在!'); - } - - $name = basename($output, '.json'); - $file = $saveDir . '/' . $name . '.' . $options['type'] . '.json'; - - // 去掉空白 - if ($options['type '] === 'min') { - $data = preg_replace('/(?!\w)\s*?(?!\w)/i', '', $data); - } - - return file_put_contents($file, $data); - } -} diff --git a/libs/str-utils/src/Str.php b/libs/str-utils/src/Str.php deleted file mode 100644 index e24b930..0000000 --- a/libs/str-utils/src/Str.php +++ /dev/null @@ -1,18 +0,0 @@ -body = $content; - } - - /** - * @param string $content - */ - public function write(string $content): void - { - $this->body .= $content; - } - - /** - * @param string $content - */ - public function append(string $content): void - { - $this->write($content); - } - - /** - * @param string $content - */ - public function prepend(string $content): void - { - $this->body = $content . $this->body; - } - - /** - * clear data - */ - public function clear(): string - { - $string = $this->body; - // clear - $this->body = ''; - - return $string; - } - - /** - * @return string - */ - public function getBody(): string - { - return $this->body; - } - - /** - * @param string $body - */ - public function setBody(string $body): void - { - $this->body = $body; - } - - /** - * @return string - */ - public function toString(): string - { - return $this->body; - } - - /** - * @return string - */ - public function __toString() - { - return $this->toString(); - } -} diff --git a/libs/str-utils/src/StringHelper.php b/libs/str-utils/src/StringHelper.php deleted file mode 100644 index 27d7959..0000000 --- a/libs/str-utils/src/StringHelper.php +++ /dev/null @@ -1,1078 +0,0 @@ - '/\S+/', - 'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', - // 'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/', - 'url' => '/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', - 'currency' => '/^\d+(\.\d+)?$/', - # 货币 - 'number' => '/^\d+$/', - 'zip' => '/^\d{6}$/', - 'integer' => '/^[-\+]?\d+$/', - 'double' => '/^[-\+]?\d+(\.\d+)?$/', - 'english' => '/^[A-Za-z]+$/', - ]; - - $value = trim($value); - $name = strtolower($rule); - - // 检查是否有内置的正则表达式 - if (isset($validate[$name])) { - $rule = $validate[$name]; - } - - return preg_match($rule, $value) === 1; - } - - //////////////////////////////////////////////////////////////////////// - /// Check Length - //////////////////////////////////////////////////////////////////////// - - /** - * from Symfony - * - * @param string $string - * - * @return int - */ - public static function len(string $string): int - { - if (false === $encoding = mb_detect_encoding($string, null, true)) { - return strlen($string); - } - - return mb_strwidth($string, $encoding); - } - - public static function strlen(string $str, string $encoding = 'UTF-8'): int - { - $str = html_entity_decode($str, ENT_COMPAT, 'UTF-8'); - - return function_exists('mb_strlen') ? mb_strlen($str, $encoding) : strlen($str); - } - - /** - * @param string $string - * - * @return int - */ - public static function utf8Len(string $string): int - { - // strlen: one chinese is 3 char. - // mb_strlen: one chinese is 1 char. - // mb_strwidth: one chinese is 2 char. - return mb_strlen($string, 'utf-8'); - } - - /** - * 计算字符长度 - * - * @param string $str - * - * @return int - */ - public static function length(string $str): int - { - if ($str === '') { - return 0; - } - - if (function_exists('mb_strlen')) { - return mb_strlen($str, 'utf-8'); - } - - preg_match_all('/./u', $str, $arr); - - return count($arr[0]); - } - - /** - * @from web - * 可以统计中文字符串长度的函数 - * - * @param string $str 要计算长度的字符串 - * - * @return int - * @internal param bool $type 计算长度类型,0(默认)表示一个中文算一个字符,1表示一个中文算两个字符 - */ - public static function absLen(string $str): int - { - if (empty($str)) { - return 0; - } - - if (function_exists('mb_strwidth')) { - return mb_strwidth($str, 'utf-8'); - } - - if (function_exists('mb_strlen')) { - return mb_strlen($str, 'utf-8'); - } - - preg_match_all('/./u', $str, $ar); - - return count($ar[0]); - } - - //////////////////////////////////////////////////////////// - /// Security - //////////////////////////////////////////////////////////// - - /** - * ********************** 生成一定长度的随机字符串函数 ********************** - * - * @param int $length - 随机字符串长度 - * @param array|string $param - - * - * @return string - * @throws Exception - * @internal param string $chars - */ - public static function random(int $length, array $param = []): string - { - $param = array_merge([ - 'prefix' => '', - 'suffix' => '', - 'chars' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' - ], $param); - - $chars = $param['chars']; - $max = strlen($chars) - 1; //strlen($chars) 计算字符串的长度 - $str = ''; - - for ($i = 0; $i < $length; $i++) { - $str .= $chars[random_int(0, $max)]; - } - - return $param['prefix'] . $str . $param['suffix']; - } - - /** - * @param int $length - * - * @return string - */ - public static function genSalt(int $length = 32): string - { - return substr(str_replace('+', '.', base64_encode(hex2bin(random_token($length)))), 0, 44); - } - - /** - * @param int $length - * - * @return bool|string - */ - public static function genUid(int $length = 7): string - { - if (!is_int($length) || $length > 32 || $length < 1) { - $length = 7; - } - - return substr(hash('md5', uniqid('', true)), 0, $length); - } - - /** - * @param string $string - * @param int $padLen - * @param string $padStr - * @param int $padType - * - * @return string - */ - public static function pad(string $string, int $padLen, string $padStr = ' ', int $padType = STR_PAD_RIGHT): string - { - return $padLen > 0 ? str_pad($string, $padLen, $padStr, $padType) : $string; - } - - public static function padLeft(string $string, int $padLen, string $padStr = ' '): string - { - return $padLen > 0 ? str_pad($string, $padLen, $padStr, STR_PAD_LEFT) : $string; - } - - public static function padRight(string $string, int $padLen, string $padStr = ' '): string - { - return $padLen > 0 ? str_pad($string, $padLen, $padStr) : $string; - } - - /** - * gen UUID - * - * @param int $version - * @param null $node - * @param null $ns - * - * @return UUID - * @throws InvalidArgumentException - */ - // public static function genUUID($version = 1, $node = null, $ns = null) - // { - // return UUID::generate($version, $node, $ns); - // } - - //////////////////////////////////////////////////////////////////////// - /// Case Convert - //////////////////////////////////////////////////////////////////////// - - /** - * Convert \n and \r\n and \r to
- * - * @param string $str String to transform - * - * @return string New string - */ - public static function nl2br(string $str): string - { - return str_replace(["\r\n", "\r", "\n"], '
', $str); - } - - public static function lower(string $str): string - { - return static::strtolower($str); - } - - /** - * @param string $str - * - * @return bool|string - */ - public static function strtolower(string $str): string - { - return function_exists('mb_strtolower') ? mb_strtolower($str, 'utf-8') : strtolower($str); - } - - public static function upper(string $str): string - { - return static::strtoupper($str); - } - - /** - * @param $str - * - * @return bool|string - */ - public static function strtoupper(string $str) - { - if (!is_string($str)) { - return $str; - } - - return function_exists('mb_strtoupper') ? mb_strtoupper($str, 'utf-8') : strtoupper($str); - } - - /** - * @param $str - * - * @return string - */ - public static function ucfirst(string $str): string - { - return self::strtoupper(self::substr($str, 0, 1)) . self::substr($str, 1); - } - - /** - * @param $str - * - * @return string - */ - public static function ucwords(string $str): string - { - return function_exists('mb_convert_case') ? mb_convert_case($str, MB_CASE_TITLE) : - ucwords(self::strtolower($str)); - } - - /** - * @param string $str - * @param bool $upperFirstChar - * - * @return mixed - */ - public static function camel(string $str, bool $upperFirstChar = false): string - { - return self::toCamelCase($str, $upperFirstChar); - } - - /** - * @param string $str - * @param bool $upperFirstChar - * - * @return mixed - */ - public static function toCamel(string $str, bool $upperFirstChar = false): string - { - return self::toCamelCase($str, $upperFirstChar); - } - - /** - * to camel - * - * @param string $name - * @param bool $upperFirst - * - * @return string - */ - public static function camelCase(string $name, bool $upperFirst = false): string - { - $name = trim($name, '-_'); - - // convert 'first-second' to 'firstSecond' - if (strpos($name, '-')) { - $name = ucwords(str_replace('-', ' ', $name)); - $name = str_replace(' ', '', lcfirst($name)); - } - - return $upperFirst ? ucfirst($name) : $name; - } - - /** - * Translates a string with underscores into camel case (e.g. first_name -> firstName) - * - * @param string $str - * @param bool $upperFirst - * - * @return mixed - */ - public static function toCamelCase(string $str, bool $upperFirst = false): string - { - $str = (string)self::strtolower($str); - - if ($upperFirst) { - $str = self::ucfirst($str); - } - - return preg_replace_callback('/_+([a-z])/', function ($c) { - return strtoupper($c[1]); - }, $str); - } - - public static function snake(string $str, string $sep = '_'): string - { - return self::toSnakeCase($str, $sep); - } - - public static function toSnake(string $str, string $sep = '_'): string - { - return self::toSnakeCase($str, $sep); - } - - /** - * Transform a CamelCase string to underscore_case string - * - * @param string $str - * @param string $sep - * - * @return string - */ - public static function toSnakeCase(string $str, string $sep = '_'): string - { - // 'CMSCategories' => 'cms_categories' - // 'RangePrice' => 'range_price' - return self::lower(trim(preg_replace('/([A-Z][a-z])/', $sep . '$1', $str), $sep)); - } - - /** - * 驼峰式 <=> 下划线式 - * - * @param string $str [description] - * @param bool $toCamelCase - * true : 驼峰式 => 下划线式 - * false : 驼峰式 <= 下划线式 - * - * @return string - */ - public static function nameChange(string $str, bool $toCamelCase = true): string - { - $str = trim($str); - - // 默认 :下划线式 =>驼峰式 - if ($toCamelCase) { - if (strpos($str, '_') === false) { - return $str; - } - - $arr_char = explode('_', strtolower($str)); - $newString = array_shift($arr_char); - - foreach ($arr_char as $val) { - $newString .= ucfirst($val); - } - - return $newString; - } - - // 驼峰式 => 下划线式 - return strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', $str)); - } - - //////////////////////////////////////////////////////////////////////// - /// Convert to array - //////////////////////////////////////////////////////////////////////// - - /** - * var_dump(str2array('34,56,678, 678, 89, ')); - * - * @param string $str - * @param string $sep - * - * @return array - */ - public static function str2array(string $str, string $sep = ','): array - { - $str = trim($str, "$sep "); - - if (!$str) { - return []; - } - - return preg_split("/\s*$sep\s*/", $str, -1, PREG_SPLIT_NO_EMPTY); - } - - public static function toArray(string $string, string $delimiter = ',', int $limit = 0): array - { - $string = trim($string, "$delimiter "); - if ($string === '') { - return []; - } - - $values = []; - $rawList = $limit < 1 ? explode($delimiter, $string) : explode($delimiter, $string, $limit); - - foreach ($rawList as $val) { - if (($val = trim($val)) !== '') { - $values[] = $val; - } - } - - return $values; - } - - public static function explode(string $str, string $separator = '.', int $limit = 0): array - { - return static::split2Array($str, $separator, $limit); - } - - /** - * @param string $string - * @param string $delimiter - * @param int $limit - * - * @return array - */ - public static function split2Array(string $string, string $delimiter = ',', int $limit = 0): array - { - $string = trim($string, "$delimiter "); - - if (!strpos($string, $delimiter)) { - return [$string]; - } - - if ($limit < 1) { - $list = explode($delimiter, $string); - } else { - $list = explode($delimiter, $string, $limit); - } - - return array_values(array_filter(array_map('trim', $list), 'strlen')); - } - - /** - * @param string $string - * @param int $width - * - * @return array - */ - public static function splitByWidth(string $string, int $width): array - { - // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly. - // additionally, array_slice() is not enough as some character has doubled width. - // we need a function to split string not by character count but by string width - if (false === $encoding = mb_detect_encoding($string, null, true)) { - return str_split($string, $width); - } - - $utf8String = mb_convert_encoding($string, 'utf8', $encoding); - $lines = []; - $line = ''; - - foreach (preg_split('//u', $utf8String) as $char) { - // test if $char could be appended to current line - if (mb_strwidth($line . $char, 'utf8') <= $width) { - $line .= $char; - continue; - } - - // if not, push current line to array and make new line - $lines[] = str_pad($line, $width); - $line = $char; - } - - if ('' !== $line) { - $lines[] = count($lines) ? str_pad($line, $width) : $line; - } - - mb_convert_variables($encoding, 'utf8', $lines); - - return $lines; - } - - //////////////////////////////////////////////////////////////////////// - /// Truncate - //////////////////////////////////////////////////////////////////////// - - /** - * @param string $str - * @param int $start - * @param int|null $length - * @param string $encoding - * - * @return bool|string - */ - public static function substr(string $str, int $start, int $length = null, string $encoding = 'utf-8') - { - if (function_exists('mb_substr')) { - return mb_substr($str, $start, ($length === null ? self::strlen($str) : (int)$length), $encoding); - } - - return substr($str, $start, ($length === null ? self::strlen($str) : (int)$length)); - } - - /** - * @from web - * utf-8编码下截取中文字符串,参数可以参照substr函数 - * - * @param string $str 要进行截取的字符串 - * @param int $start 要进行截取的开始位置,负数为反向截取 - * @param int $end 要进行截取的长度 - * - * @return string - */ - public static function utf8SubStr(string $str, int $start = 0, int $end = null): string - { - if (empty($str)) { - return false; - } - - if (function_exists('mb_substr')) { - if (func_num_args() >= 3) { - $end = func_get_arg(2); - - return mb_substr($str, $start, $end, 'utf-8'); - } - - mb_internal_encoding('UTF-8'); - - return mb_substr($str, $start); - - } - - $null = ''; - preg_match_all('/./u', $str, $ar); - - if (func_num_args() >= 3) { - $end = func_get_arg(2); - return implode($null, array_slice($ar[0], $start, $end)); - } - - return implode($null, array_slice($ar[0], $start)); - } - - - /** - * @from web - * 中文截取,支持gb2312,gbk,utf-8,big5 * - * - * @param string $str 要截取的字串 - * @param int $start 截取起始位置 - * @param int $length 截取长度 - * @param string $charset utf-8|gb2312|gbk|big5 编码 - * @param bool $suffix 是否加尾缀 - * - * @return string - */ - public static function zhSubStr($str, $start = 0, $length = 0, $charset = 'utf-8', $suffix = true): string - { - if (function_exists('mb_substr')) { - if (mb_strlen($str, $charset) <= $length) { - return $str; - } - - $slice = mb_substr($str, $start, $length, $charset); - } else { - $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; - $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; - $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; - $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; - - preg_match_all($re[$charset], $str, $match); - if (count($match[0]) <= $length) { - return $str; - } - - $slice = implode('', array_slice($match[0], $start, $length)); - } - - return (bool)$suffix ? $slice . '…' : $slice; - } - - /** - * Truncate strings - * - * @param string $str - * @param int $maxLength Max length - * @param string $suffix Suffix optional - * - * @return string $str truncated - */ - /* CAUTION : Use it only on module hookEvents. - ** For other purposes use the smarty function instead */ - public static function truncate(string $str, $maxLength, $suffix = '...'): string - { - if (self::strlen($str) <= $maxLength) { - return $str; - } - - $str = utf8_decode($str); - - return utf8_encode(substr($str, 0, $maxLength - self::strlen($suffix)) . $suffix); - } - - /** - * 字符截断输出 - * - * @param string $str - * @param int $start - * @param null|int $length - * - * @return string - */ - public static function truncate2(string $str, int $start, int $length = null): string - { - if (!$length) { - $length = $start; - $start = 0; - } - - if (strlen($str) <= $length) { - return $str; - } - - if (function_exists('mb_substr')) { - $str = mb_substr(strip_tags($str), $start, $length, 'utf-8'); - } else { - $str = substr($str, $start, $length) . '...'; - } - - return $str; - } - - /** - * Copied from CakePHP String utility file - * - * @param string $text - * @param int $length - * @param array $options - * - * @return bool|string - */ - public static function truncate3(string $text, int $length = 120, array $options = []) - { - $default = [ - 'ellipsis' => '...', - 'exact' => true, - 'html' => true - ]; - - $options = array_merge($default, $options); - $ellipsis = $options['ellipsis']; - $exact = $options['exact']; - $html = $options['html']; - - /** - * @var string $ellipsis - * @var bool $exact - * @var bool $html - */ - if ($html) { - if (self::strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { - return $text; - } - - $total_length = self::strlen(strip_tags($ellipsis)); - $open_tags = $tags = []; - $truncate = ''; - preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER); - - foreach ($tags as $tag) { - if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/', $tag[2])) { - if (preg_match('/<[\w]+[^>]*>/', $tag[0])) { - array_unshift($open_tags, $tag[2]); - } elseif (preg_match('/<\/([\w]+)[^>]*>/', $tag[0], $close_tag)) { - $pos = array_search($close_tag[1], $open_tags, true); - if ($pos !== false) { - array_splice($open_tags, $pos, 1); - } - } - } - $truncate .= $tag[1]; - $content_length = self::strlen(preg_replace('/&[0-9a-z]{2,8};|&#[\d]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', - $tag[3])); - - if ($content_length + $total_length > $length) { - $left = $length - $total_length; - $entities_length = 0; - - if (preg_match_all('/&[0-9a-z]{2,8};|&#[\d]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, - PREG_OFFSET_CAPTURE) - ) { - foreach ((array)$entities[0] as $entity) { - if ($entity[1] + 1 - $entities_length <= $left) { - $left--; - $entities_length += self::strlen($entity[0]); - } else { - break; - } - } - } - - $truncate .= self::substr($tag[3], 0, $left + $entities_length); - break; - } - - $truncate .= $tag[3]; - $total_length += $content_length; - - if ($total_length >= $length) { - break; - } - } - } else { - if (self::strlen($text) <= $length) { - return $text; - } - - $truncate = self::substr($text, 0, $length - self::strlen($ellipsis)); - } - - $open_tags = null; - - if (!$exact) { - $spacepos = self::strrpos($truncate, ' '); - if ($html) { - $truncate_check = self::substr($truncate, 0, $spacepos); - $last_open_tag = self::strrpos($truncate_check, '<'); - $last_close_tag = self::strrpos($truncate_check, '>'); - - if ($last_open_tag > $last_close_tag) { - preg_match_all('/<[\w]+[^>]*>/', $truncate, $last_tag_matches); - $last_tag = array_pop($last_tag_matches[0]); - $spacepos = self::strrpos($truncate, $last_tag) + self::strlen($last_tag); - } - - $bits = self::substr($truncate, $spacepos); - preg_match_all('/<\/([a-z]+)>/', $bits, $dropped_tags, PREG_SET_ORDER); - - /** @var array $dropped_tags */ - if (!empty($dropped_tags)) { - if (!empty($open_tags)) { - foreach ($dropped_tags as $closing_tag) { - if (!in_array($closing_tag[1], $open_tags, true)) { - array_unshift($open_tags, $closing_tag[1]); - } - } - } else { - foreach ($dropped_tags as $closing_tag) { - $open_tags[] = $closing_tag[1]; - } - } - } - } - - $truncate = self::substr($truncate, 0, $spacepos); - } - - $truncate .= $ellipsis; - - if ($html && $open_tags) { - foreach ((array)$open_tags as $tag) { - $truncate .= ''; - } - } - - return $truncate; - } - - //////////////////////////////////////////////////////////////////////// - /// Format - //////////////////////////////////////////////////////////////////////// - - /** - * [format description] - * - * @param $str - * @param array $replaceParams 用于 str_replace('search','replace',$str ) - * @param array $pregParams 用于 preg_replace('pattern','replace',$str) - * - * @return string [type] [description] - * @example - * $pregParams = [ - * 'xx', //'pattern' - * 'yy', //'replace' - * ] - * * $pregParams = [ - * ['xx','xx2'], //'pattern' - * ['yy','yy2'], //'replace' - * ] - * @example - * $replaceParams = [ - * 'xx', //'search' - * 'yy', //'replace' - * ] - * $replaceParams = [ - * ['xx','xx2'], //'search' - * ['yy','yy2'], //'replace' - * ] - */ - public static function format($str, array $replaceParams = [], array $pregParams = []): string - { - if (!is_string($str) || !$str || (!$replaceParams && !$pregParams)) { - return $str; - } - - if ($replaceParams && count($replaceParams) === 2) { - [$search, $replace] = $replaceParams; - $str = str_replace($search, $replace, $str); - } - - if ($pregParams && count($pregParams) === 2) { - [$pattern, $replace] = $pregParams; - $str = preg_replace($pattern, $replace, $str); - } - - return trim($str); - } - - /** - * 格式化,用空格分隔各个词组 - * - * @param string $keyword 字符串 - * - * @return string 格式化后的字符串 - */ - public static function wordFormat($keyword): string - { - // 将全角角逗号换为空格 - $keyword = str_replace([',', ','], ' ', $keyword); - - return preg_replace([ - // 去掉两个空格以上的 - '/\s(?=\s)/', - // 将非空格替换为一个空格 - '/[\n\r\t]/' - ], ['', ' '], trim($keyword)); - } - - /** - * 缩进格式化内容,去空白/注释 - * - * @param $fileName - * @param int $type - * - * @return mixed - */ - public static function deleteStripSpace($fileName, $type = 0) - { - $data = trim(file_get_contents($fileName)); - $data = 0 === strpos($data, '' ? substr($data, 0, -2) : $data; - - //去掉所有注释 换行空白保留 - if ((int)$type === 1) { - $preg_arr = [ - '/\/\*.*?\*\/\s*/is' // 去掉所有多行注释/* .... */ - , - '/\/\/.*?[\r\n]/is' // 去掉所有单行注释//.... - , - '/\#.*?[\r\n]/is' // 去掉所有单行注释 #.... - ]; - - return preg_replace($preg_arr, '', $data); - } - - $preg_arr = [ - '/\/\*.*?\*\/\s*/is' // 去掉所有多行注释 /* .... */ - , - '/\/\/.*?[\r\n]/is' // 去掉所有单行注释 //.... - , - '/\#.*?[\r\n]/is' // 去掉所有单行注释 #.... - , - '/(?!\w)\s*?(?!\w)/is' //去掉空白行 - ]; - - return preg_replace($preg_arr, '', $data); - } -} diff --git a/libs/str-utils/src/Token.php b/libs/str-utils/src/Token.php deleted file mode 100644 index b4de0a7..0000000 --- a/libs/str-utils/src/Token.php +++ /dev/null @@ -1,210 +0,0 @@ -query(['name' => $_POST['name'] ]); - * 1. - * gen: - * $password = Token::gen('123456'); - * verify: - * Token::verify($user['password'], '123456'); - * 2. - * gen: - * $password = Token::hash('123456'); - * verify: - * Token::verifyHash($user['password'], '123456'); - */ -class Token -{ - /** - * 指明应该使用的算法 - * $2a BLOWFISH算法。 - * $5 SHA-256 - * $6 SHA-512 - * - * @var string - */ - private static $algo = '$2y'; - - /** - * cost parameter 就是成本参数 - * $10 这是以2为底的对数,指示计算循环迭代的次数(10 => 2^10 = 1024),取值可以从04到31。 - * - * @var string - */ - private static $cost = '$10'; - - /** - * *******生成唯一序列号******* - * - * @param $var array || obj - * - * @return string - */ - public static function md5($var): string - { - //serialize()序列化,串行化 - return md5(md5(serialize($var))); - } - - /** - * @return string - */ - public static function uniqueSalt(): string - { - return (string)substr(sha1(mt_rand()), 0, 22); - } - - /** - * @param string $pwd - * @param string $algo - * @param array $opts - * - * @return bool|string - */ - public static function pwdHash(string $pwd, string $algo, array $opts = []) - { - $opts = array_merge([ - 'cost' => 9 - ], $opts); - - return password_hash($pwd, $algo, $opts); - } - - /** - * @param string $pwd - * @param string $hash - * - * @return bool|string - */ - public static function pwdVerify(string $pwd, string $hash) - { - return password_verify($pwd, $hash); - } - - /** - * this will be used to generate a hash - * - * @param $password - * - * @return string - */ - public static function gen(string $password): string - { - return crypt($password, self::$algo . self::$cost . '$' . self::uniqueSalt()); - } - - /** - * this will be used to compare a password against a hash - * - * @param string $hash - * @param string $password the user input - * - * @return bool - */ - public static function verify(string $hash, string $password): bool - { - return hash_equals($hash, crypt($password, $hash)); - } - - /** - * 2 生成 - * - * @param $password - * @param int $cost - * - * @return string - * @throws RuntimeException - * @todo from php.net - */ - public static function hash(string $password, int $cost = 11): string - { - // $bytes = \random_bytes(17); - $bytes = openssl_random_pseudo_bytes(17, $cStrong); - - if (false === $bytes || false === $cStrong) { - throw new RuntimeException('exec gen hash error!'); - } - - /* To generate the salt, first generate enough random bytes. Because - * base64 returns one character for each 6 bits, the we should generate - * at least 22*6/8=16.5 bytes, so we generate 17. Then we get the first - * 22 base64 characters - */ - $salt = substr(base64_encode($bytes), 0, 22); - /* As blowfish takes a salt with the alphabet ./A-Za-z0-9 we have to - * replace any '+' in the base64 string with '.'. We don't have to do - * anything about the '=', as this only occurs when the b64 string is - * padded, which is always after the first 22 characters. - */ - $salt = str_replace('+', '.', $salt); - /* Next, create a string that will be passed to crypt, containing all - * of the settings, separated by dollar signs - */ - $param = '$' . implode('$', [ - '2x', //select the most secure version of blowfish (>=PHP 5.3.7) - str_pad($cost, 2, '0', STR_PAD_LEFT), //add the cost in two digits - $salt //add the salt - ]); - - //now do the actual hashing - return crypt($password, $param); - } - - /** - * 2 验证 - * Check the password against a hash generated by the generate_hash - * function. - * - * @param $hash - * @param $password - * - * @return bool - */ - public static function verifyHash(string $hash, string $password): bool - { - /* Regenerating the with an available hash as the options parameter should - * produce the same hash if the same password is passed. - */ - return crypt($password, $hash) === $hash; - } - - /** - * 生成guid - * - * @return string - */ - public static function GUID(): string - { - mt_srand((double)microtime() * 10000); - - $charId = strtolower(md5(uniqid(mt_rand(), true))); - // $hyphen = chr(45); - $uuid = substr($charId, 0, 8) . substr($charId, 8, 4) . substr($charId, 12, 4) . substr($charId, 16, - 4) . substr($charId, 20, 12); - - return $uuid; - } - -} diff --git a/libs/str-utils/src/UUID.php b/libs/str-utils/src/UUID.php deleted file mode 100644 index d0198bd..0000000 --- a/libs/str-utils/src/UUID.php +++ /dev/null @@ -1,472 +0,0 @@ -bytes = $uuid; - - // Optimize the most common use - $this->string = bin2hex(substr($uuid, 0, 4)) . '-' . bin2hex(substr($uuid, 4, 2)) . '-' . bin2hex(substr($uuid, - 6, 2)) . '-' . bin2hex(substr($uuid, 8, 2)) . '-' . bin2hex(substr($uuid, 10, 6)); - } - - /** - * Generates a Version 1 UUID. - * These are derived from the time at which they were generated. - * - * @param string $node - * - * @return string - * @throws Exception - */ - protected static function mintTime(string $node = null): string - { - /** Get time since Gregorian calendar reform in 100ns intervals - * This is exceedingly difficult because of PHP's (and pack()'s) - * integer size limits. - * Note that this will never be more accurate than to the microsecond. - */ - $time = microtime(1) * 10000000 + static::INTERVAL; - - // Convert to a string representation - $time = sprintf('%F', $time); - - //strip decimal point - preg_match("/^\d+/", $time, $time); - - // And now to a 64-bit binary representation - $time = base_convert($time[0], 10, 16); - $time = pack('H*', str_pad($time, 16, '0', STR_PAD_LEFT)); - - // Reorder bytes to their proper locations in the UUID - $uuid = $time[4] . $time[5] . $time[6] . $time[7] . $time[2] . $time[3] . $time[0] . $time[1]; - - // Generate a random clock sequence - $uuid .= static::randomBytes(2); - - // set variant - $uuid[8] = chr(ord($uuid[8]) & static::CLEAR_VAR | static::VAR_RFC); - - // set version - $uuid[6] = chr(ord($uuid[6]) & static::CLEAR_VER | static::VERSION_1); - - // Set the final 'node' parameter, a MAC address - if (null !== $node) { - $node = static::makeBin($node, 6); - } - - // If no node was provided or if the node was invalid, - // generate a random MAC address and set the multicast bit - if (null === $node) { - $node = static::randomBytes(6); - $node[0] = pack('C', ord($node[0]) | 1); - } - - $uuid .= $node; - return $uuid; - } - - /** - * Randomness is returned as a string of bytes - * - * @param int $bytes - * - * @return string - * @throws Exception - */ - public static function randomBytes($bytes): string - { - return random_bytes($bytes); - } - - /** - * Insure that an input string is either binary or hexadecimal. - * Returns binary representation, or false on failure. - * - * @param string|self $str - * @param integer $len - * - * @return string|null - */ - protected static function makeBin($str, $len): ?string - { - if ($str instanceof self) { - return $str->bytes; - } - - if (strlen($str) === $len) { - return $str; - } - - $str = (string)preg_replace([ - // strip URN scheme and namespace - '/^urn:uuid:/is', - // strip non-hex characters - '/[^a-f0-9]/is', - ], '', $str); - - if (strlen($str) !== ($len * 2)) { - return null; - } - - return pack('H*', $str); - } - - /** - * Generates a Version 3 or Version 5 UUID. - * These are derived from a hash of a name and its namespace, in binary form. - * - * @param int $ver - * @param string $node - * @param string|null $ns - * - * @return string - * @throws InvalidArgumentException - */ - protected static function mintName($ver, $node, $ns): string - { - if (empty($node)) { - throw new InvalidArgumentException('A name-string is required for Version 3 or 5 UUIDs.'); - } - - // if the namespace UUID isn't binary, make it so - $ns = static::makeBin($ns, 16); - if (null === $ns) { - throw new InvalidArgumentException('A binary namespace is required for Version 3 or 5 UUIDs.'); - } - - $version = $uuid = null; - - switch ($ver) { - case static::MD5: - $version = static::VERSION_3; - $uuid = md5($ns . $node, 1); - break; - case static::SHA1: - $version = static::VERSION_5; - $uuid = substr(sha1($ns . $node, 1), 0, 16); - break; - default: - // no default really required here - } - - // set variant - $uuid[8] = chr(ord($uuid[8]) & static::CLEAR_VAR | static::VAR_RFC); - - // set version - $uuid[6] = chr(ord($uuid[6]) & static::CLEAR_VER | $version); - - return $uuid; - } - - /** - * Generate a Version 4 UUID. - * These are derived solely from random numbers. - * generate random fields - * - * @return string - * @throws Exception - */ - protected static function mintRand(): string - { - $uuid = static::randomBytes(16); - // set variant - $uuid[8] = chr(ord($uuid[8]) & static::CLEAR_VAR | static::VAR_RFC); - // set version - $uuid[6] = chr(ord($uuid[6]) & static::CLEAR_VER | static::VERSION_4); - - return $uuid; - } - - /** - * Import an existing UUID - * - * @param string $uuid - * - * @return Uuid - * @throws InvalidArgumentException - */ - public static function import(string $uuid): UUID - { - return new static(static::makeBin($uuid, 16)); - } - - /** - * Compares the binary representations of two UUIDs. - * The comparison will return true if they are bit-exact, - * or if neither is valid. - * - * @param string $a - * @param string $b - * - * @return string|string - */ - public static function compare(string $a, string $b): string - { - return static::makeBin($a, 16) === static::makeBin($b, 16); - } - - /** - * Import and validate an UUID - * - * @param Uuid|string $uuid - * - * @return boolean - * @throws InvalidArgumentException - */ - public static function validate(string $uuid): bool - { - return (boolean)preg_match('~' . static::VALID_UUID_REGEX . '~', static::import($uuid)->string); - } - - public function __isset($var) - { - // - } - - public function __set($var, $val) - { - // - } - - /** - * @param string $var - * - * @return string|int|NULL - */ - public function __get(string $var) - { - switch ($var) { - case 'bytes': - return $this->bytes; - break; - case 'hex': - return bin2hex($this->bytes); - break; - case 'node': - if (ord($this->bytes[6]) >> 4 === 1) { - return bin2hex(substr($this->bytes, 10)); - } - - return null; - break; - case 'string': - return $this->__toString(); - break; - case 'time': - if (ord($this->bytes[6]) >> 4 === 1) { - // Restore contiguous big-endian byte order - $time = bin2hex($this->bytes[6] . $this->bytes[7] . $this->bytes[4] . $this->bytes[5] . $this->bytes[0] . $this->bytes[1] . $this->bytes[2] . $this->bytes[3]); - // Clear version flag - $time[0] = '0'; - - // Do some reverse arithmetic to get a Unix timestamp - return (hexdec($time) - static::INTERVAL) / 10000000; - } - - break; - case 'urn': - return 'urn:uuid:' . $this->__toString(); - break; - case 'variant': - $byte = ord($this->bytes[8]); - if ($byte >= static::VAR_RES) { - return 3; - } - - if ($byte >= static::VAR_MS) { - return 2; - } - - if ($byte >= static::VAR_RFC) { - return 1; - } - - return 0; - break; - case 'version': - return ord($this->bytes[6]) >> 4; - break; - default: - return null; - break; - } - - return null; - } - - /** - * Return the UUID - * - * @return string - */ - public function __toString() - { - return $this->string; - } -} diff --git a/libs/str-utils/src/UrlHelper.php b/libs/str-utils/src/UrlHelper.php deleted file mode 100644 index 7450510..0000000 --- a/libs/str-utils/src/UrlHelper.php +++ /dev/null @@ -1,242 +0,0 @@ - 0; - } else { - $opts = [ - 'http' => ['timeout' => 5,] - ]; - $context = stream_context_create($opts); - $resource = file_get_contents($url, false, $context); - - return (bool)$resource; - } - - return false; - } - - // Build arrays of values we need to decode before parsing - protected static $entities = [ - '%21', - '%2A', - '%27', - '%28', - '%29', - '%3B', - '%3A', - '%40', - '%26', - '%3D', - '%24', - '%2C', - '%2F', - '%3F', - '%23', - '%5B', - '%5D' - ]; - - protected static $replacements = [ - '!', - '*', - "'", - '(', - ')', - ';', - ':', - '@', - '&', - '=', - '$', - ',', - '/', - '?', - '#', - '[', - ']' - ]; - - public static function parseUrl(string $url): array - { - $result = []; - - // Create encoded URL with special URL characters decoded so it can be parsed - // All other characters will be encoded - $encodedURL = str_replace(self::$entities, self::$replacements, urlencode($url)); - - // Parse the encoded URL - $encodedParts = parse_url($encodedURL); - - // Now, decode each value of the resulting array - if ($encodedParts) { - foreach ((array)$encodedParts as $key => $value) { - $result[$key] = urldecode(str_replace(self::$replacements, self::$entities, $value)); - } - } - - return $result; - } - - /** - * url_encode form urlencode(),但是 : / ? & = ...... 几个符号不会被转码为 %3A %2F %3F %26 %3D ...... - * $url="ftp://ud03:password@www.xxx.net/中文/中文.rar"; - * $url1 = url_encode1($url); - * //ftp://ud03:password@www.xxx.net/%E4%B8%AD%E6%96%87/%E4%B8%AD%E6%96%87.rar - * $url2 = urldecode($url); - * echo $url1.PHP_EOL.$url2.PHP_EOL; - * - * @param $url - * - * @return mixed|string [type] [description] - */ - public static function encode(string $url) - { - $url = trim($url); - - if ($url === '') { - return $url; - } - - // 若已被编码的url,将被解码,再继续重新编码 - $url = urldecode($url); - $encodeUrl = urlencode($url); - $encodeUrl = str_replace(self::$entities, self::$replacements, $encodeUrl); - - return $encodeUrl; - } - - /** - * [urlEncode 会先转换编码] - * $url="ftp://ud03:password@www.xxx.net/中文/中文.rar"; - * $url1 = url_encode($url); - * //ftp://ud03:password@www.xxx.net/%C3%A4%C2%B8%C2%AD%C3%A6%C2%96%C2%87/%C3%A4%C2%B8%C2%AD%C3%A6%C2%96%C2%87.rar - * $url2 = urldecode($url); - * echo $url1.PHP_EOL.$url2; - * - * @param string $url [description] - * - * @return mixed|string [type] [description] - */ - public static function encode2(string $url) - { - if (!$url = trim($url)) { - return $url; - } - - // 若已被编码的url,将被解码,再继续重新编码 - $url = urldecode($url); - $encodeUrl = rawurlencode(mb_convert_encoding($url, 'utf-8')); - // $url = rawurlencode($url); - $encodeUrl = str_replace(self::$entities, self::$replacements, $encodeUrl); - - return $encodeUrl; - } -} diff --git a/libs/str-utils/test/boot.php b/libs/str-utils/test/boot.php deleted file mode 100644 index b00f6f4..0000000 --- a/libs/str-utils/test/boot.php +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - test/ - - - - - - src - - - diff --git a/libs/autoload.php b/src/autoload.php similarity index 100% rename from libs/autoload.php rename to src/autoload.php diff --git a/libs/arr-utils/.gitignore b/src/collection/.gitignore similarity index 100% rename from libs/arr-utils/.gitignore rename to src/collection/.gitignore diff --git a/libs/arr-utils/LICENSE b/src/collection/LICENSE similarity index 100% rename from libs/arr-utils/LICENSE rename to src/collection/LICENSE diff --git a/libs/collection/README.md b/src/collection/README.md similarity index 100% rename from libs/collection/README.md rename to src/collection/README.md diff --git a/libs/collection/composer.json b/src/collection/composer.json similarity index 100% rename from libs/collection/composer.json rename to src/collection/composer.json diff --git a/libs/arr-utils/phpunit.xml.dist b/src/collection/phpunit.xml.dist similarity index 100% rename from libs/arr-utils/phpunit.xml.dist rename to src/collection/phpunit.xml.dist diff --git a/libs/collection/src/ActiveData.php b/src/collection/src/ActiveData.php similarity index 100% rename from libs/collection/src/ActiveData.php rename to src/collection/src/ActiveData.php diff --git a/libs/collection/src/Collection.php b/src/collection/src/Collection.php similarity index 100% rename from libs/collection/src/Collection.php rename to src/collection/src/Collection.php diff --git a/libs/collection/src/CollectionInterface.php b/src/collection/src/CollectionInterface.php similarity index 100% rename from libs/collection/src/CollectionInterface.php rename to src/collection/src/CollectionInterface.php diff --git a/libs/collection/src/Configuration.php b/src/collection/src/Configuration.php similarity index 100% rename from libs/collection/src/Configuration.php rename to src/collection/src/Configuration.php diff --git a/libs/collection/src/JsonMessage.php b/src/collection/src/JsonMessage.php similarity index 100% rename from libs/collection/src/JsonMessage.php rename to src/collection/src/JsonMessage.php diff --git a/libs/collection/src/Language.php b/src/collection/src/Language.php similarity index 100% rename from libs/collection/src/Language.php rename to src/collection/src/Language.php diff --git a/libs/collection/src/LiteCollection.php b/src/collection/src/LiteCollection.php similarity index 100% rename from libs/collection/src/LiteCollection.php rename to src/collection/src/LiteCollection.php diff --git a/libs/collection/src/SimpleCollection.php b/src/collection/src/SimpleCollection.php similarity index 100% rename from libs/collection/src/SimpleCollection.php rename to src/collection/src/SimpleCollection.php diff --git a/libs/collection/test/LanguageTest.php b/src/collection/test/LanguageTest.php similarity index 100% rename from libs/collection/test/LanguageTest.php rename to src/collection/test/LanguageTest.php diff --git a/libs/collection/test/boot.php b/src/collection/test/boot.php similarity index 100% rename from libs/collection/test/boot.php rename to src/collection/test/boot.php diff --git a/libs/collection/test/testdata/en/response.php b/src/collection/test/testdata/en/response.php similarity index 100% rename from libs/collection/test/testdata/en/response.php rename to src/collection/test/testdata/en/response.php diff --git a/libs/collection/test/testdata/zh-CN/response.php b/src/collection/test/testdata/zh-CN/response.php similarity index 100% rename from libs/collection/test/testdata/zh-CN/response.php rename to src/collection/test/testdata/zh-CN/response.php diff --git a/libs/collection/.gitignore b/src/data-parser/.gitignore similarity index 100% rename from libs/collection/.gitignore rename to src/data-parser/.gitignore diff --git a/libs/cli-utils/LICENSE b/src/data-parser/LICENSE similarity index 100% rename from libs/cli-utils/LICENSE rename to src/data-parser/LICENSE diff --git a/libs/data-parser/README.md b/src/data-parser/README.md similarity index 100% rename from libs/data-parser/README.md rename to src/data-parser/README.md diff --git a/libs/data-parser/composer.json b/src/data-parser/composer.json similarity index 100% rename from libs/data-parser/composer.json rename to src/data-parser/composer.json diff --git a/libs/data-parser/phpunit.xml.dist b/src/data-parser/phpunit.xml.dist similarity index 100% rename from libs/data-parser/phpunit.xml.dist rename to src/data-parser/phpunit.xml.dist diff --git a/libs/data-parser/src/AbstractDataParser.php b/src/data-parser/src/AbstractDataParser.php similarity index 100% rename from libs/data-parser/src/AbstractDataParser.php rename to src/data-parser/src/AbstractDataParser.php diff --git a/libs/data-parser/src/DataParserAwareTrait.php b/src/data-parser/src/DataParserAwareTrait.php similarity index 100% rename from libs/data-parser/src/DataParserAwareTrait.php rename to src/data-parser/src/DataParserAwareTrait.php diff --git a/libs/data-parser/src/DataParserInterface.php b/src/data-parser/src/DataParserInterface.php similarity index 100% rename from libs/data-parser/src/DataParserInterface.php rename to src/data-parser/src/DataParserInterface.php diff --git a/libs/data-parser/src/JsonParser.php b/src/data-parser/src/JsonParser.php similarity index 100% rename from libs/data-parser/src/JsonParser.php rename to src/data-parser/src/JsonParser.php diff --git a/libs/data-parser/src/MsgPackParser.php b/src/data-parser/src/MsgPackParser.php similarity index 100% rename from libs/data-parser/src/MsgPackParser.php rename to src/data-parser/src/MsgPackParser.php diff --git a/libs/data-parser/src/PhpParser.php b/src/data-parser/src/PhpParser.php similarity index 100% rename from libs/data-parser/src/PhpParser.php rename to src/data-parser/src/PhpParser.php diff --git a/libs/data-parser/src/SwooleParser.php b/src/data-parser/src/SwooleParser.php similarity index 100% rename from libs/data-parser/src/SwooleParser.php rename to src/data-parser/src/SwooleParser.php diff --git a/libs/data-parser/test/JsonParserTest.php b/src/data-parser/test/JsonParserTest.php similarity index 100% rename from libs/data-parser/test/JsonParserTest.php rename to src/data-parser/test/JsonParserTest.php diff --git a/libs/data-parser/test/PhpParserTest.php b/src/data-parser/test/PhpParserTest.php similarity index 100% rename from libs/data-parser/test/PhpParserTest.php rename to src/data-parser/test/PhpParserTest.php diff --git a/libs/data-parser/test/boot.php b/src/data-parser/test/boot.php similarity index 100% rename from libs/data-parser/test/boot.php rename to src/data-parser/test/boot.php diff --git a/libs/dev-helper/Console/DevController.php b/src/dev-helper/Console/DevController.php similarity index 100% rename from libs/dev-helper/Console/DevController.php rename to src/dev-helper/Console/DevController.php diff --git a/libs/data-parser/.gitignore b/src/di/.gitignore similarity index 100% rename from libs/data-parser/.gitignore rename to src/di/.gitignore diff --git a/libs/collection/LICENSE b/src/di/LICENSE similarity index 100% rename from libs/collection/LICENSE rename to src/di/LICENSE diff --git a/libs/di/README.md b/src/di/README.md similarity index 100% rename from libs/di/README.md rename to src/di/README.md diff --git a/libs/di/composer.json b/src/di/composer.json similarity index 100% rename from libs/di/composer.json rename to src/di/composer.json diff --git a/libs/di/example/di.php b/src/di/example/di.php similarity index 100% rename from libs/di/example/di.php rename to src/di/example/di.php diff --git a/libs/cli-utils/phpunit.xml.dist b/src/di/phpunit.xml.dist similarity index 100% rename from libs/cli-utils/phpunit.xml.dist rename to src/di/phpunit.xml.dist diff --git a/libs/di/src/CallableResolver.php b/src/di/src/CallableResolver.php similarity index 100% rename from libs/di/src/CallableResolver.php rename to src/di/src/CallableResolver.php diff --git a/libs/di/src/CallableResolverAwareTrait.php b/src/di/src/CallableResolverAwareTrait.php similarity index 100% rename from libs/di/src/CallableResolverAwareTrait.php rename to src/di/src/CallableResolverAwareTrait.php diff --git a/libs/di/src/Container.php b/src/di/src/Container.php similarity index 100% rename from libs/di/src/Container.php rename to src/di/src/Container.php diff --git a/libs/di/src/DIManager.php b/src/di/src/DIManager.php similarity index 100% rename from libs/di/src/DIManager.php rename to src/di/src/DIManager.php diff --git a/libs/di/src/Exception/DependencyResolutionException.php b/src/di/src/Exception/DependencyResolutionException.php similarity index 100% rename from libs/di/src/Exception/DependencyResolutionException.php rename to src/di/src/Exception/DependencyResolutionException.php diff --git a/libs/di/src/Exception/NotFoundException.php b/src/di/src/Exception/NotFoundException.php similarity index 100% rename from libs/di/src/Exception/NotFoundException.php rename to src/di/src/Exception/NotFoundException.php diff --git a/libs/di/src/NameAliasTrait.php b/src/di/src/NameAliasTrait.php similarity index 100% rename from libs/di/src/NameAliasTrait.php rename to src/di/src/NameAliasTrait.php diff --git a/libs/di/src/ObjectItem.php b/src/di/src/ObjectItem.php similarity index 100% rename from libs/di/src/ObjectItem.php rename to src/di/src/ObjectItem.php diff --git a/libs/di/src/ServiceProviderInterface.php b/src/di/src/ServiceProviderInterface.php similarity index 100% rename from libs/di/src/ServiceProviderInterface.php rename to src/di/src/ServiceProviderInterface.php diff --git a/libs/di/test/ContainerTest.php b/src/di/test/ContainerTest.php similarity index 100% rename from libs/di/test/ContainerTest.php rename to src/di/test/ContainerTest.php diff --git a/libs/di/test/MakeByMethod.php b/src/di/test/MakeByMethod.php similarity index 100% rename from libs/di/test/MakeByMethod.php rename to src/di/test/MakeByMethod.php diff --git a/libs/di/test/MakeByStatic.php b/src/di/test/MakeByStatic.php similarity index 100% rename from libs/di/test/MakeByStatic.php rename to src/di/test/MakeByStatic.php diff --git a/libs/di/test/SomeClass.php b/src/di/test/SomeClass.php similarity index 100% rename from libs/di/test/SomeClass.php rename to src/di/test/SomeClass.php diff --git a/libs/di/test/boot.php b/src/di/test/boot.php similarity index 100% rename from libs/di/test/boot.php rename to src/di/test/boot.php diff --git a/libs/di/.gitignore b/src/file-parse/.gitignore similarity index 100% rename from libs/di/.gitignore rename to src/file-parse/.gitignore diff --git a/libs/data-parser/LICENSE b/src/file-parse/LICENSE similarity index 100% rename from libs/data-parser/LICENSE rename to src/file-parse/LICENSE diff --git a/libs/file-parse/README.md b/src/file-parse/README.md similarity index 100% rename from libs/file-parse/README.md rename to src/file-parse/README.md diff --git a/libs/file-parse/composer.json b/src/file-parse/composer.json similarity index 100% rename from libs/file-parse/composer.json rename to src/file-parse/composer.json diff --git a/libs/file-parse/phpunit.xml.dist b/src/file-parse/phpunit.xml.dist similarity index 100% rename from libs/file-parse/phpunit.xml.dist rename to src/file-parse/phpunit.xml.dist diff --git a/libs/file-parse/src/BaseParser.php b/src/file-parse/src/BaseParser.php similarity index 100% rename from libs/file-parse/src/BaseParser.php rename to src/file-parse/src/BaseParser.php diff --git a/libs/file-parse/src/IniParser.php b/src/file-parse/src/IniParser.php similarity index 100% rename from libs/file-parse/src/IniParser.php rename to src/file-parse/src/IniParser.php diff --git a/libs/file-parse/src/JsonParser.php b/src/file-parse/src/JsonParser.php similarity index 100% rename from libs/file-parse/src/JsonParser.php rename to src/file-parse/src/JsonParser.php diff --git a/libs/file-parse/src/YmlParser.php b/src/file-parse/src/YmlParser.php similarity index 100% rename from libs/file-parse/src/YmlParser.php rename to src/file-parse/src/YmlParser.php diff --git a/libs/file-parse/test/IniParserTest.php b/src/file-parse/test/IniParserTest.php similarity index 100% rename from libs/file-parse/test/IniParserTest.php rename to src/file-parse/test/IniParserTest.php diff --git a/libs/file-parse/test/boot.php b/src/file-parse/test/boot.php similarity index 100% rename from libs/file-parse/test/boot.php rename to src/file-parse/test/boot.php diff --git a/libs/file-parse/test/data/include.ini b/src/file-parse/test/data/include.ini similarity index 100% rename from libs/file-parse/test/data/include.ini rename to src/file-parse/test/data/include.ini diff --git a/libs/file-parse/test/data/test.ini b/src/file-parse/test/data/test.ini similarity index 100% rename from libs/file-parse/test/data/test.ini rename to src/file-parse/test/data/test.ini diff --git a/libs/file-parse/.gitignore b/src/file-utils/.gitignore similarity index 100% rename from libs/file-parse/.gitignore rename to src/file-utils/.gitignore diff --git a/libs/di/LICENSE b/src/file-utils/LICENSE similarity index 100% rename from libs/di/LICENSE rename to src/file-utils/LICENSE diff --git a/libs/file-utils/README.md b/src/file-utils/README.md similarity index 100% rename from libs/file-utils/README.md rename to src/file-utils/README.md diff --git a/libs/file-utils/composer.json b/src/file-utils/composer.json similarity index 100% rename from libs/file-utils/composer.json rename to src/file-utils/composer.json diff --git a/libs/file-utils/example/dir-watcher.php b/src/file-utils/example/dir-watcher.php similarity index 100% rename from libs/file-utils/example/dir-watcher.php rename to src/file-utils/example/dir-watcher.php diff --git a/libs/file-utils/example/file-finder.php b/src/file-utils/example/file-finder.php similarity index 100% rename from libs/file-utils/example/file-finder.php rename to src/file-utils/example/file-finder.php diff --git a/libs/file-utils/phpunit.xml.dist b/src/file-utils/phpunit.xml.dist similarity index 100% rename from libs/file-utils/phpunit.xml.dist rename to src/file-utils/phpunit.xml.dist diff --git a/libs/file-utils/src/Directory.php b/src/file-utils/src/Directory.php similarity index 100% rename from libs/file-utils/src/Directory.php rename to src/file-utils/src/Directory.php diff --git a/libs/file-utils/src/Exception/FileNotFoundException.php b/src/file-utils/src/Exception/FileNotFoundException.php similarity index 100% rename from libs/file-utils/src/Exception/FileNotFoundException.php rename to src/file-utils/src/Exception/FileNotFoundException.php diff --git a/libs/file-utils/src/Exception/FileReadException.php b/src/file-utils/src/Exception/FileReadException.php similarity index 100% rename from libs/file-utils/src/Exception/FileReadException.php rename to src/file-utils/src/Exception/FileReadException.php diff --git a/libs/file-utils/src/Exception/FileSystemException.php b/src/file-utils/src/Exception/FileSystemException.php similarity index 100% rename from libs/file-utils/src/Exception/FileSystemException.php rename to src/file-utils/src/Exception/FileSystemException.php diff --git a/libs/file-utils/src/Exception/IOException.php b/src/file-utils/src/Exception/IOException.php similarity index 100% rename from libs/file-utils/src/Exception/IOException.php rename to src/file-utils/src/Exception/IOException.php diff --git a/libs/file-utils/src/File.php b/src/file-utils/src/File.php similarity index 100% rename from libs/file-utils/src/File.php rename to src/file-utils/src/File.php diff --git a/libs/file-utils/src/FileFinder.php b/src/file-utils/src/FileFinder.php similarity index 100% rename from libs/file-utils/src/FileFinder.php rename to src/file-utils/src/FileFinder.php diff --git a/libs/file-utils/src/FileSystem.php b/src/file-utils/src/FileSystem.php similarity index 100% rename from libs/file-utils/src/FileSystem.php rename to src/file-utils/src/FileSystem.php diff --git a/libs/file-utils/src/ModifyWatcher.php b/src/file-utils/src/ModifyWatcher.php similarity index 100% rename from libs/file-utils/src/ModifyWatcher.php rename to src/file-utils/src/ModifyWatcher.php diff --git a/libs/file-utils/src/ReadTrait.php b/src/file-utils/src/ReadTrait.php similarity index 100% rename from libs/file-utils/src/ReadTrait.php rename to src/file-utils/src/ReadTrait.php diff --git a/libs/file-utils/test/boot.php b/src/file-utils/test/boot.php similarity index 100% rename from libs/file-utils/test/boot.php rename to src/file-utils/test/boot.php diff --git a/libs/file-utils/.gitignore b/src/helper-utils/.gitignore similarity index 100% rename from libs/file-utils/.gitignore rename to src/helper-utils/.gitignore diff --git a/libs/file-parse/LICENSE b/src/helper-utils/LICENSE similarity index 100% rename from libs/file-parse/LICENSE rename to src/helper-utils/LICENSE diff --git a/libs/helper-utils/README.md b/src/helper-utils/README.md similarity index 100% rename from libs/helper-utils/README.md rename to src/helper-utils/README.md diff --git a/libs/helper-utils/composer.json b/src/helper-utils/composer.json similarity index 100% rename from libs/helper-utils/composer.json rename to src/helper-utils/composer.json diff --git a/libs/helper-utils/phpunit.xml.dist b/src/helper-utils/phpunit.xml.dist similarity index 100% rename from libs/helper-utils/phpunit.xml.dist rename to src/helper-utils/phpunit.xml.dist diff --git a/libs/helper-utils/src/Helper/AssertHelper.php b/src/helper-utils/src/Helper/AssertHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/AssertHelper.php rename to src/helper-utils/src/Helper/AssertHelper.php diff --git a/libs/helper-utils/src/Helper/DataHelper.php b/src/helper-utils/src/Helper/DataHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/DataHelper.php rename to src/helper-utils/src/Helper/DataHelper.php diff --git a/libs/helper-utils/src/Helper/DateHelper.php b/src/helper-utils/src/Helper/DateHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/DateHelper.php rename to src/helper-utils/src/Helper/DateHelper.php diff --git a/libs/helper-utils/src/Helper/DsnHelper.php b/src/helper-utils/src/Helper/DsnHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/DsnHelper.php rename to src/helper-utils/src/Helper/DsnHelper.php diff --git a/libs/helper-utils/src/Helper/FormatHelper.php b/src/helper-utils/src/Helper/FormatHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/FormatHelper.php rename to src/helper-utils/src/Helper/FormatHelper.php diff --git a/libs/helper-utils/src/Helper/Http.php b/src/helper-utils/src/Helper/Http.php similarity index 100% rename from libs/helper-utils/src/Helper/Http.php rename to src/helper-utils/src/Helper/Http.php diff --git a/libs/helper-utils/src/Helper/IntHelper.php b/src/helper-utils/src/Helper/IntHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/IntHelper.php rename to src/helper-utils/src/Helper/IntHelper.php diff --git a/libs/helper-utils/src/Helper/SslHelper.php b/src/helper-utils/src/Helper/SslHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/SslHelper.php rename to src/helper-utils/src/Helper/SslHelper.php diff --git a/libs/helper-utils/src/Helper/UtilHelper.php b/src/helper-utils/src/Helper/UtilHelper.php similarity index 100% rename from libs/helper-utils/src/Helper/UtilHelper.php rename to src/helper-utils/src/Helper/UtilHelper.php diff --git a/libs/helper-utils/src/Traits/AopProxyAwareTrait.php b/src/helper-utils/src/Traits/AopProxyAwareTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/AopProxyAwareTrait.php rename to src/helper-utils/src/Traits/AopProxyAwareTrait.php diff --git a/libs/helper-utils/src/Traits/Config/ConfigTrait.php b/src/helper-utils/src/Traits/Config/ConfigTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Config/ConfigTrait.php rename to src/helper-utils/src/Traits/Config/ConfigTrait.php diff --git a/libs/helper-utils/src/Traits/Config/LiteConfigTrait.php b/src/helper-utils/src/Traits/Config/LiteConfigTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Config/LiteConfigTrait.php rename to src/helper-utils/src/Traits/Config/LiteConfigTrait.php diff --git a/libs/helper-utils/src/Traits/Config/LiteOptionsTrait.php b/src/helper-utils/src/Traits/Config/LiteOptionsTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Config/LiteOptionsTrait.php rename to src/helper-utils/src/Traits/Config/LiteOptionsTrait.php diff --git a/libs/helper-utils/src/Traits/Config/OptionsTrait.php b/src/helper-utils/src/Traits/Config/OptionsTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Config/OptionsTrait.php rename to src/helper-utils/src/Traits/Config/OptionsTrait.php diff --git a/libs/helper-utils/src/Traits/Event/EventTrait.php b/src/helper-utils/src/Traits/Event/EventTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Event/EventTrait.php rename to src/helper-utils/src/Traits/Event/EventTrait.php diff --git a/libs/helper-utils/src/Traits/Event/FixedEventStaticTrait.php b/src/helper-utils/src/Traits/Event/FixedEventStaticTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Event/FixedEventStaticTrait.php rename to src/helper-utils/src/Traits/Event/FixedEventStaticTrait.php diff --git a/libs/helper-utils/src/Traits/Event/FixedEventTrait.php b/src/helper-utils/src/Traits/Event/FixedEventTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Event/FixedEventTrait.php rename to src/helper-utils/src/Traits/Event/FixedEventTrait.php diff --git a/libs/helper-utils/src/Traits/Event/LiteEventStaticTrait.php b/src/helper-utils/src/Traits/Event/LiteEventStaticTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Event/LiteEventStaticTrait.php rename to src/helper-utils/src/Traits/Event/LiteEventStaticTrait.php diff --git a/libs/helper-utils/src/Traits/Event/LiteEventTrait.php b/src/helper-utils/src/Traits/Event/LiteEventTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/Event/LiteEventTrait.php rename to src/helper-utils/src/Traits/Event/LiteEventTrait.php diff --git a/libs/helper-utils/src/Traits/LiteContainerStaticTrait.php b/src/helper-utils/src/Traits/LiteContainerStaticTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/LiteContainerStaticTrait.php rename to src/helper-utils/src/Traits/LiteContainerStaticTrait.php diff --git a/libs/helper-utils/src/Traits/LiteContainerTrait.php b/src/helper-utils/src/Traits/LiteContainerTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/LiteContainerTrait.php rename to src/helper-utils/src/Traits/LiteContainerTrait.php diff --git a/libs/helper-utils/src/Traits/LogProfileTrait.php b/src/helper-utils/src/Traits/LogProfileTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/LogProfileTrait.php rename to src/helper-utils/src/Traits/LogProfileTrait.php diff --git a/libs/helper-utils/src/Traits/LogShortTrait.php b/src/helper-utils/src/Traits/LogShortTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/LogShortTrait.php rename to src/helper-utils/src/Traits/LogShortTrait.php diff --git a/libs/helper-utils/src/Traits/NameAliasStaticTrait.php b/src/helper-utils/src/Traits/NameAliasStaticTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/NameAliasStaticTrait.php rename to src/helper-utils/src/Traits/NameAliasStaticTrait.php diff --git a/libs/helper-utils/src/Traits/NameAliasTrait.php b/src/helper-utils/src/Traits/NameAliasTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/NameAliasTrait.php rename to src/helper-utils/src/Traits/NameAliasTrait.php diff --git a/libs/helper-utils/src/Traits/PathAliasTrait.php b/src/helper-utils/src/Traits/PathAliasTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/PathAliasTrait.php rename to src/helper-utils/src/Traits/PathAliasTrait.php diff --git a/libs/helper-utils/src/Traits/PathResolverTrait.php b/src/helper-utils/src/Traits/PathResolverTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/PathResolverTrait.php rename to src/helper-utils/src/Traits/PathResolverTrait.php diff --git a/libs/helper-utils/src/Traits/RuntimeProfileTrait.php b/src/helper-utils/src/Traits/RuntimeProfileTrait.php similarity index 100% rename from libs/helper-utils/src/Traits/RuntimeProfileTrait.php rename to src/helper-utils/src/Traits/RuntimeProfileTrait.php diff --git a/libs/helper-utils/src/Util/AopProxy.php b/src/helper-utils/src/Util/AopProxy.php similarity index 100% rename from libs/helper-utils/src/Util/AopProxy.php rename to src/helper-utils/src/Util/AopProxy.php diff --git a/libs/helper-utils/src/Util/DataProxy.php b/src/helper-utils/src/Util/DataProxy.php similarity index 100% rename from libs/helper-utils/src/Util/DataProxy.php rename to src/helper-utils/src/Util/DataProxy.php diff --git a/libs/helper-utils/src/Util/DataResult.php b/src/helper-utils/src/Util/DataResult.php similarity index 100% rename from libs/helper-utils/src/Util/DataResult.php rename to src/helper-utils/src/Util/DataResult.php diff --git a/libs/helper-utils/src/Util/DeferredCallable.php b/src/helper-utils/src/Util/DeferredCallable.php similarity index 100% rename from libs/helper-utils/src/Util/DeferredCallable.php rename to src/helper-utils/src/Util/DeferredCallable.php diff --git a/libs/helper-utils/src/Util/Pipeline.php b/src/helper-utils/src/Util/Pipeline.php similarity index 100% rename from libs/helper-utils/src/Util/Pipeline.php rename to src/helper-utils/src/Util/Pipeline.php diff --git a/libs/helper-utils/src/Util/PipelineInterface.php b/src/helper-utils/src/Util/PipelineInterface.php similarity index 100% rename from libs/helper-utils/src/Util/PipelineInterface.php rename to src/helper-utils/src/Util/PipelineInterface.php diff --git a/libs/helper-utils/test/boot.php b/src/helper-utils/test/boot.php similarity index 100% rename from libs/helper-utils/test/boot.php rename to src/helper-utils/test/boot.php diff --git a/libs/helper-utils/.gitignore b/src/php-utils/.gitignore similarity index 100% rename from libs/helper-utils/.gitignore rename to src/php-utils/.gitignore diff --git a/libs/file-utils/LICENSE b/src/php-utils/LICENSE similarity index 100% rename from libs/file-utils/LICENSE rename to src/php-utils/LICENSE diff --git a/libs/php-utils/README.md b/src/php-utils/README.md similarity index 100% rename from libs/php-utils/README.md rename to src/php-utils/README.md diff --git a/libs/php-utils/composer.json b/src/php-utils/composer.json similarity index 100% rename from libs/php-utils/composer.json rename to src/php-utils/composer.json diff --git a/libs/php-utils/example/property_exists.php b/src/php-utils/example/property_exists.php similarity index 100% rename from libs/php-utils/example/property_exists.php rename to src/php-utils/example/property_exists.php diff --git a/libs/obj-utils/phpunit.xml.dist b/src/php-utils/phpunit.xml.dist similarity index 100% rename from libs/obj-utils/phpunit.xml.dist rename to src/php-utils/phpunit.xml.dist diff --git a/libs/php-utils/src/AutoLoader.php b/src/php-utils/src/AutoLoader.php similarity index 100% rename from libs/php-utils/src/AutoLoader.php rename to src/php-utils/src/AutoLoader.php diff --git a/libs/php-utils/src/Php.php b/src/php-utils/src/Php.php similarity index 100% rename from libs/php-utils/src/Php.php rename to src/php-utils/src/Php.php diff --git a/libs/php-utils/src/PhpDoc.php b/src/php-utils/src/PhpDoc.php similarity index 100% rename from libs/php-utils/src/PhpDoc.php rename to src/php-utils/src/PhpDoc.php diff --git a/libs/php-utils/src/PhpDotEnv.php b/src/php-utils/src/PhpDotEnv.php similarity index 100% rename from libs/php-utils/src/PhpDotEnv.php rename to src/php-utils/src/PhpDotEnv.php diff --git a/libs/php-utils/src/PhpEnv.php b/src/php-utils/src/PhpEnv.php similarity index 100% rename from libs/php-utils/src/PhpEnv.php rename to src/php-utils/src/PhpEnv.php diff --git a/libs/php-utils/src/PhpError.php b/src/php-utils/src/PhpError.php similarity index 100% rename from libs/php-utils/src/PhpError.php rename to src/php-utils/src/PhpError.php diff --git a/libs/php-utils/src/PhpException.php b/src/php-utils/src/PhpException.php similarity index 100% rename from libs/php-utils/src/PhpException.php rename to src/php-utils/src/PhpException.php diff --git a/libs/php-utils/src/PhpHelper.php b/src/php-utils/src/PhpHelper.php similarity index 100% rename from libs/php-utils/src/PhpHelper.php rename to src/php-utils/src/PhpHelper.php diff --git a/libs/php-utils/src/Type.php b/src/php-utils/src/Type.php similarity index 100% rename from libs/php-utils/src/Type.php rename to src/php-utils/src/Type.php diff --git a/libs/php-utils/test/PhpDocTest.php b/src/php-utils/test/PhpDocTest.php similarity index 100% rename from libs/php-utils/test/PhpDocTest.php rename to src/php-utils/test/PhpDocTest.php diff --git a/libs/php-utils/test/boot.php b/src/php-utils/test/boot.php similarity index 100% rename from libs/php-utils/test/boot.php rename to src/php-utils/test/boot.php diff --git a/libs/obj-utils/.gitignore b/src/sys-utils/.gitignore similarity index 100% rename from libs/obj-utils/.gitignore rename to src/sys-utils/.gitignore diff --git a/libs/helper-utils/LICENSE b/src/sys-utils/LICENSE similarity index 100% rename from libs/helper-utils/LICENSE rename to src/sys-utils/LICENSE diff --git a/libs/sys-utils/README.md b/src/sys-utils/README.md similarity index 100% rename from libs/sys-utils/README.md rename to src/sys-utils/README.md diff --git a/libs/sys-utils/composer.json b/src/sys-utils/composer.json similarity index 100% rename from libs/sys-utils/composer.json rename to src/sys-utils/composer.json diff --git a/libs/php-utils/phpunit.xml.dist b/src/sys-utils/phpunit.xml.dist similarity index 100% rename from libs/php-utils/phpunit.xml.dist rename to src/sys-utils/phpunit.xml.dist diff --git a/libs/sys-utils/src/ProcessUtil.php b/src/sys-utils/src/ProcessUtil.php similarity index 100% rename from libs/sys-utils/src/ProcessUtil.php rename to src/sys-utils/src/ProcessUtil.php diff --git a/libs/sys-utils/src/Signal.php b/src/sys-utils/src/Signal.php similarity index 100% rename from libs/sys-utils/src/Signal.php rename to src/sys-utils/src/Signal.php diff --git a/libs/sys-utils/src/Sys.php b/src/sys-utils/src/Sys.php similarity index 100% rename from libs/sys-utils/src/Sys.php rename to src/sys-utils/src/Sys.php diff --git a/libs/sys-utils/src/SysEnv.php b/src/sys-utils/src/SysEnv.php similarity index 100% rename from libs/sys-utils/src/SysEnv.php rename to src/sys-utils/src/SysEnv.php diff --git a/libs/sys-utils/test/boot.php b/src/sys-utils/test/boot.php similarity index 100% rename from libs/sys-utils/test/boot.php rename to src/sys-utils/test/boot.php