Skip to content

Commit de14e96

Browse files
committed
docs: fixes and improvements
1 parent 573237d commit de14e96

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A library for creating SDKs in PHP with support for:
1313
- Event listeners;
1414
- ...and more.
1515

16-
All methods are public for full end user hackability 🔥.
16+
All methods are public for full hackability 🔥.
1717

1818
## Requirements
1919

@@ -527,7 +527,7 @@ Event listeners are then executed from the highest priority to the lowest:
527527

528528
```php
529529
use ProgrammatorDev\Api\Api;
530-
use ProgrammatorDev\Api\Event\PostRequestEvent;
530+
use ProgrammatorDev\Api\Event\ResponseContentsEvent;
531531

532532
class YourApi extends Api
533533
{
@@ -538,13 +538,13 @@ class YourApi extends Api
538538

539539
// executed last (lower priority)
540540
$this->addResponseContentsListener(
541-
listener: function(PostRequestEvent $event) { ... },
541+
listener: function(ResponseContentsEvent $event) { ... },
542542
priority: 0
543543
);
544544

545545
// executed first (higher priority)
546546
$this->addResponseContentsListener(
547-
listener: function(PostRequestEvent $event) { ... },
547+
listener: function(ResponseContentsEvent $event) { ... },
548548
priority: 10
549549
);
550550
}
@@ -558,21 +558,21 @@ For that, you can use the `stopPropagation()` method:
558558

559559
```php
560560
use ProgrammatorDev\Api\Api;
561-
use ProgrammatorDev\Api\Event\PostRequestEvent;
561+
use ProgrammatorDev\Api\Event\ResponseContentsEvent;
562562

563563
class YourApi extends Api
564564
{
565565
public function __construct()
566566
{
567-
$this->addResponseContentsListener(function(PostRequestEvent $event) {
567+
$this->addResponseContentsListener(function(ResponseContentsEvent $event) {
568568
// stop propagation so future listeners of this event will not be called
569569
$event->stopPropagation();
570570
});
571571

572572
// this listener will not be called
573-
$this->addResponseContentsListener(function(PostRequestEvent $event) {
573+
$this->addResponseContentsListener(function(ResponseContentsEvent $event) {
574574
// ...
575-
});
575+
});
576576
}
577577
}
578578
```
@@ -849,11 +849,11 @@ class YourApi extends Api
849849
{
850850
parent::__construct();
851851

852-
$this->configureOptions($options);
852+
$this->options = $this->configureOptions($options);
853853
$this->configureApi();
854854
}
855855

856-
private function configureOptions(array $options): void
856+
private function configureOptions(array $options): array
857857
{
858858
// set defaults values, if none were provided
859859
$this->optionsResolver->setDefault('timezone', 'UTC');
@@ -867,8 +867,8 @@ class YourApi extends Api
867867
$this->optionsResolver->setAllowedValues('timezone', \DateTimeZone::listIdentifiers());
868868
$this->optionsResolver->setAllowedValues('language', ['en', 'pt']);
869869

870-
// resolve and set to options property
871-
$this->options = $this->optionsResolver->resolve($options);
870+
// return resolved options
871+
return $this->optionsResolver->resolve($options);
872872
}
873873

874874
private function configureApi(): void

src/Api.php

+14-8
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,22 @@ public function request(
102102
private function configurePlugins(): void
103103
{
104104
// https://docs.php-http.org/en/latest/plugins/content-type.html
105-
$this->clientBuilder->addPlugin(new ContentTypePlugin(), 40);
105+
$this->clientBuilder->addPlugin(
106+
plugin: new ContentTypePlugin(),
107+
priority: 40
108+
);
106109

107110
// https://docs.php-http.org/en/latest/plugins/content-length.html
108-
$this->clientBuilder->addPlugin(new ContentLengthPlugin(), 32);
111+
$this->clientBuilder->addPlugin(
112+
plugin: new ContentLengthPlugin(),
113+
priority: 32
114+
);
109115

110116
// https://docs.php-http.org/en/latest/message/authentication.html
111117
if ($this->authentication) {
112118
$this->clientBuilder->addPlugin(
113-
new AuthenticationPlugin($this->authentication),
114-
24
119+
plugin: new AuthenticationPlugin($this->authentication),
120+
priority: 24
115121
);
116122
}
117123

@@ -129,23 +135,23 @@ private function configurePlugins(): void
129135
}
130136

131137
$this->clientBuilder->addPlugin(
132-
new CachePlugin(
138+
plugin: new CachePlugin(
133139
$this->cacheBuilder->getPool(),
134140
$this->clientBuilder->getStreamFactory(),
135141
$cacheOptions
136142
),
137-
16
143+
priority: 16
138144
);
139145
}
140146

141147
// https://docs.php-http.org/en/latest/plugins/logger.html
142148
if ($this->loggerBuilder) {
143149
$this->clientBuilder->addPlugin(
144-
new LoggerPlugin(
150+
plugin: new LoggerPlugin(
145151
$this->loggerBuilder->getLogger(),
146152
$this->loggerBuilder->getFormatter()
147153
),
148-
8
154+
priority: 8
149155
);
150156
}
151157
}

0 commit comments

Comments
 (0)