Issues (134)

src/ICalendar.php (6 issues)

1
<?php
2
/**
3
 * iCalendar plugin for Craft CMS 3.x
4
 *
5
 * Tools for parsing & formatting the RFC 2445 iCalendar (.ics) specification
6
 *
7
 * @link      https://nystudio107.com
8
 * @copyright Copyright (c) 2018 nystudio107
9
 */
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
26
 * @package   ICalendar
27
 * @since     1.0.0
28
 *
29
 * @property  ConvertService $convert
30
 * @property  ParseService $parse
0 ignored issues
show
Tag value for @property tag indented incorrectly; expected 1 spaces but found 2
Loading history...
31
 */
32
class ICalendar extends Plugin
33
{
34
    // Static Properties
35
    // =========================================================================
36
37
    /**
38
     * @var ?ICalendar
39
     */
40
    public static ?ICalendar $plugin = null;
41
42
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
43
     * @var ?ICalendarVariable
44
     */
45
    public static ?ICalendarVariable $variable = null;
46
47
    // Public Properties
48
    // =========================================================================
49
50
    /**
51
     * @var string
52
     */
53
    public string $schemaVersion = '1.0.0';
54
55
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
56
     * @var bool
57
     */
58
    public bool $hasCpSection = false;
59
60
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
61
     * @var bool
62
     */
63
    public bool $hasCpSettings = false;
64
65
    // Public Methods
66
    // =========================================================================
67
68
    /**
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
Missing short description in doc comment
Loading history...
82
     * @inheritdoc
83
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
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) {
96
                /** @var CraftVariable $variable */
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