Source for file Ethna_ClassFactory.php
Documentation is available at Ethna_ClassFactory.php
// vim: foldmethod=marker
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @version $Id: Ethna_ClassFactory.php 527 2008-05-07 02:40:15Z mumumu-org $
// {{{ Ethna_ClassFactory
* Ethnaフレームワークのオブジェクト生成ゲートウェイ
* DIコンテナか、ということも考えましたがEthnaではこの程度の単純なものに
* 留めておきます。アプリケーションレベルDIしたい場合はフィルタチェインを
* @author Masaki Fujimoto <fujimoto@php.net>
/** @var object Ethna_Controller controllerオブジェクト */
/** @var object Ethna_Controller controllerオブジェクト(省略形) */
/** @var array 生成済みオブジェクトキャッシュ */
/** @var array 生成済みアプリケーションマネージャオブジェクトキャッシュ */
/** @var array メソッド一覧キャッシュ */
var $method_list =
array();
* Ethna_ClassFactoryクラスのコンストラクタ
* @param object Ethna_Controller &$controller controllerオブジェクト
* @param array $class クラス定義
$this->controller =
& $controller;
$this->ctl =
& $controller;
* typeに対応するアプリケーションマネージャオブジェクトを返す
* @param string $type クラスキー
* @param bool $weak オブジェクトが未生成の場合の強制生成フラグ(default: false)
* @return object Ethna_AppManager マネージャオブジェクト
* TODO: 現状の実装では、typeを名前として扱っているのに、
* 大文字小文字を区別して違うインスタンスを返しているのを修正する
// check if object class exists
// check if manager class exists
&&
$this->_include($class_name) ===
false) {
if (isset
($this->method_list[$class_name]) ==
false) {
for ($i =
0; $i <
count($this->method_list[$class_name]); $i++
) {
$this->method_list[$class_name][$i] =
strtolower($this->method_list[$class_name][$i]);
// see if this should be singlton or not
if (isset
($this->manager[$type]) &&
is_object($this->manager[$type])) {
return $this->manager[$type];
// see if we have helper methods
if (in_array("getinstance", $this->method_list[$class_name])) {
$obj =
& new $class_name($backend);
if (isset
($this->manager[$type]) ==
false ||
is_object($this->manager[$type]) ==
false) {
$this->manager[$type] =
& $obj;
* クラスキーに対応するオブジェクトを返す/クラスキーが未定義の場合はAppObjectを探す
* @param string $key クラスキー
* @param bool $weak オブジェクトが未生成の場合の強制生成フラグ(default: false)
* @return object 生成されたオブジェクト(エラーならnull)
* TODO: 現状の実装では、typeを名前として扱っているのに、
* 大文字小文字を区別して違うインスタンスを返しているのを修正する
if (isset
($this->class[$key]) ==
false) {
list
($key_type, $key_value, $prop) =
$ext;
$class_name =
$this->class[$key];
// try to include if not defined
if ($this->_include($class_name) ==
false) {
// handle app object first
if (isset
($this->class[$key]) ==
false) {
$object =
& new $class_name($backend, $key_type, $key_value, $prop);
if (isset
($this->method_list[$class_name]) ==
false) {
for ($i =
0; $i <
count($this->method_list[$class_name]); $i++
) {
$this->method_list[$class_name][$i] =
strtolower($this->method_list[$class_name][$i]);
// see if this should be singlton or not
if (isset
($this->object[$key]) &&
is_object($this->object[$key])) {
return $this->object[$key];
// see if we have helper methods
$object =
& $this->$method($class_name);
} else if (in_array("getinstance", $this->method_list[$class_name])) {
$object =
& new $class_name();
if (isset
($this->object[$key]) ==
false ||
is_object($this->object[$key]) ==
false) {
$this->object[$key] =
& $object;
* @param string $key クラスキー
if (isset
($this->class[$key]) ==
false) {
return $this->class[$key];
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
$_ret_object =
& new $class_name($this->ctl);
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
$_ret_object =
& new $class_name($this->ctl);
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
$_ret_object =
& new $class_name($this->ctl);
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
$_ret_object =
& new $class_name($this->ctl);
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
$_ret_object =
& new $class_name($this->ctl);
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
* @param string $class_name クラス名
* @return object 生成されたオブジェクト(エラーならnull)
$_ret_object =
& new $class_name($this->ctl);
* 指定されたクラスから想定されるファイルをincludeする
$file =
sprintf("%s.%s", $class_name, $this->controller->getExt('php'));
if (preg_match('/^(\w+?)_(.*)/', $class_name, $match)) {
// App_Foo_Bar_Baz -> Foo/Bar/App_Foo_Bar_Baz.php
$tmp[count($tmp)-
1] =
$class_name;
$this->controller->getExt('php'));
// try ethna app & pear mixed style
// App_Foo_Bar_Baz -> Foo/Bar/Baz.php
$this->controller->getExt('php'));
// try ethna master style
// Ethna_Foo_Bar -> class/Ethna/Foo/Ethna_Foo_Bar.php
$this->controller->getExt('php'));
// Foo_Bar_Baz -> Foo/Bar/Baz.php
$this->controller->getExt('php'));
* 指定されたクラスがキャッシュを利用可能かどうかをチェックする
// if we have getInstance(), use this anyway
if (in_array('getinstance', $method_list)) {
// if not, see if weak or not
return $weak ?
false :
true;
Documentation generated on Thu, 08 May 2008 00:14:37 +0900 by phpDocumentor 1.4.2