-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Http-Factory #27
Http-Factory #27
Conversation
I'm in favour of supporting PSR-17 |
I pushed my last commits.
Don't know how we should handle UploadedFile::createFromGlobals since the PSR doesn't handle this case we are using right now - maybe we should add a middleware for this? Note: I just renamed using a more appropriate name 😉 |
Rebased to current master / fixed tests |
This is great work, but I'm not prepared to put it in until PSR-17 is ratified and published in the Let's keep this around as a WIP until then. |
Maybe starting a discussion but, is it a idea to separate the both? So Slim-Http, Slim-HttpFactory ? |
After thinking about this I'm also in favor of creating a dedicated factory repository. |
Updated to psr/http-factory 1.0.0. |
@akrabat should we create an extra package to keep dependencies clean? |
Maybe we make Slim\Http a PHP 7+ library? |
This needs rebasing to pick up the changes that make Slim-Http PHP 7+ |
…obals as @internal to UriFactory, update http-factory-tests to master, fix cs
Rebased 👍 |
I'm not in favour of splitting this to a separate package. It's all directly related, i.e. you can't use the factories without the messages. |
Also, can we not make a single class for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general as I've commented, I feel that Factory classes are injectable dependencies, not inline newables. We should follow that method IMO.
src/Factory/RequestFactory.php
Outdated
public function createRequest(string $method, $uri): RequestInterface | ||
{ | ||
if (is_string($uri)) { | ||
$uri = (new UriFactory())->createUri($uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not comfortable with this. A Factory class is an injectable dependency, not a newable class. Should this not be injected via a constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree, so one could inject some other factory and must not live with ours.
src/Factory/RequestFactory.php
Outdated
throw new \InvalidArgumentException('URI must either be string or instance of ' . UriInterface::class); | ||
} | ||
|
||
$body = (new StreamFactory())->createStream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again as with UriFactory
.
src/Factory/ServerRequestFactory.php
Outdated
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface | ||
{ | ||
if (is_string($uri)) { | ||
$uri = (new UriFactory())->createUri($uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, an injectable dependency IMO.
src/Factory/ServerRequestFactory.php
Outdated
throw new \InvalidArgumentException('URI must either be string or instance of ' . UriInterface::class); | ||
} | ||
|
||
$body = (new StreamFactory())->createStream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, an injectable dependency IMO.
src/Factory/UriFactory.php
Outdated
throw new \InvalidArgumentException('URI cannot be parsed'); | ||
} | ||
|
||
$scheme = isset($parts['scheme']) ? $parts['scheme'] : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're using PHP 7, could we do something like:
$scheme = $parts['scheme'] ?? '';
Should we have a |
…ct, using null coalescing operator for UriFactory
Now we can inject a StreamFactoryInterface and UriFactoryInterface in both RequestFactories defaulting to null and so to our factories. |
This needs to be against Slim-Psr7 now. slimphp/Slim-Psr7#14 tracks it. |
I just tried to implement the PSR-17 interfaces for Slim-Http addressing #1. I copied some of the existing static methods, such as Request::createFromGlobals(). Maybe we could even call them inside the factories - else not we should remove them.
This is still not done as the classes needs some tests and there still is a todo in the ServerRequestFactory.
I just wanted to leave this here to get a review before I waste additional hours, and to start a discussion wheter we should implement them here or in an additional package.