You are here

class TwigDebugSensorPlugin in Monitoring 8

Monitors the twig debug settings.

Plugin annotation


@SensorPlugin(
  id = "twig_debug_mode",
  label = @Translation("Twig debug mode"),
  description = @Translation("Verifies that twig debug settings are disabled."),
  addable = FALSE,
)

Hierarchy

Expanded class hierarchy of TwigDebugSensorPlugin

File

src/Plugin/monitoring/SensorPlugin/TwigDebugSensorPlugin.php, line 24
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\TwigDebugSensorPlugin.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin
View source
class TwigDebugSensorPlugin extends SensorPluginBase {

  /**
   * Holds the container instance.
   *
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * {@inheritdoc}
   */
  public function __construct(SensorConfig $sensor_config, $plugin_id, $plugin_definition, ContainerInterface $container) {
    parent::__construct($sensor_config, $plugin_id, $plugin_definition, $container);
    $this->container = $container;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, SensorConfig $sensor_config, $plugin_id, $plugin_definition) {
    return new static($sensor_config, $plugin_id, $plugin_definition, $container);
  }

  /**
   * {@inheritdoc}
   */
  public function runSensor(SensorResultInterface $result) {
    $twig_config = $this->container
      ->getParameter('twig.config');
    $result
      ->setStatus(SensorResultInterface::STATUS_OK);
    if (!empty($twig_config['debug'])) {
      $result
        ->setStatus(SensorResultInterface::STATUS_WARNING);
      $result
        ->addStatusMessage('Twig debug mode is enabled');
    }
    if (isset($twig_config['cache']) && !$twig_config['cache']) {
      $result
        ->setStatus(SensorResultInterface::STATUS_WARNING);
      $result
        ->addStatusMessage('Twig cache disabled');
    }
    if (!empty($twig_config['auto_reload'])) {
      $result
        ->setStatus(SensorResultInterface::STATUS_WARNING);
      $result
        ->addStatusMessage('Automatic recompilation of Twig templates enabled');
    }
    $sensor_status = $result
      ->getStatus();
    if ($sensor_status == SensorResultInterface::STATUS_OK) {
      $result
        ->addStatusMessage('Optimal configuration');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
SensorPluginBase::$configurableValueType protected property Allows plugins to control if the value type can be configured. 6
SensorPluginBase::$pluginDefinition protected property The plugin implementation definition.
SensorPluginBase::$pluginId protected property The plugin_id.
SensorPluginBase::$sensorConfig protected property Current sensor config object.
SensorPluginBase::$services protected property
SensorPluginBase::addService public function Service setter. Overrides SensorPluginInterface::addService
SensorPluginBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 13
SensorPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides SensorPluginInterface::calculateDependencies 4
SensorPluginBase::getConfigurableValueType public function Configurable value type. Overrides SensorPluginInterface::getConfigurableValueType
SensorPluginBase::getDefaultConfiguration public function Default configuration for a sensor. Overrides SensorPluginInterface::getDefaultConfiguration 8
SensorPluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
SensorPluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
SensorPluginBase::getSensorId public function Gets sensor name (not the label). Overrides SensorPluginInterface::getSensorId
SensorPluginBase::getService public function @todo: Replace with injection Overrides SensorPluginInterface::getService
SensorPluginBase::isEnabled public function Determines if sensor is enabled. Overrides SensorPluginInterface::isEnabled
SensorPluginBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 3
SensorPluginBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TwigDebugSensorPlugin::$container protected property Holds the container instance.
TwigDebugSensorPlugin::create public static function Creates an instance of the sensor with config. Overrides SensorPluginBase::create
TwigDebugSensorPlugin::runSensor public function Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface::runSensor
TwigDebugSensorPlugin::__construct public function Instantiates a sensor object. Overrides SensorPluginBase::__construct