cli = $cli; $this->brew = $brew; $this->site = $site; $this->files = $files; $this->configuration = $configuration; } /** * Install the configuration files for Nginx. * * @return void */ function install() { $this->brew->ensureInstalled('nginx', ['--with-http2']); $this->installConfiguration(); $this->installServer(); $this->installNginxDirectory(); } /** * Install the Nginx configuration file. * * @return void */ function installConfiguration() { $contents = $this->files->get(__DIR__.'/../stubs/nginx.conf'); $this->files->putAsUser( '/usr/local/etc/nginx/nginx.conf', str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents) ); } /** * Install the Valet Nginx server configuration file. * * @return void */ function installServer() { $this->files->ensureDirExists('/usr/local/etc/nginx/valet'); $this->files->putAsUser( '/usr/local/etc/nginx/valet/valet.conf', str_replace( ['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX'], [VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX], $this->files->get(__DIR__.'/../stubs/valet.conf') ) ); $this->files->putAsUser( '/usr/local/etc/nginx/fastcgi_params', $this->files->get(__DIR__.'/../stubs/fastcgi_params') ); } /** * Install the Nginx configuration directory to the ~/.valet directory. * * This directory contains all site-specific Nginx servers. * * @return void */ function installNginxDirectory() { if (! $this->files->isDir($nginxDirectory = VALET_HOME_PATH.'/Nginx')) { $this->files->mkdirAsUser($nginxDirectory); } $this->files->putAsUser($nginxDirectory.'/.keep', "\n"); $this->rewriteSecureNginxFiles(); } /** * Generate fresh Nginx servers for existing secure sites. * * @return void */ function rewriteSecureNginxFiles() { $domain = $this->configuration->read()['domain']; $this->site->resecureForNewDomain($domain, $domain); } /** * Restart the Nginx service. * * @return void */ function restart() { $this->brew->restartService('nginx'); } /** * Stop the Nginx service. * * @return void */ function stop() { $this->cli->quietly('sudo brew services stop nginx'); } /** * Prepare Nginx for uninstallation. * * @return void */ function uninstall() { $this->stop(); } }