|
3 | 3 | namespace Drupal\qa\Plugin\Qa\Control; |
4 | 4 |
|
5 | 5 | use Drupal\Component\Utility\Crypt; |
| 6 | +use Drupal\Core\PrivateKey; |
6 | 7 | use Drupal\qa\Exportable; |
7 | 8 | use Drupal\qa\Pass; |
8 | 9 | use Drupal\qa\Plugin\QaCheckInterface; |
@@ -49,19 +50,32 @@ abstract class BaseControl extends Exportable implements QaCheckInterface { |
49 | 50 | */ |
50 | 51 | protected static $packages = []; |
51 | 52 |
|
| 53 | + /** |
| 54 | + * The private_key service. |
| 55 | + * |
| 56 | + * @var \Drupal\Core\PrivateKey |
| 57 | + */ |
| 58 | + protected $pk; |
| 59 | + |
52 | 60 | /** |
53 | 61 | * BaseControl constructor. |
| 62 | + * |
| 63 | + * @param \Drupal\Core\PrivateKey $pk |
| 64 | + * The private_ket service. |
54 | 65 | */ |
55 | | - public function __construct() { |
| 66 | + public function __construct(PrivateKey $pk) { |
56 | 67 | parent::__construct(); |
57 | 68 | $this->package_name = $this->namespace; |
| 69 | + $this->pk = $pk; |
58 | 70 | } |
59 | 71 |
|
60 | 72 | /** |
61 | 73 | * {@inheritdoc} |
62 | 74 | */ |
63 | 75 | public static function create(ContainerInterface $container) { |
64 | | - return new static(); |
| 76 | + $pk = $container->get('private_key'); |
| 77 | + assert($pk instanceof PrivateKey); |
| 78 | + return new static($pk); |
65 | 79 | } |
66 | 80 |
|
67 | 81 | /** |
@@ -141,7 +155,7 @@ public static function getControls($package_name = NULL) { |
141 | 155 | */ |
142 | 156 | public function run(): Pass { |
143 | 157 | global $base_url; |
144 | | - $site_key = Crypt::hmacBase64($base_url, \Drupal::service('private_key')->get()); |
| 158 | + $site_key = Crypt::hmacBase64($base_url, $this->pk->get()); |
145 | 159 | $key = uniqid($site_key); |
146 | 160 | $pass = new Pass($this); |
147 | 161 | $this->passes[$key] = $pass; |
|
0 commit comments