-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http-factory updates and cs fixes (#72)
- Loading branch information
1 parent
0ced97b
commit 3a81f97
Showing
33 changed files
with
252 additions
and
122 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
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\RequestFactoryInterface; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
final class RequestFactory implements RequestFactoryInterface | ||
{ | ||
use RequestFactoryTrait; | ||
use ResponseFactoryTrait; | ||
use ServerResponseFactoryTrait; | ||
use StreamFactoryTrait; | ||
use UploadedFileFactoryTrait; | ||
use UriFactoryTrait; | ||
} |
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 |
---|---|---|
|
@@ -5,23 +5,13 @@ | |
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\UriFactoryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\UriInterface; | ||
use SonsOfPHP\Component\HttpMessage\Request; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class RequestFactory implements RequestFactoryInterface | ||
final class RequestFactory implements RequestFactoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createRequest(string $method, $uri): RequestInterface | ||
{ | ||
return new Request($method, $uri); | ||
} | ||
use RequestFactoryTrait; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/SonsOfPHP/Component/HttpFactory/RequestFactoryTrait.php
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
use SonsOfPHP\Component\HttpMessage\Request; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
trait RequestFactoryTrait | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createRequest(string $method, $uri): RequestInterface | ||
{ | ||
return new Request($method, $uri); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,21 +5,13 @@ | |
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use SonsOfPHP\Component\HttpMessage\Response; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class ResponseFactory implements ResponseFactoryInterface | ||
final class ResponseFactory implements ResponseFactoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface | ||
{ | ||
return (new Response())->withStatus($code, $reasonPhrase); | ||
} | ||
use ResponseFactoryTrait; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/SonsOfPHP/Component/HttpFactory/ResponseFactoryTrait.php
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use SonsOfPHP\Component\HttpMessage\Response; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
trait ResponseFactoryTrait | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface | ||
{ | ||
return (new Response())->withStatus($code, $reasonPhrase); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,23 +5,13 @@ | |
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\ServerRequestFactoryInterface; | ||
use Psr\Http\Message\UriFactoryInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Message\UriInterface; | ||
use SonsOfPHP\Component\HttpMessage\ServerRequest; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class ServerRequestFactory implements ServerRequestFactoryInterface | ||
final class ServerRequestFactory implements ServerRequestFactoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface | ||
{ | ||
return new ServerRequest($method, $uri, $serverParams); | ||
} | ||
use ServerRequestFactoryTrait; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/SonsOfPHP/Component/HttpFactory/ServerRequestFactoryTrait.php
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use SonsOfPHP\Component\HttpMessage\ServerRequest; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
trait ServerRequestFactoryTrait | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface | ||
{ | ||
return new ServerRequest($method, $uri, $serverParams); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,47 +5,13 @@ | |
namespace SonsOfPHP\Component\HttpFactory; | ||
|
||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
use SonsOfPHP\Component\HttpMessage\Stream; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class StreamFactory implements StreamFactoryInterface | ||
final class StreamFactory implements StreamFactoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createStream(string $content = ''): StreamInterface | ||
{ | ||
$resource = fopen('php://temp', 'r+'); | ||
fwrite($resource, $content); | ||
fseek($resource, 0); | ||
|
||
return new Stream($resource); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface | ||
{ | ||
// #todo Error Handling, filename might be invalid or mode may be invalid | ||
|
||
return new Stream(fopen($filename, $mode)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createStreamFromResource($resource): StreamInterface | ||
{ | ||
if (!is_resource($resource)) { | ||
throw new \InvalidArgumentException('resource is invalid'); | ||
} | ||
|
||
return new Stream($resource); | ||
} | ||
use StreamFactoryTrait; | ||
} |
Oops, something went wrong.