1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Cookies plugin for Craft CMS |
||
5 | * |
||
6 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
7 | * @copyright Copyright (c) nystudio107 |
||
0 ignored issues
–
show
|
|||
8 | * @license MIT License https://opensource.org/licenses/MIT |
||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | namespace nystudio107\cookies; |
||
12 | |||
13 | use Craft; |
||
14 | use craft\base\Plugin; |
||
15 | use craft\web\twig\variables\CraftVariable; |
||
16 | use nystudio107\cookies\services\CookiesService; |
||
17 | use nystudio107\cookies\services\ServicesTrait; |
||
18 | use nystudio107\cookies\twigextensions\CookiesTwigExtension; |
||
19 | use nystudio107\cookies\variables\CookiesVariable; |
||
20 | use yii\base\Event; |
||
21 | |||
22 | /** |
||
23 | * Class Cookies |
||
24 | * |
||
25 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
26 | * @package Cookies |
||
0 ignored issues
–
show
|
|||
27 | * @since 1.1.0 |
||
0 ignored issues
–
show
|
|||
28 | */ |
||
0 ignored issues
–
show
|
|||
29 | class Cookies extends Plugin |
||
30 | { |
||
31 | // Traits |
||
32 | // ========================================================================= |
||
33 | |||
34 | use ServicesTrait; |
||
35 | |||
36 | // Static Public Properties |
||
37 | // ========================================================================= |
||
38 | |||
39 | /** |
||
0 ignored issues
–
show
|
|||
40 | * @var null|Cookies |
||
41 | */ |
||
42 | public static ?Cookies $plugin = null; |
||
43 | |||
44 | // Public Properties |
||
45 | // ========================================================================= |
||
46 | |||
47 | /** |
||
0 ignored issues
–
show
|
|||
48 | * @var string |
||
49 | */ |
||
50 | public string $schemaVersion = '1.0.0'; |
||
51 | |||
52 | /** |
||
0 ignored issues
–
show
|
|||
53 | * @var bool |
||
54 | */ |
||
55 | public bool $hasCpSection = false; |
||
56 | |||
57 | /** |
||
0 ignored issues
–
show
|
|||
58 | * @var bool |
||
59 | */ |
||
60 | public bool $hasCpSettings = false; |
||
61 | |||
62 | // Public Methods |
||
63 | // ========================================================================= |
||
64 | |||
65 | /** |
||
0 ignored issues
–
show
|
|||
66 | * @inheritdoc |
||
67 | */ |
||
68 | public function __construct($id, $parent = null, array $config = []) |
||
69 | { |
||
70 | $config['components'] = [ |
||
71 | 'cookies' => CookiesService::class, |
||
72 | ]; |
||
73 | |||
74 | parent::__construct($id, $parent, $config); |
||
75 | } |
||
76 | |||
77 | /** |
||
0 ignored issues
–
show
|
|||
78 | * @inheritdoc |
||
79 | */ |
||
0 ignored issues
–
show
|
|||
80 | public function init(): void |
||
81 | { |
||
82 | parent::init(); |
||
83 | self::$plugin = $this; |
||
84 | $this->name = $this->getName(); |
||
85 | |||
86 | Event::on( |
||
87 | CraftVariable::class, |
||
88 | CraftVariable::EVENT_INIT, |
||
89 | static function(Event $event): void { |
||
0 ignored issues
–
show
|
|||
90 | /** @var CraftVariable $variable */ |
||
0 ignored issues
–
show
|
|||
91 | $variable = $event->sender; |
||
92 | $variable->set('cookies', CookiesVariable::class); |
||
93 | } |
||
94 | ); |
||
95 | |||
96 | // Add in our Twig extensions |
||
97 | Craft::$app->view->registerTwigExtension(new CookiesTwigExtension()); |
||
98 | |||
99 | Craft::info( |
||
100 | Craft::t( |
||
101 | 'cookies', |
||
102 | '{name} plugin loaded', |
||
103 | ['name' => $this->name] |
||
104 | ), |
||
105 | __METHOD__ |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Returns the user-facing name of the plugin, which can override the name |
||
111 | * in composer.json |
||
112 | */ |
||
0 ignored issues
–
show
|
|||
113 | public function getName(): string |
||
114 | { |
||
115 | return Craft::t('cookies', 'Cookies'); |
||
116 | } |
||
117 | } |
||
118 |