public function check($trigger = false)
{
$issues = [];
$rawKey = $this->getKey();
$subdir = basename($this->getSubdir());
// Check for missing fields.
$required = ['key', 'type'];
foreach ($required as $fieldName) {
if (empty($this->info[$fieldName])) {
$issues["required-{$fieldName}"] = "The {$fieldName} info field is required.";
}
}
// Make sure the addon has a correct type.
if ($this->getType()) {
if (!in_array($this->getType(), [static::TYPE_ADDON, static::TYPE_THEME, static::TYPE_LOCALE])) {
$type = $this->getType();
$issues['type-invalid'] = "The addon has an invalid type ({$type}).";
} elseif (empty($this->info['priority'])) {
// Add a missing priority.
$priorities = [static::TYPE_ADDON => static::PRIORITY_NORMAL, static::TYPE_LOCALE => static::PRIORITY_LOCALE, static::TYPE_THEME => static::PRIORITY_THEME];
$this->info['priority'] = $priorities[$this->getType()];
}
}
// Themes and locales must have a key that matches their subdirectories.
if ($rawKey !== $subdir && in_array($this->getType(), [static::TYPE_LOCALE, static::TYPE_THEME])) {
$issues['key-subdir-mismatch'] = "The addon key must match it's subdirectory name ({$rawKey} vs. {$subdir}).";
}
if ($this->getType() === static::TYPE_ADDON) {
// Lowercase the keys of the other types.
$key = strtolower($rawKey);
if ($key !== $rawKey) {
$this->info['key'] = $key;
$this->info['keyRaw'] = $rawKey;
}
if (strcasecmp($key, basename($this->getSubdir())) !== 0) {
$issues['key-subdir-mismatch-case'] = "The addon key must match it's subdirectory name ({$key} vs. {$subdir}).";
}
}
if (!empty($this->special['otherPlugins'])) {
$plugins = implode(', ', array_merge([$this->special['plugin']], $this->special['otherPlugins']));
$issues['multiple-plugins'] = "The addon should have at most one plugin class ({$plugins}).";
}
if ($trigger && ($count = count($issues))) {
$subdir = $this->getSubdir();
trigger_error("The addon in {$subdir} has {$count} issues.", E_USER_NOTICE);
foreach ($issues as $issue) {
trigger_error($issue, E_USER_NOTICE);
}
}
return $issues;
}