/** * Prepare a new query object. * * @return \Database\Query */ protected function query() { return parent::query()->iterator('Comments'); }
/** * Register plugin components as service. */ protected function boot() { $c = $this->services = new Container(); // Register plugin and kirby core as service parameter $this->share('name', $this->name()); $this->share('version', $this->version()); $this->share('root', $this->kirby->roots()->plugins() . DS . $this->name()); // Register the path finder as service $this->share('finder', function ($c) { return new Finder($c->get('root')); }); // Register configuration store as service $this->share('config', function ($c) { return new Config($c->get('root'), $c->get('name')); }); // Register file cache as service $this->share('cache', function ($c) { return new FileCache($c->finder()->cache()); }); // Register database connection as service $this->share('db', function ($c) { $connections = $c->config()->get('database.connections'); $default = $c->config()->get('database.default', 'sqlite'); $credentials = array_merge($connections[$default], array('type' => $default)); return new Database($credentials); }); // Dynamically resolve database connections for models once a connection // is requested Model::resolver(function () use($c) { return $c->get('db'); }); }