- 다른 뜻에 대해서는 서비스 프로바이더 문서를 참조하십시오.
1 개요[ | ]
- 라라벨 Service Providers
- Laravel 서비스 프로바이더
- 라라벨 애플리케이션 부트스트래핑의 중심적 위치
- 라라벨의 코어 서비스들은 모두 서비스 프로바이더를 통해 부트스트래핑됨
- 라라벨 프레임워크의 패키지, 익스텐션을 준비해주는 메커니즘
- config/app.php의 providers 항목에 등록하여 사용
PHP
Copy
'providers' => [
// Other Service Providers
App\Providers\AppServiceProvider::class,
],
2 소스 코드[ | ]
- 서비스 제공자의 형식을 기술한 추상 클래스
PHP
Copy
<?php
namespace Illuminate\Support;
use BadMethodCallException;
use Illuminate\Console\Events\ArtisanStarting;
abstract class ServiceProvider
{
protected $app;
protected $defer = false;
protected static $publishes = [];
protected static $publishGroups = [];
public function __construct($app)
{
$this->app = $app;
}
abstract public function register();
protected function mergeConfigFrom($path, $key)
{
$config = $this->app['config']->get($key, []);
$this->app['config']->set($key, array_merge(require $path, $config));
}
protected function loadViewsFrom($path, $namespace)
{
if (is_dir($appPath = $this->app->basePath().'/resources/views/vendor/'.$namespace)) {
$this->app['view']->addNamespace($namespace, $appPath);
}
$this->app['view']->addNamespace($namespace, $path);
}
protected function loadTranslationsFrom($path, $namespace)
{
$this->app['translator']->addNamespace($namespace, $path);
}
protected function publishes(array $paths, $group = null)
{
$class = get_class($this);
if (! array_key_exists($class, static::$publishes)) {
static::$publishes[$class] = [];
}
static::$publishes[$class] = array_merge(static::$publishes[$class], $paths);
if ($group) {
if (! array_key_exists($group, static::$publishGroups)) {
static::$publishGroups[$group] = [];
}
static::$publishGroups[$group] = array_merge(static::$publishGroups[$group], $paths);
}
}
public static function pathsToPublish($provider = null, $group = null)
{
if ($provider && $group) {
if (empty(static::$publishes[$provider]) || empty(static::$publishGroups[$group])) {
return [];
}
return array_intersect_key(static::$publishes[$provider], static::$publishGroups[$group]);
}
if ($group && array_key_exists($group, static::$publishGroups)) {
return static::$publishGroups[$group];
}
if ($provider && array_key_exists($provider, static::$publishes)) {
return static::$publishes[$provider];
}
if ($group || $provider) {
return [];
}
$paths = [];
foreach (static::$publishes as $class => $publish) {
$paths = array_merge($paths, $publish);
}
return $paths;
}
public function commands($commands)
{
$commands = is_array($commands) ? $commands : func_get_args();
$events = $this->app['events'];
$events->listen(ArtisanStarting::class, function ($event) use ($commands) {
$event->artisan->resolveCommands($commands);
});
}
public function provides()
{
return [];
}
public function when()
{
return [];
}
public function isDeferred()
{
return $this->defer;
}
public static function compiles()
{
return [];
}
public function __call($method, $parameters)
{
if ($method == 'boot') {
return;
}
throw new BadMethodCallException("Call to undefined method [{$method}]");
}
}
3 예시[ | ]
ServiceProvider 클래스를 상속하여 구현된 서비스 프로바이더들
- 라라벨 AggregateServiceProvider
- 라라벨 AppServiceProvider
- 라라벨 AuthServiceProvider
- 라라벨 BroadcastServiceProvider
- 라라벨 BusServiceProvider
- 라라벨 CacheServiceProvider
- 라라벨 ConsoleServiceProvider
- 라라벨 ConsoleSupportServiceProvider
- 라라벨 CookieServiceProvider
- 라라벨 DatabaseServiceProvider
- 라라벨 EncryptionServiceProvider
- 라라벨 EventServiceProvider
- 라라벨 FilesystemServiceProvider
- 라라벨 FoundationServiceProvider
- 라라벨 HashServiceProvider
- 라라벨 MailServiceProvider
- 라라벨 PaginationServiceProvider
- 라라벨 PasswordResetServiceProvider
- 라라벨 PipelineServiceProvider
- 라라벨 QueueServiceProvider
- 라라벨 RedisServiceProvider
- 라라벨 RouteServiceProvider
- 라라벨 RoutingServiceProvider
- 라라벨 SessionServiceProvider
- 라라벨 TranslationServiceProvider
- 라라벨 ValidationServiceProvider
- 라라벨 ViewServiceProvider
4 같이 보기[ | ]
5 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.