获取应用层类的实例, 可以理解为 new 一个类(new Classname), 单例化操作
当应用层类被加载时, 会自动执行构造函数(__construct)、析构函数(__destruct)
如果构造函数(__construct)带形参, 将不会被自动调用
注意:
public static object Asf_Loader::get(string $class_name [, string $module_name = ''])
PHP合法的类名称
如果类名带下划线, 则会以目录形式进行分割。比如 Loader::get("Api_IndexLogic"), 查找子文件路径 module_name/logics/api/Index.php
指定在哪个模块下查找类
如果类存在, 实例化成功返回 Object, 否则返回 False
Path: module_name/logics/Index.php
<?php
Asf\Loader::get('IndexLogic');
Path: module_name/logics/api/Index.php
<?php
Asf\Loader::get('Api_IndexLogic');
Path: other_module_name/logics/Index.php
<?php
Asf\Loader::get('IndexLogic', 'other_module_name');
<?php
use Asf\Loader;
class UserLogic
{
public function setName($user) {}
public function findName($user) {}
}
$user = Loader::get('UserLogic');
$user->setName('xx');
var_dump($user->findName('xx'));
Path: module_name/ck/Test.php
<?php
namespace ck;
class Test
{
}
use Asf\Loader;
Loader::get('ck\Test');