Download the PHP package shrink/examples without Composer
On this page you can find all versions of the php package shrink/examples. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package examples
Examples
Compose example objects.
Usage
- Install the library with composer
- Define examples
- Make objects
Install
:yarn: The latest version of Examples requires PHP 8.1, use Examples v1 for PHP 7.4 and PHP 8.0 support.
Instantiate Examples
An Examples::class
instance holds your example definitions and creates your
objects from these definitions.
Define Examples
The E::define()
method accepts a class type
and zero or more named
arguments, which map to the type
's constructor arguments.
E::define()
returns a definition to register with your instance of Examples.
:sparkles: Since v2, named arguments are used instead of a parameters array.
:dna: E::define()
is a shortcut to create a simple example definition, see
Internals -> Definition for building your own implementation.
Make An Object
The E::g()
method accepts a class type
(referring to a registered example)
and zero or more named arguments to overwrite the example defaults. E::g()
returns an example configuration, which your instance of Examples will make()
.
:dna: E::g()
is a shortcut to create a simple example configuration, see
Internals -> Creation for building your own implementation.
Features
Nested Examples
Examples::class will resolve any example definitions it encounters when making an example, allowing for many levels of nested example definitions and configuration.
Internals
Definition
Examples are registered using an example definition (DefinesExample
) which in
turn uses a builder (BuildsExampleInstances
) to create an object using
optional configuration.
Implicit instance building is handled through Reflection by ReflectionBuilder
which accepts a class name to build.
E::define()
is a shortcut for creating an example definition with implicit
building. Explicit instance building is handled by providing a callable which is
called with the Example parameters as method parameters.
Creation
Objects are made, from an example, with an optional configuration of
parameters
. Ask the Examples
instance to
make(ConfiguresExample $configuration)
. A default implementation of
ConfiguresExample
is included which is constructed with the type and
parameters.
Parameters may be provided to overwrite any defaults.
License
Examples is open-sourced software licensed under the MIT license.