Services
File structure services for the application is shown below:
|-- app/
|-- Services/ # Services
|-- My/ # Services to work with XML, HHTP and others...
|-- MyService.php # The base class for adding services
`-- Zf2Service.php # Class to add `Zend` services
Silex is not only a framework, but also container service. It achieves this by extending Pimple which provides a very simple service container.
The application contains different types of services:
- Embedded services, are supplied Silex framework
- External services, you can set by yourself example by Symfony2 components
- Custom services, you can add your own in your application
- Zend Framework2 services, this additional possibilities of the known framework, that you can add to your application
Embedded services
Embedded services are delivered with Silex framework.
It services such as: request, routes, controllers, dispatcher, resolver, kernel, request_context, exception_handler, logger etc.
More details can be found here
External services
External services can be set for example with the help of the components Symfony2 vendor/symfony/symfony/src/Component/.
This is done using Composer. Required set
the components need to specify in the file composer.json. For example, to install
Symfony2 all components, Monolog, Swiftmailer, Doctrine(DBAL) and
Doctrine(ORM).
We need to make such record:
{
"require": {
...
"symfony/symfony": "^2.7",
"monolog/monolog": "^1.14",
"swiftmailer/swiftmailer": "^5.4",
"doctrine/dbal": "^2.5",
"doctrine/orm": "^2.5",
...
},
...
}
Custom services
Custom services are located here app/Services/My/. They set using the class
MyService app/Services/MyService.php
The application includes the following services:
- Working with arrays (
ArrayBox.php) - Working with XML (
CrXml.php) - Working with HTTP (
Http.php) - Working with params (
ParamBox.php) - Working with strings (
String.php) - Common functions (
System.php) - Working with Markdown (
app/Services/My/markdown/)
Zend Framework2 services
Zend Framework2 services are located here vendor/zendframework/.
They can be installed with the help of Composer.
The required set of components need to specify in the file composer.json.
For example, to install Zend-Json, Zend-Xml and Zend-Filter.
We need to make such record:
{
"require": {
...
"zendframework/zend-json": "2.*",
"zendframework/zendxml": "^1.0",
"zendframework/zend-filter": "2.*"
},
...
}
In our application Zend Framework2 services installed using
class Zf2Service app/Services/Zf2Service.php.