-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPlugin.php
84 lines (73 loc) · 2.61 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php namespace LukeTowers\Passport;
use App;
use Config;
use Laravel\Passport\Passport;
use System\Classes\PluginBase;
use Illuminate\Foundation\AliasLoader;
/**
* Passport Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'luketowers.passport::lang.plugin.name',
'description' => 'luketowers.passport::lang.plugin.description',
'author' => 'Luke Towers',
'icon' => 'icon-lock',
'homepage' => 'https://github.com/wintercms/wn-passport-plugin',
];
}
/**
* Runs right before the request route
*/
public function boot()
{
// Disable the Laravel migrations from Passport, handled via plugin updates
Passport::ignoreMigrations();
// Setup required packages
$this->bootPackages();
// Setup the API routes for Passport
Passport::routes();
}
/**
* Boots (configures and registers) any packages found within this plugin's packages.load configuration value
*
* @see https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-plugins
* @author Luke Towers <info@luketowers.ca>
*/
public function bootPackages()
{
// Get the namespace of the current plugin to use in accessing the Config of the plugin
$pluginNamespace = str_replace('\\', '.', strtolower(__NAMESPACE__));
// Instantiate the AliasLoader for any aliases that will be loaded
$aliasLoader = AliasLoader::getInstance();
// Get the packages to boot
$packages = Config::get($pluginNamespace . '::packages');
// Boot each package
foreach ($packages as $name => $options) {
// Setup the configuration for the package, pulling from this plugin's config
if (!empty($options['config']) && !empty($options['config_namespace'])) {
Config::set($options['config_namespace'], $options['config']);
}
// Register any Service Providers for the package
if (!empty($options['providers'])) {
foreach ($options['providers'] as $provider) {
App::register($provider);
}
}
// Register any Aliases for the package
if (!empty($options['aliases'])) {
foreach ($options['aliases'] as $alias => $path) {
$aliasLoader->alias($alias, $path);
}
}
}
}
}