You are here

class DrupalCodeBuilder in Module Builder 8.3

Service class that wraps around the DCB library, to make it injectable.

Hierarchy

Expanded class hierarchy of DrupalCodeBuilder

5 files declare their use of DrupalCodeBuilder
ComponentFormBase.php in src/Form/ComponentFormBase.php
DrupalCodeBuilderDevel.php in module_builder_devel/src/DrupalCodeBuilderDevel.php
DrupalCodeBuilderTestSampleData.php in tests/modules/test_dummy_module_write_location/src/DrupalCodeBuilderTestSampleData.php
DrupalCodeBuilderTestSamples.php in module_builder_devel/src/DrupalCodeBuilderTestSamples.php
TestDrupalCodeBuilder.php in tests/modules/module_builder_test_component_type/src/TestDrupalCodeBuilder.php
1 string reference to 'DrupalCodeBuilder'
module_builder.services.yml in ./module_builder.services.yml
module_builder.services.yml
1 service uses DrupalCodeBuilder
module_builder.drupal_code_builder in ./module_builder.services.yml
Drupal\module_builder\DrupalCodeBuilder

File

src/DrupalCodeBuilder.php, line 8

Namespace

Drupal\module_builder
View source
class DrupalCodeBuilder {

  /**
   * Whether the library has been initialized.
   *
   * @var bool
   */
  protected $loaded = FALSE;

  /**
   * Gets a task handler from the library.
   *
   * Same parameters as \DrupalCodeBuilder\Factory::getTask().
   *
   * @param string $task_name
   *   The task name.
   * @param mixed $task_options
   *   (optional) Options for the task.
   *
   * @return
   *   The task object.
   */
  public function getTask($task_name, $task_options = NULL) {
    if (!$this->loaded) {
      $this
        ->loadLibrary();
    }
    return \DrupalCodeBuilder\Factory::getTask($task_name, $task_options);
  }

  /**
   * Loads the Drupal Coder Builder library and sets the environment.
   *
   * @throws \Exception
   *  Throws an exception if the library can't be found.
   */
  public function loadLibrary() {
    if (!class_exists(\DrupalCodeBuilder\Factory::class)) {
      throw new \Exception("Mising library.");
    }
    $this
      ->doLoadLibrary();
    $this->loaded = TRUE;
  }

  /**
   * Helper for loadLibrary() for ease of overriding.
   */
  protected function doLoadLibrary() {

    // TODO: add an environment class with a more appropriate name.
    \DrupalCodeBuilder\Factory::setEnvironmentLocalClass('DrupalLibrary')
      ->setCoreVersionNumber(\Drupal::VERSION);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalCodeBuilder::$loaded protected property Whether the library has been initialized.
DrupalCodeBuilder::doLoadLibrary protected function Helper for loadLibrary() for ease of overriding. 4
DrupalCodeBuilder::getTask public function Gets a task handler from the library.
DrupalCodeBuilder::loadLibrary public function Loads the Drupal Coder Builder library and sets the environment.