Download the PHP package stagerightlabs/actions without Composer

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

Discrete units of logic for PHP

Latest Version on Packagist Total Downloads Tests

Actions

Action classes are a pattern for isolating business logic from the rest of an application. This makes it easier to test the business logic and it provides portability: you can use the same action class in multiple contexts which helps to DRY up your codebase.

This package provides a foundation for creating action classes that will integrate easily with the rest of your PHP application.

Inspiration

This idea has been in the back of my mind for some time. However, these blog posts really helped me shape my ideas about how Action classes should work and inspired me to create this package:

Installation

Install this library with Composer:

Instructions

This library provides an abstract Action class that you can extend to create your own action classes. All you need to do is provide a handle method which contains your business logic. For example:

To use this class in your application, you can call the static execute() method:

Notice how we generate our response based on the outcome of the action.

Input

It is not often that business logic can be performed without some sort of input. We can provide input to our action class by providing it with an associative array of data. To ensure that the action is not executed without everything in place, the class will verify the keys of that input array before your task is run.

We use the required() and optional() methods to tell the action what input keys to expect. If a required key is missing the action will fail before it executes. If any input keys are provided that are not defined as required or optional, the action will fail. It is important to note that this validation is only performed on the array keys; if a key is provided but it contains a falsy value, the action will still proceed.

The goal of this validation step is to provide clarity to future developers about how your action classes work and what input they need.

Completion Status

In the course of performing our business logic we may decide that the action will need to fail or that it has completed. Use the fail() and complete() methods to set the status of the action and halt further execution:

The message is optional. It can be accessed like so:

Output

Often you may find that your action produces artifacts that you would like to make available elsewhere. To retain these artifacts, assign them to public class properties in your action. This allows the action class itself to behave as a data transfer object:

You can then access those artifacts after the execution is complete:

Class Constructors

If you would like to define a constructor on your action classes to allow for dependency injection you will not then be able to call the execute() method statically. However, you can instead call it from the regular object context:

API


All versions of actions with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3 || ^8.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 stagerightlabs/actions contains the following files

Loading the files please wait ....