|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/domains/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/domains/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\domains; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use craft\base\Plugin as BasePlugin; |
|
13
|
|
|
use craft\events\RegisterComponentTypesEvent; |
|
14
|
|
|
use craft\services\Fields; |
|
15
|
|
|
use flipbox\domains\fields\Domains as DomainsField; |
|
16
|
|
|
use yii\base\Event; |
|
17
|
|
|
use yii\log\Logger; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Flipbox Factory <[email protected]> |
|
21
|
|
|
* @since 1.0.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class Domains extends BasePlugin |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritdoc |
|
27
|
|
|
*/ |
|
28
|
|
|
public function init() |
|
29
|
|
|
{ |
|
30
|
|
|
// Do parent |
|
31
|
|
|
parent::init(); |
|
32
|
|
|
|
|
33
|
|
|
// Register our fields |
|
34
|
|
|
Event::on( |
|
35
|
|
|
Fields::class, |
|
36
|
|
|
Fields::EVENT_REGISTER_FIELD_TYPES, |
|
37
|
|
|
function (RegisterComponentTypesEvent $event) { |
|
38
|
|
|
$event->types[] = DomainsField::class; |
|
39
|
|
|
} |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return services\Fields |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getFields() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->get('fields'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return services\Domains |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getDomains() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->get('domains'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return services\Associations |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getAssociations() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->get('associations'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/******************************************* |
|
68
|
|
|
* LOGGING |
|
69
|
|
|
*******************************************/ |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Logs a trace message. |
|
73
|
|
|
* Trace messages are logged mainly for development purpose to see |
|
74
|
|
|
* the execution work flow of some code. |
|
75
|
|
|
* @param string $message the message to be logged. |
|
76
|
|
|
* @param string $category the category of the message. |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function trace($message, string $category = null) |
|
79
|
|
|
{ |
|
80
|
|
|
Craft::getLogger()->log($message, Logger::LEVEL_TRACE, self::normalizeCategory($category)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Logs an error message. |
|
85
|
|
|
* An error message is typically logged when an unrecoverable error occurs |
|
86
|
|
|
* during the execution of an application. |
|
87
|
|
|
* @param string $message the message to be logged. |
|
88
|
|
|
* @param string $category the category of the message. |
|
89
|
|
|
*/ |
|
90
|
|
|
public static function error($message, string $category = null) |
|
91
|
|
|
{ |
|
92
|
|
|
Craft::getLogger()->log($message, Logger::LEVEL_ERROR, self::normalizeCategory($category)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Logs a warning message. |
|
97
|
|
|
* A warning message is typically logged when an error occurs while the execution |
|
98
|
|
|
* can still continue. |
|
99
|
|
|
* @param string $message the message to be logged. |
|
100
|
|
|
* @param string $category the category of the message. |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function warning($message, string $category = null) |
|
103
|
|
|
{ |
|
104
|
|
|
Craft::getLogger()->log($message, Logger::LEVEL_WARNING, self::normalizeCategory($category)); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Logs an informative message. |
|
109
|
|
|
* An informative message is typically logged by an application to keep record of |
|
110
|
|
|
* something important (e.g. an administrator logs in). |
|
111
|
|
|
* @param string $message the message to be logged. |
|
112
|
|
|
* @param string $category the category of the message. |
|
113
|
|
|
*/ |
|
114
|
|
|
public static function info($message, string $category = null) |
|
115
|
|
|
{ |
|
116
|
|
|
Craft::getLogger()->log($message, Logger::LEVEL_INFO, self::normalizeCategory($category)); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param string|null $category |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
private static function normalizeCategory(string $category = null) |
|
124
|
|
|
{ |
|
125
|
|
|
$normalizedCategory = 'Domains'; |
|
126
|
|
|
|
|
127
|
|
|
if ($category === null) { |
|
128
|
|
|
return $normalizedCategory; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $normalizedCategory . ': ' . $category; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|