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

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

msqphp 更新时间:发布时间: 百科书网 趣学号

### 万能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.051e.com
本文地址:http://www.051e.com/it/213989.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号