summaryrefslogtreecommitdiff
path: root/vendor/eluceo/ical/src/Eluceo/iCal/PropertyBag.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/eluceo/ical/src/Eluceo/iCal/PropertyBag.php')
-rw-r--r--vendor/eluceo/ical/src/Eluceo/iCal/PropertyBag.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/eluceo/ical/src/Eluceo/iCal/PropertyBag.php b/vendor/eluceo/ical/src/Eluceo/iCal/PropertyBag.php
new file mode 100644
index 00000000..7032360b
--- /dev/null
+++ b/vendor/eluceo/ical/src/Eluceo/iCal/PropertyBag.php
@@ -0,0 +1,79 @@
+<?php
+
+/*
+ * This file is part of the eluceo/iCal package.
+ *
+ * (c) Markus Poerschke <markus@eluceo.de>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Eluceo\iCal;
+
+class PropertyBag implements \IteratorAggregate
+{
+ /**
+ * @var array
+ */
+ protected $elements = array();
+
+ /**
+ * Creates a new Property with $name, $value and $params.
+ *
+ * @param $name
+ * @param $value
+ * @param array $params
+ *
+ * @return $this
+ */
+ public function set($name, $value, $params = array())
+ {
+ $property = new Property($name, $value, $params);
+ $this->elements[] = $property;
+
+ return $this;
+ }
+
+ /**
+ * @param string $name
+ *
+ * @return null|Property
+ */
+ public function get($name)
+ {
+ // Searching Property in elements-array
+ /** @var $property Property */
+ foreach ($this->elements as $property) {
+ if ($property->getName() == $name) {
+ return $property;
+ }
+ }
+ }
+
+ /**
+ * Adds a Property. If Property already exists an Exception will be thrown.
+ *
+ * @param Property $property
+ *
+ * @return $this
+ *
+ * @throws \Exception
+ */
+ public function add(Property $property)
+ {
+ // Property already exists?
+ if (null !== $this->get($property->getName())) {
+ throw new \Exception("Property with name '{$property->getName()}' already exists");
+ }
+
+ $this->elements[] = $property;
+
+ return $this;
+ }
+
+ public function getIterator()
+ {
+ return new \ArrayObject($this->elements);
+ }
+}