### 万能get,call,callStatic
* * * * *
原理:
> call和callStatic同理,只不过返回一个函数
>
> return function ($arg1, $arg2) {
> ..code
> //return $arg1 > $arg2;
> };
>
目录结构:
├──... 仓库, 放东西的, 需要对应权限
│ ├──gets万能get
| | └──test.php一个A类test属性
│ └──A.php A类session
**A.php:**
class a
{
public function __get(string $property)
{
//获得过的属性
static gets = [];
//如果不存在
//!isset($gets['test'])
if (!isset($gets[$property])) {
//载入当前目录下gets目录下$property.php
//载入文件 当前目录/gets/test.php,返回值为test,此时$gets[$property] ----> 'test'
$gets[$property] = require __DIR__ . DIRECTORY_SEPARATOR.'gets'.DIRECTORY_SEPARATOR.$property.'.php';
}
//返回值
return $gets[$property];
}
}
**test.php:**
return 'test';
**使用:**
$a = new A();
echo $a->test; ---->'test'
* * * * *
**万能call框架版本:**
*....vendor/msqphp/fraemwork/traits/Get.php*
namespace msqphptraits;
trait Get
{
public function __get(string $property)
{
//get集合
static $gets = [];
//如果属性不存在
if (!isset($gets[$property])) {
//框架路径
$framework_path = dirname(__DIR__) . DIRECTORY_SEPARATOR;
//命名空间转换为目录 msqphpbasedirDir ----> basedir
$namespace = strtr(str_replace([strrchr(__CLASS__, '\'), 'msqphp\'], '', __CLASS__), '\', DIRECTORY_SEPARATOR);
//拼装路径
$file = $framework_path . $namespace . DIRECTORY_SEPARATOR . 'gets' . DIRECTORY_SEPARATOR . $property . '.php';
//不存在则替换
is_file($file) || $file = str_replace($framework_path, msqphpEnvironment::getPath('library'), $file);
//存在载入否则报错
if (!is_file($file)) {
throw new TraitsException(__CLASS__.'类的'.$property.'属性不存在');
}
$gets[$property] = require $file;
}
return $gets[$property];
}



