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