mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 08:40:09 +01:00
* Correct the return type annotation in a serves method * Type-hint the driver in the abstract ValetDriver * Correct the return type-hint in the sample ValetDriver * Remove the return afrom the restartLinkedPhp method * Remove the return annotation from the Caddy constructor * Remove the return annotation from the Valet configuration constructor * Removed the return from the prependPath method of the Configuration class * Removed the return from the appendAsUser method of the Filesystem class * Removed the return annotation from the Site constructor * Corrected the parameter annotation of the link method in the Site class * Order use statements by length in PhpFpm * Remove the return annotation from the Valet constructor
117 lines
2.5 KiB
PHP
117 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Valet;
|
|
|
|
class Caddy
|
|
{
|
|
var $cli;
|
|
var $files;
|
|
var $daemonPath = '/Library/LaunchDaemons/com.laravel.valetServer.plist';
|
|
|
|
/**
|
|
* Create a new Brew instance.
|
|
*
|
|
* @param CommandLine $cli
|
|
* @param Filesystem $files
|
|
*/
|
|
function __construct(CommandLine $cli, Filesystem $files)
|
|
{
|
|
$this->cli = $cli;
|
|
$this->files = $files;
|
|
}
|
|
|
|
/**
|
|
* Install the system launch daemon for the Caddy server.
|
|
*
|
|
* @return void
|
|
*/
|
|
function install()
|
|
{
|
|
$this->installCaddyFile();
|
|
$this->installCaddyDirectory();
|
|
$this->installCaddyDaemon();
|
|
}
|
|
|
|
/**
|
|
* Install the Caddyfile to the ~/.valet directory.
|
|
*
|
|
* This file serves as the main server configuration for Valet.
|
|
*
|
|
* @return void
|
|
*/
|
|
function installCaddyFile()
|
|
{
|
|
$this->files->putAsUser(
|
|
VALET_HOME_PATH.'/Caddyfile',
|
|
str_replace('VALET_HOME_PATH', VALET_HOME_PATH, $this->files->get(__DIR__.'/../stubs/Caddyfile'))
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Install the Caddy configuration directory to the ~/.valet directory.
|
|
*
|
|
* This directory contains all site-specific Caddy definitions.
|
|
*
|
|
* @return void
|
|
*/
|
|
function installCaddyDirectory()
|
|
{
|
|
if (! $this->files->isDir($caddyDirectory = VALET_HOME_PATH.'/Caddy')) {
|
|
$this->files->mkdirAsUser($caddyDirectory);
|
|
}
|
|
|
|
$this->files->touchAsUser($caddyDirectory.'/.keep');
|
|
}
|
|
|
|
/**
|
|
* Install the Caddy daemon on a system level daemon.
|
|
*
|
|
* @return void
|
|
*/
|
|
function installCaddyDaemon()
|
|
{
|
|
$contents = str_replace(
|
|
'VALET_PATH', $this->files->realpath(__DIR__.'/../../'),
|
|
$this->files->get(__DIR__.'/../stubs/daemon.plist')
|
|
);
|
|
|
|
$this->files->put(
|
|
$this->daemonPath, str_replace('VALET_HOME_PATH', VALET_HOME_PATH, $contents)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Restart the launch daemon.
|
|
*
|
|
* @return void
|
|
*/
|
|
function restart()
|
|
{
|
|
$this->cli->quietly('sudo launchctl unload '.$this->daemonPath);
|
|
|
|
$this->cli->quietly('sudo launchctl load '.$this->daemonPath);
|
|
}
|
|
|
|
/**
|
|
* Stop the launch daemon.
|
|
*
|
|
* @return void
|
|
*/
|
|
function stop()
|
|
{
|
|
$this->cli->quietly('sudo launchctl unload '.$this->daemonPath);
|
|
}
|
|
|
|
/**
|
|
* Remove the launch daemon.
|
|
*
|
|
* @return void
|
|
*/
|
|
function uninstall()
|
|
{
|
|
$this->stop();
|
|
|
|
$this->files->unlink($this->daemonPath);
|
|
}
|
|
}
|