A set of interfaces & classes for creating domain driven projects.

v4.2.0 2016-04-03 08:03 UTC



Build Status Coverage Status Scrutinizer Code Quality

Axiom is a collection of PHP PSR-2 compliant interfaces and classes designed to help you flesh out domain driven projects. Sticking to a framework like Axiom will help keep all your projects consistent in their layout, design and implementation, hopefully making your job (and others working on your code) easier.


composer require enzyme/axiom

What's included


Atoms are wrappers around native php variable types such as int and string. They are used when a service or class expects one of these values and doesn't want to litter the code with type checks such as if (is_string($var)) {...}.


Bags are used to carry data around the system, whether from the user, an API or an external service.


These exceptions are thrown by the collection of concrete classes included when internal errors occur.


A factory is responsible for the creation and modification of models. It has intimate knowledge of how a model is built and the various attributes it acquires.


Models represent objects in your domain. They are unique, have a set of attributes and are the primary resource of your application.


Recipients are parts of your system that require knowledge of when a model is either successfully or unsuccessfully created, updated or destroyed after they have initiated a command.


Reports are containers that carry a message and optional details associated with the outcome of some event or action in your domain. For example, when a model failed to be created, a FailureReport can be returned with the details of what went wrong.


Repositories are model collections that allow the system to store and retrieve models from an underlying persistence layer.

Concrete classes

There are a couple concrete classes included with Axiom that you can use straight out of the box. These are:


  • IntegerAtom - represents an integer value. This does not include floats.
  • StringAtom - represents a string, either empty or of any size.


  • ArrayBag - simply stores a collection of key/value pairs using an internal native array.


  • SimpleReport - provides a basic report implementation that stores a message and optional details.
  • FailureReport - extends the simple report and is purely a more readable means of reporting a failure.


  • InMemoryRepository - stores a collection of models in-memory using a simple array.


Axiom comes with a set of command line generators for quickly creating skeleton implementations of the various interfaces included.

To use the command line tool, run it from the console at the root of your project as:

php vendor/bin/axiom list

When create a resource using the command line tool, you can either specify the namespace and location of the file using the optional parameters --location=LOCATION and --namespace=NAMESPACE or using an axiom.yaml config file (recommended).


The axiom.yaml file lays out the structure for your generated classes and looks something like:

    - namespace: Acme\Repositories
    - location: /Users/enzyme/code/acme/Repositories
    - namespace: Acme\Factories
    - location: /Users/enzyme/code/acme/Factories
    - namespace: Acme\Bags
    - location: /Users/enzyme/code/acme/Bags
    - namespace: Acme\Atoms
    - location: /Users/enzyme/code/acme/Atoms
    - namespace: Acme\Reports
    - location: /Users/enzyme/code/acme/Reports
    - namespace: Acme\Models
    - location: /Users/enzyme/code/acme/Models

When generating a class using the command line tool and no entry for the class type is found in the axiom.yaml (optional) file or through the command line parameter, an exception will be thrown.

Resource stack

To create an entire resource stack, which includes a repository, factory, bag and model for a domain resource, you can use the make:stack command. This command does not accept namespaces and locations from the command line, so you will need a axiom.yaml file present. If you want to use the stack generator but want to ignore one or more of the included generated classes, you can use the --ignore parameter. Simply pass the --ignore parameter a string with a comma-delimited list of the resource types to ignore, eg: --ignore="model" or --ignore="factory,bag".


Please see CONTRIBUTING.md


MIT - Copyright (c) 2015 Tristan Strathearn, see LICENSE