view vendor/chi-teck/drupal-code-generator/src/ApplicationFactory.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
line wrap: on
line source
<?php

namespace DrupalCodeGenerator;

use DrupalCodeGenerator\Helper\Dumper;
use DrupalCodeGenerator\Helper\InputHandler;
use DrupalCodeGenerator\Helper\OutputHandler;
use DrupalCodeGenerator\Helper\Renderer;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Filesystem\Filesystem;

/**
 * DCG application factory.
 */
class ApplicationFactory {

  /**
   * Determines path to DCG root directory.
   *
   * @return string
   *   Path to DCG root directory.
   */
  public static function getRoot() {
    return dirname(__DIR__);
  }

  /**
   * Creates an application.
   *
   * @return \Symfony\Component\Console\Application
   *   The initialized console application.
   */
  public static function create() {
    // This gets substituted with git version when DCG is packaged to PHAR file.
    $version = '@git-version@';
    // Fallback for composer installation.
    if (!is_numeric($version[0])) {
      $version = 'UNKNOWN';
    }
    $application = new Application('Drupal Code Generator', $version);

    $helper_set = new HelperSet([
      new QuestionHelper(),
      new Dumper(new Filesystem()),
      // We cannot reference the TwigEnvironment class with use statement
      // because of a PHP bug.
      // @see https://bugs.php.net/bug.php?id=66773
      // @codingStandardsIgnoreStart
      new Renderer(new \DrupalCodeGenerator\Twig\TwigEnvironment(new \Twig_Loader_Filesystem())),
      // @codingStandardsIgnoreEnd
      new InputHandler(),
      new OutputHandler(),
    ]);
    $application->setHelperSet($helper_set);

    return $application;
  }

}