Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Config / Entity / ConfigEntityDependency.php
1 <?php
2
3 namespace Drupal\Core\Config\Entity;
4
5 use Drupal\Component\Utility\NestedArray;
6
7 /**
8  * Provides a value object to discover configuration dependencies.
9  *
10  * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
11  */
12 class ConfigEntityDependency {
13
14   /**
15    * The configuration entity's configuration object name.
16    *
17    * @var string
18    */
19   protected $name;
20
21   /**
22    * The configuration entity's dependencies.
23    *
24    * @var array
25    */
26   protected $dependencies = [];
27
28   /**
29    * Constructs the configuration entity dependency from the entity values.
30    *
31    * @param string $name
32    *   The configuration entity's configuration object name.
33    * @param array $values
34    *   (optional) The configuration entity's values.
35    */
36   public function __construct($name, $values = []) {
37     $this->name = $name;
38     if (isset($values['dependencies']) && isset($values['dependencies']['enforced'])) {
39       // Merge the enforced dependencies into the list of dependencies.
40       $enforced_dependencies = $values['dependencies']['enforced'];
41       unset($values['dependencies']['enforced']);
42       $this->dependencies = NestedArray::mergeDeep($values['dependencies'], $enforced_dependencies);
43     }
44     elseif (isset($values['dependencies'])) {
45       $this->dependencies = $values['dependencies'];
46     }
47   }
48
49   /**
50    * Gets the configuration entity's dependencies of the supplied type.
51    *
52    * @param string $type
53    *   The type of dependency to return. Either 'module', 'theme', 'config' or
54    *   'content'.
55    *
56    * @return array
57    *   The list of dependencies of the supplied type.
58    */
59   public function getDependencies($type) {
60     $dependencies = [];
61     if (isset($this->dependencies[$type])) {
62       $dependencies = $this->dependencies[$type];
63     }
64     if ($type == 'module') {
65       $dependencies[] = substr($this->name, 0, strpos($this->name, '.'));
66     }
67     return $dependencies;
68   }
69
70   /**
71    * Determines if the entity is dependent on extensions or entities.
72    *
73    * @param string $type
74    *   The type of dependency being checked. Either 'module', 'theme', 'config'
75    *   or 'content'.
76    * @param string $name
77    *   The specific name to check. If $type equals 'module' or 'theme' then it
78    *   should be a module name or theme name. In the case of entity it should be
79    *   the full configuration object name.
80    *
81    * @return bool
82    */
83   public function hasDependency($type, $name) {
84     // A config entity is always dependent on its provider.
85     if ($type == 'module' && strpos($this->name, $name . '.') === 0) {
86       return TRUE;
87     }
88     return isset($this->dependencies[$type]) && array_search($name, $this->dependencies[$type]) !== FALSE;
89   }
90
91   /**
92    * Gets the configuration entity's configuration dependency name.
93    *
94    * @see \Drupal\Core\Entity\EntityInterface::getConfigDependencyName()
95    *
96    * @return string
97    *   The configuration dependency name for the entity.
98    */
99   public function getConfigDependencyName() {
100     return $this->name;
101   }
102
103 }