i18n::init PHP Method

init() public method

public init ( )
    public function init()
    {
        if ($this->isInitialized()) {
            throw new BadMethodCallException('This object from class ' . __CLASS__ . ' is already initialized. It is not possible to init one object twice!');
        }
        $this->isInitialized = true;
        $this->userLangs = $this->getUserLangs();
        // search for language file
        $this->appliedLang = NULL;
        foreach ($this->userLangs as $priority => $langcode) {
            $this->langFilePath = $this->getConfigFilename($langcode);
            if (file_exists($this->langFilePath)) {
                $this->appliedLang = $langcode;
                break;
            }
        }
        if ($this->appliedLang == NULL) {
            throw new RuntimeException('No language file was found.');
        }
        // search for cache file
        $this->cacheFilePath = $this->cachePath . '/php_i18n_' . md5_file(__FILE__) . '_' . $this->prefix . '_' . $this->appliedLang . '.cache.php';
        // whether we need to create a new cache file
        $outdated = !file_exists($this->cacheFilePath) || filemtime($this->cacheFilePath) < filemtime($this->langFilePath) || $this->mergeFallback && filemtime($this->cacheFilePath) < filemtime($this->getConfigFilename($this->fallbackLang));
        // the fallback language config was updated
        if ($outdated) {
            $config = $this->load($this->langFilePath);
            if ($this->mergeFallback) {
                self::array_extend($config, $this->load($this->getConfigFilename($this->fallbackLang)));
            }
            $compiled = "<?php class " . $this->prefix . " {\n" . $this->compile($config) . 'public static function __callStatic($string, $args) {' . "\n" . '    return vsprintf(constant("self::" . $string), $args);' . "\n}\n}\n" . "function " . $this->prefix . '($string, $args=NULL) {' . "\n" . '    $return = constant("' . $this->prefix . '::".$string);' . "\n" . '    return $args ? vsprintf($return,$args) : $return;' . "\n}";
            if (!is_dir($this->cachePath)) {
                mkdir($this->cachePath, 0755, true);
            }
            if (file_put_contents($this->cacheFilePath, $compiled) === FALSE) {
                throw new Exception("Could not write cache file to path '" . $this->cacheFilePath . "'. Is it writable?");
            }
            chmod($this->cacheFilePath, 0755);
        }
        require_once $this->cacheFilePath;
    }

Usage Example

コード例 #1
0
ファイル: core.php プロジェクト: andreums/framework1.5
 public static function init($debug = false)
 {
     define('FATAL', E_USER_ERROR);
     define('ERROR', E_USER_WARNING);
     define('WARNING', E_USER_NOTICE);
     try {
         include "framework" . DS . "bootstrap.php";
         $error = new ErrorHandler();
         $config = Config::getInstance();
         $baseURL = $config->getbaseurl();
         if (!defined("BASE_URL")) {
             define("BASE_URL", $baseURL);
         }
         $filter = BaseFilter::getInstance();
         new Request();
         $i18n = i18n::init();
         Router::getInstance();
         new Dispatcher();
     } catch (Exception $ex) {
         trigger_error("CORE | There has been an exception at the core of the Framework {$ex->getMessage()} ", E_USER_ERROR);
     }
 }
All Usage Examples Of i18n::init