ConfigurationItem.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php
  2. namespace Drupal\features;
  3. /**
  4. * Contains some configuration together with metadata like the name + package.
  5. *
  6. * @todo Should the object be immutable?
  7. * @todo Should this object have an interface?
  8. */
  9. class ConfigurationItem {
  10. /**
  11. * Prefixed configuration item name.
  12. *
  13. * @var string
  14. */
  15. protected $name;
  16. /**
  17. * Configuration item name without prefix.
  18. *
  19. * @var string
  20. */
  21. protected $shortName;
  22. /**
  23. * Human readable name of configuration item.
  24. *
  25. * @var string
  26. */
  27. protected $label;
  28. /**
  29. * Type of configuration.
  30. *
  31. * @var string
  32. */
  33. protected $type;
  34. /**
  35. * The contents of the configuration item in exported format.
  36. *
  37. * @var array
  38. */
  39. protected $data;
  40. /**
  41. * Array of names of dependent configuration items.
  42. *
  43. * @var string[]
  44. */
  45. protected $dependents = [];
  46. /**
  47. * Feature subdirectory to export item to.
  48. *
  49. * @var string
  50. */
  51. protected $subdirectory;
  52. /**
  53. * Machine name of a package the configuration is assigned to.
  54. *
  55. * @var string
  56. */
  57. protected $package;
  58. /**
  59. * Whether the configuration is marked as excluded.
  60. *
  61. * @var bool
  62. */
  63. protected $excluded = FALSE;
  64. /**
  65. * Whether the configuration provider is excluded.
  66. *
  67. * @var bool
  68. */
  69. protected $providerExcluded = FALSE;
  70. /**
  71. * The provider of the config item.
  72. *
  73. * @var string
  74. */
  75. protected $provider;
  76. /**
  77. * Array of package names that this item should be excluded from.
  78. *
  79. * @var string[]
  80. */
  81. protected $packageExcluded = [];
  82. /**
  83. * Creates a new ConfigurationItem instance.
  84. *
  85. * @param string $name
  86. * The config name.
  87. * @param array $data
  88. * The config data.
  89. * @param array $additional_properties
  90. * (optional) Additional properties set on the object.
  91. */
  92. public function __construct($name, array $data, array $additional_properties = []) {
  93. $this->name = $name;
  94. $this->data = $data;
  95. $properties = get_object_vars($this);
  96. foreach ($additional_properties as $property => $value) {
  97. if (!array_key_exists($property, $properties)) {
  98. throw new \InvalidArgumentException('Invalid property: ' . $property);
  99. }
  100. $this->{$property} = $value;
  101. }
  102. }
  103. /**
  104. * Calculates the config type usable in configuration.
  105. *
  106. * By default Drupal uses system.simple as config type, which cannot be used
  107. * inside configuration itself. Therefore convert it to system_simple.
  108. *
  109. * @param string $type
  110. * The config type provided by core.
  111. *
  112. * @return string
  113. * The config type as string without dots.
  114. */
  115. public static function fromConfigTypeToConfigString($type) {
  116. return $type == 'system.simple' ? FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG : $type;
  117. }
  118. /**
  119. * Converts a config type string in configuration back to the config type.
  120. *
  121. * @param string $type
  122. * The config type as string without dots.
  123. *
  124. * @return string
  125. * The config type provided by core.
  126. */
  127. public static function fromConfigStringToConfigType($type) {
  128. return $type == FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG ? 'system.simple' : $type;
  129. }
  130. /**
  131. * @return mixed
  132. */
  133. public function getName() {
  134. return $this->name;
  135. }
  136. /**
  137. * @param mixed $name
  138. *
  139. * @return ConfigurationItem
  140. */
  141. public function setName($name) {
  142. $this->name = $name;
  143. return $this;
  144. }
  145. /**
  146. * @return mixed
  147. */
  148. public function getShortName() {
  149. return $this->shortName;
  150. }
  151. /**
  152. * @param mixed $shortName
  153. *
  154. * @return ConfigurationItem
  155. */
  156. public function setShortName($shortName) {
  157. $this->shortName = $shortName;
  158. return $this;
  159. }
  160. /**
  161. * @return mixed
  162. */
  163. public function getLabel() {
  164. return $this->label;
  165. }
  166. /**
  167. * @param mixed $label
  168. *
  169. * @return ConfigurationItem
  170. */
  171. public function setLabel($label) {
  172. $this->label = $label;
  173. return $this;
  174. }
  175. /**
  176. * @return mixed
  177. */
  178. public function getType() {
  179. return $this->type;
  180. }
  181. /**
  182. * @param mixed $type
  183. *
  184. * @return ConfigurationItem
  185. */
  186. public function setType($type) {
  187. $this->type = $type;
  188. return $this;
  189. }
  190. /**
  191. * @return mixed
  192. */
  193. public function getData() {
  194. return $this->data;
  195. }
  196. /**
  197. * @param mixed array
  198. *
  199. * @return ConfigurationItem
  200. */
  201. public function setData(array $data) {
  202. $this->data = $data;
  203. return $this;
  204. }
  205. /**
  206. * @return string[]
  207. */
  208. public function getDependents() {
  209. return $this->dependents;
  210. }
  211. /**
  212. * @param array $dependents
  213. *
  214. * @return ConfigurationItem
  215. */
  216. public function setDependents($dependents) {
  217. $this->dependents = $dependents;
  218. return $this;
  219. }
  220. /**
  221. * @return mixed
  222. */
  223. public function getSubdirectory() {
  224. return $this->subdirectory;
  225. }
  226. /**
  227. * @param mixed $subdirectory
  228. *
  229. * @return ConfigurationItem
  230. */
  231. public function setSubdirectory($subdirectory) {
  232. $this->subdirectory = $subdirectory;
  233. return $this;
  234. }
  235. /**
  236. * @return mixed
  237. */
  238. public function getPackage() {
  239. return $this->package;
  240. }
  241. /**
  242. * @param mixed $package
  243. *
  244. * @return ConfigurationItem
  245. */
  246. public function setPackage($package) {
  247. $this->package = $package;
  248. return $this;
  249. }
  250. /**
  251. * @return boolean
  252. */
  253. public function isExcluded() {
  254. return $this->excluded;
  255. }
  256. /**
  257. * @param boolean $excluded
  258. *
  259. * @return ConfigurationItem
  260. */
  261. public function setExcluded($excluded) {
  262. $this->excluded = $excluded;
  263. return $this;
  264. }
  265. /**
  266. * @return boolean
  267. */
  268. public function isProviderExcluded() {
  269. return $this->providerExcluded;
  270. }
  271. /**
  272. * @param boolean $providerExcluded
  273. *
  274. * @return ConfigurationItem
  275. */
  276. public function setProviderExcluded($providerExcluded) {
  277. $this->providerExcluded = $providerExcluded;
  278. return $this;
  279. }
  280. /**
  281. * @return string
  282. */
  283. public function getProvider() {
  284. return $this->provider;
  285. }
  286. /**
  287. * @param string $provider
  288. */
  289. public function setProvider($provider) {
  290. $this->provider = $provider;
  291. return $this;
  292. }
  293. /**
  294. * @return string[]
  295. */
  296. public function getPackageExcluded() {
  297. return $this->packageExcluded;
  298. }
  299. /**
  300. * @param array $packageExcluded
  301. *
  302. * @return ConfigurationItem
  303. */
  304. public function setPackageExcluded($packageExcluded) {
  305. $this->packageExcluded = $packageExcluded;
  306. return $this;
  307. }
  308. }