Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->appMock = $this->getMock(\Magelight\App::class, [], [], '', false);
     \Magelight\App::forgeMock($this->appMock);
     $this->dbMock = $this->getMock(\Magelight\Db\Common\Adapter::class, [], [], '', false);
     $this->appMock->expects($this->any())->method('db')->with(App::DEFAULT_INDEX)->will($this->returnValue($this->dbMock));
     $this->dbMock->expects($this->any())->method('getType')->will($this->returnValue(\Magelight\Db\Common\Adapter::TYPE_MYSQL));
     $this->ormMock = $this->getMock(\Magelight\Db\Mysql\Orm::class, [], [], '', false);
     \Magelight\Db\Mysql\Orm::forgeMock($this->ormMock);
     $this->ormMock->expects($this->once())->method('create')->with(['arg1' => 'value1'], false);
     $this->model = Model::forge(['arg1' => 'value1']);
 }
Пример #2
0
 /**
  * Fetch entities list
  *
  * @return array
  *
  */
 public function loadEntities()
 {
     if (empty($this->entities)) {
         $configEntities = $this->getEntitiesConfig()->children();
         if (!empty($configEntities)) {
             foreach ($configEntities as $entity) {
                 /** @var $entity \SimpleXMLElement */
                 $this->entities[$entity->getName()] = ['entity' => $entity->getName(), 'comment' => (string) $entity->comment, 'model_class' => !empty($entity->model_class) ? (string) $entity->model_class : self::DEFAULT_MODEL_CLASS];
                 $this->defineEntityIdFieldName($entity)->defineEntityTableName($entity);
                 $this->entities[$entity->getName()]['count'] = $this->getEntityModel($entity->getName())->getOrm()->totalCount();
             }
         } else {
             foreach ($this->db->execute('SHOW TABLES;')->fetchAll() as $table) {
                 $this->entities[$table[0]] = ['table_name' => $table[0], 'entity' => $table[0], 'comment' => null, 'model_class' => null, 'id_field' => 'id'];
                 $this->entities[$table[0]]['count'] = $this->getEntityModel($table[0])->getOrm()->totalCount();
             }
         }
     }
     return $this->entities;
 }
Пример #3
0
 /**
  * Get database
  *
  * @param string $index
  * @return Db\Common\Adapter
  * @throws Exception
  */
 public function db($index = self::DEFAULT_INDEX)
 {
     if (!isset($this->dbs[$index])) {
         $dbConfig = \Magelight\Config::getInstance()->getConfig('/global/db/' . $index, null);
         if (is_null($dbConfig)) {
             throw new \Magelight\Exception("Database `{$index}` configuration not found.");
         }
         $adapterClass = \Magelight\Db\Common\Adapter::getAdapterClassByType((string) $dbConfig->type);
         $db = call_user_func_array([$adapterClass, 'forge'], []);
         /* @var $db \Magelight\Db\Common\Adapter */
         $db->init((array) $dbConfig);
         $this->dbs[$index] = $db;
     }
     return $this->dbs[$index];
 }
Пример #4
0
 /**
  * Rollback transaction
  *
  * @return Orm
  */
 public function rollbackTransaction()
 {
     $this->db->rollBack();
     return $this;
 }