Download the PHP package joachim-n/mutable-typed-data without Composer

On this page you can find all versions of the php package joachim-n/mutable-typed-data. 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 mutable-typed-data

Mutable Typed Data

Mutable Typed Data is a system for typed and structured data. It is loosely based on Drupal's Typed Data API, with the main difference that the structure of data can change dynamically, based on the values that are set.

Disclaimer

This works, there are tests, but more polish is needed. Releasing now because I've been working on this since the start of lockdown 5 months ago and I'm burnt out by it!

Structure types

Each piece of data is represented by an object which holds the data as well as its definition.

Data objects can be simple, holding just a scalar value:

or complex, with child properties which are in turn simple:

or can be complex themselves:

Both simple or complex data may be multiple-valued:

Complex data can be mutable, which means that its child properties change in response to a controlling property's value:

Accessing data

Simple data is always accessed with the 'value' property:

Complex data is accessed with the child property names, which can be chained until reaching the simple values at the tips of the structure:

As a shorthand, simple child values can be set with just the property name:

Multiple data can be used as a numeric array:

Note that the deltas must remain consistent:

Whether multiple data is simple or complex, accessing the array produces a data object:

Iterating

All data objects can be iterated over.

Simple data has no effect:

Complex data iterates over its child properties:

Multiple data iterates over the delta items:

Because iterating simple items has no effect, iterating data items like this is safe to do recursively into the data structure.

Alternatively, the items() method on data objects allows iteration that is agnostic of cardinality:

This is useful when working with a property that may be either single or multiple, as it gives all the values in either case. However, it should not be used recursively, as iterating on the value in the iteration for a simple item will cause an infinite loop.

Default values

Each data item can have a default defined for it. A default can serve different purposes:

UIs should not force a user to enter a required value if there is a default, as MTB's validation will set the default on data that is required but empty.

A default value can be defined as:

Expression and callable defaults can use the values of other data items, and thus have dependencies.

The following example illustrates how a default is used in a UI:

  1. The UI instantiates the data property. The default is not yet applied.
  2. The UI attempts to get a value for the data. If the default's dependencies are satisfied, it is applied.
  3. The user is presented with either the empty value or the default if it was applied.
  4. The user submits the data. If the property is set to required, the UI should nonetheless allow the user to leave the data empty, as the default can supply the value.
  5. The consumer of the data fetches the value. If it is still empty, the default is applied.

Expression language and JavaScript

MTD extends Symfony Expression Language with custom functions for getting data values with addresses. Further custom functions can be added by subclassing \MutableTypedData\DataItemFactory.

Using an expression is particularly suited to data that is shown in web UIs, as it's possible to parse a small subset of Expression Language into JavaScript, and thus show the user default values dynamically based on other values they have entered. See Drupal's Module Builder for an example of doing this.

Data definition

Data is defined with a fluent interface:

Complex data is defined by nesting properties:

Options

Options can be defined with an array, or with objects, which allow options to have descriptions and weights as well as labels:

Higher-valued weights 'sink' to the bottom of a list of options; lower-valued weights are lighter and 'rise' up.

Mutable data

Mutable data needs a single property to control the variants, and then a definition for each variant:

The variants automatically define the options for the type property.

If the values for the type property don't match up to variant names (typically because several option values of the type property correspond to the same variant), then define the options with setOptions() and use setVariantMapping().


All versions of mutable-typed-data with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
symfony/expression-language Version ^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 joachim-n/mutable-typed-data contains the following files

Loading the files please wait ....