diff --git a/.github/workflows/test-commands.yml b/.github/workflows/test-commands.yml index 9aa2838c..8c467c41 100644 --- a/.github/workflows/test-commands.yml +++ b/.github/workflows/test-commands.yml @@ -13,7 +13,7 @@ jobs: matrix: os: [macos-12] # php: ['8.3', '8.2', '8.1', '8.0', '7.4', '7.3', '7.2', '7.1'] - php: ['8.1'] + php: ['8.2'] runs-on: ${{matrix.os}} name: ${{matrix.os}} with ${{matrix.php}} @@ -21,10 +21,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: '[INSTALL] Install PHP 8.0' + - name: '[INSTALL] Install PHP 8.1' uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.1' extensions: dom, curl, libxml, mbstring, zip, fileinfo ini-values: error_reporting=E_ALL, max_execution_time=-1, memory_limit=512M tools: composer:v2 @@ -32,7 +32,7 @@ jobs: - name: '[INSTALL] Brew' run: brew cleanup - name: '[INSTALL] Composer install' - run: composer install --no-interaction --prefer-dist + run: composer install --no-dev --no-interaction --prefer-dist - name: '[INSTALL] Valet install' run: ./valet-plus install diff --git a/.github/workflows/test-static.yml b/.github/workflows/test-static.yml index bdfc8426..2f3b6994 100644 --- a/.github/workflows/test-static.yml +++ b/.github/workflows/test-static.yml @@ -13,10 +13,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: '[INSTALL] Install PHP 8.0' + - name: '[INSTALL] Install PHP 8.1' uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.1' extensions: dom, curl, libxml, mbstring, zip, fileinfo ini-values: error_reporting=E_ALL, max_execution_time=-1, memory_limit=512M tools: composer:v2 diff --git a/README.MD b/README.MD index 237b911e..7cd3e9c5 100644 --- a/README.MD +++ b/README.MD @@ -18,11 +18,12 @@ To get started, you first need to ensure that Homebrew is up to date using the u brew update ``` -Next, you should use Homebrew to install PHP 8.0: +Next, you should use Homebrew to install PHP 8.1 (using `shivammathur/php`): ```shell -brew install php@8.0 -brew link php@8.0 --force -brew services restart php@8.0 +brew tap shivammathur/php +brew install shivammathur/php/php@8.1 +brew link php@8.1 --force +brew services restart php@8.1 ``` Install Valet+ 3.x-dev with composer: diff --git a/cli/ValetPlus/AbstractDockerService.php b/cli/ValetPlus/AbstractDockerService.php index ad17b269..4277a04e 100644 --- a/cli/ValetPlus/AbstractDockerService.php +++ b/cli/ValetPlus/AbstractDockerService.php @@ -112,7 +112,7 @@ public function upContainer($name): self return $this; } - info("Docker up version {$name}..."); + info("Docker up version {$name} (this might take a while)..."); $installPath = $this->getComposeInstallPath($name); $installDir = $this->getComposeInstallDir($name); diff --git a/cli/ValetPlus/Elasticsearch.php b/cli/ValetPlus/Elasticsearch.php index 57257b57..b2348b49 100644 --- a/cli/ValetPlus/Elasticsearch.php +++ b/cli/ValetPlus/Elasticsearch.php @@ -8,13 +8,12 @@ use Valet\Brew; use Valet\CommandLine; use Valet\Filesystem; +use WeProvide\ValetPlus\Extended\Site; use function Valet\info; class Elasticsearch extends AbstractDockerService { - /** @var string */ - protected const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/elasticsearch/elasticsearch.conf'; /** @var string */ protected const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/elasticsearch.conf'; @@ -29,20 +28,25 @@ class Elasticsearch extends AbstractDockerService /** @var Brew */ protected $brew; + /** @var Site */ + protected $site; /** * @param CommandLine $cli * @param Filesystem $files * @param Brew $brew + * @param Site $site */ public function __construct( CommandLine $cli, Filesystem $files, - Brew $brew + Brew $brew, + Site $site ) { parent::__construct($cli, $files); $this->brew = $brew; + $this->site = $site; } /** @@ -242,7 +246,7 @@ public function install($version = self::ES_DEFAULT_VERSION, $tld = 'test') } $this->restart($version); - $this->updateDomain($tld); + $this->site->proxyCreate('elasticsearch', 'http://127.0.0.1:9200'); } /** @@ -250,6 +254,8 @@ public function install($version = self::ES_DEFAULT_VERSION, $tld = 'test') */ public function uninstall() { + $this->site->proxyDelete('elasticsearch'); + // Remove nginx domain listen file. $this->files->unlink(static::NGINX_CONFIGURATION_PATH); @@ -293,25 +299,4 @@ public function uninstall() $this->files->rmDirAndContents(BREW_PREFIX . '/etc/opensearch'); } } - - /** - * Set the domain (TLD) to use. - * - * @param $domain - */ - public function updateDomain($domain) - { - $currentVersion = $this->getCurrentVersion(); - if ($currentVersion) { - info('Updating elasticsearch domain...'); - $this->files->putAsUser( - static::NGINX_CONFIGURATION_PATH, - str_replace( - ['VALET_DOMAIN'], - [$domain], - $this->files->get(static::NGINX_CONFIGURATION_STUB) - ) - ); - } - } } diff --git a/cli/ValetPlus/Mailhog.php b/cli/ValetPlus/Mailhog.php index 53934212..aa5646eb 100644 --- a/cli/ValetPlus/Mailhog.php +++ b/cli/ValetPlus/Mailhog.php @@ -5,12 +5,15 @@ namespace WeProvide\ValetPlus; use Illuminate\Container\Container; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\EventDispatcher\EventDispatcher; use Valet\Brew; use Valet\CommandLine; use Valet\Configuration; use Valet\Filesystem; use WeProvide\ValetPlus\Event\DataEvent; +use WeProvide\ValetPlus\Extended\Site; use function Valet\info; @@ -22,29 +25,34 @@ class Mailhog extends AbstractService /** @var string */ protected const PHP_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.ini'; /** @var string */ - protected const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.conf'; - /** @var string */ protected const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/mailhog.conf'; /** @var EventDispatcher */ protected $eventDispatcher; + /** @var Site */ + protected $site; /** * @param Configuration $configuration * @param Brew $brew * @param Filesystem $files * @param CommandLine $cli + * @param Site $site + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function __construct( Configuration $configuration, Brew $brew, Filesystem $files, - CommandLine $cli + CommandLine $cli, + Site $site ) { parent::__construct($configuration, $brew, $files, $cli); $container = Container::getInstance(); $this->eventDispatcher = $container->get('event_dispatcher'); + $this->site = $site; } /** @@ -64,7 +72,7 @@ public function register() public function install(string $tld = 'test'): void { $this->brew->ensureInstalled(static::SERVICE_NAME); - $this->updateDomain($tld); + $this->site->proxyCreate('mailhog', 'http://127.0.0.1:8025'); $this->setEnabled(static::STATE_ENABLED); $this->restart(); } @@ -111,32 +119,13 @@ public function uninstall(): void { $this->stop(); $this->removeEnabled(); + $this->site->proxyDelete('mailhog'); $this->brew->uninstallFormula(static::SERVICE_NAME); $this->files->unlink(BREW_PREFIX . '/var/log/mailhog.log'); // Remove nginx domain listen file. $this->files->unlink(static::NGINX_CONFIGURATION_PATH); } - /** - * Set the domain (TLD) to use. - * - * @param $domain - */ - public function updateDomain($domain) - { - if ($this->installed()) { - info('Updating mailhog domain...'); - $this->files->putAsUser( - static::NGINX_CONFIGURATION_PATH, - str_replace( - ['VALET_DOMAIN'], - [$domain], - $this->files->get(static::NGINX_CONFIGURATION_STUB) - ) - ); - } - } - /** * Create php ini files. * diff --git a/cli/stubs/elasticsearch/elasticsearch.conf b/cli/stubs/elasticsearch/elasticsearch.conf deleted file mode 100644 index dcb76dd1..00000000 --- a/cli/stubs/elasticsearch/elasticsearch.conf +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen 127.0.0.1:80; - server_name elasticsearch.VALET_DOMAIN www.elasticsearch.VALET_DOMAIN; - charset utf-8; - client_max_body_size 128M; - - location / { - chunked_transfer_encoding on; - proxy_set_header X-NginX-Proxy true; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_http_version 1.1; - proxy_redirect off; - proxy_buffering off; - proxy_pass http://localhost:9200; - } -} diff --git a/cli/stubs/mailhog.conf b/cli/stubs/mailhog.conf deleted file mode 100644 index 394a21de..00000000 --- a/cli/stubs/mailhog.conf +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen 127.0.0.1:80; - server_name mailhog.VALET_DOMAIN www.mailhog.VALET_DOMAIN; - charset utf-8; - client_max_body_size 128M; - - location / { - chunked_transfer_encoding on; - proxy_set_header X-NginX-Proxy true; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_http_version 1.1; - proxy_redirect off; - proxy_buffering off; - proxy_pass http://localhost:8025; - } -} diff --git a/cli/valet.php b/cli/valet.php index cada3456..01845f9f 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; + use function Valet\info; use function Valet\table; use function Valet\warning; @@ -265,7 +266,7 @@ */ $app ->command('mailhog', function (OutputInterface $output, string $mode = null) { - $modes = ['install', 'on', 'enable', 'off', 'disable']; + $modes = ['install', 'on', 'enable', 'off', 'disable', 'uninstall']; if (!in_array($mode, $modes)) { throw new Exception('Mode not found. Available modes: ' . implode(', ', $modes)); @@ -285,11 +286,18 @@ case 'off': Mailhog::disable(); + return; + case 'uninstall': + Mailhog::uninstall(); + return; } + + PhpFpm::restart(); + Nginx::restart(); }) ->descriptions('Enable/disable Mailhog') - ->addArgument('mode', InputArgument::REQUIRED, 'Available modes: ' . implode(', ', ['install', 'on', 'enable', 'off', 'disable'])); + ->addArgument('mode', InputArgument::REQUIRED, 'Available modes: ' . implode(', ', ['install', 'on', 'enable', 'off', 'disable', 'uninstall'])); /** * Varnish services. diff --git a/composer.json b/composer.json index 2b6f0331..b9f9e98d 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,10 @@ } }, "config": { - "platform-check": false + "platform-check": false, + "allow-plugins": { + "phpro/grumphp-shim": true + } }, "bin": [ "valet-plus" @@ -27,6 +30,7 @@ "laravel/valet": "^4.5" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.8" + "squizlabs/php_codesniffer": "^3.8", + "phpro/grumphp-shim": "^2.4" } } diff --git a/grumphp.yml b/grumphp.yml new file mode 100644 index 00000000..3bd420f7 --- /dev/null +++ b/grumphp.yml @@ -0,0 +1,12 @@ +grumphp: + ascii: + failed: ~ + succeeded: ~ + tasks: + phpcs: + standard: phpcs.xml + triggered_by: + - php + whitelist_patterns: + - /^cli\/ValetPlus\/(.*)/ + - /^cli\/stubs\/drivers\/(.*)/