Quería preguntaros si veis este código bien para utilizar un patrón singleton y registrar la clase.
Código PHP:
<?php
/**
* Plantillas
*
* @package
* @author antoniopmfree
* @version 1.0
*/
Zend_Loader::loadClass('Zend_Session_Namespace');
class Yimgo_Plantillas_Plantillas {
/**
* Singleton instance
*
* @var Yimgo_Plantillas_Plantillas
*/
protected static $_instance = null;
/**
* Singleton pattern implementation makes "new" unavailable
*
* @return void
*/
protected function __construct()
{}
/**
* Singleton pattern implementation makes "clone" unavailable
*
* @return void
*/
protected function __clone()
{}
/**
* Returns an instance of Yimgo_Plantillas_Plantillas
*
* Singleton pattern implementation
*
* @return Yimgo_Plantillas_Plantillas
*/
public static function getInstance() {
if (Zend_Registry::isRegistered("pSession")) {
$sessionData=Zend_Registry::get("pSession");
} else {
$sessionData=new Zend_Session_Namespace("pSession");
Zend_Registry::set("pSession",$sessionData);
}
if (isset($sessionData->plan) && ($sessionData->plan!==null)) {
$planObject=$sessionData->plan;
} else {
if (null === self::$_instance) {
self::$_instance = new self();
}
$planObject=self::$_instance;
$sessionData->plan=$planObject;
}
return $planObject;
}
}
?>