Skip to content
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

Factories #1

Closed
geggleto opened this issue Dec 24, 2015 · 14 comments
Closed

Factories #1

geggleto opened this issue Dec 24, 2015 · 14 comments

Comments

@geggleto
Copy link
Member

I would love to see proper Factories.

Will PR @akrabat ;)

@codeguy
Copy link
Member

codeguy commented Dec 24, 2015

We can probably deprecate/remove the entire "environment" concept in favor of these new factory methods.

@codeguy
Copy link
Member

codeguy commented Dec 24, 2015

Can you provide a code snippet here that demonstrates what you want? I'm thinking something like \Slim\Http\Request::createFromGlobals($_SERVER);. Seem fine?

@geggleto
Copy link
Member Author

I was thinking....

class RequestFactory {
   public function __construct(BodyFactory $bodyFactory);

   // returns \Slim\Http\Request
   public function build($attributes, $headers);
}

$request = $requestFactory->build($_SERVER, $headers);

The reason behind it, so we have more control of the Body Object and how it's created. The Request shouldn't know or care how the Body is created, or URI object.

@codeguy
Copy link
Member

codeguy commented Dec 24, 2015

👍 Will get started today.

@codeguy
Copy link
Member

codeguy commented Dec 24, 2015

@geggleto Couldn't the same be said for headers and uri?

@codeguy
Copy link
Member

codeguy commented Dec 24, 2015

I'm not entirely sold on the need for separate factory classes... a class can know how to make itself, so why not Body::createFromText|Stream(), Uri::createFromGlobals(), Header::createFromGlobals(), and Request::createFromGlobals()? We can always supply a default body (from raw text or a stream resource), and it can easily be overridden with $request->withBody().

@codeguy
Copy link
Member

codeguy commented Dec 24, 2015

I'm just worried about over-engineering for engineering's sake.

@geggleto
Copy link
Member Author

For me it's abut reducing the class complexity. Factories are clean and easy to read. For someonek like me who does read the slim source it is nice to have readable code.

I would say choose whatever is readable and testable. Decoupling away from the use of globals inside methods and surfacing them to the signatures is the ultimate goal.

/cc @codeguy

@codeguy
Copy link
Member

codeguy commented Dec 25, 2015

Cool. I've started toying with an abstract factory. I've added the FactoryInterface interface and the FactoryDefault implementation. This will let us recycle the same creation logic in our tests and in the actual codebase. PHP 7 syntax for now while I'm playing around with some ideas.

@geggleto
Copy link
Member Author

PHP 7 <3. I like the abstract factory pattern and this is looking quite good.

@geggleto
Copy link
Member Author

https://gist.github.com/geggleto/37539ebbd679f28995b4

Been toying around with moving the construction logic.

I really want to rename the Environment class as its a container around _SERVER.

@akrabat @codeguy

@geggleto
Copy link
Member Author

I think we should rename the Request class, as in PSR 7 there are differences between ServerRequest and just Request. Slim internally uses ServerRequestInterface, so it would probably be best to reflect that.

@geggleto
Copy link
Member Author

Dropping this in here,

https://github.com/geggleto/slim-http

Lot's of refactoring, and renaming.

@akrabat
Copy link
Member

akrabat commented Dec 11, 2016

If we support factories, then https://github.com/http-interop/http-factory is the way to do it.

danopz added a commit to danopz/Slim-Http that referenced this issue Jun 20, 2017
@danopz danopz mentioned this issue Jun 20, 2017
4 tasks
@akrabat akrabat closed this as completed Jun 27, 2017
danopz added a commit to danopz/Slim-Http that referenced this issue Jun 29, 2017
danopz added a commit to danopz/Slim-Http that referenced this issue Oct 8, 2017
danopz added a commit to danopz/Slim-Http that referenced this issue Feb 5, 2018
danopz added a commit to danopz/Slim-Http that referenced this issue Jul 22, 2018
danopz added a commit to danopz/Slim-Http that referenced this issue Sep 16, 2018
akrabat pushed a commit that referenced this issue Oct 30, 2018
Test against psr7-integration-tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants