<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

  /**
   * Initialize database using application's config
   * Change the charset to UTF8
   */
  protected function _initDatabase() {
    // get the config resource
    $this->bootstrap('db');

    // retrieve the adapter
    $db = Zend_Db_Table_Abstract::getDefaultAdapter();

    // change adapter's configs
    $db->setFetchMode(Zend_Db::FETCH_OBJ);
    // $db->query("SET NAMES 'utf8'");
    // $db->query("SET CHARACTER SET 'utf8'");
    
    if(APPLICATION_ENV == 'development'){
      $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
      $profiler->setEnabled(true);

      // Attach the profiler to your db adapter
      $db->setProfiler($profiler);
    }

    // store adapter
    Zend_Db_Table::setDefaultAdapter($db);
  }

  /**
   * store the application's config in the registry
   */
  public function _initAppConfig() {
    // load the ini file
    $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
    // store in the registry
    Zend_Registry::set("_app_config", $config);
  }

  /**
   * store the site's config in the registry
   */
  public function _initSiteConfig() {
    // fetch the config
    $modelSettings = new Model_Cms_Settings();
    $settings = $modelSettings->find(1)->current()->toArray();

    // store in the registry
    Zend_Registry::set("_site_config", Pampa_Util_Array::toObject($settings));
  }

  /**

   */
  public function _initRoutes() {
    $frontController = Zend_Controller_Front::getInstance();

    // check the file
    if (is_file(APPLICATION_PATH . '/configs/routes.ini')) {
      // load the ini file
      $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'routes');

      // add the configs to the router
      $router = new Zend_Controller_Router_Rewrite();
      $router->addConfig($config, 'routes');

      // add the router to front controller
      $frontController->setRouter($router);
    }
    if(APPLICATION_ENV == 'production'){
       // $frontController->setBaseUrl('/go2pet/');
    }
  }

  /**
    public function _initCache() {
    // start the cache
    $cache = Zend_Cache::factory(
    'Core',
    'File',
    array(
    'automatic_serialization' => TRUE,
    'lifetime' => 7200
    ),
    array('cache_dir' => BASE_PATH.'/../tmp')
    );

    $frontController = Zend_Controller_Front::getInstance();
    $frontController->registerPlugin(new Pampa_Controller_Plugin_Cache($cache));

    // send to registry and locale
    Zend_Registry::set('cache', $cache);
    }
    /* */
}

