Version 1
[yaffs-website] / vendor / drupal / console-core / src / Command / Shared / ContainerAwareCommandTrait.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait.
6  */
7
8 namespace Drupal\Console\Core\Command\Shared;
9
10 /**
11  * Class CommandTrait
12  * @package Drupal\Console\Core\Command
13  */
14 trait ContainerAwareCommandTrait
15 {
16     use CommandTrait;
17
18     protected $container;
19
20     /**
21      * @param mixed $container
22      */
23     public function setContainer($container)
24     {
25         $this->container = $container;
26     }
27
28     /**
29      * @param $key
30      * @return null|object
31      */
32     public function has($key)
33     {
34         if (!$key) {
35             return null;
36         }
37
38         return $this->container->has($key);
39     }
40
41     /**
42      * @param $key
43      * @return null|object
44      */
45     public function get($key)
46     {
47         if (!$key) {
48             return null;
49         }
50
51         if ($this->has($key)) {
52             return $this->container->get($key);
53         }
54
55         return null;
56     }
57 }