Skip to content

Commit

Permalink
Add SitemapUrl::$alternateLinks.
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Feb 26, 2016
1 parent 39b2e5b commit 6eaa360
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 6 deletions.
84 changes: 84 additions & 0 deletions Url/AlternateLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* @author Igor Nikolaev <[email protected]>
* @copyright Copyright (c) 2016, Darvin Studio
* @link https://www.darvin-studio.ru
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Darvin\SitemapBundle\Url;

use Symfony\Component\Validator\Constraints as Assert;

/**
* Sitemap URL alternate link
*/
class AlternateLink
{
/**
* @var string
*
* @Assert\NotBlank
*/
private $hrefLanguage;

/**
* @var string
*
* @Assert\NotBlank
* @Assert\Url
*/
private $href;

/**
* @param string $hrefLanguage Href language
* @param string $href Href
*/
public function __construct($hrefLanguage, $href)
{
$this->hrefLanguage = $hrefLanguage;
$this->href = $href;
}

/**
* @param string $hrefLanguage hrefLanguage
*
* @return AlternateLink
*/
public function setHrefLanguage($hrefLanguage)
{
$this->hrefLanguage = $hrefLanguage;

return $this;
}

/**
* @return string
*/
public function getHrefLanguage()
{
return $this->hrefLanguage;
}

/**
* @param string $href href
*
* @return AlternateLink
*/
public function setHref($href)
{
$this->href = $href;

return $this;
}

/**
* @return string
*/
public function getHref()
{
return $this->href;
}
}
59 changes: 53 additions & 6 deletions Url/SitemapUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SitemapUrl
*
* @Assert\NotBlank
* @Assert\Length(max="2048")
* @Assert\Url
*/
private $location;

Expand All @@ -53,17 +54,31 @@ class SitemapUrl
private $priority;

/**
* @param string $location Location
* @param \DateTime $lastModifiedAt Last modified at
* @param string $changeFrequency Change frequency
* @param float $priority Priority
* @var \Darvin\SitemapBundle\Url\AlternateLink[]
*
* @Assert\Valid
*/
public function __construct($location, \DateTime $lastModifiedAt = null, $changeFrequency = null, $priority = null)
{
private $alternateLinks;

/**
* @param string $location Location
* @param \DateTime $lastModifiedAt Last modified at
* @param string $changeFrequency Change frequency
* @param float $priority Priority
* @param \Darvin\SitemapBundle\Url\AlternateLink[] $alternateLinks Alternate links
*/
public function __construct(
$location,
\DateTime $lastModifiedAt = null,
$changeFrequency = null,
$priority = null,
array $alternateLinks = array()
) {
$this->location = $location;
$this->lastModifiedAt = $lastModifiedAt;
$this->changeFrequency = $changeFrequency;
$this->priority = $priority;
$this->alternateLinks = $alternateLinks;
}

/**
Expand Down Expand Up @@ -145,4 +160,36 @@ public function getPriority()
{
return $this->priority;
}

/**
* @param \Darvin\SitemapBundle\Url\AlternateLink[] $alternateLinks alternateLinks
*
* @return SitemapUrl
*/
public function setAlternateLinks(array $alternateLinks)
{
$this->alternateLinks = $alternateLinks;

return $this;
}

/**
* @return \Darvin\SitemapBundle\Url\AlternateLink[]
*/
public function getAlternateLinks()
{
return $this->alternateLinks;
}

/**
* @param \Darvin\SitemapBundle\Url\AlternateLink $alternateLink Alternate link
*
* @return SitemapUrl
*/
public function addAlternateLink(AlternateLink $alternateLink)
{
$this->alternateLinks[] = $alternateLink;

return $this;
}
}

0 comments on commit 6eaa360

Please sign in to comment.