From 1999488635f74dc262b1a8380ddb8c639edd5f68 Mon Sep 17 00:00:00 2001 From: Lou van der Laarse Date: Mon, 26 Aug 2019 22:26:58 +0200 Subject: [PATCH] Add PHP_CodeSniffer and PSR-2 as project dependency (#399) * Add PHP_CodeSniffer as project dependency * Refactor code with PSR-2 automated fixes by phpcbf command * Refactor code for manual required PSR-2 rules --- cli/Valet/AbstractPecl.php | 30 ++-- cli/Valet/AbstractService.php | 26 +-- cli/Valet/Binaries.php | 16 +- cli/Valet/Brew.php | 31 ++-- cli/Valet/CommandLine.php | 15 +- cli/Valet/Configuration.php | 39 ++--- cli/Valet/DevTools.php | 39 +++-- cli/Valet/DnsMasq.php | 34 ++-- cli/Valet/Elasticsearch.php | 30 ++-- cli/Valet/Filesystem.php | 63 ++++---- cli/Valet/Logs.php | 2 +- cli/Valet/Mailhog.php | 24 +-- cli/Valet/Memcache.php | 12 +- cli/Valet/Mysql.php | 2 +- cli/Valet/Nginx.php | 36 +++-- cli/Valet/Ngrok.php | 6 +- cli/Valet/Pecl.php | 75 +++++---- cli/Valet/PeclCustom.php | 30 ++-- cli/Valet/PhpFpm.php | 72 +++++---- cli/Valet/RabbitMq.php | 20 +-- cli/Valet/RedisTool.php | 22 +-- cli/Valet/Site.php | 80 +++++---- cli/Valet/Valet.php | 13 +- cli/Valet/Varnish.php | 20 +-- cli/drivers/BedrockValetDriver.php | 3 +- cli/drivers/Concrete5ValetDriver.php | 1 - cli/drivers/CraftValetDriver.php | 2 +- cli/drivers/KirbyValetDriver.php | 8 +- cli/drivers/Magento2ValetDriver.php | 34 ++-- cli/drivers/MagentoValetDriver.php | 5 +- cli/drivers/PimcoreValetDriver.php | 6 +- cli/drivers/Shopware5ValetDriver.php | 2 +- cli/drivers/Typo3ValetDriver.php | 38 ++--- cli/drivers/ValetDriver.php | 6 +- ...dPressMultisiteSubdirectoryValetDriver.php | 57 +++---- cli/drivers/WordPressValetDriver.php | 7 +- cli/drivers/require.php | 2 +- cli/includes/facades.php | 88 +++++++--- cli/includes/helpers.php | 14 +- cli/stubs/magento2/env.php | 42 ++--- cli/templates/404.php | 10 +- cli/valet.php | 153 ++++++++---------- composer.json | 3 +- phpcs.xml | 31 ++++ 44 files changed, 678 insertions(+), 571 deletions(-) create mode 100644 phpcs.xml diff --git a/cli/Valet/AbstractPecl.php b/cli/Valet/AbstractPecl.php index b3449c15..8bba0557 100644 --- a/cli/Valet/AbstractPecl.php +++ b/cli/Valet/AbstractPecl.php @@ -30,12 +30,13 @@ abstract class AbstractPecl ]; - var $cli, $files; + public $cli; + public $files; /** * Create a new PECL instance. */ - function __construct(CommandLine $cli, Filesystem $files) + public function __construct(CommandLine $cli, Filesystem $files) { $this->cli = $cli; $this->files = $files; @@ -63,20 +64,20 @@ protected function getExtensionType($extension) */ public function getPhpIniPath() { - $file = str_replace("\n", '', $this->cli->runAsUser('pecl config-get php_ini')); + $file = str_replace("\n", '', $this->cli->runAsUser('pecl config-get php_ini')); - if($file) { - return $file; - } + if ($file) { + return $file; + } - $grep = $this->cli->runAsUser('php -i | grep php.ini'); - preg_match('/Path => ([^\s]*)/',$grep, $match); + $grep = $this->cli->runAsUser('php -i | grep php.ini'); + preg_match('/Path => ([^\s]*)/', $grep, $match); - if(empty($match[1])) { - return ''; - } + if (empty($match[1])) { + return ''; + } - $path = trim($match[1]); + $path = trim($match[1]); return $path . '/php.ini'; } @@ -130,7 +131,7 @@ public function getExtensionDirectory() /** * Uninstall all extensions defined in EXTENSIONS. */ - function uninstallExtensions() + public function uninstallExtensions() { throw new \Exception(__METHOD__.' not implemented!'); } @@ -141,7 +142,8 @@ function uninstallExtensions() * @param bool $onlyDefaults * @throws Exception if not overridden but used. */ - public function installExtensions($onlyDefaults = true){ + public function installExtensions($onlyDefaults = true) + { throw new \Exception(__METHOD__.' not implemented!'); } diff --git a/cli/Valet/AbstractService.php b/cli/Valet/AbstractService.php index 119ba44f..aef9a2bb 100644 --- a/cli/Valet/AbstractService.php +++ b/cli/Valet/AbstractService.php @@ -7,15 +7,15 @@ abstract class AbstractService const STATE_DISABLED = false; const STATE_ENABLED = true; - var $configuration; - var $configClassName; + public $configuration; + public $configClassName; /** * AbstractService constructor. * * @param Configuration $configuration */ - function __construct(Configuration $configuration) + public function __construct(Configuration $configuration) { $this->configuration = $configuration; } @@ -25,7 +25,7 @@ function __construct(Configuration $configuration) * * @return string */ - function getConfigClassName() + public function getConfigClassName() { if (!$this->configClassName) { try { @@ -44,7 +44,7 @@ function getConfigClassName() * * @return bool */ - function isEnabled() + public function isEnabled() { $config = $this->configuration->read(); $name = $this->getConfigClassName(); @@ -57,7 +57,7 @@ function isEnabled() * * @param $state */ - function setEnabled($state) + public function setEnabled($state) { $config = $this->configuration->read(); $name = $this->getConfigClassName(); @@ -71,7 +71,7 @@ function setEnabled($state) /** * Stops the service and stores in configuration it should not be started. */ - function disable() + public function disable() { $this->stop(); $this->setEnabled(self::STATE_DISABLED); @@ -80,7 +80,7 @@ function disable() /** * Installs the service if not installed, restarts it and stores in configuration it should be started. */ - function enable() + public function enable() { $this->setEnabled(self::STATE_ENABLED); if ($this->installed()) { @@ -94,21 +94,21 @@ function enable() /** * Implement installation of the service. */ - abstract function install(); + abstract public function install(); /** * Implement wether or not the service is installed. * @return bool */ - abstract function installed(); + abstract public function installed(); /** * Implement stopping the service. */ - abstract function stop(); + abstract public function stop(); /** * Implement restarting the service. */ - abstract function restart(); -} \ No newline at end of file + abstract public function restart(); +} diff --git a/cli/Valet/Binaries.php b/cli/Valet/Binaries.php index 5713cd68..7b195d54 100644 --- a/cli/Valet/Binaries.php +++ b/cli/Valet/Binaries.php @@ -48,7 +48,8 @@ class Binaries ] ]; - var $cli, $files; + public $cli; + public $files; /** * Create a new Brew instance. @@ -56,7 +57,7 @@ class Binaries * @param CommandLine $cli * @param Filesystem $files */ - function __construct(CommandLine $cli, Filesystem $files) + public function __construct(CommandLine $cli, Filesystem $files) { $this->cli = $cli; $this->files = $files; @@ -70,7 +71,7 @@ function __construct(CommandLine $cli, Filesystem $files) * @return bool * True if installed, false if not installed. */ - function installed($binary) + public function installed($binary) { return $this->files->exists(self::SUPPORTED_CUSTOM_BINARIES[$binary]['bin_location'] . $binary); } @@ -78,7 +79,7 @@ function installed($binary) /** * Install all binaries defined in SUPPORTED_CUSTOM_BINARIES */ - function installBinaries() + public function installBinaries() { info("[binaries] Installing binaries"); foreach (self::SUPPORTED_CUSTOM_BINARIES as $binary => $versions) { @@ -94,7 +95,7 @@ function installBinaries() * @param $binary * The binary key name. */ - function installBinary($binary) + public function installBinary($binary) { $url = $this->getUrl($binary); $urlSplit = explode('/', $url); @@ -124,7 +125,7 @@ function installBinary($binary) /** * Uninstall all binaries defined in SUPPORTED_CUSTOM_BINARIES */ - function uninstallBinaries() + public function uninstallBinaries() { info("[binaries] Uninstalling binaries"); foreach (self::SUPPORTED_CUSTOM_BINARIES as $binary => $versions) { @@ -140,7 +141,7 @@ function uninstallBinaries() * @param $binary * The binary key name. */ - function uninstallBinary($binary) + public function uninstallBinary($binary) { $binaryLocation = $this->getBinLocation($binary); $this->cli->runAsUser('rm ' . $binaryLocation); @@ -217,4 +218,3 @@ private function getBinLocation($binary) throw new DomainException('bin_location key is required for binaries.'); } } - diff --git a/cli/Valet/Brew.php b/cli/Valet/Brew.php index 2fe5d175..a65624e7 100644 --- a/cli/Valet/Brew.php +++ b/cli/Valet/Brew.php @@ -7,7 +7,8 @@ class Brew { - var $cli, $files; + public $cli; + public $files; /** * Create a new Brew instance. @@ -15,7 +16,7 @@ class Brew * @param CommandLine $cli * @param Filesystem $files */ - function __construct(CommandLine $cli, Filesystem $files) + public function __construct(CommandLine $cli, Filesystem $files) { $this->cli = $cli; $this->files = $files; @@ -27,7 +28,7 @@ function __construct(CommandLine $cli, Filesystem $files) * @param string $formula * @return bool */ - function installed($formula) + public function installed($formula) { return in_array($formula, explode(PHP_EOL, $this->cli->runAsUser('brew list | grep ' . $formula))); } @@ -37,7 +38,7 @@ function installed($formula) * * @return bool */ - function hasInstalledNginx() + public function hasInstalledNginx() { return $this->installed('nginx') || $this->installed('nginx-full'); @@ -48,7 +49,7 @@ function hasInstalledNginx() * * @return string */ - function nginxServiceName() + public function nginxServiceName() { return $this->installed('nginx-full') ? 'nginx-full' : 'nginx'; } @@ -61,7 +62,7 @@ function nginxServiceName() * @param array $taps * @return void */ - function ensureInstalled($formula, $options = [], $taps = []) + public function ensureInstalled($formula, $options = [], $taps = []) { if (!$this->installed($formula)) { $this->installOrFail($formula, $options, $taps); @@ -76,7 +77,7 @@ function ensureInstalled($formula, $options = [], $taps = []) * @param array $taps * @return void */ - function ensureUninstalled($formula, $options = [], $taps = []) + public function ensureUninstalled($formula, $options = [], $taps = []) { if ($this->installed($formula)) { $this->uninstallOrFail($formula, $options, $taps); @@ -91,7 +92,7 @@ function ensureUninstalled($formula, $options = [], $taps = []) * @param array $taps * @return void */ - function installOrFail($formula, $options = [], $taps = []) + public function installOrFail($formula, $options = [], $taps = []) { info('[' . $formula . '] Installing'); @@ -117,7 +118,7 @@ function ($exitCode, $errorOutput) use ($formula) { * @param array $taps * @return void */ - function uninstallOrFail($formula, $options = [], $taps = []) + public function uninstallOrFail($formula, $options = [], $taps = []) { info('[' . $formula . '] Uninstalling'); @@ -141,7 +142,7 @@ function ($exitCode, $errorOutput) use ($formula) { * @param dynamic [string] $formula * @return void */ - function tap($formulas) + public function tap($formulas) { $formulas = is_array($formulas) ? $formulas : func_get_args(); @@ -156,7 +157,7 @@ function tap($formulas) * @param dynamic [string] $formula * @return void */ - function unTap($formulas) + public function unTap($formulas) { $formulas = is_array($formulas) ? $formulas : func_get_args(); @@ -171,7 +172,7 @@ function unTap($formulas) * @param $formula * @return bool */ - function hasTap($formula) + public function hasTap($formula) { return strpos($this->cli->runAsUser("brew tap | grep $formula"), $formula) !== false; } @@ -181,7 +182,7 @@ function hasTap($formula) * * @param */ - function restartService($services) + public function restartService($services) { $services = is_array($services) ? $services : func_get_args(); @@ -200,7 +201,7 @@ function restartService($services) * * @param */ - function stopService($services) + public function stopService($services) { $services = is_array($services) ? $services : func_get_args(); @@ -219,7 +220,7 @@ function stopService($services) * @param $formula * @return bool */ - function isStartedService($formula) + public function isStartedService($formula) { $info = explode(" ", trim(str_replace($formula, "", $this->cli->runAsUser('brew services list | grep ' . $formula)))); $state = array_shift($info); diff --git a/cli/Valet/CommandLine.php b/cli/Valet/CommandLine.php index 341d1606..faef1dc8 100644 --- a/cli/Valet/CommandLine.php +++ b/cli/Valet/CommandLine.php @@ -12,7 +12,7 @@ class CommandLine * @param string $command * @return void */ - function quietly($command) + public function quietly($command) { $this->runCommand($command.' > /dev/null 2>&1'); } @@ -23,7 +23,7 @@ function quietly($command) * @param string $command * @return void */ - function quietlyAsUser($command) + public function quietlyAsUser($command) { $this->quietly('sudo -u '.user().' '.$command.' > /dev/null 2>&1'); } @@ -34,7 +34,7 @@ function quietlyAsUser($command) * @param string $command * @return void */ - function passthru($command) + public function passthru($command) { passthru($command); } @@ -46,7 +46,7 @@ function passthru($command) * @param callable $onError * @return string */ - function run($command, callable $onError = null) + public function run($command, callable $onError = null) { return $this->runCommand($command, $onError); } @@ -58,7 +58,7 @@ function run($command, callable $onError = null) * @param callable $onError * @return string */ - function runAsUser($command, callable $onError = null) + public function runAsUser($command, callable $onError = null) { return $this->runCommand('sudo -u '.user().' '.$command, $onError); } @@ -70,9 +70,10 @@ function runAsUser($command, callable $onError = null) * @param callable $onError * @return string */ - function runCommand($command, callable $onError = null) + public function runCommand($command, callable $onError = null) { - $onError = $onError ?: function () {}; + $onError = $onError ?: function () { + }; $process = new Process($command); diff --git a/cli/Valet/Configuration.php b/cli/Valet/Configuration.php index 2ecf3bf8..7d49f0df 100644 --- a/cli/Valet/Configuration.php +++ b/cli/Valet/Configuration.php @@ -4,14 +4,14 @@ class Configuration { - var $files; + public $files; /** * Create a new Valet configuration class instance. * * @param Filesystem $files */ - function __construct(Filesystem $files) + public function __construct(Filesystem $files) { $this->files = $files; } @@ -21,7 +21,7 @@ function __construct(Filesystem $files) * * @return void */ - function install() + public function install() { $this->createConfigurationDirectory(); $this->createDriversDirectory(); @@ -39,7 +39,7 @@ function install() * * @return void */ - function createConfigurationDirectory() + public function createConfigurationDirectory() { $this->files->ensureDirExists(VALET_HOME_PATH, user()); } @@ -49,7 +49,7 @@ function createConfigurationDirectory() * * @return void */ - function createDriversDirectory() + public function createDriversDirectory() { if ($this->files->isDir($driversDirectory = VALET_HOME_PATH.'/Drivers')) { return; @@ -68,7 +68,7 @@ function createDriversDirectory() * * @return void */ - function createSitesDirectory() + public function createSitesDirectory() { $this->files->ensureDirExists(VALET_HOME_PATH.'/Sites', user()); } @@ -78,7 +78,7 @@ function createSitesDirectory() * * @return void */ - function createExtensionsDirectory() + public function createExtensionsDirectory() { $this->files->ensureDirExists(VALET_HOME_PATH.'/Extensions', user()); } @@ -88,7 +88,7 @@ function createExtensionsDirectory() * * @return void */ - function createLogDirectory() + public function createLogDirectory() { $this->files->ensureDirExists(VALET_HOME_PATH.'/Log', user()); @@ -100,7 +100,7 @@ function createLogDirectory() * * @return void */ - function createCertificatesDirectory() + public function createCertificatesDirectory() { $this->files->ensureDirExists(VALET_HOME_PATH.'/Certificates', user()); } @@ -108,7 +108,7 @@ function createCertificatesDirectory() /** * Write the base, initial configuration for Valet. */ - function writeBaseConfiguration() + public function writeBaseConfiguration() { if (! $this->files->exists($this->path())) { $this->write(['domain' => 'test', 'paths' => []]); @@ -122,7 +122,7 @@ function writeBaseConfiguration() * @param bool $prepend * @return void */ - function addPath($path, $prepend = false) + public function addPath($path, $prepend = false) { $this->write(tap($this->read(), function (&$config) use ($path, $prepend) { $method = $prepend ? 'prepend' : 'push'; @@ -137,7 +137,7 @@ function addPath($path, $prepend = false) * @param string $path * @return void */ - function prependPath($path) + public function prependPath($path) { $this->addPath($path, true); } @@ -148,7 +148,7 @@ function prependPath($path) * @param string $path * @return void */ - function removePath($path) + public function removePath($path) { $this->write(tap($this->read(), function (&$config) use ($path) { $config['paths'] = collect($config['paths'])->reject(function ($value) use ($path) { @@ -162,7 +162,7 @@ function removePath($path) * * @return void */ - function prune() + public function prune() { if (! $this->files->exists($this->path())) { return; @@ -180,7 +180,7 @@ function prune() * * @return array */ - function read() + public function read() { return json_decode($this->files->get($this->path()), true); } @@ -192,7 +192,7 @@ function read() * @param mixed $value * @return array */ - function updateKey($key, $value) + public function updateKey($key, $value) { return tap($this->read(), function (&$config) use ($key, $value) { $config[$key] = $value; @@ -207,10 +207,11 @@ function updateKey($key, $value) * @param array $config * @return void */ - function write($config) + public function write($config) { $this->files->putAsUser($this->path(), json_encode( - $config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES + $config, + JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ).PHP_EOL); } @@ -219,7 +220,7 @@ function write($config) * * @return string */ - function path() + public function path() { return VALET_HOME_PATH.'/config.json'; } diff --git a/cli/Valet/DevTools.php b/cli/Valet/DevTools.php index d1e0b4b1..6aeaf272 100644 --- a/cli/Valet/DevTools.php +++ b/cli/Valet/DevTools.php @@ -18,12 +18,12 @@ class DevTools self::GEOIP_TOOL ]; - var $brew; - var $cli; - var $files; - var $configuration; - var $site; - var $mysql; + public $brew; + public $cli; + public $files; + public $configuration; + public $site; + public $mysql; /** * Create a new Nginx instance. @@ -35,9 +35,14 @@ class DevTools * @param Site $site * @param Mysql $mysql */ - function __construct(Brew $brew, CommandLine $cli, Filesystem $files, - Configuration $configuration, Site $site, Mysql $mysql) - { + public function __construct( + Brew $brew, + CommandLine $cli, + Filesystem $files, + Configuration $configuration, + Site $site, + Mysql $mysql + ) { $this->cli = $cli; $this->brew = $brew; $this->site = $site; @@ -51,7 +56,7 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files, * * @return void */ - function install() + public function install() { info('[devtools] Installing tools'); @@ -69,7 +74,7 @@ function install() * * @return void */ - function uninstall() + public function uninstall() { info('[devtools] Uninstalling tools'); @@ -82,26 +87,26 @@ function uninstall() } } - function sshkey() + public function sshkey() { $this->cli->passthru('pbcopy < ~/.ssh/id_rsa.pub'); info('Copied ssh key to your clipboard'); } - function phpstorm() + public function phpstorm() { info('Opening PHPstorm'); $this->cli->runAsUser('open -a PhpStorm ./'); } - function sourcetree() + public function sourcetree() { info('Opening SourceTree'); $this->cli->runAsUser('open -a SourceTree ./'); } - function vscode() + public function vscode() { info('Opening Visual Studio Code'); $command = false; @@ -125,7 +130,7 @@ function vscode() } } - function tower() + public function tower() { info('Opening git tower'); if (!$this->files->exists('/Applications/Tower.app/Contents/MacOS/gittower')) { @@ -139,7 +144,7 @@ function tower() } } - function configure() + public function configure() { require realpath(__DIR__ . '/../drivers/require.php'); diff --git a/cli/Valet/DnsMasq.php b/cli/Valet/DnsMasq.php index 3d2940f7..a892a6b2 100644 --- a/cli/Valet/DnsMasq.php +++ b/cli/Valet/DnsMasq.php @@ -4,11 +4,13 @@ class DnsMasq { - var $brew, $cli, $files; + public $brew; + public $cli; + public $files; - var $resolverPath = '/etc/resolver'; - var $configPath = '/usr/local/etc/dnsmasq.conf'; - var $exampleConfigPath = '/usr/local/opt/dnsmasq/dnsmasq.conf.example'; + public $resolverPath = '/etc/resolver'; + public $configPath = '/usr/local/etc/dnsmasq.conf'; + public $exampleConfigPath = '/usr/local/opt/dnsmasq/dnsmasq.conf.example'; /** * Create a new DnsMasq instance. @@ -17,7 +19,7 @@ class DnsMasq * @param CommandLine $cli * @param Filesystem $files */ - function __construct(Brew $brew, CommandLine $cli, Filesystem $files) + public function __construct(Brew $brew, CommandLine $cli, Filesystem $files) { $this->cli = $cli; $this->brew = $brew; @@ -29,7 +31,7 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files) * * @return void */ - function install($domain = 'test') + public function install($domain = 'test') { $this->brew->ensureInstalled('dnsmasq'); @@ -49,7 +51,7 @@ function install($domain = 'test') * @param string $domain * @return void */ - function createCustomConfigFile($domain) + public function createCustomConfigFile($domain) { $customConfigPath = $this->customConfigPath(); @@ -65,7 +67,7 @@ function createCustomConfigFile($domain) * * @return void */ - function copyExampleConfig() + public function copyExampleConfig() { if (! $this->files->exists($this->configPath)) { $this->files->copyAsUser( @@ -81,7 +83,7 @@ function copyExampleConfig() * @param string $customConfigPath * @return void */ - function appendCustomConfigImport($customConfigPath) + public function appendCustomConfigImport($customConfigPath) { if (! $this->customConfigIsBeingImported($customConfigPath)) { $this->files->appendAsUser( @@ -97,7 +99,7 @@ function appendCustomConfigImport($customConfigPath) * @param string $customConfigPath * @return bool */ - function customConfigIsBeingImported($customConfigPath) + public function customConfigIsBeingImported($customConfigPath) { return strpos($this->files->get($this->configPath), $customConfigPath) !== false; } @@ -108,7 +110,7 @@ function customConfigIsBeingImported($customConfigPath) * @param string $domain * @return void */ - function createDomainResolver($domain) + public function createDomainResolver($domain) { $this->files->ensureDirExists($this->resolverPath); @@ -122,7 +124,7 @@ function createDomainResolver($domain) * @param string $newDomain * @return void */ - function updateDomain($oldDomain, $newDomain) + public function updateDomain($oldDomain, $newDomain) { $this->files->unlink($this->resolverPath.'/'.$oldDomain); @@ -134,7 +136,7 @@ function updateDomain($oldDomain, $newDomain) * * @return string */ - function customConfigPath() + public function customConfigPath() { return $_SERVER['HOME'].'/.valet/dnsmasq.conf'; } @@ -144,7 +146,8 @@ function customConfigPath() * * @return void */ - function restart() { + public function restart() + { $this->brew->restartService('dnsmasq'); } @@ -153,7 +156,8 @@ function restart() { * * @return void */ - function stop() { + public function stop() + { $this->brew->stopService('dnsmasq'); } } diff --git a/cli/Valet/Elasticsearch.php b/cli/Valet/Elasticsearch.php index c92f5b69..d5e5382e 100644 --- a/cli/Valet/Elasticsearch.php +++ b/cli/Valet/Elasticsearch.php @@ -25,11 +25,11 @@ class Elasticsearch self::ES_V68_VERSION => self::ES_FORMULA_NAME, ]; - var $brew; - var $cli; - var $files; - var $configuration; - var $site; + public $brew; + public $cli; + public $files; + public $configuration; + public $site; /** * Create a new instance. @@ -40,7 +40,7 @@ class Elasticsearch * @param Configuration $configuration * @param Site $site */ - function __construct( + public function __construct( Brew $brew, CommandLine $cli, Filesystem $files, @@ -60,7 +60,7 @@ function __construct( * @param string $version * @return void */ - function install($version = self::ES_DEFAULT_VERSION) + public function install($version = self::ES_DEFAULT_VERSION) { if (!array_key_exists($version, self::SUPPORTED_ES_FORMULAE)) { warning('The Elasticsearch version you\'re installing is not supported.'); @@ -88,7 +88,7 @@ function install($version = self::ES_DEFAULT_VERSION) * @param string $version * @return bool */ - function installed($version = null) + public function installed($version = null) { $versions = ($version ? [$version] : array_keys(self::SUPPORTED_ES_FORMULAE)); foreach ($versions as $version) { @@ -106,7 +106,7 @@ function installed($version = null) * @param string $version * @return void */ - function restart($version = null) + public function restart($version = null) { $version = ($version ? $version : $this->getCurrentVersion()); $version = $this->installed($version); @@ -124,7 +124,7 @@ function restart($version = null) * @param string $version * @return void */ - function stop($version = null) + public function stop($version = null) { $version = ($version ? $version : $this->getCurrentVersion()); $version = $this->installed($version); @@ -142,7 +142,7 @@ function stop($version = null) * * @return void */ - function uninstall() + public function uninstall() { $this->stop(); } @@ -150,7 +150,7 @@ function uninstall() /** * @param $domain */ - function updateDomain($domain) + public function updateDomain($domain) { if ($this->files->exists(self::NGINX_CONFIGURATION_PATH)) { $this->files->putAsUser( @@ -169,7 +169,7 @@ function updateDomain($domain) * * @param $version */ - function switchTo($version) + public function switchTo($version) { $currentVersion = $this->getCurrentVersion(); @@ -196,7 +196,7 @@ function switchTo($version) // Alter elasticsearch data path in config yaml. - if (extension_loaded('yaml')){ + if (extension_loaded('yaml')) { $config = yaml_parse_file(self::ES_CONFIG_YAML); $config[self::ES_CONFIG_DATA_PATH] = self::ES_CONFIG_DATA_BASEPATH . self::SUPPORTED_ES_FORMULAE[$version] . '/'; yaml_emit_file(self::ES_CONFIG_YAML, $config); @@ -214,7 +214,7 @@ function switchTo($version) * * @return bool|int|string */ - function getCurrentVersion() + public function getCurrentVersion() { $currentVersion = false; foreach (self::SUPPORTED_ES_FORMULAE as $version => $formula) { diff --git a/cli/Valet/Filesystem.php b/cli/Valet/Filesystem.php index 868ea305..6b41686e 100644 --- a/cli/Valet/Filesystem.php +++ b/cli/Valet/Filesystem.php @@ -12,7 +12,7 @@ class Filesystem * @param string $path * @return bool */ - function isDir($path) + public function isDir($path) { return is_dir($path); } @@ -25,7 +25,7 @@ function isDir($path) * @param int $mode * @return void */ - function mkdir($path, $owner = null, $mode = 0755) + public function mkdir($path, $owner = null, $mode = 0755) { mkdir($path, $mode, true); @@ -42,7 +42,7 @@ function mkdir($path, $owner = null, $mode = 0755) * @param int $mode * @return void */ - function ensureDirExists($path, $owner = null, $mode = 0755) + public function ensureDirExists($path, $owner = null, $mode = 0755) { if (! $this->isDir($path)) { $this->mkdir($path, $owner, $mode); @@ -56,7 +56,7 @@ function ensureDirExists($path, $owner = null, $mode = 0755) * @param int $mode * @return void */ - function mkdirAsUser($path, $mode = 0755) + public function mkdirAsUser($path, $mode = 0755) { return $this->mkdir($path, user(), $mode); } @@ -68,7 +68,7 @@ function mkdirAsUser($path, $mode = 0755) * @param string|null $owner * @return string */ - function touch($path, $owner = null) + public function touch($path, $owner = null) { touch($path); @@ -85,7 +85,7 @@ function touch($path, $owner = null) * @param string $path * @return void */ - function touchAsUser($path) + public function touchAsUser($path) { return $this->touch($path, user()); } @@ -96,7 +96,7 @@ function touchAsUser($path) * @param string $path * @return bool */ - function exists($path) + public function exists($path) { return file_exists($path); } @@ -107,7 +107,7 @@ function exists($path) * @param string $path * @return string */ - function get($path) + public function get($path) { return file_get_contents($path); } @@ -120,7 +120,7 @@ function get($path) * @param string|null $owner * @return string */ - function put($path, $contents, $owner = null) + public function put($path, $contents, $owner = null) { file_put_contents($path, $contents); @@ -136,7 +136,7 @@ function put($path, $contents, $owner = null) * @param string $contents * @return string */ - function putAsUser($path, $contents) + public function putAsUser($path, $contents) { return $this->put($path, $contents, user()); } @@ -149,7 +149,7 @@ function putAsUser($path, $contents) * @param string|null $owner * @return void */ - function append($path, $contents, $owner = null) + public function append($path, $contents, $owner = null) { file_put_contents($path, $contents, FILE_APPEND); @@ -165,7 +165,7 @@ function append($path, $contents, $owner = null) * @param string $contents * @return void */ - function appendAsUser($path, $contents) + public function appendAsUser($path, $contents) { $this->append($path, $contents, user()); } @@ -177,12 +177,13 @@ function appendAsUser($path, $contents) * @param string $to * @return void */ - function copy($from, $to) + public function copy($from, $to) { copy($from, $to); } - function move($from, $to) { + public function move($from, $to) + { rename($from, $to); } @@ -193,7 +194,7 @@ function move($from, $to) { * @param string $to * @return void */ - function copyAsUser($from, $to) + public function copyAsUser($from, $to) { copy($from, $to); @@ -207,7 +208,7 @@ function copyAsUser($from, $to) * @param string $link * @return void */ - function symlink($target, $link) + public function symlink($target, $link) { if ($this->exists($link)) { $this->unlink($link); @@ -225,7 +226,7 @@ function symlink($target, $link) * @param string $link * @return void */ - function symlinkAsUser($target, $link) + public function symlinkAsUser($target, $link) { if ($this->exists($link)) { $this->unlink($link); @@ -240,7 +241,7 @@ function symlinkAsUser($target, $link) * @param string $path * @return void */ - function unlink($path) + public function unlink($path) { if (file_exists($path) || is_link($path)) { @unlink($path); @@ -253,19 +254,21 @@ function unlink($path) * @param string $path * @param string $user */ - function chown($path, $user) + public function chown($path, $user) { chown($path, $user); } - function chmod($filename, $mode) { - chmod($filename , $mode); + public function chmod($filename, $mode) + { + chmod($filename, $mode); } - function chmodPath($pathname, $filemode) { + public function chmodPath($pathname, $filemode) + { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pathname)); - foreach($iterator as $item) { + foreach ($iterator as $item) { chmod($item, $filemode); } } @@ -276,7 +279,7 @@ function chmodPath($pathname, $filemode) { * @param string $path * @param string $group */ - function chgrp($path, $group) + public function chgrp($path, $group) { chgrp($path, $group); } @@ -287,7 +290,7 @@ function chgrp($path, $group) * @param string $path * @return string */ - function realpath($path) + public function realpath($path) { return realpath($path); } @@ -298,7 +301,7 @@ function realpath($path) * @param string $path * @return bool */ - function isLink($path) + public function isLink($path) { return is_link($path); } @@ -309,7 +312,7 @@ function isLink($path) * @param string $path * @return string */ - function readLink($path) + public function readLink($path) { return readlink($path); } @@ -320,7 +323,7 @@ function readLink($path) * @param string $path * @return void */ - function removeBrokenLinksAt($path) + public function removeBrokenLinksAt($path) { collect($this->scandir($path)) ->filter(function ($file) use ($path) { @@ -337,7 +340,7 @@ function removeBrokenLinksAt($path) * @param string $path * @return bool */ - function isBrokenLink($path) + public function isBrokenLink($path) { return is_link($path) && ! file_exists($path); } @@ -348,7 +351,7 @@ function isBrokenLink($path) * @param string $path * @return array */ - function scandir($path) + public function scandir($path) { return collect(scandir($path)) ->reject(function ($file) { diff --git a/cli/Valet/Logs.php b/cli/Valet/Logs.php index ea749fbd..2b7fe792 100644 --- a/cli/Valet/Logs.php +++ b/cli/Valet/Logs.php @@ -3,7 +3,7 @@ class Logs { - function __construct(CommandLine $cli) + public function __construct(CommandLine $cli) { $this->cli = $cli; } diff --git a/cli/Valet/Mailhog.php b/cli/Valet/Mailhog.php index 8507cf68..a45d82f5 100644 --- a/cli/Valet/Mailhog.php +++ b/cli/Valet/Mailhog.php @@ -5,12 +5,12 @@ class Mailhog extends AbstractService { const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.conf'; - CONST NGINX_CONFIGURATION_PATH = '/usr/local/etc/nginx/valet/mailhog.conf'; + const NGINX_CONFIGURATION_PATH = '/usr/local/etc/nginx/valet/mailhog.conf'; - var $brew; - var $cli; - var $files; - var $site; + public $brew; + public $cli; + public $files; + public $site; /** * Create a new instance. @@ -21,7 +21,7 @@ class Mailhog extends AbstractService * @param Configuration $configuration * @param Site $site */ - function __construct( + public function __construct( Brew $brew, CommandLine $cli, Filesystem $files, @@ -40,7 +40,7 @@ function __construct( * * @return void */ - function install() + public function install() { if ($this->installed()) { info('[mailhog] already installed'); @@ -56,7 +56,7 @@ function install() * * @return bool */ - function installed() + public function installed() { return $this->brew->installed('mailhog'); } @@ -66,7 +66,7 @@ function installed() * * @return void */ - function restart() + public function restart() { if (!$this->installed() || !$this->isEnabled()) { return; @@ -81,7 +81,7 @@ function restart() * * @return void */ - function stop() + public function stop() { if (!$this->installed()) { return; @@ -96,12 +96,12 @@ function stop() * * @return void */ - function uninstall() + public function uninstall() { $this->stop(); } - function updateDomain($domain) + public function updateDomain($domain) { $this->files->putAsUser( self::NGINX_CONFIGURATION_PATH, diff --git a/cli/Valet/Memcache.php b/cli/Valet/Memcache.php index 1b852560..6601cfe7 100644 --- a/cli/Valet/Memcache.php +++ b/cli/Valet/Memcache.php @@ -4,9 +4,9 @@ class Memcache { - var $brew; - var $cli; - var $pecl; + public $brew; + public $cli; + public $pecl; /** * Memcached. @@ -15,7 +15,7 @@ class Memcache * @param CommandLine $cli * @param Pecl $pecl */ - function __construct(Brew $brew, CommandLine $cli, Pecl $pecl) + public function __construct(Brew $brew, CommandLine $cli, Pecl $pecl) { $this->cli = $cli; $this->brew = $brew; @@ -27,7 +27,7 @@ function __construct(Brew $brew, CommandLine $cli, Pecl $pecl) * * @return bool */ - function install() + public function install() { $restart = false; if ($this->brew->installed('libmemcached')) { @@ -50,7 +50,7 @@ function install() * * @return bool */ - function uninstall() + public function uninstall() { info('[memcached] Uninstalling'); $removed = $this->pecl->disableExtension('memcached'); diff --git a/cli/Valet/Mysql.php b/cli/Valet/Mysql.php index 12d95a0f..b9a15bd7 100644 --- a/cli/Valet/Mysql.php +++ b/cli/Valet/Mysql.php @@ -183,7 +183,7 @@ public function restart() public function setRootPassword($oldPwd = '', $newPwd = self::MYSQL_ROOT_PASSWORD) { $success = true; - $this->cli->runAsUser("mysqladmin -u root --password='".$oldPwd."' password ".$newPwd, function() use (&$success) { + $this->cli->runAsUser("mysqladmin -u root --password='".$oldPwd."' password ".$newPwd, function () use (&$success) { warning('Setting password for root user failed. '); $success = false; }); diff --git a/cli/Valet/Nginx.php b/cli/Valet/Nginx.php index b8dc7497..9f886a87 100644 --- a/cli/Valet/Nginx.php +++ b/cli/Valet/Nginx.php @@ -6,11 +6,11 @@ class Nginx { - var $brew; - var $cli; - var $files; - var $configuration; - var $site; + public $brew; + public $cli; + public $files; + public $configuration; + public $site; const NGINX_CONF = '/usr/local/etc/nginx/nginx.conf'; /** @@ -22,9 +22,13 @@ class Nginx * @param Configuration $configuration * @param Site $site */ - function __construct(Brew $brew, CommandLine $cli, Filesystem $files, - Configuration $configuration, Site $site) - { + public function __construct( + Brew $brew, + CommandLine $cli, + Filesystem $files, + Configuration $configuration, + Site $site + ) { $this->cli = $cli; $this->brew = $brew; $this->site = $site; @@ -37,7 +41,7 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files, * * @return void */ - function install() + public function install() { if (!$this->brew->hasInstalledNginx()) { $this->brew->installOrFail('nginx'); @@ -55,7 +59,7 @@ function install() * * @return void */ - function installConfiguration() + public function installConfiguration() { $contents = $this->files->get(__DIR__.'/../stubs/nginx.conf'); @@ -70,7 +74,7 @@ function installConfiguration() * * @return void */ - function installServer() + public function installServer() { $domain = $this->configuration->read()['domain']; @@ -98,7 +102,7 @@ function installServer() * * @return void */ - function installNginxDirectory() + public function installNginxDirectory() { if (! $this->files->isDir($nginxDirectory = VALET_HOME_PATH.'/Nginx')) { $this->files->mkdirAsUser($nginxDirectory); @@ -127,7 +131,7 @@ function ($exitCode, $outputMessage) { * * @return void */ - function rewriteSecureNginxFiles() + public function rewriteSecureNginxFiles() { $domain = $this->configuration->read()['domain']; @@ -139,7 +143,7 @@ function rewriteSecureNginxFiles() * * @return void */ - function restart() + public function restart() { $this->lint(); @@ -151,7 +155,7 @@ function restart() * * @return void */ - function stop() + public function stop() { info('[nginx] Stopping'); @@ -163,7 +167,7 @@ function stop() * * @return void */ - function uninstall() + public function uninstall() { $this->stop(); } diff --git a/cli/Valet/Ngrok.php b/cli/Valet/Ngrok.php index 1b393cc1..1d89096e 100644 --- a/cli/Valet/Ngrok.php +++ b/cli/Valet/Ngrok.php @@ -7,14 +7,14 @@ class Ngrok { - var $tunnelsEndpoint = 'http://127.0.0.1:4040/api/tunnels'; + public $tunnelsEndpoint = 'http://127.0.0.1:4040/api/tunnels'; /** * Get the current tunnel URL from the Ngrok API. * * @return string */ - function currentTunnelUrl() + public function currentTunnelUrl() { return retry(20, function () { $body = Request::get($this->tunnelsEndpoint)->send()->body; @@ -36,7 +36,7 @@ function currentTunnelUrl() * @param array $tunnels * @return string|null */ - function findHttpTunnelUrl($tunnels) + public function findHttpTunnelUrl($tunnels) { foreach ($tunnels as $tunnel) { if ($tunnel->proto === 'http') { diff --git a/cli/Valet/Pecl.php b/cli/Valet/Pecl.php index 95bd1beb..9747ca9f 100644 --- a/cli/Valet/Pecl.php +++ b/cli/Valet/Pecl.php @@ -80,12 +80,12 @@ class Pecl extends AbstractPecl ] ]; - var $peclCustom; + public $peclCustom; /** * @inheritdoc */ - function __construct(CommandLine $cli, Filesystem $files, PeclCustom $peclCustom) + public function __construct(CommandLine $cli, Filesystem $files, PeclCustom $peclCustom) { parent::__construct($cli, $files); $this->peclCustom = $peclCustom; @@ -102,7 +102,7 @@ public function installExtensions($onlyDefaults = true) continue; } - if($this->getVersion($extension) !== false){ + if ($this->getVersion($extension) !== false) { $this->installExtension($extension); $this->enableExtension($extension); } @@ -117,7 +117,7 @@ public function installExtensions($onlyDefaults = true) * The extension key name. * @return bool */ - function installExtension($extension) + public function installExtension($extension) { if ($this->isInstalled($extension)) { output("\t$extension is already installed, skipping..."); @@ -168,7 +168,7 @@ protected function install($extension, $version = null) * The extension key name. * @return bool */ - function enableExtension($extension) + public function enableExtension($extension) { if ($this->isEnabled($extension) && $this->isEnabledCorrectly($extension)) { output("\t$extension is already enabled, skipping..."); @@ -185,7 +185,7 @@ function enableExtension($extension) * @param $extension * The extension key name. */ - function enable($extension) + public function enable($extension) { $phpIniPath = $this->getPhpIniPath(); $phpIniFile = $this->files->get($phpIniPath); @@ -199,11 +199,11 @@ function enable($extension) /** * @inheritdoc */ - function uninstallExtensions() + public function uninstallExtensions() { info("[PECL] Removing extensions"); foreach (self::EXTENSIONS as $extension => $versions) { - if($this->getVersion($extension) !== false){ + if ($this->getVersion($extension) !== false) { $this->disableExtension($extension); } } @@ -217,10 +217,10 @@ function uninstallExtensions() * @return bool * Whether or not an uninstall happened. */ - function disableExtension($extension) + public function disableExtension($extension) { $version = $this->getVersion($extension); - if($this->isEnabled($extension)){ + if ($this->isEnabled($extension)) { $this->disable($extension); } if ($this->isInstalled($extension)) { @@ -230,7 +230,8 @@ function disableExtension($extension) return false; } - function disable($extension){ + public function disable($extension) + { $this->removeIniDefinition($extension); $this->alternativeDisable($extension); } @@ -313,7 +314,7 @@ private function uninstall($extension, $version = null) /** * Update the default PECL channel. */ - function updatePeclChannel() + public function updatePeclChannel() { info('[PECL] Updating PECL channel: pecl.php.net'); $this->cli->runAsUser('pecl channel-update pecl.php.net'); @@ -322,7 +323,8 @@ function updatePeclChannel() /** * Fix common problems related to the PECL/PEAR installation. */ - function fix(){ + public function fix() + { info('[PECL] Checking pear config...'); // Check if pear config is set correctly as per: // https://github.com/kabel/homebrew-core/blob/2564749d8f73e43cbb8cfc449bca4f564ac0e9e1/Formula/php%405.6.rb @@ -332,7 +334,7 @@ function fix(){ $pearConfigPath = PhpFpm::LOCAL_PHP_FOLDER . "$phpVersion/pear.conf"; - if(!$this->files->exists($pearConfigPath)){ + if (!$this->files->exists($pearConfigPath)) { warning(" Skipping $phpVersion, Pear config path could not be found at: $pearConfigPath"); continue; } @@ -342,17 +344,17 @@ function fix(){ $pearConfigVersion = ''; $pearConfig = false; - foreach($pearConfigSplit as $splitValue){ - if(strpos($splitValue, 'php_ini')){ + foreach ($pearConfigSplit as $splitValue) { + if (strpos($splitValue, 'php_ini')) { $pearConfig = unserialize($splitValue); - }else if(strpos($splitValue, 'Config')){ + } else if (strpos($splitValue, 'Config')) { $pearConfigVersion = $splitValue; - }else{ + } else { continue; } } - if($pearConfig === false){ + if ($pearConfig === false) { warning("Could not determine pear configuration for PhP version: $phpVersion, skipping..."); continue; } @@ -372,64 +374,64 @@ function fix(){ $phpBinDirPath = "/usr/local/opt/$brewname/bin/php"; // Check php_ini value of par config. - if(empty($pearConfig['php_ini']) || $pearConfig['php_ini'] !== $phpIniPath){ + if (empty($pearConfig['php_ini']) || $pearConfig['php_ini'] !== $phpIniPath) { output(" Setting pear config php_ini directive to: $phpIniPath"); $pearConfig['php_ini'] = $phpIniPath; } // Check php_dir value of par config. - if(empty($pearConfig['php_dir']) || $pearConfig['php_dir'] !== $phpDirPath){ + if (empty($pearConfig['php_dir']) || $pearConfig['php_dir'] !== $phpDirPath) { output(" Setting pear config php_dir directive to: $phpDirPath"); $pearConfig['php_dir'] = $phpDirPath; } // Check doc_dir value of par config. - if(empty($pearConfig['doc_dir']) || $pearConfig['doc_dir'] !== $pearDocDirPath){ + if (empty($pearConfig['doc_dir']) || $pearConfig['doc_dir'] !== $pearDocDirPath) { output(" Setting pear config doc_dir directive to: $pearDocDirPath"); $pearConfig['doc_dir'] = $pearDocDirPath; } // Check ext_dir value of par config. - if(empty($pearConfig['ext_dir']) || $pearConfig['ext_dir'] !== $phpExtensionDirPath){ + if (empty($pearConfig['ext_dir']) || $pearConfig['ext_dir'] !== $phpExtensionDirPath) { output(" Setting pear config ext_dir directive to: $phpExtensionDirPath"); $pearConfig['ext_dir'] = $phpExtensionDirPath; } // Check php_bin value of par config. - if(empty($pearConfig['bin_dir']) || $pearConfig['bin_dir'] !== $phpBinPath){ + if (empty($pearConfig['bin_dir']) || $pearConfig['bin_dir'] !== $phpBinPath) { output(" Setting pear config bin_dir directive to: $phpBinPath"); $pearConfig['bin_dir'] = $phpBinPath; } // Check data_dir value of par config. - if(empty($pearConfig['data_dir']) || $pearConfig['data_dir'] !== $pearDataDirPath){ + if (empty($pearConfig['data_dir']) || $pearConfig['data_dir'] !== $pearDataDirPath) { output(" Setting pear config data_dir directive to: $pearDataDirPath"); $pearConfig['data_dir'] = $pearDataDirPath; } // Check cfg_dir value of par config. - if(empty($pearConfig['cfg_dir']) || $pearConfig['cfg_dir'] !== $pearCfgDirPath){ + if (empty($pearConfig['cfg_dir']) || $pearConfig['cfg_dir'] !== $pearCfgDirPath) { output(" Setting pear config cfg_dir directive to: $pearCfgDirPath"); $pearConfig['cfg_dir'] = $pearCfgDirPath; } // Check www_dir value of par config. - if(empty($pearConfig['www_dir']) || $pearConfig['www_dir'] !== $pearWwwDirPath){ + if (empty($pearConfig['www_dir']) || $pearConfig['www_dir'] !== $pearWwwDirPath) { output(" Setting pear config www_dir directive to: $pearWwwDirPath"); $pearConfig['www_dir'] = $pearWwwDirPath; } // Check man_dir value of par config. - if(empty($pearConfig['man_dir']) || $pearConfig['man_dir'] !== $pearManDirPath){ + if (empty($pearConfig['man_dir']) || $pearConfig['man_dir'] !== $pearManDirPath) { output(" Setting pear config man_dir directive to: $pearManDirPath"); $pearConfig['man_dir'] = $pearManDirPath; } // Check test_dir value of par config. - if(empty($pearConfig['test_dir']) || $pearConfig['test_dir'] !== $pearTestDirPath){ + if (empty($pearConfig['test_dir']) || $pearConfig['test_dir'] !== $pearTestDirPath) { output(" Setting pear config test_dir directive to: $pearTestDirPath"); $pearConfig['test_dir'] = $pearTestDirPath; } // Check php_bin value of par config. - if(empty($pearConfig['php_bin']) || $pearConfig['php_bin'] !== $phpBinDirPath){ + if (empty($pearConfig['php_bin']) || $pearConfig['php_bin'] !== $phpBinDirPath) { output(" Setting pear config php_bin directive to: $phpBinDirPath"); $pearConfig['php_bin'] = $phpBinDirPath; } // Rebuild the config. $pearConfig = serialize($pearConfig); - if(!empty($pearConfigVersion)){ + if (!empty($pearConfigVersion)) { $pearConfig = $pearConfigVersion."\n".$pearConfig; } @@ -441,7 +443,7 @@ function fix(){ /** * @inheritdoc */ - function isInstalled($extension) + public function isInstalled($extension) { return strpos($this->cli->runAsUser('pecl list | grep ' . $extension), $extension) !== false; } @@ -543,7 +545,8 @@ private function getVersion($extension) * @param $extension * @return bool */ - private function isEnabledCorrectly($extension){ + private function isEnabledCorrectly($extension) + { $phpIniPath = $this->getPhpIniPath(); $phpIniFile = $this->files->get($phpIniPath); $type = $this->getExtensionType($extension); @@ -560,7 +563,8 @@ private function isEnabledCorrectly($extension){ * @param $extension * @return bool */ - private function isAlternativeEnabledCorrectly($extension){ + private function isAlternativeEnabledCorrectly($extension) + { switch ($extension) { case self::APCU_BC_EXTENSION: return $this->isEnabledCorrectly(self::APCU_EXTENSION); @@ -569,7 +573,8 @@ private function isAlternativeEnabledCorrectly($extension){ } } - private function replacePhpWithPear($brewname) { + private function replacePhpWithPear($brewname) + { return str_replace('php', 'pear', $brewname); } } diff --git a/cli/Valet/PeclCustom.php b/cli/Valet/PeclCustom.php index 61027846..67dffd68 100644 --- a/cli/Valet/PeclCustom.php +++ b/cli/Valet/PeclCustom.php @@ -67,7 +67,7 @@ class PeclCustom extends AbstractPecl /** * @inheritdoc */ - function __construct(CommandLine $cli, Filesystem $files) + public function __construct(CommandLine $cli, Filesystem $files) { parent::__construct($cli, $files); } @@ -75,7 +75,7 @@ function __construct(CommandLine $cli, Filesystem $files) /** * @inheritdoc */ - function installExtensions($onlyDefaults = true) + public function installExtensions($onlyDefaults = true) { info("[PECL-CUSTOM] Installing extensions"); foreach (self::EXTENSIONS as $extension => $versions) { @@ -96,7 +96,7 @@ function installExtensions($onlyDefaults = true) * The extension key name. * @return bool */ - function installExtension($extension) + public function installExtension($extension) { $version = $this->getVersion($extension); @@ -117,7 +117,7 @@ function installExtension($extension) * The extension key name. * @param $url */ - function install($extension, $url) + public function install($extension, $url) { // Get file name from url @@ -151,7 +151,7 @@ function install($extension, $url) * @param $extensionDirectory * The directory where the .so file needs to be placed. */ - function downloadExtension($extension, $url, $fileName, $extensionAlias, $extensionDirectory) + public function downloadExtension($extension, $url, $fileName, $extensionAlias, $extensionDirectory) { $unpackagedDirectory = $this->getPackagedDirectory($extension); @@ -192,7 +192,7 @@ function downloadExtension($extension, $url, $fileName, $extensionAlias, $extens * The extension key name. * @return bool */ - function enableExtension($extension) + public function enableExtension($extension) { if ($this->isEnabled($extension)) { output("\t$extension is already enabled, skipping..."); @@ -209,7 +209,7 @@ function enableExtension($extension) * @param $extension * The extension key name. */ - function enable($extension) + public function enable($extension) { // Install php.ini directive. $extensionAlias = $this->getExtensionAlias($extension); @@ -225,7 +225,7 @@ function enable($extension) /** * @inheritdoc */ - function uninstallExtensions() + public function uninstallExtensions() { info("[PECL-CUSTOM] Removing extensions"); foreach (self::EXTENSIONS as $extension => $versions) { @@ -240,10 +240,10 @@ function uninstallExtensions() * The extension key name. * @return bool */ - function uninstallExtension($extension) + public function uninstallExtension($extension) { $version = $this->getVersion($extension); - if($this->isEnabled($extension)){ + if ($this->isEnabled($extension)) { $this->disable($extension); } if ($this->isInstalled($extension)) { @@ -258,7 +258,8 @@ function uninstallExtension($extension) * * @param $extension */ - function disable($extension){ + public function disable($extension) + { $this->removeIniDefinition($extension); } @@ -278,7 +279,7 @@ private function uninstall($extension, $version = null) if ($this->files->exists($filePath)) { $this->cli->runAsUser("rm $filePath"); output("\t$extension successfully uninstalled."); - }else{ + } else { output("\t$extension was already removed!"); } } @@ -286,7 +287,7 @@ private function uninstall($extension, $version = null) /** * @inheritdoc */ - function isInstalled($extension) + public function isInstalled($extension) { $extensionDirectory = $this->getExtensionDirectory(); $extensionAlias = $this->getExtensionAlias($extension); @@ -434,5 +435,4 @@ private function getExtensionName($extension) } throw new DomainException('extension_php_name key is required for custom PECL packages'); } - -} \ No newline at end of file +} diff --git a/cli/Valet/PhpFpm.php b/cli/Valet/PhpFpm.php index d4c8c60b..594e1c0f 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -28,7 +28,11 @@ class PhpFpm const LOCAL_PHP_FOLDER = '/usr/local/etc/valet-php/'; - var $brew, $cli, $files, $pecl, $peclCustom; + public $brew; + public $cli; + public $files; + public $pecl; + public $peclCustom; const DEPRECATED_PHP_TAP = 'homebrew/php'; const VALET_PHP_BREW_TAP = 'henkrehorst/php'; @@ -40,7 +44,7 @@ class PhpFpm * @param CommandLine $cli * @param Filesystem $files */ - function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Pecl $pecl, PeclCustom $peclCustom) + public function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Pecl $pecl, PeclCustom $peclCustom) { $this->cli = $cli; $this->brew = $brew; @@ -54,7 +58,7 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Pecl $pecl * * @return void */ - function install() + public function install() { if (!$this->hasInstalledPhp()) { $this->brew->ensureInstalled($this->getFormulaName(self::PHP_V71_VERSION)); @@ -77,7 +81,7 @@ function install() $this->restart(); } - function iniPath() + public function iniPath() { $destFile = dirname($this->fpmConfigPath()); $destFile = str_replace('/php-fpm.d', '', $destFile); @@ -91,7 +95,7 @@ function iniPath() * * @return void */ - function restart() + public function restart() { $this->brew->restartService(self::SUPPORTED_PHP_FORMULAE[$this->linkedPhp()]); } @@ -101,7 +105,7 @@ function restart() * * @return void */ - function stop() + public function stop() { $this->brew->stopService(self::SUPPORTED_PHP_FORMULAE); } @@ -111,7 +115,7 @@ function stop() * * @return string */ - function fpmConfigPath() + public function fpmConfigPath() { $confLookup = [ self::PHP_V73_VERSION => self::LOCAL_PHP_FOLDER . '7.3/php-fpm.d/www.conf', @@ -130,7 +134,7 @@ function fpmConfigPath() * @param $version * @return string Formula name */ - function getFormulaName($version) + public function getFormulaName($version) { return self::SUPPORTED_PHP_FORMULAE[$version]; } @@ -140,13 +144,15 @@ function getFormulaName($version) * * @param $version */ - function switchTo($version) + public function switchTo($version) { $currentVersion = $this->linkedPhp(); if (!array_key_exists($version, self::SUPPORTED_PHP_FORMULAE)) { - throw new DomainException("This version of PHP not available. The following versions are available: " . implode(' ', - array_keys(self::SUPPORTED_PHP_FORMULAE))); + throw new DomainException("This version of PHP not available. The following versions are available: " . implode( + ' ', + array_keys(self::SUPPORTED_PHP_FORMULAE) + )); } // If the current version equals that of the current PHP version, do not switch. @@ -185,7 +191,7 @@ function switchTo($version) * @param $extension * @return bool */ - function enableExtension($extension) + public function enableExtension($extension) { $currentPhpVersion = $this->linkedPhp(); @@ -201,8 +207,10 @@ function enableExtension($extension) } if ($this->files->exists($iniPath . 'ext-' . $extension . '.ini.disabled')) { - $this->files->move($iniPath . 'ext-' . $extension . '.ini.disabled', - $iniPath . 'ext-' . $extension . '.ini'); + $this->files->move( + $iniPath . 'ext-' . $extension . '.ini.disabled', + $iniPath . 'ext-' . $extension . '.ini' + ); } info('Enabled ' . $extension); @@ -215,7 +223,7 @@ function enableExtension($extension) * @param $extension * @return bool */ - function disableExtension($extension) + public function disableExtension($extension) { $iniPath = $this->iniPath(); if ($this->files->exists($iniPath . 'ext-' . $extension . '.ini.disabled')) { @@ -224,8 +232,10 @@ function disableExtension($extension) } if ($this->files->exists($iniPath . 'ext-' . $extension . '.ini')) { - $this->files->move($iniPath . 'ext-' . $extension . '.ini', - $iniPath . 'ext-' . $extension . '.ini.disabled'); + $this->files->move( + $iniPath . 'ext-' . $extension . '.ini', + $iniPath . 'ext-' . $extension . '.ini.disabled' + ); } info('Disabled ' . $extension); @@ -238,7 +248,7 @@ function disableExtension($extension) * @param $extension * @return bool */ - function isExtensionEnabled($extension) + public function isExtensionEnabled($extension) { $currentPhpVersion = $this->brew->linkedPhp(); @@ -258,7 +268,7 @@ function isExtensionEnabled($extension) return true; } - function enableAutoStart() + public function enableAutoStart() { $iniPath = $this->iniPath(); if ($this->files->exists($iniPath . 'z-performance.ini')) { @@ -270,7 +280,7 @@ function enableAutoStart() return false; } - function disableAutoStart() + public function disableAutoStart() { $iniPath = $this->iniPath(); if ($this->files->exists($iniPath . 'z-performance.ini')) { @@ -288,7 +298,7 @@ function disableAutoStart() * @return string * @internal param bool $asFormula */ - function linkedPhp() + public function linkedPhp() { if (!$this->files->isLink('/usr/local/bin/php')) { throw new DomainException("Unable to determine linked PHP."); @@ -312,7 +322,7 @@ function linkedPhp() * * @return bool */ - function hasInstalledPhp() + public function hasInstalledPhp() { foreach (self::SUPPORTED_PHP_FORMULAE as $version => $brewName) { if ($this->brew->installed($brewName)) { @@ -328,7 +338,7 @@ function hasInstalledPhp() * * @return void */ - function updateConfiguration() + public function updateConfiguration() { $contents = $this->files->get($this->fpmConfigPath()); @@ -338,8 +348,11 @@ function updateConfiguration() $contents = preg_replace('/^;?listen\.owner = .+$/m', 'listen.owner = ' . user(), $contents); $contents = preg_replace('/^;?listen\.group = .+$/m', 'listen.group = staff', $contents); $contents = preg_replace('/^;?listen\.mode = .+$/m', 'listen.mode = 0777', $contents); - $contents = preg_replace('/^;?php_admin_value\[error_log\] = .+$/m', - 'php_admin_value[error_log] = ' . VALET_HOME_PATH . '/Log/php.log', $contents); + $contents = preg_replace( + '/^;?php_admin_value\[error_log\] = .+$/m', + 'php_admin_value[error_log] = ' . VALET_HOME_PATH . '/Log/php.log', + $contents + ); $this->files->put($this->fpmConfigPath(), $contents); $this->writePerformanceConfiguration(); @@ -361,10 +374,11 @@ function updateConfiguration() $this->files->putAsUser($phpIniPath, $contents); } - function writePerformanceConfiguration() { + public function writePerformanceConfiguration() + { $path = $this->iniPath() . 'z-performance.ini'; - if(file_exists($path)) { + if (file_exists($path)) { return; } @@ -381,7 +395,7 @@ function writePerformanceConfiguration() { $this->files->putAsUser($path, $contents); } - function checkInstallation() + public function checkInstallation() { // Check for errors within the installation of php. info('[php] Checking for errors within the php installation...'); @@ -416,7 +430,7 @@ function checkInstallation() /** * Fixes common problems with php installations from Homebrew. */ - function fix($reinstall) + public function fix($reinstall) { // Remove old homebrew/php tap packages. info('Removing all old php56- packages from homebrew/php tap'); diff --git a/cli/Valet/RabbitMq.php b/cli/Valet/RabbitMq.php index fdab7bfe..e60f29a0 100644 --- a/cli/Valet/RabbitMq.php +++ b/cli/Valet/RabbitMq.php @@ -4,10 +4,10 @@ class RabbitMq extends AbstractService { - var $brew; - var $cli; - var $files; - var $site; + public $brew; + public $cli; + public $files; + public $site; /** * Create a new instance. @@ -18,7 +18,7 @@ class RabbitMq extends AbstractService * @param Configuration $configuration * @param Site $site */ - function __construct( + public function __construct( Brew $brew, CommandLine $cli, Filesystem $files, @@ -37,7 +37,7 @@ function __construct( * * @return void */ - function install() + public function install() { if ($this->installed()) { info('[rabbitmq] already installed'); @@ -54,7 +54,7 @@ function install() * * @return bool */ - function installed() + public function installed() { return $this->brew->installed('rabbitmq'); } @@ -64,7 +64,7 @@ function installed() * * @return void */ - function restart() + public function restart() { if (!$this->installed() || !$this->isEnabled()) { return; @@ -79,7 +79,7 @@ function restart() * * @return void */ - function stop() + public function stop() { if (!$this->installed()) { return; @@ -94,7 +94,7 @@ function stop() * * @return void */ - function uninstall() + public function uninstall() { $this->stop(); } diff --git a/cli/Valet/RedisTool.php b/cli/Valet/RedisTool.php index 3af43094..e5048d19 100644 --- a/cli/Valet/RedisTool.php +++ b/cli/Valet/RedisTool.php @@ -4,10 +4,10 @@ class RedisTool extends AbstractService { - var $brew; - var $cli; - var $files; - var $site; + public $brew; + public $cli; + public $files; + public $site; const REDIS_CONF = '/usr/local/etc/redis.conf'; @@ -20,7 +20,7 @@ class RedisTool extends AbstractService * @param Configuration $configuration * @param Site $site */ - function __construct( + public function __construct( Brew $brew, CommandLine $cli, Filesystem $files, @@ -39,7 +39,7 @@ function __construct( * * @return void */ - function install() + public function install() { if ($this->installed()) { info('[redis] already installed'); @@ -58,7 +58,7 @@ function install() * * @return bool */ - function installed() + public function installed() { return $this->brew->installed('redis'); } @@ -68,7 +68,7 @@ function installed() * * @return void */ - function installConfiguration() + public function installConfiguration() { $this->files->copy(__DIR__.'/../stubs/redis.conf', static::REDIS_CONF); } @@ -78,7 +78,7 @@ function installConfiguration() * * @return void */ - function restart() + public function restart() { if (!$this->installed() || !$this->isEnabled()) { return; @@ -93,7 +93,7 @@ function restart() * * @return void */ - function stop() + public function stop() { if (!$this->installed()) { return; @@ -109,7 +109,7 @@ function stop() * * @return void */ - function uninstall() + public function uninstall() { $this->stop(); } diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index 39612103..5d030512 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -4,7 +4,9 @@ class Site { - var $config, $cli, $files; + public $config; + public $cli; + public $files; /** * Create a new Site instance. @@ -13,7 +15,7 @@ class Site * @param CommandLine $cli * @param Filesystem $files */ - function __construct(Configuration $config, CommandLine $cli, Filesystem $files) + public function __construct(Configuration $config, CommandLine $cli, Filesystem $files) { $this->cli = $cli; $this->files = $files; @@ -26,7 +28,7 @@ function __construct(Configuration $config, CommandLine $cli, Filesystem $files) * @param string $path * @return string|null */ - function host($path) + public function host($path) { foreach ($this->files->scandir($this->sitesPath()) as $link) { if ($resolved = realpath($this->sitesPath().'/'.$link) === $path) { @@ -44,12 +46,13 @@ function host($path) * @param string $link * @return string */ - function link($target, $link) + public function link($target, $link) { $tld = $this->config->read()['domain']; $link = str_replace('.'.$tld, '', $link); $this->files->ensureDirExists( - $linkPath = $this->sitesPath(), user() + $linkPath = $this->sitesPath(), + user() ); $this->config->prependPath($linkPath); @@ -65,7 +68,8 @@ function link($target, $link) * @param string $filterName * @return \Illuminate\Support\Collection */ - function links($filterName = '') { + public function links($filterName = '') + { $certsPath = VALET_HOME_PATH.'/Certificates'; $this->files->ensureDirExists($certsPath, user()); @@ -81,7 +85,7 @@ function links($filterName = '') { * @param string $path * @return \Illuminate\Support\Collection */ - function getCertificates($path) + public function getCertificates($path) { return collect($this->files->scanDir($path))->filter(function ($value, $key) { return ends_with($value, '.crt'); @@ -98,7 +102,7 @@ function getCertificates($path) * @param $filterName * @return \Illuminate\Support\Collection */ - function getLinks($path, $certs, $filterName = false) + public function getLinks($path, $certs, $filterName = false) { $config = $this->config->read(); $tld = $config['domain']; @@ -109,7 +113,7 @@ function getLinks($path, $certs, $filterName = false) $secured = $certs->has($site); $url = ($secured ? 'https': 'http').'://'.$site.'.'.$tld; - if($filterName) { + if ($filterName) { $site = str_replace('.'.$filterName, '', $site); } else { $site = $site.'.'.$tld; @@ -117,7 +121,7 @@ function getLinks($path, $certs, $filterName = false) return [$site, $secured ? ' X': '', $url, $path]; })->filter(function ($item) use ($filterName, $tld) { - if(!$filterName) { + if (!$filterName) { return true; } @@ -131,7 +135,7 @@ function getLinks($path, $certs, $filterName = false) * @param string $name * @return void */ - function unlink($name) + public function unlink($name) { if ($this->files->exists($path = $this->sitesPath().'/'.$name)) { $this->files->unlink($path); @@ -143,7 +147,7 @@ function unlink($name) * * @return void */ - function pruneLinks() + public function pruneLinks() { $this->files->ensureDirExists($this->sitesPath(), user()); @@ -157,7 +161,7 @@ function pruneLinks() * @param string $domain * @return void */ - function resecureForNewDomain($oldDomain, $domain) + public function resecureForNewDomain($oldDomain, $domain) { if (! $this->files->exists($this->certificatesPath())) { return; @@ -178,7 +182,7 @@ function resecureForNewDomain($oldDomain, $domain) * @param string $url * @return null|string */ - function proxied($url) + public function proxied($url) { $path = VALET_HOME_PATH.'/Nginx/'.$url; if (!$this->files->exists($path)) { @@ -198,7 +202,7 @@ function proxied($url) * @param string $url * @param string $to */ - function proxy($url, $to = null) + public function proxy($url, $to = null) { $this->configure($url, in_array($url, $this->secured()), $to); } @@ -208,7 +212,7 @@ function proxy($url, $to = null) * * @return array */ - function secured() + public function secured() { return collect($this->files->scandir($this->certificatesPath())) ->map(function ($file) { @@ -224,7 +228,7 @@ function secured() * @param null $proxy * @return void */ - function configure($url, $secure = false, $proxy = null) + public function configure($url, $secure = false, $proxy = null) { $this->unsecure($url); @@ -234,7 +238,8 @@ function configure($url, $secure = false, $proxy = null) } $this->files->putAsUser( - VALET_HOME_PATH . '/Nginx/' . $url, $this->buildNginxConfig($url, $secure, $proxy) + VALET_HOME_PATH . '/Nginx/' . $url, + $this->buildNginxConfig($url, $secure, $proxy) ); } @@ -244,7 +249,7 @@ function configure($url, $secure = false, $proxy = null) * @param string $url * @return void */ - function secure($url) + public function secure($url) { $proxied = $this->proxied($url); $this->configure($url, true, $proxied); @@ -256,7 +261,7 @@ function secure($url) * @param string $url * @return void */ - function createCertificate($url) + public function createCertificate($url) { $keyPath = $this->certificatesPath().'/'.$url.'.key'; $csrPath = $this->certificatesPath().'/'.$url.'.csr'; @@ -269,7 +274,10 @@ function createCertificate($url) $this->cli->runAsUser(sprintf( 'openssl x509 -req -days 365 -in %s -signkey %s -out %s -extensions v3_req -extfile %s', - $csrPath, $keyPath, $crtPath, $confPath + $csrPath, + $keyPath, + $crtPath, + $confPath )); $this->trustCertificate($crtPath); @@ -281,7 +289,7 @@ function createCertificate($url) * @param string $keyPath * @return void */ - function createPrivateKey($keyPath) + public function createPrivateKey($keyPath) { $this->cli->runAsUser(sprintf('openssl genrsa -out %s 2048', $keyPath)); } @@ -292,11 +300,14 @@ function createPrivateKey($keyPath) * @param string $keyPath * @return void */ - function createSigningRequest($url, $keyPath, $csrPath, $confPath) + public function createSigningRequest($url, $keyPath, $csrPath, $confPath) { $this->cli->runAsUser(sprintf( 'openssl req -new -key %s -out %s -subj "/C=/ST=/O=/localityName=/commonName=*.%s/organizationalUnitName=/emailAddress=/" -config %s -passin pass:', - $keyPath, $csrPath, $url, $confPath + $keyPath, + $csrPath, + $url, + $confPath )); } @@ -306,10 +317,11 @@ function createSigningRequest($url, $keyPath, $csrPath, $confPath) * @param string $crtPath * @return void */ - function trustCertificate($crtPath) + public function trustCertificate($crtPath) { $this->cli->run(sprintf( - 'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain %s', $crtPath + 'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain %s', + $crtPath )); } @@ -319,7 +331,7 @@ function trustCertificate($crtPath) * @param string $url * @return string */ - function buildCertificateConf($path, $url) + public function buildCertificateConf($path, $url) { $config = str_replace('VALET_DOMAIN', $url, $this->files->get(__DIR__.'/../stubs/openssl.conf')); $this->files->putAsUser($path, $config); @@ -332,7 +344,7 @@ function buildCertificateConf($path, $url) * @param null|string $proxy * @return string */ - function buildNginxConfig($url, $secure, $proxy) + public function buildNginxConfig($url, $secure, $proxy) { $path = $this->certificatesPath(); @@ -363,7 +375,7 @@ function buildNginxConfig($url, $secure, $proxy) * @param string $url * @return void */ - function unsecure($url) + public function unsecure($url) { if ($this->files->exists($this->certificatesPath().'/'.$url.'.crt')) { $this->files->unlink(VALET_HOME_PATH.'/Nginx/'.$url); @@ -382,7 +394,7 @@ function unsecure($url) * * @return string */ - function sitesPath() + public function sitesPath() { return VALET_HOME_PATH.'/Sites'; } @@ -392,7 +404,7 @@ function sitesPath() * * @return string */ - function certificatesPath() + public function certificatesPath() { return VALET_HOME_PATH.'/Certificates'; } @@ -400,7 +412,7 @@ function certificatesPath() /** * @return \Illuminate\Support\Collection */ - function rewrites() + public function rewrites() { $config = $this->config->read(); $rewrites = []; @@ -421,7 +433,7 @@ function rewrites() * @param $host * @return bool|string */ - function rewrite($url, $host) + public function rewrite($url, $host) { $url = (strpos($url, 'www.') === 0 ? substr($url, 4) : $url); $config = $this->config->read(); @@ -449,7 +461,7 @@ function rewrite($url, $host) * @param $url * @return bool|string */ - function unrewrite($url) + public function unrewrite($url) { $url = (strpos($url, 'www.') === 0 ? substr($url, 4) : $url); $config = $this->config->read(); diff --git a/cli/Valet/Valet.php b/cli/Valet/Valet.php index fe0e06b6..6050c693 100644 --- a/cli/Valet/Valet.php +++ b/cli/Valet/Valet.php @@ -4,9 +4,10 @@ class Valet { - var $cli, $files; + public $cli; + public $files; - var $valetBin = '/usr/local/bin/valet'; + public $valetBin = '/usr/local/bin/valet'; /** * Create a new Valet instance. @@ -14,7 +15,7 @@ class Valet * @param CommandLine $cli * @param Filesystem $files */ - function __construct(CommandLine $cli, Filesystem $files) + public function __construct(CommandLine $cli, Filesystem $files) { $this->cli = $cli; $this->files = $files; @@ -25,7 +26,7 @@ function __construct(CommandLine $cli, Filesystem $files) * * @return void */ - function symlinkToUsersBin() + public function symlinkToUsersBin() { $this->cli->quietlyAsUser('rm '.$this->valetBin); @@ -37,7 +38,7 @@ function symlinkToUsersBin() * * @return array */ - function extensions() + public function extensions() { if (! $this->files->isDir(VALET_HOME_PATH.'/Extensions')) { return []; @@ -59,7 +60,7 @@ function extensions() * @param string $currentVersion * @return bool */ - function onLatestVersion($currentVersion) + public function onLatestVersion($currentVersion) { $response = \Httpful\Request::get('https://api.github.com/repos/weprovide/valet-plus/releases/latest')->send(); diff --git a/cli/Valet/Varnish.php b/cli/Valet/Varnish.php index 806b837b..d92274b9 100644 --- a/cli/Valet/Varnish.php +++ b/cli/Valet/Varnish.php @@ -4,10 +4,10 @@ class Varnish extends AbstractService { - var $brew; - var $cli; - var $files; - var $site; + public $brew; + public $cli; + public $files; + public $site; /** * Create a new instance. @@ -18,7 +18,7 @@ class Varnish extends AbstractService * @param Configuration $configuration * @param Site $site */ - function __construct( + public function __construct( Brew $brew, CommandLine $cli, Filesystem $files, @@ -37,7 +37,7 @@ function __construct( * * @return void */ - function install() + public function install() { if ($this->installed()) { info('[varnish] already installed'); @@ -54,7 +54,7 @@ function install() * * @return bool */ - function installed() + public function installed() { return $this->brew->installed('varnish'); } @@ -64,7 +64,7 @@ function installed() * * @return void */ - function restart() + public function restart() { if (!$this->installed() || !$this->isEnabled()) { return; @@ -79,7 +79,7 @@ function restart() * * @return void */ - function stop() + public function stop() { if (!$this->installed()) { return; @@ -94,7 +94,7 @@ function stop() * * @return void */ - function uninstall() + public function uninstall() { $this->stop(); } diff --git a/cli/drivers/BedrockValetDriver.php b/cli/drivers/BedrockValetDriver.php index fa9464db..d166c1ab 100644 --- a/cli/drivers/BedrockValetDriver.php +++ b/cli/drivers/BedrockValetDriver.php @@ -69,7 +69,8 @@ public function frontControllerPath($sitePath, $siteName, $uri) private function forceTrailingSlash($uri) { if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') { - header('Location: '.$uri.'/'); die; + header('Location: '.$uri.'/'); + die; } return $uri; diff --git a/cli/drivers/Concrete5ValetDriver.php b/cli/drivers/Concrete5ValetDriver.php index 986706df..1cddb72c 100644 --- a/cli/drivers/Concrete5ValetDriver.php +++ b/cli/drivers/Concrete5ValetDriver.php @@ -46,5 +46,4 @@ public function frontControllerPath($sitePath, $siteName, $uri) return $sitePath . '/index.php'; } - } diff --git a/cli/drivers/CraftValetDriver.php b/cli/drivers/CraftValetDriver.php index 45cfad7f..f0a5d869 100644 --- a/cli/drivers/CraftValetDriver.php +++ b/cli/drivers/CraftValetDriver.php @@ -193,7 +193,7 @@ public function frontControllerPath($sitePath, $siteName, $uri) $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; $_SERVER['SCRIPT_NAME'] = $scriptName; $_SERVER['PHP_SELF'] = $scriptName; - $_SERVER['DOCUMENT_ROOT'] = $sitePath.'/'.$frontControllerDirectory; + $_SERVER['DOCUMENT_ROOT'] = $sitePath.'/'.$frontControllerDirectory; return $indexPath; } diff --git a/cli/drivers/KirbyValetDriver.php b/cli/drivers/KirbyValetDriver.php index a41b0c8b..b020d7f0 100644 --- a/cli/drivers/KirbyValetDriver.php +++ b/cli/drivers/KirbyValetDriver.php @@ -25,11 +25,11 @@ public function serves($sitePath, $siteName, $uri) */ public function isStaticFile($sitePath, $siteName, $uri) { - if ($this->isActualFile($staticFilePath = $sitePath.$uri)) { - return $staticFilePath; - } + if ($this->isActualFile($staticFilePath = $sitePath.$uri)) { + return $staticFilePath; + } - return false; + return false; } /** * Get the fully resolved path to the application's front controller. diff --git a/cli/drivers/Magento2ValetDriver.php b/cli/drivers/Magento2ValetDriver.php index 07379e42..df37ae04 100644 --- a/cli/drivers/Magento2ValetDriver.php +++ b/cli/drivers/Magento2ValetDriver.php @@ -2,13 +2,14 @@ class Magento2ValetDriver extends ValetDriver { - public function configure($devtools, $url) { + public function configure($devtools, $url) + { info('Configuring Magento 2...'); $devtools->cli->quietlyAsUser('chmod +x bin/magento'); $sitePath = getcwd(); - if(!$this->envExists($sitePath)) { + if (!$this->envExists($sitePath)) { info('env.php missing. Installing default env.php...'); $devtools->files->putAsUser( $sitePath.'/app/etc/env.php', @@ -20,7 +21,7 @@ public function configure($devtools, $url) { ); } - if(!$this->moduleConfigExists($sitePath)) { + if (!$this->moduleConfigExists($sitePath)) { info('config.php missing. Enabling all modules...'); $devtools->cli->quietlyAsUser('bin/magento module:enable --all'); } @@ -55,15 +56,18 @@ public function serves($sitePath, $siteName, $uri) file_exists($sitePath . '/bin/magento'); } - public function envExists($sitePath) { + public function envExists($sitePath) + { return file_exists($sitePath.'/app/etc/env.php'); } - public function moduleConfigExists($sitePath) { + public function moduleConfigExists($sitePath) + { return file_exists($sitePath.'/app/etc/config.php'); } - public function installed($sitePath) { + public function installed($sitePath) + { return $this->envExists($sitePath) && $this->moduleConfigExists($sitePath); } @@ -81,11 +85,11 @@ public function isStaticFile($sitePath, $siteName, $uri) $isMagentoStatic = false; $resource = $uri; - if(strpos($uri,'/errors') === 0 && file_exists($sitePath.'/pub'.$uri)) { + if (strpos($uri, '/errors') === 0 && file_exists($sitePath.'/pub'.$uri)) { return $sitePath.'/pub'.$uri; } - if(strpos($uri,'/pub') === 0 && file_exists($sitePath.'/setup'.$uri)) { + if (strpos($uri, '/pub') === 0 && file_exists($sitePath.'/setup'.$uri)) { return $sitePath.'/setup'.$uri; } @@ -137,11 +141,11 @@ public function frontControllerPath($sitePath, $siteName, $uri) $this->loadServerEnvironmentVariables($sitePath, $siteName); $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; - if(isset($_GET['profile'])) { + if (isset($_GET['profile'])) { $_SERVER['MAGE_PROFILER'] = 'html'; } - if(strpos($uri, '/errors') === 0) { + if (strpos($uri, '/errors') === 0) { $file = $sitePath . '/pub' . $uri; if (file_exists($file)) { return $file; @@ -149,31 +153,31 @@ public function frontControllerPath($sitePath, $siteName, $uri) return $sitePath . '/pub/errors/404.php'; } - if($uri === '/setup') { + if ($uri === '/setup') { Header('HTTP/1.1 301 Moved Permanently'); Header('Location: http://' . $_SERVER['HTTP_HOST'] . $uri . '/'); die; } - if(strpos($uri, '/setup') === 0) { + if (strpos($uri, '/setup') === 0) { $_SERVER['SCRIPT_FILENAME'] = $sitePath.'/setup/index.php'; $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['DOCUMENT_ROOT'] = $sitePath.'/setup/'; $_SERVER['REQUEST_URI'] = str_replace('/setup', '', $_SERVER['REQUEST_URI']); - if($_SERVER['REQUEST_URI'] === '') { + if ($_SERVER['REQUEST_URI'] === '') { $_SERVER['REQUEST_URI'] = '/'; } return $sitePath.'/setup/index.php'; } - if(!$this->installed($sitePath)) { + if (!$this->installed($sitePath)) { http_response_code(404); require __DIR__.'/../templates/magento2.php'; exit; } - if(strpos($uri, '/dev/tests/acceptance/utils/command.php') !== false) { + if (strpos($uri, '/dev/tests/acceptance/utils/command.php') !== false) { return $sitePath . '/dev/tests/acceptance/utils/command.php'; } diff --git a/cli/drivers/MagentoValetDriver.php b/cli/drivers/MagentoValetDriver.php index b170aac9..2fb16352 100644 --- a/cli/drivers/MagentoValetDriver.php +++ b/cli/drivers/MagentoValetDriver.php @@ -15,12 +15,13 @@ public function serves($sitePath, $siteName, $uri) return is_dir($sitePath.'/app/code/core/Mage'); } - public function configure($devtools, $url) { + public function configure($devtools, $url) + { info('Configuring Magento...'); $sitePath = getcwd(); - if(!file_exists($sitePath.'/app/etc/local.xml')) { + if (!file_exists($sitePath.'/app/etc/local.xml')) { info('local.xml missing. Installing default local.xml...'); $devtools->files->putAsUser( $sitePath.'/app/etc/local.xml', diff --git a/cli/drivers/PimcoreValetDriver.php b/cli/drivers/PimcoreValetDriver.php index 68dbf62c..0498633f 100644 --- a/cli/drivers/PimcoreValetDriver.php +++ b/cli/drivers/PimcoreValetDriver.php @@ -31,7 +31,7 @@ public function serves($sitePath, $siteName, $uri) public function isStaticFile($sitePath, $siteName, $uri) { // remove cache busting part from url - if(strpos($uri, '/cache-buster') === 0) { + if (strpos($uri, '/cache-buster') === 0) { // https://stackoverflow.com/questions/25543974/how-to-get-string-after-second-slash-in-url-using-php $last = explode("/", $uri, 3); $uri = '/'.$last[2]; @@ -55,8 +55,8 @@ public function frontControllerPath($sitePath, $siteName, $uri) { $this->loadServerEnvironmentVariables($sitePath, $siteName); - if(strpos($uri, '/install') === 0) { - return $sitePath.'/install.php'; + if (strpos($uri, '/install') === 0) { + return $sitePath.'/install.php'; } return $sitePath.'/app.php'; diff --git a/cli/drivers/Shopware5ValetDriver.php b/cli/drivers/Shopware5ValetDriver.php index 7159825d..3709449d 100644 --- a/cli/drivers/Shopware5ValetDriver.php +++ b/cli/drivers/Shopware5ValetDriver.php @@ -58,7 +58,7 @@ public function frontControllerPath($sitePath, $siteName, $uri) } if ($this->isUpdaterPath($sitePath, $uri)) { - $updaterPath = $this->buildUpdaterPath($sitePath, $uri); + $updaterPath = $this->buildUpdaterPath($sitePath, $uri); $_SERVER['SCRIPT_FILENAME'] = $updaterPath; $_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $updaterPath); $_SERVER['DOCUMENT_ROOT'] = $sitePath; diff --git a/cli/drivers/Typo3ValetDriver.php b/cli/drivers/Typo3ValetDriver.php index 06c5d296..07a948a7 100644 --- a/cli/drivers/Typo3ValetDriver.php +++ b/cli/drivers/Typo3ValetDriver.php @@ -12,7 +12,7 @@ class Typo3ValetDriver extends ValetDriver | Document Root Subdirectory |-------------------------------------------------------------------------- | - | This subdirectory contains the public server resources, such as the + | This subdirectory contains the public server resources, such as the | index.php, the typo3 and fileadmin system directories. Change it | to '', if you don't use a subdirectory but valet link directly. | @@ -66,17 +66,15 @@ public function isStaticFile($sitePath, $siteName, $uri) { // May the file contains a cache busting version string like filename.12345678.css // If that is the case, the file cannot be found on disk, so remove the version - // identifier before retrying below. - if (!$this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri)) - { + // identifier before retrying below. + if (!$this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri)) { $uri = preg_replace("@^(.+)\.(\d+)\.(js|css|png|jpg|gif|gzip)$@", "$1.$3", $uri); } // Now that any possible version string is cleared from the filename, the resulting // URI should be a valid file on disc. So assemble the absolut file name with the // same schema as above and if it exists, authorize access and return its path. - if ($this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri)) - { + if ($this->isActualFile($filePath = $sitePath . $this->documentRoot . $uri)) { return $this->isAccessAuthorized($uri) ? $filePath : false; } @@ -92,10 +90,8 @@ public function isStaticFile($sitePath, $siteName, $uri) */ private function isAccessAuthorized($uri) { - foreach ($this->forbiddenUriPatterns as $forbiddenUriPattern) - { - if (preg_match("@$forbiddenUriPattern@", $uri)) - { + foreach ($this->forbiddenUriPatterns as $forbiddenUriPattern) { + if (preg_match("@$forbiddenUriPattern@", $uri)) { return false; } } @@ -123,24 +119,18 @@ public function frontControllerPath($sitePath, $siteName, $uri) $uri = rtrim($uri, '/'); // try to find the responsible script file for the requested folder / script URI - if (file_exists($absoluteFilePath = $sitePath . $this->documentRoot . $uri)) - { - if (is_dir($absoluteFilePath)) - { - if (file_exists($absoluteFilePath . '/index.php')) - { + if (file_exists($absoluteFilePath = $sitePath . $this->documentRoot . $uri)) { + if (is_dir($absoluteFilePath)) { + if (file_exists($absoluteFilePath . '/index.php')) { // this folder can be served by index.php return $this->serveScript($sitePath, $siteName, $uri . '/index.php'); } - if (file_exists($absoluteFilePath . '/index.html')) - { + if (file_exists($absoluteFilePath . '/index.html')) { // this folder can be served by index.html return $absoluteFilePath . '/index.html'; } - } - else if (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php') - { + } else if (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php') { // this file can be served directly return $this->serveScript($sitePath, $siteName, $uri); } @@ -159,14 +149,12 @@ public function frontControllerPath($sitePath, $siteName, $uri) */ private function handleRedirectBackendShorthandUris($uri) { - if (rtrim($uri, '/') === '/typo3/install') - { + if (rtrim($uri, '/') === '/typo3/install') { header('Location: /typo3/sysext/install/Start/Install.php'); die(); } - if ($uri === '/typo3') - { + if ($uri === '/typo3') { header('Location: /typo3/'); die(); } diff --git a/cli/drivers/ValetDriver.php b/cli/drivers/ValetDriver.php index cc585f08..6262443c 100644 --- a/cli/drivers/ValetDriver.php +++ b/cli/drivers/ValetDriver.php @@ -56,7 +56,7 @@ public static function assign($sitePath, $siteName, $uri, $noCache = false) static::driversIn(__DIR__ .'/') ); - if(!$noCache && $cachedDriver) { + if (!$noCache && $cachedDriver) { $driver = new $cachedDriver; return $driver; } @@ -108,7 +108,9 @@ public static function driversIn($path, $blacklist = []) $blacklist[] = 'ValetDriver'; $blacklist[] = 'BasicValetDriver'; - $blacklist = array_map(function($i) { return $i.'.php'; }, $blacklist); + $blacklist = array_map(function ($i) { + return $i.'.php'; + }, $blacklist); $drivers = []; diff --git a/cli/drivers/WordPressMultisiteSubdirectoryValetDriver.php b/cli/drivers/WordPressMultisiteSubdirectoryValetDriver.php index 9c05edd4..0039f35d 100644 --- a/cli/drivers/WordPressMultisiteSubdirectoryValetDriver.php +++ b/cli/drivers/WordPressMultisiteSubdirectoryValetDriver.php @@ -14,14 +14,13 @@ class WordPressMultisiteSubdirectoryValetDriver extends BasicValetDriver public function serves($sitePath, $siteName, $uri) { // Look for MULTISITE in wp-config.php. It should be there for multisite installs. - return file_exists($sitePath . '/wp-config.php') && - (strpos( file_get_contents($sitePath . '/wp-config.php'), 'MULTISITE') !== false) && + return file_exists($sitePath . '/wp-config.php') && + (strpos(file_get_contents($sitePath . '/wp-config.php'), 'MULTISITE') !== false) && ( //Double check if we are using subdomains. - strpos( file_get_contents($sitePath . '/wp-config.php'), "define('SUBDOMAIN_INSTALL',true)") || - strpos( file_get_contents($sitePath . '/wp-config.php'), "define('SUBDOMAIN_INSTALL', true)") + strpos(file_get_contents($sitePath . '/wp-config.php'), "define('SUBDOMAIN_INSTALL',true)") || + strpos(file_get_contents($sitePath . '/wp-config.php'), "define('SUBDOMAIN_INSTALL', true)") ); - } /** @@ -40,50 +39,53 @@ public function frontControllerPath($sitePath, $siteName, $uri) // If URI contains one of the main WordPress directories, and it's not a request for the Network Admin, // drop the subdirectory segment before routing the request - if ( ( stripos($uri, 'wp-admin') !== false || stripos($uri, 'wp-content') !== false || stripos($uri, 'wp-includes') !== false ) ) { - - if ( stripos($uri, 'wp-admin/network') === false ) { - $uri = substr($uri, stripos($uri, '/wp-') ); + if (( stripos($uri, 'wp-admin') !== false || stripos($uri, 'wp-content') !== false || stripos($uri, 'wp-includes') !== false )) { + if (stripos($uri, 'wp-admin/network') === false) { + $uri = substr($uri, stripos($uri, '/wp-')); } - if ( $this->wp_root !== false && file_exists($sitePath . "/{$this->wp_root}/wp-admin") ) { + if ($this->wp_root !== false && file_exists($sitePath . "/{$this->wp_root}/wp-admin")) { $uri = "/{$this->wp_root}" . $uri; } - } + } // Handle wp-cron.php properly - if ( stripos($uri, 'wp-cron.php') !== false ) { - $new_uri = substr($uri, stripos($uri, '/wp-') ); + if (stripos($uri, 'wp-cron.php') !== false) { + $new_uri = substr($uri, stripos($uri, '/wp-')); - if ( file_exists( $sitePath . $new_uri ) ) { + if (file_exists($sitePath . $new_uri)) { return $sitePath . $new_uri; } } return parent::frontControllerPath( - $sitePath, $siteName, $this->forceTrailingSlash($uri) + $sitePath, + $siteName, + $this->forceTrailingSlash($uri) ); } public function isStaticFile($sitePath, $siteName, $uri) { - // If the URI contains one of the main WordPress directories and it doesn't end with a slash, - // drop the subdirectory from the URI and check if the file exists. If it does, return the new uri. - if ( stripos($uri, 'wp-admin') !== false || stripos($uri, 'wp-content') !== false || stripos($uri, 'wp-includes') !== false ) { - if ( substr($uri, -1, 1) == "/" ) return false; + // If the URI contains one of the main WordPress directories and it doesn't end with a slash, + // drop the subdirectory from the URI and check if the file exists. If it does, return the new uri. + if (stripos($uri, 'wp-admin') !== false || stripos($uri, 'wp-content') !== false || stripos($uri, 'wp-includes') !== false) { + if (substr($uri, -1, 1) == "/") { + return false; + } - $new_uri = substr($uri, stripos($uri, '/wp-') ); + $new_uri = substr($uri, stripos($uri, '/wp-')); - if ( $this->wp_root !== false && file_exists($sitePath . "/{$this->wp_root}/wp-admin") ) { + if ($this->wp_root !== false && file_exists($sitePath . "/{$this->wp_root}/wp-admin")) { $new_uri = "/{$this->wp_root}" . $new_uri; } - if ( file_exists( $sitePath . $new_uri ) ) { - return $sitePath . $new_uri; - } - } + if (file_exists($sitePath . $new_uri)) { + return $sitePath . $new_uri; + } + } - return parent::isStaticFile( $sitePath, $siteName, $uri ); + return parent::isStaticFile($sitePath, $siteName, $uri); } /** @@ -95,7 +97,8 @@ public function isStaticFile($sitePath, $siteName, $uri) private function forceTrailingSlash($uri) { if (substr($uri, -1 * strlen('/wp-admin')) == '/wp-admin') { - header('Location: '.$uri.'/'); die; + header('Location: '.$uri.'/'); + die; } return $uri; } diff --git a/cli/drivers/WordPressValetDriver.php b/cli/drivers/WordPressValetDriver.php index ae7c5572..6b7b6fed 100644 --- a/cli/drivers/WordPressValetDriver.php +++ b/cli/drivers/WordPressValetDriver.php @@ -30,7 +30,9 @@ public function frontControllerPath($sitePath, $siteName, $uri) $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; return parent::frontControllerPath( - $sitePath, $siteName, $this->forceTrailingSlash($uri) + $sitePath, + $siteName, + $this->forceTrailingSlash($uri) ); } @@ -43,7 +45,8 @@ public function frontControllerPath($sitePath, $siteName, $uri) private function forceTrailingSlash($uri) { if (substr($uri, -1 * strlen('/wp-admin')) == '/wp-admin') { - header('Location: '.$uri.'/'); die; + header('Location: '.$uri.'/'); + die; } return $uri; diff --git a/cli/drivers/require.php b/cli/drivers/require.php index d88f2b13..e6f00f74 100644 --- a/cli/drivers/require.php +++ b/cli/drivers/require.php @@ -13,4 +13,4 @@ if (strpos($driver, 'ValetDriver') !== false) { require_once(__DIR__.'/'.$driver); } -} \ No newline at end of file +} diff --git a/cli/includes/facades.php b/cli/includes/facades.php index 19be2e87..0762838f 100644 --- a/cli/includes/facades.php +++ b/cli/includes/facades.php @@ -29,25 +29,69 @@ public static function __callStatic($method, $parameters) } } -class Brew extends Facade {} -class Pecl extends Facade {} -class PeclCustom extends Facade {} -class Binaries extends Facade{} -class Nginx extends Facade {} -class Memcache extends Facade {} -class Mysql extends Facade {} -class RedisTool extends Facade {} -class Elasticsearch extends Facade {} -class RabbitMq extends Facade {} -class Varnish extends Facade {} -class Mailhog extends Facade {} -class CommandLine extends Facade {} -class Configuration extends Facade {} -class DnsMasq extends Facade {} -class Filesystem extends Facade {} -class Ngrok extends Facade {} -class PhpFpm extends Facade {} -class DevTools extends Facade {} -class Site extends Facade {} -class Logs extends Facade {} -class Valet extends Facade {} +class Brew extends Facade +{ +} +class Pecl extends Facade +{ +} +class PeclCustom extends Facade +{ +} +class Binaries extends Facade +{ +} +class Nginx extends Facade +{ +} +class Memcache extends Facade +{ +} +class Mysql extends Facade +{ +} +class RedisTool extends Facade +{ +} +class Elasticsearch extends Facade +{ +} +class RabbitMq extends Facade +{ +} +class Varnish extends Facade +{ +} +class Mailhog extends Facade +{ +} +class CommandLine extends Facade +{ +} +class Configuration extends Facade +{ +} +class DnsMasq extends Facade +{ +} +class Filesystem extends Facade +{ +} +class Ngrok extends Facade +{ +} +class PhpFpm extends Facade +{ +} +class DevTools extends Facade +{ +} +class Site extends Facade +{ +} +class Logs extends Facade +{ +} +class Valet extends Facade +{ +} diff --git a/cli/includes/helpers.php b/cli/includes/helpers.php index 652ade56..73b4e6f7 100644 --- a/cli/includes/helpers.php +++ b/cli/includes/helpers.php @@ -157,7 +157,8 @@ function tap($value, callable $callback) * @param string|array $needles * @return bool */ - function ends_with($haystack, $needles) { + function ends_with($haystack, $needles) + { foreach ((array) $needles as $needle) { if (substr($haystack, -strlen($needle)) === (string) $needle) { return true; @@ -172,14 +173,13 @@ function ends_with($haystack, $needles) { */ function user() { - if(isset($_SERVER['SUDO_USER']) && $_SERVER['SUDO_USER'] !== null) { - return $_SERVER['SUDO_USER']; + if (isset($_SERVER['SUDO_USER']) && $_SERVER['SUDO_USER'] !== null) { + return $_SERVER['SUDO_USER']; } - if(isset($_SERVER['USER']) && $_SERVER['USER'] !== null) { - return $_SERVER['USER']; + if (isset($_SERVER['USER']) && $_SERVER['USER'] !== null) { + return $_SERVER['USER']; } - return ''; + return ''; } - diff --git a/cli/stubs/magento2/env.php b/cli/stubs/magento2/env.php index bbe3b3ce..4948fcd9 100644 --- a/cli/stubs/magento2/env.php +++ b/cli/stubs/magento2/env.php @@ -1,26 +1,26 @@ + 'backend' => array ( 'frontName' => 'admin', ), - 'db' => + 'db' => array ( - 'connection' => + 'connection' => array ( - 'indexer' => + 'indexer' => array ( 'host' => '127.0.0.1', 'dbname' => 'DBNAME', 'username' => 'root', 'password' => 'root', 'active' => '1', - 'persistent' => NULL, + 'persistent' => null, 'model' => 'mysql4', 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', ), - 'default' => + 'default' => array ( 'host' => '127.0.0.1', 'dbname' => 'DBNAME', @@ -34,14 +34,14 @@ ), 'table_prefix' => '', ), - 'crypt' => + 'crypt' => array ( 'key' => 'JkeEumwvvQBCDxypLPBozvrpF2rFNhNL', ), - 'session' => + 'session' => array ( 'save' => 'redis', - 'redis' => + 'redis' => array ( 'host' => '/tmp/redis.sock', 'port' => '6379', @@ -63,24 +63,24 @@ 'max_lifetime' => '2592000', ), ), - 'cache' => + 'cache' => array ( - 'frontend' => + 'frontend' => array ( - 'default' => + 'default' => array ( 'backend' => 'Cm_Cache_Backend_Redis', - 'backend_options' => + 'backend_options' => array ( 'server' => '/tmp/redis.sock', 'port' => '6379', 'database' => '2', ), ), - 'page_cache' => + 'page_cache' => array ( 'backend' => 'Cm_Cache_Backend_Redis', - 'backend_options' => + 'backend_options' => array ( 'server' => '/tmp/redis.sock', 'port' => '6379', @@ -90,16 +90,16 @@ ), ), ), - 'resource' => + 'resource' => array ( - 'default_setup' => + 'default_setup' => array ( 'connection' => 'default', ), ), 'x-frame-options' => 'SAMEORIGIN', 'MAGE_MODE' => 'developer', - 'cache_types' => + 'cache_types' => array ( 'config' => 1, 'layout' => 1, @@ -117,13 +117,13 @@ 'compiled_config' => 0, 'customer_notification' => 1, ), - 'install' => + 'install' => array ( 'date' => 'Wed, 19 Jul 2017 00:00:00 +0000', ), - 'queue' => + 'queue' => array ( - 'amqp' => + 'amqp' => array ( 'host' => '', 'port' => '', diff --git a/cli/templates/404.php b/cli/templates/404.php index b0cc57f1..4eee59c4 100644 --- a/cli/templates/404.php +++ b/cli/templates/404.php @@ -43,20 +43,20 @@ + ?>

Available sites:

- - + +

Checked paths:

- +

- diff --git a/cli/valet.php b/cli/valet.php index 5e4195c6..3335dc4b 100644 --- a/cli/valet.php +++ b/cli/valet.php @@ -22,7 +22,7 @@ Container::setInstance(new Container); // get current version based on git describe and tags -$version = new Version('1.0.29' , __DIR__ . '/../'); +$version = new Version('1.0.29', __DIR__ . '/../'); $app = new Application('Valet+', $version->getVersion()); @@ -93,7 +93,8 @@ Elasticsearch::updateDomain($domain); DnsMasq::updateDomain( - $oldDomain = Configuration::read()['domain'], $domain = trim($domain, '.') + $oldDomain = Configuration::read()['domain'], + $domain = trim($domain, '.') ); Configuration::updateKey('domain', $domain); @@ -144,14 +145,14 @@ * Register a subdomain link with Valet. */ $app->command('subdomain [action] [name] [--secure] [--proxy]', function ($action, $name, $secure, $proxy) { - if($action === 'list') { + if ($action === 'list') { $links = Site::links(basename(getcwd())); table(['Site', 'SSL', 'URL', 'Path'], $links->all()); return; } - if($action === 'add') { + if ($action === 'add') { $domain = Site::link(getcwd(), $name.'.'.basename(getcwd())); if ($secure) { @@ -166,7 +167,7 @@ return; } - if($action === 'remove') { + if ($action === 'remove') { Site::unlink($name.'.'.basename(getcwd())); info('Current working directory unlinked from '.$name.'.'.basename(getcwd())); @@ -312,45 +313,37 @@ return; } - foreach($services as $service) { - switch($service) { - case 'nginx': { + foreach ($services as $service) { + switch ($service) { + case 'nginx': Nginx::restart(); break; - } case 'mysql': - case 'mariadb': { + case 'mariadb': Mysql::restart(); break; - } - case 'php': { + case 'php': if ($phpVersion) { PhpFpm::switchTo($phpVersion); } else { PhpFpm::restart(); } break; - } - case 'redis': { + case 'redis': RedisTool::restart(); break; - } - case 'mailhog': { + case 'mailhog': Mailhog::restart(); break; - } - case 'elasticsearch': { + case 'elasticsearch': Elasticsearch::restart(); break; - } - case 'rabbitmq': { + case 'rabbitmq': RabbitMq::restart(); break; - } - case 'varnish': { + case 'varnish': Varnish::restart(); break; - } } } @@ -361,7 +354,7 @@ * Restart the daemon services. */ $app->command('restart [services]*', function ($services) { - if(empty($services)) { + if (empty($services)) { DnsMasq::restart(); PhpFpm::restart(); Nginx::restart(); @@ -375,40 +368,32 @@ return; } - foreach($services as $service) { - switch($service) { - case 'nginx': { + foreach ($services as $service) { + switch ($service) { + case 'nginx': Nginx::restart(); break; - } - case 'mysql': { + case 'mysql': Mysql::restart(); break; - } - case 'php': { + case 'php': PhpFpm::restart(); break; - } - case 'redis': { + case 'redis': RedisTool::restart(); break; - } - case 'mailhog': { + case 'mailhog': Mailhog::restart(); break; - } - case 'elasticsearch': { + case 'elasticsearch': Elasticsearch::restart(); break; - } - case 'rabbitmq': { + case 'rabbitmq': RabbitMq::restart(); break; - } - case 'varnish': { + case 'varnish': Varnish::restart(); break; - } } } @@ -419,7 +404,7 @@ * Stop the daemon services. */ $app->command('stop [services]*', function ($services) { - if(empty($services)) { + if (empty($services)) { DnsMasq::stop(); PhpFpm::stop(); Nginx::stop(); @@ -433,40 +418,32 @@ return; } - foreach($services as $service) { - switch($service) { - case 'nginx': { + foreach ($services as $service) { + switch ($service) { + case 'nginx': Nginx::stop(); break; - } - case 'mysql': { + case 'mysql': Mysql::stop(); break; - } - case 'php': { + case 'php': PhpFpm::stop(); break; - } - case 'redis': { + case 'redis': RedisTool::stop(); break; - } - case 'mailhog': { + case 'mailhog': Mailhog::stop(); break; - } - case 'elasticsearch': { + case 'elasticsearch': Elasticsearch::stop(); break; - } - case 'rabbitmq': { + case 'rabbitmq': RabbitMq::stop(); break; - } - case 'varnish': { + case 'varnish': Varnish::stop(); break; - } } } @@ -537,15 +514,15 @@ $helper = $this->getHelperSet()->get('question'); $defaults = $input->getOptions(); - if($run === 'list' || $run === 'ls') { + if ($run === 'list' || $run === 'ls') { Mysql::listDatabases(); return; } - if($run === 'create') { + if ($run === 'create') { $databaseName = Mysql::createDatabase($name); - if(!$databaseName) { + if (!$databaseName) { return warning('Error creating database'); } @@ -553,9 +530,9 @@ return; } - if($run === 'drop') { - if(!$defaults['yes']) { - $question = new ConfirmationQuestion('Are you sure you want to delete the database? [y/N] ', FALSE); + if ($run === 'drop') { + if (!$defaults['yes']) { + $question = new ConfirmationQuestion('Are you sure you want to delete the database? [y/N] ', false); if (!$helper->ask($input, $output, $question)) { warning('Aborted'); return; @@ -563,7 +540,7 @@ } $databaseName = Mysql::dropDatabase($name); - if(!$databaseName) { + if (!$databaseName) { return warning('Error dropping database'); } @@ -571,9 +548,9 @@ return; } - if($run === 'reset') { - if(!$defaults['yes']) { - $question = new ConfirmationQuestion('Are you sure you want to reset the database? [y/N] ', FALSE); + if ($run === 'reset') { + if (!$defaults['yes']) { + $question = new ConfirmationQuestion('Are you sure you want to reset the database? [y/N] ', false); if (!$helper->ask($input, $output, $question)) { warning('Aborted'); return; @@ -582,13 +559,13 @@ $dropped = Mysql::dropDatabase($name); - if(!$dropped) { + if (!$dropped) { return warning('Error creating database'); } $databaseName = Mysql::createDatabase($name); - if(!$databaseName) { + if (!$databaseName) { return warning('Error creating database'); } @@ -596,8 +573,8 @@ return; } - if($run === 'open') { - if($name === '.') { + if ($run === 'open') { + if ($name === '.') { $name = basename(getcwd()); } @@ -607,15 +584,15 @@ return; } - if($run === 'import') { + if ($run === 'import') { info('Importing database...'); - if(!$name) { + if (!$name) { throw new Exception('Please provide a dump file'); } // check if database already exists. - if(Mysql::isDatabaseExists($optional)){ - $question = new ConfirmationQuestion('Database already exists are you sure you want to continue? [y/N] ', FALSE); + if (Mysql::isDatabaseExists($optional)) { + $question = new ConfirmationQuestion('Database already exists are you sure you want to continue? [y/N] ', false); if (!$helper->ask($input, $output, $question)) { warning('Aborted'); return; @@ -626,23 +603,23 @@ return; } - if($run === 'reimport') { - if(!$defaults['yes']) { - $question = new ConfirmationQuestion('Are you sure you want to reimport the database? [y/N] ', FALSE); + if ($run === 'reimport') { + if (!$defaults['yes']) { + $question = new ConfirmationQuestion('Are you sure you want to reimport the database? [y/N] ', false); if (!$helper->ask($input, $output, $question)) { warning('Aborted'); return; } } info('Resetting database, importing database...'); - if(!$name) { + if (!$name) { throw new Exception('Please provide a dump file'); } Mysql::reimportDatabase($name, $optional); return; } - if($run === 'export' || $run === 'dump') { + if ($run === 'export' || $run === 'dump') { info('Exporting database...'); $data = Mysql::exportDatabase($name, $optional); info('Database "' . $data['database'] . '" exported into file "' . $data['filename'] . '"'); @@ -728,7 +705,7 @@ info("[PECL-CUSTOM] Enabling ioncube_loader_dar extension"); PeclCustom::enable('ioncube_loader_dar'); PhpFpm::restart(); - }elseif($mode === 'on' || $mode === 'enable'){ + } elseif ($mode === 'on' || $mode === 'enable') { info("[PECL-CUSTOM] ioncube_loader_dar extension is already installed"); } @@ -736,13 +713,13 @@ info("[PECL-CUSTOM] Disabling ioncube_loader_dar extension"); PeclCustom::disable('ioncube_loader_dar'); PhpFpm::restart(); - }elseif($mode === 'off' || $mode === 'disable'){ + } elseif ($mode === 'off' || $mode === 'disable') { info("[PECL-CUSTOM] ioncube_loader_dar extension is already uninstalled"); } })->descriptions('Enable / disable ioncube'); $app->command('elasticsearch [mode]', function ($mode) { - if($mode === 'install' || $mode === 'on') { + if ($mode === 'install' || $mode === 'on') { Elasticsearch::install(); return; } @@ -859,7 +836,7 @@ break; } if ($restart) { - PhpFpm::restart(); + PhpFpm::restart(); } })->descriptions('Install / uninstall Memcache'); diff --git a/composer.json b/composer.json index 6e893582..44cf94af 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "symfony/process": "~2.7|~3.0", "nategood/httpful": "~0.2", "tightenco/collect": "~5.4.0", - "sebastian/version": "^2.0" + "sebastian/version": "^2.0", + "squizlabs/php_codesniffer": "*" }, "require-dev": { "mockery/mockery": "0.9.*", diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..57829232 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,31 @@ + + + + Valet-plus coding standard + ​ + + + + + + ./cli + ​ + + + + + + + + + + + + + + ​ + \ No newline at end of file