1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/vendor/eluceo/ical/src/Eluceo/iCal/PropertyBag.php

80 lines
1.7 KiB
PHP

<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
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);
}
}