-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from Laravel-Lang/11.1-split
Added abstract service provider for the templates
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the "laravel-lang/publisher" project. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Andrey Helldar <[email protected]> | ||
* | ||
* @copyright 2021 Andrey Helldar | ||
* | ||
* @license MIT | ||
* | ||
* @see https://github.com/Laravel-Lang/publisher | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Publisher\Concerns; | ||
|
||
use DragonCode\Support\Facades\Helpers\Ables\Arrayable; | ||
use Illuminate\Support\ServiceProvider; | ||
use LaravelLang\Publisher\Constants\Config; | ||
use LaravelLang\Publisher\Exceptions\ProviderNotDefinedException; | ||
|
||
class BaseServiceProvider extends ServiceProvider | ||
{ | ||
protected $provider; | ||
|
||
public function register(): void | ||
{ | ||
$this->registerProvider(); | ||
} | ||
|
||
protected function registerProvider(): void | ||
{ | ||
$config = $this->plugins(); | ||
|
||
$plugins = $this->push($config); | ||
|
||
$this->setConfig($plugins); | ||
} | ||
|
||
protected function getProvider(): string | ||
{ | ||
if ($this->provider) { | ||
return $this->provider; | ||
} | ||
|
||
throw new ProviderNotDefinedException(); | ||
} | ||
|
||
protected function push(array $plugins): array | ||
{ | ||
return Arrayable::of($plugins) | ||
->push($this->getProvider()) | ||
->unique() | ||
->sort() | ||
->values() | ||
->get(); | ||
} | ||
|
||
protected function plugins(): array | ||
{ | ||
return config(Config::PUBLIC_KEY); | ||
} | ||
|
||
protected function setConfig(array $plugins): void | ||
{ | ||
$key = Config::PUBLIC_KEY . '.plugins'; | ||
|
||
config()->set($key, $plugins); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the "laravel-lang/publisher" project. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Andrey Helldar <[email protected]> | ||
* | ||
* @copyright 2021 Andrey Helldar | ||
* | ||
* @license MIT | ||
* | ||
* @see https://github.com/Laravel-Lang/publisher | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Publisher\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
class ProviderNotDefinedException extends RuntimeException | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct('Provider class not defined.'); | ||
} | ||
} |