Download the PHP package allysonsilva/laravel-artisan-domain-contexts without Composer

On this page you can find all versions of the php package allysonsilva/laravel-artisan-domain-contexts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-artisan-domain-contexts

Laravel Artisan Domain Contexts

PHP Version Laravel Version CI Status PHPCS - GitHub Workflow Status PHPMD - GitHub Workflow Status PHPStan - GitHub Workflow Status Coverage Status Code Quality/Consistency Latest Version Total Downloads

Table of Contents

Overview

This package provides the ability to use artisan commands in different domain contexts. It allows to work interactively in the migration commands and seeders, choosing which class should be executed.

Concepts

What is "Domain"?

See the article for a better understanding!

What is "Contexts"?

See the article for better understanding!

Questions

Should I use this package in the default Laravel framework?

No, because the files handled by artisan are already in their default folders.

When should I use this package?

๐Ÿš€ Installation

Requirements

The package has been developed and tested to work with the following minimum requirements:

Laravel version Compatibility

Laravel PHP Package Maintained
9.x 8.0 ^2.0 โœ…
8.70 8.0 ^1.0 โœ…

Install the Package

You can install the package via Composer:

Publish the Config

You can then publish the package's config file by using the following command:

๐Ÿ”ง Configuration

  1. Create a folder, inside the app folder with the same name as the config of config('context.folders.domain')

  2. Add trait to app/Console/Kernel.php file with usage options in all Laravel commands:

  3. Inside the domain folder (config('context.folders.domain')), is where you can find Laravel components (such as migrations, seeders, models, jobs, etc). The names of the folders, where the classes are, are in the config of config('context.folders.components').

๐Ÿ“– Usage

To use commands by context, the following options have been added to Laravel commands:

Some options are only available in a certain command, but the --context option is present in all commands in the list below!

The list of standard laravel commands that were handled by adding these options can be seen table below.

Understanding the --context option

This option is present in all commands listed below!

When this option is passed in the command, then the component/class/resource is manipulated or created, according to the resource type setting in config('context.folders.components').

To change the path/name of the folder where the class should be manipulated or created, see the config in config('context.folders.components').

Example

So, for example, to create a middleware in a given context, in this case, in the user context, the command can be: php artisan make:middleware --context=User YourMiddleware.

A middleware class was created in app/Domain/User/Http/Middlewares/YourMiddleware.php.

If the config of config('context.folders.components.middlewares') has the value of Http/AnotherFolder instead of Http/Middlewares (default), and the previous command is executed, then the class would be created in app/Domain/User/Http/AnotherFolder/YourMiddleware.php.

Understanding the --context-namespace option

This option will only be used in the make commands, with that, see and explanation about it.

Understanding the --all-contexts option

When this option is passed in the command, then it will be executed non-interactively, that is, it will execute the context-specific filtered classes.

This option is not present in the make commands only in the migration and db:seed commands. See the table below.

It has the same behavior as the --force option.

Understanding the --only-default option

By default, migrations commands are executed in all contexts when no options are passed. To run migrations commands in Laravel's default folder (database/migrations) use this option.

This option is only in the migration and db:seed commands. It is not present in the make commands.

Understanding the --multi-databases option

This option is only present in migration commands!

By default the migration commands are run on the database configured in the DB_DATABASE env, so you can only use one database in the command. With this option, you can use multiple databases for the same command via the config config('context.migrations.databases')

When this option is passed, then the command will be executed on different databases according to the config of config('context.migrations.databases').

The config of config('context.migrations.databases') refers to the name of the database that the operation will be performed on.

List of commands using contexts

