TYPO3 CMS  TYPO3_8-7
Mirrors.php
Go to the documentation of this file.
1 <?php
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 
52  public function setSelect($mirrorId = null)
53  {
54  if (is_null($mirrorId)) {
55  $this->isRandomSelection = true;
56  } else {
57  if (is_int($mirrorId) && $mirrorId >= 1 && $mirrorId <= count($this->mirrors)) {
58  $this->currentMirror = $mirrorId - 1;
59  }
60  }
61  }
62 
72  public function getMirror()
73  {
74  $sumMirrors = count($this->mirrors);
75  if ($sumMirrors > 0) {
76  if (!is_int($this->currentMirror)) {
77  $this->currentMirror = rand(0, $sumMirrors - 1);
78  }
79  return $this->mirrors[$this->currentMirror];
80  }
81  return null;
82  }
83 
89  public function getMirrorUrl()
90  {
91  $mirror = $this->getMirror();
92  $mirrorUrl = $mirror['host'] . $mirror['path'];
93  return 'https://' . $mirrorUrl;
94  }
95 
103  public function getMirrors()
104  {
105  return $this->mirrors;
106  }
107 
114  public function setMirrors(array $mirrors)
115  {
116  if (count($mirrors) >= 1) {
117  $this->mirrors = $mirrors;
118  }
119  }
120 }