[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Domain / Model / Mirrors.php
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 /**
17 * Repository mirrors object for extension manager.
18 *
19 * @author Marcus Krause <marcus#exp2010@t3sec.info>
20 * @author Steffen Kamper <info@sk-typo3.de>
21 * @since 2010-02-11
22 */
23 class Mirrors extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
24
25 /**
26 * Keeps mirrors.
27 *
28 * @var array
29 */
30 protected $mirrors = array();
31
32 /**
33 * Keeps currently select mirror.
34 *
35 * Is array index.
36 *
37 * @var integer
38 */
39 protected $currentMirror;
40
41 /**
42 * Keeps information if a mirror should
43 * be randomly selected.
44 *
45 * @var boolean
46 */
47 protected $isRandomSelection = TRUE;
48
49 /**
50 * Method selects one specific mirror to be used.
51 *
52 * @param integer $mirrorId number (>=1) of mirror or NULL for random selection
53 * @return void
54 * @see $currentMirror
55 */
56 public function setSelect($mirrorId = NULL) {
57 if (is_null($mirrorId)) {
58 $this->isRandomSelection = TRUE;
59 } else {
60 if (is_int($mirrorId) && $mirrorId >= 1 && $mirrorId <= count($this->mirrors)) {
61 $this->currentMirror = $mirrorId - 1;
62 }
63 }
64 }
65
66 /**
67 * Method returns one mirror for use.
68 *
69 * Mirror has previously been selected or is chosen
70 * randomly.
71 *
72 * @access public
73 * @return array array of a mirror's properties or NULL in case of errors
74 */
75 public function getMirror() {
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
86 /**
87 * Gets the mirror url from selected mirror
88 *
89 * @return string
90 */
91 public function getMirrorUrl() {
92 $mirror = $this->getMirror();
93 $mirrorUrl = $mirror['host'] . $mirror['path'];
94 return 'http://' . $mirrorUrl;
95 }
96
97 /**
98 * Method returns all available mirrors.
99 *
100 * @access public
101 * @return array multidimensional array with mirrors and their properties
102 * @see $mirrors, setMirrors()
103 */
104 public function getMirrors() {
105 return $this->mirrors;
106 }
107
108 /**
109 * Method sets available mirrors.
110 *
111 * @param array $mirrors multidimensional array with mirrors and their properties
112 * @return void
113 * @see $mirrors, getMirrors()
114 */
115 public function setMirrors(array $mirrors) {
116 if (count($mirrors) >= 1) {
117 $this->mirrors = $mirrors;
118 }
119 }
120
121 }