Download the PHP package mezon/service without Composer
On this page you can find all versions of the php package mezon/service. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mezon/service
More information about mezon/service
Files in mezon/service
Package service
Short Description Small service script
License MIT
Homepage https://github.com/alexdodonov/mezon-service
Informations about the package service
Set of classes for creating microservices
Installation
Just type
First step
This is our first service.
Here:
- \Mezon\Service\ServiceBase - base class for simple services
- \Mezon\Service\ServiceBaseLogicInterface - class must implement this interface to provide actions in format 'action
' - \Mezon\Service\Service::start(TodoService::class) - launching our service
Then you can access your first endpoint in a way like this:
Here is 'ping' is part afer 'action' in the 'actionPing'.
You can create longer endpoints:
And it will be available via this URL:
Introducing logic
In the concept of Mezon framework service class is only a container for logic, model, transport, security providerrs and so on.
So we may want to fetch all logic to the separate class. Then we shall do it in this way:
And then we shall modify service class like this:
But as you see - we have empty service class with only base functionality. So we can completely remove it and change our code:
Multyple logic classes
But you can split your functionality into several classes like in the next example:
Here you just pass several classes when creating service.
Complex routing
You can create more complex routes. To do this you have to setup them in the routes.json config of your service. The content of this file must looks like this:
And we need logic class for this route:
In this example the method userHeadComment handles routing processing. And this method receives array with routes parameters. Something like that:
But you can also store all route configs in PHP files like this:
Authentication
It is quite obvious that not all your endpoints will be public. Some of them should check credentials.
First of all you should understand that framework knows nothing about your registry of users and their permissions and roles. So you have to provide information about that.
Do it by implementing security provider like inthe listing below:
And our code will look like this:
And routes must be described like this:
Custom fields
You can extend your models with fields wich configuration will be defined in the client's code. For example you have entity 'user' with some custom fields. But you don't know what custom fields it will have. You don't know will it have field 'skype', or field 'notes', or field 'gender' etc. List of these fields may vary from project to project.
To work with such fields you can use \Mezon\Service\CustomFieldsModel
Table structure
tba
Methods reference
tba
All versions of service with dependencies
mezon/custom-client Version 1.0.*
mezon/dns-client Version 1.0.*
mezon/fields-set Version 1.0.*
mezon/functional Version 1.1.*
mezon/http-request-params Version 1.0.*
mezon/infrastructure-layer Version >=1.2.6 <1.3.0
mezon/request Version >=1.0.6 <1.1.0
mezon/rest-exception Version 1.0.*
mezon/router Version 1.5.*
mezon/service-logic Version 1.3.*
mezon/service-transport Version 1.6.*