annotate 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
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace DrupalCodeGenerator;
Chris@0 4
Chris@0 5 use DrupalCodeGenerator\Helper\Dumper;
Chris@0 6 use DrupalCodeGenerator\Helper\InputHandler;
Chris@0 7 use DrupalCodeGenerator\Helper\OutputHandler;
Chris@0 8 use DrupalCodeGenerator\Helper\Renderer;
Chris@0 9 use Symfony\Component\Console\Application;
Chris@0 10 use Symfony\Component\Console\Helper\HelperSet;
Chris@0 11 use Symfony\Component\Console\Helper\QuestionHelper;
Chris@0 12 use Symfony\Component\Filesystem\Filesystem;
Chris@0 13
Chris@0 14 /**
Chris@0 15 * DCG application factory.
Chris@0 16 */
Chris@0 17 class ApplicationFactory {
Chris@0 18
Chris@0 19 /**
Chris@0 20 * Determines path to DCG root directory.
Chris@0 21 *
Chris@0 22 * @return string
Chris@0 23 * Path to DCG root directory.
Chris@0 24 */
Chris@0 25 public static function getRoot() {
Chris@0 26 return dirname(__DIR__);
Chris@0 27 }
Chris@0 28
Chris@0 29 /**
Chris@0 30 * Creates an application.
Chris@0 31 *
Chris@0 32 * @return \Symfony\Component\Console\Application
Chris@0 33 * The initialized console application.
Chris@0 34 */
Chris@0 35 public static function create() {
Chris@0 36 // This gets substituted with git version when DCG is packaged to PHAR file.
Chris@0 37 $version = '@git-version@';
Chris@0 38 // Fallback for composer installation.
Chris@0 39 if (!is_numeric($version[0])) {
Chris@0 40 $version = 'UNKNOWN';
Chris@0 41 }
Chris@0 42 $application = new Application('Drupal Code Generator', $version);
Chris@0 43
Chris@0 44 $helper_set = new HelperSet([
Chris@0 45 new QuestionHelper(),
Chris@0 46 new Dumper(new Filesystem()),
Chris@0 47 // We cannot reference the TwigEnvironment class with use statement
Chris@0 48 // because of a PHP bug.
Chris@0 49 // @see https://bugs.php.net/bug.php?id=66773
Chris@0 50 // @codingStandardsIgnoreStart
Chris@0 51 new Renderer(new \DrupalCodeGenerator\Twig\TwigEnvironment(new \Twig_Loader_Filesystem())),
Chris@0 52 // @codingStandardsIgnoreEnd
Chris@0 53 new InputHandler(),
Chris@0 54 new OutputHandler(),
Chris@0 55 ]);
Chris@0 56 $application->setHelperSet($helper_set);
Chris@0 57
Chris@0 58 return $application;
Chris@0 59 }
Chris@0 60
Chris@0 61 }