/** * Initializes the application component. * This method overrides the parent implementation by establishing the database connection. */ public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); $this->db->getCollection($this->itemTable)->createIndex(['name' => 1], ['unique' => true]); $this->db->getCollection($this->ruleTable)->createIndex(['name' => 1], ['unique' => true]); }
/** * Initializes the DbMessageSource component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * Configured [[cache]] component would also be initialized. * * @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid. */ public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); if ($this->enableCaching) { $this->cache = Instance::ensure($this->cache, Cache::className()); } }
public function init() { $this->db = Instance::ensure($this->db, Connection::className()); }
/** * Fetches associated file collection from stream options. * @return Collection file collection instance. * @throws InvalidConfigException on invalid stream options. */ private function fetchCollection() { $contextOptions = $this->getContextOptions(); if (isset($contextOptions[$this->protocol]['collection'])) { $collection = $contextOptions[$this->protocol]['collection']; if ($collection instanceof Collection) { throw new InvalidConfigException('"collection" context option should be an instance of "' . Collection::className() . '"'); } return $collection; } if (isset($contextOptions[$this->protocol]['db'])) { $connection = $contextOptions[$this->protocol]['db']; } else { $connection = 'mongodb'; } /* @var $connection Connection */ $connection = Instance::ensure($connection, Connection::className()); list($databaseName, $collectionPrefix) = explode('.', $this->namespace, 2); return $connection->getDatabase($databaseName)->getFileCollection($collectionPrefix); }