Skip to content

Commit

Permalink
phpDoc and type hinting (#29)
Browse files Browse the repository at this point in the history
* phpDoc updates.
* Remove the hasSeen class stuff for something a bit nicer.
* phpDoc and type hinting in SitemapIndex
* phpDoc the image sub-element.
* phpDoc the Link sub-element.
* phpDoc the mobile sub-element.
* phpDoc the news sub-element.
* phpDoc and type hint the Urlset class.
* Start phpDoc for Video sub-element.(Got bored with this one, will finish it tomorrow / later)
  • Loading branch information
ThePixelDeveloper committed Apr 20, 2016
1 parent f6cb58b commit 1b975d1
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 97 deletions.
2 changes: 2 additions & 0 deletions src/AppendAttributeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
interface AppendAttributeInterface
{
/**
* Appends an attribute to the collection XML attributes.
*
* @param XMLWriter $XMLWriter
*
* @return void
Expand Down
18 changes: 16 additions & 2 deletions src/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,6 +46,8 @@ public function getOutput(OutputInterface $collection)
}

/**
* Output indented?
*
* @return boolean
*/
public function isIndented()
Expand All @@ -48,6 +56,8 @@ public function isIndented()
}

/**
* Indent the output?
*
* @param boolean $indented
*
* @return $this
Expand All @@ -60,6 +70,8 @@ public function setIndented($indented)
}

/**
* String used for indentation.
*
* @return string
*/
public function getIndentString()
Expand All @@ -68,6 +80,8 @@ public function getIndentString()
}

/**
* Set the string used for indentation.
*
* @param string $indentString
*
* @return $this
Expand Down
2 changes: 2 additions & 0 deletions src/OutputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
interface OutputInterface
{
/**
* Generate the XML for a given element / sub-element.
*
* @param XMLWriter $XMLWriter
*
* @return void
Expand Down
20 changes: 17 additions & 3 deletions src/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,7 +36,7 @@ public function __construct($loc)
}

/**
* @param XMLWriter $XMLWriter
* {@inheritdoc}
*/
public function generateXML(XMLWriter $XMLWriter)
{
Expand All @@ -47,6 +51,8 @@ public function generateXML(XMLWriter $XMLWriter)
}

/**
* Get location (URL).
*
* @return string
*/
public function getLoc()
Expand All @@ -55,6 +61,8 @@ public function getLoc()
}

/**
* Get the last modification time.
*
* @return string|null
*/
public function getLastMod()
Expand All @@ -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;
}
}
25 changes: 18 additions & 7 deletions src/SitemapIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,40 @@
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;

return $this;
}

/**
* @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) {
Expand All @@ -47,7 +56,9 @@ public function generateXML(XMLWriter $XMLWriter)
}

/**
* @return Sitemap[]
* Get an array of Sitemap objects.
*
* @return OutputInterface[]
*/
public function getSitemaps()
{
Expand Down
42 changes: 35 additions & 7 deletions src/Subelements/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,52 @@
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;

/**
* Image constructor
*
* @param $loc
* @param string $loc
*/
public function __construct($loc)
{
$this->loc = $loc;
}

/**
* @param XMLWriter $XMLWriter
* {@inheritdoc}
*/
public function generateXML(XMLWriter $XMLWriter)
{
Expand All @@ -65,6 +75,8 @@ public function generateXML(XMLWriter $XMLWriter)
}

/**
* Location (URL).
*
* @return string
*/
public function getLoc()
Expand All @@ -85,6 +97,8 @@ protected function optionalWriteElement(XMLWriter $XMLWriter, $name, $value)
}

/**
* The caption of the image.
*
* @return string
*/
public function getCaption()
Expand All @@ -93,7 +107,9 @@ public function getCaption()
}

/**
* @param $caption
* Set the caption of the image.
*
* @param string $caption
*
* @return $this
*/
Expand All @@ -105,6 +121,8 @@ public function setCaption($caption)
}

/**
* The geographic location of the image.
*
* @return string
*/
public function getGeoLocation()
Expand All @@ -113,7 +131,9 @@ public function getGeoLocation()
}

/**
* @param $geoLocation
* Set the geographic location of the image.
*
* @param string $geoLocation
*
* @return $this
*/
Expand All @@ -125,6 +145,8 @@ public function setGeoLocation($geoLocation)
}

/**
* The title of the image.
*
* @return string
*/
public function getTitle()
Expand All @@ -133,7 +155,9 @@ public function getTitle()
}

/**
* @param $title
* Set the title of the image.
*
* @param string $title
*
* @return $this
*/
Expand All @@ -145,6 +169,8 @@ public function setTitle($title)
}

/**
* A URL to the license of the image.
*
* @return string
*/
public function getLicense()
Expand All @@ -153,7 +179,9 @@ public function getLicense()
}

/**
* @param $license
* Set a URL to the license of the image.
*
* @param string $license
*
* @return $this
*/
Expand All @@ -165,7 +193,7 @@ public function setLicense($license)
}

/**
* @param XMLWriter $XMLWriter
* {@inheritdoc}
*/
public function appendAttributeToCollectionXML(XMLWriter $XMLWriter)
{
Expand Down
Loading

0 comments on commit 1b975d1

Please sign in to comment.