沒有,如果有可能我想要的,但我工作的需要自定義類覆蓋了核心功能,如果存在這些文件的應用程序的想法。重寫核心類
因此,作爲一個例子,這是我的當前文件結構(簡化,而不 '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