DotLibrary
[ class tree: DotLibrary ] [ index: DotLibrary ] [ all elements ]

Source for file Settings.php

Documentation is available at Settings.php

  1. <?php
  2. /**
  3. * DotBoost Technologies Inc.
  4. * DotKernel Application Framework
  5. *
  6. @category   DotKernel
  7. @package    DotLibrary
  8. @copyright  Copyright (c) 2009 DotBoost  Technologies (http://www.dotboost.com)
  9. @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  10. @version    $Id: Settings.php 158 2010-06-25 08:59:20Z teo $
  11. */
  12.  
  13. /**
  14. * Loading Settings from database, also set PHP settings from config file
  15. @category   DotKernel
  16. @package    DotLibrary
  17. @author     DotKernel Team <team@dotkernel.com>
  18. */
  19.  
  20. {
  21.     /**
  22.      * Constructor
  23.      * @access public
  24.      * @return Dot_Settings 
  25.      */
  26.     public function __construct ()
  27.     {
  28.     }
  29.     /**
  30.      * Get settings from database, table, and load into registry $settings
  31.      * @access public
  32.      * @static
  33.      * @param  database connection singleton
  34.      * @return object with values from setting table
  35.       */
  36.     public static function getSettings()
  37.     {
  38.         $settings array();
  39.         $db Zend_Registry::get('database');
  40.         $select $db->select()
  41.                      ->from('setting');
  42.         $results $db->fetchAll($select);
  43.         foreach ($results as $key => $val)
  44.         {
  45.             $settings[$val['key']] $val['value'];
  46.         }    
  47.         return (object)$settings;
  48.     }
  49.     /**
  50.      * Set PHP configuration settings
  51.      * @access public
  52.      * @static
  53.      * @param  array $settings 
  54.      * @param  string $prefix Key prefix to prepend to array values (used to map . separated INI values)
  55.      * @return copied from Zend_Application class
  56.       */
  57.     public static function setPhpSettings(array $phpSettings$prefix '')
  58.     {
  59.         foreach ($phpSettings as $key => $value)
  60.         {
  61.             $key empty($prefix$key $prefix $key;
  62.             if (is_scalar($value)) ini_set($key$value);
  63.             elseif (is_array($value))  self::setPhpSettings($value$key '.');
  64.         }        
  65.     
  66.     /**
  67.      * Require the files according to MVC pattern, and the modules there are in application.ini file
  68.      * @access public
  69.      * @static
  70.      * @param  string $requestModule 
  71.      * @return void 
  72.      */
  73.     public static function loadControllerFiles($requestModule)
  74.     {
  75.         $resource Zend_Registry::get('resource');
  76.         $modules $resource->controllers->toArray();        
  77.         /**
  78.          *  if we are in frontend , we have an empty variable for $requestModule
  79.          *  Also, fix with $modulePath for modules path other then frontend
  80.          */        
  81.         if$requestModule != '' )
  82.         {
  83.             $modulePath $requestModule '/';
  84.         }
  85.         else
  86.         {
  87.             $modulePath '';
  88.             $requestModule 'frontend';
  89.         }
  90.         // get the list of controllers for that specific module
  91.         if(array_key_exists($requestModule$modules))
  92.         {
  93.             $modules $modules[$requestModule];
  94.         }
  95.         else 
  96.         {
  97.             die ('You must define at least one controller for the <b>' $requestModule '</b> module');
  98.         }
  99.         // Now require the files specific for each controller
  100.         foreach ($modules as $value
  101.         {
  102.             // MODEL class
  103.             if(file_exists(DOTKERNEL_PATH '/' $modulePath $value '.php'))
  104.             {
  105.                 require_once(DOTKERNEL_PATH '/' $modulePath $value '.php');
  106.             
  107.             else die ('The file: ' DOTKERNEL_PATH '/' $modulePath $value '.php' ' does NOT exist');  
  108.             // VIEW class
  109.             if(file_exists(DOTKERNEL_PATH '/' $modulePath 'views/' ucfirst($value'View.php'))
  110.             {
  111.                 require_once(DOTKERNEL_PATH '/' $modulePath 'views/' ucfirst($value'View.php');        
  112.             
  113.             else die ('The file: ' DOTKERNEL_PATH '/' $modulePath 'views/' ucfirst($value'View.php' ' does NOT exist');  
  114.         }
  115.     }
  116.     /**
  117.      * Get the option variables from an xml file for the current dots
  118.      * @param string $requestModule 
  119.      * @param string $requestController 
  120.      * @return Zend_Config 
  121.      */
  122.     public static function getOptionVariables($requestModule,$requestController)
  123.     {        
  124.         $option array();    
  125.         $dirOption CONFIGURATION_PATH.'/dots/';
  126.         $fileOption strtolower($requestController).'.xml';
  127.         $validFile new Zend_Validate_File_Exists();
  128.         $validFile->setDirectory($dirOption);        
  129.         if($validFile->isValid($fileOption))
  130.         {
  131.             $xml new Zend_Config_Xml($dirOption.$fileOption'body');
  132.             $arrayOption $xml->variable->toArray();
  133.             foreach ($arrayOption as $v)
  134.             {
  135.                 if(in_array($v['option']array('global'$requestModule)))
  136.                 {            
  137.                     $option array_merge_recursive($option,$v);
  138.                 }
  139.             }
  140.         }
  141.         // allow that SEO options may be changed - the 2nd param is true(allowModifications)
  142.         $option new Zend_Config($optiontrue);
  143.         return $option;        
  144.     
  145. }

Documentation generated on Wed, 21 Jul 2010 07:34:42 +0000 by phpDocumentor 1.4.3