Download the PHP package kirschbaum-development/laravel-actions without Composer

On this page you can find all versions of the php package kirschbaum-development/laravel-actions. 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-actions

Laravel Actions

A package for handling simple actions with eventing.

Latest Version on Packagist Total Downloads Actions Status

Laravel Actions are simple job-like classes that don't interact with the queue. Actions are great to leverage when you have some simple functionality that you need to reuse.

But why would you want to use Actions you ask? Actions are great when you have small bits of code that you want to extract into small, testable classes. Actions can also take the place of queued jobs when you don't want or need that kind of power, or if you need the results of the code right now.

But the real power is with eventing.

This package exposes two events during your Action:

The special sauce here is that you get to tell the Action which events you want triggered!

Requirements

PHP Version Laravel Actions Version
^6.0, ^7.0 ^0.1.0
^8.0 ^0.2.0

Installation

Creating and Preparing the Action

Create a new Action with artisan command:

This will create a new Action class at app/Actions/ChuckNorris.php. You are, of course, free to move the action wherever you want. Just make sure you update the namespace!

There are two public properties ready for your events: $before and $after. You can use one or both of these, and you can remove either of them if you don't use them in your Action class.

Next place your required arguments within the __construct() method and your Action code within the __invoke() method. You are free to return anything you might need from the invokeable method. Now we're ready to use the Action!

Usage

There are two different ways we can call our newly created Action.

From the Action

We can call one of three methods on the Action itself as long as the class is using the CanAct trait.

The $data is passed into the Action's constructor. You can pass as many arguments as needed in your use case.

The second two methods, actWhen and actUnless require a condition as the first variable. These work like other Laravel methods such as throw_if() and throw_unless(). Finally, you can pass as many arguments as needed for your Action after the condition.

Facade

The package also has a facade. Here's the syntax:

The usage is nearly identical to calling the methods directly on the Action as mentioned in the section above. The benefit here is that you can easily test actions using Action::shouldReceive('act'), Action::shouldReceive('actWhen') or Action::shouldReceive('actUnless').

Helpers

The package also has a few handy helpers to get Chuck in action. Here's the syntax:

Dependency Injection

You can even inject Actions as a dependencies inside your application!

Handling Failures

We all know Chuck Norris isn't going to fail us, but he isn't the only one using this... Handling failures is pretty easy with Actions. Out of the box, any exceptions thrown by your Action classes get handled by Laravel's exception handler. If you'd rather implement your own logic during a failure, add a failed() method to your Action. It's that easy! You can return data from your failed() method if you choose as well.

Hashtag #BAM!

Custom Exceptions

Another option for handling failures is to tell the Action to throw its own exception. If you don't need the extra overhead of writing your own failed() method, you can just tell your Action to throw a custom exception. It's as simple as just defining the exception you want thrown from the Action.

Auto-Discovery and Configuration

Out of the box, actions are automatically discovered and bound to Laravel's container, which allows for easier testing of your actions. If you need to add a custom path if you are placing your actions somewhere other than app/Actions, make sure to publish the configs.

If you want to disable auto-discovery, publish the config and return an empty array from the paths key.

Testing

Have no fear. Testing all of this is very straightforward. There are two approaches to testing built in.

Testing Facades

If you are using Facades to implement your Actions, you can use the standard shouldReceive() method directly from the Facade.

Mocking

If you are using helpers, the CanAct trait, or dependency injection, you can easily mock the Action class with Laravel's mocking tools.

Because actions are bound into Laravel's container by default, you can test specific actions as well.

Last thoughts

If for some reason you'd prefer not to use the cool Eventing system, Facades, Mocking, etc., that's fine. Just call your Action like this:

This will bypass all the magic and call the invoke method automagically, letting Chuck do his thing without anyone knowing, but why? ;)

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 email [email protected] or [email protected] instead of using the issue tracker.

Credits

Sponsorship

Development of this package is sponsored by Kirschbaum, a developer driven company focused on problem solving, team building, and community. Learn more about us or join us!

License

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


All versions of laravel-actions with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version >=7.20
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 kirschbaum-development/laravel-actions contains the following files

Loading the files please wait ....