From cea383c3e2601870f55fb36748283279b9e55c85 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 7 Mar 2024 19:40:05 +0800 Subject: [PATCH 1/9] Support Laravel 11 (#4) * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- .github/workflows/analyse.yml | 4 +- .github/workflows/audit.yaml | 4 +- .github/workflows/tests.yaml | 67 ++++++++++++++++++++------ composer.json | 15 +++--- src/Console/Util/CreateUserOptions.php | 2 +- src/Fields/VaporFileMixins.php | 2 +- tests/TestCase.php | 3 +- 7 files changed, 67 insertions(+), 30 deletions(-) diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml index 698e8a5..068e9f1 100644 --- a/.github/workflows/analyse.yml +++ b/.github/workflows/analyse.yml @@ -18,7 +18,7 @@ jobs: experimental: - false - name: PHP${{ matrix.php }} on ${{ matrix.os }} + name: PHP:${{ matrix.php }} on ${{ matrix.os }} steps: - name: Checkout code @@ -40,7 +40,7 @@ jobs: composer require "laravel/pint:^1.1" --no-interaction --no-update - name: Install dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: dependency-versions: "highest" composer-options: "--prefer-dist --no-cache" diff --git a/.github/workflows/audit.yaml b/.github/workflows/audit.yaml index f70e9e1..449a09a 100644 --- a/.github/workflows/audit.yaml +++ b/.github/workflows/audit.yaml @@ -21,7 +21,7 @@ jobs: experimental: - true - name: PHP${{ matrix.php }} on ${{ matrix.os }} + name: PHP:${{ matrix.php }} on ${{ matrix.os }} steps: - name: Checkout code @@ -39,7 +39,7 @@ jobs: composer config http-basic.nova.laravel.com ${{ secrets.NOVA_USERNAME }} ${{ secrets.NOVA_PASSWORD }} - name: Install dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: dependency-versions: "highest" composer-options: "--prefer-dist --prefer-stable --no-cache" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4b41959..5eca413 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -6,6 +6,53 @@ on: workflow_dispatch: jobs: + tests-on-laravel-11: + runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.experimental }} + strategy: + matrix: + os: + - "ubuntu-latest" + - "windows-latest" + php: + - 8.2 + - 8.3 + dependencies: + - "highest" + laravel: + - "11.x" + experimental: + - false + + name: Laravel:${{ matrix.laravel }} on PHP:${{ matrix.php }}-${{ matrix.os }} (${{ matrix.dependencies }}) + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlite3, pdo_sqlite, bcmath, fileinfo + coverage: none + + - name: "Setup CI Authentication" + run: | + composer config http-basic.nova.laravel.com ${{ secrets.NOVA_USERNAME }} ${{ secrets.NOVA_PASSWORD }} + + - name: Install dependencies + uses: "ramsey/composer-install@v3" + with: + dependency-versions: "${{ matrix.dependencies }}" + composer-options: "--prefer-dist --no-cache --with=laravel/framework:${{ matrix.laravel }}" + + - name: Installed dependencies + run: composer show -D + + - name: Execute tests + run: vendor/bin/phpunit --testdox + tests-on-laravel-10: runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} @@ -20,13 +67,12 @@ jobs: - 8.3 dependencies: - "highest" - - "lowest" laravel: - "10.x" experimental: - false - name: Laravel ${{ matrix.laravel }} on PHP${{ matrix.php }}-${{ matrix.os }} (${{ matrix.dependencies }}) + name: Laravel:${{ matrix.laravel }} on PHP:${{ matrix.php }}-${{ matrix.os }} (${{ matrix.dependencies }}) steps: - name: Checkout code @@ -43,15 +89,11 @@ jobs: run: | composer config http-basic.nova.laravel.com ${{ secrets.NOVA_USERNAME }} ${{ secrets.NOVA_PASSWORD }} - - name: Install Laravel Framework ${{ matrix.laravel }} - run: | - composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update - - name: Install dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: dependency-versions: "${{ matrix.dependencies }}" - composer-options: "--prefer-dist --no-cache" + composer-options: "--prefer-dist --no-cache --with=laravel/framework:${{ matrix.laravel }}" - name: Installed dependencies run: composer show -D @@ -73,7 +115,6 @@ jobs: - 8.2 dependencies: - "highest" - - "lowest" laravel: - "9.x" experimental: @@ -96,15 +137,11 @@ jobs: run: | composer config http-basic.nova.laravel.com ${{ secrets.NOVA_USERNAME }} ${{ secrets.NOVA_PASSWORD }} - - name: Install Laravel Framework ${{ matrix.laravel }} - run: | - composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update - - name: Install dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: dependency-versions: "${{ matrix.dependencies }}" - composer-options: "--prefer-dist --no-cache" + composer-options: "--prefer-dist --no-cache --with=laravel/framework:${{ matrix.laravel }}" - name: Installed dependencies run: composer show -D diff --git a/composer.json b/composer.json index 8727715..d3444a8 100644 --- a/composer.json +++ b/composer.json @@ -25,18 +25,17 @@ "require": { "php": "^7.3 || ^8.0", "composer-runtime-api": "^2.2", - "illuminate/support": "^8.83.4 || ^9.51 || ^10.0", - "laravel/vapor-core": "^2.22", - "nova-kit/nova-queued-export-as-csv": "^1.2" + "illuminate/support": "^8.83.4 || ^9.51 || ^10.0 || ^11.0", + "laravel/vapor-core": "^2.37", + "nova-kit/nova-queued-export-as-csv": "^1.4" }, "require-dev": { - "larastan/larastan": "^1.0.1 || ^2.4", - "laravel/nova": "^4.14", + "larastan/larastan": "^2.4", + "laravel/nova": "*", "league/flysystem-aws-s3-v3": "^1.0 || ^3.0", "nova-kit/nova-devtool": "^1.3", - "orchestra/testbench": "^6.31 || ^7.28 || ^8.8", - "phpunit/phpunit": "^9.6", - "nova-kit/nova-devtool": "^1.2.1" + "orchestra/testbench": "^7.40 || ^8.21 || ^9.0", + "phpunit/phpunit": "^9.6 || ^10.1" }, "repositories": [ { diff --git a/src/Console/Util/CreateUserOptions.php b/src/Console/Util/CreateUserOptions.php index 6952226..f253224 100644 --- a/src/Console/Util/CreateUserOptions.php +++ b/src/Console/Util/CreateUserOptions.php @@ -42,7 +42,7 @@ public function confirm(string $question, $default = false) /** * Prompt the user for input. */ - public function ask(string $question, string $default = null): array + public function ask(string $question, ?string $default = null): array { return [$this->parseQuestion($question), null, InputOption::VALUE_REQUIRED, '', $default]; } diff --git a/src/Fields/VaporFileMixins.php b/src/Fields/VaporFileMixins.php index d729aed..28b78fd 100644 --- a/src/Fields/VaporFileMixins.php +++ b/src/Fields/VaporFileMixins.php @@ -17,7 +17,7 @@ class VaporFileMixins */ public function downloadViaTemporaryUrl() { - return function (DateTimeInterface $expiration = null) { + return function (?DateTimeInterface $expiration = null) { return $this->download(function ($request, $model, $disk, $value) use ($expiration) { return redirect( Storage::disk($disk)->temporaryUrl($value, $expiration ?? now()->addMinutes(5)) diff --git a/tests/TestCase.php b/tests/TestCase.php index 1af7035..679ea89 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,5 +7,6 @@ class TestCase extends \Orchestra\Testbench\TestCase { - use RefreshDatabase, WithWorkbench; + use RefreshDatabase; + use WithWorkbench; } From 627302917986ab2a1c3e2c5e1987df0fa035ce3b Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 09:51:40 +0800 Subject: [PATCH 2/9] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/UserCommand.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Console/UserCommand.php b/src/Console/UserCommand.php index e124f54..71bfac7 100644 --- a/src/Console/UserCommand.php +++ b/src/Console/UserCommand.php @@ -6,7 +6,11 @@ use Illuminate\Support\Facades\Hash; use Laravel\Nova\Nova; use Laravel\Nova\Util; +use Laravel\Prompts\Prompt; use NovaKit\NovaOnVapor\Console\Util\CreateUserOptions; +use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; class UserCommand extends Command { @@ -38,11 +42,7 @@ class UserCommand extends Command */ protected $originalCreateUserCommandCallback; - /** - * Configure the command options. - * - * @return void - */ + /** {@inheritDoc} */ #[\Override] protected function configure() { @@ -50,7 +50,21 @@ protected function configure() $this->setName($this->name) ->setDescription($this->description); + } + + /** {@inheritDoc} */ + #[\Override] + protected function initialize(InputInterface $input, OutputInterface $output) + { + if (class_exists(Prompt::class)) { + Prompt::fallbackWhen(true); + } + } + /** {@inheritDoc} */ + #[\Override] + protected function specifyParameters() + { $this->originalCreateUserCommandCallback = Nova::$createUserCommandCallback; $this->createUserOptions = new CreateUserOptions( From 782281790e1f6d9b18070f4783ffe8807b763fc7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 09:52:58 +0800 Subject: [PATCH 3/9] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/UserCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Console/UserCommand.php b/src/Console/UserCommand.php index 71bfac7..c34be25 100644 --- a/src/Console/UserCommand.php +++ b/src/Console/UserCommand.php @@ -8,7 +8,6 @@ use Laravel\Nova\Util; use Laravel\Prompts\Prompt; use NovaKit\NovaOnVapor\Console\Util\CreateUserOptions; -use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; From d03c5bd66a6566947db15093672ec1edd2ce7e8d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 11:14:13 +0800 Subject: [PATCH 4/9] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/UserCommand.php | 14 +++++++++++--- src/Console/Util/CreateUserOptions.php | 7 +++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Console/UserCommand.php b/src/Console/UserCommand.php index c34be25..8b1a9b0 100644 --- a/src/Console/UserCommand.php +++ b/src/Console/UserCommand.php @@ -7,6 +7,7 @@ use Laravel\Nova\Nova; use Laravel\Nova\Util; use Laravel\Prompts\Prompt; +use Laravel\Prompts\TextPrompt; use NovaKit\NovaOnVapor\Console\Util\CreateUserOptions; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -49,21 +50,28 @@ protected function configure() $this->setName($this->name) ->setDescription($this->description); + + // if (class_exists(Prompt::class) && method_exists(Prompt::class, 'interactive')) { + Prompt::interactive(false); + //} } /** {@inheritDoc} */ #[\Override] protected function initialize(InputInterface $input, OutputInterface $output) { - if (class_exists(Prompt::class)) { - Prompt::fallbackWhen(true); - } + + $input->setInteractive(false); } /** {@inheritDoc} */ #[\Override] protected function specifyParameters() { + if (class_exists(Prompt::class)) { + Prompt::fallbackWhen(true); + } + $this->originalCreateUserCommandCallback = Nova::$createUserCommandCallback; $this->createUserOptions = new CreateUserOptions( diff --git a/src/Console/Util/CreateUserOptions.php b/src/Console/Util/CreateUserOptions.php index f253224..a85ece3 100644 --- a/src/Console/Util/CreateUserOptions.php +++ b/src/Console/Util/CreateUserOptions.php @@ -7,6 +7,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Str; use InvalidArgumentException; +use Laravel\Prompts\Prompt; use Symfony\Component\Console\Input\InputOption; class CreateUserOptions @@ -25,7 +26,7 @@ class CreateUserOptions */ public function __construct(callable $callback) { - $this->questions = new Collection(call_user_func($callback, $this)); + $this->questions = Collection::make(call_user_func($callback, $this)); } /** @@ -73,7 +74,9 @@ public function secret(string $question, bool $fallback = true): array public function toCommandOptions(Command $command): void { $this->questions->each(function ($question) use ($command) { - $command->addOption(...$question); + if (is_array($question)) { + $command->addOption(...$question); + } }); } From effd82102e4ff831814367d1036b61dbd5cecb28 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 13:38:04 +0800 Subject: [PATCH 5/9] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/UserCommand.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Console/UserCommand.php b/src/Console/UserCommand.php index 8b1a9b0..818a965 100644 --- a/src/Console/UserCommand.php +++ b/src/Console/UserCommand.php @@ -7,7 +7,6 @@ use Laravel\Nova\Nova; use Laravel\Nova\Util; use Laravel\Prompts\Prompt; -use Laravel\Prompts\TextPrompt; use NovaKit\NovaOnVapor\Console\Util\CreateUserOptions; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -51,9 +50,9 @@ protected function configure() $this->setName($this->name) ->setDescription($this->description); - // if (class_exists(Prompt::class) && method_exists(Prompt::class, 'interactive')) { + if (class_exists(Prompt::class) && method_exists(Prompt::class, 'interactive')) { Prompt::interactive(false); - //} + } } /** {@inheritDoc} */ From 8ef96496604e21e28969e50f93dd7e4cbdab6c3e Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 17:36:22 +0800 Subject: [PATCH 6/9] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/UserCommand.php | 1 - src/Console/Util/CreateUserOptions.php | 35 ++++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Console/UserCommand.php b/src/Console/UserCommand.php index 818a965..6ef9cb0 100644 --- a/src/Console/UserCommand.php +++ b/src/Console/UserCommand.php @@ -59,7 +59,6 @@ protected function configure() #[\Override] protected function initialize(InputInterface $input, OutputInterface $output) { - $input->setInteractive(false); } diff --git a/src/Console/Util/CreateUserOptions.php b/src/Console/Util/CreateUserOptions.php index a85ece3..aac4ecc 100644 --- a/src/Console/Util/CreateUserOptions.php +++ b/src/Console/Util/CreateUserOptions.php @@ -15,18 +15,25 @@ class CreateUserOptions /** * List of create user options. * - * @var \Illuminate\Support\Collection + * @var \Illuminate\Support\Collection|null */ - protected $questions; + protected $questions = null; + + /** + * The questions callback. + * + * @var callable():(\Illuminate\Support\Collection) + */ + protected $questionsCallback; /** * Construct a new Create User Options. * - * @param callable(\NovaKit\NovaOnVapor\Console\Util\CreateUserOptions):array $callback + * @param callable(\NovaKit\NovaOnVapor\Console\Util\CreateUserOptions):array $questionsCallback */ - public function __construct(callable $callback) + public function __construct(callable $questionsCallback) { - $this->questions = Collection::make(call_user_func($callback, $this)); + $this->questionsCallback = $questionsCallback; } /** @@ -73,7 +80,7 @@ public function secret(string $question, bool $fallback = true): array */ public function toCommandOptions(Command $command): void { - $this->questions->each(function ($question) use ($command) { + $this->resolveQuestions()->each(function ($question) use ($command) { if (is_array($question)) { $command->addOption(...$question); } @@ -88,7 +95,7 @@ public function toCommandOptions(Command $command): void public function toCommandCallback(Command $command): Closure { return function () use ($command) { - return $this->questions->transform(function ($question) use ($command) { + return $this->resolveQuestions()->transform(function ($question) use ($command) { $key = $question[0]; $variant = $question[2]; $value = $command->hasOption($key) ? $command->option($key) : null; @@ -117,4 +124,18 @@ protected function parseQuestion(string $question): string return Str::slug($question); } + + /** + * Resolve the available questions. + * + * @return \Illuminate\Support\Collection + */ + protected function resolveQuestions(): Collection + { + if (is_null($this->questions)) { + $this->questions = Collection::make(call_user_func($this->questionsCallback, $this)); + } + + return $this->questions; + } } From 3f8a440d173de6e00b51872166760be6fa7873b8 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 17:39:31 +0800 Subject: [PATCH 7/9] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/UserCommand.php | 15 ++++++++------- src/Console/Util/CreateUserOptions.php | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Console/UserCommand.php b/src/Console/UserCommand.php index 6ef9cb0..c20570b 100644 --- a/src/Console/UserCommand.php +++ b/src/Console/UserCommand.php @@ -49,10 +49,6 @@ protected function configure() $this->setName($this->name) ->setDescription($this->description); - - if (class_exists(Prompt::class) && method_exists(Prompt::class, 'interactive')) { - Prompt::interactive(false); - } } /** {@inheritDoc} */ @@ -60,15 +56,20 @@ protected function configure() protected function initialize(InputInterface $input, OutputInterface $output) { $input->setInteractive(false); + + if (class_exists(Prompt::class)) { + Prompt::fallbackWhen(true); + + if (method_exists(Prompt::class, 'interactive')) { + Prompt::interactive(false); + } + } } /** {@inheritDoc} */ #[\Override] protected function specifyParameters() { - if (class_exists(Prompt::class)) { - Prompt::fallbackWhen(true); - } $this->originalCreateUserCommandCallback = Nova::$createUserCommandCallback; diff --git a/src/Console/Util/CreateUserOptions.php b/src/Console/Util/CreateUserOptions.php index aac4ecc..fb0911f 100644 --- a/src/Console/Util/CreateUserOptions.php +++ b/src/Console/Util/CreateUserOptions.php @@ -22,7 +22,7 @@ class CreateUserOptions /** * The questions callback. * - * @var callable():(\Illuminate\Support\Collection) + * @var callable(\NovaKit\NovaOnVapor\Console\Util\CreateUserOptions):array */ protected $questionsCallback; From afc3048ff2acd9ec455c86b1a9711b6fc8cff82b Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 17:40:58 +0800 Subject: [PATCH 8/9] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d3444a8..41f4470 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "league/flysystem-aws-s3-v3": "^1.0 || ^3.0", "nova-kit/nova-devtool": "^1.3", "orchestra/testbench": "^7.40 || ^8.21 || ^9.0", - "phpunit/phpunit": "^9.6 || ^10.1" + "phpunit/phpunit": "^9.6" }, "repositories": [ { From e63c597bcab5b898b82865cb78355102725c24da Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 15 Apr 2024 17:41:24 +0800 Subject: [PATCH 9/9] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/UserCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Console/UserCommand.php b/src/Console/UserCommand.php index c20570b..08dc129 100644 --- a/src/Console/UserCommand.php +++ b/src/Console/UserCommand.php @@ -70,7 +70,6 @@ protected function initialize(InputInterface $input, OutputInterface $output) #[\Override] protected function specifyParameters() { - $this->originalCreateUserCommandCallback = Nova::$createUserCommandCallback; $this->createUserOptions = new CreateUserOptions(