Download the PHP package r4nkt/laravel-dto-action without Composer

On this page you can find all versions of the php package r4nkt/laravel-dto-action. 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-dto-action

A (somewhat opinionated) Laravel package that makes working with actions and data transfer objects a little easier.

Latest Version on Packagist Tests Quality Score Total Downloads

This package is inspired by a few people. Please check out the following to see where the inspiration came from:

It should also be noted that it's a variation of my own pending actions package that I hope will prove to be more useful.

Also important to note is the fact that this package is built around Spatie's data transfer object package. In fact, it's required.

Introduction

From time to time you may need to perform tasks or actions in your application or different parts of your code where there isn't an out-of-the-box Laravel solution. Most likely, this is or is related to your business logic. An oft-used example is creating an invoice. This is an action that may need to take place in one of your applications. It will likely require parameters, and it will likely be made up of smaller actions.

The goal of this package is to provide a (somewhat opinionated) way to make, define, and use actions along with data transfer objects (DTOs). You can create Action classes and then, when you want to execute that action, you "prep" that class: $myAction = MyAction::dto();. You get back a pending action object, which you define, that allows you to provide the parameters necessary for your action to be carried out. When ready, you call execute().

Here's an example:

Installation

You can install the package via composer:

Usage

For now, one must manually create your Action and DataTransferObject classes. A future release will include the ability to create Action and DataTransferObject classes via php artisan.

Create an Action

DTO Class Naming Conventions

By default, each Action class will look for a DTO class that has the same FQCN with Dto appended. So, for our example CreateSubscriber class, it will look for CreateSubscriberDto.

To override this behavior, you can specify the DTO class name in your Action class like so:

Create a DTO

To create a DTO class, refer to the documentation. Once created, simply add the ExecutesDtoActions trait:

"Prep" Your Action, Carry it Out

Once you have built your action and DTO classes, then you can begin to use them. There are three main steps to preparing your action and executing it:

  1. Call the static dto() method on your Action class. This returns the "action-aware" DTO.
  2. Optionally, make any additional changes to your DTO.
  3. Finally, call the execute() method on the pending action object.

Here is an example of preparing and executing an action all at once:

Here is an example of using the DTO to provide different parameters to carry out the action for different scenarios:

Add a Custom Static Contructor

You can also take advantage of Spatie's DTO support for custom static constructors. Simply add a custom static constructor to your DTO per the documentation and then call it via the action by prepending dto to its name.

Here is an example of how you can do this:

You can then use it like so:

NOTE: This functionality is not IDE-friendly and the developer will be responsible for passing the right types of arguments.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please use the issue tracker.

Credits

License

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


All versions of laravel-dto-action with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
laravel/framework Version ^9.15
spatie/data-transfer-object Version ^3.7
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 r4nkt/laravel-dto-action contains the following files

Loading the files please wait ....