Completed
Pull Request — 3.1 (#290)
by
unknown
09:17
created

DrupalAwareInitializer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
namespace Drupal\DrupalExtension\Context\Initializer;
4
5
use Behat\Behat\Context\Initializer\ContextInitializer;
6
use Behat\Behat\Context\Context;
7
use Behat\Testwork\Hook\HookDispatcher;
8
9
use Drupal\DrupalDriverManager;
10
use Drupal\DrupalExtension\Context\DrupalContext;
11
use Drupal\DrupalExtension\Context\DrupalAwareInterface;
12
13
class DrupalAwareInitializer implements ContextInitializer {
14
  private $drupal, $parameters, $dispatcher;
15
16
  public function __construct(DrupalDriverManager $drupal, array $parameters, HookDispatcher $dispatcher) {
17
    $this->drupal = $drupal;
18
    $this->parameters = $parameters;
19
    $this->dispatcher = $dispatcher;
20
  }
21
22
  /**
23
   * {@inheritdocs}
24
   */
25
  public function initializeContext(Context $context) {
26
27
    // All contexts are passed here, only DrupalAwareInterface is allowed.
28
    if (!$context instanceof DrupalAwareInterface) {
29
      return;
30
    }
31
32
    // Set Drupal driver manager.
33
    $context->setDrupal($this->drupal);
34
35
    // Set event dispatcher.
36
    $context->setDispatcher($this->dispatcher);
37
38
    // Add all parameters to the context.
39
    $context->setDrupalParameters($this->parameters);
40
  }
41
42
}
43