Beispiel #1
0
 /**
  *
  * @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();
     });
 }
Beispiel #2
0
 /**
  * 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;
 }