1
0
mirror of https://github.com/flarum/core.git synced 2025-10-17 17:56:14 +02:00
Files
php-flarum/src/Extension/Exception/DependentExtensionsException.php
Alexander Skvortsov 84d14f485a Basic Extension Dependency Support (#2188)
- Don't enable an extension if its dependencies are not enabled
- Don't disable an extension if its dependencies are not disabled
2020-10-02 17:54:28 -04:00

48 lines
1.3 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Extension\Exception;
use Exception;
use Flarum\Extension\Extension;
/**
* This exception is thrown when someone attempts to disable an extension
* that other enabled extensions depend on.
*/
class DependentExtensionsException extends Exception
{
public $extension;
public $dependent_extensions;
/**
* @param $extension: The extension we are attempting to disable.
* @param $dependent_extensions: Enabled Flarum extensions that depend on this extension.
*/
public function __construct(Extension $extension, array $dependent_extensions)
{
$this->extension = $extension;
$this->dependent_extensions = $dependent_extensions;
parent::__construct($extension->getId().' could not be disabled, because it is a dependency of: '.implode(', ', $this->getDependentExtensionIds()));
}
/**
* Get array of IDs for extensions that depend on this extension.
*
* @return array
*/
public function getDependentExtensionIds()
{
return array_map(function (Extension $extension) {
return $extension->getId();
}, $this->dependent_extensions);
}
}