vendor/sulu/sulu/src/Sulu/Component/Webspace/Environment.php line 14

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. class Environment
  12. {
  13.     /**
  14.      * The type of the environment (dev, staging, prod, ...).
  15.      *
  16.      * @var string
  17.      */
  18.     private $type;
  19.     /**
  20.      * The urls for this environment.
  21.      *
  22.      * @var Url[]
  23.      */
  24.     private $urls = [];
  25.     /**
  26.      * The custom-urls for this environment.
  27.      *
  28.      * @var CustomUrl[]
  29.      */
  30.     private $customUrls = [];
  31.     /**
  32.      * @var Url
  33.      */
  34.     private $mainUrl;
  35.     /**
  36.      * Sets the tye of this environment.
  37.      *
  38.      * @param string $type
  39.      */
  40.     public function setType($type)
  41.     {
  42.         $this->type $type;
  43.     }
  44.     /**
  45.      * Returns the type of this environment.
  46.      *
  47.      * @return string
  48.      */
  49.     public function getType()
  50.     {
  51.         return $this->type;
  52.     }
  53.     /**
  54.      * Adds a new url to this environment.
  55.      *
  56.      * @param Url $url The url to add
  57.      */
  58.     public function addUrl(Url $url)
  59.     {
  60.         $this->urls[] = $url;
  61.         $url->setEnvironment($this->getType());
  62.         if ($url->isMain() || !$this->mainUrl) {
  63.             $this->setMainUrl($url);
  64.         }
  65.     }
  66.     /**
  67.      * Sets the main url.
  68.      */
  69.     private function setMainUrl(Url $url)
  70.     {
  71.         if (null !== $this->mainUrl) {
  72.             $this->mainUrl->setMain(false);
  73.         }
  74.         $this->mainUrl $url;
  75.         $this->mainUrl->setMain(true);
  76.     }
  77.     /**
  78.      * Returns main url.
  79.      *
  80.      * @return Url
  81.      */
  82.     public function getMainUrl()
  83.     {
  84.         return $this->mainUrl;
  85.     }
  86.     /**
  87.      * Set the urls for this environment.
  88.      *
  89.      * @param Url[] $urls
  90.      */
  91.     public function setUrls($urls)
  92.     {
  93.         $this->urls $urls;
  94.     }
  95.     /**
  96.      * Returns the urls for this environment.
  97.      *
  98.      * @return Url[]
  99.      */
  100.     public function getUrls()
  101.     {
  102.         return $this->urls;
  103.     }
  104.     /**
  105.      * Returns custom-urls.
  106.      *
  107.      * @return CustomUrl[]
  108.      */
  109.     public function getCustomUrls()
  110.     {
  111.         return $this->customUrls;
  112.     }
  113.     /**
  114.      * Sets custom-urls.
  115.      *
  116.      * @param CustomUrl[] $customUrls
  117.      */
  118.     public function setCustomUrls($customUrls)
  119.     {
  120.         $this->customUrls $customUrls;
  121.     }
  122.     /**
  123.      * Adds a new custom-url to this environment.
  124.      */
  125.     public function addCustomUrl(CustomUrl $customUrl)
  126.     {
  127.         $this->customUrls[] = $customUrl;
  128.     }
  129.     public function toArray($depth null)
  130.     {
  131.         $res = [];
  132.         $res['type'] = $this->getType();
  133.         foreach ($this->getUrls() as $url) {
  134.             $res['urls'][] = $url->toArray();
  135.         }
  136.         foreach ($this->getCustomUrls() as $customUrl) {
  137.             $res['customUrls'][] = $customUrl->toArray();
  138.         }
  139.         return $res;
  140.     }
  141. }