没有,如果有可能我想要的,但我工作的需要自定义类覆盖了核心功能,如果存在这些文件的应用程序的想法。重写核心类
因此,作为一个例子,这是我的当前文件结构(简化,而不 'customer_slug')
- 应用
- 芯
- user.php的(类用户)
- 定制
- user.php的(类用户)
- 芯
现在我要检查,如果 “自定义/ user.php的” 的存在,并相应地包括和使用。它应该扩展核心(抽象)用户类。
我的“入口”的剧本是这样的时刻:
<?php
function __autoload($class_name) {
$dispatch = Dispatcher::getInstance();
$dispatch->get($class_name);
}
class Dispatcher {
private static $instance;
private static $customer_slug = 'sony';
private function __clone() {
// Empty magic function to prevent cloning
}
private function __construct() {
// Empty magic function to prevent initialization
}
public static function getInstance()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
public static function get($class) {
// Autoload class
$basepath = $class.'.php';
// Include bas class
include('core/'.$basepath);
// Do we have custom functionality
if (file_exists('custom/'.self::$customer_slug.'/'.$basepath)) {
include('custom/'.self::$customer_slug.'/'.$basepath);
}
}
}
$User = new User;
print_r($User);
?>
我试着摆弄命名空间,但不能真正似乎得到它的工作。我想继续说“$ user = new User;”。不知道我是怎么回事调用类的,也许是$用户=新的$ custom_or_code_classname
所以我开放给其他的办法为好。也许是一个钩子系统?
如何看起来你user.php的班? – Liutas 2011-03-29 09:19:03
<?php namespace core; class用户{ \t public function __construct(){ \t \t echo __FILE__; \t} } ?> – 2011-03-29 09:25:54
已经给出了一个很好的答案,但你可能想看看Kohana如何处理它。他们称之为级联文件系统,并且完全按照你的意愿进行:http://kohanaframework.org/3.3/guide-api/Kohana#find_file – giorgio 2013-08-12 14:00:28