Welcome Guest, Not a member yet? Register   Sign In
Automatically discovered system service called without arguments
#1

(This post was last modified: 03-28-2022, 08:16 AM by mucio. Edit Reason: formatting )

Ohayo!

Being able to extend system services is a tremendously powerful feature that I'd like to use for fun and profit. So I went ahead and wrote this in my Services.php:


PHP Code:
public static function response(?App $config null$getShared true): Response
{
    if ($getShared) {
        return static::getSharedInstance('response');
    }

    return new Response($config);


It appears, however, that the Response class expects a valid Config\App instance in its constructor. Not doing so results in many notices that shouldn't be ignored. When the service isn't overridden, the expected arguments are passed to BaseService::response and it works fine. But upon overriding the service (either from the app namespace or a custom one), the corresponding method is called without any arguments.

I'm using the signature of the method as documented in system/Config/BaseService. All of this is really just to modify the send method so I can have my own emitting code.
Reply
#2

I got it!

In order to override a service, you first have to copy the relevant method from system/Config/Services.php. So in this case it would be:
PHP Code:
    public static function response(?App $config nullbool $getShared true)
    {
        if ($getShared) {
            return static::getSharedInstance('response'$config);
        }

        $config $config ?? config('App');

        return new Response($config);
    

The emitting code does work fine though, I won't really need to re-implement it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB