-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Fix setting url to http.request #43
Conversation
I believe this works in your case in tests, but it breaks behavior of ConsoleExtension for anyone who overrides Request for standard usage. Imho what should be done here is to override RequestFactory by ConsoleExtension instead so you are still able to override Request |
I tried what i think is standard usage (is it?). Creating class <?php
namespace App;
use Nette\Http\Request;
use Nette\Http\UrlScript;
class CustomRequest extends Request
{
public function __construct()
{
parent::__construct(new UrlScript('http://whatever'));
}
} registering it as http.request services:
http.request: App\CustomRequest in cli command i tried to call $this->container->getByType(IRequest::class); which fails with error
because of this inside DI container public function createServiceHttp__request(): App\CustomRequest
{
return new Nette\Http\Request(new Nette\Http\UrlScript('http://localhost'));
} I think with console.url enabled is imposible to override http.request anyway. I will think about it and figure out better solution.. and fix tests of course. |
@@ -153,7 +153,9 @@ public function beforeCompile(): void | |||
if ($config->url !== null && $builder->hasDefinition('http.request')) { | |||
/** @var ServiceDefinition $httpDef */ | |||
$httpDef = $builder->getDefinition('http.request'); | |||
$httpDef->setFactory(Request::class, [new Statement(UrlScript::class, [$config->url])]); |
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.
What about this.
$httpDef->setFactory($httpDef->getFactory(), [new Statement(UrlScript::class, [$config->url])]);
You must preserver arguments order/position.
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 am worried it would still break due to possibly different 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.
I was thinking about that too, but i didnt like the idea of preserving argument positions. Original idea was cleaner for me.
What about now? I created console requestFactory, which is used only when default requestFactory is used. Exception is thown on custom requestFactory implementation and console.url set. Console.url in combination with custom requestFactory is in my opinion useless, url should be set by custom requestFactory itself. |
Looks way better. I will give it some final touches later today before release. Thanks |
Hey @jfilla, I want to assure you we'll handle this issue. We didn't have a time yet. |
Thank you @jfilla ❤️ |
Service
http.request
can be any class implementing interface IRequest. If you have custom IRequest implementation andconsole.url
config is set, DI container cache looks like this:, which causes type error. It should look like this