Esempio n. 1
0
 /**
  * Load a configuration file (default value is objects.xml) and add or replace content
  * 
  * @param string $file name of file to parse, file should be in application/configs folder
  * @param boolean $add wether to add to (true) or replace (false) existing configuration data
  * @return boolean true in case of success, false otherwise
  */
 public static function loadConfig($file = 'objects.xml', $add = true)
 {
     $config = Config\Loader::loadConfig($file);
     if ($config === false) {
         return false;
     }
     if ($add === false) {
         self::$_config = $config['objects'];
     } else {
         self::$_config = array_merge(self::$_config, $config['objects']);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * 
  * @param string|array $message
  * @param integer $code
  * @param Exception $previous
  */
 public function __construct($message, $code = 0, Exception $previous = null)
 {
     if (is_array($message)) {
         if (count($message) != 2) {
             throw new \Exception('Array argument should contain exactly two values');
         }
         // key O is key to message, key 1 contains a string or an array of strings
         $key = $message[0];
     } else {
         $key = $message;
     }
     $lang = Core::$lang;
     $res = Config\Loader::loadConfig('messages/exceptions/' . $this->_store . '.xml');
     //\Zend_Debug::dump($res); die;
     $this->_messages = $res['exceptions'];
     if (isset($this->_messages[$key])) {
         $messages = isset($this->_messages[$key]['labels']) ? $this->_messages[$key]['labels'] : array();
         if ($lang != 'en' && isset($messages[$lang])) {
             $str = $messages[$lang];
         } else {
             /* english version should always be available either under the 'en' key or in the parent-level 'label' key */
             $str = isset($messages['en']) ? $messages['en'] : $this->_messages[$key]['label'];
         }
         if ($str !== false && is_array($message)) {
             foreach ((array) $message[1] as $key => $val) {
                 $str = str_replace('%' . $key, is_object($val) ? get_class($val) : $val, $str);
             }
         }
     } else {
         $str = $key;
     }
     $str .= sprintf("\n(file: %s, line: %d", $this->getFile(), $this->getLine());
     if (Core::$env != Core::ENV_PROD) {
         $str .= "\n" . $this->getTraceAsString();
     }
     // if a previously caught exception is passed as parameter, its message is postfixed to current message
     if ($previous instanceof Exception) {
         $str .= "\n" . $previous->getMessage();
     }
     parent::__construct($str, (int) $code);
     //, $previous);
 }
Esempio n. 3
0
 public function validate()
 {
     return true;
     // @todo create XSD models
     $luie = libxml_use_internal_errors();
     libxml_use_internal_errors(true);
     /* XSD validation file -if exists- is based on file name */
     $xsdFileName = substr($this->_filePath, strrpos($this->_filePath, DIRECTORY_SEPARATOR) + 1);
     $xsdFileName = substr($xsdFileName, 0, strpos($xsdFileName, '.'));
     $xsdFileName = Config\Loader::findFile('xsd/' . $xsdFileName . '.xsd');
     if (is_null($xsdFileName)) {
         return true;
     } else {
         $doc = new \DOMDocument();
         $doc->load($this->filePath);
         $validate = $doc->schemaValidate($xsdFileName);
         libxml_use_internal_errors($luie);
         return $validate;
     }
 }
Esempio n. 4
0
 /**
  * Detect all modules directories and try to get config for them
  * @param string $path
  */
 public static function init($path)
 {
     if (Core::getEnvData('cache_configs') !== false) {
         $ckey = 'configs_acl';
         if (($cached = Core::cacheGet($ckey)) !== false) {
             self::$_config = $cached;
             return;
         }
     }
     // load application acl configuration file
     $config = Config\Loader::loadConfig('acl.xml', Config::REALM_CONFIGS);
     $resources = array();
     // add all fragments coming from modules
     foreach (Core\Module::getConfig() as $vendorId => $vendorModules) {
         foreach ($vendorModules as $key => $module) {
             // module menus
             if (isset($module['controller']) && isset($module['controller']['items'])) {
                 // walk recursively through all module's items (menu elements)
                 $resources += self::_getAcl($module['controller']['base'], $module['controller']['items']);
             }
             // and optional menus extensions
             if (isset($module['controllers_extends'])) {
                 foreach ($module['controllers_extends'] as $controller => $data) {
                     $resources += self::_getAcl($module['controller']['base'], $data['items']);
                 }
             }
         }
     }
     if (!isset($config['acl']['resources'])) {
         $config['acl']['resources'] = array();
     }
     $config['acl']['resources'] += $resources;
     self::$_config = $config['acl'];
     if (isset($ckey)) {
         Core::cacheSet($config['acl'], $ckey, true, array('tags' => array('config', 'acl')));
     }
 }
Esempio n. 5
0
 public function loadTemplate($tpl, $module = null)
 {
     $paths = Config::getPaths(Config::REALM_TEMPLATES);
     if ($module) {
         $path = Core::$basePath . 'application/modules/' . $module . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
         if (is_dir($path)) {
             array_unshift($paths, $path);
         }
     }
     if (Core\Layout::$module) {
         $path = Core::$basePath . 'application/modules/' . Core\Layout::$vendor . DIRECTORY_SEPARATOR . Core\Layout::$moduleKey . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
         if (is_dir($path)) {
             array_unshift($paths, $path);
         }
     }
     $files = Config\Loader::findFile($tpl, $paths);
     foreach ($files[Config::DEFAULT_PREFIX] as $file) {
         if (file_exists($file)) {
             return $file;
         }
     }
     return false;
 }
Esempio n. 6
0
 /**
  * Load a configuration file (default value is objects.xml) and add or replace content
  * 
  * @param string $file name of file to parse, file should be in application/configs folder
  * @param boolean $add wether to add to (true) or replace (false) existing configuration data
  * @return boolean true in case of success, false otherwise
  */
 public static function loadConfig($file, $add = true)
 {
     require_once 't41/Config/Loader.php';
     $config = Loader::loadConfig($file);
     if ($config === false) {
         return false;
     }
     if ($add === false) {
         self::$_config = $config;
     } else {
         self::$_config = array_merge(self::$_config, $config);
     }
     return true;
 }
Esempio n. 7
0
 /**
  * Get text message matchin given key in given store for given language
  * 
  * @param string $key	message key
  * @param string $store message store
  * @param string $lang  language iso code 
  * @return string		message if exists, given key otherwise
  */
 public static function getText($key, $store = 'base', $lang = 'en')
 {
     // @todo cache $_messages & $_loaded
     // first have a look at the file loaded status
     if (!isset(self::$_messages[$store]) || !isset(self::$_loaded[$store . '_' . $lang])) {
         if (($config = Config\Loader::loadConfig(self::$basePath . 'configs/messages/' . $store . '.' . $lang . '.xml')) === false) {
             if (($config = Config\Loader::loadConfig(self::$basePath . 'configs/messages/' . $store . '.xml')) === false) {
                 return $key;
             }
         } else {
             // set file as loaded
             self::$_loaded[$store . '_' . $lang] = true;
         }
         self::$_messages = array_merge_recursive(self::$_messages, $config);
     }
     // only keep first part of the store value
     $store = substr($store, 0, strpos($store, DIRECTORY_SEPARATOR));
     return isset(self::$_messages[$store][$key][$lang]) ? self::$_messages[$store][$key][$lang] : $key;
 }
Esempio n. 8
0
 /**
  * Load a configuration file and add or replace content
  * 
  * @param string $file name of file to parse, file should be in application/configs folder
  * @param boolean $add wether to add to (true) or replace (false) existing configuration data
  * @return boolean true in case of success, false otherwise
  */
 public static function loadConfig($file = 'backends.xml', $add = true)
 {
     // load config file (file extension defines which adapter will be used)
     $config = Config\Loader::loadConfig($file);
     if ($config === false) {
         return false;
     }
     if (!isset($config['backends'])) {
         throw new Config\Exception("NO_CONFIG_IN_GIVEN_SOURCE");
     }
     // if the key 'default' exists, it defines the default backend key value
     if (isset($config['backends']['default'])) {
         self::setDefault($config['backends']['default']);
         unset($config['backends']['default']);
     }
     if ($add === false) {
         self::$_config = $config['backends'];
     } else {
         self::$_config = array_merge((array) self::$_config, $config['backends']);
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Detect all modules directories and try to get config for them
  * @param string $path
  */
 public static function init($path)
 {
     self::$_path = $path . 'application/modules' . DIRECTORY_SEPARATOR;
     if (!is_dir(self::$_path)) {
         return false;
     }
     // get config from cache
     if (Core::getEnvData('cache_configs') == "bogus") {
         $ckey = 'configs_modules';
         if (($cached = Core::cacheGet($ckey)) !== false) {
             self::$_config = $cached;
         }
     }
     if (true) {
         //! self::$_config) {
         self::$_config = array();
         self::$_modules = array('enabled' => array(), 'disabled' => array());
         foreach (scandir(self::$_path) as $vendor) {
             if (is_dir(self::$_path . $vendor) && substr($vendor, 0, 1) != '.') {
                 foreach (scandir(self::$_path . $vendor) as $entry) {
                     $fpath = self::$_path . $vendor . DIRECTORY_SEPARATOR . $entry . DIRECTORY_SEPARATOR;
                     if (is_dir($fpath) && substr($entry, 0, 1) != '.') {
                         if (is_dir($fpath . 'configs')) {
                             // register path with $vendor as prefix
                             Config::addPath($fpath . 'configs', Config::REALM_MODULES, null, $vendor);
                         }
                     }
                 }
             }
         }
         // load all detected modules configuration file
         $config = Config\Loader::loadConfig('module.xml', Config::REALM_MODULES);
         // remove useless "modules" key
         foreach ($config as $key => $val) {
             self::$_config[$key] = $val['modules'];
         }
         // cache config if cache is enabled
         if (isset($ckey)) {
             Core::cacheSet(self::$_config, $ckey);
         }
     }
     unset($ckey);
     // build menu
     if (Core::getEnvData('cache_configs') == "bogus") {
         $ckey = 'configs_menu_main';
         if (($cached = Core::cacheGet($ckey)) !== false) {
             $menu = $cached;
         }
     }
     if (true) {
         //! isset($menu)) {
         $menu = new Layout\Menu('main');
         $menu->setLabel('Main Menu');
         foreach (self::$_config as $prefix => $modules) {
             foreach ($modules as $key => $module) {
                 if ($module['enabled'] != 'true') {
                     continue;
                 }
                 $path = Core::$basePath . 'application/modules' . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR . $key;
                 self::bind($module, $path);
                 // if module has controllers, declare them to front controller
                 // then add them to main menu
                 if (isset($module['controller']) || isset($module['controllers_extends'])) {
                     Config::addPath($path . '/controllers/', Config::REALM_CONTROLLERS, null, $module['controller']['base']);
                 }
                 if (isset($module['controller'])) {
                     $menu->addItem($module['controller']['base'], $module['controller']);
                 }
                 // if module extends existing controllers, declare them for inclusion at the end of the process
                 if (isset($module['controllers_extends']) && !empty($module['controllers_extends'])) {
                     $menu->registerExtends($module['controller']['base'], $module['controllers_extends']);
                 }
             }
         }
         // process extends declaration when menu is complete
         $menu->proceedExtends();
         if (isset($ckey)) {
             Core::cacheSet($menu, $ckey);
         }
     }
     Layout::addMenu('main', $menu);
 }