コード例 #1
0
ファイル: Select.php プロジェクト: control-corp/brands
 /**
  * Sets the primary table name and retrieves the table schema.
  *
  * @param \Micro\Database\Table\TableAbstract $adapter
  * @return \Micro\Database\Select This \Micro\Database\Select object.
  */
 public function setTable(TableAbstract $table)
 {
     $this->_adapter = $table->getAdapter();
     $this->_info = $table->info();
     $this->_table = $table;
     return $this;
 }
コード例 #2
0
 public function rollback()
 {
     if (self::$transactionLevel === 1) {
         $db = $this->table->getAdapter();
         if ($db) {
             $db->rollBack();
         }
     }
     self::$transactionLevel--;
 }
コード例 #3
0
ファイル: Application.php プロジェクト: control-corp/brands
 /**
  * @return \Micro\Application\Application
  */
 public function registerDefaultServices()
 {
     if (!isset($this['request'])) {
         $this['request'] = function () {
             return new Http\Request();
         };
     }
     if (!isset($this['response'])) {
         $this['response'] = function () {
             return new Http\Response\HtmlResponse();
         };
     }
     if (!isset($this['event'])) {
         $this['event'] = function () {
             return new Event\Manager();
         };
     }
     if (!isset($this['exception.handler'])) {
         $this['exception.handler'] = function ($app) {
             return $app;
         };
     }
     if (!isset($this['exception.handler.fallback'])) {
         $this['exception.handler.fallback'] = function ($app) {
             return $app;
         };
     }
     if (!isset($this['acl'])) {
         $this['acl'] = function ($app) {
             if ($app->get('config')->get('acl.enabled', 1)) {
                 return new Acl();
             }
             return \null;
         };
     }
     if (!isset($this['caches'])) {
         $this['caches'] = function ($app) {
             $adapters = $app['config']->get('cache.adapters', []);
             $caches = [];
             foreach ($adapters as $adapter => $config) {
                 $caches[$adapter] = Cache::factory($config['frontend']['adapter'], $config['backend']['adapter'], $config['frontend']['options'], $config['backend']['options']);
             }
             return $caches;
         };
     }
     if (!isset($this['cache'])) {
         $this['cache'] = function ($app) {
             $adapters = $app->get('caches');
             $default = (string) $app['config']->get('cache.default');
             return isset($adapters[$default]) ? $adapters[$default] : \null;
         };
     }
     /**
      * Create router with routes
      */
     if (!isset($this['router'])) {
         $this['router'] = function ($app) {
             return new Router($app['request']);
         };
     }
     /**
      * Create default db adapter
      */
     if (!isset($this['db'])) {
         $this['db'] = function ($app) {
             $default = $app['config']->get('db.default');
             $adapters = $app['config']->get('db.adapters', []);
             if (!isset($adapters[$default])) {
                 return \null;
             }
             $db = Database::factory($adapters[$default]['adapter'], $adapters[$default]);
             TableAbstract::setDefaultAdapter($db);
             TableAbstract::setDefaultMetadataCache($app['cache']);
             return $db;
         };
     }
     /**
      * Create default translator
      */
     if (!isset($this['translator'])) {
         $this['translator'] = function ($app) {
             return new Translator();
         };
     }
     /**
      * Register session config
      */
     $sessionConfig = $this['config']->get('session', []);
     if (!empty($sessionConfig)) {
         Session::register($sessionConfig);
     }
     CoreLog::register();
     CoreException::register();
     return $this;
 }
コード例 #4
0
ファイル: RowAbstract.php プロジェクト: control-corp/micro
 /**
  * _getTableFromString
  *
  * @param string $tableName
  * @return \Micro\Database\Table\TableAbstract
  */
 protected function _getTableFromString($tableName)
 {
     return TableAbstract::getTableFromString($tableName, $this->_table);
 }
コード例 #5
0
ファイル: TableAbstract.php プロジェクト: control-corp/brands
 /**
  * @param string $tableName
  * @param TableAbstract $referenceTable
  * @throws \Exception
  * @return \Micro\Database\Table\TableAbstract
  */
 public static function getTableFromString($tableName, TableAbstract $referenceTable = null)
 {
     // assume the tableName is the class name
     if (!class_exists($tableName)) {
         throw new Exception("Class '{$tableName}' does not exists");
     }
     $options = array();
     if ($referenceTable instanceof TableAbstract) {
         $options['db'] = $referenceTable->getAdapter();
     }
     return new $tableName($options);
 }
コード例 #6
0
ファイル: Select.php プロジェクト: control-corp/brands
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|\Micro\Database\Expr|\Micro\Database\Table\TableAbstract $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|\Micro\Database\Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return \Micro\Database\Table\Select This \Micro\Database\Table\Select object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof TableAbstract) {
         $info = $name->info();
         $name = $info[TableAbstract::NAME];
         if (isset($info[TableAbstract::SCHEMA])) {
             $schema = $info[TableAbstract::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }
コード例 #7
0
ファイル: Application.php プロジェクト: control-corp/micro
 public function registerDbBinder()
 {
     $config = $this->container->get('config');
     $this->container->set('db', function ($container) use($config) {
         $default = $config->get('db.default');
         $adapters = $config->get('db.adapters', []);
         if (!isset($adapters[$default]) || !isset($adapters[$default]['adapter'])) {
             return \null;
         }
         return Database::factory($adapters[$default]['adapter'], $adapters[$default]);
     }, \false);
     if ($config->get('db.set_default_adapter')) {
         TableAbstract::setDefaultAdapter($this->container->get('db'));
     }
     if ($config->get('db.set_default_cache')) {
         TableAbstract::setDefaultMetadataCache($this->container->get('cache'));
     }
 }