Commands Additional Command Options
--context --context-namespace --all-contexts --only-default --multi-databases
make:cast โœ”๏ธ โœ”๏ธ
make:channel โœ”๏ธ โœ”๏ธ
make:command โœ”๏ธ โœ”๏ธ
make:event โœ”๏ธ โœ”๏ธ
make:exception โœ”๏ธ โœ”๏ธ
make:factory โœ”๏ธ โœ”๏ธ
make:factory โœ”๏ธ โœ”๏ธ
make:job โœ”๏ธ โœ”๏ธ
make:listener โœ”๏ธ โœ”๏ธ
make:mail โœ”๏ธ โœ”๏ธ
make:middleware โœ”๏ธ โœ”๏ธ
make:migration โœ”๏ธ โœ”๏ธ
make:model โœ”๏ธ โœ”๏ธ
make:notification โœ”๏ธ โœ”๏ธ
make:observer โœ”๏ธ โœ”๏ธ
make:policy โœ”๏ธ โœ”๏ธ
make:provider โœ”๏ธ โœ”๏ธ
make:request โœ”๏ธ โœ”๏ธ
make:resource โœ”๏ธ โœ”๏ธ
make:rule โœ”๏ธ โœ”๏ธ
make:seeder โœ”๏ธ โœ”๏ธ
migrate:fresh โœ”๏ธ โœ”๏ธ
migrate:refresh โœ”๏ธ โœ”๏ธ โœ”๏ธ
migrate:reset โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
migrate:rollback โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
migrate:status โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
migrate โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
db:seed โœ”๏ธ โœ”๏ธ โœ”๏ธ

๐Ÿ— make commands

Make commands, create files in a given context or Laravel's default folder when no context is specified.

All the make commands that are listed in the table above, have 2 options in their command, which are:

To change the name of the component folder in which the class is created, see the following config config('context.folders.components').

Examples

The example commands below will use the following folder organization:

How to create a [MIGRATION] in a specific context?

Use the following command below as an example, passing the --context option with the name of the context in which the migration will be created.

The migration files will be saved in the config folder config('context.folders.components.migrations') in the context folder, according to the --context option of the command.

A new migration has been created at: app/Domain/Post/Database/Migrations/2022_xx_xx_xxxxxx_create_posts_table.php

The file path parts are:

How to create a [JOB] in a specific context?

In the same way as explained earlier in the case of migration, the --context option is also used to create a new job in a specific context.

A new job has been created at: app/Domain/Foo/Jobs/MyJob.php

The file path parts are:

How to create a class/component with a custom namespace?

Use the --context-namespace option to customize the class namespace prefix.

If you want to create a model with a specific namespace, Use the following command below as an example.

The previous command will create a model in the path: app/Domain/Post/Models/Post.php

With the following content:

The namespace for the above class is: namespace PostDomain\Models.

How to create class in Laravel's default folder?

To create the class in the default Laravel folder, don't use/pass the --context option!

The following command will create the class in Laravel's default folder at app/Events/MyEvent.php.

migrate commands

The migration commands are executed interactively, and you can even select each individual migration, or all migrations in a given context to perform the operation.

The following are the options that may be on commands:

To see the migration commands in action, let's use the folder organization below as an example and see the expected results:

Understanding the behavior of migrate:fresh and migrate:refresh

Both work in the same way / Summary:

See the questions and answers below for better understanding:

๐Ÿ“น Demo migrate:fresh

See the demo below for better understanding:

๐Ÿ“น Demo migrate:refresh

See the demo below for better understanding:

Understanding the behavior of migrate:reset, migrate:rollback, migrate:status and migrate

Summary of all commands:

See the questions and answers below for better understanding:

The $command variable, can be one of the items ['migrate:reset', 'migrate:rollback', 'migrate:status', 'migrate'].

๐Ÿ“น Demo migrate:reset

See the demo below for better understanding:

๐Ÿ“น Demo migrate:rollback

See the demo below for better understanding:

db:seed command

Three options are found in the command:

See the questions and answers below for better understanding:

๐Ÿ“น Demo db:seed

See the demo below for better understanding:

๐Ÿงช Testing

๐Ÿ“ Changelog

Please see CHANGELOG for more information about the changes on this package.

๐Ÿค Contributing

Please see CONTRIBUTING for details.

๐Ÿ”’ Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

๐Ÿ† Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-artisan-domain-contexts with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
laravel/framework Version ^9.32
nikic/php-parser Version ^4.13
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package allysonsilva/laravel-artisan-domain-contexts contains the following files

Loading the files please wait ....