Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 641a66a

Browse files

File tree

src/Boolean.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public function __construct($typeOrOptions = null, $casting = true, $translation
8888
/**
8989
* Set boolean types
9090
*
91-
* @param integer|array $type
91+
* @param int|array $type
9292
* @throws Exception\InvalidArgumentException
93-
* @return Boolean
93+
* @return bool
9494
*/
9595
public function setType($type = null)
9696
{
@@ -137,7 +137,7 @@ public function getType()
137137
* @param bool $flag When true this filter works like cast
138138
* When false it recognises only true and false
139139
* and all other values are returned as is
140-
* @return Boolean
140+
* @return bool
141141
*/
142142
public function setCasting($flag = true)
143143
{
@@ -158,7 +158,7 @@ public function getCasting()
158158
/**
159159
* @param array|Traversable $translations
160160
* @throws Exception\InvalidArgumentException
161-
* @return Boolean
161+
* @return bool
162162
*/
163163
public function setTranslations($translations)
164164
{

src/Compress/Bz2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct($options = null)
4747
/**
4848
* Returns the set blocksize
4949
*
50-
* @return integer
50+
* @return int
5151
*/
5252
public function getBlocksize()
5353
{
@@ -57,7 +57,7 @@ public function getBlocksize()
5757
/**
5858
* Sets a new blocksize
5959
*
60-
* @param integer $blocksize
60+
* @param int $blocksize
6161
* @throws Exception\InvalidArgumentException
6262
* @return Bz2
6363
*/

src/Compress/Gz.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct($options = null)
4949
/**
5050
* Returns the set compression level
5151
*
52-
* @return integer
52+
* @return int
5353
*/
5454
public function getLevel()
5555
{
@@ -59,7 +59,7 @@ public function getLevel()
5959
/**
6060
* Sets a new compression level
6161
*
62-
* @param integer $level
62+
* @param int $level
6363
* @throws Exception\InvalidArgumentException
6464
* @return Gz
6565
*/

src/DateTimeFormatter.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace Zend\Filter;
11+
12+
use DateTime;
13+
14+
class DateTimeFormatter extends AbstractFilter
15+
{
16+
/**
17+
* A valid format string accepted by date()
18+
*
19+
* @var string
20+
*/
21+
protected $format = DateTime::ISO8601;
22+
23+
/**
24+
* Sets filter options
25+
*
26+
* @param array|Traversable $options
27+
*/
28+
public function __construct($options = null)
29+
{
30+
if ($options) {
31+
$this->setOptions($options);
32+
}
33+
}
34+
35+
/**
36+
* Set the format string accepted by date() to use when formatting a string
37+
*
38+
* @param string $format
39+
* @return \Zend\Filter\DateTimeFormatter
40+
*/
41+
public function setFormat($format)
42+
{
43+
$this->format = $format;
44+
return $this;
45+
}
46+
47+
/**
48+
* Filter a datetime string by normalizing it to the filters specified format
49+
*
50+
* @param string $value
51+
* @throws Exception\InvalidArgumentException
52+
* @return string
53+
*/
54+
public function filter($value)
55+
{
56+
try {
57+
$result = $this->normalizeDateTime($value);
58+
} catch (\Exception $e) {
59+
// DateTime threw an exception, an invalid date string was provided
60+
throw new Exception\InvalidArgumentException('Invalid date string provided', $e->getCode(), $e);
61+
}
62+
63+
return $result;
64+
}
65+
66+
/**
67+
* Normalize the provided value to a formatted string
68+
*
69+
* @param string|int|DateTime $value
70+
* @returns string
71+
*/
72+
protected function normalizeDateTime($value)
73+
{
74+
if (is_int($value)) {
75+
$dateTime = new DateTime('@' . $value);
76+
} elseif (!$value instanceof DateTime) {
77+
$dateTime = new DateTime($value);
78+
}
79+
80+
return $dateTime->format($this->format);
81+
}
82+
}

src/File/Rename.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ protected function _convertOptions($options)
225225
break;
226226

227227
case 'randomize' :
228-
$files['randomize'] = (boolean) $value;
228+
$files['randomize'] = (bool) $value;
229229
break;
230230

231231
default:

src/File/RenameUpload.php

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class RenameUpload extends AbstractFilter
1919
* @var array
2020
*/
2121
protected $options = array(
22-
'target' => null,
23-
'use_upload_name' => false,
24-
'overwrite' => false,
25-
'randomize' => false,
22+
'target' => null,
23+
'use_upload_name' => false,
24+
'use_upload_extension' => false,
25+
'overwrite' => false,
26+
'randomize' => false,
2627
);
2728

2829
/**
@@ -72,55 +73,74 @@ public function getTarget()
7273
}
7374

7475
/**
75-
* @param boolean $flag When true, this filter will use the $_FILES['name']
76+
* @param bool $flag When true, this filter will use the $_FILES['name']
7677
* as the target filename.
7778
* Otherwise, it uses the default 'target' rules.
7879
* @return RenameUpload
7980
*/
8081
public function setUseUploadName($flag = true)
8182
{
82-
$this->options['use_upload_name'] = (boolean) $flag;
83+
$this->options['use_upload_name'] = (bool) $flag;
8384
return $this;
8485
}
8586

8687
/**
87-
* @return boolean
88+
* @return bool
8889
*/
8990
public function getUseUploadName()
9091
{
9192
return $this->options['use_upload_name'];
9293
}
9394

9495
/**
95-
* @param boolean $flag Shall existing files be overwritten?
96+
* @param bool $flag When true, this filter will use the original file
97+
* extension for the target filename
98+
* @return RenameUpload
99+
*/
100+
public function setUseUploadExtension($flag = true)
101+
{
102+
$this->options['use_upload_extension'] = (bool) $flag;
103+
return $this;
104+
}
105+
106+
/**
107+
* @return bool
108+
*/
109+
public function getUseUploadExtension()
110+
{
111+
return $this->options['use_upload_extension'];
112+
}
113+
114+
/**
115+
* @param bool $flag Shall existing files be overwritten?
96116
* @return RenameUpload
97117
*/
98118
public function setOverwrite($flag = true)
99119
{
100-
$this->options['overwrite'] = (boolean) $flag;
120+
$this->options['overwrite'] = (bool) $flag;
101121
return $this;
102122
}
103123

104124
/**
105-
* @return boolean
125+
* @return bool
106126
*/
107127
public function getOverwrite()
108128
{
109129
return $this->options['overwrite'];
110130
}
111131

112132
/**
113-
* @param boolean $flag Shall target files have a random postfix attached?
133+
* @param bool $flag Shall target files have a random postfix attached?
114134
* @return RenameUpload
115135
*/
116136
public function setRandomize($flag = true)
117137
{
118-
$this->options['randomize'] = (boolean) $flag;
138+
$this->options['randomize'] = (bool) $flag;
119139
return $this;
120140
}
121141

122142
/**
123-
* @return boolean
143+
* @return bool
124144
*/
125145
public function getRandomize()
126146
{
@@ -179,7 +199,7 @@ public function filter($value)
179199
* @param string $sourceFile Source file path
180200
* @param string $targetFile Target file path
181201
* @throws \Zend\Filter\Exception\RuntimeException
182-
* @return boolean
202+
* @return bool
183203
*/
184204
protected function moveUploadedFile($sourceFile, $targetFile)
185205
{
@@ -242,12 +262,19 @@ protected function getFinalTarget($uploadData)
242262
$targetFile = basename($uploadData['name']);
243263
} elseif (!is_dir($target)) {
244264
$targetFile = basename($target);
265+
if ($this->getUseUploadExtension() && !$this->getRandomize()) {
266+
$targetInfo = pathinfo($targetFile);
267+
$sourceinfo = pathinfo($uploadData['name']);
268+
if (isset($sourceinfo['extension'])) {
269+
$targetFile = $targetInfo['filename'] . '.' . $sourceinfo['extension'];
270+
}
271+
}
245272
} else {
246273
$targetFile = basename($source);
247274
}
248275

249276
if ($this->getRandomize()) {
250-
$targetFile = $this->applyRandomToFilename($targetFile);
277+
$targetFile = $this->applyRandomToFilename($uploadData['name'], $targetFile);
251278
}
252279

253280
return $targetDir . $targetFile;
@@ -257,13 +284,20 @@ protected function getFinalTarget($uploadData)
257284
* @param string $filename
258285
* @return string
259286
*/
260-
protected function applyRandomToFilename($filename)
287+
protected function applyRandomToFilename($source, $filename)
261288
{
262289
$info = pathinfo($filename);
263290
$filename = $info['filename'] . uniqid('_');
264-
if (isset($info['extension'])) {
265-
$filename .= '.' . $info['extension'];
291+
292+
$sourceinfo = pathinfo($source);
293+
294+
$extension = '';
295+
if ($this->getUseUploadExtension() === true && isset($sourceinfo['extension'])) {
296+
$extension .= '.' . $sourceinfo['extension'];
297+
} elseif (isset($info['extension'])) {
298+
$extension .= '.' . $info['extension'];
266299
}
267-
return $filename;
300+
301+
return $filename . $extension;
268302
}
269303
}

src/HtmlEntities.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class HtmlEntities extends AbstractFilter
1717
/**
1818
* Corresponds to the second htmlentities() argument
1919
*
20-
* @var integer
20+
* @var int
2121
*/
2222
protected $quoteStyle;
2323

@@ -78,7 +78,7 @@ public function __construct($options = array())
7878
/**
7979
* Returns the quoteStyle option
8080
*
81-
* @return integer
81+
* @return int
8282
*/
8383
public function getQuoteStyle()
8484
{
@@ -88,7 +88,7 @@ public function getQuoteStyle()
8888
/**
8989
* Sets the quoteStyle option
9090
*
91-
* @param integer $quoteStyle
91+
* @param int $quoteStyle
9292
* @return HtmlEntities Provides a fluent interface
9393
*/
9494
public function setQuoteStyle($quoteStyle)

src/Inflector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ public function setRules(Array $rules)
248248
*
249249
* ex:
250250
* array(
251-
* ':controller' => array('CamelCaseToUnderscore','StringToLower'),
252-
* ':action' => array('CamelCaseToUnderscore','StringToLower'),
251+
* ':controller' => array('CamelCaseToUnderscore', 'StringToLower'),
252+
* ':action' => array('CamelCaseToUnderscore', 'StringToLower'),
253253
* 'suffix' => 'phtml'
254254
* );
255255
*

src/Int.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Int extends AbstractFilter
1717
* Returns (int) $value
1818
*
1919
* @param string $value
20-
* @return integer
20+
* @return int
2121
*/
2222
public function filter($value)
2323
{

src/Null.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public function __construct($typeOrOptions = null)
6868
/**
6969
* Set boolean types
7070
*
71-
* @param integer|array $type
71+
* @param int|array $type
7272
* @throws Exception\InvalidArgumentException
73-
* @return Boolean
73+
* @return bool
7474
*/
7575
public function setType($type = null)
7676
{

0 commit comments

Comments
 (0)