π·πΊ Π ΡΡΡΠΊΠΈΠΌ Π³ΡΠ°ΠΆΠ΄Π°Π½Π°ΠΌ
ΠΡ, ΡΡΠ°ΡΡΠ½ΠΈΠΊΠΈ Laminas, ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ ΠΈ ΠΆΠΈΠ²Π΅ΠΌ Π² ΡΠ°Π·Π½ΡΡ ΡΡΡΠ°Π½Π°Ρ . Π£ ΠΌΠ½ΠΎΠ³ΠΈΡ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΠΊΠΈ ΠΈ ΠΊΠΎΠ»Π»Π΅Π³ΠΈ ΠΊΠ°ΠΊ Π² Π ΠΎΡΡΠΈΠΈ, ΡΠ°ΠΊ ΠΈ Π² Π£ΠΊΡΠ°ΠΈΠ½Π΅. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ Π² Π ΠΎΡΡΠΈΠΈ. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΠΆΠΈΠ²ΡΡ Π² Π ΠΎΡΡΠΈΠΈ. Π£ Π½Π΅ΠΊΠΎΡΠΎΡΡΡ Π±Π°Π±ΡΡΠΊΠΈ ΠΈ Π΄Π΅Π΄ΡΡΠΊΠΈ ΡΡΠ°ΠΆΠ°Π»ΠΈΡΡ Ρ ΡΠ°ΡΠΈΡΡΠ°ΠΌΠΈ Π²ΠΎ ΠΡΠΎΡΠΎΠΉ ΠΌΠΈΡΠΎΠ²ΠΎΠΉ Π²ΠΎΠΉΠ½Π΅. ΠΠ΄Π΅ΡΡ Π½ΠΈΠΊΡΠΎ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ ΡΠ°ΡΠΈΠ·ΠΌ.
Π£ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠ°Ρ ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΡΠ°, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΏΠ°ΡΠ»Π°ΡΡ ΠΈΠ· Π΄ΠΎΠΌΠ° Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΡΠ½ΠΎΠΌ. ΠΠΎΠ΅Π·Π΄ Π·Π°Π΄Π΅ΡΠΆΠ°Π»ΡΡ ΠΈΠ·-Π·Π° Π±ΠΎΠΌΠ±Π΅ΠΆΠΊΠΈ Π½Π° Π΄ΠΎΡΠΎΠ³Π΅ Π²ΠΏΠ΅ΡΠ΅Π΄ΠΈ. Π£ Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΏΡΡΡΡΡΡΡ Π² Π±ΠΎΠΌΠ±ΠΎΡΠ±Π΅ΠΆΠΈΡΠ°Ρ . ΠΡ Ρ ΡΡΠ΅Π²ΠΎΠ³ΠΎΠΉ ΠΆΠ΄Π΅ΠΌ Π²Π΅ΡΡΠΎΡΠΊΠΈ ΠΎΡ Π½ΠΈΡ ΠΏΠΎΡΠ»Π΅ Π²ΠΎΠ·Π΄ΡΡΠ½ΡΡ Π½Π°Π»Π΅ΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π±Π΅ΡΠΏΠΎΡΡΠ΄ΠΎΡΠ½ΠΎ Π½Π°Π½ΠΎΡΡΡ ΡΠ΄Π°ΡΡ ΠΈ ΠΏΠΎΠΏΠ°Π΄Π°ΡΡ ΠΏΠΎ Π±ΠΎΠ»ΡΠ½ΠΈΡΠ°ΠΌ, ΡΠΊΠΎΠ»Π°ΠΌ, Π΄Π΅ΡΡΠΊΠΈΠΌ ΡΠ°Π΄Π°ΠΌ ΠΈ Π΄ΠΎΠΌΠ°ΠΌ. ΠΡ Π½Π΅ Π±Π΅ΡΠ΅ΠΌ ΡΡΠΎ ΠΈΠ· ΠΊΠ°ΠΊΠΈΡ -Π»ΠΈΠ±ΠΎ Π‘ΠΠ. ΠΡ Π½Π°Π±Π»ΡΠ΄Π°Π΅ΠΌ ΡΡΠΎ Π½Π°ΠΏΡΡΠΌΡΡ.
ΠΡ Π΄ΠΎΠ²Π΅ΡΡΠ΅ΡΠ΅ Π½Π°ΠΌ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ, ΡΡΠΎΠ± ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π½Π°ΡΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ, ΠΈ ΠΌΡ ΠΏΡΠΎΡΠΈΠΌ Π²Π°Ρ Π΄ΠΎΠ²Π΅ΡΠΈΡΡΡΡ Π½Π°ΠΌ Π²Π½ΠΎΠ²Ρ. ΠΡ Π½ΡΠΆΠ΄Π°Π΅ΠΌΡΡ Π² ΠΏΠΎΠΌΠΎΡΠΈ. ΠΡΡ ΠΎΠ΄ΠΈΡΠ΅ ΠΈ ΠΏΡΠΎΡΠ΅ΡΡΡΠΉΡΠ΅ ΠΏΡΠΎΡΠΈΠ² ΡΡΠΎΠΉ Π±Π΅ΡΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ Π²ΠΎΠΉΠ½Ρ. ΠΡΡΠ°Π½ΠΎΠ²ΠΈΡΠ΅ ΠΊΡΠΎΠ²ΠΎΠΏΡΠΎΠ»ΠΈΡΠΈΠ΅. Π‘ΠΊΠ°ΠΆΠΈΡΠ΅ "ΠΠ΅Ρ Π²ΠΎΠΉΠ½Π΅!"
πΊπΈ To Citizens of Russia
We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
Meta-module for Laminas combining features from:
in order to provide a cohesive solution for exposing web-based APIs.
Also features database-connected REST resources.
Please see the composer.json file.
Run the following composer
command:
$ composer require laminas-api-tools/api-tools
Alternately, manually add the following to your composer.json
, in the require
section:
"require": {
"laminas-api-tools/api-tools": "^1.3"
}
And then run composer update
to ensure the module is installed.
Finally, add the module name to your project's config/application.config.php
under the modules
key:
return [
/* ... */
'modules' => [
/* ... */
'Laminas\ApiTools',
],
/* ... */
];
laminas-component-installer
If you use laminas-component-installer, that plugin will install api-tools, and all modules it depends on, as a module in your application configuration for you.
If you are using this module along with the admin and/or the welcome screen, this module contains assets that you will need to make web accessible. For that, you have two options:
composer remove laminas-api-tools/api-tools
.)The top-level configuration key for user configuration of this module is
api-tools
.
db-connected
is an array of resources that can be built via the
TableGatewayAbstractFactory and the
DbConnectedResourceAbstractFactory when required
to fulfill the use case of database table-driven resource use cases. The following example
enumerates all of the required and optional configuration necessary to enable this.
Example:
'db-connected' => [
/**
* This is sample configuration for a DB-connected service.
* Each such service requires an adapter, a hydrator, an entity, and a
* collection.
*
* The TableGateway will be called "YourDBConnectedResource\Table" should
* you wish to retrieve it manually later.
*/
'YourDBConnectedResource' => [
'table_service' => 'Optional; if present, this service will be used as the table gateway',
'resource_class' => 'Optional; if present, this class will be used as the db-connected resource',
'table_name' => 'Name of DB table to use',
'identifier_name' => 'Optional; identifier field in table; defaults to table_name_id or id',
'adapter_name' => 'Service Name for DB adapter to use',
'hydrator_name' => 'Service Name for Hydrator to use',
'entity_class' => 'Name of entity class to which to hydrate',
'collection_class' => 'Name of collection class which iterates entities; should be a Paginator extension',
],
],
The following configuration is required to ensure the proper functioning of this module in Laminas Framework applications, and is provided by the module:
namespace Laminas\ApiTools;
use Laminas\Db\Adapter\AdapterAbstractServiceFactory as DbAdapterAbstractServiceFactory;
use Laminas\ServiceManager\Factory\InvokableFactory;
return [
'asset_manager' => [
'resolver_configs' => [
'paths' => [
__DIR__ . '/../asset',
],
],
],
'router' => [
'routes' => [
'api-tools' => [
'type' => 'literal',
'options' => [
'route' => '/api-tools',
],
'may_terminate' => false,
],
],
],
'service_manager' => [
'factories' => [
MvcAuth\UnauthenticatedListener::class => InvokableFactory::class,
MvcAuth\UnauthorizedListener::class => InvokableFactory::class,
],
'abstract_factories' => [
DbAdapterAbstractServiceFactory::class, // so that db-connected works "out-of-the-box"
DbConnectedResourceAbstractFactory::class,
TableGatewayAbstractFactory::class,
],
],
];
This listener is attached to MvcAuthEvent::EVENT_AUTHENTICATION_POST
at priority 100
. The
primary purpose fo this listener is to override the api-tools-mvc-auth
unauthenticated listener in
order to be able to respond with an API-Problem response (vs. a standard HTTP response) on
authentication failure.
This listener is attached to MvcAuthEvent::EVENT_AUTHORIZATION_POST
at priority 100
. The
primary purpose of this listener is to override the api-tools-mvc-auth
unauthorized listener in order
to be able to respond with an API-Problem response (vs a standard HTTP response) on authorization
failure.
This listener is attached to MvcEvent::EVENT_RENDER
at priority 400
. Its purpose is to
conditionally attach Laminas\ApiTools\ApiProblem\RenderErrorListener
when an MvcEvent
's result is a
HalJsonModel
or JsonModel
, ensuring api-tools-api-problem
can render a response in situations where
a rendering error occurs.
This factory uses the requested name in addition to the api-tools.db-connected
configuration
in order to produce Laminas\ApiTools\DbConnectedResource
based resources.
This factory uses the requested name in addition to the api-tools.db-connected
configuration
in order to produce correctly configured Laminas\Db\TableGateway\TableGateway
instances. These
instances of TableGateway
s are configured to use the proper HydratingResultSet
and produce
the configured entities with each row returned when iterated.
This instance serves as the base class for database connected REST resource classes. This
implementation is an extension of Laminas\ApiTools\Rest\AbstractResourceListener
and can be routed to by
Laminas API Tools as a RESTful resource.