<?php
namespace phpDocumentor\Transformer;
use JMS\Serializer\Annotation as Serializer;
use phpDocumentor\Transformer\Template\Parameter;
class Template implements \ArrayAccess, \Countable, \Iterator
{
protected $name = null;
/**
* @Serializer\Type("string")
* @var string The name and optionally mail address of the author, i.e. `Mike van Riel <me@mikevanriel.com>`.
*/
protected $author = '';
protected $version = '';
protected $copyright = '';
protected $description = '';
/**
* @Serializer\XmlList(entry = "transformation")
* @Serializer\Type("array<phpDocumentor\Transformer\Transformation>")
* @var Transformation[] A series of transformations to execute in sequence during transformation.
*/
protected $transformations = array();
/**
* @Serializer\XmlList(entry = "parameter")
* @Serializer\Type("array<phpDocumentor\Transformer\Template\Parameter>")
* @var Parameter[] Global parameters that are passed to each transformation.
*/
protected $parameters = array();
public function __construct($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setAuthor($author)
{
$this->author = $author;
}
public function getAuthor()
{
return $this->author;
}
public function setCopyright($copyright)
{
$this->copyright = $copyright;
}
public function getCopyright()
{
return $this->copyright;
}
public function setVersion($version)
{
if (!preg_match('/^\d+\.\d+\.\d+$/', $version)) {
throw new \InvalidArgumentException(
'Version number is invalid; ' . $version . ' does not match '
. 'x.x.x (where x is a number)'
);
}
$this->version = $version;
}
public function getVersion()
{
return $this->version;
}
public function setDescription($description)
{
$this->description = $description;
}
public function getDescription()
{
return $this->description;
}
public function offsetSet($offset, $value)
{
if (!$value instanceof Transformation) {
throw new \InvalidArgumentException(
'\phpDocumentor\Transformer\Template may only contain items of '
. 'type \phpDocumentor\Transformer\Transformation'
);
}
$this->transformations[] = $value;
}
public function offsetGet($offset)
{
return $this->transformations[$offset];
}
public function offsetUnset($offset)
{
unset($this->transformations[$offset]);
}
public function offsetExists($offset)
{
return isset($this->transformations[$offset]);
}
public function count()
{
return count($this->transformations);
}
public function rewind()
{
reset($this->transformations);
}
public function valid()
{
return (current($this->transformations) === false)
? false
: true;
}
public function key()
{
key($this->transformations);
}
public function next()
{
next($this->transformations);
}
public function current()
{
return current($this->transformations);
}
public function getParameters()
{
return $this->parameters;
}
public function setParameter($key, $value)
{
$this->parameters[$key] = $value;
}
public function propagateParameters()
{
foreach ($this->transformations as $transformation) {
$transformation->setParameters(array_merge($transformation->getParameters(), $this->getParameters()));
}
}
}