TYPO3  7.6
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 
22 {
28  protected $mirrors = array();
29 
37  protected $currentMirror;
38 
45  protected $isRandomSelection = true;
46 
54  public function setSelect($mirrorId = null)
55  {
56  if (is_null($mirrorId)) {
57  $this->isRandomSelection = true;
58  } else {
59  if (is_int($mirrorId) && $mirrorId >= 1 && $mirrorId <= count($this->mirrors)) {
60  $this->currentMirror = $mirrorId - 1;
61  }
62  }
63  }
64 
74  public function getMirror()
75  {
76  $sumMirrors = count($this->mirrors);
77  if ($sumMirrors > 0) {
78  if (!is_int($this->currentMirror)) {
79  $this->currentMirror = rand(0, $sumMirrors - 1);
80  }
81  return $this->mirrors[$this->currentMirror];
82  }
83  return null;
84  }
85 
91  public function getMirrorUrl()
92  {
93  $mirror = $this->getMirror();
94  $mirrorUrl = $mirror['host'] . $mirror['path'];
95  return 'http://' . $mirrorUrl;
96  }
97 
105  public function getMirrors()
106  {
107  return $this->mirrors;
108  }
109 
117  public function setMirrors(array $mirrors)
118  {
119  if (count($mirrors) >= 1) {
120  $this->mirrors = $mirrors;
121  }
122  }
123 }