1

在 Laravel 的illuminate/support/Facades/Facade.php文件中有如下方法:

/**
 * Get the registered name of the component.
 *
 * @return string
 *
 * @throws \RuntimeException
 */
protected static function getFacadeAccessor()
{
    throw new RuntimeException('Facade does not implement getFacadeAccessor method.');
}

是否有这样做的潜力,而不仅仅是定义一个抽象方法,如下所示?

abstract protected static function getFacadeAccessor();

为什么他们可能想重新发明轮子?

4

1 回答 1

0

I found the following reason here:

This method is designed to be overridden when extending the Facade class to return a string, the key which the service represented by the facade is bound within the container. By default, it throws an exception if not implemented. This gives a more informative message to those creating custom facades than if the framework were to instead use an abstract method.

于 2018-11-23T19:36:56.553 回答