From 783a3a7707d8e2cc519b0fba63fd5ae784a6a1ed Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Sun, 2 Sep 2018 23:40:57 +0300 Subject: [PATCH] Resolve compatibility issues with latest Valet (#44) * fix sanitization of site_name * add ValetConfig * add Config facade * bind config to ValetConfig implementations * replace Valet::domain with Config * remove unused domain methods --- src/Config.php | 14 ++++++++++++ src/Process/FakeValet.php | 11 ---------- src/Process/SystemValet.php | 10 --------- src/Process/ValetInterface.php | 7 ------ src/Props.php | 4 ++-- src/ValetCommand.php | 5 +++++ src/ValetConfig.php | 39 ++++++++++++++++++++++++++++++++++ 7 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 src/Config.php create mode 100644 src/ValetConfig.php diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..6f868e6 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,14 @@ +run('domain')->stdout); - } - /** * Secure the installation with a self-signed TLS certificate. * diff --git a/src/Process/ValetInterface.php b/src/Process/ValetInterface.php index 392beb6..f76cbbf 100644 --- a/src/Process/ValetInterface.php +++ b/src/Process/ValetInterface.php @@ -4,13 +4,6 @@ interface ValetInterface { - /** - * Get the local domain served by Valet. - * - * @return string - */ - public function domain(); - /** * Secure the installation with a self-signed TLS certificate. * diff --git a/src/Props.php b/src/Props.php index 7898f82..d1c8cb9 100644 --- a/src/Props.php +++ b/src/Props.php @@ -33,8 +33,8 @@ public function __construct(array $positional, array $options) */ public function populate() { - $this->site_name = preg_replace('/^a-zA-Z/', '-', $this->positional[0]); - $this->domain = sprintf('%s.%s', $this->site_name, Valet::domain()); + $this->site_name = preg_replace('/[^a-zA-Z0-9\.]/', '-', $this->positional[0]); + $this->domain = sprintf('%s.%s', $this->site_name, Config::get('tld') ?: Config::get('domain')); } /** diff --git a/src/ValetCommand.php b/src/ValetCommand.php index 2210527..8b8d69a 100644 --- a/src/ValetCommand.php +++ b/src/ValetCommand.php @@ -48,6 +48,11 @@ public static function boot() $container->singleton('valet', getenv('BEHAT_RUN') ? FakeValet::class : SystemValet::class); $container->singleton('wp', SystemWp::class); $container->singleton('composer', SystemComposer::class); + $container->singleton('config', function () { + return getenv('BEHAT_RUN') + ? new ValetConfig(['tld' => 'dev']) + : ValetConfig::loadSystem(); + }); $container->bind('wp-installer', WordPressInstaller::class); $container->bind('bedrock-installer', BedrockInstaller::class); diff --git a/src/ValetConfig.php b/src/ValetConfig.php new file mode 100644 index 0000000..c942bab --- /dev/null +++ b/src/ValetConfig.php @@ -0,0 +1,39 @@ +data = $data; + } + + /** + * @throws \Exception + */ + public static function loadSystem() + { + $config_path = file_exists("{$_SERVER['HOME']}/.config/valet/config.json") + ? "{$_SERVER['HOME']}/.config/valet/config.json" + : "{$_SERVER['HOME']}/.valet/config.json"; + + if (! file_exists($config_path)) { + throw new \Exception('Valet configuration file not found.'); + } + + return new static(json_decode(file_get_contents($config_path), true)); + } + + public function get($key) + { + return isset($this->data[$key]) ? $this->data[$key] : null; + } +}