Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Thompson
committed
Jan 26, 2021
1 parent
2e8235f
commit 6d4a519
Showing
6 changed files
with
159 additions
and
70 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
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
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
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,101 @@ | ||
<?php | ||
|
||
namespace Streams\Core\Addon; | ||
|
||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Config; | ||
|
||
/** | ||
* Class AddonManager | ||
* | ||
* @link http://pyrocms.com/ | ||
* @author PyroCMS, Inc. <support@pyrocms.com> | ||
* @author Ryan Thompson <ryan@pyrocms.com> | ||
*/ | ||
class AddonManager | ||
{ | ||
/** | ||
* The addon collection. | ||
* | ||
* @var Collection | ||
*/ | ||
protected $collection; | ||
|
||
/** | ||
* The disabled addons. | ||
* | ||
* @var array | ||
*/ | ||
protected $disabled; | ||
|
||
/** | ||
* Create a new class instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->collection = new AddonCollection; | ||
$this->disabled = Config::get('streams.addons.disabled', []);; | ||
} | ||
|
||
/** | ||
* Load an addon by path. | ||
* | ||
* @param string $path | ||
*/ | ||
public function load($path) | ||
{ | ||
$path = rtrim($path, '/\\'); | ||
|
||
$composer = json_decode(file_get_contents($path . '/composer.json'), true); | ||
|
||
$addon = [ | ||
'name' => $composer['name'], | ||
'path' => $path, | ||
'composer' => $composer, | ||
]; | ||
|
||
return $this->register($addon); | ||
} | ||
|
||
/** | ||
* Register an addon. | ||
*/ | ||
public function register($addon) | ||
{ | ||
$addon['enabled'] = Arr::get($addon, 'enabled', !in_array($addon['name'], $this->disabled)); | ||
|
||
$addon = $this->build($addon); | ||
|
||
App::instance('streams.addons.' . str_replace('/', '.', $addon->name), $addon); | ||
|
||
$this->collection->put($addon->name, $addon); | ||
|
||
return $addon; | ||
} | ||
|
||
public function make($name) | ||
{ | ||
return App::make('streams.addons.' . str_replace('/', '.', $name)); | ||
} | ||
|
||
/** | ||
* Build an addon instance. | ||
* | ||
* @param $addon | ||
* @return Addon | ||
*/ | ||
public function build($addon) | ||
{ | ||
return new Addon($addon); | ||
} | ||
|
||
/** | ||
* Return the addon collection. | ||
*/ | ||
public function collection() | ||
{ | ||
return $this->collection; | ||
} | ||
} |
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
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,28 @@ | ||
<?php | ||
|
||
namespace Streams\Core\Support\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
/** | ||
* Class Addons | ||
* | ||
* @link http://pyrocms.com/ | ||
* @author PyroCMS, Inc. <support@pyrocms.com> | ||
* @author Ryan Thompson <ryan@pyrocms.com> | ||
* @method static void register($addon) | ||
*/ | ||
class Addons extends Facade | ||
{ | ||
|
||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'addons'; | ||
} | ||
} |