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