/** * Service Provider Boot * * @return void */ public function boot() { if (app()->runningInConsole() === false) { /** @var Request $request */ $request = app('request'); $host = $request->getHttpHost(); $host = $host . str_replace('/index.php', '', $request->server('SCRIPT_NAME')); $site = Site::where('host', $host)->first(); app('xe.site')->setCurrentSite($site); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $siteKey = $this->option('siteKey'); $host = $this->option('host'); $handler = $this->handler; try { $host = $this->validateHost($host); /** @var SiteModel $site */ $site = SiteModel::find($siteKey); $site->host = $host; $handler->put($site); $this->comment($this->description); } catch (NotFoundSiteException $e) { $this->comment("Cannot find site information. (find key :{$siteKey})"); } catch (InvalidArgumentException $e) { $this->comment("{$host} is incorrect host format. ex) example.com "); } }
/** * put * * @param Site $site site object * * @return Site */ public function put(Site $site) { if ($site->isDirty()) { $site->save(); } return $site; }
/** * update * * @param Site $site site entity object * * @return Site */ public function update(Site $site) { $diff = $site->diff(); if (count($diff) > 0) { $this->conn->table($this->table)->where('siteKey', $site->siteKey)->update($diff); } return $this->createModel(array_merge($site->getAttributes(), $diff)); }