<commit_before><?php
namespace Drupal\AppConsole\Command\Helper;

use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\DrupalKernel;

class KernelHelper extends Helper {

  /**
   * @var DrupalKernel
   */
  protected $kernel;

  /**
   * @var string
   */
  protected $environment;

  /**
   * @var boolean
   */
  protected $debug;

  /**
   * @param DrupalKernel $kernel
   */
  public function setKernel(DrupalKernel $kernel) {
    $this->kernel = $kernel;
  }

  /**
   * @return DrupalKernel
   */
  public function getKernel() {
    if (!$this->kernel) {
      $this->kernel = new DrupalKernel($this->environment, \drupal_classloader(), !$this->debug);
    }

    return $this->kernel;
  }

  /**
   * @param string $environment
   */
  public function setEnvironment($environment) {
    $this->environment = $environment;
  }

  /**
   * @param boolean $debug
   */
  public function setDebug($debug) {
    $this->debug = $debug;
  }

  /**
   * @return void
   */
  public function bootKernel() {
    $this->getKernel()->boot();

    $container = $this->getKernel()->getContainer();
    $request = Request::createFromGlobals();
    $container->set('request', $request);
    $container->get('request_stack')->push($request);

    // Load Drupal Bootstrap Code: load code for subsystems and modules.
    $this->getHelperSet()->get('bootstrap')->bootstrapCode();
  }

  /**
   * @param array $commands
   */<commit_msg>Register Validator Class as Service<commit_after><?php
namespace Drupal\AppConsole\Command\Helper;

use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\DrupalKernel;

class KernelHelper extends Helper {

  /**
   * @var DrupalKernel
   */
  protected $kernel;

  /**
   * @var string
   */
  protected $environment;

  /**
   * @var boolean
   */
  protected $debug;

  /**
   * @param DrupalKernel $kernel
   */
  public function setKernel(DrupalKernel $kernel) {
    $this->kernel = $kernel;
  }

  /**
   * @return DrupalKernel
   */
  public function getKernel() {
    if (!$this->kernel) {
      $this->kernel = new DrupalKernel($this->environment, \drupal_classloader(), !$this->debug);
    }

    return $this->kernel;
  }

  /**
   * @param string $environment
   */
  public function setEnvironment($environment) {
    $this->environment = $environment;
  }

  /**
   * @param boolean $debug
   */
  public function setDebug($debug) {
    $this->debug = $debug;
  }

  /**
   * @return void
   */
  public function bootKernel() {
    $this->getKernel()->boot();

    $container = $this->getKernel()->getContainer();
    $request = Request::createFromGlobals();
    $container->set('request', $request);
    $container->get('request_stack')->push($request);

    // Load Drupal Bootstrap Code: load code for subsystems and modules.
    $this->getHelperSet()->get('bootstrap')->bootstrapCode();
    
    // Register Validator Service manually
    // TODO load from file console.services.yml move to a Helper or another class
    $container->set(
      'console.validators',
      new \Drupal\AppConsole\Command\Validators()
    );

  }

  /**
   * @param array $commands
   */
{'fraction_non_alphanumeric': 0.15159653834676215, 'fraction_numerical': 0.0, 'mean_word_length': 3.1795511221945136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7054724', 'n_tokens_mistral': 1015, 'n_tokens_neox': 1002, 'n_words': 210}