"라라벨 Manager"의 두 판 사이의 차이

69번째 줄: 69번째 줄:


==같이 보기==
==같이 보기==
* [[Closure]]
* [[라라벨 SessionManager]]
* [[InvalidArgumentException]]
* [[라라벨 Closure]]
* [[라라벨 InvalidArgumentException]]


[[분류: Illuminate\Support]]
[[분류: Illuminate\Support]]

2016년 9월 9일 (금) 20:26 판

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 }}