Skip to content

Commit

Permalink
Refactor cache/optimize commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey committed Oct 16, 2024
1 parent 81b922f commit 1312458
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ All notable changes to `laravel-ddd` will be documented in this file.
- Added `ddd:request` to generate domain-spefic requests in the application layer.
- Added `ddd:middleware` to generate domain-specific middleware in the application layer.
- Added `ddd:migration` to generate domain migrations.
- Migration folders across domains will be registered and scanned when running `php artisan migrate`, in addition to the standard application `database/migrations` path.
- Added `ddd:seeder` to generate domain seeders.
- Migration folders across domains will be registered and scanned when running `php artisan migrate`, in addition to the standard application `database/migrations` path.

### Changed
- `ddd:model` now internally extends Laravel's native `make:model` and inherits all standard options:
Expand All @@ -34,6 +34,8 @@ All notable changes to `laravel-ddd` will be documented in this file.
- `-mfsc`
- `--all|-a`
- `--pivot|-p`
- `ddd:cache` is now `ddd:optimize` (`ddd:cache` is still available as an alias).
- For Laravel 11.27.1+, the framework's `optimize` and `optimize:clear` commands will automatically invoke `ddd:optimize` and `ddd:clear` respectively.

### Deprecated
- Domain base models are no longer required by default, and `config('ddd.base_model')` is now `null` by default.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ composer require lorisleiva/laravel-actions
The default DTO and Action stubs of this package use the above dependencies. Of course, you may customize the stubs to suit your needs if you aren't using the above packages.

### Deployment
In production, run `ddd:cache` during the deployment process to [optimize autoloading](#autoloading-in-production).
In production, run `ddd:optimize` during the deployment process to [optimize autoloading](#autoloading-in-production).
```bash
php artisan ddd:cache
php artisan ddd:optimize
```
Note: Since Laravel 11.27.1, `ddd:cache` will automatically be invoked during Laravel's `optimize` command, in which case you do not need to run `ddd:cache` separately if your production environment already runs `optimize`.
Since Laravel 11.27.1, `php artisan optimize` automatically invokes `ddd:optimize`. If you already run `optimize` in production, a separate `ddd:optimize` is no longer necessary.

### Version Compatibility
Laravel | LaravelDDD | |
Expand Down Expand Up @@ -110,7 +110,7 @@ Generated objects will be placed in the appropriate domain namespace as specifie
php artisan ddd:list

# Cache domain manifests (used for autoloading)
php artisan ddd:cache
php artisan ddd:optimize

# Clear the domain cache
php artisan ddd:clear
Expand Down Expand Up @@ -286,9 +286,9 @@ You may disable autoloading by setting the respective autoload options to `false
<a name="autoloading-in-production"></a>

## Autoloading in Production
In production, you should cache the autoload manifests using the `ddd:cache` command as part of your application's deployment process. This will speed up the auto-discovery and registration of domain providers and commands. The `ddd:clear` command may be used to clear the cache if needed.
In production, you should cache the autoload manifests using the `ddd:optimize` command as part of your application's deployment process. This will speed up the auto-discovery and registration of domain providers and commands. The `ddd:clear` command may be used to clear the cache if needed.

Note: Since Laravel 11.27.1, `ddd:cache` and `ddd:clear` will automatically be invoked when running Laravel's `optimize` and `optimize:clear` respectively. If this applies to you and you are already running `optimize` in production, you don't need to manually run `ddd:cache`.
> **Note**: Since Laravel 11.27.1, the framework's `optimize` and `optimize:clear` commands will automatically invoke `ddd:optimize` and `ddd:clear` respectively.
<a name="config-file"></a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
use Illuminate\Console\Command;
use Lunarstorm\LaravelDDD\Support\DomainCache;

class CacheClearCommand extends Command
class OptimizeClearCommand extends Command
{
protected $name = 'ddd:clear';

protected $description = 'Clear cached domain autoloaded objects.';

protected function configure()
{
$this->setAliases([
'ddd:optimize:clear',
]);

parent::configure();
}

public function handle()
{
DomainCache::clear();
Expand Down
13 changes: 11 additions & 2 deletions src/Commands/CacheCommand.php → src/Commands/OptimizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
use Lunarstorm\LaravelDDD\Support\DomainAutoloader;
use Lunarstorm\LaravelDDD\Support\DomainMigration;

class CacheCommand extends Command
class OptimizeCommand extends Command
{
protected $name = 'ddd:cache';
protected $name = 'ddd:optimize';

protected $description = 'Cache auto-discovered domain objects and migration paths.';

protected function configure()
{
$this->setAliases([
'ddd:cache',
]);

parent::configure();
}

public function handle()
{
$this->components->info('Caching DDD providers, commands, migration paths.');
Expand Down
8 changes: 4 additions & 4 deletions src/LaravelDDDServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function configurePackage(Package $package): void
->hasCommands([
Commands\InstallCommand::class,
Commands\UpgradeCommand::class,
Commands\CacheCommand::class,
Commands\CacheClearCommand::class,
Commands\OptimizeCommand::class,
Commands\OptimizeClearCommand::class,
Commands\DomainListCommand::class,
Commands\DomainModelMakeCommand::class,
Commands\DomainFactoryMakeCommand::class,
Expand Down Expand Up @@ -92,9 +92,9 @@ public function packageBooted()

if ($this->app->runningInConsole() && method_exists($this, 'optimizes')) {
$this->optimizes(
optimize: 'ddd:cache',
optimize: 'ddd:optimize',
clear: 'ddd:clear',
key: 'ddd:cache',
key: 'ddd cache',
);
}
}
Expand Down

0 comments on commit 1312458

Please sign in to comment.