andrew-gos / double-gis
Advanced strictly typed library for 2Gis Api
1.1.1
2024-07-16 15:34 UTC
Requires
- php: >=8.2
- ext-ctype: *
- ext-curl: >=8
- andrew-gos/class-builder: >=1.0
- psr/container: ^2.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
Requires (Dev)
- phpunit/phpunit: ^11.2
This package is auto-updated.
Last update: 2025-03-16 17:05:44 UTC
README
Version 1.1.1
Overview
This library is designed to simplify the development of applications which use 2Gis by leveraging strict typing and other improvements.
It allows developers to create highly modular and maintainable bots by defining handlers for various updates in a clear and structured manner.
Contacts
If you received a bug or have an idea, please, write to Gostev71@outlook.com
and type 2Gis Library Bug
or 2Gis Library Idea
in email header.
Features
- Strict Typing: Ensures type safety and better code completion, reducing the likelihood of runtime errors.
- Ease of Use: Designed with simplicity in mind, allowing you to focus on your bot's functionality rather than boilerplate code.
Installation
To install the library, use Composer:
composer require andrew-gos/double-gis
Usage
- Get library instance
<?php use AndrewGos\DoubleGis\DoubleGisFactory; use AndrewGos\DoubleGis\ValueObject\AuthToken; $doubleGis = DoubleGisFactory::getDefault(new AuthToken('123456-7890-abcd-ef12-34567890abcd'));
- Get api
<?php use AndrewGos\DoubleGis\DoubleGisFactory; use AndrewGos\DoubleGis\ValueObject\AuthToken; $doubleGis = DoubleGisFactory::getDefault(new AuthToken('123456-7890-abcd-ef12-34567890abcd')); $api = $doubleGis->getApi();
- Use api
<?php use AndrewGos\DoubleGis\DoubleGisFactory; use AndrewGos\DoubleGis\ValueObject\AuthToken; use AndrewGos\DoubleGis\Request\RegionGetRequest; use AndrewGos\DoubleGis\Entity\Region; $doubleGis = DoubleGisFactory::getDefault(new AuthToken('123456-7890-abcd-ef12-34567890abcd')); $api = $doubleGis->getApi(); $regionResponse = $api->regionGet(new RegionGetRequest('1')); /** @var Region[] $regions */ $regions = $regionResponse->getResult()?->getItems();
- Specify logger for library
<?php use AndrewGos\DoubleGis\DoubleGisFactory; use AndrewGos\DoubleGis\ValueObject\AuthToken; $doubleGis = DoubleGisFactory::getDefault(new AuthToken('123456-7890-abcd-ef12-34567890abcd')); $doubleGis->setLogger(new MyLogger());
Usage as service in Symfony
If you use Symfony, and you want to create DoubleGis object like service, type:
# services.yaml services: andrew-gos.double-gis.token: class: AndrewGos\DoubleGis\ValueObject\AuthToken arguments: $token: '%env(YOUR_TOKEN_ENV_PARAM)%' # Or if you don`t use .env # $token: 'YOUR_TOKEN' AndrewGos\DoubleGis\DoubleGis: factory: ['AndrewGos\DoubleGis\DoubleGisFactory', 'getDefault'] arguments: $token: '@andrew-gos.double-gis.token' # If you want to set custom loggers calls: - setLogger: ['@logger']
Usage in Yii2
If you use Yii2, you can use this library with Yii2 DI:
// IN main.php OR web.php // your config: [ 'container' => [ 'definitions' => [ \AndrewGos\DoubleGis\DoubleGis::class => function () { return \AndrewGos\DoubleGis\DoubleGisFactory::getDefault( new \AndrewGos\DoubleGis\ValueObject\AuthToken('YOUR_TOKEN'); ), }, ], ], ];