vendor/sulu/sulu/src/Sulu/Component/Webspace/Url.php line 16

  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\Webspace;
  11. use Sulu\Component\Util\ArrayableInterface;
  12. class Url implements ArrayableInterface
  13. {
  14.     /**
  15.      * The url itself.
  16.      *
  17.      * @var string
  18.      */
  19.     private $url;
  20.     /**
  21.      * The language to which the url leads.
  22.      *
  23.      * @var string
  24.      */
  25.     private $language;
  26.     /**
  27.      * The country to which the url leads.
  28.      *
  29.      * @var string
  30.      */
  31.     private $country;
  32.     /**
  33.      * The segment to which the url leads.
  34.      *
  35.      * @var string
  36.      */
  37.     private $segment;
  38.     /**
  39.      * The url to which this url redirects.
  40.      *
  41.      * @var string
  42.      */
  43.     private $redirect;
  44.     /**
  45.      * Indicate the main url.
  46.      *
  47.      * @var bool
  48.      */
  49.     private $main;
  50.     /**
  51.      * @var string
  52.      */
  53.     private $environment;
  54.     public function __construct($url null$environment null)
  55.     {
  56.         $this->url $url;
  57.         $this->environment $environment;
  58.     }
  59.     /**
  60.      * Sets the url.
  61.      *
  62.      * @param string $url
  63.      */
  64.     public function setUrl($url)
  65.     {
  66.         $this->url $url;
  67.     }
  68.     /**
  69.      * Returns the url.
  70.      *
  71.      * @return string
  72.      */
  73.     public function getUrl()
  74.     {
  75.         return $this->url;
  76.     }
  77.     /**
  78.      * Sets the country to which this url leads.
  79.      *
  80.      * @param string $country
  81.      */
  82.     public function setCountry($country)
  83.     {
  84.         $this->country $country;
  85.     }
  86.     /**
  87.      * Returns the country to which this url leads.
  88.      *
  89.      * @return string
  90.      */
  91.     public function getCountry()
  92.     {
  93.         return $this->country;
  94.     }
  95.     /**
  96.      * Sets the language to which this url leads.
  97.      *
  98.      * @param string $language
  99.      */
  100.     public function setLanguage($language)
  101.     {
  102.         $this->language $language;
  103.     }
  104.     /**
  105.      * Returns the language to which this url leads.
  106.      *
  107.      * @return string
  108.      */
  109.     public function getLanguage()
  110.     {
  111.         return $this->language;
  112.     }
  113.     /**
  114.      * Sets the segment to which this url leads.
  115.      *
  116.      * @param string $segment
  117.      */
  118.     public function setSegment($segment)
  119.     {
  120.         $this->segment $segment;
  121.     }
  122.     /**
  123.      * Returns the segment to which this url leads.
  124.      *
  125.      * @return string
  126.      */
  127.     public function getSegment()
  128.     {
  129.         return $this->segment;
  130.     }
  131.     /**
  132.      * Sets the redirect for this url.
  133.      *
  134.      * @param string $redirect
  135.      */
  136.     public function setRedirect($redirect)
  137.     {
  138.         $this->redirect $redirect;
  139.     }
  140.     /**
  141.      * Returns the redirect url.
  142.      *
  143.      * @return string
  144.      */
  145.     public function getRedirect()
  146.     {
  147.         return $this->redirect;
  148.     }
  149.     /**
  150.      * Return main flag.
  151.      *
  152.      * @return bool
  153.      */
  154.     public function isMain()
  155.     {
  156.         return $this->main;
  157.     }
  158.     /**
  159.      * Sets main flag.
  160.      *
  161.      * @param bool $main
  162.      */
  163.     public function setMain($main)
  164.     {
  165.         $this->main $main;
  166.     }
  167.     /**
  168.      * Returns the environment.
  169.      *
  170.      * @return string
  171.      */
  172.     public function getEnvironment()
  173.     {
  174.         return $this->environment;
  175.     }
  176.     /**
  177.      * Sets the environment.
  178.      *
  179.      * @param string $environment
  180.      */
  181.     public function setEnvironment($environment)
  182.     {
  183.         $this->environment $environment;
  184.     }
  185.     /**
  186.      * Checks if this URL handles the locale for the given language and country.
  187.      *
  188.      * @param string $language
  189.      * @param string $country
  190.      *
  191.      * @return bool
  192.      */
  193.     public function isValidLocale($language$country)
  194.     {
  195.         return ($this->getLanguage() === $language && $this->getCountry() === $country)
  196.             || (empty($this->getLanguage()) && empty($this->getCountry()));
  197.     }
  198.     public function toArray($depth null)
  199.     {
  200.         $res = [];
  201.         $res['url'] = $this->getUrl();
  202.         $res['language'] = $this->getLanguage();
  203.         $res['country'] = $this->getCountry();
  204.         $res['segment'] = $this->getSegment();
  205.         $res['redirect'] = $this->getRedirect();
  206.         $res['main'] = $this->isMain();
  207.         $res['environment'] = $this->getEnvironment();
  208.         return $res;
  209.     }
  210. }