UseCaseBundle provides OpenClassrooms\UseCase Library in a Symfony2 context. UseCase Library provides facilities to manage technical code over a Use Case in a Clean / Hexagonal / Use Case Architecture.
- Security access
- Cache management
- Transactional context
- Events
The goal is to have only functional code on the Use Case and manage technical code in an elegant way using annotations.
For usage of UseCase Library, please see the UseCase Library documentation.
This bundle can be installed using composer:
composer require openclassrooms/use-case-bundle
or by adding the package to the composer.json file directly.
{
"require": {
"openclassrooms/use-case-bundle": "*"
}
}After the package has been installed, add the bundle to the AppKernel.php file:
// in AppKernel::registerBundles()$bundles = array(
// ...newOpenClassrooms\Bundle\OpenClassroomsUseCaseBundle(),
// ...
);If cache facilities are needed, add the OpenClassrooms\CacheBundle to the AppKernel.php file:
// in AppKernel::registerBundles()$bundles = array(
// ...newOpenClassrooms\Bundle\CacheBundle\OpenClassroomsCacheBundle(),
newOpenClassrooms\Bundle\UseCaseBundle\OpenClassroomsUseCaseBundle(),
// ...
);UseCaseBundle requires no initial configuration.
This is the default configuration:
# app/config/config.ymlopenclassrooms_use_case:
security: security_context # an implementation of OpenClassrooms\UseCase\Application\Services\Security\Securitytransaction: doctrine.orm.entity_manager# an implementation of EntityManagerInterface or OpenClassrooms\UseCase\Application\Services\Transaction\Transactionevent_sender: event_dispatcher# an implementation of EventDispatcherInterface or OpenClassrooms\UseCase\Application\Services\Event\EventSenderevent_factory: openclassrooms.use_case.event_factory# an implementation of OpenClassrooms\UseCase\Application\Services\Event\EventFactoryIf cache facilities are needed, CacheBundle configuration MUST be set. See documentation for more details.
Furthermore, only needed services are used. It means, for example, if only security is used, the others services will never be called. Even if the services of the default configuration exist or not.
For usage of UseCase Library, please see the UseCase Library documentation.
Add the tag openclassrooms.use_case to the use case declaration to enable UseCase Library facilities.
<?xml version="1.0" ?>
<containerxmlns="http://symfony.com/schema/dic/services"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameterkey="a_project.a_use_case.class">AProject\BusinessRules\UseCases\AUseCase</parameter>
</parameters>
<services>
<serviceid="a_project.a_use_case"class="a_project.a_use_case.class">
<tagname="openclassrooms.use_case"/>
</service>
</services>
</container>The different services used are those defined in the configuration file. For each tag and each facility, a specific service can be set:
<serviceid="a_project.a_use_case"class="a_project.a_use_case.class">
<tagname="openclassrooms.use_case"security="a.different.security_context"cache="a.different.cache"transaction="a.different.entity_manager"event-sender="a.different.event_dipsatcher"event-factory="a.different.event_factory"/>
</service>- security parameter MUST be an implementation of OpenClassrooms\UseCase\Application\Services\Security\Security
- cache parameter MUST be an implementation of OpenClassrooms\Cache\Cache\Cache
- transaction parameter MUST be an implementation of EntityManagerInterface or OpenClassrooms\UseCase\Application\Services\Transaction\Transaction
- event-sender parameter MUST be an implementation of EventDispatcherInterface or OpenClassrooms\UseCase\Application\Services\Event\EventSender
- event-factory parameter MUST be an implementation of OpenClassrooms\UseCase\Application\Services\Event\EventFactory

