laravel application 容器app
vendor/laravel/framework/src/Illuminate/Foundation/Application.php
Application是laravel的核心容器,几乎处理所有东西的时候都需要用到,主要功能有:
1. app首先继承了container,作为一个容器类存在
2。注册了laravel运行过程的需要的基础类进容器,并且生成了运行需要的实例。承担了初始化功能。
这里需要额外说一下,app里面说的所谓注册,不是指绑定,应该是直接直接实例化了,并注入到容器。但是,针对provider,实例化了provider,并运行了,并不会生成实际的类,而是将类绑定。
3. 额外提供了更方便的一些功能,主要是与程序的环境相关的,比如:provider处理运行是在这里,config app里面的配置就在本类读取并处理。
具体功能如下:
1. container的功能就不说了,前面微博已经描述这个了。
2. 注册程序运行中需要的最基础的类
在 __construct:构造函数中处理:
if ($basePath) {
$this->setBasePath($basePath);
}
$this->registerBaseBindings();
$this->registerBaseServiceProviders();
$this->registerCoreContainerAliases();
setBasePath 基本路径添加进容器实例,这也是这绝大多数框架里面都需要做都事情,防止出现相对绝对等各种路径使用时候的混乱,总共添加了这么多:
$this->instance('path', $this->path());
$this->instance('path.base', $this->basePath());
$this->instance('path.lang', $this->langPath());
$this->instance('path.config', $this->configPath());
$this->instance('path.public', $this->publicPath());
$this->instance('path.storage', $this->storagePath());
$this->instance('path.database', $this->databasePath());
$this->instance('path.resources', $this->resourcePath());
$this->instance('path.bootstrap', $this->bootstrapPath());
registerBaseBindings
注册基本绑定,添加app本身进容器实例,然后,PackageManifest添加进容器实例,本功能可以处理一些默认的provider和aliases,本功能后续展开描述。
registerBaseServiceProviders
注册基本的Providers,包括event/log/router 这三部分
event:vendor/laravel/framework/src/Illuminate/Events/EventServiceProvider.php
log:vendor/laravel/framework/src/Illuminate/Log/LogServiceProvider.php
router:vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php
router的provider跟别的不一样,提供了多个相关绑定:router url redirect Psr\Http\Message\ServerRequestInterface Psr\Http\Message\ResponseInterface Illuminate\Contracts\Routing\ResponseFactory Illuminate\Routing\Contracts\ControllerDispatcher
registerCoreContainerAliases 注册一些核心的别名,包括:
'app' => [\Illuminate\Foundation\Application::class, \Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class],
'auth' => [\Illuminate\Auth\AuthManager::class, \Illuminate\Contracts\Auth\Factory::class],
'auth.driver' => [\Illuminate\Contracts\Auth\Guard::class],
'blade.compiler' => [\Illuminate\View\Compilers\BladeCompiler::class],
'cache' => [\Illuminate\Cache\CacheManager::class, \Illuminate\Contracts\Cache\Factory::class],
'cache.store' => [\Illuminate\Cache\Repository::class, \Illuminate\Contracts\Cache\Repository::class],
'config' => [\Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class],
'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class],
'db' => [\Illuminate\Database\DatabaseManager::class],
'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
'events' => [\Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class],
'files' => [\Illuminate\Filesystem\Filesystem::class],
'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],
'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class],
'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class],
'hash' => [\Illuminate\Contracts\Hashing\Hasher::class],
'translator' => [\Illuminate\Translation\Translator::class, \Illuminate\Contracts\Translation\Translator::class],
'log' => [\Illuminate\Log\Writer::class, \Illuminate\Contracts\Logging\Log::class, \Psr\Log\LoggerInterface::class],
'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class],
'auth.password' => [\Illuminate\Auth\Passwords\PasswordBrokerManager::class, \Illuminate\Contracts\Auth\PasswordBrokerFactory::class],
'auth.password.broker' => [\Illuminate\Auth\Passwords\PasswordBroker::class, \Illuminate\Contracts\Auth\PasswordBroker::class],
'queue' => [\Illuminate\Queue\QueueManager::class, \Illuminate\Contracts\Queue\Factory::class, \Illuminate\Contracts\Queue\Monitor::class],
'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class],
'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class],
'redirect' => [\Illuminate\Routing\Redirector::class],
'redis' => [\Illuminate\Redis\RedisManager::class, \Illuminate\Contracts\Redis\Factory::class],
'request' => [\Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class],
'router' => [\Illuminate\Routing\Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
'session' => [\Illuminate\Session\SessionManager::class],
'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class],
'url' => [\Illuminate\Routing\UrlGenerator::class, \Illuminate\Contracts\Routing\UrlGenerator::class],
'validator' => [\Illuminate\Validation\Factory::class, \Illuminate\Contracts\Validation\Factory::class],
'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class],
所以,初始化之后的app里面的内容如下:
bindings 里面有如下内容:
events
log
router
url
redirect
Psr\Http\Message\ServerRequestInterface
Psr\Http\Message\ResponseInterface
Illuminate\Contracts\Routing\ResponseFactory
Illuminate\Routing\Contracts\ControllerDispatcher
总结一下,application初始化的时候,就干了这么几个事情:
1. 定位自己,确定文件运行的相关目录
2. 把自己扔进容器,把用来引用其他代码的package类实例化进容器。
3. log/event/router 三大基本功能提高provider
4. 绑定别名,当然,许多别名,这这个时候,实际上是无效的。因为根本没绑定到实际类,估计是为了占空。
在container之外扩展的功能:
1. 启动时额外提供的初始化功能,并且添加了相关事件的注册,主要函数bootstrapWith。
添加事件 bootstrapping bootstrapped 并且注册外面类提供的所有初始化功能。准备程序运行的参数和环境的注入。
2. registerConfiguredProviders 函数,读取app.providers里面定义的provider,并注册。
3. provider的处理,主要函数,register(注册provider),boot等。
4. 延迟加载deferredServices,延迟加载的provider,只是注册进container,但是,并不实例化provider,只有调用相关类的时候,才会运行provider进行注册。
5.handle 直接调用kernel处理request,也是针对网络访问的一个出口函数。
app在container之外,添加了provider的概念,添加了request相关处理的概念,将container包装成了一个处理网络请求的新container。
instances里面有如下内容:
path::/Users/yuxuezhong/git/webservice/api/app
path.base::/Users/yuxuezhong/git/webservice/api
path.lang::/Users/yuxuezhong/git/webservice/api/resources/lang
path.config::/Users/yuxuezhong/git/webservice/api/config
path.public::/Users/yuxuezhong/git/webservice/api/public
path.storage::/Users/yuxuezhong/git/webservice/api/storage
path.database::/Users/yuxuezhong/git/webservice/api/database
path.resources::/Users/yuxuezhong/git/webservice/api/resources
path.bootstrap::/Users/yuxuezhong/git/webservice/api/bootstrap
app::Illuminate\Foundation\Application
Illuminate\Container\Container::Illuminate\Foundation\Application
Illuminate\Foundation\PackageManifest::Illuminate\Foundation\PackageManifest
转载于:https://www.cnblogs.com/yxzamy/p/7612531.html
laravel application 容器app相关推荐
- 使用 Docker Compose 构建复杂的多容器 App
1 为什么需要 Docker Compose 在创建容器过程中,特别是在代码调试阶段,一般需要重复运行一些命令, 如 docker build ,docker run 等等,这些命令有时冗长而复杂,手 ...
- laravel 服务容器,容器概念
Laravel 服务容器 发现一篇讲服务容器的文章,讲的很好,转载过来laravel 服务容器 实质是工厂模式的升级,类的传递动态加载 ####以下内容转载 容器,字面上理解就是装东西的东西.常见的变 ...
- Laravel服务容器
DI DI就是常说的依赖注入,那么究竟什么是依赖注入呢? 打个比方,电脑(非笔记本哈)需要键盘和鼠标我们才能进行操作,这个'需要'换句话说就是'依赖'键盘和鼠标. 那么,相应的,一个类需要另一个类才能 ...
- Laravel Ioc容器singleton和bind方法的区别
Laravel中使用Ioc容器的singleton方法和bind方法创建实例有什么区别呢?它们两个都是返回一个类的实例,不同的是singleton是单例模式,而bind是每次返回一个新的实例,看下面的 ...
- Android借助Application重写App的Crash(简易版)
MainActivity如下: package cn.testcrash; import android.app.Activity; import android.os.Bundle; /*** De ...
- Azure Active Directory Powershell命令创建一个application以及App需要的权限
下面会用Powershell Azure AD实现创建一个自定义的App,其中包括Micrsoft Graph Read all groups权限添加,以及certificate证书验证上传证书的操作 ...
- laravel服务容器-----深入理解控制反转(IoC)和依赖注入(DI)
首先大家想一想什么是容器,字面意思就是盛放东西的东西,常见的变量,对象属性都是容器,一个容器能够装什么东西,完全在于你对这个容器的定义.有的容器不仅仅只是存文本,变量,而是对象,属性,那么我们通过这种 ...
- php ico容器,Laravel 核心——IoC 服务容器
服务容器 Laravel 服务容器是一个用于管理类依赖和执行依赖注入的强大工具. 在理解这句话之前,我们需要先了解一下服务容器的来龙去脉: laravel神奇的服务容器.这篇博客告诉我们,服务容器就是 ...
- Laravel源码入门-启动引导过程(四)app/Http/Kernel.php
2019独角兽企业重金招聘Python工程师标准>>> == 回顾 == 再来回顾一下 public/index.php ,代码如下(去掉详细注释部分). <?php // p ...
最新文章
- “中台不就是微服务吗?有啥区别?”
- ZooKeeper最佳指南--云平台技术栈11
- Linux内核中的进程等待与其实现解析
- Mysql5.7 ZIP 压缩包非安装版的安装方式
- C++不同数据类型的转换
- IE10兼容性故障的解决办法
- Spring的消息 Java Message Service (JMS)
- 让数据可视化告诉你,中秋吃这样的月饼绝对没错
- Lucene开发(一):快速入门
- 开源中文bi_odoo:免费开源ERP入门与实践
- 金蝶显示服务器连接超时,金蝶连接云服务器超时
- 微云同步盘 linux,微云同步盘pc版下载
- lisp6 暖通cad_浩辰CAD暖通2018
- 人人商城互动直播(与通信服务器连接失败)
- python-pygame作品之MineCraft小鸡
- C# Word文档添加水印
- 阿里达摩院人工智能科学家杨红霞离职,AI商用是难题
- 莫纳什计算机专业优势,2020年去澳洲留学就读莫纳什大学计算机学院有哪些优势?...
- react入门-列表渲染(动态获取数据)
- 将视频背景扣掉换成白色相关知识
热门文章
- 江苏大学矩阵论、数理统计期末考试复习
- 网络协议从入门到底层原理(6)应用层 - 域名、DNS、DHCP、HTTP(ABNF、HTTP报文格式、请求方法、头部字段、状态码、跨域)、代理、CDN
- 小程序入门学习07--动态设置标题、转发
- Windows域控管理 常用操作 详细汇总
- 白皮书 | 以太坊 (Ethereum ):下一代智能合约和去中心化应用平台
- 设计模式04_抽象工厂
- 30岁女IT工程师感叹:靠这工具,把报表做成养老工作,月薪快3W
- 商业智能SAAS走向中小企业
- python32位系统下载_pythonwin下载-PythonWin 32位(Python集成开发环境) 3.6 官方版 - 河东下载站...
- python列表数据类型(一分钟读懂)