1 | <?php |
||
50 | trait ProcessingInstructionsTrait |
||
51 | { |
||
52 | /** |
||
53 | * Processing instructions |
||
54 | * |
||
55 | * @var GenericPropertiesInterface |
||
56 | */ |
||
57 | protected $processingInstructions; |
||
58 | |||
59 | /** |
||
60 | * Get a processing instruction |
||
61 | * |
||
62 | * @param string $procInst Processing instruction name |
||
63 | * @return mixed Processing instruction |
||
64 | */ |
||
65 | public function getProcessingInstruction($procInst) |
||
66 | { |
||
67 | return $this->processingInstructions->getProperty($procInst); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Set a processing instruction |
||
72 | * |
||
73 | * @param string $procInst Processing instruction name |
||
74 | * @param mixed $value Processing instruction |
||
75 | * @return ObjectInterface Self reference |
||
76 | */ |
||
77 | 1 | public function setProcessingInstruction($procInst, $value) |
|
78 | { |
||
79 | 1 | $this->setProcessingInstructions($this->processingInstructions->setProperty($procInst, $value)); |
|
80 | 1 | return $this; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Set the processing instruction collection |
||
85 | * |
||
86 | * @param GenericPropertiesInterface $procInstructions Processing instruction collection |
||
87 | * @param bool $overwrite Overwrite the existing collection (if present) |
||
88 | */ |
||
89 | 45 | protected function setProcessingInstructions(GenericPropertiesInterface $procInstructions, $overwrite = false) |
|
90 | { |
||
91 | 45 | $this->processingInstructions = $procInstructions; |
|
92 | 45 | $procInstState = spl_object_hash($this->processingInstructions); |
|
93 | |||
94 | // If the domain property collection state has changed |
||
95 | 45 | if (!$overwrite |
|
96 | 45 | && !empty($this->collectionStates[ProcessingInstructions::COLLECTION]) |
|
97 | 45 | && ($procInstState !== $this->collectionStates[ProcessingInstructions::COLLECTION]) |
|
98 | ) { |
||
99 | // Flag this object as modified |
||
100 | 1 | $this->setModifiedState(); |
|
101 | } |
||
102 | |||
103 | 45 | $this->collectionStates[ProcessingInstructions::COLLECTION] = $procInstState; |
|
104 | 45 | } |
|
105 | |||
106 | /** |
||
107 | * Set the object state to modified |
||
108 | */ |
||
109 | abstract protected function setModifiedState(); |
||
110 | } |
||
111 |