Skip to content

Commit

Permalink
Prompts (#48)
Browse files Browse the repository at this point in the history
* Use Laravel Prompts for domain input prompt.

* Add version matrix to readme.
  • Loading branch information
JasperTey authored Mar 25, 2024
1 parent 34e8711 commit c18c676
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.2, 8.1]
laravel: [11.*, 10.*]
laravel: [11.*, 10.25.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
carbon: ^3.0
- laravel: 10.*
- laravel: 10.25.*
testbench: 8.*
carbon: ^2.63
carbon: 2.*
exclude:
- laravel: 11.*
php: 8.1
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

Laravel-DDD is a toolkit to support domain driven design (DDD) patterns in Laravel applications. One of the pain points when adopting DDD is the inability to use Laravel's native `make:model` artisan command to properly generate domain models, since domain models are not intended to be stored in the `App/Models/*` namespace. This package aims to fill the gaps by providing an equivalent command, `ddd:model`, plus many more.

## Version Compatibility
Laravel | LaravelDDD
:-----------|:-----------
9.x | 0.x
<10.25 | 0.x
10.25+ | 1.x
11.x | 1.x

## Installation

You can install the package via composer:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
],
"require": {
"php": "^8.1|^8.2|^8.3",
"spatie/laravel-package-tools": "^1.13.0",
"illuminate/contracts": "^10.0|^11.0"
"illuminate/contracts": "^10.17|^11.0",
"laravel/prompts": "^0.1.16",
"spatie/laravel-package-tools": "^1.13.0"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
35 changes: 35 additions & 0 deletions src/Commands/Concerns/CanPromptForDomain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Lunarstorm\LaravelDDD\Commands\Concerns;

use Illuminate\Support\Str;
use Lunarstorm\LaravelDDD\Support\DomainResolver;

use function Laravel\Prompts\suggest;

trait CanPromptForDomain
{
protected function promptForDomainName(): string
{
$choices = collect(DomainResolver::domainChoices())
->mapWithKeys(fn ($name) => [Str::lower($name) => $name]);

// Prompt for the domain
$domainName = suggest(
label: 'What is the domain?',
options: fn ($value) => collect($choices)
->filter(fn ($name) => Str::contains($name, $value, ignoreCase: true))
->toArray(),
placeholder: 'Start typing to search...',
required: true
);

// Normalize the case of the domain name
// if it is an existing domain.
if ($match = $choices->get(Str::lower($domainName))) {
$domainName = $match;
}

return $domainName;
}
}
6 changes: 3 additions & 3 deletions src/Commands/Concerns/ResolvesDomainFromInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

trait ResolvesDomainFromInput
{
use CanPromptForDomain;

protected ?Domain $domain = null;

protected function getOptions()
Expand Down Expand Up @@ -81,9 +83,7 @@ public function handle()

// If the domain is not set, prompt for it
if (! $this->domain) {
$this->domain = new Domain(
$this->anticipate('What is the domain?', DomainResolver::domainChoices())
);
$this->domain = new Domain($this->promptForDomainName());
}

parent::handle();
Expand Down

0 comments on commit c18c676

Please sign in to comment.