vendor/sulu/sulu/src/Sulu/Component/Webspace/PortalInformation.php line 20

Open in your IDE?
  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\Localization\Localization;
  12. use Sulu\Component\Util\ArrayableInterface;
  13. /**
  14.  * This class represents the information for a given URL.
  15.  */
  16. class PortalInformation implements ArrayableInterface
  17. {
  18.     /**
  19.      * The type of the match.
  20.      *
  21.      * @var int
  22.      */
  23.     private $type;
  24.     /**
  25.      * The webspace for this portal information.
  26.      *
  27.      * @var Webspace
  28.      */
  29.     private $webspace;
  30.     /**
  31.      * The portal for this portal information.
  32.      *
  33.      * @var Portal
  34.      */
  35.     private $portal;
  36.     /**
  37.      * The localization for this portal information.
  38.      *
  39.      * @var Localization
  40.      */
  41.     private $localization;
  42.     /**
  43.      * The segment for this portal information.
  44.      *
  45.      * @deprecated Is not set anymore since https://github.com/sulu/sulu/pull/5277
  46.      *
  47.      * @var Segment
  48.      */
  49.     private $segment;
  50.     /**
  51.      * The url for this portal information.
  52.      *
  53.      * @var string
  54.      */
  55.     private $url;
  56.     /**
  57.      * @var string The url to redirect to
  58.      */
  59.     private $redirect;
  60.     /**
  61.      * @var bool
  62.      */
  63.     private $main;
  64.     /**
  65.      * @var string
  66.      */
  67.     private $urlExpression;
  68.     /**
  69.      * @var int
  70.      */
  71.     private $priority;
  72.     public function __construct(
  73.         $type,
  74.         Webspace $webspace null,
  75.         Portal $portal null,
  76.         Localization $localization null,
  77.         $url null,
  78.         Segment $segment null,
  79.         $redirect null,
  80.         $main false,
  81.         $urlExpression null,
  82.         $priority 0
  83.     ) {
  84.         $this->setType($type);
  85.         $this->setWebspace($webspace);
  86.         $this->setPortal($portal);
  87.         $this->setLocalization($localization);
  88.         $this->setUrl($url);
  89.         $this->setRedirect($redirect);
  90.         $this->setMain($main);
  91.         $this->setUrlExpression($urlExpression);
  92.         $this->setPriority($priority);
  93.         if ($segment) {
  94.             $this->setSegment($segment);
  95.         }
  96.     }
  97.     /**
  98.      * Sets the localization for this PortalInformation.
  99.      *
  100.      * @param Localization $localization
  101.      */
  102.     public function setLocalization($localization)
  103.     {
  104.         $this->localization $localization;
  105.     }
  106.     /**
  107.      * Returns the localization for this PortalInformation.
  108.      *
  109.      * @return Localization
  110.      */
  111.     public function getLocalization()
  112.     {
  113.         return $this->localization;
  114.     }
  115.     /**
  116.      * Returns the localization for this PortalInformation.
  117.      *
  118.      * @return string
  119.      */
  120.     public function getLocale()
  121.     {
  122.         if (null === $this->localization) {
  123.             return;
  124.         }
  125.         return $this->localization->getLocale();
  126.     }
  127.     /**
  128.      * Sets the portal for this PortalInformation.
  129.      *
  130.      * @param Portal $portal
  131.      */
  132.     public function setPortal($portal)
  133.     {
  134.         $this->portal $portal;
  135.     }
  136.     /**
  137.      * Returns the portal for this PortalInformation.
  138.      *
  139.      * @return Portal
  140.      */
  141.     public function getPortal()
  142.     {
  143.         return $this->portal;
  144.     }
  145.     /**
  146.      * Returns key of portal.
  147.      */
  148.     public function getPortalKey()
  149.     {
  150.         if (null === $this->portal) {
  151.             return;
  152.         }
  153.         return $this->portal->getKey();
  154.     }
  155.     /**
  156.      * Sets the redirect for the PortalInformation.
  157.      *
  158.      * @param string $redirect
  159.      */
  160.     public function setRedirect($redirect)
  161.     {
  162.         $this->redirect $redirect;
  163.     }
  164.     /**
  165.      * Returns the redirect for the PortalInformation.
  166.      *
  167.      * @return string
  168.      */
  169.     public function getRedirect()
  170.     {
  171.         return $this->redirect;
  172.     }
  173.     /**
  174.      * Sets the segment for the PortalInformation.
  175.      *
  176.      * @deprecated Is not set anymore since https://github.com/sulu/sulu/pull/5277
  177.      *
  178.      * @param Segment $segment
  179.      */
  180.     public function setSegment($segment)
  181.     {
  182.         @\trigger_error(
  183.             'Segment on the PortalInformation will be removed and should not be used anymore since Sulu 2.2',
  184.             \E_USER_DEPRECATED
  185.         );
  186.         $this->segment $segment;
  187.     }
  188.     /**
  189.      * Returns the segment for the PortalInformation.
  190.      *
  191.      * @deprecated Is not set anymore since https://github.com/sulu/sulu/pull/5277
  192.      *
  193.      * @return Segment
  194.      */
  195.     public function getSegment()
  196.     {
  197.         @\trigger_error(
  198.             'Segment on the PortalInformation will be removed and should not be used anymore since Sulu 2.2',
  199.             \E_USER_DEPRECATED
  200.         );
  201.         return $this->segment;
  202.     }
  203.     /**
  204.      * @deprecated Is not set anymore since https://github.com/sulu/sulu/pull/5277
  205.      */
  206.     public function getSegmentKey()
  207.     {
  208.         @\trigger_error(
  209.             'Segment on the PortalInformation will be removed and should not be used anymore since Sulu 2.2',
  210.             \E_USER_DEPRECATED
  211.         );
  212.         return $this->segment $this->segment->getKey() : null;
  213.     }
  214.     /**
  215.      * Sets the match type of this PortalInformation.
  216.      *
  217.      * @param int $type
  218.      */
  219.     public function setType($type)
  220.     {
  221.         $this->type $type;
  222.     }
  223.     /**
  224.      * Returns the match type of this PortalInformation.
  225.      *
  226.      * @return int
  227.      */
  228.     public function getType()
  229.     {
  230.         return $this->type;
  231.     }
  232.     /**
  233.      * Sets the URL of this Portalinformation.
  234.      *
  235.      * @param string $url
  236.      */
  237.     public function setUrl($url)
  238.     {
  239.         $this->url $url;
  240.     }
  241.     /**
  242.      * Returns the URL of this Portalinformation.
  243.      *
  244.      * @return string
  245.      */
  246.     public function getUrl()
  247.     {
  248.         return $this->url;
  249.     }
  250.     /**
  251.      * Returns the host including the domain for the PortalInformation.
  252.      *
  253.      * @return string
  254.      */
  255.     public function getHost()
  256.     {
  257.         return \substr($this->url0$this->getHostLength());
  258.     }
  259.     /**
  260.      * Returns the prefix (the url without the host) for this PortalInformation.
  261.      *
  262.      * @return string
  263.      */
  264.     public function getPrefix()
  265.     {
  266.         $prefix \substr($this->url$this->getHostLength() + 1);
  267.         return $prefix $prefix '/' null;
  268.     }
  269.     /**
  270.      * Sets the webspace for this PortalInformation.
  271.      *
  272.      * @param Webspace $webspace
  273.      */
  274.     public function setWebspace($webspace)
  275.     {
  276.         $this->webspace $webspace;
  277.     }
  278.     /**
  279.      * Returns the webspace for this PortalInformation.
  280.      *
  281.      * @return Webspace
  282.      */
  283.     public function getWebspace()
  284.     {
  285.         return $this->webspace;
  286.     }
  287.     /**
  288.      * Returns key of webspace.
  289.      */
  290.     public function getWebspaceKey()
  291.     {
  292.         if (null === $this->webspace) {
  293.             return;
  294.         }
  295.         return $this->webspace->getKey();
  296.     }
  297.     /**
  298.      * Returns true if url is main.
  299.      *
  300.      * @return bool
  301.      */
  302.     public function isMain()
  303.     {
  304.         return $this->main;
  305.     }
  306.     /**
  307.      * Sets true if url is main.
  308.      *
  309.      * @param bool $main
  310.      */
  311.     public function setMain($main)
  312.     {
  313.         $this->main $main;
  314.     }
  315.     /**
  316.      * Returns expression for url.
  317.      *
  318.      * @return string
  319.      */
  320.     public function getUrlExpression()
  321.     {
  322.         return $this->urlExpression;
  323.     }
  324.     /**
  325.      * Sets expression for url.
  326.      *
  327.      * @param string $urlExpression
  328.      */
  329.     public function setUrlExpression($urlExpression)
  330.     {
  331.         $this->urlExpression $urlExpression;
  332.     }
  333.     /**
  334.      * Calculate the length of the host part of the URL.
  335.      *
  336.      * @return int
  337.      */
  338.     private function getHostLength()
  339.     {
  340.         $hostLength \strpos($this->url'/');
  341.         $hostLength = (false === $hostLength) ? \strlen($this->url) : $hostLength;
  342.         return $hostLength;
  343.     }
  344.     /**
  345.      * @return int
  346.      */
  347.     public function getPriority()
  348.     {
  349.         return $this->priority;
  350.     }
  351.     /**
  352.      * @param int $priority
  353.      */
  354.     public function setPriority($priority)
  355.     {
  356.         $this->priority $priority;
  357.     }
  358.     public function toArray($depth null)
  359.     {
  360.         $result = [];
  361.         $result['type'] = $this->getType();
  362.         $result['webspace'] = $this->getWebspace()->getKey();
  363.         $result['url'] = $this->getUrl();
  364.         $result['main'] = $this->isMain();
  365.         $result['priority'] = $this->getPriority();
  366.         $portal $this->getPortal();
  367.         if ($portal) {
  368.             $result['portal'] = $portal->getKey();
  369.         }
  370.         $localization $this->getLocalization();
  371.         if ($localization) {
  372.             $result['localization'] = $localization->toArray();
  373.         }
  374.         $result['redirect'] = $this->getRedirect();
  375.         $segment $this->getSegment();
  376.         if ($segment) {
  377.             $result['segment'] = $segment->getKey();
  378.         }
  379.         $urlExpression $this->getUrlExpression();
  380.         if ($urlExpression) {
  381.             $result['urlExpression'] = $urlExpression;
  382.         }
  383.         return $result;
  384.     }
  385. }