@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | // extract parameter names from the query string |
38 | 38 | $result = array(); |
39 | 39 | preg_match_all('/&?([^&]+)=.*/sixU', $queryString, $result, PREG_PATTERN_ORDER); |
40 | - if(isset($result[1])) { |
|
40 | + if (isset($result[1])) { |
|
41 | 41 | $paramNames = $result[1]; |
42 | 42 | } |
43 | 43 | |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | // possible naming conflicts like having both parameters "foo.bar" |
61 | 61 | // and "foo_bar" in the query string: since "foo.bar" would be converted |
62 | 62 | // to "foo_bar", one of the two would be replaced. |
63 | - if($fixRequired) |
|
63 | + if ($fixRequired) |
|
64 | 64 | { |
65 | 65 | $counter = 1; |
66 | 66 | $placeholders = array(); |
67 | - foreach($paramNames as $paramName) |
|
67 | + foreach ($paramNames as $paramName) |
|
68 | 68 | { |
69 | 69 | // create a unique placeholder name |
70 | 70 | $placeholder = '__PLACEHOLDER'.$counter.'__'; |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | parse_str($queryString, $parsed); |
95 | 95 | |
96 | 96 | // do any of the parameter names need to be fixed? |
97 | - if(!$fixRequired) { |
|
97 | + if (!$fixRequired) { |
|
98 | 98 | return $parsed; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $keep = array(); |
102 | 102 | |
103 | - foreach($parsed as $name => $value) |
|
103 | + foreach ($parsed as $name => $value) |
|
104 | 104 | { |
105 | 105 | $keep[$table[$name]] = $value; |
106 | 106 | } |
@@ -63,7 +63,7 @@ |
||
63 | 63 | return $this->getBoolOption('cut'); |
64 | 64 | } |
65 | 65 | |
66 | - public function setCuttingEnabled(bool $enabled=true) : ConvertHelper_WordWrapper |
|
66 | + public function setCuttingEnabled(bool $enabled = true) : ConvertHelper_WordWrapper |
|
67 | 67 | { |
68 | 68 | $this->setOption('cut', $enabled); |
69 | 69 | return $this; |
@@ -92,8 +92,7 @@ |
||
92 | 92 | if (mb_strlen($actual.$word) <= $width) |
93 | 93 | { |
94 | 94 | $actual .= $word.' '; |
95 | - } |
|
96 | - else |
|
95 | + } else |
|
97 | 96 | { |
98 | 97 | if ($actual != '') { |
99 | 98 | $line .= rtrim($actual).$break; |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | const TOKEN_MONTHS = 'm'; |
38 | 38 | const TOKEN_YEARS = 'y'; |
39 | 39 | |
40 | - /** |
|
41 | - * @var \DateInterval |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var \DateInterval |
|
42 | + */ |
|
43 | 43 | protected $interval; |
44 | 44 | |
45 | - /** |
|
46 | - * @var int |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var int |
|
47 | + */ |
|
48 | 48 | protected $seconds; |
49 | 49 | |
50 | 50 | protected function __construct(int $seconds) |
@@ -69,33 +69,33 @@ discard block |
||
69 | 69 | $this->interval = $interval; |
70 | 70 | } |
71 | 71 | |
72 | - /** |
|
73 | - * Creates the interval from a specific amount of seconds. |
|
74 | - * |
|
75 | - * @param int $seconds |
|
76 | - * @return \AppUtils\ConvertHelper_DateInterval |
|
77 | - */ |
|
72 | + /** |
|
73 | + * Creates the interval from a specific amount of seconds. |
|
74 | + * |
|
75 | + * @param int $seconds |
|
76 | + * @return \AppUtils\ConvertHelper_DateInterval |
|
77 | + */ |
|
78 | 78 | public static function fromSeconds(int $seconds) |
79 | 79 | { |
80 | 80 | return new ConvertHelper_DateInterval($seconds); |
81 | 81 | } |
82 | 82 | |
83 | - /** |
|
84 | - * Creates the interval from an existing regular interval instance. |
|
85 | - * |
|
86 | - * @param \DateInterval $interval |
|
87 | - * @return \AppUtils\ConvertHelper_DateInterval |
|
88 | - */ |
|
83 | + /** |
|
84 | + * Creates the interval from an existing regular interval instance. |
|
85 | + * |
|
86 | + * @param \DateInterval $interval |
|
87 | + * @return \AppUtils\ConvertHelper_DateInterval |
|
88 | + */ |
|
89 | 89 | public static function fromInterval(\DateInterval $interval) |
90 | 90 | { |
91 | 91 | return self::fromSeconds(ConvertHelper::interval2seconds($interval)); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * Retrieves the PHP native date interval. |
|
96 | - * |
|
97 | - * @return \DateInterval |
|
98 | - */ |
|
94 | + /** |
|
95 | + * Retrieves the PHP native date interval. |
|
96 | + * |
|
97 | + * @return \DateInterval |
|
98 | + */ |
|
99 | 99 | public function getInterval() : \DateInterval |
100 | 100 | { |
101 | 101 | return $this->interval; |
@@ -131,31 +131,31 @@ discard block |
||
131 | 131 | return $this->getToken(self::TOKEN_YEARS); |
132 | 132 | } |
133 | 133 | |
134 | - /** |
|
135 | - * Retrieves a specific time token, e.g. "h" (for hours). |
|
136 | - * Using the constants to specifiy the tokens is recommended. |
|
137 | - * |
|
138 | - * @param string $token |
|
139 | - * @return int |
|
140 | - * |
|
141 | - * @see ConvertHelper_DateInterval::TOKEN_SECONDS |
|
142 | - * @see ConvertHelper_DateInterval::TOKEN_MINUTES |
|
143 | - * @see ConvertHelper_DateInterval::TOKEN_HOURS |
|
144 | - * @see ConvertHelper_DateInterval::TOKEN_DAYS |
|
145 | - * @see ConvertHelper_DateInterval::TOKEN_MONTHS |
|
146 | - * @see ConvertHelper_DateInterval::TOKEN_YEARS |
|
147 | - */ |
|
134 | + /** |
|
135 | + * Retrieves a specific time token, e.g. "h" (for hours). |
|
136 | + * Using the constants to specifiy the tokens is recommended. |
|
137 | + * |
|
138 | + * @param string $token |
|
139 | + * @return int |
|
140 | + * |
|
141 | + * @see ConvertHelper_DateInterval::TOKEN_SECONDS |
|
142 | + * @see ConvertHelper_DateInterval::TOKEN_MINUTES |
|
143 | + * @see ConvertHelper_DateInterval::TOKEN_HOURS |
|
144 | + * @see ConvertHelper_DateInterval::TOKEN_DAYS |
|
145 | + * @see ConvertHelper_DateInterval::TOKEN_MONTHS |
|
146 | + * @see ConvertHelper_DateInterval::TOKEN_YEARS |
|
147 | + */ |
|
148 | 148 | public function getToken(string $token) : int |
149 | 149 | { |
150 | 150 | return (int)$this->interval->$token; |
151 | 151 | } |
152 | 152 | |
153 | - /** |
|
154 | - * The total amount of seconds in the interval (including |
|
155 | - * everything, from seconds to days, months, years...). |
|
156 | - * |
|
157 | - * @return int |
|
158 | - */ |
|
153 | + /** |
|
154 | + * The total amount of seconds in the interval (including |
|
155 | + * everything, from seconds to days, months, years...). |
|
156 | + * |
|
157 | + * @return int |
|
158 | + */ |
|
159 | 159 | public function getTotalSeconds() : int |
160 | 160 | { |
161 | 161 | return $this->seconds; |
@@ -57,7 +57,7 @@ |
||
57 | 57 | |
58 | 58 | $interval = $d2->diff($d1); |
59 | 59 | |
60 | - if($interval === false) |
|
60 | + if ($interval === false) |
|
61 | 61 | { |
62 | 62 | throw new ConvertHelper_Exception( |
63 | 63 | 'Cannot create interval', |
@@ -26,39 +26,39 @@ discard block |
||
26 | 26 | const ERROR_NO_DATE_FROM_SET = 43401; |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @var int |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var int |
|
31 | + */ |
|
32 | 32 | protected $dateFrom; |
33 | 33 | |
34 | - /** |
|
35 | - * @var int |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var int |
|
36 | + */ |
|
37 | 37 | protected $dateTo; |
38 | 38 | |
39 | - /** |
|
40 | - * @var bool |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | 42 | protected $future = false; |
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | 47 | protected $interval = ''; |
48 | 48 | |
49 | - /** |
|
50 | - * @var int |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var int |
|
51 | + */ |
|
52 | 52 | protected $difference = 0; |
53 | 53 | |
54 | - /** |
|
55 | - * @var int |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var int |
|
56 | + */ |
|
57 | 57 | protected $dateDiff = 0; |
58 | 58 | |
59 | - /** |
|
60 | - * @var array |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var array |
|
61 | + */ |
|
62 | 62 | protected static $texts; |
63 | 63 | |
64 | 64 | public function __construct() |
@@ -78,17 +78,17 @@ discard block |
||
78 | 78 | unset(self::$texts); |
79 | 79 | } |
80 | 80 | |
81 | - /** |
|
82 | - * Sets the origin date to calculate from. |
|
83 | - * |
|
84 | - * NOTE: if this is further in the future than |
|
85 | - * the to: date, it will be considered as a |
|
86 | - * calculation for something to come, i.e. |
|
87 | - * "In two days". |
|
88 | - * |
|
89 | - * @param \DateTime $date |
|
90 | - * @return ConvertHelper_DurationConverter |
|
91 | - */ |
|
81 | + /** |
|
82 | + * Sets the origin date to calculate from. |
|
83 | + * |
|
84 | + * NOTE: if this is further in the future than |
|
85 | + * the to: date, it will be considered as a |
|
86 | + * calculation for something to come, i.e. |
|
87 | + * "In two days". |
|
88 | + * |
|
89 | + * @param \DateTime $date |
|
90 | + * @return ConvertHelper_DurationConverter |
|
91 | + */ |
|
92 | 92 | public function setDateFrom(\DateTime $date) : ConvertHelper_DurationConverter |
93 | 93 | { |
94 | 94 | $this->dateFrom = ConvertHelper::date2timestamp($date); |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | return $this; |
97 | 97 | } |
98 | 98 | |
99 | - /** |
|
100 | - * Sets the date to calculate to. Defaults to |
|
101 | - * the current time if not set. |
|
102 | - * |
|
103 | - * @param \DateTime $date |
|
104 | - * @return ConvertHelper_DurationConverter |
|
105 | - */ |
|
99 | + /** |
|
100 | + * Sets the date to calculate to. Defaults to |
|
101 | + * the current time if not set. |
|
102 | + * |
|
103 | + * @param \DateTime $date |
|
104 | + * @return ConvertHelper_DurationConverter |
|
105 | + */ |
|
106 | 106 | public function setDateTo(\DateTime $date) : ConvertHelper_DurationConverter |
107 | 107 | { |
108 | 108 | $this->dateTo = ConvertHelper::date2timestamp($date); |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | return $this; |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * Converts the specified dates to a human readable string. |
|
115 | - * |
|
116 | - * @throws ConvertHelper_Exception |
|
117 | - * @return string |
|
118 | - * |
|
119 | - * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
120 | - */ |
|
113 | + /** |
|
114 | + * Converts the specified dates to a human readable string. |
|
115 | + * |
|
116 | + * @throws ConvertHelper_Exception |
|
117 | + * @return string |
|
118 | + * |
|
119 | + * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
120 | + */ |
|
121 | 121 | public function convert() : string |
122 | 122 | { |
123 | 123 | $this->initTexts(); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function __construct() |
65 | 65 | { |
66 | - if(class_exists('\AppLocalize\Localization')) { |
|
66 | + if (class_exists('\AppLocalize\Localization')) { |
|
67 | 67 | \AppLocalize\Localization::onLocaleChanged(array($this, 'handle_localeChanged')); |
68 | 68 | } |
69 | 69 | } |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | |
126 | 126 | $epoch = 'past'; |
127 | 127 | $key = 'singular'; |
128 | - if($this->dateDiff > 1) { |
|
128 | + if ($this->dateDiff > 1) { |
|
129 | 129 | $key = 'plural'; |
130 | 130 | } |
131 | 131 | |
132 | - if($this->future) { |
|
132 | + if ($this->future) { |
|
133 | 133 | $epoch = 'future'; |
134 | 134 | } |
135 | 135 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | protected function initTexts() |
144 | 144 | { |
145 | - if(isset(self::$texts)) { |
|
145 | + if (isset(self::$texts)) { |
|
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $day = (int)date("j", $this->dateTo); |
229 | 229 | $year = (int)date("Y", $this->dateFrom); |
230 | 230 | |
231 | - while(mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $this->dateTo) |
|
231 | + while (mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $this->dateTo) |
|
232 | 232 | { |
233 | 233 | $months_difference++; |
234 | 234 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | protected function resolveCalculations() : void |
250 | 250 | { |
251 | - if(!isset($this->dateFrom)) |
|
251 | + if (!isset($this->dateFrom)) |
|
252 | 252 | { |
253 | 253 | throw new ConvertHelper_Exception( |
254 | 254 | 'No date from has been specified.', |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | } |
259 | 259 | |
260 | 260 | // no date to set? Assume we want to use today. |
261 | - if(!isset($this->dateTo)) |
|
261 | + if (!isset($this->dateTo)) |
|
262 | 262 | { |
263 | 263 | $this->dateTo = time(); |
264 | 264 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | |
338 | 338 | $difference = $this->dateTo - $this->dateFrom; |
339 | 339 | |
340 | - if($difference < 0) |
|
340 | + if ($difference < 0) |
|
341 | 341 | { |
342 | 342 | $difference = $difference * -1; |
343 | 343 | $this->future = true; |
@@ -17,21 +17,20 @@ discard block |
||
17 | 17 | * @package Application Utils |
18 | 18 | * @subpackage ConvertHelper |
19 | 19 | * @author Sebastian Mordziol <[email protected]> |
20 | - |
|
21 | 20 | * @see ConvertHelper::interval2string() |
22 | 21 | */ |
23 | 22 | class ConvertHelper_IntervalConverter |
24 | 23 | { |
25 | 24 | const ERROR_MISSING_TRANSLATION = 43501; |
26 | 25 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
30 | 29 | protected static $texts; |
31 | 30 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
35 | 34 | protected $tokens = array('y', 'm', 'd', 'h', 'i', 's'); |
36 | 35 | |
37 | 36 | public function __construct() |
@@ -41,25 +40,25 @@ discard block |
||
41 | 40 | } |
42 | 41 | } |
43 | 42 | |
44 | - /** |
|
45 | - * Called whenever the application locale has changed, |
|
46 | - * to reset the internal translation cache. |
|
47 | - */ |
|
43 | + /** |
|
44 | + * Called whenever the application locale has changed, |
|
45 | + * to reset the internal translation cache. |
|
46 | + */ |
|
48 | 47 | public function handle_localeChanged() |
49 | 48 | { |
50 | 49 | unset(self::$texts); |
51 | 50 | } |
52 | 51 | |
53 | - /** |
|
54 | - * Converts the specified interval to a human readable |
|
55 | - * string, e.g. "2 hours and 4 minutes". |
|
56 | - * |
|
57 | - * @param \DateInterval $interval |
|
58 | - * @return string |
|
59 | - * @throws ConvertHelper_Exception |
|
60 | - * |
|
61 | - * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
62 | - */ |
|
52 | + /** |
|
53 | + * Converts the specified interval to a human readable |
|
54 | + * string, e.g. "2 hours and 4 minutes". |
|
55 | + * |
|
56 | + * @param \DateInterval $interval |
|
57 | + * @return string |
|
58 | + * @throws ConvertHelper_Exception |
|
59 | + * |
|
60 | + * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
61 | + */ |
|
63 | 62 | public function toString(\DateInterval $interval) : string |
64 | 63 | { |
65 | 64 | $this->initTexts(); |
@@ -88,14 +87,14 @@ discard block |
||
88 | 87 | return t('%1$s and %2$s', implode(', ', $parts), $last); |
89 | 88 | } |
90 | 89 | |
91 | - /** |
|
92 | - * Translates the selected time token, e.g. "y" (for year). |
|
93 | - * |
|
94 | - * @param string $token |
|
95 | - * @param ConvertHelper_DateInterval $interval |
|
96 | - * @throws ConvertHelper_Exception |
|
97 | - * @return string |
|
98 | - */ |
|
90 | + /** |
|
91 | + * Translates the selected time token, e.g. "y" (for year). |
|
92 | + * |
|
93 | + * @param string $token |
|
94 | + * @param ConvertHelper_DateInterval $interval |
|
95 | + * @throws ConvertHelper_Exception |
|
96 | + * @return string |
|
97 | + */ |
|
99 | 98 | protected function translateToken(string $token, ConvertHelper_DateInterval $interval) : string |
100 | 99 | { |
101 | 100 | $value = $interval->getToken($token); |
@@ -123,13 +122,13 @@ discard block |
||
123 | 122 | ); |
124 | 123 | } |
125 | 124 | |
126 | - /** |
|
127 | - * Resolves all time tokens that need to be translated in |
|
128 | - * the subject interval, depending on its length. |
|
129 | - * |
|
130 | - * @param ConvertHelper_DateInterval $interval |
|
131 | - * @return array |
|
132 | - */ |
|
125 | + /** |
|
126 | + * Resolves all time tokens that need to be translated in |
|
127 | + * the subject interval, depending on its length. |
|
128 | + * |
|
129 | + * @param ConvertHelper_DateInterval $interval |
|
130 | + * @return array |
|
131 | + */ |
|
133 | 132 | protected function resolveTokens(ConvertHelper_DateInterval $interval) : array |
134 | 133 | { |
135 | 134 | $offset = 0; |
@@ -147,9 +146,9 @@ discard block |
||
147 | 146 | return array(); |
148 | 147 | } |
149 | 148 | |
150 | - /** |
|
151 | - * Initializes the translateable strings. |
|
152 | - */ |
|
149 | + /** |
|
150 | + * Initializes the translateable strings. |
|
151 | + */ |
|
153 | 152 | protected function initTexts() : void |
154 | 153 | { |
155 | 154 | if(isset(self::$texts)) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function __construct() |
38 | 38 | { |
39 | - if(class_exists('\AppLocalize\Localization')) { |
|
39 | + if (class_exists('\AppLocalize\Localization')) { |
|
40 | 40 | \AppLocalize\Localization::onLocaleChanged(array($this, 'handle_localeChanged')); |
41 | 41 | } |
42 | 42 | } |
@@ -69,17 +69,17 @@ discard block |
||
69 | 69 | $keep = $this->resolveTokens($interval); |
70 | 70 | |
71 | 71 | $parts = array(); |
72 | - foreach($keep as $token) |
|
72 | + foreach ($keep as $token) |
|
73 | 73 | { |
74 | 74 | $value = $interval->getToken($token); |
75 | - if($value === 0) { |
|
75 | + if ($value === 0) { |
|
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | |
79 | 79 | $parts[] = $this->translateToken($token, $interval); |
80 | 80 | } |
81 | 81 | |
82 | - if(count($parts) == 1) { |
|
82 | + if (count($parts) == 1) { |
|
83 | 83 | return $parts[0]; |
84 | 84 | } |
85 | 85 | |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | $value = $interval->getToken($token); |
102 | 102 | |
103 | 103 | $suffix = 'p'; |
104 | - if($value == 1) { $suffix = 's'; } |
|
104 | + if ($value == 1) { $suffix = 's'; } |
|
105 | 105 | $token .= $suffix; |
106 | 106 | |
107 | - if(!isset(self::$texts[$token])) |
|
107 | + if (!isset(self::$texts[$token])) |
|
108 | 108 | { |
109 | 109 | throw new ConvertHelper_Exception( |
110 | 110 | 'Missing interval translation', |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | { |
135 | 135 | $offset = 0; |
136 | 136 | |
137 | - foreach($this->tokens as $token) |
|
137 | + foreach ($this->tokens as $token) |
|
138 | 138 | { |
139 | - if($interval->getToken($token) > 0) |
|
139 | + if ($interval->getToken($token) > 0) |
|
140 | 140 | { |
141 | 141 | return array_slice($this->tokens, $offset); |
142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function initTexts() : void |
154 | 154 | { |
155 | - if(isset(self::$texts)) { |
|
155 | + if (isset(self::$texts)) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | |
39 | 39 | protected $file; |
40 | 40 | |
41 | - /** |
|
42 | - * @var \ZipArchive |
|
43 | - */ |
|
41 | + /** |
|
42 | + * @var \ZipArchive |
|
43 | + */ |
|
44 | 44 | protected $zip; |
45 | 45 | |
46 | 46 | public function __construct($targetFile) |
@@ -48,33 +48,33 @@ discard block |
||
48 | 48 | $this->file = $targetFile; |
49 | 49 | } |
50 | 50 | |
51 | - /** |
|
52 | - * Sets an option, among the available options: |
|
53 | - * |
|
54 | - * <ul> |
|
55 | - * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
56 | - * </ul> |
|
57 | - * |
|
58 | - * @param string $name |
|
59 | - * @param mixed $value |
|
60 | - * @return ZIPHelper |
|
61 | - */ |
|
51 | + /** |
|
52 | + * Sets an option, among the available options: |
|
53 | + * |
|
54 | + * <ul> |
|
55 | + * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
56 | + * </ul> |
|
57 | + * |
|
58 | + * @param string $name |
|
59 | + * @param mixed $value |
|
60 | + * @return ZIPHelper |
|
61 | + */ |
|
62 | 62 | public function setOption($name, $value) |
63 | 63 | { |
64 | 64 | $this->options[$name] = $value; |
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Adds a file to the zip. By default, the file is stored |
|
70 | - * with the same name in the root of the zip. Use the optional |
|
71 | - * parameter to change the location in the zip. |
|
72 | - * |
|
73 | - * @param string $filePath |
|
74 | - * @param string $zipPath |
|
75 | - * @throws ZIPHelper_Exception |
|
76 | - * @return bool |
|
77 | - */ |
|
68 | + /** |
|
69 | + * Adds a file to the zip. By default, the file is stored |
|
70 | + * with the same name in the root of the zip. Use the optional |
|
71 | + * parameter to change the location in the zip. |
|
72 | + * |
|
73 | + * @param string $filePath |
|
74 | + * @param string $zipPath |
|
75 | + * @throws ZIPHelper_Exception |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | 78 | public function addFile($filePath, $zipPath=null) |
79 | 79 | { |
80 | 80 | $this->open(); |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | readfile($this->file); |
245 | 245 | } |
246 | 246 | |
247 | - /** |
|
248 | - * Like {@link ZIPHelper::download()}, but deletes the |
|
249 | - * file after sending it to the browser. |
|
250 | - * |
|
251 | - * @param string|NULL $fileName Override the ZIP's file name for the download |
|
252 | - * @see ZIPHelper::download() |
|
253 | - */ |
|
247 | + /** |
|
248 | + * Like {@link ZIPHelper::download()}, but deletes the |
|
249 | + * file after sending it to the browser. |
|
250 | + * |
|
251 | + * @param string|NULL $fileName Override the ZIP's file name for the download |
|
252 | + * @see ZIPHelper::download() |
|
253 | + */ |
|
254 | 254 | public function downloadAndDelete($fileName=null) |
255 | 255 | { |
256 | 256 | $this->download($fileName); |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | FileHelper::deleteFile($fileName); |
259 | 259 | } |
260 | 260 | |
261 | - /** |
|
262 | - * Extracts all files and folders from the zip to the |
|
263 | - * target folder. If no folder is specified, the files |
|
264 | - * are extracted into the same folder as the zip itself. |
|
265 | - * |
|
266 | - * @param string $outputFolder |
|
267 | - * @return boolean |
|
268 | - */ |
|
261 | + /** |
|
262 | + * Extracts all files and folders from the zip to the |
|
263 | + * target folder. If no folder is specified, the files |
|
264 | + * are extracted into the same folder as the zip itself. |
|
265 | + * |
|
266 | + * @param string $outputFolder |
|
267 | + * @return boolean |
|
268 | + */ |
|
269 | 269 | public function extractAll($outputFolder=null) |
270 | 270 | { |
271 | 271 | if(empty($outputFolder)) { |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | } |
279 | 279 | |
280 | 280 | |
281 | - /** |
|
282 | - * @return \ZipArchive |
|
283 | - */ |
|
281 | + /** |
|
282 | + * @return \ZipArchive |
|
283 | + */ |
|
284 | 284 | public function getArchive() |
285 | 285 | { |
286 | 286 | $this->open(); |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | return $this->zip; |
289 | 289 | } |
290 | 290 | |
291 | - /** |
|
292 | - * JSON encodes the specified data and adds the json as |
|
293 | - * a file in the ZIP archive. |
|
294 | - * |
|
295 | - * @param mixed $data |
|
296 | - * @param string $zipPath |
|
297 | - * @return boolean |
|
298 | - */ |
|
291 | + /** |
|
292 | + * JSON encodes the specified data and adds the json as |
|
293 | + * a file in the ZIP archive. |
|
294 | + * |
|
295 | + * @param mixed $data |
|
296 | + * @param string $zipPath |
|
297 | + * @return boolean |
|
298 | + */ |
|
299 | 299 | public function addJSON($data, $zipPath) |
300 | 300 | { |
301 | 301 | return $this->addString( |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | const ERROR_OPENING_ZIP_FILE = 338003; |
32 | 32 | |
33 | - const ERROR_CANNOT_SAVE_FILE_TO_DISK =338004; |
|
33 | + const ERROR_CANNOT_SAVE_FILE_TO_DISK = 338004; |
|
34 | 34 | |
35 | 35 | protected $options = array( |
36 | 36 | 'WriteThreshold' => 100 |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @throws ZIPHelper_Exception |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public function addFile($filePath, $zipPath=null) |
|
78 | + public function addFile($filePath, $zipPath = null) |
|
79 | 79 | { |
80 | 80 | $this->open(); |
81 | 81 | |
@@ -120,16 +120,16 @@ discard block |
||
120 | 120 | |
121 | 121 | protected function open() |
122 | 122 | { |
123 | - if($this->open) { |
|
123 | + if ($this->open) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - if(!isset($this->zip)) { |
|
127 | + if (!isset($this->zip)) { |
|
128 | 128 | $this->zip = new \ZipArchive(); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $flag = null; |
132 | - if(!file_exists($this->file)) { |
|
132 | + if (!file_exists($this->file)) { |
|
133 | 133 | $flag = \ZipArchive::CREATE; |
134 | 134 | } |
135 | 135 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | $this->fileTracker++; |
171 | 171 | |
172 | - if($this->options['WriteThreshold'] < 1) { |
|
172 | + if ($this->options['WriteThreshold'] < 1) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | protected function close() |
184 | 184 | { |
185 | - if(!$this->open) { |
|
185 | + if (!$this->open) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | throw new ZIPHelper_Exception( |
191 | 191 | 'Could not save ZIP file to disk', |
192 | 192 | sprintf( |
193 | - 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, ' . |
|
194 | - 'including adding files that do not exist on disk, trying to create an empty zip, ' . |
|
193 | + 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, '. |
|
194 | + 'including adding files that do not exist on disk, trying to create an empty zip, '. |
|
195 | 195 | 'or trying to save to a directory that does not exist.', |
196 | 196 | $this->file |
197 | 197 | ), |
@@ -228,17 +228,17 @@ discard block |
||
228 | 228 | * @see ZIPHelper::downloadAndDelete() |
229 | 229 | * @throws ZIPHelper_Exception |
230 | 230 | */ |
231 | - public function download($fileName=null) |
|
231 | + public function download($fileName = null) |
|
232 | 232 | { |
233 | 233 | $this->save(); |
234 | 234 | |
235 | - if(empty($fileName)) { |
|
235 | + if (empty($fileName)) { |
|
236 | 236 | $fileName = basename($this->file); |
237 | 237 | } |
238 | 238 | |
239 | 239 | header('Content-type: application/zip'); |
240 | - header('Content-Disposition: attachment; filename=' . $fileName); |
|
241 | - header('Content-length: ' . filesize($this->file)); |
|
240 | + header('Content-Disposition: attachment; filename='.$fileName); |
|
241 | + header('Content-length: '.filesize($this->file)); |
|
242 | 242 | header('Pragma: no-cache'); |
243 | 243 | header('Expires: 0'); |
244 | 244 | readfile($this->file); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param string|NULL $fileName Override the ZIP's file name for the download |
252 | 252 | * @see ZIPHelper::download() |
253 | 253 | */ |
254 | - public function downloadAndDelete($fileName=null) |
|
254 | + public function downloadAndDelete($fileName = null) |
|
255 | 255 | { |
256 | 256 | $this->download($fileName); |
257 | 257 | |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | * @param string $outputFolder |
267 | 267 | * @return boolean |
268 | 268 | */ |
269 | - public function extractAll($outputFolder=null) |
|
269 | + public function extractAll($outputFolder = null) |
|
270 | 270 | { |
271 | - if(empty($outputFolder)) { |
|
271 | + if (empty($outputFolder)) { |
|
272 | 272 | $outputFolder = dirname($this->file); |
273 | 273 | } |
274 | 274 |