Container 的背后
打赏作者

nofriend

就差一个仓库设计模式了。

paopaolong 回复 nofriend

观察者模式->工厂模式->IOC容器

pluxwill

这个视屏怎么挂了

JellyBool 回复 pluxwill

我这显示的是没有问题的,你用 chrome 的么?

pluxwill 回复 JellyBool

是的,其他视屏都正常,只有这个0:00

JellyBool 回复 pluxwill

这就尴尬了,我这里现在都还是好的。

pluxwill 回复 JellyBool

现在在公司里就好了,可能是网络导致的,谢谢啦

JellyBool 回复 pluxwill

OK,解决了就行。估计得七牛的 cdn 时不时抽下风

pluxwill 回复 JellyBool

这个网站好棒,加油喔!

JellyBool 回复 pluxwill

哈哈哈,阔以阔以,感谢支持!

yuesir

app(‘Illuminate\Hashing\BcryptHasher’) ,自己用 XDebug 查看这个其实不能够在 aliases 中找到(aliases 中 hash 对应的类名是 Illuminate\Contracts\Hashing\Hasher ),最终是通过 类的反射来实现的。

foxriver123 回复 yuesir

\Illuminate\Hashing\HashManager::class

wangyi

思路已经完全跟不上了- -

ksr

所以,app('Illuminate\Hashing\BcryptHasher')new 了一个实例,而 app('hasher') 只是从 IOC 容器中取出 已存在 的实例?

foxriver123 回复 ksr

准确的说app(‘hasher’)第一次也是new.如果后面再次用到才是从容器的singleton数组里面取。

Smile雨后21
// 这个才会在  public function registerCoreContainerAliases() 里找到别名 hash
dd(app('Illuminate\Contracts\Hashing\Hasher')->make('password'));

// 这个还是返回  Illuminate\Hashing\BcryptHasher
dd(app('Illuminate\Hashing\BcryptHasher')->make('password'));

印度油神 回复 Smile雨后21

正解.我也是看了之后通过xdebug测试出来的.

foxriver123 回复 Smile雨后21

app(‘Illuminate\Contracts\Hashing\Hasher’)
容器的aliases数组有对应关系,所以getAlias方法 返回hash。通过getConcrete方法拿到容器bingdings数组里面对应的闭包,然后通过容器的build方法执行闭包取得实例。
app(‘Illuminate\Hashing\BcryptHasher’)
容器的aliases数组找不到对应key,所以getAlias方法原样返回Illuminate\Hashing\BcryptHasher。然后通过getConcrete方法再次原样返回Illuminate\Hashing\BcryptHasher,然后通过容器的build方法利用php反射解析取得实例

foxriver123

太可惜了,教主。你就这样离我们而去! 哎。

BigXia 回复 foxriver123

啊?人没了么,你这有歧义呀

foxriver123

@jelly