ecamp/ecamp3 — pull request #62 by pmattmann (2012-03-12 22:59:09+00:00)
Title: Validation

This pull request contains two commits. These commits can be seen as a two-step development of the final suggested ServiceValidation-Concept.

1. Commit:
(https://github.com/pmattmann/ecamp3/commit/95141ce3f9f16cb5f14aa63271bdd76c8bd024f3)

It removes the ServiceResponse Object. I do not like it at all! It does not allow autocompletion of an IDE.
ServiceResponse Object is removed with the following concepts:
- A $ServiceBase::start() and ServiceBase::end() at each ServiceCall (first and last line) count statically the depth of the service call (on ServiceBase::serviceCounter)
- Parallel, all the validation-errors are collected on a static array (ServiceBase::validationException)
- If depth-counter is zero and ServiceBase::start() is called, the ServiceBase::validationException is set to null.
- At the first validation error, the ServiceBase::validationException is set to new ValidationException
- Further validation errors are collected on the ValidationException.
- If depth-counter is zero after calling the ServiceBase::end(), the ServiceBase::validationException is thrown, if it is availlable.

At the same time, I changed the beginTransaction() to check whether it is the first transaction or if it would be a nested one. It opens only a transaction, if it is the first one. The method beginTransaction() returns an object, with the methods commit() and rollback(). The Transaction-Object it self knows whether it opened the first transaction or not. Commit() and rollback() do only react, if it was the first transaction.

2. Commit:
(https://github.com/pmattmann/ecamp3/commit/5e526e90fd50b7e5c92aaf3f1879bd99284343dd)

Moved the ServiceBase::start() and ServiceBase::end() into a Core\Service\ValidationWrapper. This wrapper calls the start() and end() method by it self (magic __call). Parallel it holds the counter and the ValidationException, if any validation failed.
As the construction of a service become complex (two wrappers; ACWrapper and ValidationWrapper)) I introduced a ServiceFactory, which does the job right.