Download the PHP package germania-kg/order-dispatcher without Composer
On this page you can find all versions of the php package germania-kg/order-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download germania-kg/order-dispatcher
More information about germania-kg/order-dispatcher
Files in germania-kg/order-dispatcher
Package order-dispatcher
Short Description Creating and handling orders
License MIT
Informations about the package order-dispatcher
Germania KG · OrderDispatcher
Sourcing that stuff out…
Installation
Classes and interfaces
Working with orders
OrderInterface
public function getCustomerData() : array;
public function getItems() : iterable;
OrderFactoryInterface
OrderFactoryAbstract
This abstract class implements the Item factory interceptors defined in OrderFactoryInterface and uses the ValidatorTrait.
ArrayOrderFactory
Creates an Order instance from an array, typically from user input.
The ArrayOrderFactory extends OrderFactoryAbstract and implements the OrderFactoryInterface.
The constructor accepts an ItemFactoryInterface, the order items array key, and optionally a PSR-3 LoggerInterface.
Usage with above setup:
OrderHandlerController
This controller class accepts user input from the ServerRequest body, creates an Order object underway and delegates it to the given handler.
Its constructor accepts an OrderFactoryInterface instance, an OrderHandlerInterface instance, and optionally a PSR-3 LoggerInterface.
Given a ServerRequest and a Response object, invoke the controller like this:
Response status codes
Status code | |
---|---|
400 | When OrderFactoryExceptionInterface occured |
500 | When OrderHandlerExceptionInterface occured |
500 | any other Throwable |
Response headers
In case of an error, the response object will have a X-Order-Dispatch-Message
header with the class name of the thrown Exception:
Working with order items
Order items are the things one can order.
Item class and ItemInterface
The ItemInterface extends \ArrayAccess
.
The Item class extends \ArrayObject
and implements ItemInterface.
ItemFactoryInterface
SimpleItemFactory
Create an “order item” array based on any array data. Extends ItemFactoryAbstract and implements ItemFactoryInterface.
ContainerItemFactory
Use this to restrict order items to only items from a PSR-11 Psr\Container\ContainerInterface
. The array field name with which the item shall be retrieved is required, and the constructor optionally accepts a PSR-3 Logger.
Extends ItemFactoryAbstract and implements ItemFactoryInterface.
When an item is not available, a ItemNotAvailableException
will be thrown.
ValidatorItemFactoryDecorator
This decorator accepts any ItemFactoryInterface and a ValidatorInterface to validate the order item data.
Render orders
Renderers are used to create a string representation from an order object, typically for emails.
RendererInterface
Renderers accept a template string and a context variables array. In case of errors, Germania\OrderDispatcher\Exceptions\RendererExceptionInterface
must be thrown.
TwigRenderer
The TwigRenderer implements the RendererInterface. Its constructor accepts a Twig environment object, and optionally an array with default context variables.
Work with orders
OrderHandlerInterface
SwiftMailerOrderHandler
The SwiftMailerOrderHandler implements the OrderHandlerInterface. Its constructor accepts a SwiftMailer instance, a mail configuration array, and a RendererInterface instance.
Typically, you will use the TwigRenderer for RendererInterface.
The mail configuration array must contain a to
, from
, template,
and a subject
element. The subject may have field variables in curly braces which are interpolated from the handle method context.
Subject and template given in mail configuration array may be overridden by mailSubject
or mailTemplate
entry in the context array.
The renderer will be passed the handler context with additional customer
, orderItems
, and datetimeNow
information.
OrderHandlerChain
Use this handler to mangle an order through multiple handlers.
Validators
ValidatorInterface
Validates user input and returns cleaned data. Usually PHP's filter_var_array
will be used.
When writing your own implementation, missing fields should be added and set to null
, any additional content should be merged back.
ValidatorTrait
Interceptors for ValidatorInterface.
FilterValidator
This validator checks user input with PHP's filter_var_array
.
- Missing fields will be added and set to
null
- Additional “unvalidated” content will be merged back, as opposite to original filter_var_array.
The FilterValidator Implements ValidatorInterface.
SkuQtyItemValidator
This is a predefined Validator which checks user input for sku
and quantity
elements. It works just like FilterValidator:
- Missing fields will be added and set to
null
- Additional “unvalidated” content will be merged back, as opposite to original filter_var_array.
Exceptions
- ItemInvalidUserDataException, when
sku
orquantity
missing or false - ItemNotOrderedException, when
quantity
is int 0.
The SkuQtyItemValidator Implements ValidatorInterface.
Exceptions
Interface | sub interface | Class | parent |
---|---|---|---|
OrderFactoryExceptionInterface | ItemNotAvailableException | UnexpectedValueException | |
OrderFactoryExceptionInterface | RequiredUserDataMissingException | UnexpectedValueException | |
OrderFactoryExceptionInterface | NoArticlesOrderedException | Exception | |
OrderHandlerExceptionInterface | OrderHandlerRuntimeException | RuntimeException | |
OrderHandlerExceptionInterface | ItemExceptionInterface | ItemInvalidUserDataException | UnexpectedValueException |
OrderHandlerExceptionInterface | ItemExceptionInterface | ItemNotOrderedException | Exception |
RendererExceptionInterface | RendererRuntimeException | RuntimeException | |
ValidatorExceptionInterface | ValidatorUnexpectedValueException | UnexpectedValueException |
All versions of order-dispatcher with dependencies
psr/http-message Version ^1.0
psr/log Version ^1.1
psr/container Version ^1.0|^2.0
twig/twig Version ^3.0
swiftmailer/swiftmailer Version ^6.2
nyholm/psr7 Version ^1.3
germania-kg/responder Version ^1.0