@@ -13,7 +13,7 @@ A library for creating SDKs in PHP with support for:
13
13
- Event listeners;
14
14
- ...and more.
15
15
16
- All methods are public for full end user hackability 🔥.
16
+ All methods are public for full hackability 🔥.
17
17
18
18
## Requirements
19
19
@@ -144,7 +144,7 @@ class YourApi extends Api
144
144
145
145
By default, this method will return a ` string ` as it will be the response of the request as is.
146
146
If you want to change how the response is handled in all requests (for example, decode a JSON string into an array),
147
- check the [ ` addResponseContentsHandler ` ] ( #addresponsecontentshandler ) method in the [ Event Listeners] ( #event-listeners ) section.
147
+ check the [ ` addResponseContentsListener ` ] ( #addresponsecontentslistener ) method in the [ Event Listeners] ( #event-listeners ) section.
148
148
149
149
#### ` buildPath `
150
150
@@ -472,7 +472,7 @@ The `addResponseContentsListener` method is used to manipulate the response that
472
472
This event listener will be applied to every API request.
473
473
474
474
``` php
475
- $this->addResponseContentsListener(callable $handler , int $priority = 0): self;
475
+ $this->addResponseContentsListener(callable $listener , int $priority = 0): self;
476
476
```
477
477
478
478
For example, if the API responses are JSON strings, you can use this event listener to decode them into arrays:
@@ -527,7 +527,7 @@ Event listeners are then executed from the highest priority to the lowest:
527
527
528
528
``` php
529
529
use ProgrammatorDev\Api\Api;
530
- use ProgrammatorDev\Api\Event\PostRequestEvent ;
530
+ use ProgrammatorDev\Api\Event\ResponseContentsEvent ;
531
531
532
532
class YourApi extends Api
533
533
{
@@ -538,13 +538,13 @@ class YourApi extends Api
538
538
539
539
// executed last (lower priority)
540
540
$this->addResponseContentsListener(
541
- listener: function(PostRequestEvent $event) { ... },
541
+ listener: function(ResponseContentsEvent $event) { ... },
542
542
priority: 0
543
543
);
544
544
545
545
// executed first (higher priority)
546
546
$this->addResponseContentsListener(
547
- listener: function(PostRequestEvent $event) { ... },
547
+ listener: function(ResponseContentsEvent $event) { ... },
548
548
priority: 10
549
549
);
550
550
}
@@ -558,21 +558,21 @@ For that, you can use the `stopPropagation()` method:
558
558
559
559
``` php
560
560
use ProgrammatorDev\Api\Api;
561
- use ProgrammatorDev\Api\Event\PostRequestEvent ;
561
+ use ProgrammatorDev\Api\Event\ResponseContentsEvent ;
562
562
563
563
class YourApi extends Api
564
564
{
565
565
public function __construct()
566
566
{
567
- $this->addResponseContentsListener(function(PostRequestEvent $event) {
567
+ $this->addResponseContentsListener(function(ResponseContentsEvent $event) {
568
568
// stop propagation so future listeners of this event will not be called
569
569
$event->stopPropagation();
570
570
});
571
571
572
572
// this listener will not be called
573
- $this->addResponseContentsListener(function(PostRequestEvent $event) {
573
+ $this->addResponseContentsListener(function(ResponseContentsEvent $event) {
574
574
// ...
575
- });
575
+ });
576
576
}
577
577
}
578
578
```
@@ -849,11 +849,11 @@ class YourApi extends Api
849
849
{
850
850
parent::__construct();
851
851
852
- $this->configureOptions($options);
852
+ $this->options = $this-> configureOptions($options);
853
853
$this->configureApi();
854
854
}
855
855
856
- private function configureOptions(array $options): void
856
+ private function configureOptions(array $options): array
857
857
{
858
858
// set defaults values, if none were provided
859
859
$this->optionsResolver->setDefault('timezone', 'UTC');
@@ -867,8 +867,8 @@ class YourApi extends Api
867
867
$this->optionsResolver->setAllowedValues('timezone', \DateTimeZone::listIdentifiers());
868
868
$this->optionsResolver->setAllowedValues('language', ['en', 'pt']);
869
869
870
- // resolve and set to options property
871
- $this->options = $this->optionsResolver->resolve($options);
870
+ // return resolved options
871
+ return $this->optionsResolver->resolve($options);
872
872
}
873
873
874
874
private function configureApi(): void
@@ -906,7 +906,12 @@ $api = new YourApi([
906
906
$posts = $api->getPosts();
907
907
```
908
908
909
- For all available methods, check the official page documentation [ here] ( https://symfony.com/doc/current/components/options_resolver.html ) .
909
+ For all available methods, check the official page [ documentation] ( https://symfony.com/doc/current/components/options_resolver.html ) .
910
+
911
+ ## Libraries using PHP API SDK
912
+
913
+ - [ programmatordev/openweathermap-php-api] ( https://github.com/programmatordev/openweathermap-php-api )
914
+ - [ programmatordev/sportmonksfootball-php-api] ( https://github.com/programmatordev/sportmonksfootball-php-api )
910
915
911
916
## Contributing
912
917
0 commit comments