d81f7ead0b57c168385bf5c1fdad01280a3de851
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Domain / Model / Mirrors.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Domain\Model;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Marcus Krause <marcus#exp2010@t3sec.info>
8 * Steffen Kamper <info@sk-typo3.de>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Repository mirrors object for extension manager.
29 *
30 * @author Marcus Krause <marcus#exp2010@t3sec.info>
31 * @author Steffen Kamper <info@sk-typo3.de>
32 * @since 2010-02-11
33 */
34 class Mirrors extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
35
36 /**
37 * Keeps mirrors.
38 *
39 * @var array
40 */
41 protected $mirrors = array();
42
43 /**
44 * Keeps currently select mirror.
45 *
46 * Is array index.
47 *
48 * @var integer
49 */
50 protected $currentMirror;
51
52 /**
53 * Keeps information if a mirror should
54 * be randomly selected.
55 *
56 * @var boolean
57 */
58 protected $isRandomSelection = TRUE;
59
60 /**
61 * Method selects one specific mirror to be used.
62 *
63 * @param integer $mirrorId number (>=1) of mirror or NULL for random selection
64 * @return void
65 * @see $currentMirror
66 */
67 public function setSelect($mirrorId = NULL) {
68 if (is_null($mirrorId)) {
69 $this->isRandomSelection = TRUE;
70 } else {
71 if (is_int($mirrorId) && $mirrorId >= 1 && $mirrorId <= count($this->mirrors)) {
72 $this->currentMirror = $mirrorId - 1;
73 }
74 }
75 }
76
77 /**
78 * Method returns one mirror for use.
79 *
80 * Mirror has previously been selected or is chosen
81 * randomly.
82 *
83 * @access public
84 * @return array array of a mirror's properties or NULL in case of errors
85 */
86 public function getMirror() {
87 $sumMirrors = count($this->mirrors);
88 if ($sumMirrors > 0) {
89 if (!is_int($this->currentMirror)) {
90 $this->currentMirror = rand(0, $sumMirrors - 1);
91 }
92 return $this->mirrors[$this->currentMirror];
93 }
94 return NULL;
95 }
96
97 /**
98 * Gets the mirror url from selected mirror
99 *
100 * @return string
101 */
102 public function getMirrorUrl() {
103 $mirror = $this->getMirror();
104 $mirrorUrl = $mirror['host'] . $mirror['path'];
105 return 'http://' . $mirrorUrl;
106 }
107
108 /**
109 * Method returns all available mirrors.
110 *
111 * @access public
112 * @return array multidimensional array with mirrors and their properties
113 * @see $mirrors, setMirrors()
114 */
115 public function getMirrors() {
116 return $this->mirrors;
117 }
118
119 /**
120 * Method sets available mirrors.
121 *
122 * @param array $mirrors multidimensional array with mirrors and their properties
123 * @return void
124 * @see $mirrors, getMirrors()
125 */
126 public function setMirrors(array $mirrors) {
127 if (count($mirrors) >= 1) {
128 $this->mirrors = $mirrors;
129 }
130 }
131
132 }