1: <?php
2: /**
3: * PHP version 5
4: * @package generalDriver
5: * @author Christian Schiffler <c.schiffler@cyberspectrum.de>
6: * @author Stefan Heimes <stefan_heimes@hotmail.com>
7: * @author Tristan Lins <tristan.lins@bit3.de>
8: * @copyright The MetaModels team.
9: * @license LGPL.
10: * @filesource
11: */
12:
13: namespace DcGeneral;
14:
15: use DcGeneral\DataDefinition\ContainerInterface;
16: use DcGeneral\Exception\DcGeneralInvalidArgumentException;
17:
18: /**
19: * Default implementation of the data definition container.
20: *
21: * This container holds all created data definitions.
22: *
23: * @package DcGeneral
24: */
25: class DataDefinitionContainer
26: implements DataDefinitionContainerInterface
27: {
28: /**
29: * The definitions stored in the container.
30: *
31: * @var ContainerInterface[]
32: */
33: protected $definitions;
34:
35: /**
36: * {@inheritDoc}
37: */
38: public function setDefinition($name, $definition)
39: {
40: if ($definition)
41: {
42: $this->definitions[$name] = $definition;
43: }
44: else
45: {
46: unset($this->definitions[$name]);
47: }
48:
49: return $this;
50: }
51:
52: /**
53: * {@inheritDoc}
54: */
55: public function hasDefinition($name)
56: {
57: return isset($this->definitions[$name]);
58: }
59:
60: /**
61: * {@inheritDoc}
62: *
63: * @throws DcGeneralInvalidArgumentException When a definition is requested that is not contained.
64: */
65: public function getDefinition($name)
66: {
67: if (!$this->hasDefinition($name))
68: {
69: throw new DcGeneralInvalidArgumentException('Data definition ' . $name . ' is not contained.');
70: }
71:
72: return $this->definitions[$name];
73: }
74: }
75: