1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace flipbox\patron\cp; |
4
|
|
|
|
5
|
|
|
use Craft; |
6
|
|
|
use craft\events\RegisterTemplateRootsEvent; |
7
|
|
|
use craft\web\View; |
8
|
|
|
use Flipbox\OAuth2\Client\Provider\Guardian; |
9
|
|
|
use flipbox\patron\events\RegisterProviderIcons; |
10
|
|
|
use flipbox\patron\events\RegisterProviders; |
11
|
|
|
use flipbox\patron\events\RegisterProviderSettings; |
12
|
|
|
use flipbox\patron\Patron; |
13
|
|
|
use flipbox\patron\settings\FacebookSettings; |
14
|
|
|
use flipbox\patron\settings\GuardianSettings; |
15
|
|
|
use League\OAuth2\Client\Provider\Facebook; |
16
|
|
|
use yii\base\Event; |
17
|
|
|
use yii\base\Module; |
18
|
|
|
use yii\web\NotFoundHttpException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @property Patron $module |
22
|
|
|
*/ |
23
|
|
|
class Cp extends Module |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private $icons; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $providers; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritdoc |
37
|
|
|
*/ |
38
|
|
|
public function init() |
39
|
|
|
{ |
40
|
|
|
parent::init(); |
41
|
|
|
|
42
|
|
|
// Components |
43
|
|
|
$this->setComponents([ |
44
|
|
|
'settings' => services\Settings::class |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
// Register settings for providers |
48
|
|
|
RegisterProviderSettings::on( |
49
|
|
|
Guardian::class, |
50
|
|
|
RegisterProviderSettings::REGISTER_SETTINGS, |
51
|
|
|
function (RegisterProviderSettings $event) { |
52
|
|
|
$event->class = GuardianSettings::class; |
53
|
|
|
} |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
RegisterProviderSettings::on( |
57
|
|
|
Facebook::class, |
58
|
|
|
RegisterProviderSettings::REGISTER_SETTINGS, |
59
|
|
|
function (RegisterProviderSettings $event) { |
60
|
|
|
$event->class = FacebookSettings::class; |
61
|
|
|
} |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
// Ember templates |
65
|
|
|
Event::on( |
66
|
|
|
View::class, |
67
|
|
|
View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, |
68
|
|
|
function (RegisterTemplateRootsEvent $e) { |
69
|
|
|
$e->roots['patron/ember/card'] = Craft::$app->getPath()->getVendorPath() . |
70
|
|
|
'/flipboxfactory/craft-assets-card/src/templates'; |
71
|
|
|
$e->roots['patron/ember/circle-icon'] = Craft::$app->getPath()->getVendorPath() . |
72
|
|
|
'/flipboxfactory/craft-assets-circle-icon/src/templates'; |
73
|
|
|
} |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritdoc |
79
|
|
|
* @throws NotFoundHttpException |
80
|
|
|
*/ |
81
|
|
|
public function beforeAction($action) |
82
|
|
|
{ |
83
|
|
|
if (!Craft::$app->request->getIsCpRequest()) { |
84
|
|
|
throw new NotFoundHttpException(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return parent::beforeAction($action); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/******************************************* |
92
|
|
|
* SERVICES |
93
|
|
|
*******************************************/ |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @noinspection PhpDocMissingThrowsInspection |
97
|
|
|
* @return services\Settings |
98
|
|
|
*/ |
99
|
|
|
public function getSettings(): services\Settings |
100
|
|
|
{ |
101
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
102
|
|
|
/** @noinspection PhpIncompatibleReturnTypeInspection */ |
103
|
|
|
return $this->get('settings'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/******************************************* |
108
|
|
|
* PROVIDERS |
109
|
|
|
*******************************************/ |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
|
|
public function getProviders(): array |
115
|
|
|
{ |
116
|
|
|
if ($this->providers === null) { |
117
|
|
|
$event = new RegisterProviders(); |
118
|
|
|
|
119
|
|
|
$this->trigger( |
120
|
|
|
$event::REGISTER_PROVIDERS, |
121
|
|
|
$event |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
$this->providers = $event->providers; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $this->providers; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
|
public function getProviderIcons(): array |
134
|
|
|
{ |
135
|
|
|
if ($this->icons === null) { |
136
|
|
|
$event = new RegisterProviderIcons(); |
137
|
|
|
|
138
|
|
|
$this->trigger( |
139
|
|
|
$event::REGISTER_ICON, |
140
|
|
|
$event |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$this->icons = $event->icons; |
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return $this->icons; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..