栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > msqphp

万能get,call,callStatic - msqphp轻量级php7.1框架beta -1.9版本使用手册

msqphp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

万能get,call,callStatic - msqphp轻量级php7.1框架beta -1.9版本使用手册


### 万能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];
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/213989.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号