From 531de211c5952d74a7af9dd512acaef9a02faf5d Mon Sep 17 00:00:00 2001 From: netjoin Date: Sat, 23 Feb 2019 23:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=AE=9A=E4=B9=89=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8A=A8=E6=80=81=E6=98=BE=E7=A4=BA=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E4=B8=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Arr.php | 32 ++++++++++++++++++++++++++++++++ src/Ext/Test.php | 37 +++++++++++++++++++++++++++++++++++++ src/Filesystem.php | 18 ++++++++++++++++++ src/global/arr.php | 20 ++++++++++++++++++++ src/global/filesystem.php | 10 ++++++++++ src/global/pcre.php | 10 ++++++++++ src/global/str.php | 10 ++++++++++ src/global/variable.php | 15 +++++++++++++++ web/index.php | 33 +++++++++++++++++++++++++++++++++ 9 files changed, 185 insertions(+) create mode 100644 src/Ext/Test.php create mode 100644 src/Filesystem.php create mode 100644 src/global/arr.php create mode 100644 src/global/filesystem.php create mode 100644 src/global/pcre.php create mode 100644 src/global/str.php create mode 100644 src/global/variable.php create mode 100644 web/index.php diff --git a/src/Arr.php b/src/Arr.php index 1733a79..0150885 100644 --- a/src/Arr.php +++ b/src/Arr.php @@ -41,3 +41,35 @@ function array_diff_kv($arr = [], $other = [], $ignore = [], $null = false) } return $diff; } + +function arr_fixed_assoc(array &$array, $reset = false) +{ + $arr = $array; + foreach ($arr as $key => $value) { + if (is_numeric($key)) { + unset($arr[$key]); + $key = $value; + $arr[$key] = $value; + } + } + if ($reset) { + $array = $arr; + } + return $arr; +} + +function arr_reset_values(array &$array, $set = [], $reset = false) +{ + $prefix = isset($set['prefix']) ? $set['prefix'] : ''; + $suffix = isset($set['suffix']) ? $set['suffix'] : ''; + $arr = $array; + foreach ($arr as $key => &$value) { + if (is_string($key)) { + $value = $prefix . $value . $suffix; + } + } + if ($reset) { + $array = $arr; + } + return $arr; +} diff --git a/src/Ext/Test.php b/src/Ext/Test.php new file mode 100644 index 0000000..9f8072e --- /dev/null +++ b/src/Ext/Test.php @@ -0,0 +1,37 @@ +name = func_get_args(); + } + + public static function _get($name) + { + self::$arg[$name] = func_get_args(); + return self::$cache[$name]; + } + + public function set($name) + { + $arg = func_get_args(); + self::$cache[$name] = $arg; + } + + public function __debugInfo() + { + return [ + 'name' => $this->name, + 'cache' => self::$cache, + 'arg' => self::$arg, + ]; + } +} \ No newline at end of file diff --git a/src/Filesystem.php b/src/Filesystem.php new file mode 100644 index 0000000..a84f1dd --- /dev/null +++ b/src/Filesystem.php @@ -0,0 +1,18 @@ + 'index', + 'index', +); + + +$Composer = require __DIR__ . '/../../../../vendor/autoload.php'; +$functions = [ + '_isset' => ['', [], '', null], + #'\Func\array_diff_kv' => ['', [], [], [], false], + 'str_match' => ['', '//', '', null, false], + #'\Func\Arr\arr_fixed_assoc' => ['', [], false], + #'arr_reset_values', +]; +func($functions, ['variable', 'arr', 'pcre', 'Filesystem']); + + + + +arr_fixed_assoc($_NAMES, true); +arr_reset_values($_NAMES, ['prefix' => __DIR__ . '/../example/', 'suffix' => '.php'], true); +$basename = \Func\path_info(0, PATHINFO_BASENAME); +#print_r([__LINE__, get_defined_functions()['user'], get_included_files(), $_NAMES, $basename, $_NAMES[$basename]]); +if (array_key_exists($basename, $_NAMES) && include $_NAMES[$basename]) { + // +} else { + include $_NAMES['']; +} +/**/ +# print_r([__LINE__, get_defined_constants(), get_defined_vars()]);