예제 #1
0
파일: currency.php 프로젝트: cepharum/txf
 public function __construct()
 {
     if (!is_array(static::$currencies)) {
         static::$currencies = config::get('data.currencies', array('EUR' => \de\toxa\txf\_L('€')));
     }
 }
예제 #2
0
파일: pdo.php 프로젝트: cepharum/txf
 /**
  *
  * @param string $dsn name of datasource to connect to
  * @param string $username optional username for authenticating
  * @param string $password optional password to use for authentication
  */
 public function __construct($dsn = null, $username = null, $password = null)
 {
     // got DSN in parameters?
     if ($dsn === null) {
         // no -> use simple definition in runtime configuration
         /**
          * @note This case isn't preferred one.
          * @see datasource::selectConfigured()
          */
         $setup = config::get('datasource');
         $dsn = data::qualifyString(@$setup['dsn']);
         $username = @$setup['user'];
         $password = @$setup['password'];
     }
     // store normalized name of driver used to connect with datasource
     $this->driver = strtolower(trim(strtok($dsn, ':')));
     // establish connection to datasource
     $this->link = new \PDO($dsn, $username, $password);
     /**
      * ensure connection is using utf8 encoding unless disabled in configuration
      */
     if (config::get('datasource.set-utf8-encoding', true)) {
         switch ($this->driver) {
             case 'mysql':
                 $this->link->exec('SET NAMES utf8');
                 break;
             case 'mssql':
                 $this->link->setAttribute(PDO::SQLSRV_ENCODING_UTF8, 1);
                 break;
         }
     }
     $this->transaction = new transaction($this, function (connection $c) {
         txf\log::debug("starting transaction");
         return $c->link->beginTransaction();
     }, function (connection $c) {
         txf\log::debug("committing transaction");
         return $c->link->commit();
     }, function (connection $c) {
         txf\log::debug("reverting transaction");
         return $c->link->rollBack();
     });
 }
예제 #3
0
파일: gettext.php 프로젝트: cepharum/txf
 public function onLoad()
 {
     // select language to use (this must be listed in server's locale -a)
     $this->language = config::get('locale.language', 'en_US.utf8');
     $this->domain = config::get('locale.domain', TXF_APPLICATION);
     putenv('LANGUAGE=' . $this->language);
     putenv('LANG=' . $this->language);
     putenv('LC_ALL=' . $this->language);
     if (!setlocale(LC_ALL, $this->language)) {
         log::error('could not select locale %s', $this->language);
     }
     if (\extension_loaded('gettext')) {
         // bind configured domain to configured path containing l10n files
         $path = config::get('locale.path', path::glue(TXF_APPLICATION_PATH, 'locale'));
         bindtextdomain($this->domain, $path);
         textdomain($this->domain);
         bind_textdomain_codeset($this->domain, 'UTF-8');
         if ($this->domain !== 'txf') {
             // bind domain "txf" to l10n path included with current extension
             $path = path::glue(dirname(__DIR__), 'locale');
             bindtextdomain('txf', $path);
             bind_textdomain_codeset('txf', 'UTF-8');
         }
     }
     self::$collectionMode = config::get('locale.collect.mode', '');
     self::$collectionFile = config::get('locale.collect.file');
 }
예제 #4
0
파일: manager.php 프로젝트: cepharum/txf
 /**
  * Maps viewports onto regions of page.
  *
  * This mapping is supported to improve content/view abstraction by enabling
  * content of viewports being assembled into code of page's regions in a
  * configurable way ...
  *
  * @param array $viewports content of viewports
  * @return array content of regions
  */
 protected function collectRegions($viewports)
 {
     $configs = array(config::getList('view.region'), array(array('name' => 'main', 'viewport' => array('flash', 'title', 'error', 'main')), array('name' => 'head', 'viewport' => array('header')), array('name' => 'foot', 'viewport' => array('footer', 'debug')), array('name' => 'left', 'viewport' => array('navigation')), array('name' => 'right', 'viewport' => array('aside'))));
     $regions = array();
     foreach ($configs as $config) {
         if (is_array($config)) {
             foreach ($config as $region) {
                 // get name of region to customize
                 $name = trim(@$region['name']);
                 if ($name === '') {
                     log::debug('ignoring nameless region configuration');
                     continue;
                 }
                 if (!array_key_exists($name, $regions)) {
                     // region haven't been collected before ...
                     if (array_key_exists('code', $region)) {
                         // there is a line of code containing markers selecting viewports to collect their content in current region
                         // e.g. "{{title}}<some-literal-content-to-insert/>{{main}}"
                         $regions[$name] = data::qualifyString($region['code'], $viewports);
                     } else {
                         if (is_array(@$region['viewport'])) {
                             // collect set of viewports named in configuration
                             foreach (@$region['viewport'] as $viewportName) {
                                 $regions[$name] .= \de\toxa\txf\view::wrapNotEmpty(@$viewports[$viewportName], config::get('view.viewport.wrap.' . $viewportName, ''));
                             }
                         }
                     }
                     // support default content to show if a region keeps empty finally
                     if (trim($regions[$name]) === '') {
                         $regions[$name] = trim(@$region['default']);
                     }
                     // process any additionally contained markers
                     $regions[$name] = data::qualifyString($regions[$name]);
                 }
             }
         }
     }
     return $regions;
 }