public function loadDependencies()
 {
     if ($this->db === null) {
         $this->db = \Config\Database::connect($this->DBGroup);
         $this->db->initialize();
     }
     if ($this->migrations === null) {
         // Ensure that we can run migrations
         $config = new \Config\Migrations();
         $config->enabled = true;
         $this->migrations = Services::migrations($config, $this->db);
         $this->migrations->setSilent(true);
     }
     if ($this->seeder === null) {
         $this->seeder = \Config\Database::seeder($this->DBGroup);
         $this->seeder->setSilent(true);
     }
 }
Esempio n. 2
0
 /**
  * Seeder constructor.
  *
  * @param BaseConfig $config
  * @param BaseConnection $db
  */
 public function __construct(BaseConfig $config, BaseConnection $db = null)
 {
     $this->seedPath = $config->filesPath ?? APPPATH . 'Database/';
     if (empty($this->seedPath)) {
         throw new \InvalidArgumentException('Invalid filesPath set in the Config\\Database.');
     }
     $this->seedPath = rtrim($this->seedPath, '/') . '/Seeds/';
     if (!is_dir($this->seedPath)) {
         throw new \InvalidArgumentException('Unable to locate the seeds directory. Please check Config\\Database::filesPath');
     }
     $this->config =& $config;
     if (is_null($db)) {
         $db = \Config\Database::connect($this->DBGroup);
     }
     $this->db =& $db;
 }
Esempio n. 3
0
 /**
  * Provides a shared instance of the Query Builder.
  *
  * @param string $table
  *
  * @return BaseBuilder|Database\QueryBuilder
  */
 protected function builder(string $table = null)
 {
     if ($this->builder instanceof BaseBuilder) {
         return $this->builder;
     }
     $table = empty($table) ? $this->table : $table;
     // Ensure we have a good db connection
     if (!$this->db instanceof BaseConnection) {
         $this->db = Database::connect($this->DBGroup);
     }
     $this->builder = $this->db->table($table);
     return $this->builder;
 }
Esempio n. 4
0
 /**
  * Constructor.
  * 
  * @param BaseConfig $config
  * @param \CodeIgniter\Database\ConnectionInterface $db
  * @throws ConfigException
  */
 public function __construct(BaseConfig $config, ConnectionInterface $db = null)
 {
     $this->enabled = $config->enabled ?? false;
     $this->type = $config->type ?? 'timestamp';
     $this->table = $config->table ?? 'migrations';
     $this->currentVersion = $config->currentVersion ?? 0;
     $this->path = $config->path ?? APPPATH . 'Database/Migrations/';
     $this->path = rtrim($this->path, '/') . '/';
     if (empty($this->table)) {
         throw new ConfigException('Migrations table must be set.');
     }
     if (!in_array($this->type, ['sequential', 'timestamp'])) {
         throw new ConfigException('An invalid migration numbering type was specified: ' . $this->type);
     }
     // Migration basename regex
     $this->regex = $this->type === 'timestamp' ? '/^\\d{14}_(\\w+)$/' : '/^\\d{3}_(\\w+)$/';
     // If no db connection passed in, use
     // default database group.
     $this->db = !empty($db) ? $db : \Config\Database::connect();
     $this->ensureTable();
 }