Download the PHP package underpin/decision-list-loader without Composer

On this page you can find all versions of the php package underpin/decision-list-loader. 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 decision-list-loader

Underpin decision list Loader

Loader That assists with adding decision lists to a WordPress website.

Installation

Using Composer

composer require underpin/decision-list-loader

Manually

This plugin uses a built-in autoloader, so as long as it is required before Underpin, it should work as-expected.

require_once(__DIR__ . '/underpin-decision-lists/decision-lists.php');

Setup

  1. Install Underpin. See Underpin Docs
  2. Register new decision lists as-needed.

Decision Lists

Typically, WordPress plugins rely solely on WordPress hooks to determine extended logic. This works for simple solutions, but it becomes cumbersome very fast as soon as several plugins are attempting to override one-another. The biggest issue is that the actual logic that determines the decision is decentralized. Since there isn't a single source-of-truth to dictate the order of logic, let alone what the actual choices are, you have no easy way of understanding why a plugin decided to-do what it did.

Decision lists aim to make this easier to work with by making the extensions all centralized in a single registry. This registry is exported in the Underpin console when WP_DEBUG is enabled, so it is abundantly clear what the actual hierarchy is for this site.

If you're debugging a live site, you can output the decision list using a PHP console tool, such as debug bar console.

Set Up

Fundamentally a Decision List is nothing more than a loader class, and can be treated in the same way.

Let's say we wanted to create a decision list that allows people to override an email address in a plugin. This would need to check an options value for an email address, and fallback to a hard-coded address. It also needs to be possible to override this value with other plugins.

In traditional WordPress, you would probably see this done using apply_filters at the end of the function, something like this:

With a decision list, however, this is put inside of a class, and that class can be extended. Like so:

Notice that I'm using anonymous classes here, just to keep everything in a single file. You absolutely do not have to use anonymous classes. In fact, in most cases you shouldn't. If you pass a reference to the class as a string, it will not instantiate the class unless it's explicitly called. This saves on resources and keeps things fast.

The $priority value inside each class tells the decision tree which option to try to use first. If it returns a WP_Error, it moves on to the next one. As soon as it finds an option that returns true, it grabs the value from the valid_actions method, and move on.

Like the custom logger class, this needs to be registered inside Service_Locator.

Finally, we can use this decision list directly in our get_email_address function:

Now that we have this set up, it can be extended by other plugins using the add method. The example below would force the decision list to run this before any other option.

Example

A very basic example could look something like this.

Alternatively, you can extend decision list and reference the extended class directly, like so:

This is especially useful when using decision lists, since they have a tendency to get quite long, and nest deep.

Getting Decision Results

When a decision list determines an action, it does three things:

  1. Sorts all decisions by priority, smallest numbers first.
  2. Loops through each item, and stops on the first decision that passes their respective test.
  3. Returns the result of the decision's valid_actions callback.

The example above would return '', because the first item to pass would be the item with the smallest priority that will pass.

The second argument, $params is an array of arguments that are passed to both the valid_callback and valid_actions_callback.


All versions of decision-list-loader with dependencies

PHP Build Version
Package Version
No informations.
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 underpin/decision-list-loader contains the following files

Loading the files please wait ....