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