Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / src / ApplicationFactory.php
diff --git a/vendor/chi-teck/drupal-code-generator/src/ApplicationFactory.php b/vendor/chi-teck/drupal-code-generator/src/ApplicationFactory.php
new file mode 100644 (file)
index 0000000..40c3f3f
--- /dev/null
@@ -0,0 +1,61 @@
+<?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;
+  }
+
+}