Skip to content

Commit

Permalink
Merge remote-tracking branch 'zf2/master' into bugfix/templatemap-gen…
Browse files Browse the repository at this point in the history
…erator-append-to-non-existing-file
  • Loading branch information
rohm1 committed Nov 27, 2014
2 parents 9f70235 + 3eb24ff commit 9857682
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 115 deletions.
24 changes: 4 additions & 20 deletions library/Zend/Crypt/Password/Bcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ class Bcrypt implements PasswordInterface
*/
protected $salt;

/**
* @var bool
*/
protected $backwardCompatibility = false;

/**
* Constructor
*
Expand Down Expand Up @@ -87,19 +82,7 @@ public function create($password)
* Check for security flaw in the bcrypt implementation used by crypt()
* @see http://php.net/security/crypt_blowfish.php
*/
if ((PHP_VERSION_ID >= 50307) && !$this->backwardCompatibility) {
$prefix = '$2y$';
} else {
$prefix = '$2a$';
// check if the password contains 8-bit character
if (preg_match('/[\x80-\xFF]/', $password)) {
throw new Exception\RuntimeException(
'The bcrypt implementation used by PHP can contain a security flaw ' .
'using password with 8-bit character. ' .
'We suggest to upgrade to PHP 5.3.7+ or use passwords with only 7-bit characters'
);
}
}
$prefix = '$2y$';
$hash = crypt($password, $prefix . $this->cost . '$' . $salt64);
if (strlen($hash) < 13) {
throw new Exception\RuntimeException('Error during the bcrypt generation');
Expand Down Expand Up @@ -186,22 +169,23 @@ public function getSalt()
/**
* Set the backward compatibility $2a$ instead of $2y$ for PHP 5.3.7+
*
* @deprecated since zf 2.3 requires PHP >= 5.3.23
* @param bool $value
* @return Bcrypt
*/
public function setBackwardCompatibility($value)
{
$this->backwardCompatibility = (bool) $value;
return $this;
}

/**
* Get the backward compatibility
*
* @deprecated since zf 2.3 requires PHP >= 5.3.23
* @return bool
*/
public function getBackwardCompatibility()
{
return $this->backwardCompatibility;
return false;
}
}
21 changes: 6 additions & 15 deletions library/Zend/Di/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ protected function handleInjectDependencies($instance, $injectionMethods, $param
if ($methodParams) {
foreach ($methodParams as $methodParam) {
$objectToInjectClass = $this->getClass($objectToInject);
if ($objectToInjectClass == $methodParam[1] || self::isSubclassOf($objectToInjectClass, $methodParam[1])) {
if ($objectToInjectClass == $methodParam[1] || is_subclass_of($objectToInjectClass, $methodParam[1])) {
if ($this->resolveAndCallInjectionMethodForInstance($instance, $typeInjectionMethod, array($methodParam[0] => $objectToInject), $instanceAlias, self::METHOD_IS_REQUIRED, $type)) {
$calledMethods[$typeInjectionMethod] = true;
}
Expand Down Expand Up @@ -743,7 +743,7 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
}
$pInstanceClass = ($this->instanceManager->hasAlias($pInstance)) ?
$this->instanceManager->getClassFromAlias($pInstance) : $pInstance;
if ($pInstanceClass === $type || self::isSubclassOf($pInstanceClass, $type)) {
if ($pInstanceClass === $type || is_subclass_of($pInstanceClass, $type)) {
$computedParams['retrieval'][$fqParamPos] = array($pInstance, $pInstanceClass);
continue 2;
}
Expand All @@ -760,7 +760,7 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
}
$pInstanceClass = ($this->instanceManager->hasAlias($pInstance)) ?
$this->instanceManager->getClassFromAlias($pInstance) : $pInstance;
if ($pInstanceClass === $type || self::isSubclassOf($pInstanceClass, $type)) {
if ($pInstanceClass === $type || is_subclass_of($pInstanceClass, $type)) {
$computedParams['retrieval'][$fqParamPos] = array($pInstance, $pInstanceClass);
continue 2;
}
Expand Down Expand Up @@ -887,23 +887,14 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
* @see https://bugs.php.net/bug.php?id=53727
* @see https://github.com/zendframework/zf2/pull/1807
*
* @deprecated since zf 2.3 requires PHP >= 5.3.23
*
* @param string $className
* @param $type
* @return bool
*/
protected static function isSubclassOf($className, $type)
{
if (is_subclass_of($className, $type)) {
return true;
}
if (PHP_VERSION_ID >= 50307) {
return false;
}
if (!interface_exists($type)) {
return false;
}
$r = new ReflectionClass($className);

return $r->implementsInterface($type);
return is_subclass_of($className, $type);
}
}
17 changes: 4 additions & 13 deletions library/Zend/Form/Annotation/AnnotationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Zend\Form\Annotation;

use ArrayObject;
use ReflectionClass;
use Zend\Code\Annotation\AnnotationCollection;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Annotation\Parser;
Expand Down Expand Up @@ -335,7 +334,7 @@ protected function configureElement($annotations, $reflection, $formSpec, $filte
: 'Zend\Form\Element';

// Compose as a fieldset or an element, based on specification type
if (static::isSubclassOf($type, 'Zend\Form\FieldsetInterface')) {
if (is_subclass_of($type, 'Zend\Form\FieldsetInterface')) {
if (!isset($formSpec['fieldsets'])) {
$formSpec['fieldsets'] = array();
}
Expand Down Expand Up @@ -388,22 +387,14 @@ protected function checkForExclude($annotations)
* @see https://bugs.php.net/bug.php?id=53727
* @see https://github.com/zendframework/zf2/pull/1807
*
* @deprecated since zf 2.3 requires PHP >= 5.3.23
*
* @param string $className
* @param string $type
* @return bool
*/
protected static function isSubclassOf($className, $type)
{
if (is_subclass_of($className, $type)) {
return true;
}
if (PHP_VERSION_ID >= 50307) {
return false;
}
if (!interface_exists($type)) {
return false;
}
$r = new ReflectionClass($className);
return $r->implementsInterface($type);
return is_subclass_of($className, $type);
}
}
17 changes: 4 additions & 13 deletions library/Zend/Loader/AutoloaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Loader;

use ReflectionClass;
use Traversable;

if (class_exists('Zend\Loader\AutoloaderFactory')) {
Expand Down Expand Up @@ -87,7 +86,7 @@ public static function factory($options = null)
);
}

if (!static::isSubclassOf($class, 'Zend\Loader\SplAutoloader')) {
if (!is_subclass_of($class, 'Zend\Loader\SplAutoloader')) {
require_once 'Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(
sprintf('Autoloader class %s must implement Zend\\Loader\\SplAutoloader', $class)
Expand Down Expand Up @@ -199,22 +198,14 @@ protected static function getStandardAutoloader()
* @see https://bugs.php.net/bug.php?id=53727
* @see https://github.com/zendframework/zf2/pull/1807
*
* @deprecated since zf 2.3 requires PHP >= 5.3.23
*
* @param string $className
* @param string $type
* @return bool
*/
protected static function isSubclassOf($className, $type)
{
if (is_subclass_of($className, $type)) {
return true;
}
if (PHP_VERSION_ID >= 50307) {
return false;
}
if (!interface_exists($type)) {
return false;
}
$r = new ReflectionClass($className);
return $r->implementsInterface($type);
return is_subclass_of($className, $type);
}
}
6 changes: 1 addition & 5 deletions library/Zend/Log/Processor/Backtrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ protected function getBacktrace()
return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $this->traceLimit);
}

if (PHP_VERSION_ID >= 50306) {
return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}

return debug_backtrace();
return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
}
10 changes: 2 additions & 8 deletions library/Zend/Math/Rand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,13 @@ public static function getBytes($length, $strong = false)
return false;
}

if (function_exists('openssl_random_pseudo_bytes')
&& ((PHP_VERSION_ID >= 50304)
|| strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
) {
if (function_exists('openssl_random_pseudo_bytes')) {
$bytes = openssl_random_pseudo_bytes($length, $usable);
if (true === $usable) {
return $bytes;
}
}
if (function_exists('mcrypt_create_iv')
&& ((PHP_VERSION_ID >= 50307)
|| strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
) {
if (function_exists('mcrypt_create_iv')) {
$bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
if ($bytes !== false && strlen($bytes) === $length) {
return $bytes;
Expand Down
16 changes: 3 additions & 13 deletions library/Zend/ServiceManager/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Zend\ServiceManager;

use ReflectionClass;

class ServiceManager implements ServiceLocatorInterface
{
/**@#+
Expand Down Expand Up @@ -1189,6 +1187,8 @@ protected function createDelegatorFromFactory($canonicalName, $requestedName)
* @see https://bugs.php.net/bug.php?id=53727
* @see https://github.com/zendframework/zf2/pull/1807
*
* @deprecated since zf 2.3 requires PHP >= 5.3.23
*
* @param string $className
* @param string $type
* @return bool
Expand All @@ -1197,17 +1197,7 @@ protected function createDelegatorFromFactory($canonicalName, $requestedName)
*/
protected static function isSubclassOf($className, $type)
{
if (is_subclass_of($className, $type)) {
return true;
}
if (PHP_VERSION_ID >= 50307) {
return false;
}
if (!interface_exists($type)) {
return false;
}
$r = new ReflectionClass($className);
return $r->implementsInterface($type);
return is_subclass_of($className, $type);
}

/**
Expand Down
16 changes: 4 additions & 12 deletions library/Zend/XmlRpc/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public function getResponse()
*/
public function setResponseClass($class)
{
if (!class_exists($class) || !static::isSubclassOf($class, 'Zend\XmlRpc\Response')) {
if (!class_exists($class) || !is_subclass_of($class, 'Zend\XmlRpc\Response')) {
throw new Server\Exception\InvalidArgumentException('Invalid response class');
}
$this->responseClass = $class;
Expand Down Expand Up @@ -588,22 +588,14 @@ protected function registerSystemMethods()
* @see https://bugs.php.net/bug.php?id=53727
* @see https://github.com/zendframework/zf2/pull/1807
*
* @deprecated since zf 2.3 requires PHP >= 5.3.23
*
* @param string $className
* @param string $type
* @return bool
*/
protected static function isSubclassOf($className, $type)
{
if (is_subclass_of($className, $type)) {
return true;
}
if (PHP_VERSION_ID >= 50307) {
return false;
}
if (!interface_exists($type)) {
return false;
}
$r = new ReflectionClass($className);
return $r->implementsInterface($type);
return is_subclass_of($className, $type);
}
}
3 changes: 3 additions & 0 deletions library/Zend/XmlRpc/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"zendframework/zend-stdlib": "self.version",
"zendframework/zendxml": "1.*"
},
"suggest": {
"zendframework/zend-cache": "To support Zend\\XmlRpc\\Server\\Cache usage"
},
"extra": {
"branch-alias": {
"dev-master": "2.3-dev",
Expand Down
16 changes: 0 additions & 16 deletions tests/ZendTest/Crypt/Password/BcryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,4 @@ public function testPasswordWith8bitCharacter()
$this->assertEquals('$2y$10$MTIzNDU2Nzg5MDEyMzQ1NemFdU/4JOrNpxMym09Mbp0m4hKTgfQo.',
$this->bcrypt->create($password));
}

public function testSetBackwardCompatibility()
{
$result = $this->bcrypt->setBackwardCompatibility(true);
$this->assertTrue($result instanceof Bcrypt);
$this->assertTrue($this->bcrypt->getBackwardCompatibility());
}

public function testBackwardCompatibility()
{
$this->bcrypt->setSalt($this->salt);
$this->bcrypt->setBackwardCompatibility(true);
$password = $this->bcrypt->create($this->password);
$this->assertEquals('$2a$', substr($password, 0, 4));
$this->assertEquals(substr($password, 4), substr($this->bcryptPassword, 4));
}
}

0 comments on commit 9857682

Please sign in to comment.