Skip to content

Commit

Permalink
添加全局函数定义方式,添加动态显示实例的主页
Browse files Browse the repository at this point in the history
  • Loading branch information
wuding committed Feb 23, 2019
1 parent 853e7ff commit 531de21
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
37 changes: 37 additions & 0 deletions src/Ext/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Func\Ext;

class Test
{
public $name = [];
public static $cache = [];
public static $arg = [];
public static $args = [];

public function __construct($name = null)
{
$this->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,
];
}
}
18 changes: 18 additions & 0 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Func;

class Filesystem
{
public function __construct()
{

}
}

function path_info($url_path = null , $options = null)
{
$url_path = $url_path ? : $_SERVER['REQUEST_URI'];
$url_path = parse_url($url_path, PHP_URL_PATH);
return pathinfo($url_path, $options);
}
20 changes: 20 additions & 0 deletions src/global/arr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Func as f;

new \Func\Arr;

function array_diff_kv($arr = [], $other = [], $ignore = [], $null = false)
{
return f\array_diff_kv($arr, $other, $ignore, $null);
}

function arr_fixed_assoc(array &$array, $reset = false)
{
return f\arr_fixed_assoc($array, $reset);
}

function arr_reset_values(array &$array, $set = [], $reset = false)
{
return f\arr_reset_values($array, $set, $reset);
}
10 changes: 10 additions & 0 deletions src/global/filesystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Func as f;

new \Func\Filesystem;

function path_info($url_path = null , $options = null)
{
return f\path_info($url_path, $options);
}
10 changes: 10 additions & 0 deletions src/global/pcre.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Func as f;

new \Func\PCRE;

function str_match($pattern, $subject, $value = null, $type = false)
{
return f\str_match($pattern, $subject, $value, $type);
}
10 changes: 10 additions & 0 deletions src/global/str.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Func as f;

new \Func\Str;

function unicode_decode($str, $type = null)
{
return f\unicode_decode($str, $type);
}
15 changes: 15 additions & 0 deletions src/global/variable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Func as f;

new \Func\Variable;

function _isset($arr, $key = '', $value = null)
{
return f\_isset($arr, $key, $value);
}

function _unset($arr, $keys = [])
{
return f\_unset($arr, $keys);
}
33 changes: 33 additions & 0 deletions web/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php


$_NAMES = array(
'' => '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()]);

0 comments on commit 531de21

Please sign in to comment.