Skip to content

Commit

Permalink
wip Foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Jan 19, 2024
1 parent c10bb51 commit 0a01d07
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 96 deletions.
4 changes: 1 addition & 3 deletions src/Foundation/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ public function __construct(Credential $credential = null, \GuzzleHttp\Client $h
*/
public function send(Contracts\Message $message): ResponseInterface
{
assert($message instanceof Message);

return $this
->httpClient
->request($message->httpMethod(), $message->httpUri(), $message->httpOptions());
->request($message->httpMethod(), $message->httpUri(), $message->toHttpOptions());
}
}
2 changes: 1 addition & 1 deletion src/Foundation/Concerns/AsBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
trait AsBody
{
public function httpOptions(): array
public function toHttpOptions(): array
{
return [
RequestOptions::BODY => $this->toPayload(),
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Concerns/AsFormParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
trait AsFormParams
{
public function httpOptions(): array
public function toHttpOptions(): array
{
return [
RequestOptions::FORM_PARAMS => $this->toPayload(),
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Concerns/AsJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
trait AsJson
{
public function httpOptions(): array
public function toHttpOptions(): array
{
return [
RequestOptions::JSON => $this->toPayload(),
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Concerns/AsMultipart.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
trait AsMultipart
{
public function httpOptions(): array
public function toHttpOptions(): array
{
return [
RequestOptions::MULTIPART => $this->toPayload(),
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Concerns/AsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
trait AsQuery
{
public function httpOptions(): array
public function toHttpOptions(): array
{
return [
RequestOptions::QUERY => $this->toPayload(),
Expand Down
10 changes: 7 additions & 3 deletions src/Foundation/Contracts/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@

namespace Guanguans\Notify\Foundation\Contracts;

use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;

interface Message extends \ArrayAccess
{
public function httpMethod(): string;

/**
* @return string|resource|array|object|StreamInterface
* @return string|UriInterface
*/
public function toPayload();
public function httpUri();

public function toHttpOptions(): array;
}
12 changes: 4 additions & 8 deletions src/Foundation/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Guanguans\Notify\Foundation\Traits\HasOptions;
use Guanguans\Notify\Traits\CreateStaticable;
use Psr\Http\Message\UriInterface;
use Psr\Http\Message\StreamInterface;

abstract class Message implements Contracts\Message
{
Expand All @@ -26,15 +26,11 @@ public function __construct(array $options = [])
$this->setOptions($options);
}

abstract public function httpMethod(): string;

/**
* @return string|UriInterface
* @return string|array|object|resource|StreamInterface
*
* @noinspection PhpReturnDocTypeMismatchInspection
*/
abstract public function httpUri();

abstract public function httpOptions(): array;

public function toPayload()
{
return $this->options;
Expand Down
12 changes: 12 additions & 0 deletions src/Foundation/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@
*
* This source file is subject to the MIT license that is bundled.
*/

if (! function_exists('tap')) {
/**
* Call the given Closure with the given value then return the value.
*/
function tap($value, callable $callback)
{
$callback($value);

return $value;
}
}
74 changes: 0 additions & 74 deletions src/Foundation/Traits/CreatesDefaultHttpClient.php

This file was deleted.

4 changes: 1 addition & 3 deletions src/Foundation/Traits/Tappable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ trait Tappable
{
public function tap(callable $callback): self
{
$callback($this);

return $this;
return tap($this, $callback);
}
}

0 comments on commit 0a01d07

Please sign in to comment.