Minor improvements

git-svn-id: http://php-reader.googlecode.com/svn/trunk@141 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2009-02-19 21:38:20 +00:00
parent 4b68a78dc8
commit 72ad79e344

View File

@@ -293,6 +293,7 @@ class ISO14496_Box
* <var>true</var> if one or more boxes are present, <var>false</var> * <var>true</var> if one or more boxes are present, <var>false</var>
* otherwise. * otherwise.
* *
* @param string $identifier The box identifier.
* @return boolean * @return boolean
* @throws ISO14496_Exception if called on a non-container box * @throws ISO14496_Exception if called on a non-container box
*/ */
@@ -329,6 +330,7 @@ class ISO14496_Box
* the first box with the identifier given. Wildcards cannot be used with * the first box with the identifier given. Wildcards cannot be used with
* the shorthand and they will not work with user defined uuid types. * the shorthand and they will not work with user defined uuid types.
* *
* @param string $identifier The box identifier.
* @return Array * @return Array
* @throws ISO14496_Exception if called on a non-container box * @throws ISO14496_Exception if called on a non-container box
*/ */
@@ -346,14 +348,41 @@ class ISO14496_Box
return $matches; return $matches;
} }
/**
* Removes any boxes matching the given box identifier.
*
* The identifier may contain wildcard characters "*" and "?". The asterisk
* matches against zero or more characters, and the question mark matches any
* single character.
*
* One may also use the shorthand unset($obj->identifier) to achieve the same
* result. Wildcards cannot be used with the shorthand method.
*
* @param string $identifier The box identifier.
* @throws ISO14496_Exception if called on a non-container box
*/
public final function removeBoxesByIdentifier($identifier)
{
if (!$this->isContainer())
throw new ISO14496_Exception("Box not a container");
$searchPattern = "/^" .
str_replace(array("*", "?"), array(".*", "."), $identifier) . "$/i";
foreach ($this->_objects as $identifier => $objects)
if (preg_match($searchPattern, $identifier))
unset($this->_objects[$identifier]);
}
/** /**
* Adds a new box into the current box and returns it. * Adds a new box into the current box and returns it.
* *
* @param ISO14496_Box The box to add * @param ISO14496_Box $box The box to add
* @return ISO14496_Box * @return ISO14496_Box
* @throws ISO14496_Exception if called on a non-container box
*/ */
public final function addBox($box) public final function addBox($box)
{ {
if (!$this->isContainer())
throw new ISO14496_Exception("Box not a container");
$box->setParent($this); $box->setParent($this);
$box->setOptions($this->_options); $box->setOptions($this->_options);
if (!$this->hasBox($box->getType())) if (!$this->hasBox($box->getType()))
@@ -361,6 +390,22 @@ class ISO14496_Box
return $this->_boxes[$box->getType()][] = $box; return $this->_boxes[$box->getType()][] = $box;
} }
/**
* Removes the given box.
*
* @param ISO14496_Box $box The box to remove
* @throws ISO14496_Exception if called on a non-container box
*/
public final function removeBox($box)
{
if (!$this->isContainer())
throw new ISO14496_Exception("Box not a container");
if ($this->hasBox($box->getType()))
foreach ($this->_boxes[$box->getType()] as $key => $value)
if ($box === $value)
unset($this->_boxes[$box->getType()][$key]);
}
/** /**
* Magic function so that $obj->value will work. If called on a container box, * Magic function so that $obj->value will work. If called on a container box,
* the method will first attempt to return the first contained box that * the method will first attempt to return the first contained box that