Skip to content

Commit

Permalink
Resolve compatibility issues with latest Valet (#44)
Browse files Browse the repository at this point in the history
* fix sanitization of site_name

* add ValetConfig

* add Config facade

* bind config to ValetConfig implementations

* replace Valet::domain with Config

* remove unused domain methods
  • Loading branch information
aaemnnosttv authored Sep 2, 2018
1 parent ab3dedb commit 783a3a7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 30 deletions.
14 changes: 14 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace WP_CLI_Valet;

/**
* @method static get(string $key)
*/
class Config extends Facade
{
public static function getContainerKey()
{
return 'config';
}
}
11 changes: 0 additions & 11 deletions src/Process/FakeValet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@

class FakeValet implements ValetInterface
{

/**
* Get the local domain served by Valet.
*
* @return string
*/
public function domain()
{
return 'dev';
}

/**
* Secure the installation with a self-signed TLS certificate.
*
Expand Down
10 changes: 0 additions & 10 deletions src/Process/SystemValet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ class SystemValet extends ShellCommand implements ValetInterface
{
protected $command = 'valet';

/**
* Get the local domain served by Valet.
*
* @return string
*/
public function domain()
{
return trim($this->run('domain')->stdout);
}

/**
* Secure the installation with a self-signed TLS certificate.
*
Expand Down
7 changes: 0 additions & 7 deletions src/Process/ValetInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Props.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/ValetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions src/ValetConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace WP_CLI_Valet;

class ValetConfig
{
protected $data;

/**
* ValetConfig constructor.
*
* @param $data
*/
public function __construct($data)
{
$this->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;
}
}

0 comments on commit 783a3a7

Please sign in to comment.