[PHP-users 35554] 初期化した配列のキーについて質問させてください

root-^_^-home yk_mailing @ yahoo.co.jp
2011年 4月 23日 (土) 10:00:59 JST


質問させてください。

((AuthController.php))

	public function loginAction() 
	{
		$request = $this->getRequest();
		$auth 	 = Zend_Auth::getInstance();
		if ($auth->hasIdentity()) {
			$this->_redirect($this->view->serverUrl().$this->view->url(array(),
'core_dashboard_index'));
		}
		if ($request->isPost()) {
			$username = $request->getPost('username');
			$password = $request->getPost('password');
			$adapter  = new Core_Services_Auth($username, $password);
			$result   = $auth->authenticate($adapter);
			switch ($result->getCode()) {
				/**
				 * Logged in successfully
				 */
				case Core_Services_Auth::SUCCESS:
					$user = $auth->getIdentity();
				
Hook_Registry::getInstance()->executeAction('Core_Auth_Login_LoginSuccess',
$user); // 
★A
					$this->_redirect($this->view->serverUrl() . $this->view->url(array(),
'core_dashboard_index'));
					break;
					

((Registry.php))

class Hook_Registry 
{
	const HOOKS = 'Tomato_Hook_Registry';
	private static $_instance;
	/**
	 * @var array
	 */
	private static $_hooks;
	public static function getInstance() 
	{
		if (null == self::$_instance) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	private function __construct() 
	{
		self::$_hooks = array();
	}
	
	/**
	 * Run action
	 * 
	 * @param $actionName
	 * @param $args
	 * @return void
	 */
	public function executeAction($name, $args = array()) 
	{
		$hooks = self::$_hooks;
		if (!array_key_exists($name, $hooks)) { //★B
			return;
		}
		if (!is_array($hooks[$name])) {
			throw new Exception('There is not hook for ' . $name ."\n");
			return;
		}
		foreach ($hooks[$name] as $index => $hookArray) {
			foreach ($hookArray as $key => $hook) {


と2つのファイルあります。

ここで、★Aの部分が分からないのですが、Hook_Registryクラスにてインスタン
スを作成し、コンストラクタにて$_hooksを配列へ初期化しています。
それがexecuteAction内の★B部などでは$hooks内に$name要素が無ければエラー処
理とかあります。
これはどういう事なのでしょうか?
$hooksという初期化した変数(配列)内には現在何も入っていないと思うのです
が、キーを持つかどうかで判別しているのは何故なのでしょうか?



PHP-users メーリングリストの案内