Download the PHP package zachflower/eloquent-interactions without Composer

On this page you can find all versions of the php package zachflower/eloquent-interactions. 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 eloquent-interactions

Eloquent Interactions

Eloquent Interactions manages application-specific business logic. It's an implementation of the command pattern in PHP for Laravel, and is inspired by the ActiveInteraction library in Ruby.

Latest Stable Version CI


Eloquent Interactions gives you a place to put your business logic. It also helps you write safer code by validating that your inputs conform to your expectations, and provides a platform for creating discrete, easily testable code.

Installation

To install Eloquent Interactions, require the library via Composer:

Eloquent Interactions is built with Laravel 7.0+ in mind, and has tests currently validating compatibility with Laravel 7, 8, 9, and 10 on PHP 7.2.5 through 8.3. If you find any issues with your specific version of Laravel or PHP, please open an issue and I will do my best to address it.

Basic Usage

To get started with Eloquent Interactions, let's first create a new Interaction. Interactions typically live in the app/Interactions directory, but you are free to place them anywhere that can be auto-loaded according to your composer.json file. All Eloquent Interactions extend the \ZachFlower\EloquentInteractions\Interaction abstract class.

The easiest way to create an Interaction is using the make:interaction Artisan command:

Now, let's take a look at the base Interaction that was created by the make:interaction command above:

Once generated, every interaction will require the following two components:

  1. Input Validations. The class $validations property utilizes the built-in Laravel validator to define and validate the expected input of a given Interaction. Alternatively, the $validations property can be replaced with a validations() method.
  2. Business Logic. The execute() method takes the provided input—after it passes validation, of course—and executes any necessary business logic on it. Each input you defined will be available. If any of the inputs are invalid, execute() won't be run.

Given that information, let's update the generated Interaction into something usable:

To execute the Interaction, you can call the static run() method on the class. As the Interaction's $validations property defines the expected inputs, a simple key-value array should be passed to run() with the expected input. This method will return a new instance of the \ZachFlower\EloquentInteractions\Outcome class. To check the success of the outcome, a boolean $valid property will be set on the Outcome object, with TRUE meaning the input validation passed, and FALSE meaning it failed. If the validation failed, all validation errors will be stored in the $errors property on the Outcome object. If validation passes, the value returned from the execute() method will be stored in the $result property on the Outcome object.

If you would rather deal with error handling on your own, you can pass TRUE as a second parameter to the run() method. This, for lack of a better word, will execute the Interaction "dangerously," meaning that any defined errors will be thrown as exceptions of the type \ZachFlower\EloquentInteractions\Exceptions\ValidationException instead.

Validations

Eloquent Interactions relies heavily on the build-in Laravel validator. This means that any validation method available within a Laravel application will also be available to the Eloquent Interactions validator. That said, there is currently one custom validator (with more on the horizon) to better facilitate the backend-nature of Eloquent Interactions.

Advanced Validators

If the built-in validators aren't powerful enough for your needs, you can use a validations() method in lieu of the $validations property. For example, let's say that we want to use a class to validate the meters parameter in the above examples. Our interaction would change to look something like this:

Objects

In some instances, it might be desireable to validate the type of an object. For example, if we wanted to validate that an input parameter is User model, the following validation rule may be used:

In a nutshell, this validator checks the instanceof of an input parameter against the defined validation. This is especially useful when validating whether or not a provided object is a child of the defined validation object.

Errors

In addition to the built-in validation errors, Eloquent Interactions also has support for custom validation errors directly within the execute() method. This can be accomplished by utilizing the Laravel validator's own add() method directly on its errors() method:

It is important to note that, while adding custom validation errors within the execute() method will mark the Outcome as invalid and return the expected error messages, what it won't do is halt Interaction execution, so any business logic in the execute() method will be executed as normal unless special steps are taken.

Contributing

Please read through the contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

For personal support requests, please use Gitter to get help.

Versioning

For transparency into the release cycle and in striving to maintain backward compatibility, Eloquent Interactions is maintained under the Semantic Versioning guidelines. Sometimes I screw up, but I'll adhere to those rules whenever possible.

See the Releases section of the GitHub project for changelogs for each release version of Eloquent Interactions.

Support

The issue tracker is the preferred channel for bug reports, feature requests and submitting pull requests.

Copyright and License

Code and documentation copyright 2024 Zachary Flower. Code released under the MIT license.


All versions of eloquent-interactions with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2.5|^8.0
illuminate/validation Version ^7.0|^8.0|^9.0|^10.0
illuminate/support Version ^7.0|^8.0|^9.0|^10.0
illuminate/console Version ^7.0|^8.0|^9.0|^10.0
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 zachflower/eloquent-interactions contains the following files

Loading the files please wait ....