Skip to content

Instantly share code, notes, and snippets.

@kellymears
Last active August 23, 2019 20:26
Show Gist options
  • Save kellymears/927af91b79a40a76772f69116c844a20 to your computer and use it in GitHub Desktop.
Save kellymears/927af91b79a40a76772f69116c844a20 to your computer and use it in GitHub Desktop.
Utilize service providers
<?php
namespace App\Composers\Concerns;
use Roots\Acorn\Application;
use Illuminate\Support\Collection;
trait Services
{
/**
* Service Provider
* @var array
*/
// public static $services = [
// 'Parser' => 'commonmark',
// ];
/**
* Utilize service providers
*
* @param array $services
* @return void
*/
protected function resolveServices() : void
{
if (isset(self::$services) && !empty(self::$services)) {
Collection::make(self::$services)->each(function ($alias, $call) {
$callable = Application::getInstance()->make($alias);
$this->$call = $callable;
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment