TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Mirrors.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Domain\Model;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
27  protected $mirrors = [];
28 
36  protected $currentMirror;
37 
44  protected $isRandomSelection = true;
45 
53  public function setSelect($mirrorId = null)
54  {
55  if (is_null($mirrorId)) {
56  $this->isRandomSelection = true;
57  } else {
58  if (is_int($mirrorId) && $mirrorId >= 1 && $mirrorId <= count($this->mirrors)) {
59  $this->currentMirror = $mirrorId - 1;
60  }
61  }
62  }
63 
73  public function getMirror()
74  {
75  $sumMirrors = count($this->mirrors);
76  if ($sumMirrors > 0) {
77  if (!is_int($this->currentMirror)) {
78  $this->currentMirror = rand(0, $sumMirrors - 1);
79  }
80  return $this->mirrors[$this->currentMirror];
81  }
82  return null;
83  }
84 
90  public function getMirrorUrl()
91  {
92  $mirror = $this->getMirror();
93  $mirrorUrl = $mirror['host'] . $mirror['path'];
94  return 'https://' . $mirrorUrl;
95  }
96 
104  public function getMirrors()
105  {
106  return $this->mirrors;
107  }
108 
116  public function setMirrors(array $mirrors)
117  {
118  if (count($mirrors) >= 1) {
119  $this->mirrors = $mirrors;
120  }
121  }
122 }