/** * This function serves to setup the application, can be overriden * to setup custom settings.. * * @access protected * @return void */ protected function setup() { /** Set Debug to TRUE **/ self::$DEBUG = true; /** Read Base dir and save **/ $baseDir = getcwd(); /** Setup Log **/ $logFile = $baseDir . "/log/messages.log"; Gecko_Log::setLogWriter(new Zend_Log_Writer_Stream($logFile)); /** Get Registry Instance **/ $registry = Zend_Registry::getInstance(); $registry['baseDir'] = $baseDir; /** Set Config File and create Config parser **/ $configFile = $baseDir . "/config/config.xml"; $config = new Zend_Config_Xml($configFile, 'staging'); /** Save Config to Registry **/ $registry['config'] = $config; /** Create DB if we can... **/ try { $db = Gecko_DB::getInstance(); } catch (Zend_Db_Exception $zde) { // There isn't a DB Settings.. silently omit... Gecko_Log::getInstance()->log("No database settings found", Zend_Log::INFO); Gecko_Log::getInstance()->log($zde->getMessage(), Zend_Log::INFO); } /** Register filters for request parameters **/ require_once "Gecko/Request/Filter/MagicQuotes.php"; Gecko_Request::registerFilter(new Gecko_Request_Filter_MagicQuotes()); header("Cache-control: private"); // IE6 Session Fix /** Save a copy of the base router on registry **/ Zend_Registry::set("base", $this); /** Setup Complete **/ Gecko_Log::getInstance()->log("Router Initialized", Zend_Log::INFO); }
/** * Returns an instance of Zend_DB_Adapter * * Singleton pattern implementation * * @return Zend_DB_Adapter_Interface */ public static function getInstance() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance->dbConn; }
/** * Creates a new Gecko_Auth object, it uses Zend_Auth to validate * directly with the database * * @params array $settings los settings para levantar el objeto **/ public function __construct($settings) { // Check Input settings array $this->checkSettings($settings); // Get DB Adapter if (!isset($settings['db'])) { $db = Gecko_DB::getInstance(); } else { $db = $settings['db']; } $adapter = new Zend_Auth_Adapter_DbTable($db, $settings['tableName'], $settings['identityColumn'], $settings['credentialColumn']); // Check if there is a credential treatment if (isset($settings['credentialTreatment']) && !empty($settings['credentialTreatment'])) { $adapter->setCredentialTreatment($settings['credentialTreatment']); } $this->adapter = $adapter; $this->settings = $settings; $this->passwordColumn = $settings['credentialColumn']; $auth = Zend_Auth::getInstance(); $auth->setStorage(new Zend_Auth_Storage_Session($settings['sessionNamespace'])); }
/** * Creates a Grid from a SQL Query (or Zend_Db_Select), if you * don't submit a Db Adapter it will try to create from Gecko_DB(Singleton), * or it will look for a 'db' entry in Zend_Registry * * @param string $name The table name * @param string|Zend_Db_Select $sql * @param Zend_Db_Adapter_Abstract $db * @return Gecko_DataGrid The grid pre-populated */ public static function createFromSQL($name, $sql, $db = null) { if ($db === null) { // Try to create try { $db = Gecko_DB::getInstance(); } catch (Zend_Db_Exception $zde) { if (Zend_Registry::isRegistered('db')) { $db = Zend_Registry::get('db'); } } if ($db === null) { // DB still not set Throw a error throw new Gecko_DataGrid_Exception('$db it\'s not set, check the documentation'); } } /** Check if it's a select object **/ if ($sql instanceof Zend_Db_Select) { $sql = $sql->__toString(); } require_once 'Gecko/DataSource/Table/SQL.php'; $model = new Gecko_DataSource_Table_SQL($sql, $db); $grid = new self($name, $model); return $grid; }