Source for file Container.php
Documentation is available at Container.php
* Teeple2 - PHP5 Web Application Framework inspired by Seasar2
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @author Mitsutaka Sato <miztaka@gmail.com>
* @license http://www.php.net/license/3_0.txt PHP License 3.0
const SESSION_KEY =
'__SESSION_COMPONENTS';
private static $instance;
* Containerとして管理するインスタンスを格納
* ContainerのSingletonインスタンスを取得します。
* @return Teeple_Container
if (self::$instance ===
NULL) {
self::$instance =
new Teeple_Container();
* @param string $configfile
public function setup($configfile) {
if (count($config) <
1) {
foreach($config as $key =>
$value) {
list
($clsname, $path) =
explode(':', $key);
$this->_dicon[$clsname] =
array(
* ContainerにComponentのインスタンスをセット
* @param string $name Component名
* @param Object $component Componentのインスタンス
public function register($name, $component) {
* Componentのインスタンスを取得します。
* (RequestスコープのComponent)
* @param string $name Component名
* @return Object Componentのインスタンス
$component =
$this->_createComponent($name);
* SessionスコープのComponentを取得します。
if (! isset
($_SESSION[self::SESSION_KEY])) {
$_SESSION[self::SESSION_KEY] =
array();
if (isset
($_SESSION[self::SESSION_KEY][$name])) {
$component =
$_SESSION[self::SESSION_KEY][$name];
$this->log->debug("セッションに存在しないので作成します。");
$component =
$this->_createComponent($name, FALSE);
$_SESSION[self::SESSION_KEY][$name] =
$component;
* prototypeのComponentを取得します。
return $this->_createComponent($name, FALSE);
* Teeple_ActiveRecordのエンティティを取得します。
* @return Teeple_ActiveRecord
return $defaultTx->$name;
private function _createComponent($name, $register=
TRUE) {
$this->log->debug("コンポーネント {$name} を作成します。");
if (isset
($this->_dicon[$name])) {
$className =
$this->_dicon[$name]['class'];
$instance =
new $className();
foreach($methods as $method) {
if (preg_match('/^setComponent_(.+)$/', $method, $m)) {
$this->log->debug("自動セット: {$m[1]}");
elseif (preg_match('/^setSessionComponent_(.+)$/', $method, $m)) {
$this->log->debug("自動セット(s): {$m[1]}");
elseif (preg_match('/^setPrototype_(.+)$/', $method, $m)) {
$this->log->debug("自動セット(p): {$m[1]}");
elseif (preg_match('/^set(Entity_.+)$/', $method, $m)) {
$this->log->debug("自動セット(e): {$m[1]}");