라라벨 Manager

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:57 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

라라벨 Manager
<?php

namespace Illuminate\Support;

use Closure;
use InvalidArgumentException;

abstract class Manager
{
    protected $app;
    protected $customCreators = [];
    protected $drivers = [];

    public function __construct($app)
    {
        $this->app = $app;
    }

    abstract public function getDefaultDriver();

    public function driver($driver = null)
    {
        $driver = $driver ?: $this->getDefaultDriver();
        if (! isset($this->drivers[$driver])) {
            $this->drivers[$driver] = $this->createDriver($driver);
        }
        return $this->drivers[$driver];
    }

    protected function createDriver($driver)
    {
        $method = 'create'.Str::studly($driver).'Driver';
        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver);
        } elseif (method_exists($this, $method)) {
            return $this->$method();
        }

        throw new InvalidArgumentException("Driver [$driver] not supported.");
    }

    protected function callCustomCreator($driver)
    {
        return $this->customCreators[$driver]($this->app);
    }

    public function extend($driver, Closure $callback)
    {
        $this->customCreators[$driver] = $callback;

        return $this;
    }

    public function getDrivers()
    {
        return $this->drivers;
    }

    public function __call($method, $parameters)
    {
        return call_user_func_array([$this->driver(), $method], $parameters);
    }
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}