-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from lion-packages/new
Refactoring fetch helper
- Loading branch information
Showing
17 changed files
with
354 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lion\Bundle\Helpers\Http; | ||
|
||
/** | ||
* Defines parameters for consuming HTTP requests with GuzzleHttp | ||
* | ||
* @property string $httpMethod [HTTP protocol] | ||
* @property string $uri [URL to make the request] | ||
* @property array<string, mixed> $options [Options to send through the request, | ||
* such as headers or parameters] | ||
* @property FetchConfiguration|null $fetchConfiguration [Defines the | ||
* configuration data for making an HTTP request] | ||
* | ||
* @package Lion\Bundle\Helpers\Http | ||
*/ | ||
class Fetch | ||
{ | ||
/** | ||
* @var FetchConfiguration|null $fetchConfiguration [Defines the | ||
* configuration data for making an HTTP request] | ||
*/ | ||
private ?FetchConfiguration $fetchConfiguration = null; | ||
|
||
/** | ||
* Class Constructor | ||
* | ||
* @param string $httpMethod [HTTP protocol] | ||
* @param string $uri [URL to make the request] | ||
* @param array<string, mixed> $options [Options to send through the request, such as | ||
* headers or parameters] | ||
*/ | ||
public function __construct( | ||
private readonly string $httpMethod, | ||
private readonly string $uri, | ||
private readonly array $options = [] | ||
) {} | ||
|
||
/** | ||
* Returns an HTTP configuration object | ||
* | ||
* @return FetchConfiguration|null | ||
* | ||
* @internal | ||
*/ | ||
public function getFetchConfiguration(): ?FetchConfiguration | ||
{ | ||
return $this->fetchConfiguration; | ||
} | ||
|
||
/** | ||
* Adds an HTTP configuration object | ||
* | ||
* @param FetchConfiguration $fetchConfiguration [Defines the configuration | ||
* data for making an HTTP request] | ||
* | ||
* @return Fetch | ||
*/ | ||
public function setFetchConfiguration(FetchConfiguration $fetchConfiguration): Fetch | ||
{ | ||
$this->fetchConfiguration = $fetchConfiguration; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns the HTTP method of the HTTP request | ||
* | ||
* @return string | ||
* | ||
* @internal | ||
*/ | ||
public function getHttpMethod(): string | ||
{ | ||
return $this->httpMethod; | ||
} | ||
|
||
/** | ||
* Returns the URI of the HTTP request | ||
* | ||
* @return string | ||
* | ||
* @internal | ||
*/ | ||
public function getUri(): string | ||
{ | ||
return $this->uri; | ||
} | ||
|
||
/** | ||
* Returns the data from the HTTP request | ||
* | ||
* @return array<string, mixed> | ||
* | ||
* @internal | ||
*/ | ||
public function getOptions(): array | ||
{ | ||
return $this->options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lion\Bundle\Helpers\Http; | ||
|
||
/** | ||
* Defines the configuration data for making an HTTP request | ||
* | ||
* @property array<string, string> $configuration [Configuration data] | ||
* | ||
* @package Lion\Bundle\Helpers\Http | ||
*/ | ||
class FetchConfiguration | ||
{ | ||
/** | ||
* Class Constructor | ||
* | ||
* @param array<string, string> $configuration [Configuration data] | ||
*/ | ||
public function __construct( | ||
private readonly array $configuration = [] | ||
) {} | ||
|
||
/** | ||
* Returns configuration data | ||
* | ||
* @return array<string, string> | ||
* | ||
* @internal | ||
*/ | ||
public function getConfiguration(): array | ||
{ | ||
return $this->configuration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.