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\DataDefinition\Palette\Builder\Event;
14:
15: use DcGeneral\DataDefinition\Palette\Condition\Palette\PaletteConditionInterface;
16: use DcGeneral\DataDefinition\Palette\Condition\Palette\PropertyValueCondition as PalettePropertyValueCondition;
17: use DcGeneral\DataDefinition\Palette\Condition\Property\PropertyConditionInterface;
18: use DcGeneral\DataDefinition\Palette\Condition\Property\PropertyValueCondition;
19: use DcGeneral\DataDefinition\Palette\Builder\PaletteBuilder;
20: use DcGeneral\Exception\DcGeneralInvalidArgumentException;
21:
22: /**
23: * This event gets emitted when a condition is created.
24: *
25: * @package DcGeneral\DataDefinition\Palette\Builder\Event
26: */
27: class CreateConditionEvent extends BuilderEvent
28: {
29: const NAME = 'dc-general.data-definition.palette.builder.create-condition';
30:
31: /**
32: * The condition being created.
33: *
34: * @var PaletteConditionInterface|PropertyConditionInterface
35: */
36: protected $condition;
37:
38: /**
39: * Create a new instance.
40: *
41: * @param PaletteConditionInterface|PropertyConditionInterface $condition The condition that has been created.
42: *
43: * @param PaletteBuilder $paletteBuilder The palette builder that created the
44: * condition.
45: */
46: public function __construct($condition, PaletteBuilder $paletteBuilder)
47: {
48: $this->setCondition($condition);
49:
50: parent::__construct($paletteBuilder);
51: }
52:
53: /**
54: * Set the condition.
55: *
56: * @param PalettePropertyValueCondition|PropertyValueCondition $condition The condition to use.
57: *
58: * @return CreateConditionEvent
59: *
60: * @throws DcGeneralInvalidArgumentException When an invalid condition has been passed.
61: */
62: public function setCondition($condition)
63: {
64: if ((!$condition instanceof PaletteConditionInterface) && (!$condition instanceof PropertyConditionInterface))
65: {
66: throw new DcGeneralInvalidArgumentException();
67: }
68:
69: $this->condition = $condition;
70:
71: return $this;
72: }
73:
74: /**
75: * Retrieve the condition.
76: *
77: * @return PalettePropertyValueCondition|PropertyValueCondition
78: */
79: public function getCondition()
80: {
81: return $this->condition;
82: }
83: }
84: