This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'refs/pull/2936/head' of github.com:zendframework/zf2 in…
…to hotfix/ssl-case-sensitive
- Loading branch information
83 parents
90b47c5
+
89df4b8
+
07eac97
+
dbff227
+
a8bc04a
+
9e53124
+
aa8a772
+
1dacd62
+
b1d673b
+
4ca3a91
+
3823a47
+
fcdb53c
+
4695159
+
8c4a1a4
+
1ac8bc9
+
266a726
+
a48d0b4
+
8bbe006
+
f7a58c4
+
ef00607
+
03f1a39
+
fa9020e
+
290a868
+
12376e4
+
f183282
+
5609ded
+
b742a14
+
6ee62cd
+
2d5f08c
+
5f0a20d
+
da6d437
+
6020243
+
6cf319f
+
7764705
+
8858064
+
d35a73e
+
4dca7a7
+
e331113
+
b288c81
+
a7e1ad0
+
c0434da
+
bc3b794
+
137fd45
+
d2ea768
+
614b493
+
f2158f1
+
6ad7c37
+
4f10632
+
1be14cc
+
46a76e6
+
bb3de95
+
f1962e2
+
8c5e72d
+
580978e
+
fcbde5a
+
0bc3146
+
e29de4d
+
3fda4ad
+
69ba799
+
3227b7b
+
5f6a326
+
0f56ab5
+
5b30430
+
a696f90
+
08b23c4
+
6438497
+
1d7c8db
+
9d80a9e
+
10c5fc3
+
875f572
+
d32773b
+
ab30fab
+
679b87a
+
4d48267
+
9b1b333
+
a1ead02
+
8013fb4
+
257d444
+
742fa1f
+
2cc8054
+
ab199de
+
4a7857c
+
a36f375
commit a8ec94c
Showing
7 changed files
with
613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_ProgressBar | ||
*/ | ||
|
||
namespace Zend\ProgressBar\Exception; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_ProgressBar | ||
*/ | ||
class PhpEnvironmentException extends RuntimeException | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_ProgressBar | ||
*/ | ||
|
||
namespace Zend\ProgressBar\Upload; | ||
|
||
use Traversable; | ||
use Zend\ProgressBar\Adapter\AbstractAdapter as AbstractProgressAdapter; | ||
use Zend\ProgressBar\Exception; | ||
use Zend\ProgressBar\ProgressBar; | ||
use Zend\Stdlib\ArrayUtils; | ||
|
||
/** | ||
* Abstract class for Upload Progress Handlers | ||
* | ||
* @category Zend | ||
* @package Zend_ProgressBar | ||
*/ | ||
abstract class AbstractUploadHandler implements UploadHandlerInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $sessionNamespace = 'Zend\ProgressBar\Upload\AbstractUploadHandler'; | ||
|
||
/** | ||
* @var AbstractProgressAdapter|ProgressBar | ||
*/ | ||
protected $progressAdapter; | ||
|
||
/** | ||
* @param array|\Traversable $options Optional options | ||
* @throws Exception\InvalidArgumentException | ||
*/ | ||
public function __construct($options = array()) | ||
{ | ||
if (!empty($options)) { | ||
$this->setOptions($options); | ||
} | ||
} | ||
|
||
/** | ||
* Set options for a upload handler. Accepted options are: | ||
* - session_namespace: session namespace for upload progress | ||
* - progress_adapter: progressbar adapter to use for updating progress | ||
* | ||
* @param array|\Traversable $options | ||
* @return AbstractUploadHandler | ||
* @throws Exception\InvalidArgumentException | ||
*/ | ||
public function setOptions($options) | ||
{ | ||
if ($options instanceof Traversable) { | ||
$options = ArrayUtils::iteratorToArray($options); | ||
} elseif (!is_array($options)) { | ||
throw new Exception\InvalidArgumentException( | ||
'The options parameter must be an array or a Traversable' | ||
); | ||
} | ||
|
||
if (isset($options['session_namespace'])) { | ||
$this->setSessionNamespace($options['session_namespace']); | ||
} | ||
if (isset($options['progress_adapter'])) { | ||
$this->setProgressAdapter($options['progress_adapter']); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $sessionNamespace | ||
* @return AbstractUploadHandler|UploadHandlerInterface | ||
*/ | ||
public function setSessionNamespace($sessionNamespace) | ||
{ | ||
$this->sessionNamespace = $sessionNamespace; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSessionNamespace() | ||
{ | ||
return $this->sessionNamespace; | ||
} | ||
|
||
/** | ||
* @param AbstractProgressAdapter|ProgressBar $progressAdapter | ||
* @return AbstractUploadHandler|UploadHandlerInterface | ||
*/ | ||
public function setProgressAdapter($progressAdapter) | ||
{ | ||
$this->progressAdapter = $progressAdapter; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return AbstractProgressAdapter|ProgressBar | ||
*/ | ||
public function getProgressAdapter() | ||
{ | ||
return $this->progressAdapter; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return array | ||
*/ | ||
public function getProgress($id) | ||
{ | ||
$status = array( | ||
'total' => 0, | ||
'current' => 0, | ||
'rate' => 0, | ||
'message' => 'No upload in progress', | ||
'done' => true | ||
); | ||
if (empty($id)) { | ||
return $status; | ||
} | ||
|
||
$newStatus = $this->getUploadProgress($id); | ||
if (false === $newStatus) { | ||
return $status; | ||
} | ||
$status = $newStatus; | ||
if ('' === $status['message']) { | ||
$status['message'] = $this->toByteString($status['current']) . | ||
" - " . $this->toByteString($status['total']); | ||
} | ||
$status['id'] = $id; | ||
|
||
$adapter = $this->getProgressAdapter(); | ||
if (isset($adapter)) { | ||
if ($adapter instanceof AbstractProgressAdapter) { | ||
$adapter = new ProgressBar( | ||
$adapter, 0, $status['total'], $this->getSessionNamespace() | ||
); | ||
$this->setProgressAdapter($adapter); | ||
} | ||
|
||
if (!$adapter instanceof ProgressBar) { | ||
throw new Exception\RuntimeException('Unknown Adapter type given'); | ||
} | ||
|
||
if ($status['done']) { | ||
$adapter->finish(); | ||
} else { | ||
$adapter->update($status['current'], $status['message']); | ||
} | ||
} | ||
|
||
return $status; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return array|boolean | ||
*/ | ||
abstract protected function getUploadProgress($id); | ||
|
||
/** | ||
* Returns the formatted size | ||
* | ||
* @param integer $size | ||
* @return string | ||
*/ | ||
protected function toByteString($size) | ||
{ | ||
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); | ||
for ($i=0; $size >= 1024 && $i < 9; $i++) { | ||
$size /= 1024; | ||
} | ||
|
||
return round($size, 2) . $sizes[$i]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_ProgressBar | ||
*/ | ||
|
||
namespace Zend\ProgressBar\Upload; | ||
|
||
use Traversable; | ||
use Zend\ProgressBar\Exception; | ||
use Zend\Stdlib\ArrayUtils; | ||
|
||
/** | ||
* Progress Bar Upload Handler for the APC extension | ||
* | ||
* @category Zend | ||
* @package Zend_ProgressBar | ||
*/ | ||
class ApcProgress extends AbstractUploadHandler | ||
{ | ||
/** | ||
* @param string $id | ||
* @return array|boolean | ||
* @throws Exception\PhpEnvironmentException | ||
*/ | ||
protected function getUploadProgress($id) | ||
{ | ||
if (!$this->isApcAvailable()) { | ||
throw new Exception\PhpEnvironmentException('APC extension is not installed'); | ||
} | ||
|
||
$uploadInfo = apc_fetch(ini_get('apc.rfc1867_prefix') . $id); | ||
if (!is_array($uploadInfo)) { | ||
return false; | ||
} | ||
|
||
$status = array( | ||
'total' => 0, | ||
'current' => 0, | ||
'rate' => 0, | ||
'message' => '', | ||
'done' => false | ||
); | ||
$status = $uploadInfo + $status; | ||
if (!empty($status['cancel_upload'])) { | ||
$status['done'] = true; | ||
$status['message'] = 'The upload has been canceled'; | ||
} | ||
|
||
return $status; | ||
} | ||
|
||
/** | ||
* Checks for the APC extension | ||
* | ||
* @return boolean | ||
*/ | ||
public function isApcAvailable() | ||
{ | ||
return (bool) ini_get('apc.enabled') | ||
&& (bool) ini_get('apc.rfc1867') | ||
&& is_callable('apc_fetch'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_ProgressBar | ||
*/ | ||
|
||
namespace Zend\ProgressBar\Upload; | ||
|
||
use Traversable; | ||
use Zend\ProgressBar\Exception; | ||
use Zend\Stdlib\ArrayUtils; | ||
|
||
/** | ||
* Progress Bar Upload Handler for PHP 5.4+ Session Upload Progress handling | ||
* | ||
* @category Zend | ||
* @package Zend_ProgressBar | ||
*/ | ||
class SessionProgress extends AbstractUploadHandler | ||
{ | ||
/** | ||
* @param string $id | ||
* @return array|boolean | ||
* @throws Exception\PhpEnvironmentException | ||
*/ | ||
protected function getUploadProgress($id) | ||
{ | ||
if (!$this->isSessionUploadProgressAvailable()) { | ||
throw new Exception\PhpEnvironmentException( | ||
'Session Upload Progress is not available' | ||
); | ||
} | ||
|
||
$uploadInfo = $_SESSION[ini_get('session.upload_progress.prefix') . $id]; | ||
if (!is_array($uploadInfo)) { | ||
return false; | ||
} | ||
|
||
$status = array( | ||
'total' => 0, | ||
'current' => 0, | ||
'rate' => 0, | ||
'message' => '', | ||
'done' => false | ||
); | ||
$status = $uploadInfo + $status; | ||
$status['total'] = $status['content_length']; | ||
$status['current'] = $status['bytes_processed']; | ||
$status['rate'] = $status['bytes_processed'] / (time() - $status['start_time']); | ||
if (!empty($status['cancel_upload'])) { | ||
$status['done'] = true; | ||
$status['message'] = 'The upload has been canceled'; | ||
} | ||
|
||
return $status; | ||
} | ||
|
||
/** | ||
* Checks if Session Upload Progress is available | ||
* | ||
* @return boolean | ||
*/ | ||
public function isSessionUploadProgressAvailable() | ||
{ | ||
return (bool) version_compare(PHP_VERSION, '5.4.0rc1', '>=') | ||
&& (bool) ini_get('session.upload_progress.enabled'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_ProgressBar | ||
*/ | ||
|
||
namespace Zend\ProgressBar\Upload; | ||
|
||
use Traversable; | ||
use Zend\Stdlib\ArrayUtils; | ||
|
||
/** | ||
* Interface for Upload Progress Handlers | ||
* | ||
* @category Zend | ||
* @package Zend_ProgressBar | ||
*/ | ||
interface UploadHandlerInterface | ||
{ | ||
/** | ||
* @param string $id | ||
* @return array | ||
*/ | ||
public function getProgress($id); | ||
} |
Oops, something went wrong.