PHPackages                             ekino/drupal-debug - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. ekino/drupal-debug

AbandonedArchivedComposer-plugin[Debugging &amp; Profiling](/categories/debugging)

ekino/drupal-debug
==================

Provides an alternative Debug Kernel for Drupal 8 to improve the Developer eXperience.

v0.1.0-alpha(6y ago)316778[16 issues](https://github.com/ekino/drupal-debug/issues)[2 PRs](https://github.com/ekino/drupal-debug/pulls)MITPHPPHP &gt;=7.1

Since Jan 13Pushed 6y ago9 watchersCompare

[ Source](https://github.com/ekino/drupal-debug)[ Packagist](https://packagist.org/packages/ekino/drupal-debug)[ RSS](/packages/ekino-drupal-debug/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (29)Versions (4)Used By (0)

Drupal Debug
============

[](#drupal-debug)

[![Build Status](https://camo.githubusercontent.com/b116b83632863b24301c4adc0766ec0328b81b0f2e1024ee3302a749bfc5b9fb/68747470733a2f2f7472617669732d63692e6f72672f656b696e6f2f64727570616c2d64656275672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ekino/drupal-debug)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3a1359eaf2d259a161f4b9e264e74aa47ed0ff95e85275fdbbf49d6f0761fe88/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656b696e6f2f64727570616c2d64656275672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ekino/drupal-debug/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/077cd701e8776e70221e3514e35bf9ebbd0271c603b091e0e1c5a116f8a1230b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656b696e6f2f64727570616c2d64656275672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ekino/drupal-debug/?branch=master)

---

This library provides an alternative Kernel for Drupal 8 to improve the Developer eXperience during the development process.

This Debug Kernel extends (but substitutes entirely by default) the original Drupal Kernel in order to alter some inner Drupal behaviors. It is done for one reason: help you develop better and faster!

Once this library is installed, you will be able to experience a « debug mode » during the development process. For example, you will not need to manually clear the cache anymore when you add or remove a custom service, a route or a module hook implementation.

Requirements
============

[](#requirements)

This library requires that your Drupal project uses [Composer](https://getcomposer.org/). If it is not the case yet, you can check [this Composer template for Drupal projects](https://github.com/drupal-composer/drupal-project) for example.

It has active support for the [latest released Drupal minor version](https://www.drupal.org/project/drupal/releases) only.

It has active support for the [currently supported versions of PHP](http://php.net/supported-versions.php) only.

Installation
============

[](#installation)

Require this library as a development dependency.

```
composer require ekino/drupal-debug --dev

```

It **MUST** only be installed as a development dependency. You do not want to use it in production!

Actions
=======

[](#actions)

This library works with « actions ». An action has an unique goal that improves your development experience with Drupal.

At the moment, all actions are enabled and mandatory but the plan is to make most of them optional, step by step.

Also, you cannot provide your own custom actions yet but this is planned for the future as well.

Here is the list of the current available actions and how they help you:

NameDescriptionDisable CSS AggregationDisable CSS files aggregationDisable Dynamic Page CacheDisable [Drupal Dynamic Page Cache](https://www.drupal.org/docs/8/core/modules/dynamic-page-cache)Disable Internal Page CacheDisable [Drupal Internal Page Cache](https://www.drupal.org/docs/8/administering-a-drupal-8-site/internal-page-cache)Disable JS AggregationDisable JS files aggregationDisable Render CacheDisable [Drupal Render Cache](https://www.drupal.org/docs/8/api/render-api/cacheability-of-render-arrays)Disable Twig CacheDisable Twig CacheDisplay Dump LocationDisplay location when you use the `dump()` function of the Symfony VarDumper componentDisplay Pretty ExceptionsDisplay a better looking exception page and log exceptions (active when the `Request` is handled by the Kernel and if the exceptions are caught)Display Pretty Exceptions ASAPDisplay a better looking exception page (active as soon as the Kernel is instantiated)Enable Debug Class LoaderEnable the `DebugClassLoader` of the Symfony Debug componentEnable Twig DebugEnable Twig Debug modeEnable Twig Strict VariablesEnable Twig `strict_variables` option (disabled at the moment because the [Drupal core is not ready](https://www.drupal.org/project/drupal/issues/2445705) at all)Throw Errors As ExceptionsThrow PHP errors as exceptionsWatch Container DefinitionsWatch services definitions and service providers files to automatically invalidate the container definitionWatch Modules Hooks ImplementationsWatch `.module` files to automatically refresh the modules hooks implementationsWatch Routing DefinitionsWatch routing definitions files to automatically rebuild the routesAnd more to come!

Configuration
=============

[](#configuration)

Some actions are configurable with options that can be set in a dedicated configuration file. However, this configuration file is not mandatory because every option has a default value that is resolved if it is not explicitly defined.

At the moment, those options are not configurable independently for each action (with this file) but this is of course planned. What is configurable is actually the defaults values of reused options. If you want to specify options for each actions, you have to [manually use the Debug Kernel](#manually-use-the-debug-kernel).

Here is the default configuration file content (i.e. the default resolved configuration if the configuration file does not exist, or if a key is not defined):

```
# This is the drupal-debug configuration file.
drupal-debug:

    # The defaults values are common values that are reused by different actions.
    defaults:
        cache_directory_path: cache
        logger:
            enabled: true
            channel: drupal-debug
            file_path: logs/drupal-debug.log
        charset: null
        file_link_format: null

    # It is recommended to disable the original Drupal Kernel substitution to run your tests.
    # To programmatically toggle it, use the two dedicated composer commands.
    substitute_original_drupal_kernel:
        enabled: true
        composer_autoload_file_path: vendor/autoload.php

        # If not specified, it fall backs to the default cache directory path.
        cache_directory_path: null
```

By default, the location of this configuration file is the root of the project (the parent directory of the Composer vendor directory). But it can be defined with the `DRUPAL_DEBUG_CONFIGURATION_FILE_PATH` environment variable.

For performance, the resolved configuration is cached. By default, the location of this cache is the system temporary directory. But it can be defined with the `DRUPAL_DEBUG_CONFIGURATION_CACHE_DIRECTORY_PATH` environment variable.

Here is the list of all the actions that have options :

#### Display Pretty Exceptions

[](#display-pretty-exceptions)

- charset: The charset of the exception page.
- fileLinkFormat: The file link format used to create links to your IDE.
- logger: A `LoggerInterface` instance to log exceptions.

#### Display Pretty Exceptions ASAP

[](#display-pretty-exceptions-asap)

- charset: The charset of the exception page.
- fileLinkFormat: The file link format used to create links to your IDE.

#### Throw Errors As Exceptions

[](#throw-errors-as-exceptions)

- levels: Required. The bit field of E\_\* constants for thrown errors.
- logger: A `LoggerInterface` instance to log errors.

#### Watch Container Definitions

[](#watch-container-definitions)

- cacheFilePath: Required. The location of the cached container definition file.
- resourcesCollection: Required. An `ResourcesCollection` instance (the resources to watch).

#### Watch Modules Hooks Implementations

[](#watch-modules-hooks-implementations)

- cacheFilePath: Required. The location of the cached modules hooks implementations file.
- resourcesCollection: Required. An `ResourcesCollection` instance (the resources to watch).

#### Watch Routing Definitions

[](#watch-routing-definitions)

- cacheFilePath: Required. The location of the cached routing file.
- resourcesCollection: Required. An `ResourcesCollection` instance (the resources to watch).

Composer commands
=================

[](#composer-commands)

Here is the list of the provided Composer commands that help you manage the configuration file:

CommandAliasDescriptioncomposer drupal-debug:dump-reference-configuration-fileNoneDump the reference configuration filecomposer drupal-debug:disable-original-drupal-kernel-substitutioncomposer drupal-debug:disableAlter the configuration file to disable the original Drupal Kernel substitutioncomposer drupal-debug:enable-original-drupal-kernel-substitutioncomposer drupal-debug:enableAlter the configuration file to enable the original Drupal Kernel substitutionOriginal Drupal Kernel substitution
===================================

[](#original-drupal-kernel-substitution)

Substituting the original Drupal Kernel concretely means that every time the `DrupalKernel` class is used somewhere after the Composer autoload file has been required, it is this library `DebugKernel` class that is actually being used, despite appearances!

It is great because any third party libraries interacting with Drupal (such as `drush` for example) will automatically use the Debug Kernel.

However, it could lead to unwanted behaviors, especially during the WIP phase of this library. This is why you **SHOULD NOT** use the original Drupal Kernel substitution when you run your tests for example. Keep it for the development part only!

Manually use the Debug Kernel
=============================

[](#manually-use-the-debug-kernel)

It is possible to directly use the Debug Kernel in your front controller (typically the `index.php` file in your web exposed directory) to specify options for each actions. It is also the solution to use the Debug Kernel with the original Drupal Kernel substitution disabled.

You simply need to use the `OptionsStackBuilder` helper class to build an `OptionsStack` instance and pass it to the `DebugKernel` constructor.

Manually setting an option in the options stack overrides the default value defined by the configuration (if it exists).

Here is an example usage:

```
