diff --git a/src/AppendAttributeInterface.php b/src/AppendAttributeInterface.php index 2b815c3..25a509c 100644 --- a/src/AppendAttributeInterface.php +++ b/src/AppendAttributeInterface.php @@ -12,6 +12,8 @@ interface AppendAttributeInterface { /** + * Appends an attribute to the collection XML attributes. + * * @param XMLWriter $XMLWriter * * @return void diff --git a/src/Output.php b/src/Output.php index 43f4dc9..3c45f40 100644 --- a/src/Output.php +++ b/src/Output.php @@ -12,16 +12,22 @@ class Output { /** - * @var bool Is the output indented + * Is the output indented. + * + * @var boolean */ protected $indented = true; /** - * @var string What string is used for indentation + * What string is used for indentation. + * + * @var string */ protected $indentString = ' '; /** + * Renders the Sitemap as an XML string. + * * @param OutputInterface $collection * * @return string @@ -40,6 +46,8 @@ public function getOutput(OutputInterface $collection) } /** + * Output indented? + * * @return boolean */ public function isIndented() @@ -48,6 +56,8 @@ public function isIndented() } /** + * Indent the output? + * * @param boolean $indented * * @return $this @@ -60,6 +70,8 @@ public function setIndented($indented) } /** + * String used for indentation. + * * @return string */ public function getIndentString() @@ -68,6 +80,8 @@ public function getIndentString() } /** + * Set the string used for indentation. + * * @param string $indentString * * @return $this diff --git a/src/OutputInterface.php b/src/OutputInterface.php index 59a7889..486528f 100644 --- a/src/OutputInterface.php +++ b/src/OutputInterface.php @@ -12,6 +12,8 @@ interface OutputInterface { /** + * Generate the XML for a given element / sub-element. + * * @param XMLWriter $XMLWriter * * @return void diff --git a/src/Sitemap.php b/src/Sitemap.php index 37f10bc..b0b4f41 100644 --- a/src/Sitemap.php +++ b/src/Sitemap.php @@ -12,12 +12,16 @@ class Sitemap implements OutputInterface { /** - * @var string Location (URL) + * Location (URL). + * + * @var string */ protected $loc; /** - * @var string Last modified time + * Last modified time. + * + * @var string */ protected $lastMod; @@ -32,7 +36,7 @@ public function __construct($loc) } /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function generateXML(XMLWriter $XMLWriter) { @@ -47,6 +51,8 @@ public function generateXML(XMLWriter $XMLWriter) } /** + * Get location (URL). + * * @return string */ public function getLoc() @@ -55,6 +61,8 @@ public function getLoc() } /** + * Get the last modification time. + * * @return string|null */ public function getLastMod() @@ -63,10 +71,16 @@ public function getLastMod() } /** + * Set the last modification time. + * * @param string $lastMod + * + * @return $this */ public function setLastMod($lastMod) { $this->lastMod = $lastMod; + + return $this; } } diff --git a/src/SitemapIndex.php b/src/SitemapIndex.php index 1e92121..b794dee 100644 --- a/src/SitemapIndex.php +++ b/src/SitemapIndex.php @@ -12,16 +12,20 @@ class SitemapIndex implements OutputInterface { /** - * @var Sitemap[] + * Array of Sitemap entries. + * + * @var OutputInterface[] */ protected $sitemaps = []; /** - * @param Sitemap $sitemap + * Add a new Sitemap object to the collection. + * + * @param OutputInterface $sitemap * * @return $this */ - public function addSitemap(Sitemap $sitemap) + public function addSitemap(OutputInterface $sitemap) { $this->sitemaps[] = $sitemap; @@ -29,14 +33,19 @@ public function addSitemap(Sitemap $sitemap) } /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function generateXML(XMLWriter $XMLWriter) { $XMLWriter->startElement('sitemapindex'); $XMLWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); - $XMLWriter->writeAttribute('xsi:schemaLocation', - 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd'); + + $XMLWriter->writeAttribute( + 'xsi:schemaLocation', + 'http://www.sitemaps.org/schemas/sitemap/0.9 ' . + 'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd' + ); + $XMLWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($this->getSitemaps() as $sitemap) { @@ -47,7 +56,9 @@ public function generateXML(XMLWriter $XMLWriter) } /** - * @return Sitemap[] + * Get an array of Sitemap objects. + * + * @return OutputInterface[] */ public function getSitemaps() { diff --git a/src/Subelements/Image.php b/src/Subelements/Image.php index 9d8f950..a304483 100644 --- a/src/Subelements/Image.php +++ b/src/Subelements/Image.php @@ -14,26 +14,36 @@ class Image implements OutputInterface, AppendAttributeInterface { /** + * Location (URL). + * * @var string */ protected $loc; /** + * The caption of the image. + * * @var string */ protected $caption; /** + * The geographic location of the image. + * * @var string */ protected $geoLocation; /** + * The title of the image. + * * @var string */ protected $title; /** + * A URL to the license of the image. + * * @var string */ protected $license; @@ -41,7 +51,7 @@ class Image implements OutputInterface, AppendAttributeInterface /** * Image constructor * - * @param $loc + * @param string $loc */ public function __construct($loc) { @@ -49,7 +59,7 @@ public function __construct($loc) } /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function generateXML(XMLWriter $XMLWriter) { @@ -65,6 +75,8 @@ public function generateXML(XMLWriter $XMLWriter) } /** + * Location (URL). + * * @return string */ public function getLoc() @@ -85,6 +97,8 @@ protected function optionalWriteElement(XMLWriter $XMLWriter, $name, $value) } /** + * The caption of the image. + * * @return string */ public function getCaption() @@ -93,7 +107,9 @@ public function getCaption() } /** - * @param $caption + * Set the caption of the image. + * + * @param string $caption * * @return $this */ @@ -105,6 +121,8 @@ public function setCaption($caption) } /** + * The geographic location of the image. + * * @return string */ public function getGeoLocation() @@ -113,7 +131,9 @@ public function getGeoLocation() } /** - * @param $geoLocation + * Set the geographic location of the image. + * + * @param string $geoLocation * * @return $this */ @@ -125,6 +145,8 @@ public function setGeoLocation($geoLocation) } /** + * The title of the image. + * * @return string */ public function getTitle() @@ -133,7 +155,9 @@ public function getTitle() } /** - * @param $title + * Set the title of the image. + * + * @param string $title * * @return $this */ @@ -145,6 +169,8 @@ public function setTitle($title) } /** + * A URL to the license of the image. + * * @return string */ public function getLicense() @@ -153,7 +179,9 @@ public function getLicense() } /** - * @param $license + * Set a URL to the license of the image. + * + * @param string $license * * @return $this */ @@ -165,7 +193,7 @@ public function setLicense($license) } /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) { diff --git a/src/Subelements/Link.php b/src/Subelements/Link.php index 6300a34..202e056 100644 --- a/src/Subelements/Link.php +++ b/src/Subelements/Link.php @@ -14,40 +14,45 @@ class Link implements OutputInterface, AppendAttributeInterface { /** + * Language code for the page. + * * @var string */ - protected $hreflang; + protected $hrefLang; /** + * Location of the translated page. + * * @var string */ protected $href; /** - * Image constructor + * Link constructor. * - * @param $loc + * @param string $hrefLang + * @param string $href */ - public function __construct($hreflang, $href) + public function __construct($hrefLang, $href) { - $this->hreflang = $hreflang; + $this->hrefLang = $hrefLang; $this->href = $href; } /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function generateXML(XMLWriter $XMLWriter) { $XMLWriter->startElement('xhtml:link'); $XMLWriter->writeAttribute('rel', 'alternate'); - $XMLWriter->writeAttribute('hreflang', $this->hreflang); + $XMLWriter->writeAttribute('hreflang', $this->hrefLang); $XMLWriter->writeAttribute('href', $this->href); $XMLWriter->endElement(); } /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) { @@ -55,6 +60,8 @@ public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) } /** + * Location of the translated page. + * * @return string */ public function getHref() @@ -63,10 +70,12 @@ public function getHref() } /** + * Language code for the page. + * * @return string */ - public function getHreflang() + public function getHrefLang() { - return $this->hreflang; + return $this->hrefLang; } } diff --git a/src/Subelements/Mobile.php b/src/Subelements/Mobile.php index c857bb0..8c7686c 100644 --- a/src/Subelements/Mobile.php +++ b/src/Subelements/Mobile.php @@ -14,7 +14,7 @@ class Mobile implements OutputInterface, AppendAttributeInterface { /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) { @@ -22,7 +22,7 @@ public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) } /** - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function generateXML(XMLWriter $XMLWriter) { diff --git a/src/Subelements/News.php b/src/Subelements/News.php index 5bb16b2..3ca5018 100644 --- a/src/Subelements/News.php +++ b/src/Subelements/News.php @@ -14,59 +14,64 @@ class News implements OutputInterface, AppendAttributeInterface { /** + * Location (URL). + * * @var string */ protected $loc; /** - * Publication name + * Publication name. * * @var string */ protected $publicationName; /** - * Publication language + * Publication language. * * @var string */ protected $publicationLanguage; /** - * Access + * Access. * * @var string */ protected $access; /** - * List of genres, comma-separated string values + * List of genres, comma-separated string values. + * * @var string */ protected $genres; /** - * Date of publication + * Date of publication. * * @var \DateTime */ protected $publicationDate; /** - * Title + * Title. * * @var string */ protected $title; /** - * Key words, comma-separated string values + * Key words, comma-separated string values. * * @var string */ protected $keywords; /** + * Publication name. + * * @return string */ public function getPublicationName() @@ -75,8 +80,11 @@ public function getPublicationName() } /** + * Set the publication name. + * * @param string $publicationName - * @return News + * + * @return $this */ public function setPublicationName($publicationName) { @@ -86,6 +94,8 @@ public function setPublicationName($publicationName) } /** + * Publication language. + * * @return string */ public function getPublicationLanguage() @@ -94,8 +104,11 @@ public function getPublicationLanguage() } /** + * Set the publication language. + * * @param string $publicationLanguage - * @return News + * + * @return $this */ public function setPublicationLanguage($publicationLanguage) { @@ -105,6 +118,8 @@ public function setPublicationLanguage($publicationLanguage) } /** + * Access. + * * @return string */ public function getAccess() @@ -113,8 +128,11 @@ public function getAccess() } /** + * Set access. + * * @param string $access - * @return News + * + * @return $this */ public function setAccess($access) { @@ -124,6 +142,8 @@ public function setAccess($access) } /** + * List of genres, comma-separated string values. + * * @return string */ public function getGenres() @@ -132,8 +152,11 @@ public function getGenres() } /** + * Set list of genres, comma-separated string values. + * * @param string $genres - * @return News + * + * @return $this */ public function setGenres($genres) { @@ -143,6 +166,8 @@ public function setGenres($genres) } /** + * Date of publication. + * * @return \DateTime */ public function getPublicationDate() @@ -151,8 +176,11 @@ public function getPublicationDate() } /** + * Set date of publication. + * * @param \DateTime $publicationDate - * @return News + * + * @return $this */ public function setPublicationDate(\DateTime $publicationDate) { @@ -162,6 +190,8 @@ public function setPublicationDate(\DateTime $publicationDate) } /** + * Title. + * * @return string */ public function getTitle() @@ -170,8 +200,11 @@ public function getTitle() } /** + * Set title. + * * @param string $title - * @return News + * + * @return $this */ public function setTitle($title) { @@ -181,6 +214,8 @@ public function setTitle($title) } /** + * Key words, comma-separated string values. + * * @return string */ public function getKeywords() @@ -189,8 +224,11 @@ public function getKeywords() } /** + * Set key words, comma-separated string values. + * * @param string $keywords - * @return News + * + * @return $this */ public function setKeywords($keywords) { diff --git a/src/Subelements/Video.php b/src/Subelements/Video.php index f3a880c..56f7bca 100644 --- a/src/Subelements/Video.php +++ b/src/Subelements/Video.php @@ -14,47 +14,67 @@ class Video implements OutputInterface, AppendAttributeInterface { /** - * @var + * URL pointing to an image thumbnail. + * + * @var string */ protected $thumbnailLoc; /** - * @var + * Title of the video, max 100 characters. + * + * @var string */ protected $title; /** - * @var + * Description of the video, max 2048 characters. + * + * @var string */ protected $description; /** - * @var + * URL pointing to the actual media file (mp4). + * + * @var string */ protected $contentLoc; /** - * @var + * URL pointing to the player file (normally a SWF). + * + * @var string */ protected $playerLoc; /** - * @var + * Indicates whether the video is live. + * + * @var boolean */ protected $live; /** - * @var + * Duration of the video in seconds. + * + * @var integer */ protected $duration; /** - * @var + * String of space delimited platform values. + * + * Allowed values are web, mobile, and tv. + * + * @var string */ protected $platform; /** - * @var + * Does the video require a subscription? + * + * @var boolean */ protected $requiresSubscription; diff --git a/src/Url.php b/src/Url.php index c83b65c..86e9920 100644 --- a/src/Url.php +++ b/src/Url.php @@ -12,33 +12,46 @@ class Url implements OutputInterface { /** - * @var string Location (URL) + * Location (URL). + * + * @var string */ protected $loc; /** - * @var string Last modified time + * Last modified time. + * + * @var string */ protected $lastMod; /** - * @var string Change frequency of the location + * Change frequency of the location. + * + * @var string */ protected $changeFreq; /** - * @var string Priority of page importance + * Priority of page importance. + * + * @var string */ protected $priority; /** + * Array of sub-elements. + * * @var OutputInterface[] */ - protected $subElements = []; + protected $subelements = []; + /** - * @var array + * Sub-elements that append to the collection attributes. + * + * @var AppendAttributeInterface[] */ - protected $seenClasses = []; + protected $subelementsThatAppend = []; /** * Url constructor @@ -55,11 +68,8 @@ public function __construct($loc) */ public function generateXML(XMLWriter $XMLWriter) { - foreach ($this->getSubelements() as $subelement) { - if (!$this->hasSeenClass($subelement) && $subelement instanceof AppendAttributeInterface) { - $subelement->appendAttributeToCollectionXML($XMLWriter); - $this->seeClass($subelement); - } + foreach ($this->getSubelementsThatAppend() as $subelement) { + $subelement->appendAttributeToCollectionXML($XMLWriter); } $XMLWriter->startElement('url'); @@ -70,45 +80,35 @@ public function generateXML(XMLWriter $XMLWriter) $this->optionalWriteElement($XMLWriter, 'priority', $this->getPriority()); foreach ($this->getSubelements() as $subelement) { - if ($subelement instanceof OutputInterface) { - $subelement->generateXML($XMLWriter); - } + $subelement->generateXML($XMLWriter); } $XMLWriter->endElement(); } /** + * Array of sub-elements. + * * @return OutputInterface[] */ - public function getSubElements() + public function getSubelements() { - return $this->subElements; + return $this->subelements; } /** - * @param $object + * Array of sub-elements that append to the collections attributes. * - * @return bool + * @return AppendAttributeInterface[] */ - protected function hasSeenClass($object) + public function getSubelementsThatAppend() { - return in_array(get_class($object), $this->seenClasses, true); + return $this->subelementsThatAppend; } /** - * @param $object + * Get location (URL). * - * @return $this - */ - protected function seeClass($object) - { - $this->seenClasses[] = get_class($object); - - return $this; - } - - /** * @return string */ public function getLoc() @@ -205,14 +205,34 @@ public function setPriority($priority) /** * Add a new sub element. * - * @param mixed $subElement + * @param OutputInterface $subElement * * @return $this */ - public function addSubElement($subElement) + public function addSubElement(OutputInterface $subElement) { - $this->subElements[] = $subElement; + $this->subelements[] = $subElement; + + if ($this->isSubelementGoingToAppend($subElement)) { + $this->subelementsThatAppend[get_class($subElement)] = $subElement; + } return $this; } + + /** + * Checks if the sub-element is going to append collection attributes. + * + * @param OutputInterface $subelement + * + * @return boolean + */ + protected function isSubelementGoingToAppend(OutputInterface $subelement) + { + if (!$subelement instanceof AppendAttributeInterface) { + return false; + } + + return !in_array(get_class($subelement), $this->subelementsThatAppend, false); + } } diff --git a/src/Urlset.php b/src/Urlset.php index 6217cec..d683609 100644 --- a/src/Urlset.php +++ b/src/Urlset.php @@ -12,18 +12,20 @@ class Urlset implements OutputInterface { /** - * @var Url[] + * Array of URL objects. + * + * @var OutputInterface[] */ protected $urls = []; /** - * Add a new Url + * Add a new URL object. * - * @param Url $url + * @param OutputInterface $url * * @return $this */ - public function addUrl(Url $url) + public function addUrl(OutputInterface $url) { $this->urls[] = $url; @@ -31,9 +33,7 @@ public function addUrl(Url $url) } /** - * Generate the XML for the urlset. - * - * @param XMLWriter $XMLWriter + * {@inheritdoc} */ public function generateXML(XMLWriter $XMLWriter) { @@ -55,7 +55,9 @@ public function generateXML(XMLWriter $XMLWriter) } /** - * @return Url[] + * Get array of URL objects. + * + * @return OutputInterface[] */ public function getUrls() {