diff --git a/library/TorrentPier/ReCaptcha/ReCaptcha.php b/library/TorrentPier/ReCaptcha/ReCaptcha.php old mode 100755 new mode 100644 index b97a2ae25..523c4aae4 --- a/library/TorrentPier/ReCaptcha/ReCaptcha.php +++ b/library/TorrentPier/ReCaptcha/ReCaptcha.php @@ -94,4 +94,4 @@ class ReCaptcha $rawResponse = $this->requestMethod->submit($params); return Response::fromJson($rawResponse); } -} \ No newline at end of file +} diff --git a/library/TorrentPier/ReCaptcha/RequestMethod.php b/library/TorrentPier/ReCaptcha/RequestMethod.php old mode 100755 new mode 100644 index 58015cb62..fc4dde59c --- a/library/TorrentPier/ReCaptcha/RequestMethod.php +++ b/library/TorrentPier/ReCaptcha/RequestMethod.php @@ -39,4 +39,4 @@ interface RequestMethod * @return string Body of the reCAPTCHA response */ public function submit(RequestParameters $params); -} \ No newline at end of file +} diff --git a/library/TorrentPier/ReCaptcha/RequestMethod/Post.php b/library/TorrentPier/ReCaptcha/RequestMethod/Post.php old mode 100755 new mode 100644 index 4147641be..7770d9081 --- a/library/TorrentPier/ReCaptcha/RequestMethod/Post.php +++ b/library/TorrentPier/ReCaptcha/RequestMethod/Post.php @@ -67,4 +67,4 @@ class Post implements RequestMethod $context = stream_context_create($options); return file_get_contents(self::SITE_VERIFY_URL, false, $context); } -} \ No newline at end of file +} diff --git a/library/TorrentPier/ReCaptcha/RequestMethod/Socket.php b/library/TorrentPier/ReCaptcha/RequestMethod/Socket.php old mode 100755 new mode 100644 index dd2091c06..e74fc49d6 --- a/library/TorrentPier/ReCaptcha/RequestMethod/Socket.php +++ b/library/TorrentPier/ReCaptcha/RequestMethod/Socket.php @@ -101,4 +101,4 @@ class Socket { return fclose($this->handle); } -} \ No newline at end of file +} diff --git a/library/TorrentPier/ReCaptcha/RequestMethod/SocketPost.php b/library/TorrentPier/ReCaptcha/RequestMethod/SocketPost.php old mode 100755 new mode 100644 index a09430ac5..4f0c61a3f --- a/library/TorrentPier/ReCaptcha/RequestMethod/SocketPost.php +++ b/library/TorrentPier/ReCaptcha/RequestMethod/SocketPost.php @@ -117,4 +117,4 @@ class SocketPost implements RequestMethod return self::BAD_REQUEST; } -} \ No newline at end of file +} diff --git a/library/TorrentPier/ReCaptcha/RequestParameters.php b/library/TorrentPier/ReCaptcha/RequestParameters.php old mode 100755 new mode 100644 index d3d46f461..cb66f26cf --- a/library/TorrentPier/ReCaptcha/RequestParameters.php +++ b/library/TorrentPier/ReCaptcha/RequestParameters.php @@ -100,4 +100,4 @@ class RequestParameters { return http_build_query($this->toArray(), '', '&'); } -} \ No newline at end of file +} diff --git a/library/TorrentPier/ReCaptcha/Response.php b/library/TorrentPier/ReCaptcha/Response.php old mode 100755 new mode 100644 index c1c77aa4d..d2d8a8bf7 --- a/library/TorrentPier/ReCaptcha/Response.php +++ b/library/TorrentPier/ReCaptcha/Response.php @@ -99,4 +99,4 @@ class Response { return $this->errorCodes; } -} \ No newline at end of file +} diff --git a/library/TorrentPier/Zend/Authentication/Adapter/DbTable/AbstractAdapter.php b/library/TorrentPier/Zend/Authentication/Adapter/DbTable/AbstractAdapter.php index 21c68eb3c..f99cd9672 100644 --- a/library/TorrentPier/Zend/Authentication/Adapter/DbTable/AbstractAdapter.php +++ b/library/TorrentPier/Zend/Authentication/Adapter/DbTable/AbstractAdapter.php @@ -173,7 +173,7 @@ abstract class AbstractAdapter extends BaseAdapter */ public function getDbSelect() { - if ($this->dbSelect == null) { + if ($this->dbSelect === null) { $this->dbSelect = new Sql\Select(); } return $this->dbSelect; diff --git a/library/TorrentPier/Zend/Authentication/composer.json b/library/TorrentPier/Zend/Authentication/composer.json index 78c98ec12..d1fa89140 100644 --- a/library/TorrentPier/Zend/Authentication/composer.json +++ b/library/TorrentPier/Zend/Authentication/composer.json @@ -36,8 +36,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Barcode/Renderer/Image.php b/library/TorrentPier/Zend/Barcode/Renderer/Image.php index 2bcd35ae3..0dca09cc9 100644 --- a/library/TorrentPier/Zend/Barcode/Renderer/Image.php +++ b/library/TorrentPier/Zend/Barcode/Renderer/Image.php @@ -375,7 +375,7 @@ class Image extends AbstractRenderer $color & 0x0000FF ); - if ($font == null) { + if ($font === null) { $font = 3; } $position[0] += $this->leftOffset; diff --git a/library/TorrentPier/Zend/Barcode/composer.json b/library/TorrentPier/Zend/Barcode/composer.json index 1014ad0f7..72cefc47f 100644 --- a/library/TorrentPier/Zend/Barcode/composer.json +++ b/library/TorrentPier/Zend/Barcode/composer.json @@ -27,8 +27,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Cache/Storage/Adapter/MongoDbOptions.php b/library/TorrentPier/Zend/Cache/Storage/Adapter/MongoDbOptions.php index 4b87abc32..b0e1e8be4 100644 --- a/library/TorrentPier/Zend/Cache/Storage/Adapter/MongoDbOptions.php +++ b/library/TorrentPier/Zend/Cache/Storage/Adapter/MongoDbOptions.php @@ -19,9 +19,9 @@ class MongoDbOptions extends AdapterOptions private $namespaceSeparator = ':'; /** - * The redis resource manager + * The mongo DB resource manager * - * @var null|RedisResourceManager + * @var null|MongoDbResourceManager */ private $resourceManager; @@ -101,7 +101,7 @@ class MongoDbOptions extends AdapterOptions } /** - * Set the redis resource id + * Set the mongodb resource id * * @param string $resourceId * diff --git a/library/TorrentPier/Zend/Cache/composer.json b/library/TorrentPier/Zend/Cache/composer.json index c2bfad4ff..fef8d4ec8 100644 --- a/library/TorrentPier/Zend/Cache/composer.json +++ b/library/TorrentPier/Zend/Cache/composer.json @@ -34,8 +34,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Captcha/composer.json b/library/TorrentPier/Zend/Captcha/composer.json index 52842a878..aad0a586f 100644 --- a/library/TorrentPier/Zend/Captcha/composer.json +++ b/library/TorrentPier/Zend/Captcha/composer.json @@ -32,8 +32,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Code/Generator/ClassGenerator.php b/library/TorrentPier/Zend/Code/Generator/ClassGenerator.php index bf9a1f34d..749edfe02 100644 --- a/library/TorrentPier/Zend/Code/Generator/ClassGenerator.php +++ b/library/TorrentPier/Zend/Code/Generator/ClassGenerator.php @@ -943,6 +943,8 @@ class ClassGenerator extends AbstractGenerator if ($this->isAbstract()) { $output .= 'abstract '; + } elseif ($this->isFinal()) { + $output .= 'final '; } $output .= static::OBJECT_TYPE . ' ' . $this->getName(); diff --git a/library/TorrentPier/Zend/Code/Generator/FileGenerator.php b/library/TorrentPier/Zend/Code/Generator/FileGenerator.php index 3b531d646..5fb91a1b8 100644 --- a/library/TorrentPier/Zend/Code/Generator/FileGenerator.php +++ b/library/TorrentPier/Zend/Code/Generator/FileGenerator.php @@ -302,7 +302,7 @@ class FileGenerator extends AbstractGenerator */ public function getClass($name = null) { - if ($name == null) { + if ($name === null) { reset($this->classes); return current($this->classes); diff --git a/library/TorrentPier/Zend/Code/Generator/FileGeneratorRegistry.php b/library/TorrentPier/Zend/Code/Generator/FileGeneratorRegistry.php index 953cb6bf5..dfacb6b38 100644 --- a/library/TorrentPier/Zend/Code/Generator/FileGeneratorRegistry.php +++ b/library/TorrentPier/Zend/Code/Generator/FileGeneratorRegistry.php @@ -27,7 +27,7 @@ class FileGeneratorRegistry */ public static function registerFileCodeGenerator(FileGenerator $fileCodeGenerator, $fileName = null) { - if ($fileName == null) { + if ($fileName === null) { $fileName = $fileCodeGenerator->getFilename(); } diff --git a/library/TorrentPier/Zend/Code/Generator/PropertyGenerator.php b/library/TorrentPier/Zend/Code/Generator/PropertyGenerator.php index a5bd0bd74..159e415c6 100644 --- a/library/TorrentPier/Zend/Code/Generator/PropertyGenerator.php +++ b/library/TorrentPier/Zend/Code/Generator/PropertyGenerator.php @@ -204,7 +204,7 @@ class PropertyGenerator extends AbstractMemberGenerator } if ($this->isConst()) { - if ($defaultValue != null && !$defaultValue->isValidConstantType()) { + if ($defaultValue !== null && !$defaultValue->isValidConstantType()) { throw new Exception\RuntimeException(sprintf( 'The property %s is said to be ' . 'constant but does not have a valid constant value.', diff --git a/library/TorrentPier/Zend/Code/NameInformation.php b/library/TorrentPier/Zend/Code/NameInformation.php index 5a7166c12..59bb6b0d4 100644 --- a/library/TorrentPier/Zend/Code/NameInformation.php +++ b/library/TorrentPier/Zend/Code/NameInformation.php @@ -58,7 +58,7 @@ class NameInformation */ public function hasNamespace() { - return ($this->namespace != null); + return ($this->namespace !== null); } /** diff --git a/library/TorrentPier/Zend/Code/Reflection/ClassReflection.php b/library/TorrentPier/Zend/Code/Reflection/ClassReflection.php index 13801c2fb..25bcaf058 100644 --- a/library/TorrentPier/Zend/Code/Reflection/ClassReflection.php +++ b/library/TorrentPier/Zend/Code/Reflection/ClassReflection.php @@ -177,11 +177,16 @@ class ClassReflection extends ReflectionClass implements ReflectionInterface return $methods; } + /** + * Returns an array of reflection classes of traits used by this class. + * + * @return array|null + */ public function getTraits() { $vals = array(); $traits = parent::getTraits(); - if (! $traits) { + if ($traits === null) { return; } diff --git a/library/TorrentPier/Zend/Code/Reflection/ParameterReflection.php b/library/TorrentPier/Zend/Code/Reflection/ParameterReflection.php index 17153f504..ba095255a 100644 --- a/library/TorrentPier/Zend/Code/Reflection/ParameterReflection.php +++ b/library/TorrentPier/Zend/Code/Reflection/ParameterReflection.php @@ -40,7 +40,7 @@ class ParameterReflection extends ReflectionParameter implements ReflectionInter public function getClass() { $phpReflection = parent::getClass(); - if ($phpReflection == null) { + if ($phpReflection === null) { return; } diff --git a/library/TorrentPier/Zend/Code/Scanner/ClassScanner.php b/library/TorrentPier/Zend/Code/Scanner/ClassScanner.php index 86b7438b2..d7507a200 100644 --- a/library/TorrentPier/Zend/Code/Scanner/ClassScanner.php +++ b/library/TorrentPier/Zend/Code/Scanner/ClassScanner.php @@ -269,7 +269,7 @@ class ClassScanner implements ScannerInterface public function hasParentClass() { $this->scan(); - return ($this->parentClass != null); + return ($this->parentClass !== null); } /** diff --git a/library/TorrentPier/Zend/Code/Scanner/DerivedClassScanner.php b/library/TorrentPier/Zend/Code/Scanner/DerivedClassScanner.php index a7c7f37fd..4790c7389 100644 --- a/library/TorrentPier/Zend/Code/Scanner/DerivedClassScanner.php +++ b/library/TorrentPier/Zend/Code/Scanner/DerivedClassScanner.php @@ -123,7 +123,7 @@ class DerivedClassScanner extends ClassScanner */ public function hasParentClass() { - return ($this->classScanner->getParentClass() != null); + return ($this->classScanner->getParentClass() !== null); } /** diff --git a/library/TorrentPier/Zend/Code/Scanner/TokenArrayScanner.php b/library/TorrentPier/Zend/Code/Scanner/TokenArrayScanner.php index 4abc60376..26c9d1407 100644 --- a/library/TorrentPier/Zend/Code/Scanner/TokenArrayScanner.php +++ b/library/TorrentPier/Zend/Code/Scanner/TokenArrayScanner.php @@ -587,7 +587,7 @@ class TokenArrayScanner implements ScannerInterface || ($tokenType === T_FUNCTION && $infos[$infoIndex]['type'] === 'function')) ) { $infos[$infoIndex]['shortName'] = $tokens[$tokenIndex + 2][1]; - $infos[$infoIndex]['name'] = (($namespace != null) ? $namespace . '\\' : '') . $infos[$infoIndex]['shortName']; + $infos[$infoIndex]['name'] = (($namespace !== null) ? $namespace . '\\' : '') . $infos[$infoIndex]['shortName']; } if ($tokenType === null) { diff --git a/library/TorrentPier/Zend/Code/composer.json b/library/TorrentPier/Zend/Code/composer.json index 3d72c672d..8375dc741 100644 --- a/library/TorrentPier/Zend/Code/composer.json +++ b/library/TorrentPier/Zend/Code/composer.json @@ -26,8 +26,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Config/composer.json b/library/TorrentPier/Zend/Config/composer.json index 8123db628..a23525825 100644 --- a/library/TorrentPier/Zend/Config/composer.json +++ b/library/TorrentPier/Zend/Config/composer.json @@ -30,8 +30,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Console/Response.php b/library/TorrentPier/Zend/Console/Response.php index b6784257d..a96974d7d 100644 --- a/library/TorrentPier/Zend/Console/Response.php +++ b/library/TorrentPier/Zend/Console/Response.php @@ -38,6 +38,10 @@ class Response extends Message implements ResponseInterface */ public function setErrorLevel($errorLevel) { + if (is_string($errorLevel) && !ctype_digit($errorLevel)) { + return $this; + } + $this->setMetadata('errorLevel', $errorLevel); return $this; } diff --git a/library/TorrentPier/Zend/Console/composer.json b/library/TorrentPier/Zend/Console/composer.json index 41af21119..59cf8c38c 100644 --- a/library/TorrentPier/Zend/Console/composer.json +++ b/library/TorrentPier/Zend/Console/composer.json @@ -22,8 +22,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Crypt/composer.json b/library/TorrentPier/Zend/Crypt/composer.json index 89ed21b8a..aba2930bf 100644 --- a/library/TorrentPier/Zend/Crypt/composer.json +++ b/library/TorrentPier/Zend/Crypt/composer.json @@ -23,8 +23,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Db/Adapter/Adapter.php b/library/TorrentPier/Zend/Db/Adapter/Adapter.php index 1ad6fb1fd..3771b94c8 100644 --- a/library/TorrentPier/Zend/Db/Adapter/Adapter.php +++ b/library/TorrentPier/Zend/Db/Adapter/Adapter.php @@ -87,7 +87,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface $driver->checkEnvironment(); $this->driver = $driver; - if ($platform == null) { + if ($platform === null) { $platform = $this->createPlatform($parameters); } @@ -128,7 +128,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface */ public function getDriver() { - if ($this->driver == null) { + if ($this->driver === null) { throw new Exception\RuntimeException('Driver has not been set or configured for this adapter.'); } return $this->driver; @@ -209,7 +209,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface public function createStatement($initialSql = null, $initialParameters = null) { $statement = $this->driver->createStatement($initialSql); - if ($initialParameters == null || !$initialParameters instanceof ParameterContainer && is_array($initialParameters)) { + if ($initialParameters === null || !$initialParameters instanceof ParameterContainer && is_array($initialParameters)) { $initialParameters = new ParameterContainer((is_array($initialParameters) ? $initialParameters : array())); } $statement->setParameterContainer($initialParameters); diff --git a/library/TorrentPier/Zend/Db/Adapter/Driver/IbmDb2/Statement.php b/library/TorrentPier/Zend/Db/Adapter/Driver/IbmDb2/Statement.php index dc7e3df4c..97d258848 100644 --- a/library/TorrentPier/Zend/Db/Adapter/Driver/IbmDb2/Statement.php +++ b/library/TorrentPier/Zend/Db/Adapter/Driver/IbmDb2/Statement.php @@ -167,7 +167,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface throw new Exception\RuntimeException('This statement has been prepared already'); } - if ($sql == null) { + if ($sql === null) { $sql = $this->sql; } diff --git a/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Pdo.php b/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Pdo.php index 6c8c0073e..c70afa8da 100644 --- a/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Pdo.php +++ b/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Pdo.php @@ -297,7 +297,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA */ public function formatParameterName($name, $type = null) { - if ($type == null && !is_numeric($name) || $type == self::PARAMETERIZATION_NAMED) { + if ($type === null && !is_numeric($name) || $type == self::PARAMETERIZATION_NAMED) { return ':' . $name; } diff --git a/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Statement.php b/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Statement.php index 730ee8540..0180859db 100644 --- a/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Statement.php +++ b/library/TorrentPier/Zend/Db/Adapter/Driver/Pdo/Statement.php @@ -179,7 +179,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface throw new Exception\RuntimeException('This statement has been prepared already'); } - if ($sql == null) { + if ($sql === null) { $sql = $this->sql; } diff --git a/library/TorrentPier/Zend/Db/Adapter/Driver/Pgsql/Connection.php b/library/TorrentPier/Zend/Db/Adapter/Driver/Pgsql/Connection.php index 762a50041..ea2025a7c 100644 --- a/library/TorrentPier/Zend/Db/Adapter/Driver/Pgsql/Connection.php +++ b/library/TorrentPier/Zend/Db/Adapter/Driver/Pgsql/Connection.php @@ -19,6 +19,11 @@ class Connection extends AbstractConnection */ protected $driver = null; + /** + * @var null|int PostgreSQL connection type + */ + protected $type = null; + /** * Constructor * @@ -46,6 +51,26 @@ class Connection extends AbstractConnection return $this; } + /** + * @param int|null $type + * @return self + */ + public function setType($type) + { + $invalidConectionType = ($type !== PGSQL_CONNECT_FORCE_NEW); + + // Compatibility with PHP < 5.6 + if ($invalidConectionType && defined('PGSQL_CONNECT_ASYNC')) { + $invalidConectionType = ($type !== PGSQL_CONNECT_ASYNC); + } + + if ($invalidConectionType) { + throw new Exception\InvalidArgumentException('Connection type is not valid. (See: http://php.net/manual/en/function.pg-connect.php)'); + } + $this->type = $type; + return $this; + } + /** * {@inheritDoc} * @@ -109,6 +134,7 @@ class Connection extends AbstractConnection public function disconnect() { pg_close($this->resource); + return $this; } /** @@ -207,7 +233,7 @@ class Connection extends AbstractConnection */ public function getLastGeneratedValue($name = null) { - if ($name == null) { + if ($name === null) { return; } $result = pg_query($this->resource, 'SELECT CURRVAL(\'' . str_replace('\'', '\\\'', $name) . '\') as "currval"'); diff --git a/library/TorrentPier/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php b/library/TorrentPier/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php index dc917d4d9..652874a21 100644 --- a/library/TorrentPier/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php +++ b/library/TorrentPier/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php @@ -165,7 +165,7 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface $statement->initialize($this->connection->getResource()); if (is_string($sqlOrResource)) { $statement->setSql($sqlOrResource); - } elseif ($sqlOrResource != null) { + } elseif ($sqlOrResource !== null) { throw new Exception\InvalidArgumentException('createStatement() only accepts an SQL string or a Sqlsrv resource'); } } diff --git a/library/TorrentPier/Zend/Db/Adapter/Platform/AbstractPlatform.php b/library/TorrentPier/Zend/Db/Adapter/Platform/AbstractPlatform.php old mode 100644 new mode 100755 diff --git a/library/TorrentPier/Zend/Db/ResultSet/AbstractResultSet.php b/library/TorrentPier/Zend/Db/ResultSet/AbstractResultSet.php index 7352e3b07..f1f904d95 100644 --- a/library/TorrentPier/Zend/Db/ResultSet/AbstractResultSet.php +++ b/library/TorrentPier/Zend/Db/ResultSet/AbstractResultSet.php @@ -90,7 +90,7 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface throw new Exception\InvalidArgumentException('DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate'); } - if ($this->count == null && $this->dataSource instanceof Countable) { + if ($this->count === null && $this->dataSource instanceof Countable) { $this->count = $this->dataSource->count(); } diff --git a/library/TorrentPier/Zend/Db/RowGateway/AbstractRowGateway.php b/library/TorrentPier/Zend/Db/RowGateway/AbstractRowGateway.php index ed3f60aea..662fb226b 100644 --- a/library/TorrentPier/Zend/Db/RowGateway/AbstractRowGateway.php +++ b/library/TorrentPier/Zend/Db/RowGateway/AbstractRowGateway.php @@ -71,7 +71,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI throw new Exception\RuntimeException('This row object does not have a valid table set.'); } - if ($this->primaryKeyColumn == null) { + if ($this->primaryKeyColumn === null) { throw new Exception\RuntimeException('This row object does not have a primary key column set.'); } elseif (is_string($this->primaryKeyColumn)) { $this->primaryKeyColumn = (array) $this->primaryKeyColumn; diff --git a/library/TorrentPier/Zend/Db/Sql/AbstractSql.php b/library/TorrentPier/Zend/Db/Sql/AbstractSql.php index 1830f9037..f99b3b9ca 100644 --- a/library/TorrentPier/Zend/Db/Sql/AbstractSql.php +++ b/library/TorrentPier/Zend/Db/Sql/AbstractSql.php @@ -47,18 +47,26 @@ abstract class AbstractSql implements SqlInterface * @param PlatformInterface $platform * @param null|DriverInterface $driver * @param null|ParameterContainer $parameterContainer - * * @return string */ - protected function buildSqlString(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { + protected function buildSqlString( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { $this->localizeVariables(); $sqls = array(); $parameters = array(); foreach ($this->specifications as $name => $specification) { - $parameters[$name] = $this->{'process' . $name}($platform, $driver, $parameterContainer, $sqls, $parameters); + $parameters[$name] = $this->{'process' . $name}( + $platform, + $driver, + $parameterContainer, + $sqls, + $parameters + ); if ($specification && is_array($parameters[$name])) { $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); @@ -74,26 +82,32 @@ abstract class AbstractSql implements SqlInterface } /** - * * @staticvar int $runtimeExpressionPrefix * @param ExpressionInterface $expression * @param PlatformInterface $platform * @param null|DriverInterface $driver * @param null|ParameterContainer $parameterContainer * @param null|string $namedParameterPrefix - * * @return string - * * @throws Exception\RuntimeException */ - protected function processExpression(ExpressionInterface $expression, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, $namedParameterPrefix = null) - { - $namedParameterPrefix = !$namedParameterPrefix ? $namedParameterPrefix : $this->processInfo['paramPrefix'] . $namedParameterPrefix; + protected function processExpression( + ExpressionInterface $expression, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null, + $namedParameterPrefix = null + ) { + $namedParameterPrefix = ! $namedParameterPrefix + ? $namedParameterPrefix + : $this->processInfo['paramPrefix'] . $namedParameterPrefix; // static counter for the number of times this method was invoked across the PHP runtime static $runtimeExpressionPrefix = 0; if ($parameterContainer && ((!is_string($namedParameterPrefix) || $namedParameterPrefix == ''))) { $namedParameterPrefix = sprintf('expr%04dParam', ++$runtimeExpressionPrefix); + } else { + $namedParameterPrefix = preg_replace('/\s/', '__', $namedParameterPrefix); } $sql = ''; @@ -108,10 +122,17 @@ abstract class AbstractSql implements SqlInterface $expressionParamIndex = &$this->instanceParameterIndex[$namedParameterPrefix]; foreach ($parts as $part) { - // if it is a string, simply tack it onto the return sql "specification" string + // #7407: use $expression->getExpression() to get the unescaped + // version of the expression + if (is_string($part) && $expression instanceof Expression) { + $sql .= $expression->getExpression(); + continue; + } + + // If it is a string, simply tack it onto the return sql + // "specification" string if (is_string($part)) { $sql .= $part; - continue; } @@ -121,7 +142,8 @@ abstract class AbstractSql implements SqlInterface ); } - // process values and types (the middle and last position of the expression data) + // Process values and types (the middle and last position of the + // expression data) $values = $part[1]; $types = isset($part[2]) ? $part[2] : array(); foreach ($values as $vIndex => $value) { @@ -131,10 +153,18 @@ abstract class AbstractSql implements SqlInterface $type = $types[$vIndex]; if ($value instanceof Select) { // process sub-select - $values[$vIndex] = '(' . $this->processSubSelect($value, $platform, $driver, $parameterContainer) . ')'; + $values[$vIndex] = '(' + . $this->processSubSelect($value, $platform, $driver, $parameterContainer) + . ')'; } elseif ($value instanceof ExpressionInterface) { // recursive call to satisfy nested expressions - $values[$vIndex] = $this->processExpression($value, $platform, $driver, $parameterContainer, $namedParameterPrefix . $vIndex . 'subpart'); + $values[$vIndex] = $this->processExpression( + $value, + $platform, + $driver, + $parameterContainer, + $namedParameterPrefix . $vIndex . 'subpart' + ); } elseif ($type == ExpressionInterface::TYPE_IDENTIFIER) { $values[$vIndex] = $platform->quoteIdentifierInFragment($value); } elseif ($type == ExpressionInterface::TYPE_VALUE) { @@ -154,7 +184,8 @@ abstract class AbstractSql implements SqlInterface } } - // after looping the values, interpolate them into the sql string (they might be placeholder names, or values) + // After looping the values, interpolate them into the sql string + // (they might be placeholder names, or values) $sql .= vsprintf($part[0], $values); } @@ -198,7 +229,10 @@ abstract class AbstractSql implements SqlInterface foreach ($paramsForPosition as $multiParamsForPosition) { $ppCount = count($multiParamsForPosition); if (!isset($paramSpecs[$position][$ppCount])) { - throw new Exception\RuntimeException('A number of parameters (' . $ppCount . ') was found that is not supported by this specification'); + throw new Exception\RuntimeException(sprintf( + 'A number of parameters (%d) was found that is not supported by this specification', + $ppCount + )); } $multiParamValues[] = vsprintf($paramSpecs[$position][$ppCount], $multiParamsForPosition); } @@ -206,7 +240,10 @@ abstract class AbstractSql implements SqlInterface } elseif ($paramSpecs[$position] !== null) { $ppCount = count($paramsForPosition); if (!isset($paramSpecs[$position][$ppCount])) { - throw new Exception\RuntimeException('A number of parameters (' . $ppCount . ') was found that is not supported by this specification'); + throw new Exception\RuntimeException(sprintf( + 'A number of parameters (%d) was found that is not supported by this specification', + $ppCount + )); } $topParameters[] = vsprintf($paramSpecs[$position][$ppCount], $paramsForPosition); } else { @@ -223,8 +260,12 @@ abstract class AbstractSql implements SqlInterface * @param null|ParameterContainer $parameterContainer * @return string */ - protected function processSubSelect(Select $subselect, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { + protected function processSubSelect( + Select $subselect, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { if ($this instanceof PlatformDecoratorInterface) { $decorator = clone $this; $decorator->setSubject($subselect); @@ -237,7 +278,8 @@ abstract class AbstractSql implements SqlInterface $processInfoContext = ($decorator instanceof PlatformDecoratorInterface) ? $subselect : $decorator; $this->processInfo['subselectCount']++; $processInfoContext->processInfo['subselectCount'] = $this->processInfo['subselectCount']; - $processInfoContext->processInfo['paramPrefix'] = 'subselect' . $processInfoContext->processInfo['subselectCount']; + $processInfoContext->processInfo['paramPrefix'] = 'subselect' + . $processInfoContext->processInfo['subselectCount']; $sql = $decorator->buildSqlString($platform, $driver, $parameterContainer); @@ -257,9 +299,16 @@ abstract class AbstractSql implements SqlInterface * @param null|ParameterContainer $parameterContainer * @return string */ - protected function resolveColumnValue($column, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, $namedParameterPrefix = null) - { - $namedParameterPrefix = !$namedParameterPrefix ? $namedParameterPrefix : $this->processInfo['paramPrefix'] . $namedParameterPrefix; + protected function resolveColumnValue( + $column, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null, + $namedParameterPrefix = null + ) { + $namedParameterPrefix = ! $namedParameterPrefix + ? $namedParameterPrefix + : $this->processInfo['paramPrefix'] . $namedParameterPrefix; $isIdentifier = false; $fromTable = ''; if (is_array($column)) { @@ -293,8 +342,12 @@ abstract class AbstractSql implements SqlInterface * @param ParameterContainer $parameterContainer * @return string */ - protected function resolveTable($table, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { + protected function resolveTable( + $table, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { $schema = null; if ($table instanceof TableIdentifier) { list($table, $schema) = $table->getTableAndSchema(); diff --git a/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php b/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php index 34eadf4ec..c6390e341 100644 --- a/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php +++ b/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php @@ -135,7 +135,8 @@ class AlterTableDecorator extends AlterTable implements PlatformDecoratorInterfa if ($insert) { $j = isset($j) ? $j : 0; $sql = substr_replace($sql, $insert, $insertStart[$j], 0); - for (; $j < count($insertStart); ++$j) { + $insertStartCount = count($insertStart); + for (; $j < $insertStartCount; ++$j) { $insertStart[$j] += strlen($insert); } } @@ -199,7 +200,8 @@ class AlterTableDecorator extends AlterTable implements PlatformDecoratorInterfa if ($insert) { $j = isset($j) ? $j : 0; $sql = substr_replace($sql, $insert, $insertStart[$j], 0); - for (; $j < count($insertStart); ++$j) { + $insertStartCount = count($insertStart); + for (; $j < $insertStartCount; ++$j) { $insertStart[$j] += strlen($insert); } } diff --git a/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php b/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php index c24cdbad3..34ea4adf6 100644 --- a/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php +++ b/library/TorrentPier/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php @@ -139,7 +139,8 @@ class CreateTableDecorator extends CreateTable implements PlatformDecoratorInter if ($insert) { $j = isset($j) ? $j : 0; $sql = substr_replace($sql, $insert, $insertStart[$j], 0); - for (; $j < count($insertStart); ++$j) { + $insertStartCount = count($insertStart); + for (; $j < $insertStartCount; ++$j) { $insertStart[$j] += strlen($insert); } } diff --git a/library/TorrentPier/Zend/Db/Sql/Predicate/Predicate.php b/library/TorrentPier/Zend/Db/Sql/Predicate/Predicate.php index 825bf1ca3..c928100e0 100644 --- a/library/TorrentPier/Zend/Db/Sql/Predicate/Predicate.php +++ b/library/TorrentPier/Zend/Db/Sql/Predicate/Predicate.php @@ -57,7 +57,7 @@ class Predicate extends PredicateSet */ public function unnest() { - if ($this->unnest == null) { + if ($this->unnest === null) { throw new RuntimeException('Not nested'); } $unnest = $this->unnest; diff --git a/library/TorrentPier/Zend/Db/Sql/Sql.php b/library/TorrentPier/Zend/Db/Sql/Sql.php index be46488a1..4f5b15149 100644 --- a/library/TorrentPier/Zend/Db/Sql/Sql.php +++ b/library/TorrentPier/Zend/Db/Sql/Sql.php @@ -48,7 +48,7 @@ class Sql public function hasTable() { - return ($this->table != null); + return ($this->table !== null); } public function setTable($table) diff --git a/library/TorrentPier/Zend/Db/Sql/TableIdentifier.php b/library/TorrentPier/Zend/Db/Sql/TableIdentifier.php index c671d3e8e..315e52433 100644 --- a/library/TorrentPier/Zend/Db/Sql/TableIdentifier.php +++ b/library/TorrentPier/Zend/Db/Sql/TableIdentifier.php @@ -85,7 +85,7 @@ class TableIdentifier */ public function hasSchema() { - return ($this->schema != null); + return ($this->schema !== null); } /** diff --git a/library/TorrentPier/Zend/Db/Sql/Update.php b/library/TorrentPier/Zend/Db/Sql/Update.php index 8c27a1de0..75dd4ea8b 100644 --- a/library/TorrentPier/Zend/Db/Sql/Update.php +++ b/library/TorrentPier/Zend/Db/Sql/Update.php @@ -92,7 +92,7 @@ class Update extends AbstractPreparableSql */ public function set(array $values, $flag = self::VALUES_SET) { - if ($values == null) { + if ($values === null) { throw new Exception\InvalidArgumentException('set() expects an array of values'); } diff --git a/library/TorrentPier/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php b/library/TorrentPier/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php index b266265ee..4e5510155 100644 --- a/library/TorrentPier/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php +++ b/library/TorrentPier/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php @@ -62,7 +62,7 @@ class MasterSlaveFeature extends AbstractFeature public function postInitialize() { $this->masterSql = $this->tableGateway->sql; - if ($this->slaveSql == null) { + if ($this->slaveSql === null) { $this->slaveSql = new Sql( $this->slaveAdapter, $this->tableGateway->sql->getTable(), diff --git a/library/TorrentPier/Zend/Db/TableGateway/Feature/MetadataFeature.php b/library/TorrentPier/Zend/Db/TableGateway/Feature/MetadataFeature.php index 278895af3..a1cc39e5a 100644 --- a/library/TorrentPier/Zend/Db/TableGateway/Feature/MetadataFeature.php +++ b/library/TorrentPier/Zend/Db/TableGateway/Feature/MetadataFeature.php @@ -39,7 +39,7 @@ class MetadataFeature extends AbstractFeature public function postInitialize() { - if ($this->metadata == null) { + if ($this->metadata === null) { $this->metadata = new Metadata($this->tableGateway->adapter); } diff --git a/library/TorrentPier/Zend/Db/composer.json b/library/TorrentPier/Zend/Db/composer.json index 31596ab59..08be381f5 100644 --- a/library/TorrentPier/Zend/Db/composer.json +++ b/library/TorrentPier/Zend/Db/composer.json @@ -27,8 +27,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Debug/composer.json b/library/TorrentPier/Zend/Debug/composer.json index 9a419f454..1ec069889 100644 --- a/library/TorrentPier/Zend/Debug/composer.json +++ b/library/TorrentPier/Zend/Debug/composer.json @@ -24,8 +24,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Di/Definition/CompilerDefinition.php b/library/TorrentPier/Zend/Di/Definition/CompilerDefinition.php index 5cb27a9c2..1553cf3fe 100644 --- a/library/TorrentPier/Zend/Di/Definition/CompilerDefinition.php +++ b/library/TorrentPier/Zend/Di/Definition/CompilerDefinition.php @@ -100,7 +100,7 @@ class CompilerDefinition implements DefinitionInterface */ public function addCodeScannerFile(FileScanner $fileScanner) { - if ($this->directoryScanner == null) { + if ($this->directoryScanner === null) { $this->directoryScanner = new DirectoryScanner(); } @@ -185,7 +185,7 @@ class CompilerDefinition implements DefinitionInterface $def['supertypes'] = $supertypes; - if ($def['instantiator'] == null) { + if ($def['instantiator'] === null) { if ($rClass->isInstantiable()) { $def['instantiator'] = '__construct'; } diff --git a/library/TorrentPier/Zend/Di/Definition/RuntimeDefinition.php b/library/TorrentPier/Zend/Di/Definition/RuntimeDefinition.php index 45ab6bfd5..0b94e6a75 100644 --- a/library/TorrentPier/Zend/Di/Definition/RuntimeDefinition.php +++ b/library/TorrentPier/Zend/Di/Definition/RuntimeDefinition.php @@ -233,7 +233,7 @@ class RuntimeDefinition implements DefinitionInterface $def['supertypes'] = array_keys(array_flip($supertypes)); - if ($def['instantiator'] == null) { + if ($def['instantiator'] === null) { if ($rClass->isInstantiable()) { $def['instantiator'] = '__construct'; } diff --git a/library/TorrentPier/Zend/Di/Di.php b/library/TorrentPier/Zend/Di/Di.php index bee8ceeba..5293410c9 100644 --- a/library/TorrentPier/Zend/Di/Di.php +++ b/library/TorrentPier/Zend/Di/Di.php @@ -10,7 +10,6 @@ namespace Zend\Di; use Closure; -use ReflectionClass; use Zend\Di\Exception\RuntimeException as DiRuntimeException; use Zend\ServiceManager\Exception\ExceptionInterface as ServiceManagerException; diff --git a/library/TorrentPier/Zend/Di/composer.json b/library/TorrentPier/Zend/Di/composer.json index a6272b437..1312aa84f 100644 --- a/library/TorrentPier/Zend/Di/composer.json +++ b/library/TorrentPier/Zend/Di/composer.json @@ -25,8 +25,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Dom/composer.json b/library/TorrentPier/Zend/Dom/composer.json index acf8896f9..9d94841f9 100644 --- a/library/TorrentPier/Zend/Dom/composer.json +++ b/library/TorrentPier/Zend/Dom/composer.json @@ -17,8 +17,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Escaper/composer.json b/library/TorrentPier/Zend/Escaper/composer.json index 958f14a82..a81c8700e 100644 --- a/library/TorrentPier/Zend/Escaper/composer.json +++ b/library/TorrentPier/Zend/Escaper/composer.json @@ -17,8 +17,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/EventManager/composer.json b/library/TorrentPier/Zend/EventManager/composer.json index ce922411e..559df9936 100644 --- a/library/TorrentPier/Zend/EventManager/composer.json +++ b/library/TorrentPier/Zend/EventManager/composer.json @@ -18,8 +18,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Feed/Reader/Entry/Rss.php b/library/TorrentPier/Zend/Feed/Reader/Entry/Rss.php index 409190450..79678a537 100644 --- a/library/TorrentPier/Zend/Feed/Reader/Entry/Rss.php +++ b/library/TorrentPier/Zend/Feed/Reader/Entry/Rss.php @@ -204,7 +204,7 @@ class Rss extends AbstractEntry implements EntryInterface $date = date_create_from_format($standard, $dateModified); break; } catch (\Exception $e) { - if ($standard == null) { + if ($standard === null) { throw new Exception\RuntimeException( 'Could not load date due to unrecognised' .' format (should follow RFC 822 or 2822):' diff --git a/library/TorrentPier/Zend/Feed/Reader/Feed/Rss.php b/library/TorrentPier/Zend/Feed/Reader/Feed/Rss.php index cb9f038bc..9e045d7be 100644 --- a/library/TorrentPier/Zend/Feed/Reader/Feed/Rss.php +++ b/library/TorrentPier/Zend/Feed/Reader/Feed/Rss.php @@ -212,7 +212,7 @@ class Rss extends AbstractFeed $date = DateTime::createFromFormat($standard, $dateModified); break; } catch (\Exception $e) { - if ($standard == null) { + if ($standard === null) { throw new Exception\RuntimeException( 'Could not load date due to unrecognised' .' format (should follow RFC 822 or 2822):' @@ -272,7 +272,7 @@ class Rss extends AbstractFeed $date = DateTime::createFromFormat($standard, $lastBuildDateParsed); break; } catch (\Exception $e) { - if ($standard == null) { + if ($standard === null) { throw new Exception\RuntimeException( 'Could not load date due to unrecognised' .' format (should follow RFC 822 or 2822):' diff --git a/library/TorrentPier/Zend/Feed/composer.json b/library/TorrentPier/Zend/Feed/composer.json index 5541ae5d5..134ef322d 100644 --- a/library/TorrentPier/Zend/Feed/composer.json +++ b/library/TorrentPier/Zend/Feed/composer.json @@ -33,8 +33,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/File/Transfer/Adapter/AbstractAdapter.php b/library/TorrentPier/Zend/File/Transfer/Adapter/AbstractAdapter.php index 7606f3e2a..7be8c58d7 100644 --- a/library/TorrentPier/Zend/File/Transfer/Adapter/AbstractAdapter.php +++ b/library/TorrentPier/Zend/File/Transfer/Adapter/AbstractAdapter.php @@ -441,7 +441,7 @@ abstract class AbstractAdapter implements TranslatorAwareInterface */ public function getValidators($files = null) { - if ($files == null) { + if ($files === null) { return $this->validators; } diff --git a/library/TorrentPier/Zend/File/composer.json b/library/TorrentPier/Zend/File/composer.json index 63ba606f1..af48a8a21 100644 --- a/library/TorrentPier/Zend/File/composer.json +++ b/library/TorrentPier/Zend/File/composer.json @@ -28,8 +28,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Filter/Word/SeparatorToSeparator.php b/library/TorrentPier/Zend/Filter/Word/SeparatorToSeparator.php index 21713c680..5f0ffd135 100644 --- a/library/TorrentPier/Zend/Filter/Word/SeparatorToSeparator.php +++ b/library/TorrentPier/Zend/Filter/Word/SeparatorToSeparator.php @@ -87,7 +87,7 @@ class SeparatorToSeparator extends AbstractFilter return $value; } - if ($this->searchSeparator == null) { + if ($this->searchSeparator === null) { throw new Exception\RuntimeException('You must provide a search separator for this filter to work.'); } diff --git a/library/TorrentPier/Zend/Filter/Word/UnderscoreToStudlyCase.php b/library/TorrentPier/Zend/Filter/Word/UnderscoreToStudlyCase.php old mode 100644 new mode 100755 diff --git a/library/TorrentPier/Zend/Filter/composer.json b/library/TorrentPier/Zend/Filter/composer.json index 39e91b597..7d5c4a8b1 100644 --- a/library/TorrentPier/Zend/Filter/composer.json +++ b/library/TorrentPier/Zend/Filter/composer.json @@ -29,8 +29,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Form/Element/Collection.php b/library/TorrentPier/Zend/Form/Element/Collection.php index 112dc9faa..88cbd8c8e 100644 --- a/library/TorrentPier/Zend/Form/Element/Collection.php +++ b/library/TorrentPier/Zend/Form/Element/Collection.php @@ -209,7 +209,8 @@ class Collection extends Fieldset } // Check to see if elements have been replaced or removed - foreach ($this->iterator as $name => $elementOrFieldset) { + $toRemove = array(); + foreach ($this as $name => $elementOrFieldset) { if (isset($data[$name])) { continue; } @@ -221,6 +222,10 @@ class Collection extends Fieldset )); } + $toRemove[] = $name; + } + + foreach ($toRemove as $name) { $this->remove($name); } @@ -382,7 +387,8 @@ class Collection extends Fieldset } /** - * If set to true, a template prototype is automatically added to the form to ease the creation of dynamic elements through JavaScript + * If set to true, a template prototype is automatically added to the form + * to ease the creation of dynamic elements through JavaScript * * @param bool $shouldCreateTemplate * @return Collection @@ -485,7 +491,8 @@ class Collection extends Fieldset parent::prepareElement($form); - // The template element has been prepared, but we don't want it to be rendered nor validated, so remove it from the list + // The template element has been prepared, but we don't want it to be + // rendered nor validated, so remove it from the list. if ($this->shouldCreateTemplate) { $this->remove($this->templatePlaceholder); } diff --git a/library/TorrentPier/Zend/Form/Fieldset.php b/library/TorrentPier/Zend/Form/Fieldset.php index 7fa8aa5d4..5074b59ab 100644 --- a/library/TorrentPier/Zend/Form/Fieldset.php +++ b/library/TorrentPier/Zend/Form/Fieldset.php @@ -203,7 +203,7 @@ class Fieldset extends Element implements FieldsetInterface */ public function has($elementOrFieldset) { - return $this->iterator->get($elementOrFieldset) != null; + return $this->iterator->get($elementOrFieldset) !== null; } /** diff --git a/library/TorrentPier/Zend/Form/Form.php b/library/TorrentPier/Zend/Form/Form.php index 854644f3f..886f94edd 100644 --- a/library/TorrentPier/Zend/Form/Form.php +++ b/library/TorrentPier/Zend/Form/Form.php @@ -788,7 +788,12 @@ class Form extends Fieldset implements FormInterface } } - $inputFilter->add($input, $name); + // Add element input filter to CollectionInputFilter + if ($inputFilter instanceof CollectionInputFilter && !$inputFilter->getInputFilter()->has($name)) { + $inputFilter->getInputFilter()->add($input, $name); + } else { + $inputFilter->add($input, $name); + } } if ($fieldset === $this && $fieldset instanceof InputFilterProviderInterface) { @@ -807,8 +812,27 @@ class Form extends Fieldset implements FormInterface if ($childFieldset->getObject() instanceof InputFilterAwareInterface) { $inputFilter->add($childFieldset->getObject()->getInputFilter(), $name); } else { - if ($fieldset instanceof Collection && $inputFilter instanceof CollectionInputFilter) { - continue; + // Add input filter for collections via getInputFilterSpecification() + if ($childFieldset instanceof Collection + && $childFieldset->getTargetElement() instanceof InputFilterProviderInterface + && $childFieldset->getTargetElement()->getInputFilterSpecification() + ) { + $collectionContainerFilter = new CollectionInputFilter(); + + $spec = $childFieldset->getTargetElement()->getInputFilterSpecification(); + $filter = $inputFactory->createInputFilter($spec); + + $collectionContainerFilter->setInputFilter($filter); + + $inputFilter->add($collectionContainerFilter, $name); + + // We need to copy the inputs to the collection input filter + if ($inputFilter instanceof CollectionInputFilter) { + $inputFilter = $this->addInputsToCollectionInputFilter($inputFilter); + } + + // Add child elements from target element + $childFieldset = $childFieldset->getTargetElement(); } else { $inputFilter->add(new InputFilter(), $name); } @@ -840,9 +864,31 @@ class Form extends Fieldset implements FormInterface // Recursively attach sub filters $this->attachInputFilterDefaults($filter, $childFieldset); + + // We need to copy the inputs to the collection input filter to ensure that all sub filters are added + if ($inputFilter instanceof CollectionInputFilter) { + $inputFilter = $this->addInputsToCollectionInputFilter($inputFilter); + } } } + /** + * Add inputs to CollectionInputFilter + * + * @param CollectionInputFilter $inputFilter + * @return CollectionInputFilter + */ + private function addInputsToCollectionInputFilter(CollectionInputFilter $inputFilter) + { + foreach ($inputFilter->getInputs() as $name => $input) { + if (!$inputFilter->getInputFilter()->has($name)) { + $inputFilter->getInputFilter()->add($input, $name); + } + } + + return $inputFilter; + } + /** * Are the form elements/fieldsets names wrapped by the form name ? * diff --git a/library/TorrentPier/Zend/Form/composer.json b/library/TorrentPier/Zend/Form/composer.json index 1c9395e87..95dea0874 100644 --- a/library/TorrentPier/Zend/Form/composer.json +++ b/library/TorrentPier/Zend/Form/composer.json @@ -42,8 +42,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Http/Header/AbstractAccept.php b/library/TorrentPier/Zend/Http/Header/AbstractAccept.php index 4b9f3bc23..e8f09728d 100644 --- a/library/TorrentPier/Zend/Http/Header/AbstractAccept.php +++ b/library/TorrentPier/Zend/Http/Header/AbstractAccept.php @@ -69,6 +69,8 @@ abstract class AbstractAccept implements HeaderInterface $value = $headerLine; } + HeaderValue::assertValid($value); + foreach ($this->getFieldValuePartsFromHeaderLine($value) as $value) { $this->addFieldValuePartToQueue($value); } @@ -108,7 +110,6 @@ abstract class AbstractAccept implements HeaderInterface $out = array(); foreach ($values[0] as $value) { $value = trim($value); - $out[] = $this->parseFieldValuePart($value); } diff --git a/library/TorrentPier/Zend/Http/Header/AbstractLocation.php b/library/TorrentPier/Zend/Http/Header/AbstractLocation.php index ed262c898..d493be3ba 100644 --- a/library/TorrentPier/Zend/Http/Header/AbstractLocation.php +++ b/library/TorrentPier/Zend/Http/Header/AbstractLocation.php @@ -54,6 +54,7 @@ abstract class AbstractLocation implements HeaderInterface ); } + HeaderValue::assertValid($uri); $locationHeader->setUri(trim($uri)); return $locationHeader; diff --git a/library/TorrentPier/Zend/Http/Header/AcceptRanges.php b/library/TorrentPier/Zend/Http/Header/AcceptRanges.php index b084df1e3..2f1c73ad8 100644 --- a/library/TorrentPier/Zend/Http/Header/AcceptRanges.php +++ b/library/TorrentPier/Zend/Http/Header/AcceptRanges.php @@ -24,7 +24,9 @@ class AcceptRanges implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'accept-ranges') { - throw new Exception\InvalidArgumentException('Invalid header line for Accept-Ranges string'); + throw new Exception\InvalidArgumentException( + 'Invalid header line for Accept-Ranges string' + ); } $header = new static($value); @@ -34,7 +36,9 @@ class AcceptRanges implements HeaderInterface public function __construct($rangeUnit = null) { - $this->rangeUnit = $rangeUnit; + if ($rangeUnit) { + $this->setRangeUnit($rangeUnit); + } } public function getFieldName() @@ -49,6 +53,7 @@ class AcceptRanges implements HeaderInterface public function setRangeUnit($rangeUnit) { + HeaderValue::assertValid($rangeUnit); $this->rangeUnit = $rangeUnit; return $this; } diff --git a/library/TorrentPier/Zend/Http/Header/Age.php b/library/TorrentPier/Zend/Http/Header/Age.php index aa8637ee6..a11974663 100644 --- a/library/TorrentPier/Zend/Http/Header/Age.php +++ b/library/TorrentPier/Zend/Http/Header/Age.php @@ -79,6 +79,9 @@ class Age implements HeaderInterface */ public function setDeltaSeconds($delta) { + if (! is_int($delta) && ! is_numeric($delta)) { + throw new Exception\InvalidArgumentException('Invalid delta provided'); + } $this->deltaSeconds = (int) $delta; return $this; } diff --git a/library/TorrentPier/Zend/Http/Header/Allow.php b/library/TorrentPier/Zend/Http/Header/Allow.php index aee66731f..424017986 100644 --- a/library/TorrentPier/Zend/Http/Header/Allow.php +++ b/library/TorrentPier/Zend/Http/Header/Allow.php @@ -110,6 +110,12 @@ class Allow implements HeaderInterface { foreach ((array) $allowedMethods as $method) { $method = trim(strtoupper($method)); + if (preg_match('/\s/', $method)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Unable to whitelist method; "%s" is not a valid method', + $method + )); + } $this->methods[$method] = true; } @@ -126,6 +132,12 @@ class Allow implements HeaderInterface { foreach ((array) $disallowedMethods as $method) { $method = trim(strtoupper($method)); + if (preg_match('/\s/', $method)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Unable to blacklist method; "%s" is not a valid method', + $method + )); + } $this->methods[$method] = false; } diff --git a/library/TorrentPier/Zend/Http/Header/AuthenticationInfo.php b/library/TorrentPier/Zend/Http/Header/AuthenticationInfo.php index 73e0044a8..c9df1f4a3 100644 --- a/library/TorrentPier/Zend/Http/Header/AuthenticationInfo.php +++ b/library/TorrentPier/Zend/Http/Header/AuthenticationInfo.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class AuthenticationInfo implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class AuthenticationInfo implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'authentication-info') { - throw new Exception\InvalidArgumentException('Invalid header line for Authentication-Info string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Authentication-Info string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class AuthenticationInfo implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Authorization.php b/library/TorrentPier/Zend/Http/Header/Authorization.php index 197eef974..4a5bcfd62 100644 --- a/library/TorrentPier/Zend/Http/Header/Authorization.php +++ b/library/TorrentPier/Zend/Http/Header/Authorization.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Authorization implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class Authorization implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'authorization') { - throw new Exception\InvalidArgumentException('Invalid header line for Authorization string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Authorization string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class Authorization implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/CacheControl.php b/library/TorrentPier/Zend/Http/Header/CacheControl.php index 678041374..05e63af9c 100644 --- a/library/TorrentPier/Zend/Http/Header/CacheControl.php +++ b/library/TorrentPier/Zend/Http/Header/CacheControl.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class CacheControl implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; /** @@ -44,6 +46,7 @@ class CacheControl implements HeaderInterface )); } + HeaderValue::assertValid($value); $directives = static::parseValue($value); // @todo implementation details @@ -86,6 +89,10 @@ class CacheControl implements HeaderInterface */ public function addDirective($key, $value = true) { + HeaderValue::assertValid($key); + if (! is_bool($value)) { + HeaderValue::assertValid($value); + } $this->directives[$key] = $value; return $this; } diff --git a/library/TorrentPier/Zend/Http/Header/Connection.php b/library/TorrentPier/Zend/Http/Header/Connection.php index 45be7259e..739fb13aa 100644 --- a/library/TorrentPier/Zend/Http/Header/Connection.php +++ b/library/TorrentPier/Zend/Http/Header/Connection.php @@ -55,11 +55,9 @@ class Connection implements HeaderInterface */ public function setPersistent($flag) { - if ((bool) $flag === true) { - $this->value = self::CONNECTION_KEEP_ALIVE; - } else { - $this->value = self::CONNECTION_CLOSE; - } + $this->value = (bool) $flag + ? self::CONNECTION_KEEP_ALIVE + : self::CONNECTION_CLOSE; return $this; } @@ -82,6 +80,7 @@ class Connection implements HeaderInterface */ public function setValue($value) { + HeaderValue::assertValid($value); $this->value = strtolower($value); return $this; } diff --git a/library/TorrentPier/Zend/Http/Header/ContentDisposition.php b/library/TorrentPier/Zend/Http/Header/ContentDisposition.php index 1c24f7a65..508fbfcdd 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentDisposition.php +++ b/library/TorrentPier/Zend/Http/Header/ContentDisposition.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ContentDisposition implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class ContentDisposition implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'content-disposition') { - throw new Exception\InvalidArgumentException('Invalid header line for Content-Disposition string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Content-Disposition string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class ContentDisposition implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ContentEncoding.php b/library/TorrentPier/Zend/Http/Header/ContentEncoding.php index c166b66a8..a6c642870 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentEncoding.php +++ b/library/TorrentPier/Zend/Http/Header/ContentEncoding.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ContentEncoding implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,9 @@ class ContentEncoding implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'content-encoding') { - throw new Exception\InvalidArgumentException('Invalid header line for Content-Encoding string: "' . $name . '"'); + throw new Exception\InvalidArgumentException( + 'Invalid header line for Content-Encoding string: "' . $name . '"' + ); } // @todo implementation details @@ -35,7 +39,10 @@ class ContentEncoding implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ContentLanguage.php b/library/TorrentPier/Zend/Http/Header/ContentLanguage.php index 104911f09..58d320b50 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentLanguage.php +++ b/library/TorrentPier/Zend/Http/Header/ContentLanguage.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ContentLanguage implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class ContentLanguage implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'content-language') { - throw new Exception\InvalidArgumentException('Invalid header line for Content-Language string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Content-Language string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class ContentLanguage implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ContentLength.php b/library/TorrentPier/Zend/Http/Header/ContentLength.php index 62e5bde0c..7b89798a4 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentLength.php +++ b/library/TorrentPier/Zend/Http/Header/ContentLength.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ContentLength implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class ContentLength implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'content-length') { - throw new Exception\InvalidArgumentException('Invalid header line for Content-Length string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Content-Length string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class ContentLength implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ContentMD5.php b/library/TorrentPier/Zend/Http/Header/ContentMD5.php index 581de8157..7cd6006e3 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentMD5.php +++ b/library/TorrentPier/Zend/Http/Header/ContentMD5.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ContentMD5 implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class ContentMD5 implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ContentRange.php b/library/TorrentPier/Zend/Http/Header/ContentRange.php index 100eedd65..c23f921eb 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentRange.php +++ b/library/TorrentPier/Zend/Http/Header/ContentRange.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ContentRange implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class ContentRange implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'content-range') { - throw new Exception\InvalidArgumentException('Invalid header line for Content-Range string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Content-Range string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class ContentRange implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ContentSecurityPolicy.php b/library/TorrentPier/Zend/Http/Header/ContentSecurityPolicy.php index 85f1cff0e..e149db2bb 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentSecurityPolicy.php +++ b/library/TorrentPier/Zend/Http/Header/ContentSecurityPolicy.php @@ -65,7 +65,7 @@ class ContentSecurityPolicy implements HeaderInterface */ public function setDirective($name, array $sources) { - if (!in_array($name, $this->validDirectiveNames, true)) { + if (! in_array($name, $this->validDirectiveNames, true)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects a valid directive name; received "%s"', __METHOD__, @@ -74,9 +74,12 @@ class ContentSecurityPolicy implements HeaderInterface } if (empty($sources)) { $this->directives[$name] = "'none'"; - } else { - $this->directives[$name] = implode(' ', $sources); + return $this; } + + array_walk($sources, array(__NAMESPACE__ . '\HeaderValue', 'assertValid')); + + $this->directives[$name] = implode(' ', $sources); return $this; } @@ -107,7 +110,7 @@ class ContentSecurityPolicy implements HeaderInterface if ($token) { list($directiveName, $directiveValue) = explode(' ', $token, 2); if (!isset($header->directives[$directiveName])) { - $header->directives[$directiveName] = $directiveValue; + $header->setDirective($directiveName, array($directiveValue)); } } } diff --git a/library/TorrentPier/Zend/Http/Header/ContentTransferEncoding.php b/library/TorrentPier/Zend/Http/Header/ContentTransferEncoding.php index ec72a2169..480fb44c0 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentTransferEncoding.php +++ b/library/TorrentPier/Zend/Http/Header/ContentTransferEncoding.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ContentTransferEncoding implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class ContentTransferEncoding implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'content-transfer-encoding') { - throw new Exception\InvalidArgumentException('Invalid header line for Content-Transfer-Encoding string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Content-Transfer-Encoding string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class ContentTransferEncoding implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ContentType.php b/library/TorrentPier/Zend/Http/Header/ContentType.php index 58f5a465e..c7d0c28c9 100644 --- a/library/TorrentPier/Zend/Http/Header/ContentType.php +++ b/library/TorrentPier/Zend/Http/Header/ContentType.php @@ -44,7 +44,10 @@ class ContentType implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'content-type') { - throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Content-Type string: "%s"', + $name + )); } $parts = explode(';', $value); @@ -68,7 +71,10 @@ class ContentType implements HeaderInterface public function __construct($value = null, $mediaType = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } $this->mediaType = $mediaType; } @@ -155,6 +161,7 @@ class ContentType implements HeaderInterface */ public function setMediaType($mediaType) { + HeaderValue::assertValid($mediaType); $this->mediaType = strtolower($mediaType); $this->value = null; return $this; @@ -178,6 +185,10 @@ class ContentType implements HeaderInterface */ public function setParameters(array $parameters) { + foreach ($parameters as $key => $value) { + HeaderValue::assertValid($key); + HeaderValue::assertValid($value); + } $this->parameters = array_merge($this->parameters, $parameters); $this->value = null; return $this; @@ -201,6 +212,7 @@ class ContentType implements HeaderInterface */ public function setCharset($charset) { + HeaderValue::assertValid($charset); $this->parameters['charset'] = $charset; $this->value = null; return $this; diff --git a/library/TorrentPier/Zend/Http/Header/Cookie.php b/library/TorrentPier/Zend/Http/Header/Cookie.php index 558c5150a..5cbac5e52 100644 --- a/library/TorrentPier/Zend/Http/Header/Cookie.php +++ b/library/TorrentPier/Zend/Http/Header/Cookie.php @@ -22,17 +22,25 @@ class Cookie extends ArrayObject implements HeaderInterface public static function fromSetCookieArray(array $setCookies) { $nvPairs = array(); - /* @var $setCookie SetCookie */ + foreach ($setCookies as $setCookie) { - if (!$setCookie instanceof SetCookie) { - throw new Exception\InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . ' requires an array of SetCookie objects'); + if (! $setCookie instanceof SetCookie) { + throw new Exception\InvalidArgumentException(sprintf( + '%s requires an array of SetCookie objects', + __METHOD__ + )); } + if (array_key_exists($setCookie->getName(), $nvPairs)) { - throw new Exception\InvalidArgumentException('Two cookies with the same name were provided to ' . __CLASS__ . '::' . __METHOD__); + throw new Exception\InvalidArgumentException(sprintf( + 'Two cookies with the same name were provided to %s', + __METHOD__ + )); } $nvPairs[$setCookie->getName()] = $setCookie->getValue(); } + return new static($nvPairs); } diff --git a/library/TorrentPier/Zend/Http/Header/Etag.php b/library/TorrentPier/Zend/Http/Header/Etag.php index 169bfb85b..8f23d7f94 100644 --- a/library/TorrentPier/Zend/Http/Header/Etag.php +++ b/library/TorrentPier/Zend/Http/Header/Etag.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Etag implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Etag implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Expect.php b/library/TorrentPier/Zend/Http/Header/Expect.php index 87dea578a..d6eb74334 100644 --- a/library/TorrentPier/Zend/Http/Header/Expect.php +++ b/library/TorrentPier/Zend/Http/Header/Expect.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Expect implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Expect implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/From.php b/library/TorrentPier/Zend/Http/Header/From.php index 0089227b2..505080d4b 100644 --- a/library/TorrentPier/Zend/Http/Header/From.php +++ b/library/TorrentPier/Zend/Http/Header/From.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class From implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class From implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/GenericHeader.php b/library/TorrentPier/Zend/Http/Header/GenericHeader.php index bb1cc0e58..d17c8e161 100644 --- a/library/TorrentPier/Zend/Http/Header/GenericHeader.php +++ b/library/TorrentPier/Zend/Http/Header/GenericHeader.php @@ -53,6 +53,10 @@ class GenericHeader implements HeaderInterface throw new Exception\InvalidArgumentException('Header must match with the format "name:value"'); } + if (! HeaderValue::isValid($parts[1])) { + throw new Exception\InvalidArgumentException('Invalid header value detected'); + } + $parts[1] = ltrim($parts[1]); return $parts; @@ -126,6 +130,7 @@ class GenericHeader implements HeaderInterface public function setFieldValue($fieldValue) { $fieldValue = (string) $fieldValue; + HeaderValue::assertValid($fieldValue); if (preg_match('/^\s+$/', $fieldValue)) { $fieldValue = ''; diff --git a/library/TorrentPier/Zend/Http/Header/HeaderValue.php b/library/TorrentPier/Zend/Http/Header/HeaderValue.php new file mode 100644 index 000000000..a16e22e47 --- /dev/null +++ b/library/TorrentPier/Zend/Http/Header/HeaderValue.php @@ -0,0 +1,107 @@ + 254 + ) { + continue; + } + + $string .= $value[$i]; + } + + return $string; + } + + /** + * Validate a header value. + * + * Per RFC 7230, only VISIBLE ASCII characters, spaces, and horizontal + * tabs are allowed in values; only one whitespace character is allowed + * between visible characters. + * + * @see http://en.wikipedia.org/wiki/HTTP_response_splitting + * @param string $value + * @return bool + */ + public static function isValid($value) + { + $value = (string) $value; + $length = strlen($value); + for ($i = 0; $i < $length; $i += 1) { + $ascii = ord($value[$i]); + + // Non-visible, non-whitespace characters + // 9 === horizontal tab + // 32-126, 128-254 === visible + // 127 === DEL + // 255 === null byte + if (($ascii < 32 && $ascii !== 9) + || $ascii === 127 + || $ascii > 254 + ) { + return false; + } + } + + return true; + } + + /** + * Assert a header value is valid. + * + * @param string $value + * @throws Exception\RuntimeException for invalid values + * @return void + */ + public static function assertValid($value) + { + if (! self::isValid($value)) { + throw new Exception\InvalidArgumentException('Invalid header value'); + } + } +} diff --git a/library/TorrentPier/Zend/Http/Header/Host.php b/library/TorrentPier/Zend/Http/Header/Host.php index 2446d155a..ada179ac3 100644 --- a/library/TorrentPier/Zend/Http/Header/Host.php +++ b/library/TorrentPier/Zend/Http/Header/Host.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Host implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Host implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/IfMatch.php b/library/TorrentPier/Zend/Http/Header/IfMatch.php index adb5e8afc..e4e40b254 100644 --- a/library/TorrentPier/Zend/Http/Header/IfMatch.php +++ b/library/TorrentPier/Zend/Http/Header/IfMatch.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class IfMatch implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class IfMatch implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/IfNoneMatch.php b/library/TorrentPier/Zend/Http/Header/IfNoneMatch.php index 8ce5b15ea..f7e8605a8 100644 --- a/library/TorrentPier/Zend/Http/Header/IfNoneMatch.php +++ b/library/TorrentPier/Zend/Http/Header/IfNoneMatch.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class IfNoneMatch implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class IfNoneMatch implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'if-none-match') { - throw new Exception\InvalidArgumentException('Invalid header line for If-None-Match string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for If-None-Match string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class IfNoneMatch implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/IfRange.php b/library/TorrentPier/Zend/Http/Header/IfRange.php index 3f763d32f..592315830 100644 --- a/library/TorrentPier/Zend/Http/Header/IfRange.php +++ b/library/TorrentPier/Zend/Http/Header/IfRange.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class IfRange implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class IfRange implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/KeepAlive.php b/library/TorrentPier/Zend/Http/Header/KeepAlive.php index 86f9dc727..10486bd2e 100644 --- a/library/TorrentPier/Zend/Http/Header/KeepAlive.php +++ b/library/TorrentPier/Zend/Http/Header/KeepAlive.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class KeepAlive implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class KeepAlive implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/MaxForwards.php b/library/TorrentPier/Zend/Http/Header/MaxForwards.php index ac2988718..4d4b1620b 100644 --- a/library/TorrentPier/Zend/Http/Header/MaxForwards.php +++ b/library/TorrentPier/Zend/Http/Header/MaxForwards.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class MaxForwards implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class MaxForwards implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'max-forwards') { - throw new Exception\InvalidArgumentException('Invalid header line for Max-Forwards string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Max-Forwards string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class MaxForwards implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Origin.php b/library/TorrentPier/Zend/Http/Header/Origin.php index d95d56fa6..01b95b94d 100644 --- a/library/TorrentPier/Zend/Http/Header/Origin.php +++ b/library/TorrentPier/Zend/Http/Header/Origin.php @@ -20,7 +20,7 @@ class Origin implements HeaderInterface /** * @var string */ - protected $value; + protected $value = ''; public static function fromString($headerLine) { @@ -44,7 +44,10 @@ class Origin implements HeaderInterface */ public function __construct($value = null) { - $this->value = (string) $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Pragma.php b/library/TorrentPier/Zend/Http/Header/Pragma.php index f7198577d..a9b68d912 100644 --- a/library/TorrentPier/Zend/Http/Header/Pragma.php +++ b/library/TorrentPier/Zend/Http/Header/Pragma.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Pragma implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Pragma implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/ProxyAuthenticate.php b/library/TorrentPier/Zend/Http/Header/ProxyAuthenticate.php index 292c4ba71..7b4a09239 100644 --- a/library/TorrentPier/Zend/Http/Header/ProxyAuthenticate.php +++ b/library/TorrentPier/Zend/Http/Header/ProxyAuthenticate.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ProxyAuthenticate implements MultipleHeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class ProxyAuthenticate implements MultipleHeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'proxy-authenticate') { - throw new Exception\InvalidArgumentException('Invalid header line for Proxy-Authenticate string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Proxy-Authenticate string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class ProxyAuthenticate implements MultipleHeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() @@ -59,7 +67,8 @@ class ProxyAuthenticate implements MultipleHeaderInterface foreach ($headers as $header) { if (!$header instanceof ProxyAuthenticate) { throw new Exception\RuntimeException( - 'The ProxyAuthenticate multiple header implementation can only accept an array of ProxyAuthenticate headers' + 'The ProxyAuthenticate multiple header implementation can only accept' + . ' an array of ProxyAuthenticate headers' ); } $strings[] = $header->toString(); diff --git a/library/TorrentPier/Zend/Http/Header/ProxyAuthorization.php b/library/TorrentPier/Zend/Http/Header/ProxyAuthorization.php index b0d5738ab..1d7c7dc82 100644 --- a/library/TorrentPier/Zend/Http/Header/ProxyAuthorization.php +++ b/library/TorrentPier/Zend/Http/Header/ProxyAuthorization.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class ProxyAuthorization implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class ProxyAuthorization implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'proxy-authorization') { - throw new Exception\InvalidArgumentException('Invalid header line for Proxy-Authorization string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for Proxy-Authorization string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class ProxyAuthorization implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Range.php b/library/TorrentPier/Zend/Http/Header/Range.php index 103b7b49e..bfeb7ed76 100644 --- a/library/TorrentPier/Zend/Http/Header/Range.php +++ b/library/TorrentPier/Zend/Http/Header/Range.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Range implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Range implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Refresh.php b/library/TorrentPier/Zend/Http/Header/Refresh.php index f887325ff..209139303 100644 --- a/library/TorrentPier/Zend/Http/Header/Refresh.php +++ b/library/TorrentPier/Zend/Http/Header/Refresh.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Refresh implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Refresh implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Server.php b/library/TorrentPier/Zend/Http/Header/Server.php index bf07f0e44..e3343178b 100644 --- a/library/TorrentPier/Zend/Http/Header/Server.php +++ b/library/TorrentPier/Zend/Http/Header/Server.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Server implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Server implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/SetCookie.php b/library/TorrentPier/Zend/Http/Header/SetCookie.php index a1dec80e7..707d0e96d 100644 --- a/library/TorrentPier/Zend/Http/Header/SetCookie.php +++ b/library/TorrentPier/Zend/Http/Header/SetCookie.php @@ -153,6 +153,7 @@ class SetCookie implements MultipleHeaderInterface } list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + HeaderValue::assertValid($value); // some sites return set-cookie::value, this is to get rid of the second : $name = (strtolower($name) =='set-cookie:') ? 'set-cookie' : $name; @@ -190,8 +191,17 @@ class SetCookie implements MultipleHeaderInterface * @param string $maxAge * @param int $version */ - public function __construct($name = null, $value = null, $expires = null, $path = null, $domain = null, $secure = false, $httponly = false, $maxAge = null, $version = null) - { + public function __construct( + $name = null, + $value = null, + $expires = null, + $path = null, + $domain = null, + $secure = false, + $httponly = false, + $maxAge = null, + $version = null + ) { $this->type = 'Cookie'; $this->setName($name) @@ -231,7 +241,7 @@ class SetCookie implements MultipleHeaderInterface $fieldValue = $this->getName() . '=' . $value; $version = $this->getVersion(); - if ($version!==null) { + if ($version !== null) { $fieldValue .= '; Version=' . $version; } @@ -273,6 +283,7 @@ class SetCookie implements MultipleHeaderInterface */ public function setName($name) { + HeaderValue::assertValid($name); $this->name = $name; return $this; } @@ -291,6 +302,7 @@ class SetCookie implements MultipleHeaderInterface */ public function setValue($value) { + HeaderValue::assertValid($value); $this->value = $value; return $this; } @@ -419,6 +431,7 @@ class SetCookie implements MultipleHeaderInterface */ public function setDomain($domain) { + HeaderValue::assertValid($domain); $this->domain = $domain; return $this; } @@ -437,6 +450,7 @@ class SetCookie implements MultipleHeaderInterface */ public function setPath($path) { + HeaderValue::assertValid($path); $this->path = $path; return $this; } @@ -455,6 +469,9 @@ class SetCookie implements MultipleHeaderInterface */ public function setSecure($secure) { + if (null !== $secure) { + $secure = (bool) $secure; + } $this->secure = $secure; return $this; } @@ -485,6 +502,9 @@ class SetCookie implements MultipleHeaderInterface */ public function setHttponly($httponly) { + if (null !== $httponly) { + $httponly = (bool) $httponly; + } $this->httponly = $httponly; return $this; } diff --git a/library/TorrentPier/Zend/Http/Header/TE.php b/library/TorrentPier/Zend/Http/Header/TE.php index 55178a977..b9a1eefd1 100644 --- a/library/TorrentPier/Zend/Http/Header/TE.php +++ b/library/TorrentPier/Zend/Http/Header/TE.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class TE implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class TE implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Trailer.php b/library/TorrentPier/Zend/Http/Header/Trailer.php index 0fcba569e..6caf7eb54 100644 --- a/library/TorrentPier/Zend/Http/Header/Trailer.php +++ b/library/TorrentPier/Zend/Http/Header/Trailer.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Trailer implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Trailer implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/TransferEncoding.php b/library/TorrentPier/Zend/Http/Header/TransferEncoding.php index 17606e3a5..526253d27 100644 --- a/library/TorrentPier/Zend/Http/Header/TransferEncoding.php +++ b/library/TorrentPier/Zend/Http/Header/TransferEncoding.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class TransferEncoding implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,9 @@ class TransferEncoding implements HeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'transfer-encoding') { - throw new Exception\InvalidArgumentException('Invalid header line for Transfer-Encoding string: "' . $name . '"'); + throw new Exception\InvalidArgumentException( + 'Invalid header line for Transfer-Encoding string: "' . $name . '"' + ); } // @todo implementation details @@ -35,7 +39,10 @@ class TransferEncoding implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Upgrade.php b/library/TorrentPier/Zend/Http/Header/Upgrade.php index 162251e13..909a3f014 100644 --- a/library/TorrentPier/Zend/Http/Header/Upgrade.php +++ b/library/TorrentPier/Zend/Http/Header/Upgrade.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Upgrade implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Upgrade implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/UserAgent.php b/library/TorrentPier/Zend/Http/Header/UserAgent.php index 65941f80b..6fdbec64b 100644 --- a/library/TorrentPier/Zend/Http/Header/UserAgent.php +++ b/library/TorrentPier/Zend/Http/Header/UserAgent.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class UserAgent implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class UserAgent implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Vary.php b/library/TorrentPier/Zend/Http/Header/Vary.php index f80cb34c7..3e41b6b7c 100644 --- a/library/TorrentPier/Zend/Http/Header/Vary.php +++ b/library/TorrentPier/Zend/Http/Header/Vary.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Vary implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Vary implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/Via.php b/library/TorrentPier/Zend/Http/Header/Via.php index f8004331e..a387be16f 100644 --- a/library/TorrentPier/Zend/Http/Header/Via.php +++ b/library/TorrentPier/Zend/Http/Header/Via.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Via implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Via implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Header/WWWAuthenticate.php b/library/TorrentPier/Zend/Http/Header/WWWAuthenticate.php index 11de97af8..d1b8bd17c 100644 --- a/library/TorrentPier/Zend/Http/Header/WWWAuthenticate.php +++ b/library/TorrentPier/Zend/Http/Header/WWWAuthenticate.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class WWWAuthenticate implements MultipleHeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -24,7 +26,10 @@ class WWWAuthenticate implements MultipleHeaderInterface // check to ensure proper header type for this factory if (strtolower($name) !== 'www-authenticate') { - throw new Exception\InvalidArgumentException('Invalid header line for WWW-Authenticate string: "' . $name . '"'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid header line for WWW-Authenticate string: "%s"', + $name + )); } // @todo implementation details @@ -35,7 +40,10 @@ class WWWAuthenticate implements MultipleHeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() @@ -59,7 +67,8 @@ class WWWAuthenticate implements MultipleHeaderInterface foreach ($headers as $header) { if (!$header instanceof WWWAuthenticate) { throw new Exception\RuntimeException( - 'The WWWAuthenticate multiple header implementation can only accept an array of WWWAuthenticate headers' + 'The WWWAuthenticate multiple header implementation can only' + . ' accept an array of WWWAuthenticate headers' ); } $strings[] = $header->toString(); diff --git a/library/TorrentPier/Zend/Http/Header/Warning.php b/library/TorrentPier/Zend/Http/Header/Warning.php index b94b09d35..4b36e1948 100644 --- a/library/TorrentPier/Zend/Http/Header/Warning.php +++ b/library/TorrentPier/Zend/Http/Header/Warning.php @@ -15,7 +15,9 @@ namespace Zend\Http\Header; */ class Warning implements HeaderInterface { - /** @var string */ + /** + * @var string + */ protected $value; public static function fromString($headerLine) @@ -35,7 +37,10 @@ class Warning implements HeaderInterface public function __construct($value = null) { - $this->value = $value; + if ($value) { + HeaderValue::assertValid($value); + $this->value = $value; + } } public function getFieldName() diff --git a/library/TorrentPier/Zend/Http/Headers.php b/library/TorrentPier/Zend/Http/Headers.php index 0ed582fd6..85aa555e9 100644 --- a/library/TorrentPier/Zend/Http/Headers.php +++ b/library/TorrentPier/Zend/Http/Headers.php @@ -51,13 +51,29 @@ class Headers implements Countable, Iterator */ public static function fromString($string) { - $headers = new static(); - $current = array(); + $headers = new static(); + $current = array(); + $emptyLine = 0; // iterate the header lines, some might be continuations foreach (explode("\r\n", $string) as $line) { + // CRLF*2 is end of headers; an empty line by itself or between header lines + // is an attempt at CRLF injection. + if (preg_match('/^\s*$/', $line)) { + // empty line indicates end of headers + $emptyLine += 1; + if ($emptyLine > 2) { + throw new Exception\RuntimeException('Malformed header detected'); + } + continue; + } + + if ($emptyLine) { + throw new Exception\RuntimeException('Malformed header detected'); + } + // check if a header name is present - if (preg_match('/^(?P[^()><@,;:\"\\/\[\]?=}{ \t]+):.*$/', $line, $matches)) { + if (preg_match('/^(?P[^()><@,;:\"\\/\[\]?={} \t]+):.*$/', $line, $matches)) { if ($current) { // a header name was present, then store the current complete line $headers->headersKeys[] = static::createKey($current['name']); @@ -67,19 +83,21 @@ class Headers implements Countable, Iterator 'name' => $matches['name'], 'line' => trim($line) ); - } elseif (preg_match('/^(?P\s+).*$/', $line, $matches)) { - // continuation: append to current line - $current['line'] .= "\r\n" . $matches['ws'] . trim($line); - } elseif (preg_match('/^\s*$/', $line)) { - // empty line indicates end of headers - break; - } else { - // Line does not match header format! - throw new Exception\RuntimeException(sprintf( - 'Line "%s" does not match header format!', - $line - )); + + continue; } + + if (preg_match("/^[ \t][^\r\n]*$/", $line, $matches)) { + // continuation: append to current line + $current['line'] .= trim($line); + continue; + } + + // Line does not match header format! + throw new Exception\RuntimeException(sprintf( + 'Line "%s" does not match header format!', + $line + )); } if ($current) { $headers->headersKeys[] = static::createKey($current['name']); diff --git a/library/TorrentPier/Zend/Http/PhpEnvironment/Request.php b/library/TorrentPier/Zend/Http/PhpEnvironment/Request.php index 3682f461d..10abf5980 100644 --- a/library/TorrentPier/Zend/Http/PhpEnvironment/Request.php +++ b/library/TorrentPier/Zend/Http/PhpEnvironment/Request.php @@ -59,6 +59,8 @@ class Request extends HttpRequest /** * Construct * Instantiates request. + * + * @param bool $allowCustomMethods */ public function __construct($allowCustomMethods = true) { diff --git a/library/TorrentPier/Zend/Http/Request.php b/library/TorrentPier/Zend/Http/Request.php index 987a47ad6..9cac07782 100644 --- a/library/TorrentPier/Zend/Http/Request.php +++ b/library/TorrentPier/Zend/Http/Request.php @@ -77,7 +77,6 @@ class Request extends AbstractMessage implements RequestInterface */ public static function fromString($string, $allowCustomMethods = true) { - /** @var Request $request */ $request = new static(); $request->setAllowCustomMethods($allowCustomMethods); @@ -136,11 +135,23 @@ class Request extends AbstractMessage implements RequestInterface $isHeader = false; continue; } + if ($isHeader) { + if (preg_match("/[\r\n]/", $nextLine)) { + throw new Exception\RuntimeException('CRLF injection detected'); + } $headers[] = $nextLine; - } else { - $rawBody[] = $nextLine; + continue; } + + + if (empty($rawBody) + && preg_match('/^[a-z0-9!#$%&\'*+.^_`|~-]+:$/i', $nextLine) + ) { + throw new Exception\RuntimeException('CRLF injection detected'); + } + + $rawBody[] = $nextLine; } if ($headers) { diff --git a/library/TorrentPier/Zend/Http/Response.php b/library/TorrentPier/Zend/Http/Response.php index 5dcab5991..2d5c1a45a 100644 --- a/library/TorrentPier/Zend/Http/Response.php +++ b/library/TorrentPier/Zend/Http/Response.php @@ -202,11 +202,22 @@ class Response extends AbstractMessage implements ResponseInterface $isHeader = false; continue; } + if ($isHeader) { + if (preg_match("/[\r\n]/", $line)) { + throw new Exception\RuntimeException('CRLF injection detected'); + } $headers[] = $line; - } else { - $content[] = $line; + continue; } + + if (empty($content) + && preg_match('/^[a-z0-9!#$%&\'*+.^_`|~-]+:$/i', $line) + ) { + throw new Exception\RuntimeException('CRLF injection detected'); + } + + $content[] = $line; } if ($headers) { diff --git a/library/TorrentPier/Zend/Http/Response/Stream.php b/library/TorrentPier/Zend/Http/Response/Stream.php index cc74cdc27..dbb1ea760 100644 --- a/library/TorrentPier/Zend/Http/Response/Stream.php +++ b/library/TorrentPier/Zend/Http/Response/Stream.php @@ -174,7 +174,6 @@ class Stream extends Response if (!$headerComplete) { while (false !== ($nextLine = fgets($stream))) { - $headersString .= trim($nextLine)."\r\n"; if ($nextLine == "\r\n" || $nextLine == "\n") { $headerComplete = true; @@ -231,7 +230,7 @@ class Stream extends Response */ public function getBody() { - if ($this->stream != null) { + if ($this->stream !== null) { $this->readStream(); } return parent::getBody(); diff --git a/library/TorrentPier/Zend/Http/composer.json b/library/TorrentPier/Zend/Http/composer.json index ec475c49e..2f3e65755 100644 --- a/library/TorrentPier/Zend/Http/composer.json +++ b/library/TorrentPier/Zend/Http/composer.json @@ -21,8 +21,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/I18n/Validator/DateTime.php b/library/TorrentPier/Zend/I18n/Validator/DateTime.php index 24355d1a5..ad8eb480d 100644 --- a/library/TorrentPier/Zend/I18n/Validator/DateTime.php +++ b/library/TorrentPier/Zend/I18n/Validator/DateTime.php @@ -298,7 +298,7 @@ class DateTime extends AbstractValidator */ protected function getIntlDateFormatter() { - if ($this->formatter == null || $this->invalidateFormatter) { + if ($this->formatter === null || $this->invalidateFormatter) { $this->formatter = new IntlDateFormatter( $this->getLocale(), $this->getDateType(), diff --git a/library/TorrentPier/Zend/I18n/composer.json b/library/TorrentPier/Zend/I18n/composer.json index 955683b0e..a2091f448 100644 --- a/library/TorrentPier/Zend/I18n/composer.json +++ b/library/TorrentPier/Zend/I18n/composer.json @@ -38,8 +38,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/InputFilter/BaseInputFilter.php b/library/TorrentPier/Zend/InputFilter/BaseInputFilter.php index 3e41a24cd..a6b70dad2 100644 --- a/library/TorrentPier/Zend/InputFilter/BaseInputFilter.php +++ b/library/TorrentPier/Zend/InputFilter/BaseInputFilter.php @@ -14,20 +14,35 @@ use Traversable; use Zend\Stdlib\ArrayUtils; use Zend\Stdlib\InitializableInterface; -/** - * @todo How should we deal with required input when data is missing? - * should a message be returned? if so, what message? - */ class BaseInputFilter implements InputFilterInterface, UnknownInputsCapableInterface, InitializableInterface, ReplaceableInputInterface { + /** + * @var array + */ protected $data; + + /** + * @var InputInterface[]|InputFilterInterface[] + */ protected $inputs = array(); + + /** + * @var InputInterface[]|InputFilterInterface[] + */ protected $invalidInputs; + + /** + * @var array + */ protected $validationGroup; + + /** + * @var InputInterface[]|InputFilterInterface[] + */ protected $validInputs; /** @@ -297,35 +312,33 @@ class BaseInputFilter implements if (is_array($name)) { $inputs = array(); foreach ($name as $key => $value) { - if (!$this->has($key)) { + if (! $this->has($key)) { $inputs[] = $value; - } else { - $inputs[] = $key; - - if (!$this->inputs[$key] instanceof InputFilterInterface) { - throw new Exception\InvalidArgumentException( - sprintf( - 'Input "%s" must implement InputFilterInterface', - $key - ) - ); - } - // Recursively populate validation groups for sub input filters - $this->inputs[$key]->setValidationGroup($value); + continue; } - } - if (!empty($inputs)) { - $this->validateValidationGroup($inputs); - $this->validationGroup = $inputs; - } + $inputs[] = $key; - return $this; + if (! $this->inputs[$key] instanceof InputFilterInterface) { + throw new Exception\InvalidArgumentException( + sprintf( + 'Input "%s" must implement InputFilterInterface', + $key + ) + ); + } + + // Recursively populate validation groups for sub input filters + $this->inputs[$key]->setValidationGroup($value); + } + } else { + $inputs = func_get_args(); } - $inputs = func_get_args(); - $this->validateValidationGroup($inputs); - $this->validationGroup = $inputs; + if (! empty($inputs)) { + $this->validateValidationGroup($inputs); + $this->validationGroup = $inputs; + } return $this; } @@ -603,5 +616,7 @@ class BaseInputFilter implements foreach ($inputFilter->getInputs() as $name => $input) { $this->add($input, $name); } + + return $this; } } diff --git a/library/TorrentPier/Zend/InputFilter/CollectionInputFilter.php b/library/TorrentPier/Zend/InputFilter/CollectionInputFilter.php index 1e2f1daeb..c4cc348a1 100644 --- a/library/TorrentPier/Zend/InputFilter/CollectionInputFilter.php +++ b/library/TorrentPier/Zend/InputFilter/CollectionInputFilter.php @@ -200,11 +200,8 @@ class CollectionInputFilter extends InputFilter public function setValidationGroup($name) { if ($name === self::VALIDATE_ALL) { - $this->validationGroup = null; - - return $this; + $name = null; } - $this->validationGroup = $name; return $this; diff --git a/library/TorrentPier/Zend/InputFilter/EmptyContextInterface.php b/library/TorrentPier/Zend/InputFilter/EmptyContextInterface.php index 3c1411290..62e2e2251 100644 --- a/library/TorrentPier/Zend/InputFilter/EmptyContextInterface.php +++ b/library/TorrentPier/Zend/InputFilter/EmptyContextInterface.php @@ -11,7 +11,14 @@ namespace Zend\InputFilter; interface EmptyContextInterface { + /** + * @param bool $continueIfEmpty + * @return self + */ public function setContinueIfEmpty($continueIfEmpty); + /** + * @return bool + */ public function continueIfEmpty(); } diff --git a/library/TorrentPier/Zend/InputFilter/FileInput.php b/library/TorrentPier/Zend/InputFilter/FileInput.php index 3a11f934d..3e0ac77d6 100644 --- a/library/TorrentPier/Zend/InputFilter/FileInput.php +++ b/library/TorrentPier/Zend/InputFilter/FileInput.php @@ -112,10 +112,17 @@ class FileInput extends Input */ public function isValid($context = null) { - $rawValue = $this->getRawValue(); - $empty = $this->isEmptyFile($rawValue); + $rawValue = $this->getRawValue(); + $empty = $this->isEmptyFile($rawValue); + $required = $this->isRequired(); + $allowEmpty = $this->allowEmpty(); + $continueIfEmpty = $this->continueIfEmpty(); - if ($empty && $this->allowEmpty() && !$this->continueIfEmpty()) { + if ($empty && ! $required && ! $continueIfEmpty) { + return true; + } + + if ($empty && $required && $allowEmpty && ! $continueIfEmpty) { return true; } diff --git a/library/TorrentPier/Zend/InputFilter/Input.php b/library/TorrentPier/Zend/InputFilter/Input.php index 665af4218..fe2395bca 100644 --- a/library/TorrentPier/Zend/InputFilter/Input.php +++ b/library/TorrentPier/Zend/InputFilter/Input.php @@ -13,7 +13,9 @@ use Zend\Filter\FilterChain; use Zend\Validator\NotEmpty; use Zend\Validator\ValidatorChain; -class Input implements InputInterface, EmptyContextInterface +class Input implements + InputInterface, + EmptyContextInterface { /** * @var bool @@ -102,7 +104,7 @@ class Input implements InputInterface, EmptyContextInterface /** * @param bool $continueIfEmpty - * @return \Zend\InputFilter\Input + * @return Input */ public function setContinueIfEmpty($continueIfEmpty) { @@ -147,7 +149,6 @@ class Input implements InputInterface, EmptyContextInterface public function setRequired($required) { $this->required = (bool) $required; - $this->setAllowEmpty(!$required); return $this; } @@ -319,23 +320,31 @@ class Input implements InputInterface, EmptyContextInterface */ public function isValid($context = null) { - $value = $this->getValue(); - $empty = ($value === null || $value === '' || $value === array()); + $value = $this->getValue(); + $empty = ($value === null || $value === '' || $value === array()); + $required = $this->isRequired(); + $allowEmpty = $this->allowEmpty(); + $continueIfEmpty = $this->continueIfEmpty(); - if ($empty && $this->allowEmpty() && !$this->continueIfEmpty()) { + if ($empty && ! $required && ! $continueIfEmpty) { return true; } - // Empty value needs further validation if continueIfEmpty is set - // so don't inject NotEmpty validator which would always - // mark that as false - if (!$this->continueIfEmpty() && !$this->allowEmpty()) { + if ($empty && $required && $allowEmpty && ! $continueIfEmpty) { + return true; + } + + // At this point, we need to run validators. + // If we do not allow empty and the "continue if empty" flag are + // BOTH false, we inject the "not empty" validator into the chain, + // which adds that logic into the validation routine. + if (! $allowEmpty && ! $continueIfEmpty) { $this->injectNotEmptyValidator(); } - $validator = $this->getValidatorChain(); + $validator = $this->getValidatorChain(); $result = $validator->isValid($value, $context); - if (!$result && $this->hasFallback()) { + if (! $result && $this->hasFallback()) { $this->setValue($this->getFallbackValue()); $result = true; } diff --git a/library/TorrentPier/Zend/InputFilter/InputFilterPluginManager.php b/library/TorrentPier/Zend/InputFilter/InputFilterPluginManager.php index 562b7cf7a..bb5bccc3a 100644 --- a/library/TorrentPier/Zend/InputFilter/InputFilterPluginManager.php +++ b/library/TorrentPier/Zend/InputFilter/InputFilterPluginManager.php @@ -51,12 +51,12 @@ class InputFilterPluginManager extends AbstractPluginManager /** * Inject this and populate the factory with filter chain and validator chain * - * @param $inputfilter + * @param $inputFilter */ - public function populateFactory($inputfilter) + public function populateFactory($inputFilter) { - if ($inputfilter instanceof InputFilter) { - $factory = $inputfilter->getFactory(); + if ($inputFilter instanceof InputFilter) { + $factory = $inputFilter->getFactory(); $factory->setInputFilterManager($this); @@ -73,7 +73,7 @@ class InputFilterPluginManager extends AbstractPluginManager public function validatePlugin($plugin) { if ($plugin instanceof InputFilterInterface || $plugin instanceof InputInterface) { - // Hook to perform various initialization, when the inputfilter is not created through the factory + // Hook to perform various initialization, when the inputFilter is not created through the factory if ($plugin instanceof InitializableInterface) { $plugin->init(); } diff --git a/library/TorrentPier/Zend/InputFilter/ReplaceableInputInterface.php b/library/TorrentPier/Zend/InputFilter/ReplaceableInputInterface.php index 02e5c0950..9bf55190b 100644 --- a/library/TorrentPier/Zend/InputFilter/ReplaceableInputInterface.php +++ b/library/TorrentPier/Zend/InputFilter/ReplaceableInputInterface.php @@ -15,5 +15,10 @@ namespace Zend\InputFilter; */ interface ReplaceableInputInterface { + /** + * @param $input + * @param $name + * @return self + */ public function replace($input, $name); } diff --git a/library/TorrentPier/Zend/InputFilter/UnknownInputsCapableInterface.php b/library/TorrentPier/Zend/InputFilter/UnknownInputsCapableInterface.php index 0c34bc738..58156fe52 100644 --- a/library/TorrentPier/Zend/InputFilter/UnknownInputsCapableInterface.php +++ b/library/TorrentPier/Zend/InputFilter/UnknownInputsCapableInterface.php @@ -15,6 +15,19 @@ namespace Zend\InputFilter; */ interface UnknownInputsCapableInterface { + /** + * Is the data set has unknown input ? + * + * @throws Exception\RuntimeException + * @return bool + */ public function hasUnknown(); + + /** + * Return the unknown input + * + * @throws Exception\RuntimeException + * @return array + */ public function getUnknown(); } diff --git a/library/TorrentPier/Zend/InputFilter/composer.json b/library/TorrentPier/Zend/InputFilter/composer.json index ca9357d84..0615067ee 100644 --- a/library/TorrentPier/Zend/InputFilter/composer.json +++ b/library/TorrentPier/Zend/InputFilter/composer.json @@ -26,8 +26,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Json/Json.php b/library/TorrentPier/Zend/Json/Json.php index e8253df50..03159557e 100644 --- a/library/TorrentPier/Zend/Json/Json.php +++ b/library/TorrentPier/Zend/Json/Json.php @@ -333,7 +333,7 @@ class Json // If it is not a valid XML content, throw an exception. if (!$simpleXmlElementObject) { throw new RuntimeException('Function fromXml was called with an invalid XML formatted string.'); - } // End of if ($simpleXmlElementObject == null) + } // End of if ($simpleXmlElementObject === null) // Call the recursive function to convert the XML into a PHP array. $resultArray = static::_processXml($simpleXmlElementObject, $ignoreXmlAttributes); diff --git a/library/TorrentPier/Zend/Json/composer.json b/library/TorrentPier/Zend/Json/composer.json index 53abdcc2c..a2e2e250a 100644 --- a/library/TorrentPier/Zend/Json/composer.json +++ b/library/TorrentPier/Zend/Json/composer.json @@ -27,8 +27,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Ldap/Attribute.php b/library/TorrentPier/Zend/Ldap/Attribute.php index 80524c06a..6ee974c2f 100644 --- a/library/TorrentPier/Zend/Ldap/Attribute.php +++ b/library/TorrentPier/Zend/Ldap/Attribute.php @@ -197,7 +197,7 @@ class Attribute } else { return $return; } - } catch (Exception\InvalidArgumentException $e) { + } catch (Converter\Exception\InvalidArgumentException $e) { return $value; } } diff --git a/library/TorrentPier/Zend/Ldap/Converter/Converter.php b/library/TorrentPier/Zend/Ldap/Converter/Converter.php index e6ff940e8..5bf4a035c 100644 --- a/library/TorrentPier/Zend/Ldap/Converter/Converter.php +++ b/library/TorrentPier/Zend/Ldap/Converter/Converter.php @@ -72,7 +72,6 @@ class Converter * By setting the $type-parameter the conversion of a certain * type can be forced * - * @todo write more tests * * @param mixed $value The value to convert * @param int $type The conversion type to use @@ -340,7 +339,15 @@ class Converter . $time['offdir'] . str_pad($time['offsethours'], 2, '0', STR_PAD_LEFT) . str_pad($time['offsetminutes'], 2, '0', STR_PAD_LEFT); - $date = new DateTime($timestring); + try { + $date = new DateTime($timestring); + } catch (\Exception $e) { + throw new Exception\InvalidArgumentException( + 'Invalid date format found', + 0, + $e + ); + } if ($asUtc) { $date->setTimezone(new DateTimeZone('UTC')); } diff --git a/library/TorrentPier/Zend/Ldap/Dn.php b/library/TorrentPier/Zend/Ldap/Dn.php index 1b94e19e8..1b10e5a8a 100644 --- a/library/TorrentPier/Zend/Ldap/Dn.php +++ b/library/TorrentPier/Zend/Ldap/Dn.php @@ -553,9 +553,9 @@ class Dn implements ArrayAccess } $ret = array(); for ($i = 0, $count = count($k); $i < $count; $i++) { - if (is_array($k[$i]) && is_array($v[$i]) && (count($k[$i]) === count($v[$i]))) { + if (is_array($k[$i]) && is_array($v[$i]) && (($keyCount = count($k[$i])) === count($v[$i]))) { $multi = array(); - for ($j = 0; $j < count($k[$i]); $j++) { + for ($j = 0; $j < $keyCount; $j++) { $key = $k[$i][$j]; $val = $v[$i][$j]; $multi[$key] = $val; diff --git a/library/TorrentPier/Zend/Ldap/composer.json b/library/TorrentPier/Zend/Ldap/composer.json index bf527af6e..ef753a780 100644 --- a/library/TorrentPier/Zend/Ldap/composer.json +++ b/library/TorrentPier/Zend/Ldap/composer.json @@ -25,8 +25,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Loader/AutoloaderFactory.php b/library/TorrentPier/Zend/Loader/AutoloaderFactory.php index 1ade337a2..a786c494a 100644 --- a/library/TorrentPier/Zend/Loader/AutoloaderFactory.php +++ b/library/TorrentPier/Zend/Loader/AutoloaderFactory.php @@ -22,7 +22,7 @@ abstract class AutoloaderFactory /** * @var array All autoloaders registered using the factory */ - protected static $loaders = []; + protected static $loaders = array(); /** * @var StandardAutoloader StandardAutoloader instance for resolving @@ -71,7 +71,7 @@ abstract class AutoloaderFactory if (!is_array($options) && !($options instanceof Traversable)) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException( + throw new Exception\InvalidArgumentException( 'Options provided must be an array or Traversable' ); } @@ -81,14 +81,14 @@ abstract class AutoloaderFactory $autoloader = static::getStandardAutoloader(); if (!class_exists($class) && !$autoloader->autoload($class)) { require_once 'Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException( + throw new Exception\InvalidArgumentException( sprintf('Autoloader class "%s" not loaded', $class) ); } if (!is_subclass_of($class, 'Zend\Loader\SplAutoloader')) { require_once 'Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException( + throw new Exception\InvalidArgumentException( sprintf('Autoloader class %s must implement Zend\\Loader\\SplAutoloader', $class) ); } @@ -129,7 +129,7 @@ abstract class AutoloaderFactory { if (!isset(static::$loaders[$class])) { require_once 'Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException(sprintf('Autoloader class "%s" not loaded', $class)); + throw new Exception\InvalidArgumentException(sprintf('Autoloader class "%s" not loaded', $class)); } return static::$loaders[$class]; } @@ -143,7 +143,7 @@ abstract class AutoloaderFactory public static function unregisterAutoloaders() { foreach (static::getRegisteredAutoloaders() as $class => $autoloader) { - spl_autoload_unregister([$autoloader, 'autoload']); + spl_autoload_unregister(array($autoloader, 'autoload')); unset(static::$loaders[$class]); } } @@ -161,7 +161,7 @@ abstract class AutoloaderFactory } $autoloader = static::$loaders[$autoloaderClass]; - spl_autoload_unregister([$autoloader, 'autoload']); + spl_autoload_unregister(array($autoloader, 'autoload')); unset(static::$loaders[$autoloaderClass]); return true; } @@ -185,9 +185,9 @@ abstract class AutoloaderFactory if (!class_exists(static::STANDARD_AUTOLOADER)) { // Extract the filename from the classname $stdAutoloader = substr(strrchr(static::STANDARD_AUTOLOADER, '\\'), 1); - require_once __DIR__ . "/AutoloaderFactory.php"; - } - $loader = new StandardAutoloader(); + require_once __DIR__ . "/$stdAutoloader.php"; + } + $loader = new StandardAutoloader(); static::$standardAutoloader = $loader; return static::$standardAutoloader; } diff --git a/library/TorrentPier/Zend/Loader/ClassMapAutoloader.php b/library/TorrentPier/Zend/Loader/ClassMapAutoloader.php index 2c5a328e5..a50e1fc0a 100644 --- a/library/TorrentPier/Zend/Loader/ClassMapAutoloader.php +++ b/library/TorrentPier/Zend/Loader/ClassMapAutoloader.php @@ -25,13 +25,13 @@ class ClassMapAutoloader implements SplAutoloader * Registry of map files that have already been loaded * @var array */ - protected $mapsLoaded = []; + protected $mapsLoaded = array(); /** * Class name/filename map * @var array */ - protected $map = []; + protected $map = array(); /** * Constructor @@ -85,7 +85,7 @@ class ClassMapAutoloader implements SplAutoloader if (!is_array($map)) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\InvalidArgumentException(sprintf( 'Map file provided does not return a map. Map file: "%s"', (isset($location) && is_string($location) ? $location : 'unexpected type: ' . gettype($map)) )); @@ -111,7 +111,7 @@ class ClassMapAutoloader implements SplAutoloader { if (!is_array($locations) && !($locations instanceof Traversable)) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException('Map list must be an array or implement Traversable'); + throw new Exception\InvalidArgumentException('Map list must be an array or implement Traversable'); } foreach ($locations as $location) { $this->registerAutoloadMap($location); @@ -150,7 +150,7 @@ class ClassMapAutoloader implements SplAutoloader */ public function register() { - spl_autoload_register([$this, 'autoload'], true, true); + spl_autoload_register(array($this, 'autoload'), true, true); } /** @@ -168,7 +168,7 @@ class ClassMapAutoloader implements SplAutoloader { if (!file_exists($location)) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\InvalidArgumentException(sprintf( 'Map file provided does not exist. Map file: "%s"', (is_string($location) ? $location : 'unexpected type: ' . gettype($location)) )); @@ -202,7 +202,7 @@ class ClassMapAutoloader implements SplAutoloader } $prefixLength = 5 + strlen($match[1]); - $parts = explode('/', str_replace(['/', '\\'], '/', substr($path, $prefixLength))); + $parts = explode('/', str_replace(array('/', '\\'), '/', substr($path, $prefixLength))); $parts = array_values(array_filter($parts, function ($p) { return ($p !== '' && $p !== '.'); })); diff --git a/library/TorrentPier/Zend/Loader/ModuleAutoloader.php b/library/TorrentPier/Zend/Loader/ModuleAutoloader.php index 6b49ffd24..e867aae84 100644 --- a/library/TorrentPier/Zend/Loader/ModuleAutoloader.php +++ b/library/TorrentPier/Zend/Loader/ModuleAutoloader.php @@ -23,17 +23,17 @@ class ModuleAutoloader implements SplAutoloader /** * @var array An array of module paths to scan */ - protected $paths = []; + protected $paths = array(); /** * @var array An array of modulename => path */ - protected $explicitPaths = []; + protected $explicitPaths = array(); /** * @var array An array of namespaceName => namespacePath */ - protected $namespacedPaths = []; + protected $namespacedPaths = array(); /** * @var string Will contain the absolute phar:// path to the executable when packaged as phar file @@ -43,12 +43,12 @@ class ModuleAutoloader implements SplAutoloader /** * @var array An array of supported phar extensions (filled on constructor) */ - protected $pharExtensions = []; + protected $pharExtensions = array(); /** * @var array An array of module classes to their containing files */ - protected $moduleClassMap = []; + protected $moduleClassMap = array(); /** * Constructor @@ -61,11 +61,11 @@ class ModuleAutoloader implements SplAutoloader { if (extension_loaded('phar')) { $this->pharBasePath = Phar::running(true); - $this->pharExtensions = [ + $this->pharExtensions = array( 'phar', 'phar.tar', 'tar', - ]; + ); // ext/zlib enabled -> phar can read gzip & zip compressed files if (extension_loaded('zlib')) { @@ -325,7 +325,7 @@ class ModuleAutoloader implements SplAutoloader */ public function register() { - spl_autoload_register([$this, 'autoload']); + spl_autoload_register(array($this, 'autoload')); } /** @@ -335,7 +335,7 @@ class ModuleAutoloader implements SplAutoloader */ public function unregister() { - spl_autoload_unregister([$this, 'autoload']); + spl_autoload_unregister(array($this, 'autoload')); } /** @@ -349,7 +349,7 @@ class ModuleAutoloader implements SplAutoloader { if (!is_array($paths) && !$paths instanceof Traversable) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException( + throw new Exception\InvalidArgumentException( 'Parameter to \\Zend\\Loader\\ModuleAutoloader\'s ' . 'registerPaths method must be an array or ' . 'implement the Traversable interface' @@ -379,13 +379,13 @@ class ModuleAutoloader implements SplAutoloader { if (!is_string($path)) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\InvalidArgumentException(sprintf( 'Invalid path provided; must be a string, received %s', gettype($path) )); } if ($moduleName) { - if (in_array(substr($moduleName, -2), ['\\*', '\\%'])) { + if (in_array(substr($moduleName, -2), array('\\*', '\\%'))) { $this->namespacedPaths[substr($moduleName, 0, -2)] = static::normalizePath($path); } else { $this->explicitPaths[$moduleName] = static::normalizePath($path); diff --git a/library/TorrentPier/Zend/Loader/StandardAutoloader.php b/library/TorrentPier/Zend/Loader/StandardAutoloader.php index 334bccafd..2d744a88e 100644 --- a/library/TorrentPier/Zend/Loader/StandardAutoloader.php +++ b/library/TorrentPier/Zend/Loader/StandardAutoloader.php @@ -31,12 +31,12 @@ class StandardAutoloader implements SplAutoloader /** * @var array Namespace/directory pairs to search; ZF library added by default */ - protected $namespaces = []; + protected $namespaces = array(); /** * @var array Prefix/directory pairs to search */ - protected $prefixes = []; + protected $prefixes = array(); /** * @var bool Whether or not the autoloader should also act as a fallback autoloader @@ -81,7 +81,7 @@ class StandardAutoloader implements SplAutoloader { if (!is_array($options) && !($options instanceof \Traversable)) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException('Options must be either an array or Traversable'); + throw new Exception\InvalidArgumentException('Options must be either an array or Traversable'); } foreach ($options as $type => $pairs) { @@ -159,7 +159,7 @@ class StandardAutoloader implements SplAutoloader { if (!is_array($namespaces) && !$namespaces instanceof \Traversable) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException('Namespace pairs must be either an array or Traversable'); + throw new Exception\InvalidArgumentException('Namespace pairs must be either an array or Traversable'); } foreach ($namespaces as $namespace => $directory) { @@ -193,7 +193,7 @@ class StandardAutoloader implements SplAutoloader { if (!is_array($prefixes) && !$prefixes instanceof \Traversable) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException('Prefix pairs must be either an array or Traversable'); + throw new Exception\InvalidArgumentException('Prefix pairs must be either an array or Traversable'); } foreach ($prefixes as $prefix => $directory) { @@ -240,7 +240,7 @@ class StandardAutoloader implements SplAutoloader */ public function register() { - spl_autoload_register([$this, 'autoload']); + spl_autoload_register(array($this, 'autoload')); } /** @@ -254,7 +254,7 @@ class StandardAutoloader implements SplAutoloader { // $class may contain a namespace portion, in which case we need // to preserve any underscores in that portion. - $matches = []; + $matches = array(); preg_match('/(?P.+\\\)?(?P[^\\\]+$)/', $class, $matches); $class = (isset($matches['class'])) ? $matches['class'] : ''; @@ -276,9 +276,9 @@ class StandardAutoloader implements SplAutoloader */ protected function loadClass($class, $type) { - if (!in_array($type, [self::LOAD_NS, self::LOAD_PREFIX, self::ACT_AS_FALLBACK])) { + if (!in_array($type, array(self::LOAD_NS, self::LOAD_PREFIX, self::ACT_AS_FALLBACK))) { require_once __DIR__ . '/Exception/InvalidArgumentException.php'; - throw new Exception\InvalidArgumentException(); + throw new Exception\InvalidArgumentException(); } // Fallback autoloading @@ -317,7 +317,7 @@ class StandardAutoloader implements SplAutoloader protected function normalizeDirectory($directory) { $last = $directory[strlen($directory) - 1]; - if (in_array($last, ['/', '\\'])) { + if (in_array($last, array('/', '\\'))) { $directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR; return $directory; } diff --git a/library/TorrentPier/Zend/Loader/composer.json b/library/TorrentPier/Zend/Loader/composer.json index e34b4f9fb..53ab6b547 100644 --- a/library/TorrentPier/Zend/Loader/composer.json +++ b/library/TorrentPier/Zend/Loader/composer.json @@ -17,8 +17,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Log/composer.json b/library/TorrentPier/Zend/Log/composer.json index ec27f288e..87f3c25fa 100644 --- a/library/TorrentPier/Zend/Log/composer.json +++ b/library/TorrentPier/Zend/Log/composer.json @@ -36,8 +36,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Mail/Address.php b/library/TorrentPier/Zend/Mail/Address.php index e34c85069..e97878d59 100644 --- a/library/TorrentPier/Zend/Mail/Address.php +++ b/library/TorrentPier/Zend/Mail/Address.php @@ -9,6 +9,9 @@ namespace Zend\Mail; +use Zend\Validator\EmailAddress as EmailAddressValidator; +use Zend\Validator\Hostname; + class Address implements Address\AddressInterface { protected $email; @@ -24,15 +27,33 @@ class Address implements Address\AddressInterface */ public function __construct($email, $name = null) { - if (!is_string($email)) { - throw new Exception\InvalidArgumentException('Email must be a string'); + $emailAddressValidator = new EmailAddressValidator(Hostname::ALLOW_LOCAL); + if (! is_string($email) || empty($email)) { + throw new Exception\InvalidArgumentException('Email must be a valid email address'); } - if (null !== $name && !is_string($name)) { - throw new Exception\InvalidArgumentException('Name must be a string'); + + if (preg_match("/[\r\n]/", $email)) { + throw new Exception\InvalidArgumentException('CRLF injection detected'); + } + + if (! $emailAddressValidator->isValid($email)) { + $invalidMessages = $emailAddressValidator->getMessages(); + throw new Exception\InvalidArgumentException(array_shift($invalidMessages)); + } + + if (null !== $name) { + if (! is_string($name)) { + throw new Exception\InvalidArgumentException('Name must be a string'); + } + + if (preg_match("/[\r\n]/", $name)) { + throw new Exception\InvalidArgumentException('CRLF injection detected'); + } + + $this->name = $name; } $this->email = $email; - $this->name = $name; } /** @@ -68,7 +89,6 @@ class Address implements Address\AddressInterface return $string; } - $string = $name . ' ' . $string; - return $string; + return $name . ' ' . $string; } } diff --git a/library/TorrentPier/Zend/Mail/Header/AbstractAddressList.php b/library/TorrentPier/Zend/Mail/Header/AbstractAddressList.php index b76d04a80..e7db7240b 100644 --- a/library/TorrentPier/Zend/Mail/Header/AbstractAddressList.php +++ b/library/TorrentPier/Zend/Mail/Header/AbstractAddressList.php @@ -41,9 +41,10 @@ abstract class AbstractAddressList implements HeaderInterface public static function fromString($headerLine) { - $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); - // split into name/value - list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($decodedLine); + list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine); + $decodedValue = HeaderWrap::mimeDecodeValue($fieldValue); + $wasEncoded = ($decodedValue !== $fieldValue); + $fieldValue = $decodedValue; if (strtolower($fieldName) !== static::$type) { throw new Exception\InvalidArgumentException(sprintf( @@ -52,7 +53,7 @@ abstract class AbstractAddressList implements HeaderInterface )); } $header = new static(); - if ($decodedLine != $headerLine) { + if ($wasEncoded) { $header->setEncoding('UTF-8'); } // split value on "," @@ -81,22 +82,33 @@ abstract class AbstractAddressList implements HeaderInterface { $emails = array(); $encoding = $this->getEncoding(); + foreach ($this->getAddressList() as $address) { $email = $address->getEmail(); $name = $address->getName(); + if (empty($name)) { $emails[] = $email; - } else { - if (false !== strstr($name, ',')) { - $name = sprintf('"%s"', $name); - } + continue; + } - if ($format == HeaderInterface::FORMAT_ENCODED - && 'ASCII' !== $encoding - ) { - $name = HeaderWrap::mimeEncodeValue($name, $encoding); - } - $emails[] = sprintf('%s <%s>', $name, $email); + if (false !== strstr($name, ',')) { + $name = sprintf('"%s"', $name); + } + + if ($format === HeaderInterface::FORMAT_ENCODED + && 'ASCII' !== $encoding + ) { + $name = HeaderWrap::mimeEncodeValue($name, $encoding); + } + + $emails[] = sprintf('%s <%s>', $name, $email); + } + + // Ensure the values are valid before sending them. + if ($format !== HeaderInterface::FORMAT_RAW) { + foreach ($emails as $email) { + HeaderValue::assertValid($email); } } diff --git a/library/TorrentPier/Zend/Mail/Header/ContentTransferEncoding.php b/library/TorrentPier/Zend/Mail/Header/ContentTransferEncoding.php index c97bfb459..86233a45c 100644 --- a/library/TorrentPier/Zend/Mail/Header/ContentTransferEncoding.php +++ b/library/TorrentPier/Zend/Mail/Header/ContentTransferEncoding.php @@ -40,8 +40,8 @@ class ContentTransferEncoding implements HeaderInterface public static function fromString($headerLine) { - $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'content-transfer-encoding') { diff --git a/library/TorrentPier/Zend/Mail/Header/ContentType.php b/library/TorrentPier/Zend/Mail/Header/ContentType.php index 7d0788290..32349cb38 100644 --- a/library/TorrentPier/Zend/Mail/Header/ContentType.php +++ b/library/TorrentPier/Zend/Mail/Header/ContentType.php @@ -25,32 +25,28 @@ class ContentType implements HeaderInterface public static function fromString($headerLine) { - $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'content-type') { throw new Exception\InvalidArgumentException('Invalid header line for Content-Type string'); } - $value = str_replace(Headers::FOLDING, " ", $value); + $value = str_replace(Headers::FOLDING, ' ', $value); $values = preg_split('#\s*;\s*#', $value); + $type = array_shift($values); - - //Remove empty values - $values = array_filter($values); - $header = new static(); $header->setType($type); + // Remove empty values $values = array_filter($values); - if (count($values)) { - foreach ($values as $keyValuePair) { - list($key, $value) = explode('=', $keyValuePair, 2); - $value = trim($value, "'\" \t\n\r\0\x0B"); - $header->addParameter($key, $value); - } + foreach ($values as $keyValuePair) { + list($key, $value) = explode('=', $keyValuePair, 2); + $value = trim($value, "'\" \t\n\r\0\x0B"); + $header->addParameter($key, $value); } return $header; @@ -128,11 +124,22 @@ class ContentType implements HeaderInterface * @param string $name * @param string $value * @return ContentType + * @throws Exception\InvalidArgumentException for parameter names that do not follow RFC 2822 + * @throws Exception\InvalidArgumentException for parameter values that do not follow RFC 2822 */ public function addParameter($name, $value) { - $name = strtolower($name); - $this->parameters[$name] = (string) $value; + $name = strtolower($name); + $value = (string) $value; + + if (! HeaderValue::isValid($name)) { + throw new Exception\InvalidArgumentException('Invalid content-type parameter name detected'); + } + if (! HeaderValue::isValid($value)) { + throw new Exception\InvalidArgumentException('Invalid content-type parameter value detected'); + } + + $this->parameters[$name] = $value; return $this; } diff --git a/library/TorrentPier/Zend/Mail/Header/Date.php b/library/TorrentPier/Zend/Mail/Header/Date.php index fdf5941bd..9b6595465 100644 --- a/library/TorrentPier/Zend/Mail/Header/Date.php +++ b/library/TorrentPier/Zend/Mail/Header/Date.php @@ -22,6 +22,7 @@ class Date implements HeaderInterface public static function fromString($headerLine) { list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'date') { @@ -35,6 +36,9 @@ class Date implements HeaderInterface public function __construct($value) { + if (! HeaderValue::isValid($value)) { + throw new Exception\InvalidArgumentException('Invalid Date header value detected'); + } $this->value = $value; } diff --git a/library/TorrentPier/Zend/Mail/Header/GenericHeader.php b/library/TorrentPier/Zend/Mail/Header/GenericHeader.php index 05989179a..20619a83a 100644 --- a/library/TorrentPier/Zend/Mail/Header/GenericHeader.php +++ b/library/TorrentPier/Zend/Mail/Header/GenericHeader.php @@ -9,6 +9,8 @@ namespace Zend\Mail\Header; +use Zend\Mime\Mime; + class GenericHeader implements HeaderInterface, UnstructuredInterface { /** @@ -24,18 +26,16 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface /** * Header encoding * - * @var string + * @var null|string */ - protected $encoding = 'ASCII'; + protected $encoding; public static function fromString($headerLine) { - $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); - list($name, $value) = GenericHeader::splitHeaderLine($decodedLine); + list($name, $value) = self::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); $header = new static($name, $value); - if ($decodedLine != $headerLine) { - $header->setEncoding('UTF-8'); - } + return $header; } @@ -53,6 +53,15 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface throw new Exception\InvalidArgumentException('Header must match with the format "name:value"'); } + if (! HeaderName::isValid($parts[0])) { + throw new Exception\InvalidArgumentException('Invalid header name detected'); + } + + if (! HeaderValue::isValid($parts[1])) { + throw new Exception\InvalidArgumentException('Invalid header value detected'); + } + + $parts[0] = $parts[0]; $parts[1] = ltrim($parts[1]); return $parts; @@ -79,8 +88,8 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface * Set header name * * @param string $fieldName - * @throws Exception\InvalidArgumentException * @return GenericHeader + * @throws Exception\InvalidArgumentException; */ public function setFieldName($fieldName) { @@ -91,8 +100,7 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface // Pre-filter to normalize valid characters, change underscore to dash $fieldName = str_replace(' ', '-', ucwords(str_replace(array('_', '-'), ' ', $fieldName))); - // Validate what we have - if (!preg_match('/^[\x21-\x39\x3B-\x7E]*$/', $fieldName)) { + if (! HeaderName::isValid($fieldName)) { throw new Exception\InvalidArgumentException( 'Header name must be composed of printable US-ASCII characters, except colon.' ); @@ -112,16 +120,21 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface * * @param string $fieldValue * @return GenericHeader + * @throws Exception\InvalidArgumentException; */ public function setFieldValue($fieldValue) { $fieldValue = (string) $fieldValue; - if (empty($fieldValue) || preg_match('/^\s+$/', $fieldValue)) { - $fieldValue = ''; + if (! HeaderWrap::canBeEncoded($fieldValue)) { + throw new Exception\InvalidArgumentException( + 'Header value must be composed of printable US-ASCII characters and valid folding sequences.' + ); } $this->fieldValue = $fieldValue; + $this->encoding = null; + return $this; } @@ -142,12 +155,19 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface public function getEncoding() { + if (! $this->encoding) { + $this->encoding = Mime::isPrintable($this->fieldValue) ? 'ASCII' : 'UTF-8'; + } + return $this->encoding; } public function toString() { - $name = $this->getFieldName(); + $name = $this->getFieldName(); + if (empty($name)) { + throw new Exception\RuntimeException('Header name is not set, use setFieldName()'); + } $value = $this->getFieldValue(HeaderInterface::FORMAT_ENCODED); return $name . ': ' . $value; diff --git a/library/TorrentPier/Zend/Mail/Header/GenericMultiHeader.php b/library/TorrentPier/Zend/Mail/Header/GenericMultiHeader.php index d0b0d204f..122c4c183 100644 --- a/library/TorrentPier/Zend/Mail/Header/GenericMultiHeader.php +++ b/library/TorrentPier/Zend/Mail/Header/GenericMultiHeader.php @@ -16,24 +16,18 @@ class GenericMultiHeader extends GenericHeader implements MultipleHeadersInterfa { public static function fromString($headerLine) { - $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); - list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($decodedLine); + list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine); + $fieldValue = HeaderWrap::mimeDecodeValue($fieldValue); if (strpos($fieldValue, ',')) { $headers = array(); - $encoding = ($decodedLine != $headerLine) ? 'UTF-8' : 'ASCII'; foreach (explode(',', $fieldValue) as $multiValue) { - $header = new static($fieldName, $multiValue); - $headers[] = $header->setEncoding($encoding); + $headers[] = new static($fieldName, $multiValue); } return $headers; - } else { - $header = new static($fieldName, $fieldValue); - if ($decodedLine != $headerLine) { - $header->setEncoding('UTF-8'); - } - return $header; } + + return new static($fieldName, $fieldValue); } /** @@ -45,16 +39,18 @@ class GenericMultiHeader extends GenericHeader implements MultipleHeadersInterfa */ public function toStringMultipleHeaders(array $headers) { - $name = $this->getFieldName(); + $name = $this->getFieldName(); $values = array($this->getFieldValue(HeaderInterface::FORMAT_ENCODED)); + foreach ($headers as $header) { - if (!$header instanceof static) { + if (! $header instanceof static) { throw new Exception\InvalidArgumentException( 'This method toStringMultipleHeaders was expecting an array of headers of the same type' ); } $values[] = $header->getFieldValue(HeaderInterface::FORMAT_ENCODED); } + return $name . ': ' . implode(',', $values); } } diff --git a/library/TorrentPier/Zend/Mail/Header/HeaderName.php b/library/TorrentPier/Zend/Mail/Header/HeaderName.php new file mode 100644 index 000000000..46eefdd5d --- /dev/null +++ b/library/TorrentPier/Zend/Mail/Header/HeaderName.php @@ -0,0 +1,74 @@ + 32 && $ord < 127 && $ord !== 58) { + $result .= $name[$i]; + } + } + return $result; + } + + /** + * Determine if the header name contains any invalid characters. + * + * @param string $name + * @return bool + */ + public static function isValid($name) + { + $tot = strlen($name); + for ($i = 0; $i < $tot; $i += 1) { + $ord = ord($name[$i]); + if ($ord < 33 || $ord > 126 || $ord === 58) { + return false; + } + } + return true; + } + + /** + * Assert that the header name is valid. + * + * Raises an exception if invalid. + * + * @param string $name + * @throws Exception\RuntimeException + * @return void + */ + public static function assertValid($name) + { + if (! self::isValid($name)) { + throw new Exception\RuntimeException('Invalid header name detected'); + } + } +} diff --git a/library/TorrentPier/Zend/Mail/Header/HeaderValue.php b/library/TorrentPier/Zend/Mail/Header/HeaderValue.php new file mode 100644 index 000000000..7282ccac4 --- /dev/null +++ b/library/TorrentPier/Zend/Mail/Header/HeaderValue.php @@ -0,0 +1,118 @@ + 126) + && $ord !== 13 + ) { + continue; + } + + if ($ord === 13) { + if ($i + 2 >= $tot) { + continue; + } + + $lf = ord($value[$i + 1]); + $sp = ord($value[$i + 2]); + + if ($lf !== 10 || $sp !== 32) { + continue; + } + + $result .= "\r\n "; + $i += 2; + continue; + } + + $result .= $value[$i]; + } + + return $result; + } + + /** + * Determine if the header value contains any invalid characters. + * + * @see http://www.rfc-base.org/txt/rfc-2822.txt (section 2.2) + * @param string $value + * @return bool + */ + public static function isValid($value) + { + $tot = strlen($value); + for ($i = 0; $i < $tot; $i += 1) { + $ord = ord($value[$i]); + if (($ord < 32 || $ord > 126) + && $ord !== 13 + ) { + return false; + } + + if ($ord === 13) { + if ($i + 2 >= $tot) { + return false; + } + + $lf = ord($value[$i + 1]); + $sp = ord($value[$i + 2]); + + if ($lf !== 10 || $sp !== 32) { + return false; + } + + $i += 2; + } + } + + return true; + } + + /** + * Assert that the header value is valid. + * + * Raises an exception if invalid. + * + * @param string $value + * @throws Exception\RuntimeException + * @return void + */ + public static function assertValid($value) + { + if (! self::isValid($value)) { + throw new Exception\RuntimeException('Invalid header value detected'); + } + } +} diff --git a/library/TorrentPier/Zend/Mail/Header/HeaderWrap.php b/library/TorrentPier/Zend/Mail/Header/HeaderWrap.php index 24b72ce11..df532edc5 100644 --- a/library/TorrentPier/Zend/Mail/Header/HeaderWrap.php +++ b/library/TorrentPier/Zend/Mail/Header/HeaderWrap.php @@ -92,4 +92,32 @@ abstract class HeaderWrap { return Mime::encodeQuotedPrintableHeader($value, $encoding, $lineLength, Headers::EOL); } + + /** + * MIME-decode a value + * + * Performs quoted-printable decoding on a value. + * + * @param string $value + * @return string Returns the mime encode value without the last line ending + */ + public static function mimeDecodeValue($value) + { + $decodedValue = iconv_mime_decode($value, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); + + return $decodedValue; + } + + /** + * Test if is possible apply MIME-encoding + * + * @param string $value + * @return bool + */ + public static function canBeEncoded($value) + { + $encoded = iconv_mime_encode('x-test', $value, array('scheme' => 'Q')); + + return (false !== $encoded); + } } diff --git a/library/TorrentPier/Zend/Mail/Header/MessageId.php b/library/TorrentPier/Zend/Mail/Header/MessageId.php index 80c56e0bd..850757ea1 100644 --- a/library/TorrentPier/Zend/Mail/Header/MessageId.php +++ b/library/TorrentPier/Zend/Mail/Header/MessageId.php @@ -19,6 +19,7 @@ class MessageId implements HeaderInterface public static function fromString($headerLine) { list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'message-id') { @@ -69,8 +70,13 @@ class MessageId implements HeaderInterface $id = $this->createMessageId(); } - $id = sprintf('<%s>', $id); - $this->messageId = $id; + if (! HeaderValue::isValid($id) + || preg_match("/[\r\n]/", $id) + ) { + throw new Exception\InvalidArgumentException('Invalid ID detected'); + } + + $this->messageId = sprintf('<%s>', $id); return $this; } diff --git a/library/TorrentPier/Zend/Mail/Header/MimeVersion.php b/library/TorrentPier/Zend/Mail/Header/MimeVersion.php index 80da4cf38..41c5996ef 100644 --- a/library/TorrentPier/Zend/Mail/Header/MimeVersion.php +++ b/library/TorrentPier/Zend/Mail/Header/MimeVersion.php @@ -19,6 +19,7 @@ class MimeVersion implements HeaderInterface public static function fromString($headerLine) { list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'mime-version') { @@ -68,6 +69,9 @@ class MimeVersion implements HeaderInterface */ public function setVersion($version) { + if (! preg_match('/^[1-9]\d*\.\d+$/', $version)) { + throw new Exception\InvalidArgumentException('Invalid MIME-Version value detected'); + } $this->version = $version; return $this; } diff --git a/library/TorrentPier/Zend/Mail/Header/Received.php b/library/TorrentPier/Zend/Mail/Header/Received.php index 904e30763..b0a541971 100644 --- a/library/TorrentPier/Zend/Mail/Header/Received.php +++ b/library/TorrentPier/Zend/Mail/Header/Received.php @@ -24,6 +24,7 @@ class Received implements HeaderInterface, MultipleHeadersInterface public static function fromString($headerLine) { list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'received') { @@ -37,6 +38,9 @@ class Received implements HeaderInterface, MultipleHeadersInterface public function __construct($value = '') { + if (! HeaderValue::isValid($value)) { + throw new Exception\InvalidArgumentException('Invalid Received value provided'); + } $this->value = $value; } @@ -77,7 +81,7 @@ class Received implements HeaderInterface, MultipleHeadersInterface { $strings = array($this->toString()); foreach ($headers as $header) { - if (!$header instanceof Received) { + if (! $header instanceof Received) { throw new Exception\RuntimeException( 'The Received multiple header implementation can only accept an array of Received headers' ); diff --git a/library/TorrentPier/Zend/Mail/Header/Sender.php b/library/TorrentPier/Zend/Mail/Header/Sender.php index 9c08d3b67..3a70405ca 100644 --- a/library/TorrentPier/Zend/Mail/Header/Sender.php +++ b/library/TorrentPier/Zend/Mail/Header/Sender.php @@ -10,7 +10,14 @@ namespace Zend\Mail\Header; use Zend\Mail; +use Zend\Mime\Mime; +/** + * Sender header class methods. + * + * @see https://tools.ietf.org/html/rfc2822 RFC 2822 + * @see https://tools.ietf.org/html/rfc2047 RFC 2047 + */ class Sender implements HeaderInterface { /** @@ -21,36 +28,35 @@ class Sender implements HeaderInterface /** * Header encoding * - * @var string + * @var null|string */ - protected $encoding = 'ASCII'; + protected $encoding; public static function fromString($headerLine) { - $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); - list($name, $value) = GenericHeader::splitHeaderLine($decodedLine); + list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'sender') { throw new Exception\InvalidArgumentException('Invalid header line for Sender string'); } - $header = new static(); - if ($decodedLine != $headerLine) { - $header->setEncoding('UTF-8'); - } + $header = new static(); + $senderName = ''; + $senderEmail = ''; // Check for address, and set if found if (preg_match('/^(?P.*?)<(?P[^>]+)>$/', $value, $matches)) { - $name = $matches['name']; - if (empty($name)) { - $name = null; - } else { - $name = iconv_mime_decode($name, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); + $senderName = trim($matches['name']); + if (empty($senderName)) { + $senderName = null; } - $header->setAddress($matches['email'], $name); + $senderEmail = $matches['email']; } + $header->setAddress($senderEmail, $senderName); + return $header; } @@ -61,21 +67,23 @@ class Sender implements HeaderInterface public function getFieldValue($format = HeaderInterface::FORMAT_RAW) { - if (!$this->address instanceof Mail\Address\AddressInterface) { + if (! $this->address instanceof Mail\Address\AddressInterface) { return ''; } $email = sprintf('<%s>', $this->address->getEmail()); $name = $this->address->getName(); + if (!empty($name)) { - $encoding = $this->getEncoding(); - if ($format == HeaderInterface::FORMAT_ENCODED - && 'ASCII' !== $encoding - ) { - $name = HeaderWrap::mimeEncodeValue($name, $encoding); + if ($format == HeaderInterface::FORMAT_ENCODED) { + $encoding = $this->getEncoding(); + if ('ASCII' !== $encoding) { + $name = HeaderWrap::mimeEncodeValue($name, $encoding); + } } $email = sprintf('%s %s', $name, $email); } + return $email; } @@ -87,6 +95,12 @@ class Sender implements HeaderInterface public function getEncoding() { + if (! $this->encoding) { + $this->encoding = Mime::isPrintable($this->getFieldValue(HeaderInterface::FORMAT_RAW)) + ? 'ASCII' + : 'UTF-8'; + } + return $this->encoding; } diff --git a/library/TorrentPier/Zend/Mail/Header/Subject.php b/library/TorrentPier/Zend/Mail/Header/Subject.php index a4858c2f3..4eb444348 100644 --- a/library/TorrentPier/Zend/Mail/Header/Subject.php +++ b/library/TorrentPier/Zend/Mail/Header/Subject.php @@ -9,6 +9,14 @@ namespace Zend\Mail\Header; +use Zend\Mime\Mime; + +/** + * Subject header class methods. + * + * @see https://tools.ietf.org/html/rfc2822 RFC 2822 + * @see https://tools.ietf.org/html/rfc2047 RFC 2047 + */ class Subject implements UnstructuredInterface { /** @@ -19,14 +27,14 @@ class Subject implements UnstructuredInterface /** * Header encoding * - * @var string + * @var null|string */ - protected $encoding = 'ASCII'; + protected $encoding; public static function fromString($headerLine) { - $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8'); - list($name, $value) = GenericHeader::splitHeaderLine($decodedLine); + list($name, $value) = GenericHeader::splitHeaderLine($headerLine); + $value = HeaderWrap::mimeDecodeValue($value); // check to ensure proper header type for this factory if (strtolower($name) !== 'subject') { @@ -34,9 +42,6 @@ class Subject implements UnstructuredInterface } $header = new static(); - if ($decodedLine != $headerLine) { - $header->setEncoding('UTF-8'); - } $header->setSubject($value); return $header; @@ -64,12 +69,26 @@ class Subject implements UnstructuredInterface public function getEncoding() { + if (! $this->encoding) { + $this->encoding = Mime::isPrintable($this->subject) ? 'ASCII' : 'UTF-8'; + } + return $this->encoding; } public function setSubject($subject) { - $this->subject = (string) $subject; + $subject = (string) $subject; + + if (! HeaderWrap::canBeEncoded($subject)) { + throw new Exception\InvalidArgumentException( + 'Subject value must be composed of printable US-ASCII or UTF-8 characters.' + ); + } + + $this->subject = $subject; + $this->encoding = null; + return $this; } diff --git a/library/TorrentPier/Zend/Mail/Headers.php b/library/TorrentPier/Zend/Mail/Headers.php index e5b8ad495..3ceb10be8 100644 --- a/library/TorrentPier/Zend/Mail/Headers.php +++ b/library/TorrentPier/Zend/Mail/Headers.php @@ -66,9 +66,28 @@ class Headers implements Countable, Iterator { $headers = new static(); $currentLine = ''; + $emptyLine = 0; // iterate the header lines, some might be continuations - foreach (explode($EOL, $string) as $line) { + $lines = explode($EOL, $string); + $total = count($lines); + for ($i = 0; $i < $total; $i += 1) { + $line = $lines[$i]; + + // Empty line indicates end of headers + // EXCEPT if there are more lines, in which case, there's a possible error condition + if (preg_match('/^\s*$/', $line)) { + $emptyLine += 1; + if ($emptyLine > 2) { + throw new Exception\RuntimeException('Malformed header detected'); + } + continue; + } + + if ($emptyLine > 0) { + throw new Exception\RuntimeException('Malformed header detected'); + } + // check if a header name is present if (preg_match('/^[\x21-\x39\x3B-\x7E]+:.*$/', $line)) { if ($currentLine) { @@ -76,20 +95,21 @@ class Headers implements Countable, Iterator $headers->addHeaderLine($currentLine); } $currentLine = trim($line); - } elseif (preg_match('/^\s+.*$/', $line)) { - // continuation: append to current line - // recover the whitespace that break the line (unfolding, rfc2822#section-2.2.3) - $currentLine .= ' ' . trim($line); - } elseif (preg_match('/^\s*$/', $line)) { - // empty line indicates end of headers - break; - } else { - // Line does not match header format! - throw new Exception\RuntimeException(sprintf( - 'Line "%s"does not match header format!', - $line - )); + continue; } + + // continuation: append to current line + // recover the whitespace that break the line (unfolding, rfc2822#section-2.2.3) + if (preg_match('/^\s+.*$/', $line)) { + $currentLine .= ' ' . trim($line); + continue; + } + + // Line does not match header format! + throw new Exception\RuntimeException(sprintf( + 'Line "%s"does not match header format!', + $line + )); } if ($currentLine) { $headers->addHeaderLine($currentLine); @@ -200,7 +220,9 @@ class Headers implements Countable, Iterator if (!is_string($headerFieldNameOrLine)) { throw new Exception\InvalidArgumentException(sprintf( '%s expects its first argument to be a string; received "%s"', - (is_object($headerFieldNameOrLine) ? get_class($headerFieldNameOrLine) : gettype($headerFieldNameOrLine)) + (is_object($headerFieldNameOrLine) + ? get_class($headerFieldNameOrLine) + : gettype($headerFieldNameOrLine)) )); } @@ -208,10 +230,10 @@ class Headers implements Countable, Iterator $this->addHeader(Header\GenericHeader::fromString($headerFieldNameOrLine)); } elseif (is_array($fieldValue)) { foreach ($fieldValue as $i) { - $this->addHeader(new Header\GenericMultiHeader($headerFieldNameOrLine, $i)); + $this->addHeader(Header\GenericMultiHeader::fromString($headerFieldNameOrLine . ':' . $i)); } } else { - $this->addHeader(new Header\GenericHeader($headerFieldNameOrLine, $fieldValue)); + $this->addHeader(Header\GenericHeader::fromString($headerFieldNameOrLine . ':' . $fieldValue)); } return $this; @@ -449,8 +471,7 @@ class Headers implements Countable, Iterator { $current = $this->headers[$index]; - $key = $this->headersKeys[$index]; - /* @var $class Header\HeaderInterface */ + $key = $this->headersKeys[$index]; $class = ($this->getPluginClassLoader()->load($key)) ?: 'Zend\Mail\Header\GenericHeader'; $encoding = $current->getEncoding(); diff --git a/library/TorrentPier/Zend/Mail/Message.php b/library/TorrentPier/Zend/Mail/Message.php index a1cfdbcb6..b5069fb98 100644 --- a/library/TorrentPier/Zend/Mail/Message.php +++ b/library/TorrentPier/Zend/Mail/Message.php @@ -372,7 +372,8 @@ class Message if (!$body instanceof Mime\Message) { if (!method_exists($body, '__toString')) { throw new Exception\InvalidArgumentException(sprintf( - '%s expects object arguments of type Zend\Mime\Message or implementing __toString(); object of type "%s" received', + '%s expects object arguments of type Zend\Mime\Message or implementing __toString();' + . ' object of type "%s" received', __METHOD__, get_class($body) )); @@ -402,7 +403,7 @@ class Message $parts = $this->body->getParts(); if (!empty($parts)) { $part = array_shift($parts); - $headers->addHeaders($part->getHeadersArray()); + $headers->addHeaders($part->getHeadersArray("\r\n")); } return $this; } @@ -510,7 +511,8 @@ class Message } if (!is_string($emailOrAddressOrList) && !$emailOrAddressOrList instanceof Address\AddressInterface) { throw new Exception\InvalidArgumentException(sprintf( - '%s expects a string, AddressInterface, array, AddressList, or Traversable as its first argument; received "%s"', + '%s expects a string, AddressInterface, array, AddressList, or Traversable as its first argument;' + . ' received "%s"', $callingMethod, (is_object($emailOrAddressOrList) ? get_class($emailOrAddressOrList) : gettype($emailOrAddressOrList)) )); diff --git a/library/TorrentPier/Zend/Mail/Protocol/Imap.php b/library/TorrentPier/Zend/Mail/Protocol/Imap.php index c56ba948a..53eb3bafc 100644 --- a/library/TorrentPier/Zend/Mail/Protocol/Imap.php +++ b/library/TorrentPier/Zend/Mail/Protocol/Imap.php @@ -651,7 +651,7 @@ class Imap $flags = $this->escapeList($flags); $set = (int) $from; - if ($to != null) { + if ($to !== null) { $set .= ':' . ($to == INF ? '*' : (int) $to); } @@ -710,7 +710,7 @@ class Imap public function copy($folder, $from, $to = null) { $set = (int) $from; - if ($to != null) { + if ($to !== null) { $set .= ':' . ($to == INF ? '*' : (int) $to); } diff --git a/library/TorrentPier/Zend/Mail/Protocol/Smtp.php b/library/TorrentPier/Zend/Mail/Protocol/Smtp.php index 2c67e111b..d542c79a7 100644 --- a/library/TorrentPier/Zend/Mail/Protocol/Smtp.php +++ b/library/TorrentPier/Zend/Mail/Protocol/Smtp.php @@ -117,7 +117,7 @@ class Smtp extends AbstractProtocol case 'ssl': $this->transport = 'ssl'; $this->secure = 'ssl'; - if ($port == null) { + if ($port === null) { $port = 465; } break; @@ -128,7 +128,7 @@ class Smtp extends AbstractProtocol } // If no port has been specified then check the master PHP ini file. Defaults to 25 if the ini setting is null. - if ($port == null) { + if ($port === null) { if (($port = ini_get('smtp_port')) == '') { $port = 25; } diff --git a/library/TorrentPier/Zend/Mail/Storage/Imap.php b/library/TorrentPier/Zend/Mail/Storage/Imap.php index 2eacf0663..142f8624d 100644 --- a/library/TorrentPier/Zend/Mail/Storage/Imap.php +++ b/library/TorrentPier/Zend/Mail/Storage/Imap.php @@ -388,7 +388,7 @@ class Imap extends AbstractStorage implements Folder\FolderInterface, Writable\W // TODO: we assume / as the hierarchy delim - need to get that from the folder class! if ($parentFolder instanceof Folder) { $folder = $parentFolder->getGlobalName() . '/' . $name; - } elseif ($parentFolder != null) { + } elseif ($parentFolder !== null) { $folder = $parentFolder . '/' . $name; } else { $folder = $name; diff --git a/library/TorrentPier/Zend/Mail/Storage/Writable/Maildir.php b/library/TorrentPier/Zend/Mail/Storage/Writable/Maildir.php index b5d75d4a3..c96a9f4ad 100644 --- a/library/TorrentPier/Zend/Mail/Storage/Writable/Maildir.php +++ b/library/TorrentPier/Zend/Mail/Storage/Writable/Maildir.php @@ -107,7 +107,7 @@ class Maildir extends Folder\Maildir implements WritableInterface { if ($parentFolder instanceof Folder) { $folder = $parentFolder->getGlobalName() . $this->delim . $name; - } elseif ($parentFolder != null) { + } elseif ($parentFolder !== null) { $folder = rtrim($parentFolder, $this->delim) . $this->delim . $name; } else { $folder = $name; diff --git a/library/TorrentPier/Zend/Mail/composer.json b/library/TorrentPier/Zend/Mail/composer.json index 069e8ba40..a259247ed 100644 --- a/library/TorrentPier/Zend/Mail/composer.json +++ b/library/TorrentPier/Zend/Mail/composer.json @@ -28,8 +28,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Math/composer.json b/library/TorrentPier/Zend/Math/composer.json index 86343dcbe..4af34e2a8 100644 --- a/library/TorrentPier/Zend/Math/composer.json +++ b/library/TorrentPier/Zend/Math/composer.json @@ -23,8 +23,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Memory/Container/Movable.php b/library/TorrentPier/Zend/Memory/Container/Movable.php index c5d129762..68ec50ace 100644 --- a/library/TorrentPier/Zend/Memory/Container/Movable.php +++ b/library/TorrentPier/Zend/Memory/Container/Movable.php @@ -102,7 +102,7 @@ class Movable extends AbstractContainer */ public function isLocked() { - return $this->state & self::LOCKED; + return (bool) ($this->state & self::LOCKED); } /** diff --git a/library/TorrentPier/Zend/Memory/composer.json b/library/TorrentPier/Zend/Memory/composer.json index ae78a7bf2..4e6e5284c 100644 --- a/library/TorrentPier/Zend/Memory/composer.json +++ b/library/TorrentPier/Zend/Memory/composer.json @@ -23,8 +23,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Mime/Mime.php b/library/TorrentPier/Zend/Mime/Mime.php index 18e348ca2..c7b9f2974 100644 --- a/library/TorrentPier/Zend/Mime/Mime.php +++ b/library/TorrentPier/Zend/Mime/Mime.php @@ -181,28 +181,29 @@ class Mime $str = str_replace(array('?', ' ', '_'), array('=3F', '=20', '=5F'), $str); // initialize first line, we need it anyways - $lines = array(0 => ""); + $lines = array(0 => ''); // Split encoded text into separate lines - $tmp = ""; + $tmp = ''; while (strlen($str) > 0) { - $currentLine = max(count($lines)-1, 0); + $currentLine = max(count($lines) - 1, 0); $token = static::getNextQuotedPrintableToken($str); - $str = substr($str, strlen($token)) ?: ''; + $substr = substr($str, strlen($token)); + $str = (false === $substr) ? '' : $substr; $tmp .= $token; - if ($token == '=20') { + if ($token === '=20') { // only if we have a single char token or space, we can append the // tempstring it to the current line or start a new line if necessary. if (strlen($lines[$currentLine] . $tmp) > $lineLength) { - $lines[$currentLine+1] = $tmp; + $lines[$currentLine + 1] = $tmp; } else { $lines[$currentLine] .= $tmp; } - $tmp = ""; + $tmp = ''; } // don't forget to append the rest to the last line - if (strlen($str) == 0) { + if (strlen($str) === 0) { $lines[$currentLine] .= $tmp; } } @@ -223,7 +224,7 @@ class Mime */ private static function getNextQuotedPrintableToken($str) { - if (substr($str, 0, 1) == "=") { + if (substr($str, 0, 1) === "=") { $token = substr($str, 0, 3); } else { $token = substr($str, 0, 1); diff --git a/library/TorrentPier/Zend/Mime/composer.json b/library/TorrentPier/Zend/Mime/composer.json index 10d1a709b..315b5359e 100644 --- a/library/TorrentPier/Zend/Mime/composer.json +++ b/library/TorrentPier/Zend/Mime/composer.json @@ -24,8 +24,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/ModuleManager/composer.json b/library/TorrentPier/Zend/ModuleManager/composer.json index 6c8ce16e7..43b57cc69 100644 --- a/library/TorrentPier/Zend/ModuleManager/composer.json +++ b/library/TorrentPier/Zend/ModuleManager/composer.json @@ -32,8 +32,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Mvc/composer.json b/library/TorrentPier/Zend/Mvc/composer.json index aa4c3e746..fc18b2a6b 100644 --- a/library/TorrentPier/Zend/Mvc/composer.json +++ b/library/TorrentPier/Zend/Mvc/composer.json @@ -62,8 +62,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Navigation/Page/Mvc.php b/library/TorrentPier/Zend/Navigation/Page/Mvc.php index 569caedf7..324d2ed9b 100644 --- a/library/TorrentPier/Zend/Navigation/Page/Mvc.php +++ b/library/TorrentPier/Zend/Navigation/Page/Mvc.php @@ -130,18 +130,18 @@ class Mvc extends AbstractPage $reqParams['controller'] = $reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER]; } - $myParams = $this->params; + $pageParams = $this->params; if (null !== $this->controller) { - $myParams['controller'] = $this->controller; + $pageParams['controller'] = $this->controller; } if (null !== $this->action) { - $myParams['action'] = $this->action; + $pageParams['action'] = $this->action; } if (null !== $this->getRoute()) { if ( $this->routeMatch->getMatchedRouteName() === $this->getRoute() - && (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) + && (count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) ) { $this->active = true; return $this->active; @@ -151,27 +151,27 @@ class Mvc extends AbstractPage } } - $myParams = $this->params; + $pageParams = $this->params; if (null !== $this->controller) { - $myParams['controller'] = $this->controller; + $pageParams['controller'] = $this->controller; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ - $myParams['controller'] = 'index'; + $pageParams['controller'] = 'index'; } if (null !== $this->action) { - $myParams['action'] = $this->action; + $pageParams['action'] = $this->action; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ - $myParams['action'] = 'index'; + $pageParams['action'] = 'index'; } - if (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) { + if (count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) { $this->active = true; return true; } @@ -226,11 +226,11 @@ class Mvc extends AbstractPage } - if (($param = $this->getController()) != null) { + if (($param = $this->getController()) !== null) { $params['controller'] = $param; } - if (($param = $this->getAction()) != null) { + if (($param = $this->getAction()) !== null) { $params['action'] = $param; } diff --git a/library/TorrentPier/Zend/Navigation/composer.json b/library/TorrentPier/Zend/Navigation/composer.json index 72f69219e..67ad7c462 100644 --- a/library/TorrentPier/Zend/Navigation/composer.json +++ b/library/TorrentPier/Zend/Navigation/composer.json @@ -32,8 +32,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Paginator/Paginator.php b/library/TorrentPier/Zend/Paginator/Paginator.php index 376b615aa..e524f44b3 100644 --- a/library/TorrentPier/Zend/Paginator/Paginator.php +++ b/library/TorrentPier/Zend/Paginator/Paginator.php @@ -176,7 +176,7 @@ class Paginator implements Countable, IteratorAggregate $scrollingStyle = isset($config['scrolling_style']) ? $config['scrolling_style'] : null; - if ($scrollingStyle != null) { + if ($scrollingStyle !== null) { static::setDefaultScrollingStyle($scrollingStyle); } } @@ -294,7 +294,7 @@ class Paginator implements Countable, IteratorAggregate $key = strtolower($setupMethod); $value = isset($config[$key]) ? $config[$key] : null; - if ($value != null) { + if ($value !== null) { $setupMethod = 'set' . $setupMethod; $this->$setupMethod($value); } @@ -394,7 +394,7 @@ class Paginator implements Countable, IteratorAggregate { $relativeItemNumber = $this->normalizeItemNumber($relativeItemNumber); - if ($pageNumber == null) { + if ($pageNumber === null) { $pageNumber = $this->getCurrentPageNumber(); } @@ -500,7 +500,7 @@ class Paginator implements Countable, IteratorAggregate */ public function getItem($itemNumber, $pageNumber = null) { - if ($pageNumber == null) { + if ($pageNumber === null) { $pageNumber = $this->getCurrentPageNumber(); } elseif ($pageNumber < 0) { $pageNumber = ($this->count() + 1) + $pageNumber; diff --git a/library/TorrentPier/Zend/Paginator/composer.json b/library/TorrentPier/Zend/Paginator/composer.json index 927d539f7..3a304077a 100644 --- a/library/TorrentPier/Zend/Paginator/composer.json +++ b/library/TorrentPier/Zend/Paginator/composer.json @@ -34,8 +34,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Permissions/Acl/composer.json b/library/TorrentPier/Zend/Permissions/Acl/composer.json index a7f370def..ae51d363a 100644 --- a/library/TorrentPier/Zend/Permissions/Acl/composer.json +++ b/library/TorrentPier/Zend/Permissions/Acl/composer.json @@ -20,8 +20,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Permissions/Rbac/composer.json b/library/TorrentPier/Zend/Permissions/Rbac/composer.json index a7d45d8cc..3b93d9ee5 100644 --- a/library/TorrentPier/Zend/Permissions/Rbac/composer.json +++ b/library/TorrentPier/Zend/Permissions/Rbac/composer.json @@ -17,8 +17,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/ProgressBar/composer.json b/library/TorrentPier/Zend/ProgressBar/composer.json index 93df8738b..a1708c2ec 100644 --- a/library/TorrentPier/Zend/ProgressBar/composer.json +++ b/library/TorrentPier/Zend/ProgressBar/composer.json @@ -26,8 +26,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Serializer/composer.json b/library/TorrentPier/Zend/Serializer/composer.json index fa453bd95..c4d9d293a 100644 --- a/library/TorrentPier/Zend/Serializer/composer.json +++ b/library/TorrentPier/Zend/Serializer/composer.json @@ -26,8 +26,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Server/composer.json b/library/TorrentPier/Zend/Server/composer.json index fda84138c..21d9ad526 100644 --- a/library/TorrentPier/Zend/Server/composer.json +++ b/library/TorrentPier/Zend/Server/composer.json @@ -19,8 +19,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/ServiceManager/Di/DiServiceInitializer.php b/library/TorrentPier/Zend/ServiceManager/Di/DiServiceInitializer.php index 2e3c594d1..66760f068 100644 --- a/library/TorrentPier/Zend/ServiceManager/Di/DiServiceInitializer.php +++ b/library/TorrentPier/Zend/ServiceManager/Di/DiServiceInitializer.php @@ -10,7 +10,6 @@ namespace Zend\ServiceManager\Di; use Zend\Di\Di; -use Zend\ServiceManager\Exception; use Zend\ServiceManager\InitializerInterface; use Zend\ServiceManager\ServiceLocatorInterface; diff --git a/library/TorrentPier/Zend/ServiceManager/composer.json b/library/TorrentPier/Zend/ServiceManager/composer.json index 59cc60558..efde3f7c3 100644 --- a/library/TorrentPier/Zend/ServiceManager/composer.json +++ b/library/TorrentPier/Zend/ServiceManager/composer.json @@ -24,8 +24,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Session/SessionManager.php b/library/TorrentPier/Zend/Session/SessionManager.php index f36ff79b0..e2d9dff4e 100644 --- a/library/TorrentPier/Zend/Session/SessionManager.php +++ b/library/TorrentPier/Zend/Session/SessionManager.php @@ -145,12 +145,7 @@ class SessionManager extends AbstractManager continue; } - $referenceValue = null; - if (is_array($validatorValues) && array_key_exists($validator, $validatorValues)) { - $referenceValue = $validatorValues[$validator]; - } - - $validator = new $validator($referenceValue); + $validator = new $validator(null); $validatorChain->attach('session.validate', array($validator, 'isValid')); } } diff --git a/library/TorrentPier/Zend/Session/Validator/RemoteAddr.php b/library/TorrentPier/Zend/Session/Validator/RemoteAddr.php index 93baf58bb..ba7626f18 100644 --- a/library/TorrentPier/Zend/Session/Validator/RemoteAddr.php +++ b/library/TorrentPier/Zend/Session/Validator/RemoteAddr.php @@ -50,6 +50,8 @@ class RemoteAddr implements SessionValidator /** * Constructor * get the current user IP and store it in the session as 'valid data' + * + * @param null|string $data */ public function __construct($data = null) { diff --git a/library/TorrentPier/Zend/Session/composer.json b/library/TorrentPier/Zend/Session/composer.json index ca7cb6ebb..42a67e8f2 100644 --- a/library/TorrentPier/Zend/Session/composer.json +++ b/library/TorrentPier/Zend/Session/composer.json @@ -34,8 +34,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Soap/AutoDiscover.php b/library/TorrentPier/Zend/Soap/AutoDiscover.php index fc534aafa..c4ca0f530 100644 --- a/library/TorrentPier/Zend/Soap/AutoDiscover.php +++ b/library/TorrentPier/Zend/Soap/AutoDiscover.php @@ -150,7 +150,7 @@ class AutoDiscover /** * Set the class map of php to wsdl mappings. * - * @param array $classmap + * @param array $classMap * @return self * @throws Exception\InvalidArgumentException */ diff --git a/library/TorrentPier/Zend/Soap/Client.php b/library/TorrentPier/Zend/Soap/Client.php index 5ec8c7bfa..381e6d717 100644 --- a/library/TorrentPier/Zend/Soap/Client.php +++ b/library/TorrentPier/Zend/Soap/Client.php @@ -326,7 +326,7 @@ class Client implements ServerClient unset($options[$key]); } } else { - if ($value == null) { + if ($value === null) { unset($options[$key]); } } @@ -1003,7 +1003,7 @@ class Client implements ServerClient $wsdl = $this->getWSDL(); $options = array_merge($this->getOptions(), array('trace' => true)); - if ($wsdl == null) { + if ($wsdl === null) { if (!isset($options['location'])) { throw new Exception\UnexpectedValueException('"location" parameter is required in non-WSDL mode.'); } @@ -1142,7 +1142,7 @@ class Client implements ServerClient */ public function getFunctions() { - if ($this->getWSDL() == null) { + if ($this->getWSDL() === null) { throw new Exception\UnexpectedValueException(sprintf( '%s method is available only in WSDL mode.', __METHOD__ @@ -1161,7 +1161,7 @@ class Client implements ServerClient */ public function getTypes() { - if ($this->getWSDL() == null) { + if ($this->getWSDL() === null) { throw new Exception\UnexpectedValueException(sprintf( '%s method is available only in WSDL mode.', __METHOD__ @@ -1191,7 +1191,7 @@ class Client implements ServerClient */ public function getSoapClient() { - if ($this->soapClient == null) { + if ($this->soapClient === null) { $this->_initSoapClientObject(); } return $this->soapClient; diff --git a/library/TorrentPier/Zend/Soap/Server.php b/library/TorrentPier/Zend/Soap/Server.php index 2349bf540..d5e22fb21 100644 --- a/library/TorrentPier/Zend/Soap/Server.php +++ b/library/TorrentPier/Zend/Soap/Server.php @@ -960,7 +960,9 @@ class Server implements ZendServerServer /** * Set the debug mode. * In debug mode, all exceptions are send to the client. - * @param bool $debug + * + * @param bool $debug + * @return self */ public function setDebugMode($debug) { diff --git a/library/TorrentPier/Zend/Soap/Wsdl.php b/library/TorrentPier/Zend/Soap/Wsdl.php index 225d44a3e..5cac9b2ba 100644 --- a/library/TorrentPier/Zend/Soap/Wsdl.php +++ b/library/TorrentPier/Zend/Soap/Wsdl.php @@ -165,9 +165,10 @@ class Wsdl /** * Set the class map of php to wsdl mappings.. * + * @param array $classMap * @return self */ - public function setClassMap($classMap) + public function setClassMap(array $classMap) { $this->classMap = $classMap; return $this; @@ -587,7 +588,7 @@ class Wsdl */ public function getSchema() { - if ($this->schema == null) { + if ($this->schema === null) { $this->addSchemaTypeSection(); } return $this->schema; diff --git a/library/TorrentPier/Zend/Soap/composer.json b/library/TorrentPier/Zend/Soap/composer.json index 5ee4c9635..828aed149 100644 --- a/library/TorrentPier/Zend/Soap/composer.json +++ b/library/TorrentPier/Zend/Soap/composer.json @@ -26,8 +26,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Stdlib/Hydrator/Filter/FilterComposite.php b/library/TorrentPier/Zend/Stdlib/Hydrator/Filter/FilterComposite.php index 000fc701e..060034bb9 100644 --- a/library/TorrentPier/Zend/Stdlib/Hydrator/Filter/FilterComposite.php +++ b/library/TorrentPier/Zend/Stdlib/Hydrator/Filter/FilterComposite.php @@ -36,6 +36,8 @@ class FilterComposite implements FilterInterface /** * Define default Filter * + * @param array $orFilter + * @param array $andFilter * @throws InvalidArgumentException */ public function __construct($orFilter = array(), $andFilter = array()) diff --git a/library/TorrentPier/Zend/Stdlib/composer.json b/library/TorrentPier/Zend/Stdlib/composer.json index dfe178bf9..a3aeb47d3 100644 --- a/library/TorrentPier/Zend/Stdlib/composer.json +++ b/library/TorrentPier/Zend/Stdlib/composer.json @@ -29,8 +29,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Tag/Cloud/Decorator/AbstractDecorator.php b/library/TorrentPier/Zend/Tag/Cloud/Decorator/AbstractDecorator.php index cfc913625..eab899406 100644 --- a/library/TorrentPier/Zend/Tag/Cloud/Decorator/AbstractDecorator.php +++ b/library/TorrentPier/Zend/Tag/Cloud/Decorator/AbstractDecorator.php @@ -160,6 +160,12 @@ abstract class AbstractDecorator implements Decorator } } + /** + * Wrap html with tag + * + * @param string $html + * @return string + */ protected function wrapTag($html) { $escaper = $this->getEscaper(); diff --git a/library/TorrentPier/Zend/Tag/composer.json b/library/TorrentPier/Zend/Tag/composer.json index 6b20f108d..4e0e47b11 100644 --- a/library/TorrentPier/Zend/Tag/composer.json +++ b/library/TorrentPier/Zend/Tag/composer.json @@ -25,8 +25,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Test/composer.json b/library/TorrentPier/Zend/Test/composer.json index 488c451cd..f04ccc588 100644 --- a/library/TorrentPier/Zend/Test/composer.json +++ b/library/TorrentPier/Zend/Test/composer.json @@ -33,8 +33,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Text/Table/Column.php b/library/TorrentPier/Zend/Text/Table/Column.php index 8a2aacc95..b51b8e5fd 100644 --- a/library/TorrentPier/Zend/Text/Table/Column.php +++ b/library/TorrentPier/Zend/Text/Table/Column.php @@ -10,7 +10,6 @@ namespace Zend\Text\Table; use Zend\Stdlib\StringUtils; -use Zend\Text; /** * Column class for Zend\Text\Table\Row diff --git a/library/TorrentPier/Zend/Text/composer.json b/library/TorrentPier/Zend/Text/composer.json index 2fd1684f2..ff1df4aee 100644 --- a/library/TorrentPier/Zend/Text/composer.json +++ b/library/TorrentPier/Zend/Text/composer.json @@ -19,8 +19,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Uri/composer.json b/library/TorrentPier/Zend/Uri/composer.json index 1d4001446..c6bd852c7 100644 --- a/library/TorrentPier/Zend/Uri/composer.json +++ b/library/TorrentPier/Zend/Uri/composer.json @@ -19,8 +19,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Validator/ValidatorPluginManager.php b/library/TorrentPier/Zend/Validator/ValidatorPluginManager.php index 90a5c7ab3..4a7c21b0d 100644 --- a/library/TorrentPier/Zend/Validator/ValidatorPluginManager.php +++ b/library/TorrentPier/Zend/Validator/ValidatorPluginManager.php @@ -105,7 +105,6 @@ class ValidatorPluginManager extends AbstractPluginManager 'isfloat' => 'Zend\I18n\Validator\IsFloat', 'isinstanceof' => 'Zend\Validator\IsInstanceOf', 'isint' => 'Zend\I18n\Validator\IsInt', - 'ip' => 'Zend\Validator\Ip', 'lessthan' => 'Zend\Validator\LessThan', 'notempty' => 'Zend\Validator\NotEmpty', 'phonenumber' => 'Zend\I18n\Validator\PhoneNumber', diff --git a/library/TorrentPier/Zend/Validator/composer.json b/library/TorrentPier/Zend/Validator/composer.json index a72cf2688..709077634 100644 --- a/library/TorrentPier/Zend/Validator/composer.json +++ b/library/TorrentPier/Zend/Validator/composer.json @@ -37,8 +37,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/Version/Version.php b/library/TorrentPier/Zend/Version/Version.php index 820d37540..757f5a54a 100644 --- a/library/TorrentPier/Zend/Version/Version.php +++ b/library/TorrentPier/Zend/Version/Version.php @@ -20,7 +20,7 @@ final class Version /** * Zend Framework version identification - see compareVersion() */ - const VERSION = '2.4.0'; + const VERSION = '2.4.2'; /** * Github Service Identifier for version information is retrieved from diff --git a/library/TorrentPier/Zend/Version/composer.json b/library/TorrentPier/Zend/Version/composer.json index 1e587e97c..04d8fc514 100644 --- a/library/TorrentPier/Zend/Version/composer.json +++ b/library/TorrentPier/Zend/Version/composer.json @@ -22,8 +22,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/View/Helper/FlashMessenger.php b/library/TorrentPier/Zend/View/Helper/FlashMessenger.php index 72c11f8e5..2097454d6 100644 --- a/library/TorrentPier/Zend/View/Helper/FlashMessenger.php +++ b/library/TorrentPier/Zend/View/Helper/FlashMessenger.php @@ -116,8 +116,9 @@ class FlashMessenger extends AbstractTranslatorHelper implements ServiceLocatorA /** * Render Current Messages * - * @param string $namespace - * @param array $classes + * @param string $namespace + * @param array $classes + * @param bool|null $autoEscape * @return string */ public function renderCurrent($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $classes = array(), $autoEscape = null) diff --git a/library/TorrentPier/Zend/View/Helper/HtmlList.php b/library/TorrentPier/Zend/View/Helper/HtmlList.php index 4845461c6..76bf67e1d 100644 --- a/library/TorrentPier/Zend/View/Helper/HtmlList.php +++ b/library/TorrentPier/Zend/View/Helper/HtmlList.php @@ -43,14 +43,14 @@ class HtmlList extends AbstractHtmlElement $escaper = $this->getView()->plugin('escapeHtml'); $item = $escaper($item); } - $list .= '
  • ' . $item . '
  • ' . self::EOL; + $list .= '
  • ' . $item . '
  • ' . PHP_EOL; } else { - $itemLength = 5 + strlen(self::EOL); + $itemLength = 5 + strlen(PHP_EOL); if ($itemLength < strlen($list)) { $list = substr($list, 0, strlen($list) - $itemLength) - . $this($item, $ordered, $attribs, $escape) . '' . self::EOL; + . $this($item, $ordered, $attribs, $escape) . '' . PHP_EOL; } else { - $list .= '
  • ' . $this($item, $ordered, $attribs, $escape) . '
  • ' . self::EOL; + $list .= '
  • ' . $this($item, $ordered, $attribs, $escape) . '
  • ' . PHP_EOL; } } } @@ -63,6 +63,6 @@ class HtmlList extends AbstractHtmlElement $tag = ($ordered) ? 'ol' : 'ul'; - return '<' . $tag . $attribs . '>' . self::EOL . $list . '' . self::EOL; + return '<' . $tag . $attribs . '>' . PHP_EOL . $list . '' . PHP_EOL; } } diff --git a/library/TorrentPier/Zend/View/Helper/HtmlObject.php b/library/TorrentPier/Zend/View/Helper/HtmlObject.php index ea4d2dcdf..d0042a984 100644 --- a/library/TorrentPier/Zend/View/Helper/HtmlObject.php +++ b/library/TorrentPier/Zend/View/Helper/HtmlObject.php @@ -31,7 +31,7 @@ class HtmlObject extends AbstractHtmlElement array $params = array(), $content = null ) { - if ($data == null || $type == null) { + if ($data === null || $type === null) { throw new InvalidArgumentException( 'HTMLObject: missing argument. $data and $type are required in ' . 'htmlObject($data, $type, array $attribs = array(), array $params = array(), $content = null)' @@ -57,13 +57,13 @@ class HtmlObject extends AbstractHtmlElement // Content if (is_array($content)) { - $content = implode(self::EOL, $content); + $content = implode(PHP_EOL, $content); } // Object header - $xhtml = 'htmlAttribs($attribs) . '>' . self::EOL - . implode(self::EOL, $paramHtml) . self::EOL - . ($content ? $content . self::EOL : '') + $xhtml = 'htmlAttribs($attribs) . '>' . PHP_EOL + . implode(PHP_EOL, $paramHtml) . PHP_EOL + . ($content ? $content . PHP_EOL : '') . ''; return $xhtml; diff --git a/library/TorrentPier/Zend/View/Helper/Navigation/Links.php b/library/TorrentPier/Zend/View/Helper/Navigation/Links.php index 853530f97..f3d5ee490 100644 --- a/library/TorrentPier/Zend/View/Helper/Navigation/Links.php +++ b/library/TorrentPier/Zend/View/Helper/Navigation/Links.php @@ -167,7 +167,7 @@ class Links extends AbstractHelper foreach ($pages as $page) { $r = $this->renderLink($page, $attrib, $relation); if ($r) { - $output .= $indent . $r . self::EOL; + $output .= $indent . $r . PHP_EOL; } } } @@ -176,7 +176,7 @@ class Links extends AbstractHelper $this->root = null; // return output (trim last newline by spec) - return strlen($output) ? rtrim($output, self::EOL) : ''; + return strlen($output) ? rtrim($output, PHP_EOL) : ''; } /** diff --git a/library/TorrentPier/Zend/View/Helper/PartialLoop.php b/library/TorrentPier/Zend/View/Helper/PartialLoop.php index 96a9d3801..460c91744 100644 --- a/library/TorrentPier/Zend/View/Helper/PartialLoop.php +++ b/library/TorrentPier/Zend/View/Helper/PartialLoop.php @@ -129,7 +129,9 @@ class PartialLoop extends Partial $this->setObjectKey(null); $this->nestingLevel -= 1; - $this->objectKey = $this->objectKeyStack[$this->nestingLevel]; + if (isset($this->objectKeyStack[$this->nestingLevel])) { + $this->objectKey = $this->objectKeyStack[$this->nestingLevel]; + } return $this; } diff --git a/library/TorrentPier/Zend/View/Helper/Placeholder.php b/library/TorrentPier/Zend/View/Helper/Placeholder.php index 8fda0a88a..cc7c2795e 100644 --- a/library/TorrentPier/Zend/View/Helper/Placeholder.php +++ b/library/TorrentPier/Zend/View/Helper/Placeholder.php @@ -42,7 +42,7 @@ class Placeholder extends AbstractHelper */ public function __invoke($name = null) { - if ($name == null) { + if ($name === null) { throw new InvalidArgumentException( 'Placeholder: missing argument. $name is required by placeholder($name)' ); diff --git a/library/TorrentPier/Zend/View/Renderer/PhpRenderer.php b/library/TorrentPier/Zend/View/Renderer/PhpRenderer.php index 6a43c643e..696bafa15 100644 --- a/library/TorrentPier/Zend/View/Renderer/PhpRenderer.php +++ b/library/TorrentPier/Zend/View/Renderer/PhpRenderer.php @@ -30,7 +30,7 @@ use Zend\View\Variables; * * Convenience methods for build in helpers (@see __call): * - * @method \Zend\View\Helper\BasePath basePath($file = null) + * @method string|null basePath($file = null) * @method \Zend\View\Helper\Cycle cycle(array $data = array(), $name = \Zend\View\Helper\Cycle::DEFAULT_NAME) * @method \Zend\View\Helper\DeclareVars declareVars() * @method \Zend\View\Helper\Doctype doctype($doctype = null) diff --git a/library/TorrentPier/Zend/View/composer.json b/library/TorrentPier/Zend/View/composer.json index dfcce1c87..499461291 100644 --- a/library/TorrentPier/Zend/View/composer.json +++ b/library/TorrentPier/Zend/View/composer.json @@ -50,8 +50,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } } diff --git a/library/TorrentPier/Zend/XmlRpc/AbstractValue.php b/library/TorrentPier/Zend/XmlRpc/AbstractValue.php index 35f8a701e..3a580cabe 100644 --- a/library/TorrentPier/Zend/XmlRpc/AbstractValue.php +++ b/library/TorrentPier/Zend/XmlRpc/AbstractValue.php @@ -438,7 +438,9 @@ abstract class AbstractValue */ protected static function _extractTypeAndValue(\SimpleXMLElement $xml, &$type, &$value) { - list($type, $value) = each($xml); + // Casting is necessary to work with strict-typed systems + $xmlAsArray = (array) $xml; + list($type, $value) = each($xmlAsArray); if (!$type and $value === null) { $namespaces = array('ex' => 'http://ws.apache.org/xmlrpc/namespaces/extensions'); foreach ($namespaces as $namespaceName => $namespaceUri) { diff --git a/library/TorrentPier/Zend/XmlRpc/Fault.php b/library/TorrentPier/Zend/XmlRpc/Fault.php index 04a1e5ca3..e64cd6aa5 100644 --- a/library/TorrentPier/Zend/XmlRpc/Fault.php +++ b/library/TorrentPier/Zend/XmlRpc/Fault.php @@ -83,6 +83,8 @@ class Fault /** * Constructor * + * @param int $code + * @param string $message */ public function __construct($code = 404, $message = '') { diff --git a/library/TorrentPier/Zend/XmlRpc/Server.php b/library/TorrentPier/Zend/XmlRpc/Server.php index 0c36a3583..7fdb30589 100644 --- a/library/TorrentPier/Zend/XmlRpc/Server.php +++ b/library/TorrentPier/Zend/XmlRpc/Server.php @@ -492,6 +492,9 @@ class Server extends AbstractServer * how to handle arguments. If set to true, all methods including constructor * will receive the arguments. If set to false, only constructor will receive the * arguments + * + * @param bool|null $flag + * @return self */ public function sendArgumentsToAllMethods($flag = null) { diff --git a/library/TorrentPier/Zend/XmlRpc/composer.json b/library/TorrentPier/Zend/XmlRpc/composer.json index 9a0707501..7f053cce4 100644 --- a/library/TorrentPier/Zend/XmlRpc/composer.json +++ b/library/TorrentPier/Zend/XmlRpc/composer.json @@ -25,8 +25,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3-dev", - "dev-develop": "2.4-dev" + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" } } }