Completed
Push — Leksat-patch-1 ( 31c1c0...66f278 )
by Jonathan
01:23
created

DrupalSubContextBase::getContext()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Drupal\DrupalExtension\Context\DrupalSubContextBase.
6
 */
7
8
namespace Drupal\DrupalExtension\Context;
9
10
use Drupal\DrupalDriverManager;
11
12
/**
13
 * Base class for subcontexts that use the Drupal API.
14
 */
15
abstract class DrupalSubContextBase extends RawDrupalContext implements DrupalSubContextInterface {
16
17
  /**
18
   * The Drupal Driver Manager.
19
   *
20
   * @var \Drupal\DrupalDriverManager $drupal
21
   */
22
  protected $drupal;
23
24
  /**
25
   * Constructs a DrupalSubContextBase object.
26
   *
27
   * @param \Drupal\DrupalDriverManager $drupal
28
   *   The Drupal driver manager.
29
   */
30
  public function __construct(DrupalDriverManager $drupal) {
31
    $this->drupal = $drupal;
32
  }
33
34
  /**
35
   * Get the currently logged in user from DrupalContext.
36
   *
37
   * @deprecated
38
   *   Deprecated in 4.x, will be removed before 5.x.
39
   *   The currently logged in user is now available in all context classes.
40
   *   Use $this->getUserManager()->getCurrentUser() instead.
41
   */
42
  protected function getUser() {
43
    trigger_error('DrupalSubContextBase::getUser() is deprecated. Use RawDrupalContext::getUserManager()->getCurrentUser() instead.', E_USER_DEPRECATED);
44
45
    $user = $this->getUserManager()->getCurrentUser();
46
47
    if (empty($user)) {
48
      throw new \Exception('No user is logged in.');
49
    }
50
51
    return $user;
52
  }
53
54
}
55