signnow / rest-entity-manager
Library gives you ability to communicate to REST API within DTO objects
Installs: 65 569
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 2
Open Issues: 2
Requires
- php: >=7.1
- ext-ctype: *
- ext-json: *
- doctrine/annotations: ~1.6
- guzzlehttp/guzzle: ^7.0.0
- jms/serializer: ^3.12.0
Requires (Dev)
- phpunit/phpunit: ^7
This package is not auto-updated.
Last update: 2024-12-03 20:14:07 UTC
README
This project helps to communicate with REST API using DTO objects
Requirements
PHP 7.1 or newer
Installation
The library can be installed using Composer.
composer require signnow/rest-entity-manager
Usage
use Doctrine\Common\Annotations\AnnotationRegistry; use JMS\Serializer\Annotation as Serializer; use SignNow\Rest\EntityManager\Annotation\HttpEntity; use SignNow\Rest\Entity\Entity; use SignNow\Rest\Factories\ClientFactory; use SignNow\Rest\Factories\EntityManagerFactory; /** * Class User * * @HttpEntity("users/{user}") */ class User extends Entity { /** * @var int * @Serializer\Type("int") */ private $id; /** * @var string * @Serializer\Type("string") */ private $name; /** * @return int */ public function getId(): ?int { return $this->id; } /** * @return string */ public function getName(): string { return $this->name; } } $clientFactory = new ClientFactory(['base_uri' => 'https://api.github.com']); $entityManager = (new EntityManagerFactory($clientFactory))->create(); /** @var User $user */ $user = $entityManager->get(User::class, ['user' => 'codeception']); echo sprintf('Id: %s; Name: %s.', $user->getId(), $user->getName());