From d75ace74409b8524062d5497f1f77cf4fb4ec250 Mon Sep 17 00:00:00 2001 From: Lars Moelleken Date: Sun, 3 Mar 2019 11:46:11 +0100 Subject: [PATCH] [+]: update composer.json (require min. php 7.0) + update "voku/simple-cache" --- .gitignore | 8 +- bundled-libs/autoload.php | 4 +- bundled-libs/composer/ClassLoader.php | 60 +- bundled-libs/composer/LICENSE | 2 +- bundled-libs/composer/autoload_classmap.php | 284 ++++ bundled-libs/composer/autoload_namespaces.php | 1 - bundled-libs/composer/autoload_psr4.php | 2 + bundled-libs/composer/autoload_real.php | 3 +- bundled-libs/composer/autoload_static.php | 304 +++- bundled-libs/composer/installed.json | 325 ++-- bundled-libs/psr/simple-cache/LICENSE.md | 21 + bundled-libs/psr/simple-cache/README.md | 8 + bundled-libs/psr/simple-cache/composer.json | 25 + .../psr/simple-cache/src/CacheException.php | 10 + .../psr/simple-cache/src/CacheInterface.php | 114 ++ .../src/InvalidArgumentException.php | 13 + bundled-libs/voku/simple-cache/CHANGELOG.md | 12 + bundled-libs/voku/simple-cache/README.md | 97 +- bundled-libs/voku/simple-cache/composer.json | 2 +- .../src/voku/cache/AdapterApc.php | 3 +- .../src/voku/cache/AdapterApcu.php | 3 +- .../src/voku/cache/AdapterFile.php | 4 +- .../src/voku/cache/AdapterFileAbstract.php | 22 +- .../src/voku/cache/AdapterOpCache.php | 7 +- .../simple-cache/src/voku/cache/Cache.php | 767 ++++----- .../voku/cache/CacheAdapterAutoManager.php | 230 +++ .../src/voku/cache/CacheChain.php | 13 +- .../src/voku/cache/CachePsr16.php | 40 +- .../simple-cache/src/voku/cache/iCache.php | 8 +- .../src/voku/cache/iSerializer.php | 8 +- .../zend-db/.ci/mysql_fixtures.sh | 5 + .../zend-db/.ci/mysql_fixtures_travis.sh | 5 + .../zend-db/.ci/pgsql_fixtures.sh | 6 + .../zend-db/.ci/sqlsrv_fixtures.sh | 5 + .../zendframework/zend-db/CHANGELOG.md | 445 +++++ bundled-libs/zendframework/zend-db/LICENSE.md | 27 + bundled-libs/zendframework/zend-db/README.md | 12 + .../Zend/Db/Adapter/AdapterServiceFactory.php | 28 - .../Zend/Db/Adapter/Platform/IbmDb2.php | 209 --- .../Zend/Db/Adapter/Platform/Mysql.php | 214 --- .../Zend/Db/Adapter/Platform/Oracle.php | 189 --- .../Zend/Db/Adapter/Platform/Postgresql.php | 213 --- .../Zend/Db/Adapter/Platform/Sql92.php | 162 -- .../Zend/Db/Adapter/Platform/SqlServer.php | 204 --- .../Zend/Db/Adapter/Platform/Sqlite.php | 204 --- .../Profiler/ProfilerAwareInterface.php | 8 - .../Db/Adapter/Profiler/ProfilerInterface.php | 13 - .../Zend/Db/Metadata/MetadataInterface.php | 36 - .../zendframework/zend-db/Zend/Db/README.md | 15 - .../zend-db/Zend/Db/Sql/AbstractSql.php | 188 --- .../zend-db/Zend/Db/Sql/Ddl/Column/Blob.php | 91 - .../Zend/Db/Sql/Ddl/Column/Boolean.php | 42 - .../zend-db/Zend/Db/Sql/Ddl/Column/Char.php | 58 - .../zend-db/Zend/Db/Sql/Ddl/Column/Date.php | 50 - .../Zend/Db/Sql/Ddl/Column/Decimal.php | 69 - .../zend-db/Zend/Db/Sql/Ddl/Column/Float.php | 66 - .../Zend/Db/Sql/Ddl/Column/Integer.php | 32 - .../zend-db/Zend/Db/Sql/Ddl/Column/Text.php | 52 - .../zend-db/Zend/Db/Sql/Ddl/Column/Time.php | 50 - .../Zend/Db/Sql/Ddl/Column/Varchar.php | 58 - .../Sql/Ddl/Constraint/AbstractConstraint.php | 58 - .../Zend/Db/Sql/Ddl/Constraint/ForeignKey.php | 177 -- .../Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php | 36 - .../Zend/Db/Sql/Ddl/Constraint/UniqueKey.php | 55 - .../zend-db/Zend/Db/Sql/Ddl/DropTable.php | 77 - .../zend-db/Zend/Db/Sql/Delete.php | 244 --- .../zend-db/Zend/Db/Sql/Insert.php | 302 ---- .../Zend/Db/Sql/Platform/AbstractPlatform.php | 110 -- .../Mysql/Ddl/CreateTableDecorator.php | 87 - .../Db/Sql/Platform/Mysql/SelectDecorator.php | 88 - .../Sql/Platform/Oracle/SelectDecorator.php | 182 -- .../zend-db/Zend/Db/Sql/Platform/Platform.php | 42 - .../zend-db/Zend/Db/Sql/Predicate/In.php | 111 -- .../zend-db/Zend/Db/Sql/Predicate/Literal.php | 10 - .../Zend/Db/Sql/Predicate/PredicateSet.php | 136 -- .../zend-db/Zend/Db/Sql/Select.php | 996 ----------- .../zend-db/Zend/Db/Sql/TableIdentifier.php | 81 - .../zend-db/Zend/Db/Sql/Update.php | 316 ---- .../zend-db/Zend/Db/composer.json | 27 - .../zendframework/zend-db/composer.json | 73 + .../zend-db/docs/CODE_OF_CONDUCT.md | 43 + .../zend-db/docs/CONTRIBUTING.md | 189 +++ .../zend-db/docs/ISSUE_TEMPLATE.md | 19 + .../zend-db/docs/PULL_REQUEST_TEMPLATE.md | 25 + .../zendframework/zend-db/docs/SUPPORT.md | 25 + .../zend-db/docs/book/adapter.md | 498 ++++++ .../zend-db/docs/book/index.html | 10 + .../zend-db/docs/book/metadata.md | 229 +++ .../zend-db/docs/book/result-set.md | 157 ++ .../zend-db/docs/book/row-gateway.md | 98 ++ .../zend-db/docs/book/sql-ddl.md | 201 +++ .../zendframework/zend-db/docs/book/sql.md | 741 ++++++++ .../zend-db/docs/book/table-gateway.md | 217 +++ bundled-libs/zendframework/zend-db/phpcs.xml | 11 + .../{Zend/Db => src}/Adapter/Adapter.php | 122 +- .../Adapter/AdapterAbstractServiceFactory.php | 68 +- .../Adapter/AdapterAwareInterface.php | 2 +- .../Db => src}/Adapter/AdapterAwareTrait.php | 6 +- .../Db => src}/Adapter/AdapterInterface.php | 3 +- .../src/Adapter/AdapterServiceFactory.php | 42 + .../src/Adapter/Driver/AbstractConnection.php | 135 ++ .../Adapter/Driver/ConnectionInterface.php | 2 +- .../Adapter/Driver/DriverInterface.php | 4 +- .../Driver/Feature/AbstractFeature.php | 4 +- .../Driver/Feature/DriverFeatureInterface.php | 2 +- .../Adapter/Driver/IbmDb2/Connection.php | 227 +-- .../Adapter/Driver/IbmDb2/IbmDb2.php | 20 +- .../Adapter/Driver/IbmDb2/Result.php | 8 +- .../Adapter/Driver/IbmDb2/Statement.php | 63 +- .../Adapter/Driver/Mysqli/Connection.php | 224 +-- .../Adapter/Driver/Mysqli/Mysqli.php | 31 +- .../Adapter/Driver/Mysqli/Result.php | 32 +- .../Adapter/Driver/Mysqli/Statement.php | 31 +- .../Adapter/Driver/Oci8/Connection.php | 201 +-- .../Driver/Oci8/Feature/RowCounter.php | 75 + .../Db => src}/Adapter/Driver/Oci8/Oci8.php | 107 +- .../Db => src}/Adapter/Driver/Oci8/Result.php | 43 +- .../Adapter/Driver/Oci8/Statement.php | 54 +- .../Adapter/Driver/Pdo/Connection.php | 263 ++- .../Driver/Pdo/Feature/OracleRowCounter.php | 22 +- .../Driver/Pdo/Feature/SqliteRowCounter.php | 21 +- .../Db => src}/Adapter/Driver/Pdo/Pdo.php | 54 +- .../Db => src}/Adapter/Driver/Pdo/Result.php | 45 +- .../Adapter/Driver/Pdo/Statement.php | 44 +- .../Adapter/Driver/Pgsql/Connection.php | 232 +-- .../Db => src}/Adapter/Driver/Pgsql/Pgsql.php | 41 +- .../Adapter/Driver/Pgsql/Result.php | 7 +- .../Adapter/Driver/Pgsql/Statement.php | 21 +- .../Adapter/Driver/ResultInterface.php | 2 +- .../Adapter/Driver/Sqlsrv/Connection.php | 173 +- .../Sqlsrv/Exception/ErrorException.php | 5 +- .../Sqlsrv/Exception/ExceptionInterface.php | 2 +- .../Adapter/Driver/Sqlsrv/Result.php | 7 +- .../Adapter/Driver/Sqlsrv/Sqlsrv.php | 29 +- .../Adapter/Driver/Sqlsrv/Statement.php | 79 +- .../Adapter/Driver/StatementInterface.php | 7 +- .../Adapter/Exception/ErrorException.php | 2 +- .../Adapter/Exception/ExceptionInterface.php | 2 +- .../Exception/InvalidArgumentException.php | 2 +- .../InvalidConnectionParametersException.php | 3 +- .../Exception/InvalidQueryException.php | 2 +- .../Adapter/Exception/RuntimeException.php | 2 +- .../Exception/UnexpectedValueException.php | 2 +- .../Db => src}/Adapter/ParameterContainer.php | 120 +- .../src/Adapter/Platform/AbstractPlatform.php | 142 ++ .../zend-db/src/Adapter/Platform/IbmDb2.php | 125 ++ .../zend-db/src/Adapter/Platform/Mysql.php | 122 ++ .../zend-db/src/Adapter/Platform/Oracle.php | 129 ++ .../Adapter/Platform/PlatformInterface.php | 4 +- .../src/Adapter/Platform/Postgresql.php | 112 ++ .../zend-db/src/Adapter/Platform/Sql92.php | 33 + .../src/Adapter/Platform/SqlServer.php | 119 ++ .../zend-db/src/Adapter/Platform/Sqlite.php | 105 ++ .../Db => src}/Adapter/Profiler/Profiler.php | 27 +- .../Profiler/ProfilerAwareInterface.php | 18 + .../Adapter/Profiler/ProfilerInterface.php | 20 + .../Db => src}/Adapter/StatementContainer.php | 7 +- .../Adapter/StatementContainerInterface.php | 2 +- .../zend-db/src/ConfigProvider.php | 43 + .../Db => src}/Exception/ErrorException.php | 2 +- .../Exception/ExceptionInterface.php | 2 +- .../Exception/InvalidArgumentException.php | 2 +- .../Db => src}/Exception/RuntimeException.php | 2 +- .../Exception/UnexpectedValueException.php | 2 +- .../{Zend/Db => src}/Metadata/Metadata.php | 132 +- .../src/Metadata/MetadataInterface.php | 154 ++ .../Metadata/Object/AbstractTableObject.php | 3 +- .../Metadata/Object/ColumnObject.php | 31 +- .../Metadata/Object/ConstraintKeyObject.php | 249 +++ .../Metadata/Object/ConstraintObject.php | 24 +- .../Metadata/Object/TableObject.php | 2 +- .../Metadata/Object/TriggerObject.php | 32 +- .../Db => src}/Metadata/Object/ViewObject.php | 8 +- .../Metadata/Source/AbstractSource.php | 157 +- .../zend-db/src/Metadata/Source/Factory.php | 47 + .../Metadata/Source/MysqlMetadata.php | 322 ++-- .../src/Metadata/Source/OracleMetadata.php | 256 +++ .../Metadata/Source/PostgresqlMetadata.php | 191 +-- .../Metadata/Source/SqlServerMetadata.php | 222 +-- .../Metadata/Source/SqliteMetadata.php | 111 +- .../zendframework/zend-db/src/Module.php | 24 + .../ResultSet/AbstractResultSet.php | 54 +- .../Exception/ExceptionInterface.php | 2 +- .../Exception/InvalidArgumentException.php | 2 +- .../ResultSet/Exception/RuntimeException.php | 2 +- .../ResultSet/HydratingResultSet.php | 34 +- .../{Zend/Db => src}/ResultSet/ResultSet.php | 28 +- .../ResultSet/ResultSetInterface.php | 7 +- .../RowGateway/AbstractRowGateway.php | 58 +- .../Exception/ExceptionInterface.php | 2 +- .../Exception/InvalidArgumentException.php | 2 +- .../RowGateway/Exception/RuntimeException.php | 2 +- .../RowGateway/Feature/AbstractFeature.php | 7 +- .../RowGateway/Feature/FeatureSet.php | 22 +- .../Db => src}/RowGateway/RowGateway.php | 9 +- .../RowGateway/RowGatewayInterface.php | 2 +- .../zend-db/src/Sql/AbstractExpression.php | 93 + .../zend-db/src/Sql/AbstractPreparableSql.php | 39 + .../zend-db/src/Sql/AbstractSql.php | 479 ++++++ .../zendframework/zend-db/src/Sql/Combine.php | 212 +++ .../{Zend/Db => src}/Sql/Ddl/AlterTable.php | 148 +- .../Sql/Ddl/Column/AbstractLengthColumn.php | 71 + .../Ddl/Column/AbstractPrecisionColumn.php | 86 + .../Ddl/Column/AbstractTimestampColumn.php | 63 + .../Db => src}/Sql/Ddl/Column/BigInteger.php | 2 +- .../zend-db/src/Sql/Ddl/Column/Binary.php | 18 + .../zend-db/src/Sql/Ddl/Column/Blob.php | 18 + .../zend-db/src/Sql/Ddl/Column/Boolean.php | 31 + .../zend-db/src/Sql/Ddl/Column/Char.php | 18 + .../Db => src}/Sql/Ddl/Column/Column.php | 68 +- .../Sql/Ddl/Column/ColumnInterface.php | 22 +- .../zend-db/src/Sql/Ddl/Column/Date.php | 18 + .../zend-db/src/Sql/Ddl/Column/Datetime.php | 18 + .../zend-db/src/Sql/Ddl/Column/Decimal.php | 18 + .../zend-db/src/Sql/Ddl/Column/Float.php | 48 + .../zend-db/src/Sql/Ddl/Column/Floating.php | 24 + .../zend-db/src/Sql/Ddl/Column/Integer.php | 28 + .../zend-db/src/Sql/Ddl/Column/Text.php | 18 + .../zend-db/src/Sql/Ddl/Column/Time.php | 18 + .../zend-db/src/Sql/Ddl/Column/Timestamp.php | 18 + .../zend-db/src/Sql/Ddl/Column/Varbinary.php | 18 + .../zend-db/src/Sql/Ddl/Column/Varchar.php | 18 + .../Sql/Ddl/Constraint/AbstractConstraint.php | 130 ++ .../Db => src}/Sql/Ddl/Constraint/Check.php | 29 +- .../Ddl/Constraint/ConstraintInterface.php | 2 +- .../src/Sql/Ddl/Constraint/ForeignKey.php | 184 ++ .../src/Sql/Ddl/Constraint/PrimaryKey.php | 18 + .../src/Sql/Ddl/Constraint/UniqueKey.php | 18 + .../{Zend/Db => src}/Sql/Ddl/CreateTable.php | 181 +- .../zend-db/src/Sql/Ddl/DropTable.php | 44 + .../src/Sql/Ddl/Index/AbstractIndex.php | 16 + .../zend-db/src/Sql/Ddl/Index/Index.php | 80 + .../{Zend/Db => src}/Sql/Ddl/SqlInterface.php | 2 +- .../zendframework/zend-db/src/Sql/Delete.php | 172 ++ .../Sql/Exception/ExceptionInterface.php | 2 +- .../Exception/InvalidArgumentException.php | 2 +- .../Sql/Exception/RuntimeException.php | 2 +- .../{Zend/Db => src}/Sql/Expression.php | 85 +- .../Db => src}/Sql/ExpressionInterface.php | 6 +- .../zend-db/{Zend/Db => src}/Sql/Having.php | 3 +- .../zendframework/zend-db/src/Sql/Insert.php | 300 ++++ .../zendframework/zend-db/src/Sql/Join.php | 163 ++ .../zend-db/{Zend/Db => src}/Sql/Literal.php | 17 +- .../src/Sql/Platform/AbstractPlatform.php | 112 ++ .../src/Sql/Platform/IbmDb2/IbmDb2.php | 23 + .../Sql/Platform/IbmDb2/SelectDecorator.php | 212 +++ .../Mysql/Ddl/AlterTableDecorator.php | 251 +++ .../Mysql/Ddl/CreateTableDecorator.php | 184 ++ .../Db => src}/Sql/Platform/Mysql/Mysql.php | 3 +- .../Sql/Platform/Mysql/SelectDecorator.php | 77 + .../Db => src}/Sql/Platform/Oracle/Oracle.php | 4 +- .../Sql/Platform/Oracle/SelectDecorator.php | 155 ++ .../zend-db/src/Sql/Platform/Platform.php | 173 ++ .../Platform/PlatformDecoratorInterface.php | 7 +- .../SqlServer/Ddl/CreateTableDecorator.php | 45 + .../Platform/SqlServer/SelectDecorator.php | 84 +- .../Sql/Platform/SqlServer/SqlServer.php | 4 +- .../Sql/Platform/Sqlite/SelectDecorator.php | 105 ++ .../src/Sql/Platform/Sqlite/Sqlite.php | 25 + .../Db => src}/Sql/Predicate/Between.php | 29 +- .../Db => src}/Sql/Predicate/Expression.php | 16 +- .../zend-db/src/Sql/Predicate/In.php | 140 ++ .../Db => src}/Sql/Predicate/IsNotNull.php | 2 +- .../{Zend/Db => src}/Sql/Predicate/IsNull.php | 20 +- .../{Zend/Db => src}/Sql/Predicate/Like.php | 31 +- .../zend-db/src/Sql/Predicate/Literal.php | 16 + .../zend-db/src/Sql/Predicate/NotBetween.php | 15 + .../{Zend/Db => src}/Sql/Predicate/NotIn.php | 5 +- .../zend-db/src/Sql/Predicate/NotLike.php | 15 + .../Db => src}/Sql/Predicate/Operator.php | 112 +- .../Db => src}/Sql/Predicate/Predicate.php | 146 +- .../Sql/Predicate/PredicateInterface.php | 3 +- .../src/Sql/Predicate/PredicateSet.php | 201 +++ .../Db => src}/Sql/PreparableSqlInterface.php | 6 +- .../zendframework/zend-db/src/Sql/Select.php | 836 +++++++++ .../zend-db/{Zend/Db => src}/Sql/Sql.php | 77 +- .../{Zend/Db => src}/Sql/SqlInterface.php | 9 +- .../zend-db/src/Sql/TableIdentifier.php | 113 ++ .../zendframework/zend-db/src/Sql/Update.php | 277 +++ .../zend-db/{Zend/Db => src}/Sql/Where.php | 3 +- .../TableGateway/AbstractTableGateway.php | 154 +- .../Exception/ExceptionInterface.php | 2 +- .../Exception/InvalidArgumentException.php | 2 +- .../Exception/RuntimeException.php | 2 +- .../TableGateway/Feature/AbstractFeature.php | 8 +- .../TableGateway/Feature/EventFeature.php | 76 +- .../EventFeature/TableGatewayEvent.php | 5 +- .../Feature/EventFeatureEventsInterface.php | 36 + .../TableGateway/Feature/FeatureSet.php | 45 +- .../Feature/GlobalAdapterFeature.php | 7 +- .../Feature/MasterSlaveFeature.php | 6 +- .../TableGateway/Feature/MetadataFeature.php | 27 +- .../Feature/RowGatewayFeature.php | 28 +- .../TableGateway/Feature/SequenceFeature.php | 25 +- .../Db => src}/TableGateway/TableGateway.php | 38 +- .../TableGateway/TableGatewayInterface.php | 2 +- .../zendframework/zend-db/test/autoload.php | 26 + .../Adapter/Driver/Mysqli/ConnectionTest.php | 25 + .../Driver/Mysqli/TableGatewayTest.php | 50 + .../Adapter/Driver/Mysqli/TraitSetup.php | 43 + .../Adapter/Driver/Pdo/Mysql/AdapterTest.php | 20 + .../Adapter/Driver/Pdo/Mysql/AdapterTrait.php | 23 + .../Adapter/Driver/Pdo/Mysql/QueryTest.php | 57 + .../Driver/Pdo/Mysql/TableGatewayTest.php | 98 ++ .../Adapter/Platform/MysqlTest.php | 75 + .../Adapter/Platform/PostgresqlTest.php | 75 + .../Adapter/Platform/SqlServerTest.php | 61 + .../Adapter/Platform/SqliteTest.php | 49 + .../integration/IntegrationTestListener.php | 62 + .../integration/Platform/FixtureLoader.php | 16 + .../Platform/MysqlFixtureLoader.php | 58 + .../Platform/PgsqlFixtureLoader.php | 76 + .../test/integration/TestFixtures/mysql.sql | 21 + .../test/integration/TestFixtures/pgsql.sql | 19 + .../AdapterAbstractServiceFactoryTest.php | 88 + .../unit/Adapter/AdapterAwareTraitTest.php | 32 + .../Adapter/AdapterServiceFactoryTest.php | 57 + .../zend-db/test/unit/Adapter/AdapterTest.php | 316 ++++ .../Driver/IbmDb2/AbstractIntegrationTest.php | 44 + .../IbmDb2/ConnectionIntegrationTest.php | 213 +++ .../Adapter/Driver/IbmDb2/ConnectionTest.php | 64 + .../Driver/IbmDb2/IbmDb2IntegrationTest.php | 55 + .../unit/Adapter/Driver/IbmDb2/IbmDb2Test.php | 166 ++ .../Driver/IbmDb2/ResultIntegrationTest.php | 198 +++ .../IbmDb2/StatementIntegrationTest.php | 134 ++ .../Adapter/Driver/IbmDb2/StatementTest.php | 188 +++ .../Driver/IbmDb2/TestAsset/Db2Functions.php | 57 + .../Adapter/Driver/Mysqli/ConnectionTest.php | 76 + .../Driver/Oci8/AbstractIntegrationTest.php | 41 + .../Driver/Oci8/ConnectionIntegrationTest.php | 180 ++ .../Adapter/Driver/Oci8/ConnectionTest.php | 64 + .../Driver/Oci8/Feature/RowCounterTest.php | 113 ++ .../Driver/Oci8/Oci8IntegrationTest.php | 50 + .../unit/Adapter/Driver/Oci8/Oci8Test.php | 166 ++ .../Driver/Oci8/ResultIntegrationTest.php | 198 +++ .../unit/Adapter/Driver/Oci8/ResultTest.php | 90 + .../Driver/Oci8/StatementIntegrationTest.php | 117 ++ .../Adapter/Driver/Oci8/StatementTest.php | 161 ++ .../Driver/Pdo/ConnectionIntegrationTest.php | 183 ++ .../Adapter/Driver/Pdo/ConnectionTest.php | 123 ++ .../Driver/Pdo/ConnectionTransactionsTest.php | 201 +++ .../Pdo/Feature/OracleRowCounterTest.php | 133 ++ .../Pdo/Feature/SqliteRowCounterTest.php | 133 ++ .../test/unit/Adapter/Driver/Pdo/PdoTest.php | 87 + .../unit/Adapter/Driver/Pdo/ResultTest.php | 72 + .../Driver/Pdo/StatementIntegrationTest.php | 74 + .../unit/Adapter/Driver/Pdo/StatementTest.php | 131 ++ .../Driver/Pdo/TestAsset/CtorlessPdo.php | 25 + .../Driver/Pdo/TestAsset/SqliteMemoryPdo.php | 31 + .../Adapter/Driver/Pgsql/ConnectionTest.php | 168 ++ .../unit/Adapter/Driver/Pgsql/PgsqlTest.php | 178 ++ .../Driver/Pgsql/pgsqlMockFunctions.php | 15 + .../Driver/Sqlsrv/AbstractIntegrationTest.php | 45 + .../Sqlsrv/ConnectionIntegrationTest.php | 192 +++ .../Adapter/Driver/Sqlsrv/ConnectionTest.php | 64 + .../Sqlsrv/PdoSqlSrvIntegrationTest.php | 29 + .../Driver/Sqlsrv/ResultIntegrationTest.php | 198 +++ .../Driver/Sqlsrv/SqlSrvIntegrationTest.php | 70 + .../unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php | 166 ++ .../Sqlsrv/StatementIntegrationTest.php | 87 + .../Adapter/Driver/Sqlsrv/StatementTest.php | 138 ++ .../unit/Adapter/Driver/TestAsset/PdoMock.php | 39 + .../unit/Adapter/ParameterContainerTest.php | 299 ++++ .../test/unit/Adapter/Platform/IbmDb2Test.php | 196 +++ .../test/unit/Adapter/Platform/MysqlTest.php | 242 +++ .../test/unit/Adapter/Platform/OracleTest.php | 256 +++ .../unit/Adapter/Platform/PostgresqlTest.php | 184 ++ .../test/unit/Adapter/Platform/Sql92Test.php | 176 ++ .../unit/Adapter/Platform/SqlServerTest.php | 194 +++ .../test/unit/Adapter/Platform/SqliteTest.php | 206 +++ .../unit/Adapter/Platform/_files/.gitkeep | 0 .../unit/Adapter/Profiler/ProfilerTest.php | 89 + .../zend-db/test/unit/ConfigProviderTest.php | 42 + .../Metadata/Source/AbstractSourceTest.php | 80 + .../test/unit/Metadata/Source/FactoryTest.php | 65 + .../Metadata/Source/OracleMetadataTest.php | 55 + .../Metadata/Source/SqliteMetadataTest.php | 102 ++ .../AbstractResultSetIntegrationTest.php | 58 + .../unit/ResultSet/AbstractResultSetTest.php | 271 +++ .../HydratingResultSetIntegrationTest.php | 33 + .../unit/ResultSet/HydratingResultSetTest.php | 102 ++ .../ResultSet/ResultSetIntegrationTest.php | 251 +++ .../RowGateway/AbstractRowGatewayTest.php | 316 ++++ .../test/unit/RowGateway/RowGatewayTest.php | 49 + .../zend-db/test/unit/Sql/AbstractSqlTest.php | 187 +++ .../zend-db/test/unit/Sql/CombineTest.php | 213 +++ .../test/unit/Sql/Ddl/AlterTableTest.php | 122 ++ .../Ddl/Column/AbstractLengthColumnTest.php | 48 + .../Column/AbstractPrecisionColumnTest.php | 68 + .../unit/Sql/Ddl/Column/BigIntegerTest.php | 37 + .../test/unit/Sql/Ddl/Column/BinaryTest.php | 28 + .../test/unit/Sql/Ddl/Column/BlobTest.php | 28 + .../test/unit/Sql/Ddl/Column/BooleanTest.php | 44 + .../test/unit/Sql/Ddl/Column/CharTest.php | 28 + .../test/unit/Sql/Ddl/Column/ColumnTest.php | 132 ++ .../test/unit/Sql/Ddl/Column/DateTest.php | 28 + .../test/unit/Sql/Ddl/Column/DatetimeTest.php | 28 + .../test/unit/Sql/Ddl/Column/DecimalTest.php | 28 + .../test/unit/Sql/Ddl/Column/FloatTest.php | 29 + .../test/unit/Sql/Ddl/Column/FloatingTest.php | 32 + .../test/unit/Sql/Ddl/Column/IntegerTest.php | 49 + .../test/unit/Sql/Ddl/Column/TextTest.php | 28 + .../test/unit/Sql/Ddl/Column/TimeTest.php | 28 + .../unit/Sql/Ddl/Column/TimestampTest.php | 28 + .../unit/Sql/Ddl/Column/VarbinaryTest.php | 28 + .../test/unit/Sql/Ddl/Column/VarcharTest.php | 38 + .../Ddl/Constraint/AbstractConstraintTest.php | 50 + .../unit/Sql/Ddl/Constraint/CheckTest.php | 32 + .../Sql/Ddl/Constraint/ForeignKeyTest.php | 134 ++ .../Sql/Ddl/Constraint/PrimaryKeyTest.php | 32 + .../unit/Sql/Ddl/Constraint/UniqueKeyTest.php | 32 + .../test/unit/Sql/Ddl/CreateTableTest.php | 175 ++ .../test/unit/Sql/Ddl/DropTableTest.php | 32 + .../test/unit/Sql/Ddl/Index/IndexTest.php | 64 + .../zend-db/test/unit/Sql/DeleteTest.php | 228 +++ .../zend-db/test/unit/Sql/ExpressionTest.php | 182 ++ .../zend-db/test/unit/Sql/InsertTest.php | 412 +++++ .../zend-db/test/unit/Sql/JoinTest.php | 135 ++ .../zend-db/test/unit/Sql/LiteralTest.php | 47 + .../Platform/IbmDb2/SelectDecoratorTest.php | 155 ++ .../Mysql/Ddl/AlterTableDecoratorTest.php | 55 + .../Mysql/Ddl/CreateTableDecoratorTest.php | 57 + .../unit/Sql/Platform/Mysql/MysqlTest.php | 31 + .../Platform/Mysql/SelectDecoratorTest.php | 249 +++ .../unit/Sql/Platform/Oracle/OracleTest.php | 31 + .../Platform/Oracle/SelectDecoratorTest.php | 144 ++ .../test/unit/Sql/Platform/PlatformTest.php | 126 ++ .../Ddl/CreateTableDecoratorTest.php | 46 + .../SqlServer/SelectDecoratorTest.php | 142 ++ .../Sql/Platform/SqlServer/SqlServerTest.php | 31 + .../Platform/Sqlite/SelectDecoratorTest.php | 160 ++ .../unit/Sql/Platform/Sqlite/SqliteTest.php | 31 + .../test/unit/Sql/Predicate/BetweenTest.php | 139 ++ .../unit/Sql/Predicate/ExpressionTest.php | 183 ++ .../test/unit/Sql/Predicate/InTest.php | 127 ++ .../test/unit/Sql/Predicate/IsNullTest.php | 61 + .../test/unit/Sql/Predicate/LikeTest.php | 68 + .../test/unit/Sql/Predicate/LiteralTest.php | 34 + .../unit/Sql/Predicate/NotBetweenTest.php | 60 + .../test/unit/Sql/Predicate/NotInTest.php | 66 + .../test/unit/Sql/Predicate/NotLikeTest.php | 64 + .../test/unit/Sql/Predicate/OperatorTest.php | 103 ++ .../unit/Sql/Predicate/PredicateSetTest.php | 133 ++ .../test/unit/Sql/Predicate/PredicateTest.php | 287 ++++ .../zend-db/test/unit/Sql/SelectTest.php | 1490 +++++++++++++++++ .../test/unit/Sql/SqlFunctionalTest.php | 624 +++++++ .../zend-db/test/unit/Sql/SqlTest.php | 237 +++ .../test/unit/Sql/TableIdentifierTest.php | 118 ++ .../zend-db/test/unit/Sql/UpdateTest.php | 429 +++++ .../TableGateway/AbstractTableGatewayTest.php | 425 +++++ .../TableGateway/Feature/EventFeatureTest.php | 246 +++ .../TableGateway/Feature/FeatureSetTest.php | 176 ++ .../Feature/MasterSlaveFeatureTest.php | 101 ++ .../Feature/MetadataFeatureTest.php | 125 ++ .../Feature/SequenceFeatureTest.php | 98 ++ .../unit/TableGateway/TableGatewayTest.php | 263 +++ .../test/unit/TestAsset/ConnectionWrapper.php | 28 + .../test/unit/TestAsset/DeleteDecorator.php | 27 + .../test/unit/TestAsset/DeleteIgnore.php | 26 + .../test/unit/TestAsset/InsertDecorator.php | 27 + .../test/unit/TestAsset/PdoStubDriver.php | 24 + .../zend-db/test/unit/TestAsset/Replace.php | 26 + .../test/unit/TestAsset/SelectDecorator.php | 27 + .../unit/TestAsset/TemporaryResultSet.php | 7 + .../unit/TestAsset/TrustingMysqlPlatform.php | 20 + .../unit/TestAsset/TrustingOraclePlatform.php | 20 + .../unit/TestAsset/TrustingSql92Platform.php | 23 + .../TestAsset/TrustingSqlServerPlatform.php | 20 + .../test/unit/TestAsset/UpdateDecorator.php | 27 + .../test/unit/TestAsset/UpdateIgnore.php | 27 + .../zendframework/zend-stdlib/CHANGELOG.md | 385 +++++ .../zendframework/zend-stdlib/LICENSE.md | 27 + .../zendframework/zend-stdlib/README.md | 29 + .../benchmark/ExtractPriorityQueueBench.php | 54 + .../benchmark/InsertPriorityQueueBench.php | 47 + .../benchmark/RemovePriorityQueueBench.php | 46 + .../zendframework/zend-stdlib/composer.json | 56 + .../zend-stdlib/docs/CODE_OF_CONDUCT.md | 43 + .../zend-stdlib/docs/CONTRIBUTING.md | 189 +++ .../zend-stdlib/docs/ISSUE_TEMPLATE.md | 19 + .../zend-stdlib/docs/PULL_REQUEST_TEMPLATE.md | 25 + .../zendframework/zend-stdlib/docs/SUPPORT.md | 25 + .../zend-stdlib/docs/book/console-helper.md | 126 ++ .../zend-stdlib/docs/book/index.html | 10 + .../zend-stdlib/docs/book/migration.md | 60 + .../zend-stdlib/docs/bookdown.json | 14 + .../zend-stdlib/src/AbstractOptions.php | 178 ++ .../zend-stdlib/src/ArrayObject.php | 434 +++++ .../src/ArraySerializableInterface.php | 28 + .../zend-stdlib/src/ArrayStack.php | 33 + .../zend-stdlib/src/ArrayUtils.php | 314 ++++ .../src/ArrayUtils/MergeRemoveKey.php | 14 + .../src/ArrayUtils/MergeReplaceKey.php | 34 + .../ArrayUtils/MergeReplaceKeyInterface.php | 21 + .../zend-stdlib/src/ConsoleHelper.php | 158 ++ .../zend-stdlib/src/DispatchableInterface.php | 22 + .../zend-stdlib/src/ErrorHandler.php | 115 ++ .../src/Exception/BadMethodCallException.php | 17 + .../src/Exception/DomainException.php | 17 + .../src/Exception/ExceptionInterface.php | 17 + .../Exception/ExtensionNotLoadedException.php | 17 + .../Exception/InvalidArgumentException.php | 17 + .../src/Exception/LogicException.php | 17 + .../src/Exception/RuntimeException.php | 17 + .../zend-stdlib/src/FastPriorityQueue.php | 371 ++++ .../zendframework/zend-stdlib/src/Glob.php | 202 +++ .../zend-stdlib/src/Guard/AllGuardsTrait.php | 20 + .../Guard/ArrayOrTraversableGuardTrait.php | 41 + .../zend-stdlib/src/Guard/EmptyGuardTrait.php | 35 + .../zend-stdlib/src/Guard/NullGuardTrait.php | 35 + .../src/InitializableInterface.php | 23 + .../zend-stdlib/src/JsonSerializable.php | 17 + .../zendframework/zend-stdlib/src/Message.php | 118 ++ .../zend-stdlib/src/MessageInterface.php | 44 + .../src/ParameterObjectInterface.php | 38 + .../zend-stdlib/src/Parameters.php | 115 ++ .../zend-stdlib/src/ParametersInterface.php | 86 + .../zend-stdlib/src/PriorityList.php | 274 +++ .../zend-stdlib/src/PriorityQueue.php | 301 ++++ .../zendframework/zend-stdlib/src/Request.php | 15 + .../zend-stdlib/src/RequestInterface.php | 14 + .../zend-stdlib/src/Response.php | 15 + .../zend-stdlib/src/ResponseInterface.php | 14 + .../zend-stdlib/src/SplPriorityQueue.php | 93 + .../zend-stdlib/src/SplQueue.php | 55 + .../zend-stdlib/src/SplStack.php | 55 + .../zend-stdlib/src/StringUtils.php | 187 +++ .../StringWrapper/AbstractStringWrapper.php | 269 +++ .../zend-stdlib/src/StringWrapper/Iconv.php | 289 ++++ .../zend-stdlib/src/StringWrapper/Intl.php | 88 + .../src/StringWrapper/MbString.php | 121 ++ .../zend-stdlib/src/StringWrapper/Native.php | 134 ++ .../StringWrapper/StringWrapperInterface.php | 111 ++ .../zend-stdlib/test/ArrayObjectTest.php | 389 +++++ .../zend-stdlib/test/ArrayUtilsTest.php | 521 ++++++ .../zend-stdlib/test/ConsoleHelperTest.php | 148 ++ .../zend-stdlib/test/ErrorHandlerTest.php | 105 ++ .../test/FastPriorityQueueTest.php | 348 ++++ .../zend-stdlib/test/GlobTest.php | 73 + .../ArrayOrTraversableGuardTraitTest.php | 42 + .../test/Guard/EmptyGuardTraitTest.php | 34 + .../test/Guard/NullGuardTraitTest.php | 35 + .../zend-stdlib/test/MessageTest.php | 73 + .../zend-stdlib/test/OptionsTest.php | 205 +++ .../zend-stdlib/test/ParametersTest.php | 63 + .../zend-stdlib/test/PriorityListTest.php | 244 +++ .../zend-stdlib/test/PriorityQueueTest.php | 164 ++ .../zend-stdlib/test/SplPriorityQueueTest.php | 73 + .../zend-stdlib/test/SplQueueTest.php | 50 + .../zend-stdlib/test/SplStackTest.php | 52 + .../zend-stdlib/test/StringUtilsTest.php | 160 ++ .../StringWrapper/CommonStringWrapperTest.php | 264 +++ .../test/StringWrapper/IconvTest.php | 46 + .../test/StringWrapper/IntlTest.php | 46 + .../test/StringWrapper/MbStringTest.php | 46 + .../test/StringWrapper/NativeTest.php | 31 + .../test/TestAsset/ArrayObjectIterator.php | 51 + .../test/TestAsset/ArrayObjectObjectCount.php | 18 + .../test/TestAsset/ArrayObjectObjectVars.php | 17 + .../test/TestAsset/ArraySerializable.php | 49 + .../test/TestAsset/GuardedObject.php | 32 + .../test/TestAsset/TestOptions.php | 86 + .../test/TestAsset/TestOptionsDerived.php | 72 + .../test/TestAsset/TestOptionsNoStrict.php | 34 + .../TestAsset/TestOptionsWithoutGetter.php | 25 + .../zend-stdlib/test/_files/alpha | 0 .../zend-stdlib/test/_files/beta | 0 .../zend-stdlib/test/_files/delta | 0 .../zend-stdlib/test/_files/eta.alpha | 0 .../zend-stdlib/test/_files/eta.beta | 0 .../zend-stdlib/test/_files/gamma | 0 .../zend-stdlib/test/_files/zeta.alpha | 0 .../zend-stdlib/test/_files/zeta.beta | 0 composer.json | 17 +- 574 files changed, 44341 insertions(+), 8530 deletions(-) create mode 100644 bundled-libs/psr/simple-cache/LICENSE.md create mode 100644 bundled-libs/psr/simple-cache/README.md create mode 100644 bundled-libs/psr/simple-cache/composer.json create mode 100644 bundled-libs/psr/simple-cache/src/CacheException.php create mode 100644 bundled-libs/psr/simple-cache/src/CacheInterface.php create mode 100644 bundled-libs/psr/simple-cache/src/InvalidArgumentException.php create mode 100644 bundled-libs/voku/simple-cache/src/voku/cache/CacheAdapterAutoManager.php create mode 100644 bundled-libs/zendframework/zend-db/.ci/mysql_fixtures.sh create mode 100644 bundled-libs/zendframework/zend-db/.ci/mysql_fixtures_travis.sh create mode 100644 bundled-libs/zendframework/zend-db/.ci/pgsql_fixtures.sh create mode 100644 bundled-libs/zendframework/zend-db/.ci/sqlsrv_fixtures.sh create mode 100644 bundled-libs/zendframework/zend-db/CHANGELOG.md create mode 100644 bundled-libs/zendframework/zend-db/LICENSE.md create mode 100644 bundled-libs/zendframework/zend-db/README.md delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterServiceFactory.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/IbmDb2.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Mysql.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Oracle.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Postgresql.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sql92.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/SqlServer.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sqlite.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerAwareInterface.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerInterface.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Metadata/MetadataInterface.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/README.md delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/AbstractSql.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Blob.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Boolean.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Char.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Date.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Decimal.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Float.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Integer.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Text.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Time.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Varchar.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ForeignKey.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/UniqueKey.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/DropTable.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Delete.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Insert.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/AbstractPlatform.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/SelectDecorator.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Platform.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/In.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Literal.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateSet.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Select.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/TableIdentifier.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/Sql/Update.php delete mode 100644 bundled-libs/zendframework/zend-db/Zend/Db/composer.json create mode 100644 bundled-libs/zendframework/zend-db/composer.json create mode 100644 bundled-libs/zendframework/zend-db/docs/CODE_OF_CONDUCT.md create mode 100644 bundled-libs/zendframework/zend-db/docs/CONTRIBUTING.md create mode 100644 bundled-libs/zendframework/zend-db/docs/ISSUE_TEMPLATE.md create mode 100644 bundled-libs/zendframework/zend-db/docs/PULL_REQUEST_TEMPLATE.md create mode 100644 bundled-libs/zendframework/zend-db/docs/SUPPORT.md create mode 100644 bundled-libs/zendframework/zend-db/docs/book/adapter.md create mode 100644 bundled-libs/zendframework/zend-db/docs/book/index.html create mode 100644 bundled-libs/zendframework/zend-db/docs/book/metadata.md create mode 100644 bundled-libs/zendframework/zend-db/docs/book/result-set.md create mode 100644 bundled-libs/zendframework/zend-db/docs/book/row-gateway.md create mode 100644 bundled-libs/zendframework/zend-db/docs/book/sql-ddl.md create mode 100644 bundled-libs/zendframework/zend-db/docs/book/sql.md create mode 100644 bundled-libs/zendframework/zend-db/docs/book/table-gateway.md create mode 100644 bundled-libs/zendframework/zend-db/phpcs.xml rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Adapter.php (73%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/AdapterAbstractServiceFactory.php (50%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/AdapterAwareInterface.php (88%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/AdapterAwareTrait.php (83%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/AdapterInterface.php (90%) create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/AdapterServiceFactory.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Driver/AbstractConnection.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/ConnectionInterface.php (95%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/DriverInterface.php (95%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Feature/AbstractFeature.php (91%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Feature/DriverFeatureInterface.php (92%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/IbmDb2/Connection.php (51%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/IbmDb2/IbmDb2.php (92%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/IbmDb2/Result.php (96%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/IbmDb2/Statement.php (71%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Mysqli/Connection.php (60%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Mysqli/Mysqli.php (89%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Mysqli/Result.php (90%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Mysqli/Statement.php (89%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Oci8/Connection.php (59%) create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Feature/RowCounter.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Oci8/Oci8.php (63%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Oci8/Result.php (79%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Oci8/Statement.php (80%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pdo/Connection.php (63%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pdo/Feature/OracleRowCounter.php (76%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php (76%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pdo/Pdo.php (82%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pdo/Result.php (80%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pdo/Statement.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pgsql/Connection.php (58%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pgsql/Pgsql.php (82%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pgsql/Result.php (94%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Pgsql/Statement.php (89%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/ResultInterface.php (94%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Sqlsrv/Connection.php (68%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Sqlsrv/Exception/ErrorException.php (87%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Sqlsrv/Result.php (96%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Sqlsrv/Sqlsrv.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/Sqlsrv/Statement.php (78%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Driver/StatementInterface.php (83%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Exception/ErrorException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Exception/ExceptionInterface.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Exception/InvalidArgumentException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Exception/InvalidConnectionParametersException.php (91%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Exception/InvalidQueryException.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Exception/RuntimeException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Exception/UnexpectedValueException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/ParameterContainer.php (67%) create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/AbstractPlatform.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/IbmDb2.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/Mysql.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/Oracle.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Platform/PlatformInterface.php (95%) create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/Postgresql.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sql92.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/SqlServer.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sqlite.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/Profiler/Profiler.php (65%) create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Profiler/ProfilerAwareInterface.php create mode 100644 bundled-libs/zendframework/zend-db/src/Adapter/Profiler/ProfilerInterface.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/StatementContainer.php (90%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Adapter/StatementContainerInterface.php (93%) create mode 100644 bundled-libs/zendframework/zend-db/src/ConfigProvider.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Exception/ErrorException.php (84%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Exception/ExceptionInterface.php (82%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Exception/InvalidArgumentException.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Exception/RuntimeException.php (84%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Exception/UnexpectedValueException.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Metadata.php (50%) create mode 100644 bundled-libs/zendframework/zend-db/src/Metadata/MetadataInterface.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Object/AbstractTableObject.php (96%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Object/ColumnObject.php (90%) create mode 100644 bundled-libs/zendframework/zend-db/src/Metadata/Object/ConstraintKeyObject.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Object/ConstraintObject.php (92%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Object/TableObject.php (83%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Object/TriggerObject.php (90%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Object/ViewObject.php (87%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Source/AbstractSource.php (81%) create mode 100644 bundled-libs/zendframework/zend-db/src/Metadata/Source/Factory.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Source/MysqlMetadata.php (52%) create mode 100644 bundled-libs/zendframework/zend-db/src/Metadata/Source/OracleMetadata.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Source/PostgresqlMetadata.php (58%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Source/SqlServerMetadata.php (52%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Metadata/Source/SqliteMetadata.php (83%) create mode 100644 bundled-libs/zendframework/zend-db/src/Module.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/ResultSet/AbstractResultSet.php (83%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/ResultSet/Exception/ExceptionInterface.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/ResultSet/Exception/InvalidArgumentException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/ResultSet/Exception/RuntimeException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/ResultSet/HydratingResultSet.php (76%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/ResultSet/ResultSet.php (75%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/ResultSet/ResultSetInterface.php (82%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/AbstractRowGateway.php (81%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/Exception/ExceptionInterface.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/Exception/InvalidArgumentException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/Exception/RuntimeException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/Feature/AbstractFeature.php (90%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/Feature/FeatureSet.php (83%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/RowGateway.php (79%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/RowGateway/RowGatewayInterface.php (85%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/AbstractExpression.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/AbstractPreparableSql.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/AbstractSql.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Combine.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/AlterTable.php (58%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractLengthColumn.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractPrecisionColumn.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractTimestampColumn.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/Column/BigInteger.php (85%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Binary.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Blob.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Boolean.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Char.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/Column/Column.php (61%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/Column/ColumnInterface.php (59%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Date.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Datetime.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Decimal.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Float.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Floating.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Integer.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Text.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Time.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Timestamp.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Varbinary.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Varchar.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/AbstractConstraint.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/Constraint/Check.php (56%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/Constraint/ConstraintInterface.php (86%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/ForeignKey.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/PrimaryKey.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/UniqueKey.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/CreateTable.php (51%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/DropTable.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Index/AbstractIndex.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Ddl/Index/Index.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Ddl/SqlInterface.php (85%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Delete.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Exception/ExceptionInterface.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Exception/InvalidArgumentException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Exception/RuntimeException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Expression.php (52%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/ExpressionInterface.php (88%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Having.php (82%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Insert.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Join.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Literal.php (62%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/AbstractPlatform.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/IbmDb2.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/SelectDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Platform/Mysql/Mysql.php (78%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/SelectDecorator.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Platform/Oracle/Oracle.php (89%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/Oracle/SelectDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/Platform.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Platform/PlatformDecoratorInterface.php (73%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Platform/SqlServer/SelectDecorator.php (61%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Platform/SqlServer/SqlServer.php (77%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/SelectDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/Sqlite.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/Between.php (78%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/Expression.php (59%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Predicate/In.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/IsNotNull.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/IsNull.php (78%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/Like.php (66%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Predicate/Literal.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Predicate/NotBetween.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/NotIn.php (63%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Predicate/NotLike.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/Operator.php (65%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/Predicate.php (72%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Predicate/PredicateInterface.php (85%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Predicate/PredicateSet.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/PreparableSqlInterface.php (83%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Select.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Sql.php (61%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/SqlInterface.php (67%) create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/TableIdentifier.php create mode 100644 bundled-libs/zendframework/zend-db/src/Sql/Update.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/Sql/Where.php (82%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/AbstractTableGateway.php (66%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Exception/ExceptionInterface.php (85%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Exception/InvalidArgumentException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Exception/RuntimeException.php (86%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/AbstractFeature.php (92%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/EventFeature.php (74%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/EventFeature/TableGatewayEvent.php (96%) create mode 100644 bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeatureEventsInterface.php rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/FeatureSet.php (67%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/GlobalAdapterFeature.php (93%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/MasterSlaveFeature.php (94%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/MetadataFeature.php (76%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/RowGatewayFeature.php (68%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/Feature/SequenceFeature.php (84%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/TableGateway.php (58%) rename bundled-libs/zendframework/zend-db/{Zend/Db => src}/TableGateway/TableGatewayInterface.php (88%) create mode 100644 bundled-libs/zendframework/zend-db/test/autoload.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/ConnectionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TraitSetup.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/MysqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/PostgresqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqlServerTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqliteTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/IntegrationTestListener.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Platform/FixtureLoader.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Platform/MysqlFixtureLoader.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/Platform/PgsqlFixtureLoader.php create mode 100644 bundled-libs/zendframework/zend-db/test/integration/TestFixtures/mysql.sql create mode 100644 bundled-libs/zendframework/zend-db/test/integration/TestFixtures/pgsql.sql create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAwareTraitTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterServiceFactoryTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Mysqli/ConnectionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8Test.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/PdoTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ResultTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/TestAsset/PdoMock.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/ParameterContainerTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/IbmDb2Test.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/MysqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/OracleTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/PostgresqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/Sql92Test.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqlServerTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqliteTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/_files/.gitkeep create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Adapter/Profiler/ProfilerTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/ConfigProviderTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/AbstractSourceTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/FactoryTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/OracleMetadataTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/SqliteMetadataTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/ResultSet/ResultSetIntegrationTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/RowGateway/AbstractRowGatewayTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/RowGateway/RowGatewayTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/AbstractSqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/CombineTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/AlterTableTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BigIntegerTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BinaryTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BlobTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BooleanTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/CharTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/ColumnTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DateTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DatetimeTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DecimalTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatingTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/IntegerTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TextTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimeTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimestampTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarbinaryTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarcharTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/CheckTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/CreateTableTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/DropTableTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Index/IndexTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/DeleteTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/ExpressionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/InsertTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/JoinTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/LiteralTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/MysqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/OracleTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/PlatformTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SqlServerTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SqliteTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/BetweenTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/ExpressionTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/InTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/IsNullTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LikeTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LiteralTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotBetweenTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotInTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotLikeTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/OperatorTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateSetTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/SelectTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/SqlFunctionalTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/SqlTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/TableIdentifierTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/Sql/UpdateTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TableGateway/AbstractTableGatewayTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/EventFeatureTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/FeatureSetTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MetadataFeatureTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/SequenceFeatureTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TableGateway/TableGatewayTest.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/ConnectionWrapper.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteIgnore.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/InsertDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/PdoStubDriver.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/Replace.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/SelectDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/TemporaryResultSet.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingMysqlPlatform.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingOraclePlatform.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSql92Platform.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSqlServerPlatform.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateDecorator.php create mode 100644 bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateIgnore.php create mode 100644 bundled-libs/zendframework/zend-stdlib/CHANGELOG.md create mode 100644 bundled-libs/zendframework/zend-stdlib/LICENSE.md create mode 100644 bundled-libs/zendframework/zend-stdlib/README.md create mode 100644 bundled-libs/zendframework/zend-stdlib/benchmark/ExtractPriorityQueueBench.php create mode 100644 bundled-libs/zendframework/zend-stdlib/benchmark/InsertPriorityQueueBench.php create mode 100644 bundled-libs/zendframework/zend-stdlib/benchmark/RemovePriorityQueueBench.php create mode 100644 bundled-libs/zendframework/zend-stdlib/composer.json create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/CODE_OF_CONDUCT.md create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/CONTRIBUTING.md create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/ISSUE_TEMPLATE.md create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/PULL_REQUEST_TEMPLATE.md create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/SUPPORT.md create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/book/console-helper.md create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/book/index.html create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/book/migration.md create mode 100644 bundled-libs/zendframework/zend-stdlib/docs/bookdown.json create mode 100644 bundled-libs/zendframework/zend-stdlib/src/AbstractOptions.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ArrayObject.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ArraySerializableInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ArrayStack.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ArrayUtils.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeRemoveKey.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKey.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKeyInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ConsoleHelper.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/DispatchableInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ErrorHandler.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Exception/BadMethodCallException.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Exception/DomainException.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Exception/ExceptionInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Exception/ExtensionNotLoadedException.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Exception/InvalidArgumentException.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Exception/LogicException.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Exception/RuntimeException.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/FastPriorityQueue.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Glob.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Guard/AllGuardsTrait.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Guard/ArrayOrTraversableGuardTrait.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Guard/EmptyGuardTrait.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Guard/NullGuardTrait.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/InitializableInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/JsonSerializable.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Message.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/MessageInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ParameterObjectInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Parameters.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ParametersInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/PriorityList.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/PriorityQueue.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Request.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/RequestInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/Response.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/ResponseInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/SplPriorityQueue.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/SplQueue.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/SplStack.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/StringUtils.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Iconv.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Intl.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/StringWrapper/MbString.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Native.php create mode 100644 bundled-libs/zendframework/zend-stdlib/src/StringWrapper/StringWrapperInterface.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/ArrayObjectTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/ArrayUtilsTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/ConsoleHelperTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/ErrorHandlerTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/FastPriorityQueueTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/GlobTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/Guard/ArrayOrTraversableGuardTraitTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/Guard/EmptyGuardTraitTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/Guard/NullGuardTraitTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/MessageTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/OptionsTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/ParametersTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/PriorityListTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/PriorityQueueTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/SplPriorityQueueTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/SplQueueTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/SplStackTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/StringUtilsTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/StringWrapper/CommonStringWrapperTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IconvTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IntlTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/StringWrapper/MbStringTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/StringWrapper/NativeTest.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectIterator.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectObjectCount.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectObjectVars.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArraySerializable.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/GuardedObject.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptions.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsDerived.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsNoStrict.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsWithoutGetter.php create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/alpha create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/beta create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/delta create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/eta.alpha create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/eta.beta create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/gamma create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/zeta.alpha create mode 100644 bundled-libs/zendframework/zend-stdlib/test/_files/zeta.beta diff --git a/.gitignore b/.gitignore index 2a9aa49c..b3ce8ba3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,13 @@ +# application stuff uploads/* templates_c/* serendipity_config_local.inc.php +plugins/additional_plugins* + +# php stuff +composer.lock + +# ide / dev stuff .cvsignore .htaccess* *.db @@ -8,7 +15,6 @@ private/* archives/* *~ DEADJOE -plugins/additional_plugins* /.settings /.buildpath /.project diff --git a/bundled-libs/autoload.php b/bundled-libs/autoload.php index 2d714c76..5c877fcb 100644 --- a/bundled-libs/autoload.php +++ b/bundled-libs/autoload.php @@ -1,7 +1,7 @@ classMapAuthoritative; } + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + /** * Registers this instance as an autoloader. * @@ -313,29 +334,34 @@ class ClassLoader */ public function findFile($class) { - // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 - if ('\\' == $class[0]) { - $class = substr($class, 1); - } - // class map lookup if (isset($this->classMap[$class])) { return $this->classMap[$class]; } - if ($this->classMapAuthoritative) { + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { return false; } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } $file = $this->findFileWithExtension($class, '.php'); // Search for Hack files if we are running on HHVM - if ($file === null && defined('HHVM_VERSION')) { + if (false === $file && defined('HHVM_VERSION')) { $file = $this->findFileWithExtension($class, '.hh'); } - if ($file === null) { + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { // Remember that this class does not exist. - return $this->classMap[$class] = false; + $this->missingClasses[$class] = true; } return $file; @@ -348,10 +374,14 @@ class ClassLoader $first = $class[0]; if (isset($this->prefixLengthsPsr4[$first])) { - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { - if (0 === strpos($class, $prefix)) { - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { return $file; } } @@ -399,6 +429,8 @@ class ClassLoader if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { return $file; } + + return false; } } diff --git a/bundled-libs/composer/LICENSE b/bundled-libs/composer/LICENSE index 1a281248..f27399a0 100644 --- a/bundled-libs/composer/LICENSE +++ b/bundled-libs/composer/LICENSE @@ -1,5 +1,5 @@ -Copyright (c) 2016 Nils Adermann, Jordi Boggiano +Copyright (c) Nils Adermann, Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/bundled-libs/composer/autoload_classmap.php b/bundled-libs/composer/autoload_classmap.php index 7532b0c0..cecd36ce 100644 --- a/bundled-libs/composer/autoload_classmap.php +++ b/bundled-libs/composer/autoload_classmap.php @@ -7,4 +7,288 @@ $baseDir = dirname($vendorDir); return array( 'Katzgrau\\KLogger\\Logger' => $vendorDir . '/katzgrau/klogger/src/Logger.php', + 'Psr\\Log\\AbstractLogger' => $vendorDir . '/psr/log/Psr/Log/AbstractLogger.php', + 'Psr\\Log\\InvalidArgumentException' => $vendorDir . '/psr/log/Psr/Log/InvalidArgumentException.php', + 'Psr\\Log\\LogLevel' => $vendorDir . '/psr/log/Psr/Log/LogLevel.php', + 'Psr\\Log\\LoggerAwareInterface' => $vendorDir . '/psr/log/Psr/Log/LoggerAwareInterface.php', + 'Psr\\Log\\LoggerAwareTrait' => $vendorDir . '/psr/log/Psr/Log/LoggerAwareTrait.php', + 'Psr\\Log\\LoggerInterface' => $vendorDir . '/psr/log/Psr/Log/LoggerInterface.php', + 'Psr\\Log\\LoggerTrait' => $vendorDir . '/psr/log/Psr/Log/LoggerTrait.php', + 'Psr\\Log\\NullLogger' => $vendorDir . '/psr/log/Psr/Log/NullLogger.php', + 'Psr\\Log\\Test\\DummyTest' => $vendorDir . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php', + 'Psr\\Log\\Test\\LoggerInterfaceTest' => $vendorDir . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php', + 'Psr\\SimpleCache\\CacheException' => $vendorDir . '/psr/simple-cache/src/CacheException.php', + 'Psr\\SimpleCache\\CacheInterface' => $vendorDir . '/psr/simple-cache/src/CacheInterface.php', + 'Psr\\SimpleCache\\InvalidArgumentException' => $vendorDir . '/psr/simple-cache/src/InvalidArgumentException.php', + 'Zend\\Db\\Adapter\\Adapter' => $vendorDir . '/zendframework/zend-db/src/Adapter/Adapter.php', + 'Zend\\Db\\Adapter\\AdapterAbstractServiceFactory' => $vendorDir . '/zendframework/zend-db/src/Adapter/AdapterAbstractServiceFactory.php', + 'Zend\\Db\\Adapter\\AdapterAwareInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/AdapterAwareInterface.php', + 'Zend\\Db\\Adapter\\AdapterAwareTrait' => $vendorDir . '/zendframework/zend-db/src/Adapter/AdapterAwareTrait.php', + 'Zend\\Db\\Adapter\\AdapterInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/AdapterInterface.php', + 'Zend\\Db\\Adapter\\AdapterServiceFactory' => $vendorDir . '/zendframework/zend-db/src/Adapter/AdapterServiceFactory.php', + 'Zend\\Db\\Adapter\\Driver\\AbstractConnection' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/AbstractConnection.php', + 'Zend\\Db\\Adapter\\Driver\\ConnectionInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/ConnectionInterface.php', + 'Zend\\Db\\Adapter\\Driver\\DriverInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/DriverInterface.php', + 'Zend\\Db\\Adapter\\Driver\\Feature\\AbstractFeature' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Feature/AbstractFeature.php', + 'Zend\\Db\\Adapter\\Driver\\Feature\\DriverFeatureInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Feature/DriverFeatureInterface.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\Connection' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\IbmDb2' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/IbmDb2.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\Result' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Result.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Connection' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Mysqli' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Mysqli.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Result' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Statement' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Connection' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Feature\\RowCounter' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Feature/RowCounter.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Oci8' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Oci8.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Result' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Statement' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Connection' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Feature\\OracleRowCounter' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/OracleRowCounter.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Feature\\SqliteRowCounter' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Pdo' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Pdo.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Result' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Statement' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Connection' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Pgsql' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Pgsql.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Result' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Statement' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\ResultInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/ResultInterface.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Connection' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Exception\\ErrorException' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ErrorException.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Result' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Sqlsrv' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Sqlsrv.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\StatementInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Driver/StatementInterface.php', + 'Zend\\Db\\Adapter\\Exception\\ErrorException' => $vendorDir . '/zendframework/zend-db/src/Adapter/Exception/ErrorException.php', + 'Zend\\Db\\Adapter\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Exception/ExceptionInterface.php', + 'Zend\\Db\\Adapter\\Exception\\InvalidArgumentException' => $vendorDir . '/zendframework/zend-db/src/Adapter/Exception/InvalidArgumentException.php', + 'Zend\\Db\\Adapter\\Exception\\InvalidConnectionParametersException' => $vendorDir . '/zendframework/zend-db/src/Adapter/Exception/InvalidConnectionParametersException.php', + 'Zend\\Db\\Adapter\\Exception\\InvalidQueryException' => $vendorDir . '/zendframework/zend-db/src/Adapter/Exception/InvalidQueryException.php', + 'Zend\\Db\\Adapter\\Exception\\RuntimeException' => $vendorDir . '/zendframework/zend-db/src/Adapter/Exception/RuntimeException.php', + 'Zend\\Db\\Adapter\\Exception\\UnexpectedValueException' => $vendorDir . '/zendframework/zend-db/src/Adapter/Exception/UnexpectedValueException.php', + 'Zend\\Db\\Adapter\\ParameterContainer' => $vendorDir . '/zendframework/zend-db/src/Adapter/ParameterContainer.php', + 'Zend\\Db\\Adapter\\Platform\\AbstractPlatform' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/AbstractPlatform.php', + 'Zend\\Db\\Adapter\\Platform\\IbmDb2' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/IbmDb2.php', + 'Zend\\Db\\Adapter\\Platform\\Mysql' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/Mysql.php', + 'Zend\\Db\\Adapter\\Platform\\Oracle' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/Oracle.php', + 'Zend\\Db\\Adapter\\Platform\\PlatformInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/PlatformInterface.php', + 'Zend\\Db\\Adapter\\Platform\\Postgresql' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/Postgresql.php', + 'Zend\\Db\\Adapter\\Platform\\Sql92' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/Sql92.php', + 'Zend\\Db\\Adapter\\Platform\\SqlServer' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/SqlServer.php', + 'Zend\\Db\\Adapter\\Platform\\Sqlite' => $vendorDir . '/zendframework/zend-db/src/Adapter/Platform/Sqlite.php', + 'Zend\\Db\\Adapter\\Profiler\\Profiler' => $vendorDir . '/zendframework/zend-db/src/Adapter/Profiler/Profiler.php', + 'Zend\\Db\\Adapter\\Profiler\\ProfilerAwareInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Profiler/ProfilerAwareInterface.php', + 'Zend\\Db\\Adapter\\Profiler\\ProfilerInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/Profiler/ProfilerInterface.php', + 'Zend\\Db\\Adapter\\StatementContainer' => $vendorDir . '/zendframework/zend-db/src/Adapter/StatementContainer.php', + 'Zend\\Db\\Adapter\\StatementContainerInterface' => $vendorDir . '/zendframework/zend-db/src/Adapter/StatementContainerInterface.php', + 'Zend\\Db\\ConfigProvider' => $vendorDir . '/zendframework/zend-db/src/ConfigProvider.php', + 'Zend\\Db\\Exception\\ErrorException' => $vendorDir . '/zendframework/zend-db/src/Exception/ErrorException.php', + 'Zend\\Db\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-db/src/Exception/ExceptionInterface.php', + 'Zend\\Db\\Exception\\InvalidArgumentException' => $vendorDir . '/zendframework/zend-db/src/Exception/InvalidArgumentException.php', + 'Zend\\Db\\Exception\\RuntimeException' => $vendorDir . '/zendframework/zend-db/src/Exception/RuntimeException.php', + 'Zend\\Db\\Exception\\UnexpectedValueException' => $vendorDir . '/zendframework/zend-db/src/Exception/UnexpectedValueException.php', + 'Zend\\Db\\Metadata\\Metadata' => $vendorDir . '/zendframework/zend-db/src/Metadata/Metadata.php', + 'Zend\\Db\\Metadata\\MetadataInterface' => $vendorDir . '/zendframework/zend-db/src/Metadata/MetadataInterface.php', + 'Zend\\Db\\Metadata\\Object\\AbstractTableObject' => $vendorDir . '/zendframework/zend-db/src/Metadata/Object/AbstractTableObject.php', + 'Zend\\Db\\Metadata\\Object\\ColumnObject' => $vendorDir . '/zendframework/zend-db/src/Metadata/Object/ColumnObject.php', + 'Zend\\Db\\Metadata\\Object\\ConstraintKeyObject' => $vendorDir . '/zendframework/zend-db/src/Metadata/Object/ConstraintKeyObject.php', + 'Zend\\Db\\Metadata\\Object\\ConstraintObject' => $vendorDir . '/zendframework/zend-db/src/Metadata/Object/ConstraintObject.php', + 'Zend\\Db\\Metadata\\Object\\TableObject' => $vendorDir . '/zendframework/zend-db/src/Metadata/Object/TableObject.php', + 'Zend\\Db\\Metadata\\Object\\TriggerObject' => $vendorDir . '/zendframework/zend-db/src/Metadata/Object/TriggerObject.php', + 'Zend\\Db\\Metadata\\Object\\ViewObject' => $vendorDir . '/zendframework/zend-db/src/Metadata/Object/ViewObject.php', + 'Zend\\Db\\Metadata\\Source\\AbstractSource' => $vendorDir . '/zendframework/zend-db/src/Metadata/Source/AbstractSource.php', + 'Zend\\Db\\Metadata\\Source\\Factory' => $vendorDir . '/zendframework/zend-db/src/Metadata/Source/Factory.php', + 'Zend\\Db\\Metadata\\Source\\MysqlMetadata' => $vendorDir . '/zendframework/zend-db/src/Metadata/Source/MysqlMetadata.php', + 'Zend\\Db\\Metadata\\Source\\OracleMetadata' => $vendorDir . '/zendframework/zend-db/src/Metadata/Source/OracleMetadata.php', + 'Zend\\Db\\Metadata\\Source\\PostgresqlMetadata' => $vendorDir . '/zendframework/zend-db/src/Metadata/Source/PostgresqlMetadata.php', + 'Zend\\Db\\Metadata\\Source\\SqlServerMetadata' => $vendorDir . '/zendframework/zend-db/src/Metadata/Source/SqlServerMetadata.php', + 'Zend\\Db\\Metadata\\Source\\SqliteMetadata' => $vendorDir . '/zendframework/zend-db/src/Metadata/Source/SqliteMetadata.php', + 'Zend\\Db\\Module' => $vendorDir . '/zendframework/zend-db/src/Module.php', + 'Zend\\Db\\ResultSet\\AbstractResultSet' => $vendorDir . '/zendframework/zend-db/src/ResultSet/AbstractResultSet.php', + 'Zend\\Db\\ResultSet\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-db/src/ResultSet/Exception/ExceptionInterface.php', + 'Zend\\Db\\ResultSet\\Exception\\InvalidArgumentException' => $vendorDir . '/zendframework/zend-db/src/ResultSet/Exception/InvalidArgumentException.php', + 'Zend\\Db\\ResultSet\\Exception\\RuntimeException' => $vendorDir . '/zendframework/zend-db/src/ResultSet/Exception/RuntimeException.php', + 'Zend\\Db\\ResultSet\\HydratingResultSet' => $vendorDir . '/zendframework/zend-db/src/ResultSet/HydratingResultSet.php', + 'Zend\\Db\\ResultSet\\ResultSet' => $vendorDir . '/zendframework/zend-db/src/ResultSet/ResultSet.php', + 'Zend\\Db\\ResultSet\\ResultSetInterface' => $vendorDir . '/zendframework/zend-db/src/ResultSet/ResultSetInterface.php', + 'Zend\\Db\\RowGateway\\AbstractRowGateway' => $vendorDir . '/zendframework/zend-db/src/RowGateway/AbstractRowGateway.php', + 'Zend\\Db\\RowGateway\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-db/src/RowGateway/Exception/ExceptionInterface.php', + 'Zend\\Db\\RowGateway\\Exception\\InvalidArgumentException' => $vendorDir . '/zendframework/zend-db/src/RowGateway/Exception/InvalidArgumentException.php', + 'Zend\\Db\\RowGateway\\Exception\\RuntimeException' => $vendorDir . '/zendframework/zend-db/src/RowGateway/Exception/RuntimeException.php', + 'Zend\\Db\\RowGateway\\Feature\\AbstractFeature' => $vendorDir . '/zendframework/zend-db/src/RowGateway/Feature/AbstractFeature.php', + 'Zend\\Db\\RowGateway\\Feature\\FeatureSet' => $vendorDir . '/zendframework/zend-db/src/RowGateway/Feature/FeatureSet.php', + 'Zend\\Db\\RowGateway\\RowGateway' => $vendorDir . '/zendframework/zend-db/src/RowGateway/RowGateway.php', + 'Zend\\Db\\RowGateway\\RowGatewayInterface' => $vendorDir . '/zendframework/zend-db/src/RowGateway/RowGatewayInterface.php', + 'Zend\\Db\\Sql\\AbstractExpression' => $vendorDir . '/zendframework/zend-db/src/Sql/AbstractExpression.php', + 'Zend\\Db\\Sql\\AbstractPreparableSql' => $vendorDir . '/zendframework/zend-db/src/Sql/AbstractPreparableSql.php', + 'Zend\\Db\\Sql\\AbstractSql' => $vendorDir . '/zendframework/zend-db/src/Sql/AbstractSql.php', + 'Zend\\Db\\Sql\\Combine' => $vendorDir . '/zendframework/zend-db/src/Sql/Combine.php', + 'Zend\\Db\\Sql\\Ddl\\AlterTable' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/AlterTable.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\AbstractLengthColumn' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/AbstractLengthColumn.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\AbstractPrecisionColumn' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/AbstractPrecisionColumn.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\AbstractTimestampColumn' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/AbstractTimestampColumn.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\BigInteger' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/BigInteger.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Binary' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Binary.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Blob' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Blob.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Boolean' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Boolean.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Char' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Char.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Column' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Column.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\ColumnInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/ColumnInterface.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Date' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Date.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Datetime' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Datetime.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Decimal' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Decimal.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Float' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Float.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Floating' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Floating.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Integer' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Integer.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Text' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Text.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Time' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Time.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Timestamp' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Timestamp.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Varbinary' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Varbinary.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Varchar' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Column/Varchar.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\AbstractConstraint' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Constraint/AbstractConstraint.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\Check' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Constraint/Check.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\ConstraintInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Constraint/ConstraintInterface.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\ForeignKey' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Constraint/ForeignKey.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\PrimaryKey' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Constraint/PrimaryKey.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\UniqueKey' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Constraint/UniqueKey.php', + 'Zend\\Db\\Sql\\Ddl\\CreateTable' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/CreateTable.php', + 'Zend\\Db\\Sql\\Ddl\\DropTable' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/DropTable.php', + 'Zend\\Db\\Sql\\Ddl\\Index\\AbstractIndex' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Index/AbstractIndex.php', + 'Zend\\Db\\Sql\\Ddl\\Index\\Index' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/Index/Index.php', + 'Zend\\Db\\Sql\\Ddl\\SqlInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/Ddl/SqlInterface.php', + 'Zend\\Db\\Sql\\Delete' => $vendorDir . '/zendframework/zend-db/src/Sql/Delete.php', + 'Zend\\Db\\Sql\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/Exception/ExceptionInterface.php', + 'Zend\\Db\\Sql\\Exception\\InvalidArgumentException' => $vendorDir . '/zendframework/zend-db/src/Sql/Exception/InvalidArgumentException.php', + 'Zend\\Db\\Sql\\Exception\\RuntimeException' => $vendorDir . '/zendframework/zend-db/src/Sql/Exception/RuntimeException.php', + 'Zend\\Db\\Sql\\Expression' => $vendorDir . '/zendframework/zend-db/src/Sql/Expression.php', + 'Zend\\Db\\Sql\\ExpressionInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/ExpressionInterface.php', + 'Zend\\Db\\Sql\\Having' => $vendorDir . '/zendframework/zend-db/src/Sql/Having.php', + 'Zend\\Db\\Sql\\Insert' => $vendorDir . '/zendframework/zend-db/src/Sql/Insert.php', + 'Zend\\Db\\Sql\\Join' => $vendorDir . '/zendframework/zend-db/src/Sql/Join.php', + 'Zend\\Db\\Sql\\Literal' => $vendorDir . '/zendframework/zend-db/src/Sql/Literal.php', + 'Zend\\Db\\Sql\\Platform\\AbstractPlatform' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/AbstractPlatform.php', + 'Zend\\Db\\Sql\\Platform\\IbmDb2\\IbmDb2' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/IbmDb2/IbmDb2.php', + 'Zend\\Db\\Sql\\Platform\\IbmDb2\\SelectDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/IbmDb2/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\Ddl\\AlterTableDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\Ddl\\CreateTableDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\Mysql' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Mysql/Mysql.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\SelectDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Mysql/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Oracle\\Oracle' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Oracle/Oracle.php', + 'Zend\\Db\\Sql\\Platform\\Oracle\\SelectDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Oracle/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Platform' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Platform.php', + 'Zend\\Db\\Sql\\Platform\\PlatformDecoratorInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/PlatformDecoratorInterface.php', + 'Zend\\Db\\Sql\\Platform\\SqlServer\\Ddl\\CreateTableDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php', + 'Zend\\Db\\Sql\\Platform\\SqlServer\\SelectDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/SqlServer/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\SqlServer\\SqlServer' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/SqlServer/SqlServer.php', + 'Zend\\Db\\Sql\\Platform\\Sqlite\\SelectDecorator' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Sqlite/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Sqlite\\Sqlite' => $vendorDir . '/zendframework/zend-db/src/Sql/Platform/Sqlite/Sqlite.php', + 'Zend\\Db\\Sql\\Predicate\\Between' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/Between.php', + 'Zend\\Db\\Sql\\Predicate\\Expression' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/Expression.php', + 'Zend\\Db\\Sql\\Predicate\\In' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/In.php', + 'Zend\\Db\\Sql\\Predicate\\IsNotNull' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/IsNotNull.php', + 'Zend\\Db\\Sql\\Predicate\\IsNull' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/IsNull.php', + 'Zend\\Db\\Sql\\Predicate\\Like' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/Like.php', + 'Zend\\Db\\Sql\\Predicate\\Literal' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/Literal.php', + 'Zend\\Db\\Sql\\Predicate\\NotBetween' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/NotBetween.php', + 'Zend\\Db\\Sql\\Predicate\\NotIn' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/NotIn.php', + 'Zend\\Db\\Sql\\Predicate\\NotLike' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/NotLike.php', + 'Zend\\Db\\Sql\\Predicate\\Operator' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/Operator.php', + 'Zend\\Db\\Sql\\Predicate\\Predicate' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/Predicate.php', + 'Zend\\Db\\Sql\\Predicate\\PredicateInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/PredicateInterface.php', + 'Zend\\Db\\Sql\\Predicate\\PredicateSet' => $vendorDir . '/zendframework/zend-db/src/Sql/Predicate/PredicateSet.php', + 'Zend\\Db\\Sql\\PreparableSqlInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/PreparableSqlInterface.php', + 'Zend\\Db\\Sql\\Select' => $vendorDir . '/zendframework/zend-db/src/Sql/Select.php', + 'Zend\\Db\\Sql\\Sql' => $vendorDir . '/zendframework/zend-db/src/Sql/Sql.php', + 'Zend\\Db\\Sql\\SqlInterface' => $vendorDir . '/zendframework/zend-db/src/Sql/SqlInterface.php', + 'Zend\\Db\\Sql\\TableIdentifier' => $vendorDir . '/zendframework/zend-db/src/Sql/TableIdentifier.php', + 'Zend\\Db\\Sql\\Update' => $vendorDir . '/zendframework/zend-db/src/Sql/Update.php', + 'Zend\\Db\\Sql\\Where' => $vendorDir . '/zendframework/zend-db/src/Sql/Where.php', + 'Zend\\Db\\TableGateway\\AbstractTableGateway' => $vendorDir . '/zendframework/zend-db/src/TableGateway/AbstractTableGateway.php', + 'Zend\\Db\\TableGateway\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Exception/ExceptionInterface.php', + 'Zend\\Db\\TableGateway\\Exception\\InvalidArgumentException' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Exception/InvalidArgumentException.php', + 'Zend\\Db\\TableGateway\\Exception\\RuntimeException' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Exception/RuntimeException.php', + 'Zend\\Db\\TableGateway\\Feature\\AbstractFeature' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/AbstractFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\EventFeature' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/EventFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\EventFeatureEventsInterface' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/EventFeatureEventsInterface.php', + 'Zend\\Db\\TableGateway\\Feature\\EventFeature\\TableGatewayEvent' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/EventFeature/TableGatewayEvent.php', + 'Zend\\Db\\TableGateway\\Feature\\FeatureSet' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/FeatureSet.php', + 'Zend\\Db\\TableGateway\\Feature\\GlobalAdapterFeature' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/GlobalAdapterFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\MasterSlaveFeature' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/MasterSlaveFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\MetadataFeature' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/MetadataFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\RowGatewayFeature' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/RowGatewayFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\SequenceFeature' => $vendorDir . '/zendframework/zend-db/src/TableGateway/Feature/SequenceFeature.php', + 'Zend\\Db\\TableGateway\\TableGateway' => $vendorDir . '/zendframework/zend-db/src/TableGateway/TableGateway.php', + 'Zend\\Db\\TableGateway\\TableGatewayInterface' => $vendorDir . '/zendframework/zend-db/src/TableGateway/TableGatewayInterface.php', + 'Zend\\Stdlib\\AbstractOptions' => $vendorDir . '/zendframework/zend-stdlib/src/AbstractOptions.php', + 'Zend\\Stdlib\\ArrayObject' => $vendorDir . '/zendframework/zend-stdlib/src/ArrayObject.php', + 'Zend\\Stdlib\\ArraySerializableInterface' => $vendorDir . '/zendframework/zend-stdlib/src/ArraySerializableInterface.php', + 'Zend\\Stdlib\\ArrayStack' => $vendorDir . '/zendframework/zend-stdlib/src/ArrayStack.php', + 'Zend\\Stdlib\\ArrayUtils' => $vendorDir . '/zendframework/zend-stdlib/src/ArrayUtils.php', + 'Zend\\Stdlib\\ArrayUtils\\MergeRemoveKey' => $vendorDir . '/zendframework/zend-stdlib/src/ArrayUtils/MergeRemoveKey.php', + 'Zend\\Stdlib\\ArrayUtils\\MergeReplaceKey' => $vendorDir . '/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKey.php', + 'Zend\\Stdlib\\ArrayUtils\\MergeReplaceKeyInterface' => $vendorDir . '/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKeyInterface.php', + 'Zend\\Stdlib\\ConsoleHelper' => $vendorDir . '/zendframework/zend-stdlib/src/ConsoleHelper.php', + 'Zend\\Stdlib\\DispatchableInterface' => $vendorDir . '/zendframework/zend-stdlib/src/DispatchableInterface.php', + 'Zend\\Stdlib\\ErrorHandler' => $vendorDir . '/zendframework/zend-stdlib/src/ErrorHandler.php', + 'Zend\\Stdlib\\Exception\\BadMethodCallException' => $vendorDir . '/zendframework/zend-stdlib/src/Exception/BadMethodCallException.php', + 'Zend\\Stdlib\\Exception\\DomainException' => $vendorDir . '/zendframework/zend-stdlib/src/Exception/DomainException.php', + 'Zend\\Stdlib\\Exception\\ExceptionInterface' => $vendorDir . '/zendframework/zend-stdlib/src/Exception/ExceptionInterface.php', + 'Zend\\Stdlib\\Exception\\ExtensionNotLoadedException' => $vendorDir . '/zendframework/zend-stdlib/src/Exception/ExtensionNotLoadedException.php', + 'Zend\\Stdlib\\Exception\\InvalidArgumentException' => $vendorDir . '/zendframework/zend-stdlib/src/Exception/InvalidArgumentException.php', + 'Zend\\Stdlib\\Exception\\LogicException' => $vendorDir . '/zendframework/zend-stdlib/src/Exception/LogicException.php', + 'Zend\\Stdlib\\Exception\\RuntimeException' => $vendorDir . '/zendframework/zend-stdlib/src/Exception/RuntimeException.php', + 'Zend\\Stdlib\\FastPriorityQueue' => $vendorDir . '/zendframework/zend-stdlib/src/FastPriorityQueue.php', + 'Zend\\Stdlib\\Glob' => $vendorDir . '/zendframework/zend-stdlib/src/Glob.php', + 'Zend\\Stdlib\\Guard\\AllGuardsTrait' => $vendorDir . '/zendframework/zend-stdlib/src/Guard/AllGuardsTrait.php', + 'Zend\\Stdlib\\Guard\\ArrayOrTraversableGuardTrait' => $vendorDir . '/zendframework/zend-stdlib/src/Guard/ArrayOrTraversableGuardTrait.php', + 'Zend\\Stdlib\\Guard\\EmptyGuardTrait' => $vendorDir . '/zendframework/zend-stdlib/src/Guard/EmptyGuardTrait.php', + 'Zend\\Stdlib\\Guard\\NullGuardTrait' => $vendorDir . '/zendframework/zend-stdlib/src/Guard/NullGuardTrait.php', + 'Zend\\Stdlib\\InitializableInterface' => $vendorDir . '/zendframework/zend-stdlib/src/InitializableInterface.php', + 'Zend\\Stdlib\\JsonSerializable' => $vendorDir . '/zendframework/zend-stdlib/src/JsonSerializable.php', + 'Zend\\Stdlib\\Message' => $vendorDir . '/zendframework/zend-stdlib/src/Message.php', + 'Zend\\Stdlib\\MessageInterface' => $vendorDir . '/zendframework/zend-stdlib/src/MessageInterface.php', + 'Zend\\Stdlib\\ParameterObjectInterface' => $vendorDir . '/zendframework/zend-stdlib/src/ParameterObjectInterface.php', + 'Zend\\Stdlib\\Parameters' => $vendorDir . '/zendframework/zend-stdlib/src/Parameters.php', + 'Zend\\Stdlib\\ParametersInterface' => $vendorDir . '/zendframework/zend-stdlib/src/ParametersInterface.php', + 'Zend\\Stdlib\\PriorityList' => $vendorDir . '/zendframework/zend-stdlib/src/PriorityList.php', + 'Zend\\Stdlib\\PriorityQueue' => $vendorDir . '/zendframework/zend-stdlib/src/PriorityQueue.php', + 'Zend\\Stdlib\\Request' => $vendorDir . '/zendframework/zend-stdlib/src/Request.php', + 'Zend\\Stdlib\\RequestInterface' => $vendorDir . '/zendframework/zend-stdlib/src/RequestInterface.php', + 'Zend\\Stdlib\\Response' => $vendorDir . '/zendframework/zend-stdlib/src/Response.php', + 'Zend\\Stdlib\\ResponseInterface' => $vendorDir . '/zendframework/zend-stdlib/src/ResponseInterface.php', + 'Zend\\Stdlib\\SplPriorityQueue' => $vendorDir . '/zendframework/zend-stdlib/src/SplPriorityQueue.php', + 'Zend\\Stdlib\\SplQueue' => $vendorDir . '/zendframework/zend-stdlib/src/SplQueue.php', + 'Zend\\Stdlib\\SplStack' => $vendorDir . '/zendframework/zend-stdlib/src/SplStack.php', + 'Zend\\Stdlib\\StringUtils' => $vendorDir . '/zendframework/zend-stdlib/src/StringUtils.php', + 'Zend\\Stdlib\\StringWrapper\\AbstractStringWrapper' => $vendorDir . '/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php', + 'Zend\\Stdlib\\StringWrapper\\Iconv' => $vendorDir . '/zendframework/zend-stdlib/src/StringWrapper/Iconv.php', + 'Zend\\Stdlib\\StringWrapper\\Intl' => $vendorDir . '/zendframework/zend-stdlib/src/StringWrapper/Intl.php', + 'Zend\\Stdlib\\StringWrapper\\MbString' => $vendorDir . '/zendframework/zend-stdlib/src/StringWrapper/MbString.php', + 'Zend\\Stdlib\\StringWrapper\\Native' => $vendorDir . '/zendframework/zend-stdlib/src/StringWrapper/Native.php', + 'Zend\\Stdlib\\StringWrapper\\StringWrapperInterface' => $vendorDir . '/zendframework/zend-stdlib/src/StringWrapper/StringWrapperInterface.php', + 'voku\\cache\\AdapterApc' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterApc.php', + 'voku\\cache\\AdapterApcu' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterApcu.php', + 'voku\\cache\\AdapterArray' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterArray.php', + 'voku\\cache\\AdapterFile' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterFile.php', + 'voku\\cache\\AdapterFileAbstract' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterFileAbstract.php', + 'voku\\cache\\AdapterFileSimple' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterFileSimple.php', + 'voku\\cache\\AdapterMemcache' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterMemcache.php', + 'voku\\cache\\AdapterMemcached' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterMemcached.php', + 'voku\\cache\\AdapterOpCache' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterOpCache.php', + 'voku\\cache\\AdapterPredis' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterPredis.php', + 'voku\\cache\\AdapterXcache' => $vendorDir . '/voku/simple-cache/src/voku/cache/AdapterXcache.php', + 'voku\\cache\\Cache' => $vendorDir . '/voku/simple-cache/src/voku/cache/Cache.php', + 'voku\\cache\\CacheAdapterAutoManager' => $vendorDir . '/voku/simple-cache/src/voku/cache/CacheAdapterAutoManager.php', + 'voku\\cache\\CacheChain' => $vendorDir . '/voku/simple-cache/src/voku/cache/CacheChain.php', + 'voku\\cache\\CachePsr16' => $vendorDir . '/voku/simple-cache/src/voku/cache/CachePsr16.php', + 'voku\\cache\\Exception\\InvalidArgumentException' => $vendorDir . '/voku/simple-cache/src/voku/cache/Exception/InvalidArgumentException.php', + 'voku\\cache\\SerializerDefault' => $vendorDir . '/voku/simple-cache/src/voku/cache/SerializerDefault.php', + 'voku\\cache\\SerializerIgbinary' => $vendorDir . '/voku/simple-cache/src/voku/cache/SerializerIgbinary.php', + 'voku\\cache\\SerializerNo' => $vendorDir . '/voku/simple-cache/src/voku/cache/SerializerNo.php', + 'voku\\cache\\iAdapter' => $vendorDir . '/voku/simple-cache/src/voku/cache/iAdapter.php', + 'voku\\cache\\iCache' => $vendorDir . '/voku/simple-cache/src/voku/cache/iCache.php', + 'voku\\cache\\iSerializer' => $vendorDir . '/voku/simple-cache/src/voku/cache/iSerializer.php', ); diff --git a/bundled-libs/composer/autoload_namespaces.php b/bundled-libs/composer/autoload_namespaces.php index 9c803970..10c9b820 100644 --- a/bundled-libs/composer/autoload_namespaces.php +++ b/bundled-libs/composer/autoload_namespaces.php @@ -6,6 +6,5 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( - 'Zend\\Db\\' => array($vendorDir . '/zendframework/zend-db'), 'Psr\\Log\\' => array($vendorDir . '/psr/log'), ); diff --git a/bundled-libs/composer/autoload_psr4.php b/bundled-libs/composer/autoload_psr4.php index 8fd64e4b..8615aada 100644 --- a/bundled-libs/composer/autoload_psr4.php +++ b/bundled-libs/composer/autoload_psr4.php @@ -7,6 +7,8 @@ $baseDir = dirname($vendorDir); return array( 'voku\\cache\\' => array($vendorDir . '/voku/simple-cache/src/voku/cache'), + 'Zend\\Stdlib\\' => array($vendorDir . '/zendframework/zend-stdlib/src'), + 'Zend\\Db\\' => array($vendorDir . '/zendframework/zend-db/src'), 'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'), 'Katzgrau\\KLogger\\' => array($vendorDir . '/katzgrau/klogger/src'), ); diff --git a/bundled-libs/composer/autoload_real.php b/bundled-libs/composer/autoload_real.php index d3e0d4de..907af5b1 100644 --- a/bundled-libs/composer/autoload_real.php +++ b/bundled-libs/composer/autoload_real.php @@ -23,7 +23,7 @@ class ComposerAutoloaderInitcbda25b16bb8365467298ce193f0f30c self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitcbda25b16bb8365467298ce193f0f30c', 'loadClassLoader')); - $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); + $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; @@ -45,6 +45,7 @@ class ComposerAutoloaderInitcbda25b16bb8365467298ce193f0f30c } } + $loader->setApcuPrefix('WIBdJgt9/OFG9RxODXgrL'); $loader->register(true); return $loader; diff --git a/bundled-libs/composer/autoload_static.php b/bundled-libs/composer/autoload_static.php index 2831c8a5..6bd004ad 100644 --- a/bundled-libs/composer/autoload_static.php +++ b/bundled-libs/composer/autoload_static.php @@ -11,6 +11,11 @@ class ComposerStaticInitcbda25b16bb8365467298ce193f0f30c array ( 'voku\\cache\\' => 11, ), + 'Z' => + array ( + 'Zend\\Stdlib\\' => 12, + 'Zend\\Db\\' => 8, + ), 'P' => array ( 'Psr\\SimpleCache\\' => 16, @@ -26,6 +31,14 @@ class ComposerStaticInitcbda25b16bb8365467298ce193f0f30c array ( 0 => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache', ), + 'Zend\\Stdlib\\' => + array ( + 0 => __DIR__ . '/..' . '/zendframework/zend-stdlib/src', + ), + 'Zend\\Db\\' => + array ( + 0 => __DIR__ . '/..' . '/zendframework/zend-db/src', + ), 'Psr\\SimpleCache\\' => array ( 0 => __DIR__ . '/..' . '/psr/simple-cache/src', @@ -37,13 +50,6 @@ class ComposerStaticInitcbda25b16bb8365467298ce193f0f30c ); public static $prefixesPsr0 = array ( - 'Z' => - array ( - 'Zend\\Db\\' => - array ( - 0 => __DIR__ . '/..' . '/zendframework/zend-db', - ), - ), 'P' => array ( 'Psr\\Log\\' => @@ -55,6 +61,290 @@ class ComposerStaticInitcbda25b16bb8365467298ce193f0f30c public static $classMap = array ( 'Katzgrau\\KLogger\\Logger' => __DIR__ . '/..' . '/katzgrau/klogger/src/Logger.php', + 'Psr\\Log\\AbstractLogger' => __DIR__ . '/..' . '/psr/log/Psr/Log/AbstractLogger.php', + 'Psr\\Log\\InvalidArgumentException' => __DIR__ . '/..' . '/psr/log/Psr/Log/InvalidArgumentException.php', + 'Psr\\Log\\LogLevel' => __DIR__ . '/..' . '/psr/log/Psr/Log/LogLevel.php', + 'Psr\\Log\\LoggerAwareInterface' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerAwareInterface.php', + 'Psr\\Log\\LoggerAwareTrait' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerAwareTrait.php', + 'Psr\\Log\\LoggerInterface' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerInterface.php', + 'Psr\\Log\\LoggerTrait' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerTrait.php', + 'Psr\\Log\\NullLogger' => __DIR__ . '/..' . '/psr/log/Psr/Log/NullLogger.php', + 'Psr\\Log\\Test\\DummyTest' => __DIR__ . '/..' . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php', + 'Psr\\Log\\Test\\LoggerInterfaceTest' => __DIR__ . '/..' . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php', + 'Psr\\SimpleCache\\CacheException' => __DIR__ . '/..' . '/psr/simple-cache/src/CacheException.php', + 'Psr\\SimpleCache\\CacheInterface' => __DIR__ . '/..' . '/psr/simple-cache/src/CacheInterface.php', + 'Psr\\SimpleCache\\InvalidArgumentException' => __DIR__ . '/..' . '/psr/simple-cache/src/InvalidArgumentException.php', + 'Zend\\Db\\Adapter\\Adapter' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Adapter.php', + 'Zend\\Db\\Adapter\\AdapterAbstractServiceFactory' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/AdapterAbstractServiceFactory.php', + 'Zend\\Db\\Adapter\\AdapterAwareInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/AdapterAwareInterface.php', + 'Zend\\Db\\Adapter\\AdapterAwareTrait' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/AdapterAwareTrait.php', + 'Zend\\Db\\Adapter\\AdapterInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/AdapterInterface.php', + 'Zend\\Db\\Adapter\\AdapterServiceFactory' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/AdapterServiceFactory.php', + 'Zend\\Db\\Adapter\\Driver\\AbstractConnection' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/AbstractConnection.php', + 'Zend\\Db\\Adapter\\Driver\\ConnectionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/ConnectionInterface.php', + 'Zend\\Db\\Adapter\\Driver\\DriverInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/DriverInterface.php', + 'Zend\\Db\\Adapter\\Driver\\Feature\\AbstractFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Feature/AbstractFeature.php', + 'Zend\\Db\\Adapter\\Driver\\Feature\\DriverFeatureInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Feature/DriverFeatureInterface.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\Connection' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\IbmDb2' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/IbmDb2.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\Result' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Result.php', + 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Connection' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Mysqli' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Mysqli.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Result' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Statement' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Mysqli/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Connection' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Feature\\RowCounter' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Feature/RowCounter.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Oci8' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Oci8.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Result' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Oci8\\Statement' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Oci8/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Connection' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Feature\\OracleRowCounter' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/OracleRowCounter.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Feature\\SqliteRowCounter' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Pdo' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Pdo.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Result' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Pdo\\Statement' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Connection' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Pgsql' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Pgsql.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Result' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Statement' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Pgsql/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\ResultInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/ResultInterface.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Connection' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Connection.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Exception\\ErrorException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ErrorException.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Result' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Result.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Sqlsrv' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Sqlsrv.php', + 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Statement.php', + 'Zend\\Db\\Adapter\\Driver\\StatementInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Driver/StatementInterface.php', + 'Zend\\Db\\Adapter\\Exception\\ErrorException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Exception/ErrorException.php', + 'Zend\\Db\\Adapter\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Exception/ExceptionInterface.php', + 'Zend\\Db\\Adapter\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Exception/InvalidArgumentException.php', + 'Zend\\Db\\Adapter\\Exception\\InvalidConnectionParametersException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Exception/InvalidConnectionParametersException.php', + 'Zend\\Db\\Adapter\\Exception\\InvalidQueryException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Exception/InvalidQueryException.php', + 'Zend\\Db\\Adapter\\Exception\\RuntimeException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Exception/RuntimeException.php', + 'Zend\\Db\\Adapter\\Exception\\UnexpectedValueException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Exception/UnexpectedValueException.php', + 'Zend\\Db\\Adapter\\ParameterContainer' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/ParameterContainer.php', + 'Zend\\Db\\Adapter\\Platform\\AbstractPlatform' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/AbstractPlatform.php', + 'Zend\\Db\\Adapter\\Platform\\IbmDb2' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/IbmDb2.php', + 'Zend\\Db\\Adapter\\Platform\\Mysql' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/Mysql.php', + 'Zend\\Db\\Adapter\\Platform\\Oracle' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/Oracle.php', + 'Zend\\Db\\Adapter\\Platform\\PlatformInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/PlatformInterface.php', + 'Zend\\Db\\Adapter\\Platform\\Postgresql' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/Postgresql.php', + 'Zend\\Db\\Adapter\\Platform\\Sql92' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/Sql92.php', + 'Zend\\Db\\Adapter\\Platform\\SqlServer' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/SqlServer.php', + 'Zend\\Db\\Adapter\\Platform\\Sqlite' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Platform/Sqlite.php', + 'Zend\\Db\\Adapter\\Profiler\\Profiler' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Profiler/Profiler.php', + 'Zend\\Db\\Adapter\\Profiler\\ProfilerAwareInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Profiler/ProfilerAwareInterface.php', + 'Zend\\Db\\Adapter\\Profiler\\ProfilerInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/Profiler/ProfilerInterface.php', + 'Zend\\Db\\Adapter\\StatementContainer' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/StatementContainer.php', + 'Zend\\Db\\Adapter\\StatementContainerInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Adapter/StatementContainerInterface.php', + 'Zend\\Db\\ConfigProvider' => __DIR__ . '/..' . '/zendframework/zend-db/src/ConfigProvider.php', + 'Zend\\Db\\Exception\\ErrorException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Exception/ErrorException.php', + 'Zend\\Db\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Exception/ExceptionInterface.php', + 'Zend\\Db\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Exception/InvalidArgumentException.php', + 'Zend\\Db\\Exception\\RuntimeException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Exception/RuntimeException.php', + 'Zend\\Db\\Exception\\UnexpectedValueException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Exception/UnexpectedValueException.php', + 'Zend\\Db\\Metadata\\Metadata' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Metadata.php', + 'Zend\\Db\\Metadata\\MetadataInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/MetadataInterface.php', + 'Zend\\Db\\Metadata\\Object\\AbstractTableObject' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Object/AbstractTableObject.php', + 'Zend\\Db\\Metadata\\Object\\ColumnObject' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Object/ColumnObject.php', + 'Zend\\Db\\Metadata\\Object\\ConstraintKeyObject' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Object/ConstraintKeyObject.php', + 'Zend\\Db\\Metadata\\Object\\ConstraintObject' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Object/ConstraintObject.php', + 'Zend\\Db\\Metadata\\Object\\TableObject' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Object/TableObject.php', + 'Zend\\Db\\Metadata\\Object\\TriggerObject' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Object/TriggerObject.php', + 'Zend\\Db\\Metadata\\Object\\ViewObject' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Object/ViewObject.php', + 'Zend\\Db\\Metadata\\Source\\AbstractSource' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Source/AbstractSource.php', + 'Zend\\Db\\Metadata\\Source\\Factory' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Source/Factory.php', + 'Zend\\Db\\Metadata\\Source\\MysqlMetadata' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Source/MysqlMetadata.php', + 'Zend\\Db\\Metadata\\Source\\OracleMetadata' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Source/OracleMetadata.php', + 'Zend\\Db\\Metadata\\Source\\PostgresqlMetadata' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Source/PostgresqlMetadata.php', + 'Zend\\Db\\Metadata\\Source\\SqlServerMetadata' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Source/SqlServerMetadata.php', + 'Zend\\Db\\Metadata\\Source\\SqliteMetadata' => __DIR__ . '/..' . '/zendframework/zend-db/src/Metadata/Source/SqliteMetadata.php', + 'Zend\\Db\\Module' => __DIR__ . '/..' . '/zendframework/zend-db/src/Module.php', + 'Zend\\Db\\ResultSet\\AbstractResultSet' => __DIR__ . '/..' . '/zendframework/zend-db/src/ResultSet/AbstractResultSet.php', + 'Zend\\Db\\ResultSet\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/ResultSet/Exception/ExceptionInterface.php', + 'Zend\\Db\\ResultSet\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/zendframework/zend-db/src/ResultSet/Exception/InvalidArgumentException.php', + 'Zend\\Db\\ResultSet\\Exception\\RuntimeException' => __DIR__ . '/..' . '/zendframework/zend-db/src/ResultSet/Exception/RuntimeException.php', + 'Zend\\Db\\ResultSet\\HydratingResultSet' => __DIR__ . '/..' . '/zendframework/zend-db/src/ResultSet/HydratingResultSet.php', + 'Zend\\Db\\ResultSet\\ResultSet' => __DIR__ . '/..' . '/zendframework/zend-db/src/ResultSet/ResultSet.php', + 'Zend\\Db\\ResultSet\\ResultSetInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/ResultSet/ResultSetInterface.php', + 'Zend\\Db\\RowGateway\\AbstractRowGateway' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/AbstractRowGateway.php', + 'Zend\\Db\\RowGateway\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/Exception/ExceptionInterface.php', + 'Zend\\Db\\RowGateway\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/Exception/InvalidArgumentException.php', + 'Zend\\Db\\RowGateway\\Exception\\RuntimeException' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/Exception/RuntimeException.php', + 'Zend\\Db\\RowGateway\\Feature\\AbstractFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/Feature/AbstractFeature.php', + 'Zend\\Db\\RowGateway\\Feature\\FeatureSet' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/Feature/FeatureSet.php', + 'Zend\\Db\\RowGateway\\RowGateway' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/RowGateway.php', + 'Zend\\Db\\RowGateway\\RowGatewayInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/RowGateway/RowGatewayInterface.php', + 'Zend\\Db\\Sql\\AbstractExpression' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/AbstractExpression.php', + 'Zend\\Db\\Sql\\AbstractPreparableSql' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/AbstractPreparableSql.php', + 'Zend\\Db\\Sql\\AbstractSql' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/AbstractSql.php', + 'Zend\\Db\\Sql\\Combine' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Combine.php', + 'Zend\\Db\\Sql\\Ddl\\AlterTable' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/AlterTable.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\AbstractLengthColumn' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/AbstractLengthColumn.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\AbstractPrecisionColumn' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/AbstractPrecisionColumn.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\AbstractTimestampColumn' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/AbstractTimestampColumn.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\BigInteger' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/BigInteger.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Binary' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Binary.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Blob' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Blob.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Boolean' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Boolean.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Char' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Char.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Column' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Column.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\ColumnInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/ColumnInterface.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Date' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Date.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Datetime' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Datetime.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Decimal' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Decimal.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Float' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Float.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Floating' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Floating.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Integer' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Integer.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Text' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Text.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Time' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Time.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Timestamp' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Timestamp.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Varbinary' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Varbinary.php', + 'Zend\\Db\\Sql\\Ddl\\Column\\Varchar' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Column/Varchar.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\AbstractConstraint' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Constraint/AbstractConstraint.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\Check' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Constraint/Check.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\ConstraintInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Constraint/ConstraintInterface.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\ForeignKey' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Constraint/ForeignKey.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\PrimaryKey' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Constraint/PrimaryKey.php', + 'Zend\\Db\\Sql\\Ddl\\Constraint\\UniqueKey' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Constraint/UniqueKey.php', + 'Zend\\Db\\Sql\\Ddl\\CreateTable' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/CreateTable.php', + 'Zend\\Db\\Sql\\Ddl\\DropTable' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/DropTable.php', + 'Zend\\Db\\Sql\\Ddl\\Index\\AbstractIndex' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Index/AbstractIndex.php', + 'Zend\\Db\\Sql\\Ddl\\Index\\Index' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/Index/Index.php', + 'Zend\\Db\\Sql\\Ddl\\SqlInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Ddl/SqlInterface.php', + 'Zend\\Db\\Sql\\Delete' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Delete.php', + 'Zend\\Db\\Sql\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Exception/ExceptionInterface.php', + 'Zend\\Db\\Sql\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Exception/InvalidArgumentException.php', + 'Zend\\Db\\Sql\\Exception\\RuntimeException' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Exception/RuntimeException.php', + 'Zend\\Db\\Sql\\Expression' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Expression.php', + 'Zend\\Db\\Sql\\ExpressionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/ExpressionInterface.php', + 'Zend\\Db\\Sql\\Having' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Having.php', + 'Zend\\Db\\Sql\\Insert' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Insert.php', + 'Zend\\Db\\Sql\\Join' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Join.php', + 'Zend\\Db\\Sql\\Literal' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Literal.php', + 'Zend\\Db\\Sql\\Platform\\AbstractPlatform' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/AbstractPlatform.php', + 'Zend\\Db\\Sql\\Platform\\IbmDb2\\IbmDb2' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/IbmDb2/IbmDb2.php', + 'Zend\\Db\\Sql\\Platform\\IbmDb2\\SelectDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/IbmDb2/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\Ddl\\AlterTableDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\Ddl\\CreateTableDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\Mysql' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Mysql/Mysql.php', + 'Zend\\Db\\Sql\\Platform\\Mysql\\SelectDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Mysql/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Oracle\\Oracle' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Oracle/Oracle.php', + 'Zend\\Db\\Sql\\Platform\\Oracle\\SelectDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Oracle/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Platform' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Platform.php', + 'Zend\\Db\\Sql\\Platform\\PlatformDecoratorInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/PlatformDecoratorInterface.php', + 'Zend\\Db\\Sql\\Platform\\SqlServer\\Ddl\\CreateTableDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php', + 'Zend\\Db\\Sql\\Platform\\SqlServer\\SelectDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/SqlServer/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\SqlServer\\SqlServer' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/SqlServer/SqlServer.php', + 'Zend\\Db\\Sql\\Platform\\Sqlite\\SelectDecorator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Sqlite/SelectDecorator.php', + 'Zend\\Db\\Sql\\Platform\\Sqlite\\Sqlite' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Platform/Sqlite/Sqlite.php', + 'Zend\\Db\\Sql\\Predicate\\Between' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/Between.php', + 'Zend\\Db\\Sql\\Predicate\\Expression' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/Expression.php', + 'Zend\\Db\\Sql\\Predicate\\In' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/In.php', + 'Zend\\Db\\Sql\\Predicate\\IsNotNull' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/IsNotNull.php', + 'Zend\\Db\\Sql\\Predicate\\IsNull' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/IsNull.php', + 'Zend\\Db\\Sql\\Predicate\\Like' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/Like.php', + 'Zend\\Db\\Sql\\Predicate\\Literal' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/Literal.php', + 'Zend\\Db\\Sql\\Predicate\\NotBetween' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/NotBetween.php', + 'Zend\\Db\\Sql\\Predicate\\NotIn' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/NotIn.php', + 'Zend\\Db\\Sql\\Predicate\\NotLike' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/NotLike.php', + 'Zend\\Db\\Sql\\Predicate\\Operator' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/Operator.php', + 'Zend\\Db\\Sql\\Predicate\\Predicate' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/Predicate.php', + 'Zend\\Db\\Sql\\Predicate\\PredicateInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/PredicateInterface.php', + 'Zend\\Db\\Sql\\Predicate\\PredicateSet' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Predicate/PredicateSet.php', + 'Zend\\Db\\Sql\\PreparableSqlInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/PreparableSqlInterface.php', + 'Zend\\Db\\Sql\\Select' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Select.php', + 'Zend\\Db\\Sql\\Sql' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Sql.php', + 'Zend\\Db\\Sql\\SqlInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/SqlInterface.php', + 'Zend\\Db\\Sql\\TableIdentifier' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/TableIdentifier.php', + 'Zend\\Db\\Sql\\Update' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Update.php', + 'Zend\\Db\\Sql\\Where' => __DIR__ . '/..' . '/zendframework/zend-db/src/Sql/Where.php', + 'Zend\\Db\\TableGateway\\AbstractTableGateway' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/AbstractTableGateway.php', + 'Zend\\Db\\TableGateway\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Exception/ExceptionInterface.php', + 'Zend\\Db\\TableGateway\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Exception/InvalidArgumentException.php', + 'Zend\\Db\\TableGateway\\Exception\\RuntimeException' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Exception/RuntimeException.php', + 'Zend\\Db\\TableGateway\\Feature\\AbstractFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/AbstractFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\EventFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/EventFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\EventFeatureEventsInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/EventFeatureEventsInterface.php', + 'Zend\\Db\\TableGateway\\Feature\\EventFeature\\TableGatewayEvent' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/EventFeature/TableGatewayEvent.php', + 'Zend\\Db\\TableGateway\\Feature\\FeatureSet' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/FeatureSet.php', + 'Zend\\Db\\TableGateway\\Feature\\GlobalAdapterFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/GlobalAdapterFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\MasterSlaveFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/MasterSlaveFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\MetadataFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/MetadataFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\RowGatewayFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/RowGatewayFeature.php', + 'Zend\\Db\\TableGateway\\Feature\\SequenceFeature' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/Feature/SequenceFeature.php', + 'Zend\\Db\\TableGateway\\TableGateway' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/TableGateway.php', + 'Zend\\Db\\TableGateway\\TableGatewayInterface' => __DIR__ . '/..' . '/zendframework/zend-db/src/TableGateway/TableGatewayInterface.php', + 'Zend\\Stdlib\\AbstractOptions' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/AbstractOptions.php', + 'Zend\\Stdlib\\ArrayObject' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ArrayObject.php', + 'Zend\\Stdlib\\ArraySerializableInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ArraySerializableInterface.php', + 'Zend\\Stdlib\\ArrayStack' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ArrayStack.php', + 'Zend\\Stdlib\\ArrayUtils' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ArrayUtils.php', + 'Zend\\Stdlib\\ArrayUtils\\MergeRemoveKey' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ArrayUtils/MergeRemoveKey.php', + 'Zend\\Stdlib\\ArrayUtils\\MergeReplaceKey' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKey.php', + 'Zend\\Stdlib\\ArrayUtils\\MergeReplaceKeyInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKeyInterface.php', + 'Zend\\Stdlib\\ConsoleHelper' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ConsoleHelper.php', + 'Zend\\Stdlib\\DispatchableInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/DispatchableInterface.php', + 'Zend\\Stdlib\\ErrorHandler' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ErrorHandler.php', + 'Zend\\Stdlib\\Exception\\BadMethodCallException' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Exception/BadMethodCallException.php', + 'Zend\\Stdlib\\Exception\\DomainException' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Exception/DomainException.php', + 'Zend\\Stdlib\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Exception/ExceptionInterface.php', + 'Zend\\Stdlib\\Exception\\ExtensionNotLoadedException' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Exception/ExtensionNotLoadedException.php', + 'Zend\\Stdlib\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Exception/InvalidArgumentException.php', + 'Zend\\Stdlib\\Exception\\LogicException' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Exception/LogicException.php', + 'Zend\\Stdlib\\Exception\\RuntimeException' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Exception/RuntimeException.php', + 'Zend\\Stdlib\\FastPriorityQueue' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/FastPriorityQueue.php', + 'Zend\\Stdlib\\Glob' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Glob.php', + 'Zend\\Stdlib\\Guard\\AllGuardsTrait' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Guard/AllGuardsTrait.php', + 'Zend\\Stdlib\\Guard\\ArrayOrTraversableGuardTrait' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Guard/ArrayOrTraversableGuardTrait.php', + 'Zend\\Stdlib\\Guard\\EmptyGuardTrait' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Guard/EmptyGuardTrait.php', + 'Zend\\Stdlib\\Guard\\NullGuardTrait' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Guard/NullGuardTrait.php', + 'Zend\\Stdlib\\InitializableInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/InitializableInterface.php', + 'Zend\\Stdlib\\JsonSerializable' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/JsonSerializable.php', + 'Zend\\Stdlib\\Message' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Message.php', + 'Zend\\Stdlib\\MessageInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/MessageInterface.php', + 'Zend\\Stdlib\\ParameterObjectInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ParameterObjectInterface.php', + 'Zend\\Stdlib\\Parameters' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Parameters.php', + 'Zend\\Stdlib\\ParametersInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ParametersInterface.php', + 'Zend\\Stdlib\\PriorityList' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/PriorityList.php', + 'Zend\\Stdlib\\PriorityQueue' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/PriorityQueue.php', + 'Zend\\Stdlib\\Request' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Request.php', + 'Zend\\Stdlib\\RequestInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/RequestInterface.php', + 'Zend\\Stdlib\\Response' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/Response.php', + 'Zend\\Stdlib\\ResponseInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/ResponseInterface.php', + 'Zend\\Stdlib\\SplPriorityQueue' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/SplPriorityQueue.php', + 'Zend\\Stdlib\\SplQueue' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/SplQueue.php', + 'Zend\\Stdlib\\SplStack' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/SplStack.php', + 'Zend\\Stdlib\\StringUtils' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/StringUtils.php', + 'Zend\\Stdlib\\StringWrapper\\AbstractStringWrapper' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php', + 'Zend\\Stdlib\\StringWrapper\\Iconv' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/StringWrapper/Iconv.php', + 'Zend\\Stdlib\\StringWrapper\\Intl' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/StringWrapper/Intl.php', + 'Zend\\Stdlib\\StringWrapper\\MbString' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/StringWrapper/MbString.php', + 'Zend\\Stdlib\\StringWrapper\\Native' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/StringWrapper/Native.php', + 'Zend\\Stdlib\\StringWrapper\\StringWrapperInterface' => __DIR__ . '/..' . '/zendframework/zend-stdlib/src/StringWrapper/StringWrapperInterface.php', + 'voku\\cache\\AdapterApc' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterApc.php', + 'voku\\cache\\AdapterApcu' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterApcu.php', + 'voku\\cache\\AdapterArray' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterArray.php', + 'voku\\cache\\AdapterFile' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterFile.php', + 'voku\\cache\\AdapterFileAbstract' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterFileAbstract.php', + 'voku\\cache\\AdapterFileSimple' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterFileSimple.php', + 'voku\\cache\\AdapterMemcache' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterMemcache.php', + 'voku\\cache\\AdapterMemcached' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterMemcached.php', + 'voku\\cache\\AdapterOpCache' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterOpCache.php', + 'voku\\cache\\AdapterPredis' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterPredis.php', + 'voku\\cache\\AdapterXcache' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/AdapterXcache.php', + 'voku\\cache\\Cache' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/Cache.php', + 'voku\\cache\\CacheAdapterAutoManager' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/CacheAdapterAutoManager.php', + 'voku\\cache\\CacheChain' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/CacheChain.php', + 'voku\\cache\\CachePsr16' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/CachePsr16.php', + 'voku\\cache\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/Exception/InvalidArgumentException.php', + 'voku\\cache\\SerializerDefault' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/SerializerDefault.php', + 'voku\\cache\\SerializerIgbinary' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/SerializerIgbinary.php', + 'voku\\cache\\SerializerNo' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/SerializerNo.php', + 'voku\\cache\\iAdapter' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/iAdapter.php', + 'voku\\cache\\iCache' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/iCache.php', + 'voku\\cache\\iSerializer' => __DIR__ . '/..' . '/voku/simple-cache/src/voku/cache/iSerializer.php', ); public static function getInitializer(ClassLoader $loader) diff --git a/bundled-libs/composer/installed.json b/bundled-libs/composer/installed.json index 3089c6ba..356a7e48 100644 --- a/bundled-libs/composer/installed.json +++ b/bundled-libs/composer/installed.json @@ -1,92 +1,4 @@ [ - { - "name": "zendframework/zend-db", - "version": "2.2.2", - "version_normalized": "2.2.2.0", - "target-dir": "Zend/Db", - "source": { - "type": "git", - "url": "https://github.com/zendframework/zend-db.git", - "reference": "release-2.2.2" - }, - "dist": { - "type": "zip", - "url": "https://packages.zendframework.com/composer/zendframework-zend-db-2.2.2-release-2.2.2-6ab69c.zip", - "reference": "release-2.2.2", - "shasum": "8bc0c8d19bfd75f9a65a4b332f556c2571424c09" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "zendframework/zend-stdlib": "2.2.2" - }, - "time": "2013-06-20 18:00:57", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.2-dev", - "dev-develop": "2.3-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-0": { - "Zend\\Db\\": "" - } - }, - "license": [ - "BSD-3-Clause" - ], - "description": " ", - "keywords": [ - "db", - "zf2" - ], - "support": { - "source": "https://github.com/zendframework/Component_ZendDb/tree/release-2.2.2" - } - }, - { - "name": "psr/log", - "version": "1.0.0", - "version_normalized": "1.0.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", - "shasum": "" - }, - "time": "2012-12-21 11:40:51", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Psr\\Log\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "keywords": [ - "log", - "psr", - "psr-3" - ] - }, { "name": "katzgrau/klogger", "version": "1.0.0", @@ -109,7 +21,7 @@ "require-dev": { "phpunit/phpunit": "4.0.*" }, - "time": "2014-03-20 02:36:36", + "time": "2014-03-20T02:36:36+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -141,6 +53,46 @@ "logging" ] }, + { + "name": "psr/log", + "version": "1.0.0", + "version_normalized": "1.0.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "shasum": "" + }, + "time": "2012-12-21T11:40:51+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Psr\\Log\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "keywords": [ + "log", + "psr", + "psr-3" + ] + }, { "name": "psr/simple-cache", "version": "1.0.1", @@ -159,7 +111,7 @@ "require": { "php": ">=5.3.0" }, - "time": "2017-10-23 01:57:42", + "time": "2017-10-23T01:57:42+00:00", "type": "library", "extra": { "branch-alias": { @@ -193,17 +145,17 @@ }, { "name": "voku/simple-cache", - "version": "3.2.2", - "version_normalized": "3.2.2.0", + "version": "4.0.1", + "version_normalized": "4.0.1.0", "source": { "type": "git", "url": "https://github.com/voku/simple-cache.git", - "reference": "b08d16b4bd802f43f963c2209049f874df83ce56" + "reference": "dfda1d803fd79d9ee918e1bac700c94a6f30659c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/voku/simple-cache/zipball/b08d16b4bd802f43f963c2209049f874df83ce56", - "reference": "b08d16b4bd802f43f963c2209049f874df83ce56", + "url": "https://api.github.com/repos/voku/simple-cache/zipball/dfda1d803fd79d9ee918e1bac700c94a6f30659c", + "reference": "dfda1d803fd79d9ee918e1bac700c94a6f30659c", "shasum": "" }, "require": { @@ -214,9 +166,9 @@ "psr/simple-cache-implementation": "1.0" }, "require-dev": { - "phpunit/phpunit": "~6.0" + "phpunit/phpunit": "~6.0 || ~7.0" }, - "time": "2018-12-21 07:48:39", + "time": "2019-03-03T10:23:55+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -243,5 +195,184 @@ "php", "simple cache" ] + }, + { + "name": "zendframework/zend-db", + "version": "2.10.0", + "version_normalized": "2.10.0.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-db.git", + "reference": "320f5faaa0f98ebc93be5476ec4eda28255935c4" + }, + "dist": { + "type": "zip", + "url": "https://packages.zendframework.com/composer/zendframework-zend-db-2.10.0-5a43dc.zip", + "reference": "320f5faaa0f98ebc93be5476ec4eda28255935c4", + "shasum": "3f285fe0d475cac25e350787779019caa6ddb188" + }, + "require": { + "php": "^5.6 || ^7.0", + "zendframework/zend-stdlib": "^2.7 || ^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.25 || ^6.4.4", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-eventmanager": "^2.6.2 || ^3.0", + "zendframework/zend-hydrator": "^1.1 || ^2.1 || ^3.0", + "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3" + }, + "suggest": { + "zendframework/zend-eventmanager": "Zend\\EventManager component", + "zendframework/zend-hydrator": "Zend\\Hydrator component for using HydratingResultSets", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component" + }, + "time": "2019-02-25T11:37:45+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.9-dev", + "dev-develop": "2.10-dev" + }, + "zf": { + "component": "Zend\\Db", + "config-provider": "Zend\\Db\\ConfigProvider" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Zend\\Db\\": "src/" + } + }, + "autoload-dev": { + "files": [ + "test/autoload.php" + ], + "psr-4": { + "ZendTest\\Db\\": "test/unit", + "ZendIntegrationTest\\Db\\": "test/integration" + } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": [ + "phpcs" + ], + "cs-fix": [ + "phpcbf" + ], + "test": [ + "phpunit --colors=always --testsuite \"unit test\"" + ], + "test-coverage": [ + "phpunit --colors=always --coverage-clover clover.xml" + ], + "test-integration": [ + "phpunit --colors=always --testsuite \"integration test\"" + ], + "upload-coverage": [ + "coveralls -v" + ] + }, + "license": [ + "BSD-3-Clause" + ], + "description": "Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations", + "keywords": [ + "db", + "zendframework", + "zf" + ], + "support": { + "docs": "https://docs.zendframework.com/zend-db/", + "issues": "https://github.com/zendframework/zend-db/issues", + "source": "https://github.com/zendframework/zend-db", + "rss": "https://github.com/zendframework/zend-db/releases.atom", + "slack": "https://zendframework-slack.herokuapp.com", + "forum": "https://discourse.zendframework.com/c/questions/components" + } + }, + { + "name": "zendframework/zend-stdlib", + "version": "3.2.1", + "version_normalized": "3.2.1.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-stdlib.git", + "reference": "04e09d7f961b2271b0e1cbbb6f5f53ad23cf8562" + }, + "dist": { + "type": "zip", + "url": "https://packages.zendframework.com/composer/zendframework-zend-stdlib-3.2.1-90faf1.zip", + "reference": "04e09d7f961b2271b0e1cbbb6f5f53ad23cf8562", + "shasum": "36f654611fab0d6fe1ea1c72184a43f9810ce7c8" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpbench/phpbench": "^0.13", + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "time": "2018-08-28T21:34:05+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev", + "dev-develop": "3.3.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Zend\\Stdlib\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "ZendTest\\Stdlib\\": "test/", + "ZendBench\\Stdlib\\": "benchmark/" + } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": [ + "phpcs" + ], + "cs-fix": [ + "phpcbf" + ], + "test": [ + "phpunit --colors=always" + ], + "test-coverage": [ + "phpunit --colors=always --coverage-clover clover.xml" + ] + }, + "license": [ + "BSD-3-Clause" + ], + "description": "SPL extensions, array utilities, error handlers, and more", + "keywords": [ + "stdlib", + "zendframework", + "zf" + ], + "support": { + "docs": "https://docs.zendframework.com/zend-stdlib/", + "issues": "https://github.com/zendframework/zend-stdlib/issues", + "source": "https://github.com/zendframework/zend-stdlib", + "rss": "https://github.com/zendframework/zend-stdlib/releases.atom", + "slack": "https://zendframework-slack.herokuapp.com", + "forum": "https://discourse.zendframework.com/c/questions/components" + } } ] diff --git a/bundled-libs/psr/simple-cache/LICENSE.md b/bundled-libs/psr/simple-cache/LICENSE.md new file mode 100644 index 00000000..e49a7c85 --- /dev/null +++ b/bundled-libs/psr/simple-cache/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) 2016 PHP Framework Interoperability Group + +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/bundled-libs/psr/simple-cache/README.md b/bundled-libs/psr/simple-cache/README.md new file mode 100644 index 00000000..43641d17 --- /dev/null +++ b/bundled-libs/psr/simple-cache/README.md @@ -0,0 +1,8 @@ +PHP FIG Simple Cache PSR +======================== + +This repository holds all interfaces related to PSR-16. + +Note that this is not a cache implementation of its own. It is merely an interface that describes a cache implementation. See [the specification](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) for more details. + +You can find implementations of the specification by looking for packages providing the [psr/simple-cache-implementation](https://packagist.org/providers/psr/simple-cache-implementation) virtual package. diff --git a/bundled-libs/psr/simple-cache/composer.json b/bundled-libs/psr/simple-cache/composer.json new file mode 100644 index 00000000..2978fa55 --- /dev/null +++ b/bundled-libs/psr/simple-cache/composer.json @@ -0,0 +1,25 @@ +{ + "name": "psr/simple-cache", + "description": "Common interfaces for simple caching", + "keywords": ["psr", "psr-16", "cache", "simple-cache", "caching"], + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/bundled-libs/psr/simple-cache/src/CacheException.php b/bundled-libs/psr/simple-cache/src/CacheException.php new file mode 100644 index 00000000..eba53815 --- /dev/null +++ b/bundled-libs/psr/simple-cache/src/CacheException.php @@ -0,0 +1,10 @@ + value pairs. Cache keys that do not exist or are stale will have $default as value. + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if $keys is neither an array nor a Traversable, + * or if any of the $keys are not a legal value. + */ + public function getMultiple($keys, $default = null); + + /** + * Persists a set of key => value pairs in the cache, with an optional TTL. + * + * @param iterable $values A list of key => value pairs for a multiple-set operation. + * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and + * the driver supports TTL then the library may set a default value + * for it or let the driver take care of that. + * + * @return bool True on success and false on failure. + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if $values is neither an array nor a Traversable, + * or if any of the $values are not a legal value. + */ + public function setMultiple($values, $ttl = null); + + /** + * Deletes multiple cache items in a single operation. + * + * @param iterable $keys A list of string-based keys to be deleted. + * + * @return bool True if the items were successfully removed. False if there was an error. + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if $keys is neither an array nor a Traversable, + * or if any of the $keys are not a legal value. + */ + public function deleteMultiple($keys); + + /** + * Determines whether an item is present in the cache. + * + * NOTE: It is recommended that has() is only to be used for cache warming type purposes + * and not to be used within your live applications operations for get/set, as this method + * is subject to a race condition where your has() will return true and immediately after, + * another script can remove it making the state of your app out of date. + * + * @param string $key The cache item key. + * + * @return bool + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if the $key string is not a legal value. + */ + public function has($key); +} diff --git a/bundled-libs/psr/simple-cache/src/InvalidArgumentException.php b/bundled-libs/psr/simple-cache/src/InvalidArgumentException.php new file mode 100644 index 00000000..6a9524a2 --- /dev/null +++ b/bundled-libs/psr/simple-cache/src/InvalidArgumentException.php @@ -0,0 +1,13 @@ +setItemToDate()" now accepts DateTimeInterface instead of DateTime + + # Changelog 3.2.2 (2018-12-21) - fix APC(u) detection for CLI usage diff --git a/bundled-libs/voku/simple-cache/README.md b/bundled-libs/voku/simple-cache/README.md index f4621a35..9a70acda 100644 --- a/bundled-libs/voku/simple-cache/README.md +++ b/bundled-libs/voku/simple-cache/README.md @@ -6,10 +6,10 @@ [![Latest Stable Version](https://poser.pugx.org/voku/simple-cache/v/stable)](https://packagist.org/packages/voku/simple-cache) [![Total Downloads](https://poser.pugx.org/voku/simple-cache/downloads)](https://packagist.org/packages/voku/simple-cache) [![License](https://poser.pugx.org/voku/simple-cache/license)](https://packagist.org/packages/voku/simple-cache) +[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/moelleken) +[![Donate to this project using Patreon](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/voku) - -:zap: Simple Cache Class -=================== +# :zap: Simple Cache Class This is a simple Cache Abstraction Layer for PHP >= 7.0 that provides a simple interaction with your cache-server. You can define the Adapter / Serializer in the "constructor" or the class will auto-detect you server-cache in this order: @@ -21,27 +21,26 @@ with your cache-server. You can define the Adapter / Serializer in the "construc 5. OpCache (via PHP-files) 6. Static-PHP-Cache -## Get "Simple Cache" +### Get "Simple Cache" You can download it from here, or require it using [composer](https://packagist.org/packages/voku/simple-cache). ```json { "require": { - "voku/simple-cache": "3.*" + "voku/simple-cache": "4.*" } } ``` -## Install via "composer require" +### Install via "composer require" ```shell composer require voku/simple-cache -composer require predis/predis # if you will use redis as cache, then add predis ``` -## Quick Start +### Quick Start ```php use voku\cache\Cache; @@ -55,7 +54,7 @@ $bar = $cache->getItem('foo'); ``` -## Usage +### Usage ```php use voku\cache\Cache; @@ -100,6 +99,84 @@ If you use the parameter "$checkForUser" (=== true) in the constructor, then the -> You can also overwrite the check for the user, if you add a global function named "checkForDev()". +## Overwrite the auto-connection option -## License +You can overwrite the cache auto-detect via "CacheAdapterAutoManager" and the +"$cacheAdapterManagerForAutoConnect" option in the "Cache"-constructor. Additional you can also +activate the "$cacheAdapterManagerForAutoConnectOverwrite" option in the "Cache"-constructor, so that +you can implement your own cache auto-detect logic. + +```php + +$cacheManager = new \voku\cache\CacheAdapterAutoManager(); + +// 1. check for "APCu" support first +$cacheManager->addAdapter( + \voku\cache\AdapterApcu::class +); + +// 2. check for "APC" support +$cacheManager->addAdapter( + \voku\cache\AdapterApcu::class +); + +// 3. try "OpCache"-Cache +$cacheManager->addAdapter( + \voku\cache\AdapterOpCache::class, + static function () { + $cacheDir = \realpath(\sys_get_temp_dir()) . '/simple_php_cache_opcache'; + + return $cacheDir; + } +); + +// 4. try "File"-Cache +$cacheManager->addAdapter( + \voku\cache\AdapterFileSimple::class, + static function () { + $cacheDir = \realpath(\sys_get_temp_dir()) . '/simple_php_cache_file'; + + return $cacheDir; + } +); + + +// 5. use Memory Cache as final fallback +$cacheManager->addAdapter( + \voku\cache\AdapterArray::class +); + +$cache = new \voku\cache\CachePsr16( + null, // use auto-detection + null, // use auto-detection + false, // do not check for usage + true, // enable the cache + false, // do not check for admin session + false, // do not check for dev + false, // do not check for admin session + false, // do not check for server vs. client ip + '', // do not use "_GET"-parameter for disabling + $cacheManager, // new auto-detection logic + true // overwrite the auto-detection logic +); +``` + +### Support + +For support and donations please visit [Github](https://github.com/voku/simple-cache/) | [Issues](https://github.com/voku/simple-cache/issues) | [PayPal](https://paypal.me/moelleken) | [Patreon](https://www.patreon.com/voku). + +For status updates and release announcements please visit [Releases](https://github.com/voku/simple-cache/releases) | [Twitter](https://twitter.com/suckup_de) | [Patreon](https://www.patreon.com/voku/posts). + +For professional support please contact [me](https://about.me/voku). + +### Thanks + +- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc. +- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm! +- Thanks to [Travis CI](https://travis-ci.com/) for being the most awesome, easiest continous integration tool out there! +- Thanks to [StyleCI](https://styleci.io/) for the simple but powerfull code style check. +- Thanks to [PHPStan](https://github.com/phpstan/phpstan) && [Psalm](https://github.com/vimeo/psalm) for relly great Static analysis tools and for discover bugs in the code! + + +### License [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache?ref=badge_large) diff --git a/bundled-libs/voku/simple-cache/composer.json b/bundled-libs/voku/simple-cache/composer.json index 394916fd..2a0c2c5f 100644 --- a/bundled-libs/voku/simple-cache/composer.json +++ b/bundled-libs/voku/simple-cache/composer.json @@ -25,7 +25,7 @@ "psr/simple-cache": "~1.0" }, "require-dev": { - "phpunit/phpunit": "~6.0" + "phpunit/phpunit": "~6.0 || ~7.0" }, "autoload": { "psr-4": { diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApc.php b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApc.php index 1c5152ec..92a10b29 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApc.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApc.php @@ -85,7 +85,8 @@ class AdapterApc implements iAdapter * @param bool $limited - If $limited is TRUE, the return value will exclude the individual list of cache * entries. This is useful when trying to optimize calls for statistics gathering * - * @return array|bool

Array of cached data (and meta-data) or FALSE on failure.

+ * @return array|false + *

Array of cached data (and meta-data) or FALSE on failure.

*/ public function cacheInfo(string $type = '', bool $limited = false): array { diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApcu.php b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApcu.php index 3186210e..000074f3 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApcu.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterApcu.php @@ -84,7 +84,8 @@ class AdapterApcu implements iAdapter * @param bool $limited - If $limited is TRUE, the return value will exclude the individual list of cache * entries. This is useful when trying to optimize calls for statistics gathering * - * @return array|bool

Array of cached data (and meta-data) or FALSE on failure.

+ * @return array|false + *

Array of cached data (and meta-data) or FALSE on failure.

*/ public function cacheInfo(bool $limited = false): array { diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFile.php b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFile.php index 9316ef57..e02c6e41 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFile.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFile.php @@ -86,7 +86,9 @@ class AdapterFile extends AdapterFileAbstract \fflush($fp); \flock($fp, \LOCK_UN); } - \fclose($fp); + if ($fp !== false) { + \fclose($fp); + } return $octetWritten !== false; } diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFileAbstract.php b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFileAbstract.php index c9b83ba1..51d4f10f 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFileAbstract.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterFileAbstract.php @@ -34,7 +34,7 @@ abstract class AdapterFileAbstract implements iAdapter protected $fileMode = '0755'; /** - * @param string|null $cacheDir + * @param \callable|string|null $cacheDir */ public function __construct($cacheDir = null) { @@ -44,9 +44,13 @@ abstract class AdapterFileAbstract implements iAdapter $cacheDir = \realpath(\sys_get_temp_dir()) . '/simple_php_cache'; } - $this->cacheDir = (string) $cacheDir; + if (\is_callable($cacheDir)) { + $this->cacheDir = (string) \call_user_func($cacheDir); + } else { + $this->cacheDir = (string) $cacheDir; + } - if ($this->createCacheDirectory($cacheDir) === true) { + if ($this->createCacheDirectory($this->cacheDir) === true) { $this->installed = true; } } @@ -106,14 +110,14 @@ abstract class AdapterFileAbstract implements iAdapter } /** - * @param $cacheFile + * @param string $cacheFileWithPath * * @return bool */ - protected function deleteFile($cacheFile): bool + protected function deleteFile($cacheFileWithPath): bool { - if (\is_file($cacheFile)) { - return \unlink($cacheFile); + if (\is_file($cacheFileWithPath)) { + return \unlink($cacheFileWithPath); } return false; @@ -199,7 +203,7 @@ abstract class AdapterFileAbstract implements iAdapter * * e.g. '0777', or '0755' ... * - * @param $fileMode + * @param string $fileMode */ public function setFileMode($fileMode) { @@ -207,7 +211,7 @@ abstract class AdapterFileAbstract implements iAdapter } /** - * @param $ttl + * @param int $ttl * * @return bool */ diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterOpCache.php b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterOpCache.php index 91c24167..9996b31e 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/AdapterOpCache.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/AdapterOpCache.php @@ -29,7 +29,12 @@ class AdapterOpCache extends AdapterFileSimple if (self::$hasCompileFileFunction === null) { /** @noinspection PhpComposerExtensionStubsInspection */ - self::$hasCompileFileFunction = \function_exists('opcache_compile_file') && !empty(\opcache_get_status()); + /** @noinspection PhpUsageOfSilenceOperatorInspection */ + self::$hasCompileFileFunction = ( + \function_exists('opcache_compile_file') + && + !empty(@\opcache_get_status()) + ); } } diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/Cache.php b/bundled-libs/voku/simple-cache/src/voku/cache/Cache.php index 388f038b..3919d912 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/Cache.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/Cache.php @@ -20,12 +20,27 @@ use voku\cache\Exception\InvalidArgumentException; class Cache implements iCache { /** - * @var iAdapter + * @var array + */ + protected static $STATIC_CACHE = []; + + /** + * @var array + */ + protected static $STATIC_CACHE_EXPIRE = []; + + /** + * @var array + */ + protected static $STATIC_CACHE_COUNTER = []; + + /** + * @var iAdapter|null */ protected $adapter; /** - * @var iSerializer + * @var iSerializer|null */ protected $serializer; @@ -69,21 +84,6 @@ class Cache implements iCache */ protected $isAdminSession; - /** - * @var array - */ - protected static $STATIC_CACHE = []; - - /** - * @var array - */ - protected static $STATIC_CACHE_EXPIRE = []; - - /** - * @var array - */ - protected static $STATIC_CACHE_COUNTER = []; - /** * @var int */ @@ -92,19 +92,27 @@ class Cache implements iCache /** * __construct * - * @param iAdapter|null $adapter - * @param iSerializer|null $serializer - * @param bool $checkForUsage

admin-session || server-ip == client-ip || check for - * dev

- * @param bool $cacheEnabled

false will disable the cache (use it e.g. for global - * settings)

- * @param bool|string $isAdminSession

set a admin-id, if the user is a admin (so we can - * disable cache for this user) - * @param bool $useCheckForAdminSession

use $isAdminSession flag or not

- * @param bool $useCheckForDev

use checkForDev() or not

- * @param bool $useCheckForServerIpIsClientIp

use check for server-ip == client-ip or not

- * @param string $disableCacheGetParameter

set the _GET parameter for disabling the cache, - * disable this check via empty string

+ * @param iAdapter|null $adapter + * @param iSerializer|null $serializer + * @param bool $checkForUsage

check for admin-session && check for + * server-ip == client-ip + * && check for dev

+ * @param bool $cacheEnabled

false === disable the cache (use it + * e.g. for global settings)

+ * @param bool $isAdminSession

true === disable cache for this user + * (use it e.g. for admin user settings) + * @param bool $useCheckForAdminSession

use $isAdminSession flag or not

+ * @param bool $useCheckForDev

use checkForDev() or not

+ * @param bool $useCheckForServerIpIsClientIp

use check for server-ip == client-ip + * or + * not

+ * @param string $disableCacheGetParameter

set the _GET parameter for disabling + * the cache, disable this check via empty + * string

+ * @param CacheAdapterAutoManager $cacheAdapterManagerForAutoConnect

Overwrite some Adapters for the + * auto-connect-function.

+ * @param bool $cacheAdapterManagerForAutoConnectOverwrite

true === Use only Adapters from your + * "CacheAdapterManager".

*/ public function __construct( iAdapter $adapter = null, @@ -115,7 +123,9 @@ class Cache implements iCache bool $useCheckForDev = true, bool $useCheckForAdminSession = true, bool $useCheckForServerIpIsClientIp = true, - string $disableCacheGetParameter = 'testWithoutCache' + string $disableCacheGetParameter = 'testWithoutCache', + CacheAdapterAutoManager $cacheAdapterManagerForAutoConnect = null, + bool $cacheAdapterManagerForAutoConnectOverwrite = false ) { $this->isAdminSession = $isAdminSession; @@ -128,19 +138,19 @@ class Cache implements iCache // First check if the cache is active at all. $this->isActive = $cacheEnabled; if ( - $this->isActive === true + $this->isActive && - $checkForUsage === true + $checkForUsage ) { $this->setActive($this->isCacheActiveForTheCurrentUser()); } // If the cache is active, then try to auto-connect to the best possible cache-system. - if ($this->isActive === true) { + if ($this->isActive) { $this->setPrefix($this->getTheDefaultPrefix()); if ($adapter === null) { - $adapter = $this->autoConnectToAvailableCacheSystem(); + $adapter = $this->autoConnectToAvailableCacheSystem($cacheAdapterManagerForAutoConnect, $cacheAdapterManagerForAutoConnectOverwrite); } // INFO: Memcache(d) has his own "serializer", so don't use it twice @@ -172,93 +182,81 @@ class Cache implements iCache } /** - * enable / disable the cache + * Auto-connect to the available cache-system on the server. * - * @param bool $isActive - */ - public function setActive(bool $isActive) - { - $this->isActive = $isActive; - } - - /** - * check if the current use is a admin || dev || server == client + * @param CacheAdapterAutoManager $cacheAdapterManagerForAutoConnect

Overwrite some Adapters for the + * auto-connect-function.

+ * @param bool $cacheAdapterManagerForAutoConnectOverwrite

true === Use only Adapters from your + * "CacheAdapterManager".

* - * @return bool + * @return iAdapter */ - public function isCacheActiveForTheCurrentUser(): bool - { - $active = true; + protected function autoConnectToAvailableCacheSystem( + CacheAdapterAutoManager $cacheAdapterManagerForAutoConnect = null, + bool $cacheAdapterManagerForAutoConnectOverwrite = false + ): iAdapter { + static $AUTO_ADAPTER_STATIC_CACHE = null; - // test the cache, with this GET-parameter - if ($this->disableCacheGetParameter) { - $testCache = isset($_GET[$this->disableCacheGetParameter]) ? (int) $_GET[$this->disableCacheGetParameter] : 0; - } else { - $testCache = 0; + if ( + \is_object($AUTO_ADAPTER_STATIC_CACHE) + && + $AUTO_ADAPTER_STATIC_CACHE instanceof iAdapter + ) { + return $AUTO_ADAPTER_STATIC_CACHE; } - if ($testCache !== 1) { - if ( - // admin session is active - ( - $this->useCheckForAdminSession - && - $this->isAdminSession - ) - || - // server == client - ( - $this->useCheckForServerIpIsClientIp === true - && - isset($_SERVER['SERVER_ADDR']) - && - $_SERVER['SERVER_ADDR'] === $this->getClientIp() - ) - || - // user is a dev - ( - $this->useCheckForDev === true - && - $this->checkForDev() === true - ) - ) { - $active = false; + // init + $adapter = null; + + $cacheAdapterManagerDefault = CacheAdapterAutoManager::getDefaultsForAutoInit(); + + if ($cacheAdapterManagerForAutoConnect !== null) { + if ($cacheAdapterManagerForAutoConnectOverwrite) { + $cacheAdapterManagerDefault = $cacheAdapterManagerForAutoConnect; + } else { + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManagerDefault->merge($cacheAdapterManagerForAutoConnect); } } - return $active; + foreach ($cacheAdapterManagerDefault->getAdapters() as $adapterTmp => $callableFunctionTmp) { + + /** @var iAdapter $adapterTest */ + if ($callableFunctionTmp !== null) { + $adapterTest = new $adapterTmp($callableFunctionTmp); + } else { + $adapterTest = new $adapterTmp(); + } + + if ($adapterTest->installed()) { + $adapter = $adapterTest; + + break; + } + } + + // save to static cache + $AUTO_ADAPTER_STATIC_CACHE = $adapter; + + return $adapter; } /** - * returns the IP address of the client + * Calculate store-key (prefix + $rawKey). * - * @param bool $trust_proxy_headers

- * Whether or not to trust the - * proxy headers HTTP_CLIENT_IP - * and HTTP_X_FORWARDED_FOR. ONLY - * use if your $_SERVER is behind a - * proxy that sets these values - *

+ * @param string $rawKey * * @return string */ - protected function getClientIp(bool $trust_proxy_headers = false): string + protected function calculateStoreKey(string $rawKey): string { - $remoteAddr = $_SERVER['REMOTE_ADDR'] ?? 'NO_REMOTE_ADDR'; + $str = $this->getPrefix() . $rawKey; - if ($trust_proxy_headers) { - return $remoteAddr; + if ($this->adapter instanceof AdapterFileAbstract) { + $str = $this->cleanStoreKey($str); } - if (!empty($_SERVER['HTTP_CLIENT_IP'])) { - $ip = $_SERVER['HTTP_CLIENT_IP']; - } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } else { - $ip = $remoteAddr; - } - - return $ip; + return $str; } /** @@ -297,182 +295,54 @@ class Cache implements iCache } /** - * Set the default-prefix via "SERVER"-var + "SESSION"-language. - */ - protected function getTheDefaultPrefix(): string - { - return ($_SERVER['SERVER_NAME'] ?? '') . '_' . - ($_SERVER['THEME'] ?? '') . '_' . - ($_SERVER['STAGE'] ?? '') . '_' . - ($_SESSION['language'] ?? '') . '_' . - ($_SESSION['language_extra'] ?? ''); - } - - /** - * Auto-connect to the available cache-system on the server. - * - * @return iAdapter - */ - protected function autoConnectToAvailableCacheSystem(): iAdapter - { - static $adapterCache; - - if (\is_object($adapterCache) && $adapterCache instanceof iAdapter) { - return $adapterCache; - } - - $memcached = null; - $isMemcachedAvailable = false; - if (\extension_loaded('memcached')) { - /** @noinspection PhpComposerExtensionStubsInspection */ - $memcached = new \Memcached(); - /** @noinspection PhpUsageOfSilenceOperatorInspection */ - $isMemcachedAvailable = @$memcached->addServer('127.0.0.1', 11211); - } - - if ($isMemcachedAvailable === false) { - $memcached = null; - } - - $adapterMemcached = new AdapterMemcached($memcached); - if ($adapterMemcached->installed() === true) { - - // ------------------------------------------------------------- - // "Memcached" - // ------------------------------------------------------------- - $adapter = $adapterMemcached; - } else { - $memcache = null; - $isMemcacheAvailable = false; - /** @noinspection ClassConstantCanBeUsedInspection */ - if (\class_exists('\Memcache')) { - /** @noinspection PhpComposerExtensionStubsInspection */ - $memcache = new \Memcache(); - /** @noinspection PhpUsageOfSilenceOperatorInspection */ - $isMemcacheAvailable = @$memcache->connect('127.0.0.1', 11211); - } - - if ($isMemcacheAvailable === false) { - $memcache = null; - } - - $adapterMemcache = new AdapterMemcache($memcache); - if ($adapterMemcache->installed() === true) { - - // ------------------------------------------------------------- - // "Memcache" - // ------------------------------------------------------------- - $adapter = $adapterMemcache; - } else { - $redis = null; - $isRedisAvailable = false; - if ( - \extension_loaded('redis') - && - \class_exists('\Predis\Client') - ) { - /** @noinspection PhpUndefinedNamespaceInspection */ - /** @noinspection PhpUndefinedClassInspection */ - $redis = new \Predis\Client( - [ - 'scheme' => 'tcp', - 'host' => '127.0.0.1', - 'port' => 6379, - 'timeout' => '2.0', - ] - ); - - try { - /** @noinspection PhpUndefinedMethodInspection */ - $redis->connect(); - /** @noinspection PhpUndefinedMethodInspection */ - $isRedisAvailable = $redis->getConnection()->isConnected(); - } catch (\Exception $e) { - // nothing - } - } - - if ($isRedisAvailable === false) { - $redis = null; - } - - $adapterRedis = new AdapterPredis($redis); - if ($adapterRedis->installed() === true) { - - // ------------------------------------------------------------- - // Redis - // ------------------------------------------------------------- - $adapter = $adapterRedis; - } else { - $adapterXcache = new AdapterXcache(); - if ($adapterXcache->installed() === true) { - - // ------------------------------------------------------------- - // "Xcache" - // ------------------------------------------------------------- - $adapter = $adapterXcache; - } else { - $adapterApcu = new AdapterApcu(); - if ($adapterApcu->installed() === true) { - - // ------------------------------------------------------------- - // "APCu" - // ------------------------------------------------------------- - $adapter = $adapterApcu; - } else { - $adapterApc = new AdapterApc(); - if ($adapterApc->installed() === true) { - - // ------------------------------------------------------------- - // "APC" - // ------------------------------------------------------------- - $adapter = $adapterApc; - } else { - $adapterObCache = new AdapterOpCache(); - if ($adapterObCache->installed() === true) { - - // ------------------------------------------------------------- - // OpCache (via PHP-files) - // ------------------------------------------------------------- - $adapter = $adapterObCache; - } else { - - // ------------------------------------------------------------- - // Static-PHP-Cache - // ------------------------------------------------------------- - $adapter = new AdapterArray(); - } - } - } - } - } - } - } - - // save to static cache - $adapterCache = $adapter; - - return $adapter; - } - - /** - * Set "isReady" state. - * - * @param bool $isReady - */ - protected function setCacheIsReady(bool $isReady) - { - $this->isReady = $isReady; - } - - /** - * Get the "isReady" state. + * @param string $storeKey * * @return bool */ - public function getCacheIsReady(): bool + protected function checkForStaticCache(string $storeKey): bool { - return $this->isReady; + return !empty(self::$STATIC_CACHE) + && + \array_key_exists($storeKey, self::$STATIC_CACHE) + && + \array_key_exists($storeKey, self::$STATIC_CACHE_EXPIRE) + && + \time() <= self::$STATIC_CACHE_EXPIRE[$storeKey]; + } + + /** + * Clean store-key (required e.g. for the "File"-Adapter). + * + * @param string $str + * + * @return string + */ + protected function cleanStoreKey(string $str): string + { + return \md5($str); + } + + /** + * Check if cached-item exists. + * + * @param string $key + * + * @return bool + */ + public function existsItem(string $key): bool + { + if (!$this->adapter instanceof iAdapter) { + return false; + } + + $storeKey = $this->calculateStoreKey($key); + + // check static-cache + if ($this->checkForStaticCache($storeKey)) { + return true; + } + + return $this->adapter->exists($storeKey); } /** @@ -503,21 +373,21 @@ class Cache implements iCache // get from static-cache if ( - $useStaticCache === true + $useStaticCache && - $this->checkForStaticCache($storeKey) === true + $this->checkForStaticCache($storeKey) ) { return self::$STATIC_CACHE[$storeKey]; } $serialized = $this->adapter->get($storeKey); - $value = $serialized ? $this->serializer->unserialize($serialized) : null; + $value = $serialized && $this->serializer ? $this->serializer->unserialize($serialized) : null; self::$STATIC_CACHE_COUNTER[$storeKey]++; // save into static-cache if needed if ( - $useStaticCache === true + $useStaticCache && ( ( @@ -540,97 +410,55 @@ class Cache implements iCache } /** - * Calculate store-key (prefix + $rawKey). - * - * @param string $rawKey - * - * @return string - */ - protected function calculateStoreKey(string $rawKey): string - { - $str = $this->getPrefix() . $rawKey; - - if ($this->adapter instanceof AdapterFileAbstract) { - $str = $this->cleanStoreKey($str); - } - - return $str; - } - - /** - * Clean store-key (required e.g. for the "File"-Adapter). - * - * @param string $str - * - * @return string - */ - protected function cleanStoreKey(string $str): string - { - return \md5($str); - } - - /** - * Get the prefix. - * - * @return string - */ - public function getPrefix(): string - { - return $this->prefix; - } - - /** - * !!! Set the prefix. !!! - * - * WARNING: Do not use if you don't know what you do. Because this will overwrite the default prefix. - * - * @param string $prefix - */ - public function setPrefix(string $prefix) - { - $this->prefix = $prefix; - } - - /** - * Get the current value, when the static cache is used. - * - * @return int - */ - public function getStaticCacheHitCounter(): int - { - return $this->staticCacheHitCounter; - } - - /** - * Set the static-hit-counter: Who often do we hit the cache, before we use static cache? - * - * @param int $staticCacheHitCounter - */ - public function setStaticCacheHitCounter(int $staticCacheHitCounter) - { - $this->staticCacheHitCounter = $staticCacheHitCounter; - } - - /** - * Set cache-item by key => value + date. - * - * @param string $key - * @param mixed $value - * @param \DateTime $date

If the date is in the past, we will remove the existing cache-item.

- * - * @throws InvalidArgumentException

If the $date is in the past.

+ * Remove all cached-items. * * @return bool */ - public function setItemToDate(string $key, $value, \DateTime $date): bool + public function removeAll(): bool { - $ttl = $date->getTimestamp() - \time(); - - if ($ttl <= 0) { - throw new InvalidArgumentException('Date in the past.'); + if (!$this->adapter instanceof iAdapter) { + return false; } - return $this->setItem($key, $value, $ttl); + // remove static-cache + if (!empty(self::$STATIC_CACHE)) { + self::$STATIC_CACHE = []; + self::$STATIC_CACHE_COUNTER = []; + self::$STATIC_CACHE_EXPIRE = []; + } + + return $this->adapter->removeAll(); + } + + /** + * Remove a cached-item. + * + * @param string $key + * + * @return bool + */ + public function removeItem(string $key): bool + { + if (!$this->adapter instanceof iAdapter) { + return false; + } + + $storeKey = $this->calculateStoreKey($key); + + // remove static-cache + if ( + !empty(self::$STATIC_CACHE) + && + \array_key_exists($storeKey, self::$STATIC_CACHE) + ) { + unset( + self::$STATIC_CACHE[$storeKey], + self::$STATIC_CACHE_COUNTER[$storeKey], + self::$STATIC_CACHE_EXPIRE[$storeKey] + ); + } + + return $this->adapter->remove($storeKey); } /** @@ -658,15 +486,15 @@ class Cache implements iCache $serialized = $this->serializer->serialize($value); // update static-cache, if it's exists - if (\array_key_exists($storeKey, self::$STATIC_CACHE) === true) { + if (\array_key_exists($storeKey, self::$STATIC_CACHE)) { self::$STATIC_CACHE[$storeKey] = $value; } if ($ttl) { if ($ttl instanceof \DateInterval) { // Converting to a TTL in seconds - $dateTimeNow = new \DateTime('now'); - $ttl = $dateTimeNow->add($ttl)->getTimestamp() - \time(); + /** @noinspection PhpUnhandledExceptionInspection */ + $ttl = (new \DateTimeImmutable('now'))->add($ttl)->getTimestamp() - \time(); } // always cache the TTL time, maybe we need this later ... @@ -679,91 +507,100 @@ class Cache implements iCache } /** - * Remove a cached-item. + * Set cache-item by key => value + date. * - * @param string $key + * @param string $key + * @param mixed $value + * @param \DateTimeInterface $date

If the date is in the past, we will remove the existing cache-item.

+ * + * @throws InvalidArgumentException + *

If the $date is in the past.

* * @return bool */ - public function removeItem(string $key): bool + public function setItemToDate(string $key, $value, \DateTimeInterface $date): bool { - if (!$this->adapter instanceof iAdapter) { - return false; + $ttl = $date->getTimestamp() - \time(); + + if ($ttl <= 0) { + throw new InvalidArgumentException('Date in the past.'); } - $storeKey = $this->calculateStoreKey($key); - - // remove static-cache - if ( - !empty(self::$STATIC_CACHE) - && - \array_key_exists($storeKey, self::$STATIC_CACHE) === true - ) { - unset(self::$STATIC_CACHE[$storeKey], self::$STATIC_CACHE_COUNTER[$storeKey], self::$STATIC_CACHE_EXPIRE[$storeKey] - ); - } - - return $this->adapter->remove($storeKey); + return $this->setItem($key, $value, $ttl); } /** - * Remove all cached-items. + * Get the "isReady" state. * * @return bool */ - public function removeAll(): bool + public function getCacheIsReady(): bool { - if (!$this->adapter instanceof iAdapter) { - return false; - } - - // remove static-cache - if (!empty(self::$STATIC_CACHE)) { - self::$STATIC_CACHE = []; - self::$STATIC_CACHE_COUNTER = []; - self::$STATIC_CACHE_EXPIRE = []; - } - - return $this->adapter->removeAll(); + return $this->isReady; } /** - * Check if cached-item exists. + * returns the IP address of the client * - * @param string $key + * @param bool $trust_proxy_headers

+ * Whether or not to trust the + * proxy headers HTTP_CLIENT_IP + * and HTTP_X_FORWARDED_FOR. ONLY + * use if your $_SERVER is behind a + * proxy that sets these values + *

* - * @return bool + * @return string */ - public function existsItem(string $key): bool + protected function getClientIp(bool $trust_proxy_headers = false): string { - if (!$this->adapter instanceof iAdapter) { - return false; + $remoteAddr = $_SERVER['REMOTE_ADDR'] ?? 'NO_REMOTE_ADDR'; + + if ($trust_proxy_headers) { + return $remoteAddr; } - $storeKey = $this->calculateStoreKey($key); - - // check static-cache - if ($this->checkForStaticCache($storeKey) === true) { - return true; + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else { + $ip = $remoteAddr; } - return $this->adapter->exists($storeKey); + return $ip; } /** - * @param string $storeKey + * Get the prefix. * - * @return bool + * @return string */ - protected function checkForStaticCache(string $storeKey): bool + public function getPrefix(): string { - return !empty(self::$STATIC_CACHE) - && - \array_key_exists($storeKey, self::$STATIC_CACHE) === true - && - \array_key_exists($storeKey, self::$STATIC_CACHE_EXPIRE) === true - && - \time() <= self::$STATIC_CACHE_EXPIRE[$storeKey]; + return $this->prefix; + } + + /** + * Get the current value, when the static cache is used. + * + * @return int + */ + public function getStaticCacheHitCounter(): int + { + return $this->staticCacheHitCounter; + } + + /** + * Set the default-prefix via "SERVER"-var + "SESSION"-language. + */ + protected function getTheDefaultPrefix(): string + { + return ($_SERVER['SERVER_NAME'] ?? '') . '_' . + ($_SERVER['THEME'] ?? '') . '_' . + ($_SERVER['STAGE'] ?? '') . '_' . + ($_SESSION['language'] ?? '') . '_' . + ($_SESSION['language_extra'] ?? ''); } /** @@ -795,4 +632,94 @@ class Cache implements iCache return ''; } + + /** + * check if the current use is a admin || dev || server == client + * + * @return bool + */ + public function isCacheActiveForTheCurrentUser(): bool + { + $active = true; + + // test the cache, with this GET-parameter + if ($this->disableCacheGetParameter) { + $testCache = isset($_GET[$this->disableCacheGetParameter]) ? (int) $_GET[$this->disableCacheGetParameter] : 0; + } else { + $testCache = 0; + } + + if ($testCache !== 1) { + if ( + // admin session is active + ( + $this->useCheckForAdminSession + && + $this->isAdminSession + ) + || + // server == client + ( + $this->useCheckForServerIpIsClientIp + && + isset($_SERVER['SERVER_ADDR']) + && + $_SERVER['SERVER_ADDR'] === $this->getClientIp() + ) + || + // user is a dev + ( + $this->useCheckForDev + && + $this->checkForDev() + ) + ) { + $active = false; + } + } + + return $active; + } + + /** + * enable / disable the cache + * + * @param bool $isActive + */ + public function setActive(bool $isActive) + { + $this->isActive = $isActive; + } + + /** + * Set "isReady" state. + * + * @param bool $isReady + */ + protected function setCacheIsReady(bool $isReady) + { + $this->isReady = $isReady; + } + + /** + * !!! Set the prefix. !!! + * + * WARNING: Do not use if you don't know what you do. Because this will overwrite the default prefix. + * + * @param string $prefix + */ + public function setPrefix(string $prefix) + { + $this->prefix = $prefix; + } + + /** + * Set the static-hit-counter: Who often do we hit the cache, before we use static cache? + * + * @param int $staticCacheHitCounter + */ + public function setStaticCacheHitCounter(int $staticCacheHitCounter) + { + $this->staticCacheHitCounter = $staticCacheHitCounter; + } } diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/CacheAdapterAutoManager.php b/bundled-libs/voku/simple-cache/src/voku/cache/CacheAdapterAutoManager.php new file mode 100644 index 00000000..42b0847f --- /dev/null +++ b/bundled-libs/voku/simple-cache/src/voku/cache/CacheAdapterAutoManager.php @@ -0,0 +1,230 @@ +validateAdapter($adapter); + $this->validateCallable($callableFunction); + + $this->adapter[] = $adapter; + $this->callableFunctions[] = $callableFunction; + + return $this; + } + + /** + * @return \Generator|\Generator + */ + public function getAdapters(): \Generator + { + foreach ($this->adapter as $key => $value) { + yield $this->adapter[$key] => $this->callableFunctions[$key]; + } + } + + /** + * @param self $adapterManager + * + * @throws InvalidArgumentException + * + * @return CacheAdapterAutoManager + */ + public function merge(self $adapterManager): self + { + foreach ($adapterManager->getAdapters() as $adapterTmp => $callableFunctionTmp) { + $this->validateAdapter($adapterTmp); + $this->validateCallable($callableFunctionTmp); + + $key = \array_search($adapterTmp, $this->adapter, true); + + if ($key) { + $this->adapter[$key] = $adapterTmp; + $this->callableFunctions[$key] = $callableFunctionTmp; + } else { + $this->adapter[] = $adapterTmp; + $this->callableFunctions[] = $callableFunctionTmp; + } + } + + return $this; + } + + /** + * @param string $replaceAdapter + * + * @throws InvalidArgumentException + */ + private function validateAdapter(string $replaceAdapter) + { + /** @noinspection PhpUnhandledExceptionInspection */ + $interfaces = (new \ReflectionClass($replaceAdapter))->getInterfaces(); + if (!\array_key_exists(iAdapter::class, $interfaces)) { + throw new InvalidArgumentException('"' . $replaceAdapter . '" did not implement the "iAdapter"-interface [' . \print_r($interfaces, true) . ']'); + } + } + + /** + * @param callable $callableFunction + * + * @throws InvalidArgumentException + */ + private function validateCallable(callable $callableFunction = null) + { + if ( + $callableFunction !== null + && + !\is_callable($callableFunction) + ) { + throw new InvalidArgumentException('$callableFunction is not callable'); + } + } + + /** + * @return CacheAdapterAutoManager + */ + public static function getDefaultsForAutoInit(): self + { + $cacheAdapterManager = new self(); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterMemcached::class, + static function () { + $memcached = null; + $isMemcachedAvailable = false; + if (\extension_loaded('memcached')) { + /** @noinspection PhpComposerExtensionStubsInspection */ + $memcached = new \Memcached(); + /** @noinspection PhpUsageOfSilenceOperatorInspection */ + $isMemcachedAvailable = @$memcached->addServer('127.0.0.1', 11211); + } + + if (!$isMemcachedAvailable) { + $memcached = null; + } + + return $memcached; + } + ); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterMemcache::class, + static function () { + $memcache = null; + $isMemcacheAvailable = false; + /** @noinspection ClassConstantCanBeUsedInspection */ + if (\class_exists('\Memcache')) { + /** @noinspection PhpComposerExtensionStubsInspection */ + $memcache = new \Memcache(); + /** @noinspection PhpUsageOfSilenceOperatorInspection */ + $isMemcacheAvailable = @$memcache->connect('127.0.0.1', 11211); + } + + if (!$isMemcacheAvailable) { + $memcache = null; + } + + return $memcache; + } + ); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterPredis::class, + static function () { + $redis = null; + $isRedisAvailable = false; + if ( + \extension_loaded('redis') + && + \class_exists('\Predis\Client') + ) { + /** @noinspection PhpUndefinedNamespaceInspection */ + /** @noinspection PhpUndefinedClassInspection */ + $redis = new \Predis\Client( + [ + 'scheme' => 'tcp', + 'host' => '127.0.0.1', + 'port' => 6379, + 'timeout' => '2.0', + ] + ); + + try { + /** @noinspection PhpUndefinedMethodInspection */ + $redis->connect(); + /** @noinspection PhpUndefinedMethodInspection */ + $isRedisAvailable = $redis->getConnection()->isConnected(); + } catch (\Exception $e) { + // nothing + } + } + + if ($isRedisAvailable === false) { + $redis = null; + } + + return $redis; + } + ); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterXcache::class + ); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterApcu::class + ); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterApc::class + ); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterOpCache::class, + static function () { + return \realpath(\sys_get_temp_dir()) . '/simple_php_cache'; + } + ); + + /** @noinspection PhpUnhandledExceptionInspection */ + $cacheAdapterManager->addAdapter( + AdapterArray::class + ); + + return $cacheAdapterManager; + } +} diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/CacheChain.php b/bundled-libs/voku/simple-cache/src/voku/cache/CacheChain.php index 89606f6b..ff1d883f 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/CacheChain.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/CacheChain.php @@ -4,9 +4,6 @@ declare(strict_types=1); namespace voku\cache; -/** - * CacheChain: global-cache-chain class - */ class CacheChain implements iCache { /** @@ -87,13 +84,13 @@ class CacheChain implements iCache $results[] = $cache->setItem($key, $value, $ttl); } - return \in_array(false, $results, true) === false; + return !\in_array(false, $results, true); } /** * {@inheritdoc} */ - public function setItemToDate(string $key, $value, \DateTime $date): bool + public function setItemToDate(string $key, $value, \DateTimeInterface $date): bool { // init $results = []; @@ -103,7 +100,7 @@ class CacheChain implements iCache $results[] = $cache->setItemToDate($key, $value, $date); } - return \in_array(false, $results, true) === false; + return !\in_array(false, $results, true); } /** @@ -118,7 +115,7 @@ class CacheChain implements iCache $results[] = $cache->removeItem($key); } - return \in_array(false, $results, true) === false; + return !\in_array(false, $results, true); } /** @@ -147,6 +144,6 @@ class CacheChain implements iCache $results[] = $cache->removeAll(); } - return \in_array(false, $results, true) === false; + return !\in_array(false, $results, true); } } diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/CachePsr16.php b/bundled-libs/voku/simple-cache/src/voku/cache/CachePsr16.php index 30edf0bf..2cb162c7 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/CachePsr16.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/CachePsr16.php @@ -40,7 +40,7 @@ class CachePsr16 extends Cache implements CacheInterface /** * Deletes multiple cache items in a single operation. * - * @param \iterable $keys a list of string-based keys to be deleted + * @param iterable $keys a list of string-based keys to be deleted * * @throws InvalidArgumentException * @@ -48,16 +48,20 @@ class CachePsr16 extends Cache implements CacheInterface */ public function deleteMultiple($keys): bool { - if (!\is_array($keys) && !($keys instanceof \Traversable)) { + if ( + !\is_array($keys) + && + !($keys instanceof \Traversable) + ) { throw new InvalidArgumentException('$keys is not iterable:' . \print_r($keys, true)); } $results = []; foreach ((array) $keys as $key) { - $results = $this->delete($key); + $results[] = $this->delete($key); } - return \in_array(false, $results, true) === false; + return !\in_array(false, $results, true); } /** @@ -72,7 +76,7 @@ class CachePsr16 extends Cache implements CacheInterface */ public function get($key, $default = null) { - if ($this->has($key) === true) { + if ($this->has($key)) { return $this->getItem($key); } @@ -82,17 +86,21 @@ class CachePsr16 extends Cache implements CacheInterface /** * Obtains multiple cache items by their unique keys. * - * @param \iterable $keys a list of keys that can obtained in a single operation - * @param mixed $default default value to return for keys that do not exist + * @param iterable $keys a list of keys that can obtained in a single operation + * @param mixed $default default value to return for keys that do not exist * * @throws InvalidArgumentException * - * @return \iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as - * value. + * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as + * value. */ public function getMultiple($keys, $default = null) { - if (!\is_array($keys) && !($keys instanceof \Traversable)) { + if ( + !\is_array($keys) + && + !($keys instanceof \Traversable) + ) { throw new InvalidArgumentException('$keys is not iterable:' . \print_r($keys, true)); } @@ -152,7 +160,7 @@ class CachePsr16 extends Cache implements CacheInterface /** * Persists a set of key => value pairs in the cache, with an optional TTL. * - * @param \iterable $values a list of key => value pairs for a multiple-set operation + * @param iterable $values a list of key => value pairs for a multiple-set operation * @param \DateInterval|int|null $ttl Optional. The TTL value of this item. If no value is sent and * the driver supports TTL then the library may set a default value * for it or let the driver take care of that. @@ -163,15 +171,19 @@ class CachePsr16 extends Cache implements CacheInterface */ public function setMultiple($values, $ttl = null): bool { - if (!\is_array($values) && !($values instanceof \Traversable)) { + if ( + !\is_array($values) + && + !($values instanceof \Traversable) + ) { throw new InvalidArgumentException('$values is not iterable:' . \print_r($values, true)); } $results = []; foreach ((array) $values as $key => $value) { - $results = $this->set($key, $value, $ttl); + $results[] = $this->set($key, $value, $ttl); } - return \in_array(false, $results, true) === false; + return !\in_array(false, $results, true); } } diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/iCache.php b/bundled-libs/voku/simple-cache/src/voku/cache/iCache.php index 7ac171e4..5b01746f 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/iCache.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/iCache.php @@ -32,13 +32,13 @@ interface iCache /** * set item a special expire-date * - * @param string $key - * @param mixed $value - * @param \DateTime $date + * @param string $key + * @param mixed $value + * @param \DateTimeInterface $date * * @return bool */ - public function setItemToDate(string $key, $value, \DateTime $date): bool; + public function setItemToDate(string $key, $value, \DateTimeInterface $date): bool; /** * remove item diff --git a/bundled-libs/voku/simple-cache/src/voku/cache/iSerializer.php b/bundled-libs/voku/simple-cache/src/voku/cache/iSerializer.php index 8d7adf20..8dfd8337 100644 --- a/bundled-libs/voku/simple-cache/src/voku/cache/iSerializer.php +++ b/bundled-libs/voku/simple-cache/src/voku/cache/iSerializer.php @@ -12,18 +12,14 @@ interface iSerializer /** * serialize * - * @param $value - * - * @return mixed + * @param mixed $value */ public function serialize($value); /** * unserialize * - * @param $value - * - * @return mixed + * @param string $value */ public function unserialize($value); } diff --git a/bundled-libs/zendframework/zend-db/.ci/mysql_fixtures.sh b/bundled-libs/zendframework/zend-db/.ci/mysql_fixtures.sh new file mode 100644 index 00000000..625903e8 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/.ci/mysql_fixtures.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +echo "Configure MySQL test database" + +mysql --user=root --password=Password123 -e 'create database zenddb_test;' diff --git a/bundled-libs/zendframework/zend-db/.ci/mysql_fixtures_travis.sh b/bundled-libs/zendframework/zend-db/.ci/mysql_fixtures_travis.sh new file mode 100644 index 00000000..b769ef74 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/.ci/mysql_fixtures_travis.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +echo "Configure MySQL test database" + +mysql -u root -e 'create database zenddb_test;' diff --git a/bundled-libs/zendframework/zend-db/.ci/pgsql_fixtures.sh b/bundled-libs/zendframework/zend-db/.ci/pgsql_fixtures.sh new file mode 100644 index 00000000..c9cf42be --- /dev/null +++ b/bundled-libs/zendframework/zend-db/.ci/pgsql_fixtures.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +echo "Configure PostgreSQL test database" + +psql -U postgres -c 'create database zenddb_test;' +psql -U postgres -c "alter role postgres password 'postgres'" diff --git a/bundled-libs/zendframework/zend-db/.ci/sqlsrv_fixtures.sh b/bundled-libs/zendframework/zend-db/.ci/sqlsrv_fixtures.sh new file mode 100644 index 00000000..58074cb3 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/.ci/sqlsrv_fixtures.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +echo "Configure SQL server test database" + +sqlcmd -S localhost -U sa -P Password123 -Q "CREATE DATABASE zenddb_test;" diff --git a/bundled-libs/zendframework/zend-db/CHANGELOG.md b/bundled-libs/zendframework/zend-db/CHANGELOG.md new file mode 100644 index 00000000..a0d05c7f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/CHANGELOG.md @@ -0,0 +1,445 @@ +# Changelog + +All notable changes to this project will be documented in this file, in reverse chronological order by release. + +## 2.10.0 - 2019-02-25 + +### Added + +- [#157](https://github.com/zendframework/zend-db/pull/157) added support of + `Zend\Db\Sql\TableIdentifier` in DDL +- [#345](https://github.com/zendframework/zend-db/pull/345) allow usage with + zend-hydrator v3 +- [#346](https://github.com/zendframework/zend-db/pull/346) adds support for PHP + 7.3 + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#303](https://github.com/zendframework/zend-db/pull/303) fixes #295 issue: + handle empty array as datasource at `AbstractResultSet::initialize()` at PHP + 7.2 +- [#313](https://github.com/zendframework/zend-db/pull/313) test + `AbstractResultSet::current()` to return null on empty array +- [#329](https://github.com/zendframework/zend-db/pull/329) fixes Exception + thrown when calling `prepareStatementForSqlObject` on a Select with a + sub-Select that has limit and/or offset set +- [#337](https://github.com/zendframework/zend-db/pull/337) fixes #330 current + NULL for mysqli +- [#338](https://github.com/zendframework/zend-db/pull/338) restore missing use + `ResultSet` in `AbstractTableGateway` +- [#341](https://github.com/zendframework/zend-db/pull/341) fixes undefined + variable bug in MetadataFeature +- [#357](https://github.com/zendframework/zend-db/pull/357) fixes named params + in subquery - limit and offset (issue #355) + +## 2.9.3 - 2018-04-09 + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#295](https://github.com/zendframework/zend-db/pull/295) fix error when + datasource passed to `AbstractResultSet::initialize()` is empty array at + php 7.2 environment + +- [#300](https://github.com/zendframework/zend-db/pull/300) Fix error for nested + queries inside field parameters + +- [#301](https://github.com/zendframework/zend-db/pull/301) fix for issue with + set fields that exists in different tables in one query + +- [#304](https://github.com/zendframework/zend-db/pull/304) fix PDO bind + parameter name to use field name with extended charset (PDO only supports + alphanumeric and underscore for placeholder/parameter names). + +## 2.9.2 - 2017-12-11 + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#292](https://github.com/zendframework/zend-db/pull/292) ensures that you may + reference bound parameter names using a leading colon (`:`) character when + using the PDO adapter. (The leading colon is not technically necessary, as the + adapter will prefix for you; however, this ensures portability with vanilla + PDO.) + +## 2.9.1 - 2017-12-07 + +### Added + +- Nothing. + +### Changed + +- [#289](https://github.com/zendframework/zend-db/pull/289) reverts a change + introduced in 2.9.0 and modifies the behavior of the PDO adapter slightly + to remove a regression. In 2.9.0, when binding parameters with names that + contained characters not supported by PDO, we would pass the parameter names + to `md5()`; this caused a regression, as the SQL string containing the + parameter name was not also updated. + + This patch modifies the behavior during a bind-operation to instead raise an + exception if a parameter name contains characters not supported by PDO. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + +## 2.9.0 - 2017-12-06 + +### Added + +- [#216](https://github.com/zendframework/zend-db/pull/216) added AFTER support + in ALTER TABLE syntax for MySQL +- [#223](https://github.com/zendframework/zend-db/pull/223) added support for + empty values set with IN predicate +- [#271](https://github.com/zendframework/zend-db/pull/271) added support for + dash character on MySQL identifier +- [#273](https://github.com/zendframework/zend-db/pull/273) added support for + implementing an error handler for db2_prepare +- [#275](https://github.com/zendframework/zend-db/pull/275) added support for + LIMIT OFFSET for db2 +- [#280](https://github.com/zendframework/zend-db/pull/280) added version dsn + parameter for pdo_dblib + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in + ORDER BY syntax +- [#224](https://github.com/zendframework/zend-db/pull/224) fixes how parameters + are bound to statements in the PDO adapter. PDO has a restriction on parameter + names of `[0-9a-zA_Z_]`; as such, the driver now hashes the parameter names + using `md5()` in order to ensure compatibility with other drivers. +- [#229](https://github.com/zendframework/zend-db/pull/229) fixes the support + of SSL for mysqli +- [#255](https://github.com/zendframework/zend-db/pull/255) fixes ResultSet with + array values +- [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in + Firebird driver doesn't support lastInsertId +- [#276](https://github.com/zendframework/zend-db/pull/276) fixes the support + of PHP 7.2 +- [#287](https://github.com/zendframework/zend-db/pull/287) fixes the usage of + count() with PHP 7.2 + +## 2.8.2 - 2016-08-09 + +### Added + +- [#110](https://github.com/zendframework/zend-db/pull/110) prepared the + documentation for publication at https://zendframework.github.io/zend-db/ +- [#114](https://github.com/zendframework/zend-db/pull/114) add + Adapter\Adapter::class to alias against Adapter\AdapterInterface::class + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#154](https://github.com/zendframework/zend-db/pull/154) fixes the how the + COMBINE operator is applied to SQLite adapters, ensuring a valid UNION + statement is generated. +- [#112](https://github.com/zendframework/zend-db/pull/112) fixes the test on + the number of replacements when using the same variable name. +- [#115](https://github.com/zendframework/zend-db/pull/115) TableGateway update + method was incorrect when specifying default join declaration. +- [#145](https://github.com/zendframework/zend-db/pull/145) Fix MSSQL Select + when encounting DISTINCT and OFFSET and LIMIT together. +- [#153](https://github.com/zendframework/zend-db/pull/153) Runtime exception + threw fatal error due to incorrect spelling of the class when a DSN did not + exist. + +## 2.8.1 - 2016-04-14 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#100](https://github.com/zendframework/zend-db/pull/100) fixes the JOIN + behavior to re-allow selecting an empty column set from the joined table. +- [#106](https://github.com/zendframework/zend-db/pull/106) fixes an issue in + the test suite when ext/pgsql is enabled, but no databases are avaiable. + +## 2.8.0 - 2016-04-12 + +### Added + +- [#92](https://github.com/zendframework/zend-db/pull/92) adds the class + `Zend\Db\Sql\Join` for creating and aggregating JOIN specifications. This is + now consumed by all `Zend\Db\Sql` implementations in order to represent JOIN + statements. +- [#92](https://github.com/zendframework/zend-db/pull/92) adds support for JOIN + operations to UPDATE statements. +- [#92](https://github.com/zendframework/zend-db/pull/92) adds support for joins + to `AbstractTableGateway::update`; you can now pass an array of + specifications via a third argument to the method. +- [#96](https://github.com/zendframework/zend-db/pull/96) exposes the package as + config-provider/component, but adding: + - `Zend\Db\ConfigProvider`, which maps the `AdapterInterface` to the + `AdapterServiceFactory`, and enables the `AdapterAbstractServiceFactory`. + - `Zend\Db\Module`, which does the same, for a zend-mvc context. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + +## 2.7.1 - 2016-04-12 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#71](https://github.com/zendframework/zend-db/pull/71) updates the `Pgsql` + adapter to allow passing the connection charset; this can be done with the + `charset` option when creating your adapter. +- [#76](https://github.com/zendframework/zend-db/pull/76) fixes the behavior of + `Zend\Db\Sql\Insert` when an array of names is used for columns to ensure the + string names are used, and not the array indices. +- [#91](https://github.com/zendframework/zend-db/pull/91) fixes the behavior of + the `Oci8` adapter when initializing a result set; previously, it was + improperly assigning the count of affected rows to the generated value. +- [#95](https://github.com/zendframework/zend-db/pull/95) fixes the `IbmDb2` + platform's `quoteIdentifier()` method to properly allow `#` characters in + identifiers (as they are commonly used on that platform). + +## 2.7.0 - 2016-02-22 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#85](https://github.com/zendframework/zend-db/pull/85) and + [#87](https://github.com/zendframework/zend-db/pull/87) update the code base + to be forwards compatible with: + - zend-eventmanager v3 + - zend-hydrator v2.1 + - zend-servicemanager v3 + - zend-stdlib v3 + +## 2.6.2 - 2015-12-09 + +### Added + +- [#49](https://github.com/zendframework/zend-db/pull/49) Add docbook + documentation. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#55](https://github.com/zendframework/zend-db/pull/55) Implement FeatureSet + canCallMagicCall and callMagicCall methods +- [#56](https://github.com/zendframework/zend-db/pull/56) + AbstractResultSet::current now does validation to ensure an array. +- [#58](https://github.com/zendframework/zend-db/pull/58) Fix unbuffered result + on MySQLi. +- [#59](https://github.com/zendframework/zend-db/pull/59) Allow unix_socket + parameter + +## 2.6.1 - 2015-10-14 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#31](https://github.com/zendframework/zend-db/pull/31) fixes table gateway + update when there is a table alias utilized. + +## 2.6.1 - 2015-10-14 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#43](https://github.com/zendframework/zend-db/pull/43) unset and get during + an insert operation would throw an InvalidArgumentException during an insert. + +## 2.6.0 - 2015-09-22 + +### Added + +- [#42](https://github.com/zendframework/zend-db/pull/42) updates the component + to use zend-hydrator for hydrator functionality; this provides forward + compatibility with zend-hydrator, and backwards compatibility with + hydrators from older versions of zend-stdlib. +- [#15](https://github.com/zendframework/zend-db/pull/15) adds a new predicate, + `Zend\Db\Sql\Predicate\NotBetween`, which can be invoked via `Sql` + instances: `$sql->notBetween($field, $min, $max)`. +- [#22](https://github.com/zendframework/zend-db/pull/22) extracts a factory, + `Zend\Db\Metadata\Source\Factory`, from `Zend\Db\Metadata\Metadata`, + removing the (non-public) `createSourceFromAdapter()` method from that + class. Additionally, it extracts `Zend\Db\Metadata\MetadataInterface`, to + allow creating alternate implementations. + +### Deprecated + +- [#27](https://github.com/zendframework/zend-db/pull/27) deprecates the + constants `JOIN_OUTER_LEFT` and `JOIN_OUTER_RIGHT` in favor of + `JOIN_LEFT_OUTER` and `JOIN_RIGHT_OUTER`. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + +## 2.5.2 - 2015-09-22 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- [#29](https://github.com/zendframework/zend-db/pull/29) removes the required + second argument to `Zend\Db\Predicate\Predicate::expression()`, allowing it to + be nullable, and mirroring the constructor of `Zend\Db\Predicate\Expression`. + +### Fixed + +- [#40](https://github.com/zendframework/zend-db/pull/40) updates the + zend-stdlib dependency to reference `>=2.5.0,<2.7.0` to ensure hydrators + will work as expected following extraction of hydrators to the zend-hydrator + repository. +- [#34](https://github.com/zendframework/zend-db/pull/34) fixes retrieval of + constraint metadata in the Oracle adapter. +- [#41](https://github.com/zendframework/zend-db/pull/41) removes hard dependency + on EventManager in AbstractTableGateway. +- [#17](https://github.com/zendframework/zend-db/pull/17) removes an executable + bit on a regular file. +- [#3](https://github.com/zendframework/zend-db/pull/3) updates the code to use + closure binding (now that we're on 5.5+, this is possible). +- [#9](https://github.com/zendframework/zend-db/pull/9) thoroughly audits the + OCI8 (Oracle) driver, ensuring it provides feature parity with other drivers, + and fixes issues with subselects, limits, and offsets. diff --git a/bundled-libs/zendframework/zend-db/LICENSE.md b/bundled-libs/zendframework/zend-db/LICENSE.md new file mode 100644 index 00000000..63df4102 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/LICENSE.md @@ -0,0 +1,27 @@ +Copyright (c) 2005-2017, Zend Technologies USA, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +- Neither the name of Zend Technologies USA, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bundled-libs/zendframework/zend-db/README.md b/bundled-libs/zendframework/zend-db/README.md new file mode 100644 index 00000000..0b1243d6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/README.md @@ -0,0 +1,12 @@ +# zend-db + +[![Build Status](https://secure.travis-ci.org/zendframework/zend-db.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-db) +[![Coverage Status](https://coveralls.io/repos/github/zendframework/zend-db/badge.svg?branch=master)](https://coveralls.io/github/zendframework/zend-db?branch=master) + +`Zend\Db` is a component that abstract the access to a Database using an object +oriented API to build the queries. `Zend\Db` consumes different storage adapters +to access different database vendors such as MySQL, PostgreSQL, Oracle, IBM DB2, +Microsoft Sql Server, PDO, etc. + +- File issues at https://github.com/zendframework/zend-db/issues +- Documentation is at https://docs.zendframework.com/zend-db/ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterServiceFactory.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterServiceFactory.php deleted file mode 100644 index 8d995a64..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterServiceFactory.php +++ /dev/null @@ -1,28 +0,0 @@ -get('Config'); - return new Adapter($config['db']); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/IbmDb2.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/IbmDb2.php deleted file mode 100644 index 67742134..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/IbmDb2.php +++ /dev/null @@ -1,209 +0,0 @@ -quoteIdentifiers = false; - } - - if (isset($options['identifier_separator'])) { - $this->identifierSeparator = $options['identifier_separator']; - } - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return 'IBM DB2'; - } - - /** - * Get quote indentifier symbol - * - * @return string - */ - public function getQuoteIdentifierSymbol() - { - return '"'; - } - - /** - * Quote identifier - * - * @param string $identifier - * @return string - */ - public function quoteIdentifier($identifier) - { - if ($this->quoteIdentifiers === false) { - return $identifier; - } - return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; - } - - /** - * Quote identifier chain - * - * @param string|string[] $identifierChain - * @return string - */ - public function quoteIdentifierChain($identifierChain) - { - if ($this->quoteIdentifiers === false) { - return (is_array($identifierChain)) ? implode($this->identifierSeparator, $identifierChain) : $identifierChain; - } - $identifierChain = str_replace('"', '\\"', $identifierChain); - if (is_array($identifierChain)) { - $identifierChain = implode('"' . $this->identifierSeparator . '"', $identifierChain); - } - return '"' . $identifierChain . '"'; - } - - /** - * Get quote value symbol - * - * @return string - */ - public function getQuoteValueSymbol() - { - return '\''; - } - - /** - * Quote value - * - * @param string $value - * @return string - */ - public function quoteValue($value) - { - if (function_exists('db2_escape_string')) { - return '\'' . db2_escape_string($value) . '\''; - } - trigger_error( - 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' - . 'can introduce security vulnerabilities in a production environment.' - ); - return '\'' . str_replace("'", "''", $value) . '\''; - } - - /** - * Quote Trusted Value - * - * The ability to quote values without notices - * - * @param $value - * @return mixed - */ - public function quoteTrustedValue($value) - { - if (function_exists('db2_escape_string')) { - return '\'' . db2_escape_string($value) . '\''; - } - return '\'' . str_replace("'", "''", $value) . '\''; - } - - /** - * Quote value list - * - * @param string|string[] $valueList - * @return string - */ - public function quoteValueList($valueList) - { - if (!is_array($valueList)) { - return $this->quoteValue($valueList); - } - - $value = reset($valueList); - do { - $valueList[key($valueList)] = $this->quoteValue($value); - } while ($value = next($valueList)); - return implode(', ', $valueList); - } - - /** - * Get identifier separator - * - * @return string - */ - public function getIdentifierSeparator() - { - return $this->identifierSeparator; - } - - /** - * Quote identifier in fragment - * - * @param string $identifier - * @param array $safeWords - * @return string - */ - public function quoteIdentifierInFragment($identifier, array $safeWords = array()) - { - if ($this->quoteIdentifiers === false) { - return $identifier; - } - $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - - if ($safeWords) { - $safeWords = array_flip($safeWords); - $safeWords = array_change_key_case($safeWords, CASE_LOWER); - } - foreach ($parts as $i => $part) { - if ($safeWords && isset($safeWords[strtolower($part)])) { - continue; - } - - switch ($part) { - case ' ': - case '.': - case '*': - case 'AS': - case 'As': - case 'aS': - case 'as': - break; - default: - $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; - } - } - - return implode('', $parts); - } - -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Mysql.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Mysql.php deleted file mode 100644 index 3b16f260..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Mysql.php +++ /dev/null @@ -1,214 +0,0 @@ -setDriver($driver); - } - } - - /** - * @param \Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo||\mysqli|\PDO $driver - * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException - * @return $this - */ - public function setDriver($driver) - { - // handle Zend\Db drivers - if ($driver instanceof Mysqli\Mysqli - || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Mysql') - || ($driver instanceof \mysqli) - || ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql') - ) { - $this->resource = $driver; - return $this; - } - - throw new Exception\InvalidArgumentException('$driver must be a Mysqli or Mysql PDO Zend\Db\Adapter\Driver, Mysqli instance or MySQL PDO instance'); - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return 'MySQL'; - } - - /** - * Get quote identifier symbol - * - * @return string - */ - public function getQuoteIdentifierSymbol() - { - return '`'; - } - - /** - * Quote identifier - * - * @param string $identifier - * @return string - */ - public function quoteIdentifier($identifier) - { - return '`' . str_replace('`', '``', $identifier) . '`'; - } - - /** - * Quote identifier chain - * - * @param string|string[] $identifierChain - * @return string - */ - public function quoteIdentifierChain($identifierChain) - { - $identifierChain = str_replace('`', '``', $identifierChain); - if (is_array($identifierChain)) { - $identifierChain = implode('`.`', $identifierChain); - } - return '`' . $identifierChain . '`'; - } - - /** - * Get quote value symbol - * - * @return string - */ - public function getQuoteValueSymbol() - { - return '\''; - } - - /** - * Quote value - * - * @param string $value - * @return string - */ - public function quoteValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if ($this->resource instanceof \mysqli) { - return '\'' . $this->resource->real_escape_string($value) . '\''; - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - trigger_error( - 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' - . 'can introduce security vulnerabilities in a production environment.' - ); - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote Trusted Value - * - * The ability to quote values without notices - * - * @param $value - * @return mixed - */ - public function quoteTrustedValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if ($this->resource instanceof \mysqli) { - return '\'' . $this->resource->real_escape_string($value) . '\''; - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote value list - * - * @param string|string[] $valueList - * @return string - */ - public function quoteValueList($valueList) - { - if (!is_array($valueList)) { - return $this->quoteValue($valueList); - } - - $value = reset($valueList); - do { - $valueList[key($valueList)] = $this->quoteValue($value); - } while ($value = next($valueList)); - return implode(', ', $valueList); - } - - /** - * Get identifier separator - * - * @return string - */ - public function getIdentifierSeparator() - { - return '.'; - } - - /** - * Quote identifier in fragment - * - * @param string $identifier - * @param array $safeWords - * @return string - */ - public function quoteIdentifierInFragment($identifier, array $safeWords = array()) - { - // regex taken from @link http://dev.mysql.com/doc/refman/5.0/en/identifiers.html - $parts = preg_split('#([^0-9,a-z,A-Z$_])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - if ($safeWords) { - $safeWords = array_flip($safeWords); - $safeWords = array_change_key_case($safeWords, CASE_LOWER); - } - foreach ($parts as $i => $part) { - if ($safeWords && isset($safeWords[strtolower($part)])) { - continue; - } - switch ($part) { - case ' ': - case '.': - case '*': - case 'AS': - case 'As': - case 'aS': - case 'as': - break; - default: - $parts[$i] = '`' . str_replace('`', '``', $part) . '`'; - } - } - return implode('', $parts); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Oracle.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Oracle.php deleted file mode 100644 index 9081243d..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Oracle.php +++ /dev/null @@ -1,189 +0,0 @@ -quoteIdentifiers = false; - } - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return 'Oracle'; - } - - /** - * Get quote identifier symbol - * - * @return string - */ - public function getQuoteIdentifierSymbol() - { - return '"'; - } - - /** - * Quote identifier - * - * @param string $identifier - * @return string - */ - public function quoteIdentifier($identifier) - { - if ($this->quoteIdentifiers === false) { - return $identifier; - } - return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; - } - - /** - * Quote identifier chain - * - * @param string|string[] $identifierChain - * @return string - */ - public function quoteIdentifierChain($identifierChain) - { - if ($this->quoteIdentifiers === false) { - return (is_array($identifierChain)) ? implode('.', $identifierChain) : $identifierChain; - } - $identifierChain = str_replace('"', '\\"', $identifierChain); - if (is_array($identifierChain)) { - $identifierChain = implode('"."', $identifierChain); - } - return '"' . $identifierChain . '"'; - } - - /** - * Get quote value symbol - * - * @return string - */ - public function getQuoteValueSymbol() - { - return '\''; - } - - /** - * Quote value - * - * @param string $value - * @return string - */ - public function quoteValue($value) - { - trigger_error( - 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' - . 'can introduce security vulnerabilities in a production environment.' - ); - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote Trusted Value - * - * The ability to quote values without notices - * - * @param $value - * @return mixed - */ - public function quoteTrustedValue($value) - { - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote value list - * - * @param string|string[] $valueList - * @return string - */ - public function quoteValueList($valueList) - { - if (!is_array($valueList)) { - return $this->quoteValue($valueList); - } - - $value = reset($valueList); - do { - $valueList[key($valueList)] = $this->quoteValue($value); - } while ($value = next($valueList)); - return implode(', ', $valueList); - } - - /** - * Get identifier separator - * - * @return string - */ - public function getIdentifierSeparator() - { - return '.'; - } - - /** - * Quote identifier in fragment - * - * @param string $identifier - * @param array $safeWords - * @return string - */ - public function quoteIdentifierInFragment($identifier, array $safeWords = array()) - { - if ($this->quoteIdentifiers === false) { - return $identifier; - } - $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - if ($safeWords) { - $safeWords = array_flip($safeWords); - $safeWords = array_change_key_case($safeWords, CASE_LOWER); - } - foreach ($parts as $i => $part) { - if ($safeWords && isset($safeWords[strtolower($part)])) { - continue; - } - switch ($part) { - case ' ': - case '.': - case '*': - case 'AS': - case 'As': - case 'aS': - case 'as': - break; - default: - $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; - } - } - return implode('', $parts); - } - -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Postgresql.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Postgresql.php deleted file mode 100644 index 71247a5f..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Postgresql.php +++ /dev/null @@ -1,213 +0,0 @@ -setDriver($driver); - } - } - - /** - * @param \Zend\Db\Adapter\Driver\Pgsql\Pgsql|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver - * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException - * @return $this - */ - public function setDriver($driver) - { - if ($driver instanceof Pgsql\Pgsql - || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Postgresql') - || (is_resource($driver) && (in_array(get_resource_type($driver), array('pgsql link', 'pgsql link persistent')))) - || ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql') - ) { - $this->resource = $driver; - return $this; - } - - throw new Exception\InvalidArgumentException('$driver must be a Pgsql or Postgresql PDO Zend\Db\Adapter\Driver, pgsql link resource or Postgresql PDO instance'); - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return 'PostgreSQL'; - } - - /** - * Get quote indentifier symbol - * - * @return string - */ - public function getQuoteIdentifierSymbol() - { - return '"'; - } - - /** - * Quote identifier - * - * @param string $identifier - * @return string - */ - public function quoteIdentifier($identifier) - { - return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; - } - - /** - * Quote identifier chain - * - * @param string|string[] $identifierChain - * @return string - */ - public function quoteIdentifierChain($identifierChain) - { - $identifierChain = str_replace('"', '\\"', $identifierChain); - if (is_array($identifierChain)) { - $identifierChain = implode('"."', $identifierChain); - } - return '"' . $identifierChain . '"'; - } - - /** - * Get quote value symbol - * - * @return string - */ - public function getQuoteValueSymbol() - { - return '\''; - } - - /** - * Quote value - * - * @param string $value - * @return string - */ - public function quoteValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if (is_resource($this->resource)) { - return '\'' . pg_escape_string($this->resource, $value) . '\''; - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - trigger_error( - 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' - . 'can introduce security vulnerabilities in a production environment.' - ); - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote Trusted Value - * - * The ability to quote values without notices - * - * @param $value - * @return mixed - */ - public function quoteTrustedValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if (is_resource($this->resource)) { - return '\'' . pg_escape_string($this->resource, $value) . '\''; - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote value list - * - * @param string|string[] $valueList - * @return string - */ - public function quoteValueList($valueList) - { - if (!is_array($valueList)) { - return $this->quoteValue($valueList); - } - - $value = reset($valueList); - do { - $valueList[key($valueList)] = $this->quoteValue($value); - } while ($value = next($valueList)); - return implode(', ', $valueList); - } - - /** - * Get identifier separator - * - * @return string - */ - public function getIdentifierSeparator() - { - return '.'; - } - - /** - * Quote identifier in fragment - * - * @param string $identifier - * @param array $safeWords - * @return string - */ - public function quoteIdentifierInFragment($identifier, array $safeWords = array()) - { - $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - if ($safeWords) { - $safeWords = array_flip($safeWords); - $safeWords = array_change_key_case($safeWords, CASE_LOWER); - } - foreach ($parts as $i => $part) { - if ($safeWords && isset($safeWords[strtolower($part)])) { - continue; - } - switch ($part) { - case ' ': - case '.': - case '*': - case 'AS': - case 'As': - case 'aS': - case 'as': - break; - default: - $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; - } - } - return implode('', $parts); - } - -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sql92.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sql92.php deleted file mode 100644 index 681774c4..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sql92.php +++ /dev/null @@ -1,162 +0,0 @@ -quoteValue($valueList); - } - - $value = reset($valueList); - do { - $valueList[key($valueList)] = $this->quoteValue($value); - } while ($value = next($valueList)); - return implode(', ', $valueList); - } - - /** - * Get identifier separator - * - * @return string - */ - public function getIdentifierSeparator() - { - return '.'; - } - - /** - * Quote identifier in fragment - * - * @param string $identifier - * @param array $safeWords - * @return string - */ - public function quoteIdentifierInFragment($identifier, array $safeWords = array()) - { - $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - if ($safeWords) { - $safeWords = array_flip($safeWords); - $safeWords = array_change_key_case($safeWords, CASE_LOWER); - } - foreach ($parts as $i => $part) { - if ($safeWords && isset($safeWords[strtolower($part)])) { - continue; - } - - switch ($part) { - case ' ': - case '.': - case '*': - case 'AS': - case 'As': - case 'aS': - case 'as': - break; - default: - $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; - } - } - - return implode('', $parts); - } - -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/SqlServer.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/SqlServer.php deleted file mode 100644 index 2d242349..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/SqlServer.php +++ /dev/null @@ -1,204 +0,0 @@ -setDriver($driver); - } - } - - /** - * @param \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo||resource|\PDO $driver - * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException - * @return $this - */ - public function setDriver($driver) - { - // handle Zend_Db drivers - if (($driver instanceof Pdo\Pdo && in_array($driver->getDatabasePlatformName(), array('Sqlsrv', 'Dblib'))) - || (($driver instanceof \PDO && in_array($driver->getAttribute(\PDO::ATTR_DRIVER_NAME), array('sqlsrv', 'dblib')))) - ) { - $this->resource = $driver; - return $this; - } - - throw new Exception\InvalidArgumentException('$driver must be a Sqlsrv PDO Zend\Db\Adapter\Driver or Sqlsrv PDO instance'); - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return 'SQLServer'; - } - - /** - * Get quote identifier symbol - * - * @return string - */ - public function getQuoteIdentifierSymbol() - { - return array('[', ']'); - } - - /** - * Quote identifier - * - * @param string $identifier - * @return string - */ - public function quoteIdentifier($identifier) - { - return '[' . $identifier . ']'; - } - - /** - * Quote identifier chain - * - * @param string|string[] $identifierChain - * @return string - */ - public function quoteIdentifierChain($identifierChain) - { - if (is_array($identifierChain)) { - $identifierChain = implode('].[', $identifierChain); - } - return '[' . $identifierChain . ']'; - } - - /** - * Get quote value symbol - * - * @return string - */ - public function getQuoteValueSymbol() - { - return '\''; - } - - /** - * Quote value - * - * @param string $value - * @return string - */ - public function quoteValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - trigger_error( - 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' - . 'can introduce security vulnerabilities in a production environment.' - ); - return '\'' . str_replace('\'', '\'\'', $value) . '\''; - } - - /** - * Quote Trusted Value - * - * The ability to quote values without notices - * - * @param $value - * @return mixed - */ - public function quoteTrustedValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - return '\'' . str_replace('\'', '\'\'', $value) . '\''; - } - - /** - * Quote value list - * - * @param string|string[] $valueList - * @return string - */ - public function quoteValueList($valueList) - { - if (!is_array($valueList)) { - return $this->quoteValue($valueList); - } - $value = reset($valueList); - do { - $valueList[key($valueList)] = $this->quoteValue($value); - } while ($value = next($valueList)); - return implode(', ', $valueList); - } - - /** - * Get identifier separator - * - * @return string - */ - public function getIdentifierSeparator() - { - return '.'; - } - - /** - * Quote identifier in fragment - * - * @param string $identifier - * @param array $safeWords - * @return string - */ - public function quoteIdentifierInFragment($identifier, array $safeWords = array()) - { - $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - if ($safeWords) { - $safeWords = array_flip($safeWords); - $safeWords = array_change_key_case($safeWords, CASE_LOWER); - } - foreach ($parts as $i => $part) { - if ($safeWords && isset($safeWords[strtolower($part)])) { - continue; - } - switch ($part) { - case ' ': - case '.': - case '*': - case 'AS': - case 'As': - case 'aS': - case 'as': - break; - default: - $parts[$i] = '[' . $part . ']'; - } - } - return implode('', $parts); - } - -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sqlite.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sqlite.php deleted file mode 100644 index f4dc7697..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/Sqlite.php +++ /dev/null @@ -1,204 +0,0 @@ -setDriver($driver); - } - } - - /** - * @param \Zend\Db\Adapter\Driver\Pdo\Pdo||\PDO $driver - * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException - * @return $this - */ - public function setDriver($driver) - { - if (($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlite') - || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlite') - ) { - $this->resource = $driver; - return $this; - } - - throw new Exception\InvalidArgumentException('$driver must be a Sqlite PDO Zend\Db\Adapter\Driver, Sqlite PDO instance'); - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return 'SQLite'; - } - - /** - * Get quote identifier symbol - * - * @return string - */ - public function getQuoteIdentifierSymbol() - { - return '"'; - } - - /** - * Quote identifier - * - * @param string $identifier - * @return string - */ - public function quoteIdentifier($identifier) - { - return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; - } - - /** - * Quote identifier chain - * - * @param string|string[] $identifierChain - * @return string - */ - public function quoteIdentifierChain($identifierChain) - { - $identifierChain = str_replace('"', '\\"', $identifierChain); - if (is_array($identifierChain)) { - $identifierChain = implode('"."', $identifierChain); - } - return '"' . $identifierChain . '"'; - } - - /** - * Get quote value symbol - * - * @return string - */ - public function getQuoteValueSymbol() - { - return '\''; - } - - /** - * Quote value - * - * @param string $value - * @return string - */ - public function quoteValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - trigger_error( - 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' - . 'can introduce security vulnerabilities in a production environment.' - ); - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote Trusted Value - * - * The ability to quote values without notices - * - * @param $value - * @return mixed - */ - public function quoteTrustedValue($value) - { - if ($this->resource instanceof DriverInterface) { - $this->resource = $this->resource->getConnection()->getResource(); - } - if ($this->resource instanceof \PDO) { - return $this->resource->quote($value); - } - return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; - } - - /** - * Quote value list - * - * @param string|string[] $valueList - * @return string - */ - public function quoteValueList($valueList) - { - if (!is_array($valueList)) { - return $this->quoteValue($valueList); - } - $value = reset($valueList); - do { - $valueList[key($valueList)] = $this->quoteValue($value); - } while ($value = next($valueList)); - return implode(', ', $valueList); - } - - /** - * Get identifier separator - * - * @return string - */ - public function getIdentifierSeparator() - { - return '.'; - } - - /** - * Quote identifier in fragment - * - * @param string $identifier - * @param array $safeWords - * @return string - */ - public function quoteIdentifierInFragment($identifier, array $safeWords = array()) - { - $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - if ($safeWords) { - $safeWords = array_flip($safeWords); - $safeWords = array_change_key_case($safeWords, CASE_LOWER); - } - foreach ($parts as $i => $part) { - if ($safeWords && isset($safeWords[strtolower($part)])) { - continue; - } - switch ($part) { - case ' ': - case '.': - case '*': - case 'AS': - case 'As': - case 'aS': - case 'as': - break; - default: - $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; - } - } - return implode('', $parts); - } - -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerAwareInterface.php b/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerAwareInterface.php deleted file mode 100644 index 189e1c56..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerAwareInterface.php +++ /dev/null @@ -1,8 +0,0 @@ - '', 'subselectCount' => 0); - - /** - * @var array - */ - protected $instanceParameterIndex = array(); - - protected function processExpression(ExpressionInterface $expression, PlatformInterface $platform, DriverInterface $driver = null, $namedParameterPrefix = null) - { - // static counter for the number of times this method was invoked across the PHP runtime - static $runtimeExpressionPrefix = 0; - - if ($driver && ((!is_string($namedParameterPrefix) || $namedParameterPrefix == ''))) { - $namedParameterPrefix = sprintf('expr%04dParam', ++$runtimeExpressionPrefix); - } - - $sql = ''; - $statementContainer = new StatementContainer; - $parameterContainer = $statementContainer->getParameterContainer(); - - // initialize variables - $parts = $expression->getExpressionData(); - - if (!isset($this->instanceParameterIndex[$namedParameterPrefix])) { - $this->instanceParameterIndex[$namedParameterPrefix] = 1; - } - - $expressionParamIndex = &$this->instanceParameterIndex[$namedParameterPrefix]; - - foreach ($parts as $part) { - - // if it is a string, simply tack it onto the return sql "specification" string - if (is_string($part)) { - $sql .= $part; - continue; - } - - if (!is_array($part)) { - throw new Exception\RuntimeException('Elements returned from getExpressionData() array must be a string or array.'); - } - - // 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) { - if (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_IDENTIFIER) { - $values[$vIndex] = $platform->quoteIdentifierInFragment($value); - } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_VALUE && $value instanceof Select) { - // process sub-select - if ($driver) { - $values[$vIndex] = '(' . $this->processSubSelect($value, $platform, $driver, $parameterContainer) . ')'; - } else { - $values[$vIndex] = '(' . $this->processSubSelect($value, $platform) . ')'; - } - } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_VALUE && $value instanceof ExpressionInterface) { - // recursive call to satisfy nested expressions - $innerStatementContainer = $this->processExpression($value, $platform, $driver, $namedParameterPrefix . $vIndex . 'subpart'); - $values[$vIndex] = $innerStatementContainer->getSql(); - if ($driver) { - $parameterContainer->merge($innerStatementContainer->getParameterContainer()); - } - } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_VALUE) { - - // if prepareType is set, it means that this particular value must be - // passed back to the statement in a way it can be used as a placeholder value - if ($driver) { - $name = $namedParameterPrefix . $expressionParamIndex++; - $parameterContainer->offsetSet($name, $value); - $values[$vIndex] = $driver->formatParameterName($name); - continue; - } - - // if not a preparable statement, simply quote the value and move on - $values[$vIndex] = $platform->quoteValue($value); - } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_LITERAL) { - $values[$vIndex] = $value; - } - } - - // after looping the values, interpolate them into the sql string (they might be placeholder names, or values) - $sql .= vsprintf($part[0], $values); - } - - $statementContainer->setSql($sql); - return $statementContainer; - } - - /** - * @param $specifications - * @param $parameters - * @return string - * @throws Exception\RuntimeException - */ - protected function createSqlFromSpecificationAndParameters($specifications, $parameters) - { - if (is_string($specifications)) { - return vsprintf($specifications, $parameters); - } - - $parametersCount = count($parameters); - foreach ($specifications as $specificationString => $paramSpecs) { - if ($parametersCount == count($paramSpecs)) { - break; - } - unset($specificationString, $paramSpecs); - } - - if (!isset($specificationString)) { - throw new Exception\RuntimeException( - 'A number of parameters was found that is not supported by this specification' - ); - } - - $topParameters = array(); - foreach ($parameters as $position => $paramsForPosition) { - if (isset($paramSpecs[$position]['combinedby'])) { - $multiParamValues = array(); - 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'); - } - $multiParamValues[] = vsprintf($paramSpecs[$position][$ppCount], $multiParamsForPosition); - } - $topParameters[] = implode($paramSpecs[$position]['combinedby'], $multiParamValues); - } 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'); - } - $topParameters[] = vsprintf($paramSpecs[$position][$ppCount], $paramsForPosition); - } else { - $topParameters[] = $paramsForPosition; - } - } - return vsprintf($specificationString, $topParameters); - } - - protected function processSubSelect(Select $subselect, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($driver) { - $stmtContainer = new StatementContainer; - - // Track subselect prefix and count for parameters - $this->processInfo['subselectCount']++; - $subselect->processInfo['subselectCount'] = $this->processInfo['subselectCount']; - $subselect->processInfo['paramPrefix'] = 'subselect' . $subselect->processInfo['subselectCount']; - - // call subselect - $subselect->prepareStatement(new \Zend\Db\Adapter\Adapter($driver, $platform), $stmtContainer); - - // copy count - $this->processInfo['subselectCount'] = $subselect->processInfo['subselectCount']; - - $parameterContainer->merge($stmtContainer->getParameterContainer()->getNamedArray()); - $sql = $stmtContainer->getSql(); - } else { - $sql = $subselect->getSqlString($platform); - } - return $sql; - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Blob.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Blob.php deleted file mode 100644 index db879b5c..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Blob.php +++ /dev/null @@ -1,91 +0,0 @@ -setName($name); - $this->setLength($length); - $this->setNullable($nullable); - $this->setDefault($default); - $this->setOptions($options); - } - - /** - * @param int $length - * @return self - */ - public function setLength($length) - { - $this->length = $length; - return $this; - } - - /** - * @return int - */ - public function getLength() - { - return $this->length; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - - $params = array(); - $params[] = $this->name; - $params[] = $this->type; - - if ($this->length) { - $params[1] .= ' ' . $this->length; - } - - $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); - - if (!$this->isNullable) { - $params[1] .= ' NOT NULL'; - } - - if ($this->default !== null) { - $spec .= ' DEFAULT %s'; - $params[] = $this->default; - $types[] = self::TYPE_VALUE; - } - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Boolean.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Boolean.php deleted file mode 100644 index d6255e53..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Boolean.php +++ /dev/null @@ -1,42 +0,0 @@ -name = $name; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array($this->name); - $types = array(self::TYPE_IDENTIFIER); - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Char.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Char.php deleted file mode 100644 index 3f1315a5..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Char.php +++ /dev/null @@ -1,58 +0,0 @@ -name = $name; - $this->length = $length; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array(); - - $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); - $params[] = $this->name; - $params[] = $this->length; - - $types[] = self::TYPE_LITERAL; - $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; - - $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; - $params[] = ($this->default !== null) ? $this->default : ''; - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Date.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Date.php deleted file mode 100644 index 930b89a3..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Date.php +++ /dev/null @@ -1,50 +0,0 @@ -name = $name; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array(); - - $types = array(self::TYPE_IDENTIFIER); - $params[] = $this->name; - - $types[] = self::TYPE_LITERAL; - $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; - - $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; - $params[] = ($this->default !== null) ? $this->default : ''; - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Decimal.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Decimal.php deleted file mode 100644 index 1983099a..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Decimal.php +++ /dev/null @@ -1,69 +0,0 @@ -name = $name; - $this->precision = $precision; - $this->scale = $scale; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array(); - - $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); - $params[] = $this->name; - $params[] = $this->precision; - - if ($this->scale !== null) { - $params[1] .= ', ' . $this->scale; - } - - $types[] = self::TYPE_LITERAL; - $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; - - $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; - $params[] = ($this->default !== null) ? $this->default : ''; - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Float.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Float.php deleted file mode 100644 index 6fe3751b..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Float.php +++ /dev/null @@ -1,66 +0,0 @@ -name = $name; - $this->digits = $digits; - $this->decimal = $decimal; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array(); - - $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); - $params[] = $this->name; - $params[] = $this->digits; - $params[1] .= ', ' . $this->decimal; - - $types[] = self::TYPE_LITERAL; - $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; - - $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; - $params[] = ($this->default !== null) ? $this->default : ''; - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Integer.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Integer.php deleted file mode 100644 index 670a7276..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Integer.php +++ /dev/null @@ -1,32 +0,0 @@ -setName($name); - $this->setNullable($nullable); - $this->setDefault($default); - $this->setOptions($options); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Text.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Text.php deleted file mode 100644 index ee07aafb..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Text.php +++ /dev/null @@ -1,52 +0,0 @@ -name = $name; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array(); - - $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); - $params[] = $this->name; - - $types[] = self::TYPE_LITERAL; - $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; - - $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; - $params[] = ($this->default !== null) ? $this->default : ''; - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Time.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Time.php deleted file mode 100644 index 60c11ad5..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Time.php +++ /dev/null @@ -1,50 +0,0 @@ -name = $name; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array(); - - $types = array(self::TYPE_IDENTIFIER); - $params[] = $this->name; - - $types[] = self::TYPE_LITERAL; - $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; - - $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; - $params[] = ($this->default !== null) ? $this->default : ''; - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Varchar.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Varchar.php deleted file mode 100644 index 7da9a362..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Varchar.php +++ /dev/null @@ -1,58 +0,0 @@ -name = $name; - $this->length = $length; - } - - /** - * @return array - */ - public function getExpressionData() - { - $spec = $this->specification; - $params = array(); - - $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); - $params[] = $this->name; - $params[] = $this->length; - - $types[] = self::TYPE_LITERAL; - $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; - - $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; - $params[] = ($this->default !== null) ? $this->default : ''; - - return array(array( - $spec, - $params, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php deleted file mode 100644 index 9212d805..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php +++ /dev/null @@ -1,58 +0,0 @@ -setColumns($columns); - } - - /** - * @param null|string|array $columns - * @return self - */ - public function setColumns($columns) - { - if (!is_array($columns)) { - $columns = array($columns); - } - - $this->columns = $columns; - return $this; - } - - /** - * @param string $column - * @return self - */ - public function addColumn($column) - { - $this->columns[] = $column; - return $this; - } - - /** - * @return array - */ - public function getColumns() - { - return $this->columns; - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ForeignKey.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ForeignKey.php deleted file mode 100644 index c29df551..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ForeignKey.php +++ /dev/null @@ -1,177 +0,0 @@ -setName($name); - $this->setColumns($column); - $this->setReferenceTable($referenceTable); - $this->setReferenceColumn($referenceColumn); - (!$onDeleteRule) ?: $this->setOnDeleteRule($onDeleteRule); - (!$onUpdateRule) ?: $this->setOnUpdateRule($onUpdateRule); - } - - /** - * @param string $name - * @return self - */ - public function setName($name) - { - $this->name = $name; - return $this; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $referenceTable - * @return self - */ - public function setReferenceTable($referenceTable) - { - $this->referenceTable = $referenceTable; - return $this; - } - - /** - * @return string - */ - public function getReferenceTable() - { - return $this->referenceTable; - } - - /** - * @param string $referenceColumn - * @return self - */ - public function setReferenceColumn($referenceColumn) - { - $this->referenceColumn = $referenceColumn; - return $this; - } - - /** - * @return string - */ - public function getReferenceColumn() - { - return $this->referenceColumn; - } - - /** - * @param string $onDeleteRule - * @return self - */ - public function setOnDeleteRule($onDeleteRule) - { - $this->onDeleteRule = $onDeleteRule; - return $this; - } - - /** - * @return string - */ - public function getOnDeleteRule() - { - return $this->onDeleteRule; - } - - /** - * @param string $onUpdateRule - * @return self - */ - public function setOnUpdateRule($onUpdateRule) - { - $this->onUpdateRule = $onUpdateRule; - return $this; - } - - /** - * @return string - */ - public function getOnUpdateRule() - { - return $this->onUpdateRule; - } - - /** - * @return array - */ - public function getExpressionData() - { - return array(array( - $this->specification, - array( - $this->name, - $this->columns[0], - $this->referenceTable, - $this->referenceColumn, - $this->onDeleteRule, - $this->onUpdateRule, - ), - array( - self::TYPE_IDENTIFIER, - self::TYPE_IDENTIFIER, - self::TYPE_IDENTIFIER, - self::TYPE_IDENTIFIER, - self::TYPE_LITERAL, - self::TYPE_LITERAL, - ), - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php deleted file mode 100644 index 597c72c9..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php +++ /dev/null @@ -1,36 +0,0 @@ -columns); - $newSpecParts = array_fill(0, $colCount, '%s'); - $newSpecTypes = array_fill(0, $colCount, self::TYPE_IDENTIFIER); - - $newSpec = sprintf($this->specification, implode(', ', $newSpecParts)); - - return array(array( - $newSpec, - $this->columns, - $newSpecTypes, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/UniqueKey.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/UniqueKey.php deleted file mode 100644 index adb496cb..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/UniqueKey.php +++ /dev/null @@ -1,55 +0,0 @@ -setColumns($column); - $this->name = $name; - } - - /** - * @return array - */ - public function getExpressionData() - { - $colCount = count($this->columns); - - $values = array(); - $values[] = ($this->name) ? $this->name : ''; - - $newSpecTypes = array(self::TYPE_IDENTIFIER); - $newSpecParts = array(); - - for ($i = 0; $i < $colCount; $i++) { - $newSpecParts[] = '%s'; - $newSpecTypes[] = self::TYPE_IDENTIFIER; - } - - $newSpec = str_replace('...', implode(', ', $newSpecParts), $this->specification); - - return array(array( - $newSpec, - array_merge($values, $this->columns), - $newSpecTypes, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/DropTable.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/DropTable.php deleted file mode 100644 index ff7eea34..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/DropTable.php +++ /dev/null @@ -1,77 +0,0 @@ - 'DROP TABLE %1$s' - ); - - /** - * @var string - */ - protected $table = ''; - - /** - * @param string $table - */ - public function __construct($table = '') - { - $this->table = $table; - } - - /** - * @param null|PlatformInterface $adapterPlatform - * @return string - */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - // get platform, or create default - $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; - - $sqls = array(); - $parameters = array(); - - foreach ($this->specifications as $name => $specification) { - $parameters[$name] = $this->{'process' . $name}( - $adapterPlatform, - null, - null, - $sqls, - $parameters - ); - - if ($specification && is_array($parameters[$name])) { - $sqls[$name] = $this->createSqlFromSpecificationAndParameters( - $specification, - $parameters[$name] - ); - } - } - - $sql = implode(' ', $sqls); - return $sql; - } - - protected function processTable(PlatformInterface $adapterPlatform = null) - { - return array($adapterPlatform->quoteIdentifier($this->table)); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Delete.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Delete.php deleted file mode 100644 index d7452f96..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Delete.php +++ /dev/null @@ -1,244 +0,0 @@ - 'DELETE FROM %1$s', - self::SPECIFICATION_WHERE => 'WHERE %1$s' - ); - - /** - * @var string|TableIdentifier - */ - protected $table = ''; - - /** - * @var bool - */ - protected $emptyWhereProtection = true; - - /** - * @var array - */ - protected $set = array(); - - /** - * @var null|string|Where - */ - protected $where = null; - - /** - * Constructor - * - * @param null|string|TableIdentifier $table - */ - public function __construct($table = null) - { - if ($table) { - $this->from($table); - } - $this->where = new Where(); - } - - /** - * Create from statement - * - * @param string|TableIdentifier $table - * @return Delete - */ - public function from($table) - { - $this->table = $table; - return $this; - } - - public function getRawState($key = null) - { - $rawState = array( - 'emptyWhereProtection' => $this->emptyWhereProtection, - 'table' => $this->table, - 'set' => $this->set, - 'where' => $this->where - ); - return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; - } - - /** - * Create where clause - * - * @param Where|\Closure|string|array $predicate - * @param string $combination One of the OP_* constants from Predicate\PredicateSet - * @return Delete - */ - public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) - { - if ($predicate instanceof Where) { - $this->where = $predicate; - } elseif ($predicate instanceof \Closure) { - $predicate($this->where); - } else { - - if (is_string($predicate)) { - // String $predicate should be passed as an expression - $predicate = new Predicate\Expression($predicate); - $this->where->addPredicate($predicate, $combination); - } elseif (is_array($predicate)) { - - foreach ($predicate as $pkey => $pvalue) { - // loop through predicates - - if (is_string($pkey) && strpos($pkey, '?') !== false) { - // First, process strings that the abstraction replacement character ? - // as an Expression predicate - $predicate = new Predicate\Expression($pkey, $pvalue); - - } elseif (is_string($pkey)) { - // Otherwise, if still a string, do something intelligent with the PHP type provided - - if ($pvalue === null) { - // map PHP null to SQL IS NULL expression - $predicate = new Predicate\IsNull($pkey, $pvalue); - } elseif (is_array($pvalue)) { - // if the value is an array, assume IN() is desired - $predicate = new Predicate\In($pkey, $pvalue); - } else { - // otherwise assume that array('foo' => 'bar') means "foo" = 'bar' - $predicate = new Predicate\Operator($pkey, Predicate\Operator::OP_EQ, $pvalue); - } - } elseif ($pvalue instanceof Predicate\PredicateInterface) { - // Predicate type is ok - $predicate = $pvalue; - } else { - // must be an array of expressions (with int-indexed array) - $predicate = new Predicate\Expression($pvalue); - } - $this->where->addPredicate($predicate, $combination); - } - } - } - return $this; - } - - /** - * Prepare the delete statement - * - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - * @return void - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) - { - $driver = $adapter->getDriver(); - $platform = $adapter->getPlatform(); - $parameterContainer = $statementContainer->getParameterContainer(); - - if (!$parameterContainer instanceof ParameterContainer) { - $parameterContainer = new ParameterContainer(); - $statementContainer->setParameterContainer($parameterContainer); - } - - $table = $this->table; - $schema = null; - - // create quoted table name to use in delete processing - if ($table instanceof TableIdentifier) { - list($table, $schema) = $table->getTableAndSchema(); - } - - $table = $platform->quoteIdentifier($table); - - if ($schema) { - $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; - } - - $sql = sprintf($this->specifications[self::SPECIFICATION_DELETE], $table); - - // process where - if ($this->where->count() > 0) { - $whereParts = $this->processExpression($this->where, $platform, $driver, 'where'); - $parameterContainer->merge($whereParts->getParameterContainer()); - $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $whereParts->getSql()); - } - $statementContainer->setSql($sql); - } - - /** - * Get the SQL string, based on the platform - * - * Platform defaults to Sql92 if none provided - * - * @param null|PlatformInterface $adapterPlatform - * @return string - */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - $adapterPlatform = ($adapterPlatform) ?: new Sql92; - $table = $this->table; - $schema = null; - - // create quoted table name to use in delete processing - if ($table instanceof TableIdentifier) { - list($table, $schema) = $table->getTableAndSchema(); - } - - $table = $adapterPlatform->quoteIdentifier($table); - - if ($schema) { - $table = $adapterPlatform->quoteIdentifier($schema) . $adapterPlatform->getIdentifierSeparator() . $table; - } - - $sql = sprintf($this->specifications[self::SPECIFICATION_DELETE], $table); - - if ($this->where->count() > 0) { - $whereParts = $this->processExpression($this->where, $adapterPlatform, null, 'where'); - $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $whereParts->getSql()); - } - - return $sql; - } - - /** - * Property overloading - * - * Overloads "where" only. - * - * @param string $name - * @return mixed - */ - public function __get($name) - { - switch (strtolower($name)) { - case 'where': - return $this->where; - } - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Insert.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Insert.php deleted file mode 100644 index 1af38099..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Insert.php +++ /dev/null @@ -1,302 +0,0 @@ - 'INSERT INTO %1$s (%2$s) VALUES (%3$s)' - ); - - /** - * @var string|TableIdentifier - */ - protected $table = null; - protected $columns = array(); - - /** - * @var array - */ - protected $values = array(); - - /** - * Constructor - * - * @param null|string|TableIdentifier $table - */ - public function __construct($table = null) - { - if ($table) { - $this->into($table); - } - } - - /** - * Crete INTO clause - * - * @param string|TableIdentifier $table - * @return Insert - */ - public function into($table) - { - $this->table = $table; - return $this; - } - - /** - * Specify columns - * - * @param array $columns - * @return Insert - */ - public function columns(array $columns) - { - $this->columns = $columns; - return $this; - } - - /** - * Specify values to insert - * - * @param array $values - * @param string $flag one of VALUES_MERGE or VALUES_SET; defaults to VALUES_SET - * @throws Exception\InvalidArgumentException - * @return Insert - */ - public function values(array $values, $flag = self::VALUES_SET) - { - if ($values == null) { - throw new \InvalidArgumentException('values() expects an array of values'); - } - - // determine if this is assoc or a set of values - $keys = array_keys($values); - $firstKey = current($keys); - - if ($flag == self::VALUES_SET) { - $this->columns = array(); - $this->values = array(); - } - - if (is_string($firstKey)) { - foreach ($keys as $key) { - if (($index = array_search($key, $this->columns)) !== false) { - $this->values[$index] = $values[$key]; - } else { - $this->columns[] = $key; - $this->values[] = $values[$key]; - } - } - } elseif (is_int($firstKey)) { - // determine if count of columns should match count of values - $this->values = array_merge($this->values, array_values($values)); - } - - return $this; - } - - public function getRawState($key = null) - { - $rawState = array( - 'table' => $this->table, - 'columns' => $this->columns, - 'values' => $this->values - ); - return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; - } - - /** - * Prepare statement - * - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - * @return void - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) - { - $driver = $adapter->getDriver(); - $platform = $adapter->getPlatform(); - $parameterContainer = $statementContainer->getParameterContainer(); - - if (!$parameterContainer instanceof ParameterContainer) { - $parameterContainer = new ParameterContainer(); - $statementContainer->setParameterContainer($parameterContainer); - } - - $table = $this->table; - $schema = null; - - // create quoted table name to use in insert processing - if ($table instanceof TableIdentifier) { - list($table, $schema) = $table->getTableAndSchema(); - } - - $table = $platform->quoteIdentifier($table); - - if ($schema) { - $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; - } - - $columns = array(); - $values = array(); - - foreach ($this->columns as $cIndex => $column) { - $columns[$cIndex] = $platform->quoteIdentifier($column); - if (isset($this->values[$cIndex]) && $this->values[$cIndex] instanceof Expression) { - $exprData = $this->processExpression($this->values[$cIndex], $platform, $driver); - $values[$cIndex] = $exprData->getSql(); - $parameterContainer->merge($exprData->getParameterContainer()); - } else { - $values[$cIndex] = $driver->formatParameterName($column); - if (isset($this->values[$cIndex])) { - $parameterContainer->offsetSet($column, $this->values[$cIndex]); - } else { - $parameterContainer->offsetSet($column, null); - } - } - } - - $sql = sprintf( - $this->specifications[self::SPECIFICATION_INSERT], - $table, - implode(', ', $columns), - implode(', ', $values) - ); - - $statementContainer->setSql($sql); - } - - /** - * Get SQL string for this statement - * - * @param null|PlatformInterface $adapterPlatform Defaults to Sql92 if none provided - * @return string - */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - $adapterPlatform = ($adapterPlatform) ?: new Sql92; - $table = $this->table; - $schema = null; - - // create quoted table name to use in insert processing - if ($table instanceof TableIdentifier) { - list($table, $schema) = $table->getTableAndSchema(); - } - - $table = $adapterPlatform->quoteIdentifier($table); - - if ($schema) { - $table = $adapterPlatform->quoteIdentifier($schema) . $adapterPlatform->getIdentifierSeparator() . $table; - } - - $columns = array_map(array($adapterPlatform, 'quoteIdentifier'), $this->columns); - $columns = implode(', ', $columns); - - $values = array(); - foreach ($this->values as $value) { - if ($value instanceof Expression) { - $exprData = $this->processExpression($value, $adapterPlatform); - $values[] = $exprData->getSql(); - } elseif ($value === null) { - $values[] = 'NULL'; - } else { - $values[] = $adapterPlatform->quoteValue($value); - } - } - - $values = implode(', ', $values); - - return sprintf($this->specifications[self::SPECIFICATION_INSERT], $table, $columns, $values); - } - - /** - * Overloading: variable setting - * - * Proxies to values, using VALUES_MERGE strategy - * - * @param string $name - * @param mixed $value - * @return Insert - */ - public function __set($name, $value) - { - $values = array($name => $value); - $this->values($values, self::VALUES_MERGE); - return $this; - } - - /** - * Overloading: variable unset - * - * Proxies to values and columns - * - * @param string $name - * @throws Exception\InvalidArgumentException - * @return void - */ - public function __unset($name) - { - if (($position = array_search($name, $this->columns)) === false) { - throw new Exception\InvalidArgumentException('The key ' . $name . ' was not found in this objects column list'); - } - - unset($this->columns[$position]); - unset($this->values[$position]); - } - - /** - * Overloading: variable isset - * - * Proxies to columns; does a column of that name exist? - * - * @param string $name - * @return bool - */ - public function __isset($name) - { - return in_array($name, $this->columns); - } - - /** - * Overloading: variable retrieval - * - * Retrieves value by column name - * - * @param string $name - * @throws Exception\InvalidArgumentException - * @return mixed - */ - public function __get($name) - { - if (($position = array_search($name, $this->columns)) === false) { - throw new Exception\InvalidArgumentException('The key ' . $name . ' was not found in this objects column list'); - } - return $this->values[$position]; - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/AbstractPlatform.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/AbstractPlatform.php deleted file mode 100644 index b65c404a..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/AbstractPlatform.php +++ /dev/null @@ -1,110 +0,0 @@ -subject = $subject; - } - - /** - * @param $type - * @param PlatformDecoratorInterface $decorator - */ - public function setTypeDecorator($type, PlatformDecoratorInterface $decorator) - { - $this->decorators[$type] = $decorator; - } - - /** - * @return array|PlatformDecoratorInterface[] - */ - public function getDecorators() - { - return $this->decorators; - } - - /** - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - * @throws Exception\RuntimeException - * @return void - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) - { - if (!$this->subject instanceof PreparableSqlInterface) { - throw new Exception\RuntimeException('The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling prepareStatement() has no effect'); - } - - $decoratorForType = false; - foreach ($this->decorators as $type => $decorator) { - if ($this->subject instanceof $type && $decorator instanceof PreparableSqlInterface) { - /** @var $decoratorForType PreparableSqlInterface|PlatformDecoratorInterface */ - $decoratorForType = $decorator; - break; - } - } - if ($decoratorForType) { - $decoratorForType->setSubject($this->subject); - $decoratorForType->prepareStatement($adapter, $statementContainer); - } else { - $this->subject->prepareStatement($adapter, $statementContainer); - } - } - - /** - * @param null|\Zend\Db\Adapter\Platform\PlatformInterface $adapterPlatform - * @return mixed - * @throws Exception\RuntimeException - */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - if (!$this->subject instanceof SqlInterface) { - throw new Exception\RuntimeException('The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling prepareStatement() has no effect'); - } - - $decoratorForType = false; - foreach ($this->decorators as $type => $decorator) { - if ($this->subject instanceof $type && $decorator instanceof SqlInterface) { - /** @var $decoratorForType SqlInterface|PlatformDecoratorInterface */ - $decoratorForType = $decorator; - break; - } - } - if ($decoratorForType) { - $decoratorForType->setSubject($this->subject); - return $decoratorForType->getSqlString($adapterPlatform); - } - - return $this->subject->getSqlString($adapterPlatform); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php deleted file mode 100644 index 47d3ba12..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php +++ /dev/null @@ -1,87 +0,0 @@ -createTable = $subject; - } - - /** - * @param null|PlatformInterface $platform - * @return string - */ - public function getSqlString(PlatformInterface $platform = null) - { - // localize variables - foreach (get_object_vars($this->createTable) as $name => $value) { - $this->{$name} = $value; - } - return parent::getSqlString($platform); - } - - protected function processColumns(PlatformInterface $platform = null) - { - $sqls = array(); - foreach ($this->columns as $i => $column) { - $stmtContainer = $this->processExpression($column, $platform); - $sql = $stmtContainer->getSql(); - $columnOptions = $column->getOptions(); - - foreach ($columnOptions as $coName => $coValue) { - switch (strtolower(str_replace(array('-', '_', ' '), '', $coName))) { - case 'identity': - case 'serial': - case 'autoincrement': - $sql .= ' AUTO_INCREMENT'; - break; - /* - case 'primary': - case 'primarykey': - $sql .= ' PRIMARY KEY'; - break; - case 'unique': - case 'uniquekey': - $sql .= ' UNIQUE KEY'; - break; - */ - case 'comment': - $sql .= ' COMMENT \'' . $coValue . '\''; - break; - case 'columnformat': - case 'format': - $sql .= ' COLUMN_FORMAT ' . strtoupper($coValue); - break; - case 'storage': - $sql .= ' STORAGE ' . strtoupper($coValue); - break; - } - } - $stmtContainer->setSql($sql); - $sqls[$i] = $stmtContainer; - } - return array($sqls); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/SelectDecorator.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/SelectDecorator.php deleted file mode 100644 index 73e8d25e..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/SelectDecorator.php +++ /dev/null @@ -1,88 +0,0 @@ -select = $select; - } - - /** - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) - { - // localize variables - foreach (get_object_vars($this->select) as $name => $value) { - $this->{$name} = $value; - } - parent::prepareStatement($adapter, $statementContainer); - } - - /** - * @param PlatformInterface $platform - * @return string - */ - public function getSqlString(PlatformInterface $platform = null) - { - // localize variables - foreach (get_object_vars($this->select) as $name => $value) { - $this->{$name} = $value; - } - return parent::getSqlString($platform); - } - - protected function processLimit(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->limit === null) { - return null; - } - if ($driver) { - $sql = $driver->formatParameterName('limit'); - $parameterContainer->offsetSet('limit', (int) $this->limit, ParameterContainer::TYPE_INTEGER); - } else { - $sql = $this->limit; - } - - return array($sql); - } - - protected function processOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->offset === null) { - return null; - } - if ($driver) { - $parameterContainer->offsetSet('offset', (int) $this->offset, ParameterContainer::TYPE_INTEGER); - return array($driver->formatParameterName('offset')); - } - - return array($this->offset); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php deleted file mode 100644 index 660a7e74..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php +++ /dev/null @@ -1,182 +0,0 @@ -select = $select; - } - - /** - * @see \Zend\Db\Sql\Select::renderTable - */ - protected function renderTable($table, $alias = null) - { - return $table . ' ' . $alias; - } - - /** - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) - { - // localize variables - foreach (get_object_vars($this->select) as $name => $value) { - $this->{$name} = $value; - } - // set specifications - unset($this->specifications[self::LIMIT]); - unset($this->specifications[self::OFFSET]); - - $this->specifications['LIMITOFFSET'] = null; - parent::prepareStatement($adapter, $statementContainer); - } - - /** - * @param PlatformInterface $platform - * @return string - */ - public function getSqlString(PlatformInterface $platform = null) - { - // localize variables - foreach (get_object_vars($this->select) as $name => $value) { - $this->{$name} = $value; - } - - // set specifications - unset($this->specifications[self::LIMIT]); - unset($this->specifications[self::OFFSET]); - - $this->specifications['LIMITOFFSET'] = null; - return parent::getSqlString($platform); - } - - /** - * @param PlatformInterface $platform - * @param DriverInterface $driver - * @param ParameterContainer $parameterContainer - * @param $sqls - * @param $parameters - * @return null - */ - protected function processLimitOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, &$sqls, &$parameters) - { - if ($this->limit === null && $this->offset === null) { - return null; - } - - $selectParameters = $parameters[self::SELECT]; - - $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; - foreach ($selectParameters[0] as $i => $columnParameters) { - if ($columnParameters[0] == self::SQL_STAR || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) || strpos($columnParameters[0], $starSuffix)) { - $selectParameters[0] = array(array(self::SQL_STAR)); - break; - } - if (isset($columnParameters[1])) { - array_shift($columnParameters); - $selectParameters[0][$i] = $columnParameters; - } - } - - if ($this->offset === null) { - $this->offset = 0; - } - - // first, produce column list without compound names (using the AS portion only) - array_unshift($sqls, $this->createSqlFromSpecificationAndParameters( - array('SELECT %1$s FROM (SELECT b.%1$s, rownum b_rownum FROM (' => current($this->specifications[self::SELECT])), $selectParameters - )); - - if ($parameterContainer) { - if ($this->limit === null) { - array_push($sqls, ') b ) WHERE b_rownum > (:offset)'); - $parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER); - } else { - // create bottom part of query, with offset and limit using row_number - array_push($sqls, ') b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)'); - $parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER); - $parameterContainer->offsetSet('limit', $this->limit, $parameterContainer::TYPE_INTEGER); - } - } else { - if ($this->limit === null) { - array_push($sqls, ') b ) WHERE b_rownum > ('. (int) $this->offset. ')' - ); - } else { - array_push($sqls, ') b WHERE rownum <= (' - . (int) $this->offset - . '+' - . (int) $this->limit - . ')) WHERE b_rownum >= (' - . (int) $this->offset - . ' + 1)' - ); - } - } - - $sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters( - $this->specifications[self::SELECT], $parameters[self::SELECT] - ); - } - - - protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if (!$this->joins) { - return null; - } - - // process joins - $joinSpecArgArray = array(); - foreach ($this->joins as $j => $join) { - $joinSpecArgArray[$j] = array(); - // type - $joinSpecArgArray[$j][] = strtoupper($join['type']); - // table name - $joinSpecArgArray[$j][] = (is_array($join['name'])) - ? $platform->quoteIdentifier(current($join['name'])) . ' ' . $platform->quoteIdentifier(key($join['name'])) - : $platform->quoteIdentifier($join['name']); - // on expression - $joinSpecArgArray[$j][] = ($join['on'] instanceof ExpressionInterface) - ? $this->processExpression($join['on'], $platform, $driver, $this->processInfo['paramPrefix'] . 'join') - : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN')); // on - if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) { - if ($parameterContainer) { - $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer()); - } - $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql(); - } - } - - return array($joinSpecArgArray); - } - -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Platform.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Platform.php deleted file mode 100644 index 19f9800d..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Platform.php +++ /dev/null @@ -1,42 +0,0 @@ -adapter = $adapter; - $platform = $adapter->getPlatform(); - switch (strtolower($platform->getName())) { - case 'mysql': - $platform = new Mysql\Mysql(); - $this->decorators = $platform->decorators; - break; - case 'sqlserver': - $platform = new SqlServer\SqlServer(); - $this->decorators = $platform->decorators; - break; - case 'oracle': - $platform = new Oracle\Oracle(); - $this->decorators = $platform->decorators; - break; - default: - } - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/In.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/In.php deleted file mode 100644 index 5928ecf0..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/In.php +++ /dev/null @@ -1,111 +0,0 @@ -setIdentifier($identifier); - } - if ($valueSet) { - $this->setValueSet($valueSet); - } - } - - /** - * Set identifier for comparison - * - * @param string $identifier - * @return In - */ - public function setIdentifier($identifier) - { - $this->identifier = $identifier; - return $this; - } - - /** - * Get identifier of comparison - * - * @return null|string - */ - public function getIdentifier() - { - return $this->identifier; - } - - /** - * Set set of values for IN comparison - * - * @param array $valueSet - * @throws Exception\InvalidArgumentException - * @return In - */ - public function setValueSet($valueSet) - { - if (!is_array($valueSet) && !$valueSet instanceof Select) { - throw new Exception\InvalidArgumentException( - '$valueSet must be either an array or a Zend\Db\Sql\Select object, ' . gettype($valueSet) . ' given' - ); - } - $this->valueSet = $valueSet; - return $this; - } - - public function getValueSet() - { - return $this->valueSet; - } - - /** - * Return array of parts for where statement - * - * @return array - */ - public function getExpressionData() - { - $values = $this->getValueSet(); - if ($values instanceof Select) { - $specification = $this->selectSpecification; - $types = array(self::TYPE_VALUE); - $values = array($values); - } else { - $specification = sprintf($this->valueSpecSpecification, implode(', ', array_fill(0, count($values), '%s'))); - $types = array_fill(0, count($values), self::TYPE_VALUE); - } - - $identifier = $this->getIdentifier(); - array_unshift($values, $identifier); - array_unshift($types, self::TYPE_IDENTIFIER); - - return array(array( - $specification, - $values, - $types, - )); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Literal.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Literal.php deleted file mode 100644 index 0734003b..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Literal.php +++ /dev/null @@ -1,10 +0,0 @@ -defaultCombination = $defaultCombination; - if ($predicates) { - foreach ($predicates as $predicate) { - $this->addPredicate($predicate); - } - } - } - - /** - * Add predicate to set - * - * @param PredicateInterface $predicate - * @param string $combination - * @return PredicateSet - */ - public function addPredicate(PredicateInterface $predicate, $combination = null) - { - if ($combination === null || !in_array($combination, array(self::OP_AND, self::OP_OR))) { - $combination = $this->defaultCombination; - } - - if ($combination == self::OP_OR) { - $this->orPredicate($predicate); - return $this; - } - - $this->andPredicate($predicate); - return $this; - } - - /** - * Return the predicates - * - * @return PredicateInterface[] - */ - public function getPredicates() - { - return $this->predicates; - } - - /** - * Add predicate using OR operator - * - * @param PredicateInterface $predicate - * @return PredicateSet - */ - public function orPredicate(PredicateInterface $predicate) - { - $this->predicates[] = array(self::OP_OR, $predicate); - return $this; - } - - /** - * Add predicate using AND operator - * - * @param PredicateInterface $predicate - * @return PredicateSet - */ - public function andPredicate(PredicateInterface $predicate) - { - $this->predicates[] = array(self::OP_AND, $predicate); - return $this; - } - - /** - * Get predicate parts for where statement - * - * @return array - */ - public function getExpressionData() - { - $parts = array(); - for ($i = 0, $count = count($this->predicates); $i < $count; $i++) { - - /** @var $predicate PredicateInterface */ - $predicate = $this->predicates[$i][1]; - - if ($predicate instanceof PredicateSet) { - $parts[] = '('; - } - - $parts = array_merge($parts, $predicate->getExpressionData()); - - if ($predicate instanceof PredicateSet) { - $parts[] = ')'; - } - - if (isset($this->predicates[$i+1])) { - $parts[] = sprintf(' %s ', $this->predicates[$i+1][0]); - } - } - return $parts; - } - - /** - * Get count of attached predicates - * - * @return int - */ - public function count() - { - return count($this->predicates); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Select.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Select.php deleted file mode 100644 index dea84756..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Select.php +++ /dev/null @@ -1,996 +0,0 @@ - '%1$s', - self::SELECT => array( - 'SELECT %1$s FROM %2$s' => array( - array(1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '), - null - ), - 'SELECT %1$s %2$s FROM %3$s' => array( - null, - array(1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '), - null - ), - ), - self::JOINS => array( - '%1$s' => array( - array(3 => '%1$s JOIN %2$s ON %3$s', 'combinedby' => ' ') - ) - ), - self::WHERE => 'WHERE %1$s', - self::GROUP => array( - 'GROUP BY %1$s' => array( - array(1 => '%1$s', 'combinedby' => ', ') - ) - ), - self::HAVING => 'HAVING %1$s', - self::ORDER => array( - 'ORDER BY %1$s' => array( - array(1 => '%1$s', 2 => '%1$s %2$s', 'combinedby' => ', ') - ) - ), - self::LIMIT => 'LIMIT %1$s', - self::OFFSET => 'OFFSET %1$s', - 'statementEnd' => '%1$s', - self::COMBINE => '%1$s ( %2$s )', - ); - - /** - * @var bool - */ - protected $tableReadOnly = false; - - /** - * @var bool - */ - protected $prefixColumnsWithTable = true; - - /** - * @var string|array|TableIdentifier - */ - protected $table = null; - - /** - * @var null|string|Expression - */ - protected $quantifier = null; - - /** - * @var array - */ - protected $columns = array(self::SQL_STAR); - - /** - * @var array - */ - protected $joins = array(); - - /** - * @var Where - */ - protected $where = null; - - /** - * @var null|string - */ - protected $order = array(); - - /** - * @var null|array - */ - protected $group = null; - - /** - * @var null|string|array - */ - protected $having = null; - - /** - * @var int|null - */ - protected $limit = null; - - /** - * @var int|null - */ - protected $offset = null; - - /** - * @var array - */ - protected $combine = array(); - - /** - * Constructor - * - * @param null|string|array|TableIdentifier $table - */ - public function __construct($table = null) - { - if ($table) { - $this->from($table); - $this->tableReadOnly = true; - } - - $this->where = new Where; - $this->having = new Having; - } - - /** - * Create from clause - * - * @param string|array|TableIdentifier $table - * @throws Exception\InvalidArgumentException - * @return Select - */ - public function from($table) - { - if ($this->tableReadOnly) { - throw new Exception\InvalidArgumentException('Since this object was created with a table and/or schema in the constructor, it is read only.'); - } - - if (!is_string($table) && !is_array($table) && !$table instanceof TableIdentifier) { - throw new Exception\InvalidArgumentException('$table must be a string, array, or an instance of TableIdentifier'); - } - - if (is_array($table) && (!is_string(key($table)) || count($table) !== 1)) { - throw new Exception\InvalidArgumentException('from() expects $table as an array is a single element associative array'); - } - - $this->table = $table; - return $this; - } - - /** - * @param string|Expression $quantifier DISTINCT|ALL - * @return Select - */ - public function quantifier($quantifier) - { - if (!is_string($quantifier) && !$quantifier instanceof Expression) { - throw new Exception\InvalidArgumentException( - 'Quantifier must be one of DISTINCT, ALL, or some platform specific Expression object' - ); - } - $this->quantifier = $quantifier; - return $this; - } - - /** - * Specify columns from which to select - * - * Possible valid states: - * - * array(*) - * - * array(value, ...) - * value can be strings or Expression objects - * - * array(string => value, ...) - * key string will be use as alias, - * value can be string or Expression objects - * - * @param array $columns - * @param bool $prefixColumnsWithTable - * @return Select - */ - public function columns(array $columns, $prefixColumnsWithTable = true) - { - $this->columns = $columns; - $this->prefixColumnsWithTable = (bool) $prefixColumnsWithTable; - return $this; - } - - /** - * Create join clause - * - * @param string|array $name - * @param string $on - * @param string|array $columns - * @param string $type one of the JOIN_* constants - * @throws Exception\InvalidArgumentException - * @return Select - */ - public function join($name, $on, $columns = self::SQL_STAR, $type = self::JOIN_INNER) - { - if (is_array($name) && (!is_string(key($name)) || count($name) !== 1)) { - throw new Exception\InvalidArgumentException( - sprintf("join() expects '%s' as an array is a single element associative array", array_shift($name)) - ); - } - if (!is_array($columns)) { - $columns = array($columns); - } - $this->joins[] = array( - 'name' => $name, - 'on' => $on, - 'columns' => $columns, - 'type' => $type - ); - return $this; - } - - /** - * Create where clause - * - * @param Where|\Closure|string|array|Predicate\PredicateInterface $predicate - * @param string $combination One of the OP_* constants from Predicate\PredicateSet - * @throws Exception\InvalidArgumentException - * @return Select - */ - public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) - { - if ($predicate instanceof Where) { - $this->where = $predicate; - } elseif ($predicate instanceof Predicate\PredicateInterface) { - $this->where->addPredicate($predicate, $combination); - } elseif ($predicate instanceof \Closure) { - $predicate($this->where); - } else { - if (is_string($predicate)) { - // String $predicate should be passed as an expression - $predicate = (strpos($predicate, Expression::PLACEHOLDER) !== false) - ? new Predicate\Expression($predicate) : new Predicate\Literal($predicate); - $this->where->addPredicate($predicate, $combination); - } elseif (is_array($predicate)) { - - foreach ($predicate as $pkey => $pvalue) { - // loop through predicates - - if (is_string($pkey) && strpos($pkey, '?') !== false) { - // First, process strings that the abstraction replacement character ? - // as an Expression predicate - $predicate = new Predicate\Expression($pkey, $pvalue); - - } elseif (is_string($pkey)) { - // Otherwise, if still a string, do something intelligent with the PHP type provided - - if ($pvalue === null) { - // map PHP null to SQL IS NULL expression - $predicate = new Predicate\IsNull($pkey, $pvalue); - } elseif (is_array($pvalue)) { - // if the value is an array, assume IN() is desired - $predicate = new Predicate\In($pkey, $pvalue); - } elseif ($pvalue instanceof Predicate\PredicateInterface) { - // - throw new Exception\InvalidArgumentException( - 'Using Predicate must not use string keys' - ); - } else { - // otherwise assume that array('foo' => 'bar') means "foo" = 'bar' - $predicate = new Predicate\Operator($pkey, Predicate\Operator::OP_EQ, $pvalue); - } - } elseif ($pvalue instanceof Predicate\PredicateInterface) { - // Predicate type is ok - $predicate = $pvalue; - } else { - // must be an array of expressions (with int-indexed array) - $predicate = (strpos($pvalue, Expression::PLACEHOLDER) !== false) - ? new Predicate\Expression($pvalue) : new Predicate\Literal($pvalue); - } - $this->where->addPredicate($predicate, $combination); - } - } - } - return $this; - } - - public function group($group) - { - if (is_array($group)) { - foreach ($group as $o) { - $this->group[] = $o; - } - } else { - $this->group[] = $group; - } - return $this; - } - - /** - * Create where clause - * - * @param Where|\Closure|string|array $predicate - * @param string $combination One of the OP_* constants from Predicate\PredicateSet - * @return Select - */ - public function having($predicate, $combination = Predicate\PredicateSet::OP_AND) - { - if ($predicate instanceof Having) { - $this->having = $predicate; - } elseif ($predicate instanceof \Closure) { - $predicate($this->having); - } else { - if (is_string($predicate)) { - $predicate = new Predicate\Expression($predicate); - $this->having->addPredicate($predicate, $combination); - } elseif (is_array($predicate)) { - foreach ($predicate as $pkey => $pvalue) { - if (is_string($pkey) && strpos($pkey, '?') !== false) { - $predicate = new Predicate\Expression($pkey, $pvalue); - } elseif (is_string($pkey)) { - $predicate = new Predicate\Operator($pkey, Predicate\Operator::OP_EQ, $pvalue); - } else { - $predicate = new Predicate\Expression($pvalue); - } - $this->having->addPredicate($predicate, $combination); - } - } - } - return $this; - } - - /** - * @param string|array $order - * @return Select - */ - public function order($order) - { - if (is_string($order)) { - if (strpos($order, ',') !== false) { - $order = preg_split('#,\s+#', $order); - } else { - $order = (array) $order; - } - } elseif (!is_array($order)) { - $order = array($order); - } - foreach ($order as $k => $v) { - if (is_string($k)) { - $this->order[$k] = $v; - } else { - $this->order[] = $v; - } - } - return $this; - } - - /** - * @param int $limit - * @return Select - */ - public function limit($limit) - { - if (!is_numeric($limit)) { - throw new Exception\InvalidArgumentException(sprintf( - '%s expects parameter to be numeric, "%s" given', - __METHOD__, - (is_object($limit) ? get_class($limit) : gettype($limit)) - )); - } - - $this->limit = $limit; - return $this; - } - - /** - * @param int $offset - * @return Select - */ - public function offset($offset) - { - if (!is_numeric($offset)) { - throw new Exception\InvalidArgumentException(sprintf( - '%s expects parameter to be numeric, "%s" given', - __METHOD__, - (is_object($offset) ? get_class($offset) : gettype($offset)) - )); - } - - $this->offset = $offset; - return $this; - } - - /** - * @param Select $select - * @param string $type - * @param string $modifier - * @return Select - * @throws Exception\InvalidArgumentException - */ - public function combine(Select $select, $type = self::COMBINE_UNION, $modifier = '') - { - if ($this->combine !== array()) { - throw new Exception\InvalidArgumentException('This Select object is already combined and cannot be combined with multiple Selects objects'); - } - $this->combine = array( - 'select' => $select, - 'type' => $type, - 'modifier' => $modifier - ); - return $this; - } - - /** - * @param string $part - * @return Select - * @throws Exception\InvalidArgumentException - */ - public function reset($part) - { - switch ($part) { - case self::TABLE: - if ($this->tableReadOnly) { - throw new Exception\InvalidArgumentException( - 'Since this object was created with a table and/or schema in the constructor, it is read only.' - ); - } - $this->table = null; - break; - case self::QUANTIFIER: - $this->quantifier = null; - break; - case self::COLUMNS: - $this->columns = array(); - break; - case self::JOINS: - $this->joins = array(); - break; - case self::WHERE: - $this->where = new Where; - break; - case self::GROUP: - $this->group = null; - break; - case self::HAVING: - $this->having = new Having; - break; - case self::LIMIT: - $this->limit = null; - break; - case self::OFFSET: - $this->offset = null; - break; - case self::ORDER: - $this->order = null; - break; - case self::COMBINE: - $this->combine = array(); - break; - } - return $this; - } - - public function setSpecification($index, $specification) - { - if (!method_exists($this, 'process' . $index)) { - throw new Exception\InvalidArgumentException('Not a valid specification name.'); - } - $this->specifications[$index] = $specification; - return $this; - } - - public function getRawState($key = null) - { - $rawState = array( - self::TABLE => $this->table, - self::QUANTIFIER => $this->quantifier, - self::COLUMNS => $this->columns, - self::JOINS => $this->joins, - self::WHERE => $this->where, - self::ORDER => $this->order, - self::GROUP => $this->group, - self::HAVING => $this->having, - self::LIMIT => $this->limit, - self::OFFSET => $this->offset, - self::COMBINE => $this->combine - ); - return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; - } - - /** - * Prepare statement - * - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - * @return void - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) - { - // ensure statement has a ParameterContainer - $parameterContainer = $statementContainer->getParameterContainer(); - if (!$parameterContainer instanceof ParameterContainer) { - $parameterContainer = new ParameterContainer(); - $statementContainer->setParameterContainer($parameterContainer); - } - - $sqls = array(); - $parameters = array(); - $platform = $adapter->getPlatform(); - $driver = $adapter->getDriver(); - - foreach ($this->specifications as $name => $specification) { - $parameters[$name] = $this->{'process' . $name}($platform, $driver, $parameterContainer, $sqls, $parameters); - if ($specification && is_array($parameters[$name])) { - $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); - } - } - - $sql = implode(' ', $sqls); - - $statementContainer->setSql($sql); - return; - } - - /** - * Get SQL string for statement - * - * @param null|PlatformInterface $adapterPlatform If null, defaults to Sql92 - * @return string - */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - // get platform, or create default - $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; - - $sqls = array(); - $parameters = array(); - - foreach ($this->specifications as $name => $specification) { - $parameters[$name] = $this->{'process' . $name}($adapterPlatform, null, null, $sqls, $parameters); - if ($specification && is_array($parameters[$name])) { - $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); - } - } - - $sql = implode(' ', $sqls); - return $sql; - } - - /** - * Returns whether the table is read only or not. - * - * @return bool - */ - public function isTableReadOnly() - { - return $this->tableReadOnly; - } - - /** - * Render table with alias in from/join parts - * - * @todo move TableIdentifier concatination here - * @param string $table - * @param string $alias - * @return string - */ - protected function renderTable($table, $alias = null) - { - $sql = $table; - if ($alias) { - $sql .= ' AS ' . $alias; - } - return $sql; - } - - protected function processStatementStart(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->combine !== array()) { - return array('('); - } - } - - protected function processStatementEnd(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->combine !== array()) { - return array(')'); - } - } - - /** - * Process the select part - * - * @param PlatformInterface $platform - * @param DriverInterface $driver - * @param ParameterContainer $parameterContainer - * @return null|array - */ - protected function processSelect(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - $expr = 1; - - if (!$this->table) { - return null; - } - - $table = $this->table; - $schema = $alias = null; - - if (is_array($table)) { - $alias = key($this->table); - $table = current($this->table); - } - - // create quoted table name to use in columns processing - if ($table instanceof TableIdentifier) { - list($table, $schema) = $table->getTableAndSchema(); - } - - if ($table instanceof Select) { - $table = '(' . $this->processSubselect($table, $platform, $driver, $parameterContainer) . ')'; - } else { - $table = $platform->quoteIdentifier($table); - } - - if ($schema) { - $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; - } - - if ($alias) { - $fromTable = $platform->quoteIdentifier($alias); - $table = $this->renderTable($table, $fromTable); - } else { - $fromTable = $table; - } - - if ($this->prefixColumnsWithTable) { - $fromTable .= $platform->getIdentifierSeparator(); - } else { - $fromTable = ''; - } - - // process table columns - $columns = array(); - foreach ($this->columns as $columnIndexOrAs => $column) { - - $columnName = ''; - if ($column === self::SQL_STAR) { - $columns[] = array($fromTable . self::SQL_STAR); - continue; - } - - if ($column instanceof Expression) { - $columnParts = $this->processExpression( - $column, - $platform, - $driver, - $this->processInfo['paramPrefix'] . ((is_string($columnIndexOrAs)) ? $columnIndexOrAs : 'column') - ); - if ($parameterContainer) { - $parameterContainer->merge($columnParts->getParameterContainer()); - } - $columnName .= $columnParts->getSql(); - } else { - $columnName .= $fromTable . $platform->quoteIdentifier($column); - } - - // process As portion - if (is_string($columnIndexOrAs)) { - $columnAs = $platform->quoteIdentifier($columnIndexOrAs); - } elseif (stripos($columnName, ' as ') === false) { - $columnAs = (is_string($column)) ? $platform->quoteIdentifier($column) : 'Expression' . $expr++; - } - $columns[] = (isset($columnAs)) ? array($columnName, $columnAs) : array($columnName); - } - - $separator = $platform->getIdentifierSeparator(); - - // process join columns - foreach ($this->joins as $join) { - foreach ($join['columns'] as $jKey => $jColumn) { - $jColumns = array(); - if ($jColumn instanceof ExpressionInterface) { - $jColumnParts = $this->processExpression( - $jColumn, - $platform, - $driver, - $this->processInfo['paramPrefix'] . ((is_string($jKey)) ? $jKey : 'column') - ); - if ($parameterContainer) { - $parameterContainer->merge($jColumnParts->getParameterContainer()); - } - $jColumns[] = $jColumnParts->getSql(); - } else { - $name = (is_array($join['name'])) ? key($join['name']) : $name = $join['name']; - if ($name instanceof TableIdentifier) { - $name = $platform->quoteIdentifier($name->getSchema()) . $separator . $platform->quoteIdentifier($name->getTable()); - } else { - $name = $platform->quoteIdentifier($name); - } - $jColumns[] = $name . $separator . $platform->quoteIdentifierInFragment($jColumn); - } - if (is_string($jKey)) { - $jColumns[] = $platform->quoteIdentifier($jKey); - } elseif ($jColumn !== self::SQL_STAR) { - $jColumns[] = $platform->quoteIdentifier($jColumn); - } - $columns[] = $jColumns; - } - } - - if ($this->quantifier) { - if ($this->quantifier instanceof Expression) { - $quantifierParts = $this->processExpression($this->quantifier, $platform, $driver, 'quantifier'); - if ($parameterContainer) { - $parameterContainer->merge($quantifierParts->getParameterContainer()); - } - $quantifier = $quantifierParts->getSql(); - } else { - $quantifier = $this->quantifier; - } - } - - if (isset($quantifier)) { - return array($quantifier, $columns, $table); - } else { - return array($columns, $table); - } - } - - protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if (!$this->joins) { - return null; - } - - // process joins - $joinSpecArgArray = array(); - foreach ($this->joins as $j => $join) { - $joinSpecArgArray[$j] = array(); - $joinName = null; - $joinAs = null; - - // type - $joinSpecArgArray[$j][] = strtoupper($join['type']); - - // table name - if (is_array($join['name'])) { - $joinName = current($join['name']); - $joinAs = $platform->quoteIdentifier(key($join['name'])); - } else { - $joinName = $join['name']; - } - if ($joinName instanceof TableIdentifier) { - $joinName = $joinName->getTableAndSchema(); - $joinName = $platform->quoteIdentifier($joinName[1]) . $platform->getIdentifierSeparator() . $platform->quoteIdentifier($joinName[0]); - } else { - if ($joinName instanceof Select) { - $joinName = '(' . $joinName->processSubSelect($joinName, $platform, $driver, $parameterContainer) . ')'; - } else { - $joinName = $platform->quoteIdentifier($joinName); - } - } - $joinSpecArgArray[$j][] = (isset($joinAs)) ? $joinName . ' AS ' . $joinAs : $joinName; - - // on expression - // note: for Expression objects, pass them to processExpression with a prefix specific to each join (used for named parameters) - $joinSpecArgArray[$j][] = ($join['on'] instanceof ExpressionInterface) - ? $this->processExpression($join['on'], $platform, $driver, $this->processInfo['paramPrefix'] . 'join' . ($j+1) . 'part') - : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN', '<', '>')); // on - if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) { - if ($parameterContainer) { - $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer()); - } - $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql(); - } - } - - return array($joinSpecArgArray); - } - - protected function processWhere(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->where->count() == 0) { - return null; - } - $whereParts = $this->processExpression($this->where, $platform, $driver, $this->processInfo['paramPrefix'] . 'where'); - if ($parameterContainer) { - $parameterContainer->merge($whereParts->getParameterContainer()); - } - return array($whereParts->getSql()); - } - - protected function processGroup(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->group === null) { - return null; - } - // process table columns - $groups = array(); - foreach ($this->group as $column) { - $columnSql = ''; - if ($column instanceof Expression) { - $columnParts = $this->processExpression($column, $platform, $driver, $this->processInfo['paramPrefix'] . 'group'); - if ($parameterContainer) { - $parameterContainer->merge($columnParts->getParameterContainer()); - } - $columnSql .= $columnParts->getSql(); - } else { - $columnSql .= $platform->quoteIdentifierInFragment($column); - } - $groups[] = $columnSql; - } - return array($groups); - } - - protected function processHaving(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->having->count() == 0) { - return null; - } - $whereParts = $this->processExpression($this->having, $platform, $driver, $this->processInfo['paramPrefix'] . 'having'); - if ($parameterContainer) { - $parameterContainer->merge($whereParts->getParameterContainer()); - } - return array($whereParts->getSql()); - } - - protected function processOrder(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if (empty($this->order)) { - return null; - } - $orders = array(); - foreach ($this->order as $k => $v) { - if ($v instanceof Expression) { - /** @var $orderParts \Zend\Db\Adapter\StatementContainer */ - $orderParts = $this->processExpression($v, $platform, $driver); - if ($parameterContainer) { - $parameterContainer->merge($orderParts->getParameterContainer()); - } - $orders[] = array($orderParts->getSql()); - continue; - } - if (is_int($k)) { - if (strpos($v, ' ') !== false) { - list($k, $v) = preg_split('# #', $v, 2); - } else { - $k = $v; - $v = self::ORDER_ASCENDING; - } - } - if (strtoupper($v) == self::ORDER_DESCENDING) { - $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_DESCENDING); - } else { - $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_ASCENDING); - } - } - return array($orders); - } - - protected function processLimit(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->limit === null) { - return null; - } - - $limit = (int) $this->limit; - - if ($driver) { - $sql = $driver->formatParameterName('limit'); - $parameterContainer->offsetSet('limit', $limit, ParameterContainer::TYPE_INTEGER); - } else { - $sql = $platform->quoteValue($limit); - } - - return array($sql); - } - - protected function processOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->offset === null) { - return null; - } - - $offset = (int) $this->offset; - - if ($driver) { - $parameterContainer->offsetSet('offset', $offset, ParameterContainer::TYPE_INTEGER); - return array($driver->formatParameterName('offset')); - } - - return array($platform->quoteValue($offset)); - } - - protected function processCombine(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) - { - if ($this->combine == array()) { - return null; - } - - $type = $this->combine['type']; - if ($this->combine['modifier']) { - $type .= ' ' . $this->combine['modifier']; - } - $type = strtoupper($type); - - if ($driver) { - $sql = $this->processSubSelect($this->combine['select'], $platform, $driver, $parameterContainer); - return array($type, $sql); - } - return array( - $type, - $this->processSubSelect($this->combine['select'], $platform) - ); - } - - /** - * Variable overloading - * - * @param string $name - * @throws Exception\InvalidArgumentException - * @return mixed - */ - public function __get($name) - { - switch (strtolower($name)) { - case 'where': - return $this->where; - case 'having': - return $this->having; - default: - throw new Exception\InvalidArgumentException('Not a valid magic property for this object'); - } - } - - /** - * __clone - * - * Resets the where object each time the Select is cloned. - * - * @return void - */ - public function __clone() - { - $this->where = clone $this->where; - $this->having = clone $this->having; - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/TableIdentifier.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/TableIdentifier.php deleted file mode 100644 index e368b2bd..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/TableIdentifier.php +++ /dev/null @@ -1,81 +0,0 @@ -table = $table; - $this->schema = $schema; - } - - /** - * @param string $table - */ - public function setTable($table) - { - $this->table = $table; - } - - /** - * @return string - */ - public function getTable() - { - return $this->table; - } - - /** - * @return bool - */ - public function hasSchema() - { - return ($this->schema != null); - } - - /** - * @param $schema - */ - public function setSchema($schema) - { - $this->schema = $schema; - } - - /** - * @return null|string - */ - public function getSchema() - { - return $this->schema; - } - - public function getTableAndSchema() - { - return array($this->table, $this->schema); - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Update.php b/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Update.php deleted file mode 100644 index b5455f00..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Update.php +++ /dev/null @@ -1,316 +0,0 @@ - 'UPDATE %1$s SET %2$s', - self::SPECIFICATION_WHERE => 'WHERE %1$s' - ); - - /** - * @var string|TableIdentifier - */ - protected $table = ''; - - /** - * @var bool - */ - protected $emptyWhereProtection = true; - - /** - * @var array - */ - protected $set = array(); - - /** - * @var string|Where - */ - protected $where = null; - - /** - * Constructor - * - * @param null|string|TableIdentifier $table - */ - public function __construct($table = null) - { - if ($table) { - $this->table($table); - } - $this->where = new Where(); - } - - /** - * Specify table for statement - * - * @param string|TableIdentifier $table - * @return Update - */ - public function table($table) - { - $this->table = $table; - return $this; - } - - /** - * Set key/value pairs to update - * - * @param array $values Associative array of key values - * @param string $flag One of the VALUES_* constants - * @throws Exception\InvalidArgumentException - * @return Update - */ - public function set(array $values, $flag = self::VALUES_SET) - { - if ($values == null) { - throw new Exception\InvalidArgumentException('set() expects an array of values'); - } - - if ($flag == self::VALUES_SET) { - $this->set = array(); - } - - foreach ($values as $k => $v) { - if (!is_string($k)) { - throw new Exception\InvalidArgumentException('set() expects a string for the value key'); - } - $this->set[$k] = $v; - } - - return $this; - } - - /** - * Create where clause - * - * @param Where|\Closure|string|array $predicate - * @param string $combination One of the OP_* constants from Predicate\PredicateSet - * @throws Exception\InvalidArgumentException - * @return Select - */ - public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) - { - if ($predicate === null) { - throw new Exception\InvalidArgumentException('Predicate cannot be null'); - } - - if ($predicate instanceof Where) { - $this->where = $predicate; - } elseif ($predicate instanceof \Closure) { - $predicate($this->where); - } else { - if (is_string($predicate)) { - // String $predicate should be passed as an expression - $predicate = new Predicate\Expression($predicate); - $this->where->addPredicate($predicate, $combination); - } elseif (is_array($predicate)) { - - foreach ($predicate as $pkey => $pvalue) { - // loop through predicates - - if (is_string($pkey) && strpos($pkey, '?') !== false) { - // First, process strings that the abstraction replacement character ? - // as an Expression predicate - $predicate = new Predicate\Expression($pkey, $pvalue); - - } elseif (is_string($pkey)) { - // Otherwise, if still a string, do something intelligent with the PHP type provided - - if ($pvalue === null) { - // map PHP null to SQL IS NULL expression - $predicate = new Predicate\IsNull($pkey, $pvalue); - } elseif (is_array($pvalue)) { - // if the value is an array, assume IN() is desired - $predicate = new Predicate\In($pkey, $pvalue); - } else { - // otherwise assume that array('foo' => 'bar') means "foo" = 'bar' - $predicate = new Predicate\Operator($pkey, Predicate\Operator::OP_EQ, $pvalue); - } - } elseif ($pvalue instanceof Predicate\PredicateInterface) { - // Predicate type is ok - $predicate = $pvalue; - } else { - // must be an array of expressions (with int-indexed array) - $predicate = new Predicate\Expression($pvalue); - } - $this->where->addPredicate($predicate, $combination); - } - } - } - return $this; - } - - public function getRawState($key = null) - { - $rawState = array( - 'emptyWhereProtection' => $this->emptyWhereProtection, - 'table' => $this->table, - 'set' => $this->set, - 'where' => $this->where - ); - return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; - } - - /** - * Prepare statement - * - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - * @return void - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) - { - $driver = $adapter->getDriver(); - $platform = $adapter->getPlatform(); - $parameterContainer = $statementContainer->getParameterContainer(); - - if (!$parameterContainer instanceof ParameterContainer) { - $parameterContainer = new ParameterContainer(); - $statementContainer->setParameterContainer($parameterContainer); - } - - $table = $this->table; - $schema = null; - - // create quoted table name to use in update processing - if ($table instanceof TableIdentifier) { - list($table, $schema) = $table->getTableAndSchema(); - } - - $table = $platform->quoteIdentifier($table); - - if ($schema) { - $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; - } - - $set = $this->set; - if (is_array($set)) { - $setSql = array(); - foreach ($set as $column => $value) { - if ($value instanceof Expression) { - $exprData = $this->processExpression($value, $platform, $driver); - $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $exprData->getSql(); - $parameterContainer->merge($exprData->getParameterContainer()); - } else { - $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $driver->formatParameterName($column); - $parameterContainer->offsetSet($column, $value); - } - } - $set = implode(', ', $setSql); - } - - $sql = sprintf($this->specifications[self::SPECIFICATION_UPDATE], $table, $set); - - // process where - if ($this->where->count() > 0) { - $whereParts = $this->processExpression($this->where, $platform, $driver, 'where'); - $parameterContainer->merge($whereParts->getParameterContainer()); - $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $whereParts->getSql()); - } - $statementContainer->setSql($sql); - } - - /** - * Get SQL string for statement - * - * @param null|PlatformInterface $adapterPlatform If null, defaults to Sql92 - * @return string - */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - $adapterPlatform = ($adapterPlatform) ?: new Sql92; - $table = $this->table; - $schema = null; - - // create quoted table name to use in update processing - if ($table instanceof TableIdentifier) { - list($table, $schema) = $table->getTableAndSchema(); - } - - $table = $adapterPlatform->quoteIdentifier($table); - - if ($schema) { - $table = $adapterPlatform->quoteIdentifier($schema) . $adapterPlatform->getIdentifierSeparator() . $table; - } - - $set = $this->set; - if (is_array($set)) { - $setSql = array(); - foreach ($set as $column => $value) { - if ($value instanceof Expression) { - $exprData = $this->processExpression($value, $adapterPlatform); - $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $exprData->getSql(); - } elseif ($value === null) { - $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = NULL'; - } else { - $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $adapterPlatform->quoteValue($value); - } - } - $set = implode(', ', $setSql); - } - - $sql = sprintf($this->specifications[self::SPECIFICATION_UPDATE], $table, $set); - if ($this->where->count() > 0) { - $whereParts = $this->processExpression($this->where, $adapterPlatform, null, 'where'); - $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $whereParts->getSql()); - } - return $sql; - } - - /** - * Variable overloading - * - * Proxies to "where" only - * - * @param string $name - * @return mixed - */ - public function __get($name) - { - switch (strtolower($name)) { - case 'where': - return $this->where; - } - } - - /** - * __clone - * - * Resets the where object each time the Update is cloned. - * - * @return void - */ - public function __clone() - { - $this->where = clone $this->where; - } -} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/composer.json b/bundled-libs/zendframework/zend-db/Zend/Db/composer.json deleted file mode 100644 index c926eecb..00000000 --- a/bundled-libs/zendframework/zend-db/Zend/Db/composer.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "zendframework/zend-db", - "description": " ", - "license": "BSD-3-Clause", - "keywords": [ - "zf2", - "db" - ], - "autoload": { - "psr-0": { - "Zend\\Db\\": "" - } - }, - "target-dir": "Zend/Db", - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "zendframework/zend-stdlib": "self.version" - }, - "extra": { - "branch-alias": { - "dev-master": "2.2-dev", - "dev-develop": "2.3-dev" - } - } -} diff --git a/bundled-libs/zendframework/zend-db/composer.json b/bundled-libs/zendframework/zend-db/composer.json new file mode 100644 index 00000000..5f75f916 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/composer.json @@ -0,0 +1,73 @@ +{ + "name": "zendframework/zend-db", + "description": "Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations", + "license": "BSD-3-Clause", + "keywords": [ + "zf", + "zendframework", + "db" + ], + "support": { + "docs": "https://docs.zendframework.com/zend-db/", + "issues": "https://github.com/zendframework/zend-db/issues", + "source": "https://github.com/zendframework/zend-db", + "rss": "https://github.com/zendframework/zend-db/releases.atom", + "slack": "https://zendframework-slack.herokuapp.com", + "forum": "https://discourse.zendframework.com/c/questions/components" + }, + "require": { + "php": "^5.6 || ^7.0", + "zendframework/zend-stdlib": "^2.7 || ^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.25 || ^6.4.4", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-eventmanager": "^2.6.2 || ^3.0", + "zendframework/zend-hydrator": "^1.1 || ^2.1 || ^3.0", + "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3" + }, + "suggest": { + "zendframework/zend-eventmanager": "Zend\\EventManager component", + "zendframework/zend-hydrator": "Zend\\Hydrator component for using HydratingResultSets", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component" + }, + "autoload": { + "psr-4": { + "Zend\\Db\\": "src/" + } + }, + "autoload-dev": { + "files": [ + "test/autoload.php" + ], + "psr-4": { + "ZendTest\\Db\\": "test/unit", + "ZendIntegrationTest\\Db\\": "test/integration" + } + }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "2.9-dev", + "dev-develop": "2.10-dev" + }, + "zf": { + "component": "Zend\\Db", + "config-provider": "Zend\\Db\\ConfigProvider" + } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always --testsuite \"unit test\"", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "test-integration" : "phpunit --colors=always --testsuite \"integration test\"", + "upload-coverage": "coveralls -v" + } +} diff --git a/bundled-libs/zendframework/zend-db/docs/CODE_OF_CONDUCT.md b/bundled-libs/zendframework/zend-db/docs/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..02fafcd1 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/CODE_OF_CONDUCT.md @@ -0,0 +1,43 @@ +# Contributor Code of Conduct + +This project adheres to [The Code Manifesto](http://codemanifesto.com) +as its guidelines for contributor interactions. + +## The Code Manifesto + +We want to work in an ecosystem that empowers developers to reach their +potential — one that encourages growth and effective collaboration. A space that +is safe for all. + +A space such as this benefits everyone that participates in it. It encourages +new developers to enter our field. It is through discussion and collaboration +that we grow, and through growth that we improve. + +In the effort to create such a place, we hold to these values: + +1. **Discrimination limits us.** This includes discrimination on the basis of + race, gender, sexual orientation, gender identity, age, nationality, technology + and any other arbitrary exclusion of a group of people. +2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort + levels. Remember that, and if brought to your attention, heed it. +3. **We are our biggest assets.** None of us were born masters of our trade. + Each of us has been helped along the way. Return that favor, when and where + you can. +4. **We are resources for the future.** As an extension of #3, share what you + know. Make yourself a resource to help those that come after you. +5. **Respect defines us.** Treat others as you wish to be treated. Make your + discussions, criticisms and debates from a position of respectfulness. Ask + yourself, is it true? Is it necessary? Is it constructive? Anything less is + unacceptable. +6. **Reactions require grace.** Angry responses are valid, but abusive language + and vindictive actions are toxic. When something happens that offends you, + handle it assertively, but be respectful. Escalate reasonably, and try to + allow the offender an opportunity to explain themselves, and possibly correct + the issue. +7. **Opinions are just that: opinions.** Each and every one of us, due to our + background and upbringing, have varying opinions. The fact of the matter, is + that is perfectly acceptable. Remember this: if you respect your own + opinions, you should respect the opinions of others. +8. **To err is human.** You might not intend it, but mistakes do happen and + contribute to build experience. Tolerate honest mistakes, and don't hesitate + to apologize if you make one yourself. diff --git a/bundled-libs/zendframework/zend-db/docs/CONTRIBUTING.md b/bundled-libs/zendframework/zend-db/docs/CONTRIBUTING.md new file mode 100644 index 00000000..3d7e856d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/CONTRIBUTING.md @@ -0,0 +1,189 @@ +# CONTRIBUTING + +## RESOURCES + +If you wish to contribute to this project, please be sure to +read/subscribe to the following resources: + + - [Coding Standards](https://github.com/zendframework/zend-coding-standard) + - [Forums](https://discourse.zendframework.com/c/contributors) + - [Slack](https://zendframework-slack.herokuapp.com) + - [Code of Conduct](CODE_OF_CONDUCT.md) + +If you are working on new features or refactoring +[create a proposal](https://github.com/zendframework/zend-db/issues/new). + +## RUNNING TESTS + +To run tests: + +- Clone the repository: + + ```console + $ git clone git://github.com/zendframework/zend-db.git + $ cd zend-db + ``` + +- Install dependencies via composer: + + ```console + $ composer install + ``` + + If you don't have `composer` installed, please download it from https://getcomposer.org/download/ + +- Run the tests using the "test" command shipped in the `composer.json`: + + ```console + $ composer test + ``` + +You can turn on conditional tests with the `phpunit.xml` file. +To do so: + + - Copy `phpunit.xml.dist` file to `phpunit.xml` + - Edit `phpunit.xml` to enable any specific functionality you + want to test, as well as to provide test values to utilize. + +## Running Coding Standards Checks + +First, ensure you've installed dependencies via composer, per the previous +section on running tests. + +To run CS checks only: + +```console +$ composer cs-check +``` + +To attempt to automatically fix common CS issues: + +```console +$ composer cs-fix +``` + +If the above fixes any CS issues, please re-run the tests to ensure +they pass, and make sure you add and commit the changes after verification. + +## Recommended Workflow for Contributions + +Your first step is to establish a public repository from which we can +pull your work into the master repository. We recommend using +[GitHub](https://github.com), as that is where the component is already hosted. + +1. Setup a [GitHub account](https://github.com/), if you haven't yet +2. Fork the repository (https://github.com/zendframework/zend-db) +3. Clone the canonical repository locally and enter it. + + ```console + $ git clone git://github.com/zendframework/zend-db.git + $ cd zend-db + ``` + +4. Add a remote to your fork; substitute your GitHub username in the command + below. + + ```console + $ git remote add {username} git@github.com:{username}/zend-db.git + $ git fetch {username} + ``` + +### Keeping Up-to-Date + +Periodically, you should update your fork or personal repository to +match the canonical ZF repository. Assuming you have setup your local repository +per the instructions above, you can do the following: + + +```console +$ git checkout master +$ git fetch origin +$ git rebase origin/master +# OPTIONALLY, to keep your remote up-to-date - +$ git push {username} master:master +``` + +If you're tracking other branches -- for example, the "develop" branch, where +new feature development occurs -- you'll want to do the same operations for that +branch; simply substitute "develop" for "master". + +### Working on a patch + +We recommend you do each new feature or bugfix in a new branch. This simplifies +the task of code review as well as the task of merging your changes into the +canonical repository. + +A typical workflow will then consist of the following: + +1. Create a new local branch based off either your master or develop branch. +2. Switch to your new local branch. (This step can be combined with the + previous step with the use of `git checkout -b`.) +3. Do some work, commit, repeat as necessary. +4. Push the local branch to your remote repository. +5. Send a pull request. + +The mechanics of this process are actually quite trivial. Below, we will +create a branch for fixing an issue in the tracker. + +```console +$ git checkout -b hotfix/9295 +Switched to a new branch 'hotfix/9295' +``` + +... do some work ... + + +```console +$ git commit +``` + +... write your log message ... + + +```console +$ git push {username} hotfix/9295:hotfix/9295 +Counting objects: 38, done. +Delta compression using up to 2 threads. +Compression objects: 100% (18/18), done. +Writing objects: 100% (20/20), 8.19KiB, done. +Total 20 (delta 12), reused 0 (delta 0) +To ssh://git@github.com/{username}/zend-db.git + b5583aa..4f51698 HEAD -> master +``` + +To send a pull request, you have two options. + +If using GitHub, you can do the pull request from there. Navigate to +your repository, select the branch you just created, and then select the +"Pull Request" button in the upper right. Select the user/organization +"zendframework" (or whatever the upstream organization is) as the recipient. + +#### What branch to issue the pull request against? + +Which branch should you issue a pull request against? + +- For fixes against the stable release, issue the pull request against the + "master" branch. +- For new features, or fixes that introduce new elements to the public API (such + as new public methods or properties), issue the pull request against the + "develop" branch. + +### Branch Cleanup + +As you might imagine, if you are a frequent contributor, you'll start to +get a ton of branches both locally and on your remote. + +Once you know that your changes have been accepted to the master +repository, we suggest doing some cleanup of these branches. + +- Local branch cleanup + + ```console + $ git branch -d + ``` + +- Remote branch removal + + ```console + $ git push {username} : + ``` diff --git a/bundled-libs/zendframework/zend-db/docs/ISSUE_TEMPLATE.md b/bundled-libs/zendframework/zend-db/docs/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..de7f91a4 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/ISSUE_TEMPLATE.md @@ -0,0 +1,19 @@ + - [ ] I was not able to find an [open](https://github.com/zendframework/zend-db/issues?q=is%3Aopen) or [closed](https://github.com/zendframework/zend-db/issues?q=is%3Aclosed) issue matching what I'm seeing. + - [ ] This is not a question. (Questions should be asked on [slack](https://zendframework.slack.com/) ([Signup for Slack here](https://zendframework-slack.herokuapp.com/)) or our [forums](https://discourse.zendframework.com/).) + +Provide a narrative description of what you are trying to accomplish. + +### Code to reproduce the issue + + + +```php +``` + +### Expected results + + + +### Actual results + + diff --git a/bundled-libs/zendframework/zend-db/docs/PULL_REQUEST_TEMPLATE.md b/bundled-libs/zendframework/zend-db/docs/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..f00d90c0 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,25 @@ +Provide a narrative description of what you are trying to accomplish: + +- [ ] Are you fixing a bug? + - [ ] Detail how the bug is invoked currently. + - [ ] Detail the original, incorrect behavior. + - [ ] Detail the new, expected behavior. + - [ ] Base your feature on the `master` branch, and submit against that branch. + - [ ] Add a regression test that demonstrates the bug, and proves the fix. + - [ ] Add a `CHANGELOG.md` entry for the fix. + +- [ ] Are you creating a new feature? + - [ ] Why is the new feature needed? What purpose does it serve? + - [ ] How will users use the new feature? + - [ ] Base your feature on the `develop` branch, and submit against that branch. + - [ ] Add only one feature per pull request; split multiple features over multiple pull requests + - [ ] Add tests for the new feature. + - [ ] Add documentation for the new feature. + - [ ] Add a `CHANGELOG.md` entry for the new feature. + +- [ ] Is this related to quality assurance? + + +- [ ] Is this related to documentation? + + diff --git a/bundled-libs/zendframework/zend-db/docs/SUPPORT.md b/bundled-libs/zendframework/zend-db/docs/SUPPORT.md new file mode 100644 index 00000000..b5c6d8a0 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/SUPPORT.md @@ -0,0 +1,25 @@ +# Getting Support + +Zend Framework offers three support channels: + +- For real-time questions, use our + [Slack](https://zendframework-slack.herokuapp.com) +- For detailed questions (e.g., those requiring examples) use our + [forums](https://discourse.zendframework.com/c/questions/components) +- To report issues, use this repository's + [issue tracker](https://github.com/zendframework/zend-db/issues/new) + +**DO NOT** use the issue tracker to ask questions; use Slack or the forums for +that. Questions posed to the issue tracker will be closed. + +When reporting an issue, please include the following details: + +- A narrative description of what you are trying to accomplish. +- The minimum code necessary to reproduce the issue. +- The expected results of exercising that code. +- The actual results received. + +We may ask for additional details: what version of the library you are using, +and what PHP version was used to reproduce the issue. + +You may also submit a failing test case as a pull request. diff --git a/bundled-libs/zendframework/zend-db/docs/book/adapter.md b/bundled-libs/zendframework/zend-db/docs/book/adapter.md new file mode 100644 index 00000000..857e12d9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/adapter.md @@ -0,0 +1,498 @@ +# Adapters + +`Zend\Db\Adapter\Adapter` is the central object of the zend-db component. It is +responsible for adapting any code written in or for zend-db to the targeted PHP +extensions and vendor databases. In doing this, it creates an abstraction layer +for the PHP extensions in the `Driver` subnamespace of `Zend\Db\Adapter`. It +also creates a lightweight "Platform" abstraction layer, for the various +idiosyncrasies that each vendor-specific platform might have in its SQL/RDBMS +implementation, separate from the driver implementations. + +## Creating an adapter using configuration + +Create an adapter by instantiating the `Zend\Db\Adapter\Adapter` class. The most +common use case, while not the most explicit, is to pass an array of +configuration to the `Adapter`: + +```php +use Zend\Db\Adapter\Adapter; + +$adapter = new Adapter($configArray); +``` + +This driver array is an abstraction for the extension level required parameters. +Here is a table for the key-value pairs that should be in configuration array. + +Key | Is Required? | Value +---------- | ---------------------- | ----- +`driver` | required | `Mysqli`, `Sqlsrv`, `Pdo_Sqlite`, `Pdo_Mysql`, `Pdo`(= Other PDO Driver) +`database` | generally required | the name of the database (schema) +`username` | generally required | the connection username +`password` | generally required | the connection password +`hostname` | not generally required | the IP address or hostname to connect to +`port` | not generally required | the port to connect to (if applicable) +`charset` | not generally required | the character set to use + +> ### Options are adapter-dependent +> +> Other names will work as well. Effectively, if the PHP manual uses a +> particular naming, this naming will be supported by the associated driver. For +> example, `dbname` in most cases will also work for 'database'. Another +> example is that in the case of `Sqlsrv`, `UID` will work in place of +> `username`. Which format you choose is up to you, but the above table +> represents the official abstraction names. + +For example, a MySQL connection using ext/mysqli: + +```php +$adapter = new Zend\Db\Adapter\Adapter([ + 'driver' => 'Mysqli', + 'database' => 'zend_db_example', + 'username' => 'developer', + 'password' => 'developer-password', +]); +``` + +Another example, of a Sqlite connection via PDO: + +```php +$adapter = new Zend\Db\Adapter\Adapter([ + 'driver' => 'Pdo_Sqlite', + 'database' => 'path/to/sqlite.db', +]); +``` + +Another example, of an IBM i DB2 connection via IbmDb2: + +```php +$adapter = new Zend\Db\Adapter\Adapter([ + 'database' => '*LOCAL', // or name from WRKRDBDIRE, may be serial # + 'driver' => 'IbmDb2', + 'driver_options' => [ + 'autocommit' => DB2_AUTOCOMMIT_ON, + 'i5_naming' => DB2_I5_NAMING_ON, + 'i5_libl' => 'SCHEMA1 SCHEMA2 SCHEMA3', + ], + 'username' => '__USER__', + 'password' => '__PASS__', + // 'persistent' => true, + 'platform' => 'IbmDb2', + 'platform_options' => ['quote_identifiers' => false], +]); +``` + +Another example, of an IBM i DB2 connection via PDO: + +```php +$adapter = new Zend\Db\Adapter\Adapter([ + 'dsn' => 'ibm:DB_NAME', // DB_NAME is from WRKRDBDIRE, may be serial # + 'driver' => 'pdo', + 'driver_options' => [ + // PDO::ATTR_PERSISTENT => true, + PDO::ATTR_AUTOCOMMIT => true, + PDO::I5_ATTR_DBC_SYS_NAMING => true, + PDO::I5_ATTR_DBC_CURLIB => '', + PDO::I5_ATTR_DBC_LIBL => 'SCHEMA1 SCHEMA2 SCHEMA3', + ], + 'username' => '__USER__', + 'password' => '__PASS__', + 'platform' => 'IbmDb2', + 'platform_options' => ['quote_identifiers' => false], +]); +``` + +It is important to know that by using this style of adapter creation, the +`Adapter` will attempt to create any dependencies that were not explicitly +provided. A `Driver` object will be created from the configuration array +provided in the constructor. A `Platform` object will be created based off the +type of `Driver` class that was instantiated. And lastly, a default `ResultSet` +object is created and utilized. Any of these objects can be injected, to do +this, see the next section. + +The list of officially supported drivers: + +- `IbmDb2`: The ext/ibm_db2 driver +- `Mysqli`: The ext/mysqli driver +- `Oci8`: The ext/oci8 driver +- `Pgsql`: The ext/pgsql driver +- `Sqlsrv`: The ext/sqlsrv driver (from Microsoft) +- `Pdo_Mysql`: MySQL via the PDO extension +- `Pdo_Sqlite`: SQLite via the PDO extension +- `Pdo_Pgsql`: PostgreSQL via the PDO extension + +## Creating an adapter using dependency injection + +The more expressive and explicit way of creating an adapter is by injecting all +your dependencies up front. `Zend\Db\Adapter\Adapter` uses constructor +injection, and all required dependencies are injected through the constructor, +which has the following signature (in pseudo-code): + +```php +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\ResultSet\ResultSet; + +class Zend\Db\Adapter\Adapter +{ + public function __construct( + $driver, + PlatformInterface $platform = null, + ResultSet $queryResultSetPrototype = null + ); +} +``` + +What can be injected: + +- `$driver`: an array of connection parameters (see above) or an instance of + `Zend\Db\Adapter\Driver\DriverInterface`. +- `$platform` (optional): an instance of `Zend\Db\Platform\PlatformInterface`; + the default will be created based off the driver implementation. +- `$queryResultSetPrototype` (optional): an instance of + `Zend\Db\ResultSet\ResultSet`; to understand this object's role, see the + section below on querying. + +## Query Preparation + +By default, `Zend\Db\Adapter\Adapter::query()` prefers that you use +"preparation" as a means for processing SQL statements. This generally means +that you will supply a SQL statement containing placeholders for the values, and +separately provide substitutions for those placeholders. As an example: + +```php +$adapter->query('SELECT * FROM `artist` WHERE `id` = ?', [5]); +``` + +The above example will go through the following steps: + +- create a new `Statement` object. +- prepare the array `[5]` into a `ParameterContainer` if necessary. +- inject the `ParameterContainer` into the `Statement` object. +- execute the `Statement` object, producing a `Result` object. +- check the `Result` object to check if the supplied SQL was a result set + producing statement: + - if the query produced a result set, clone the `ResultSet` prototype, + inject the `Result` as its datasource, and return the new `ResultSet` + instance. + - otherwise, return the `Result`. + +## Query Execution + +In some cases, you have to execute statements directly without preparation. One +possible reason for doing so would be to execute a DDL statement, as most +extensions and RDBMS systems are incapable of preparing such statements. + +To execute a query without the preparation step, you will need to pass a flag as +the second argument indicating execution is required: + +```php +$adapter->query( + 'ALTER TABLE ADD INDEX(`foo_index`) ON (`foo_column`)', + Adapter::QUERY_MODE_EXECUTE +); +``` + +The primary difference to notice is that you must provide the +`Adapter::QUERY_MODE_EXECUTE` (execute) flag as the second parameter. + +## Creating Statements + +While `query()` is highly useful for one-off and quick querying of a database +via the `Adapter`, it generally makes more sense to create a statement and +interact with it directly, so that you have greater control over the +prepare-then-execute workflow. To do this, `Adapter` gives you a routine called +`createStatement()` that allows you to create a `Driver` specific `Statement` to +use so you can manage your own prepare-then-execute workflow. + +```php +// with optional parameters to bind up-front: +$statement = $adapter->createStatement($sql, $optionalParameters); +$result = $statement->execute(); +``` + +## Using the Driver Object + +The `Driver` object is the primary place where `Zend\Db\Adapter\Adapter` +implements the connection level abstraction specific to a given extension. To +make this possible, each driver is composed of 3 objects: + +- A connection: `Zend\Db\Adapter\Driver\ConnectionInterface` +- A statement: `Zend\Db\Adapter\Driver\StatementInterface` +- A result: `Zend\Db\Adapter\Driver\ResultInterface` + +Each of the built-in drivers practice "prototyping" as a means of creating +objects when new instances are requested. The workflow looks like this: + +- An adapter is created with a set of connection parameters. +- The adapter chooses the proper driver to instantiate (for example, + `Zend\Db\Adapter\Driver\Mysqli`) +- That driver class is instantiated. +- If no connection, statement, or result objects are injected, defaults are + instantiated. + +This driver is now ready to be called on when particular workflows are +requested. Here is what the `Driver` API looks like: + +```php +namespace Zend\Db\Adapter\Driver; + +interface DriverInterface +{ + const PARAMETERIZATION_POSITIONAL = 'positional'; + const PARAMETERIZATION_NAMED = 'named'; + const NAME_FORMAT_CAMELCASE = 'camelCase'; + const NAME_FORMAT_NATURAL = 'natural'; + + public function getDatabasePlatformName(string $nameFormat = self::NAME_FORMAT_CAMELCASE) : string; + public function checkEnvironment() : bool; + public function getConnection() : ConnectionInterface; + public function createStatement(string|resource $sqlOrResource = null) : StatementInterface; + public function createResult(resource $resource) : ResultInterface; + public function getPrepareType() :string; + public function formatParameterName(string $name, $type = null) : string; + public function getLastGeneratedValue() : mixed; +} +``` + +From this `DriverInterface`, you can + +- Determine the name of the platform this driver supports (useful for choosing + the proper platform object). +- Check that the environment can support this driver. +- Return the `Connection` instance. +- Create a `Statement` instance which is optionally seeded by an SQL statement + (this will generally be a clone of a prototypical statement object). +- Create a `Result` object which is optionally seeded by a statement resource + (this will generally be a clone of a prototypical result object) +- Format parameter names; this is important to distinguish the difference + between the various ways parameters are named between extensions +- Retrieve the overall last generated value (such as an auto-increment value). + +Now let's turn to the `Statement` API: + +```php +namespace Zend\Db\Adapter\Driver; + +interface StatementInterface extends StatementContainerInterface +{ + public function getResource() : resource; + public function prepare($sql = null) : void; + public function isPrepared() : bool; + public function execute(null|array|ParameterContainer $parameters = null) : ResultInterface; + + /** Inherited from StatementContainerInterface */ + public function setSql(string $sql) : void; + public function getSql() : string; + public function setParameterContainer(ParameterContainer $parameterContainer) : void; + public function getParameterContainer() : ParameterContainer; +} +``` + +And finally, the `Result` API: + +```php +namespace Zend\Db\Adapter\Driver; + +use Countable; +use Iterator; + +interface ResultInterface extends Countable, Iterator +{ + public function buffer() : void; + public function isQueryResult() : bool; + public function getAffectedRows() : int; + public function getGeneratedValue() : mixed; + public function getResource() : resource; + public function getFieldCount() : int; +} +``` + +## Using The Platform Object + +The `Platform` object provides an API to assist in crafting queries in a way +that is specific to the SQL implementation of a particular vendor. The object +handles nuances such as how identifiers or values are quoted, or what the +identifier separator character is. To get an idea of the capabilities, the +interface for a platform object looks like this: + +```php +namespace Zend\Db\Adapter\Platform; + +interface PlatformInterface +{ + public function getName() : string; + public function getQuoteIdentifierSymbol() : string; + public function quoteIdentifier(string $identifier) : string; + public function quoteIdentifierChain(string|string[] $identiferChain) : string; + public function getQuoteValueSymbol() : string; + public function quoteValue(string $value) : string; + public function quoteTrustedValue(string $value) : string; + public function quoteValueList(string|string[] $valueList) : string; + public function getIdentifierSeparator() : string; + public function quoteIdentifierInFragment(string $identifier, array $additionalSafeWords = []) : string; +} +``` + +While you can directly instantiate a `Platform` object, generally speaking, it +is easier to get the proper `Platform` instance from the configured adapter (by +default the `Platform` type will match the underlying driver implementation): + +```php +$platform = $adapter->getPlatform(); + +// or +$platform = $adapter->platform; // magic property access +``` + +The following are examples of `Platform` usage: + +```php +// $adapter is a Zend\Db\Adapter\Adapter instance; +// $platform is a Zend\Db\Adapter\Platform\Sql92 instance. +$platform = $adapter->getPlatform(); + +// "first_name" +echo $platform->quoteIdentifier('first_name'); + +// " +echo $platform->getQuoteIdentifierSymbol(); + +// "schema"."mytable" +echo $platform->quoteIdentifierChain(['schema', 'mytable']); + +// ' +echo $platform->getQuoteValueSymbol(); + +// 'myvalue' +echo $platform->quoteValue('myvalue'); + +// 'value', 'Foo O\\'Bar' +echo $platform->quoteValueList(['value', "Foo O'Bar"]); + +// . +echo $platform->getIdentifierSeparator(); + +// "foo" as "bar" +echo $platform->quoteIdentifierInFragment('foo as bar'); + +// additionally, with some safe words: +// ("foo"."bar" = "boo"."baz") +echo $platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']); +``` + +## Using The Parameter Container + +The `ParameterContainer` object is a container for the various parameters that +need to be passed into a `Statement` object to fulfill all the various +parameterized parts of the SQL statement. This object implements the +`ArrayAccess` interface. Below is the `ParameterContainer` API: + +```php +namespace Zend\Db\Adapter; + +use ArrayAccess; +use ArrayIterator; +use Countable; +use Iterator; + +class ParameterContainer implements Iterator, ArrayAccess, Countable +{ + public function __construct(array $data = []) + + /** methods to interact with values */ + public function offsetExists(string|int $name) : bool; + public function offsetGet(string|int $name) : mixed; + public function offsetSetReference(string|int $name, string|int $from) : void; + public function offsetSet(string|int $name, mixed $value, mixed $errata = null, int $maxLength = null) : void; + public function offsetUnset(string|int $name) : void; + + /** set values from array (will reset first) */ + public function setFromArray(array $data) : ParameterContainer; + + /** methods to interact with value errata */ + public function offsetSetErrata(string|int $name, mixed $errata) : void; + public function offsetGetErrata(string|int $name) : mixed; + public function offsetHasErrata(string|int $name) : bool; + public function offsetUnsetErrata(string|int $name) : void; + + /** errata only iterator */ + public function getErrataIterator() : ArrayIterator; + + /** get array with named keys */ + public function getNamedArray() : array; + + /** get array with int keys, ordered by position */ + public function getPositionalArray() : array; + + /** iterator: */ + public function count() : int; + public function current() : mixed; + public function next() : mixed; + public function key() : string|int; + public function valid() : bool; + public function rewind() : void; + + /** merge existing array of parameters with existing parameters */ + public function merge(array $parameters) : ParameterContainer; +} +``` + +In addition to handling parameter names and values, the container will assist in +tracking parameter types for PHP type to SQL type handling. For example, it +might be important that: + +```php +$container->offsetSet('limit', 5); +``` + +be bound as an integer. To achieve this, pass in the +`ParameterContainer::TYPE_INTEGER` constant as the 3rd parameter: + +```php +$container->offsetSet('limit', 5, $container::TYPE_INTEGER); +``` + +This will ensure that if the underlying driver supports typing of bound +parameters, that this translated information will also be passed along to the +actual php database driver. + +## Examples + +Creating a `Driver`, a vendor-portable query, and preparing and iterating the +result: + +```php +$adapter = new Zend\Db\Adapter\Adapter($driverConfig); + +$qi = function ($name) use ($adapter) { + return $adapter->platform->quoteIdentifier($name); +}; +$fp = function ($name) use ($adapter) { + return $adapter->driver->formatParameterName($name); +}; + +$sql = 'UPDATE ' . $qi('artist') + . ' SET ' . $qi('name') . ' = ' . $fp('name') + . ' WHERE ' . $qi('id') . ' = ' . $fp('id'); + +$statement = $adapter->query($sql); + +$parameters = [ + 'name' => 'Updated Artist', + 'id' => 1, +]; + +$statement->execute($parameters); + +// DATA INSERTED, NOW CHECK + +$statement = $adapter->query( + 'SELECT * FROM ' + . $qi('artist') + . ' WHERE id = ' . $fp('id') +); + +$results = $statement->execute(['id' => 1]); + +$row = $results->current(); +$name = $row['name']; +``` diff --git a/bundled-libs/zendframework/zend-db/docs/book/index.html b/bundled-libs/zendframework/zend-db/docs/book/index.html new file mode 100644 index 00000000..c248f91b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/index.html @@ -0,0 +1,10 @@ +
+
+

zend-db

+ +

Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations.

+ +
$ composer require zendframework/zend-db
+
+
+ diff --git a/bundled-libs/zendframework/zend-db/docs/book/metadata.md b/bundled-libs/zendframework/zend-db/docs/book/metadata.md new file mode 100644 index 00000000..e1f5b31c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/metadata.md @@ -0,0 +1,229 @@ +# RDBMS Metadata + +`Zend\Db\Metadata` is as sub-component of zend-db that makes it possible to get +metadata information about tables, columns, constraints, triggers, and other +information from a database in a standardized way. The primary interface for +`Metadata` is: + +```php +namespace Zend\Db\Metadata; + +interface MetadataInterface +{ + public function getSchemas(); + + public function getTableNames(string $schema = null, bool $includeViews = false) : string[]; + public function getTables(string $schema = null, bool $includeViews = false) : Object\TableObject[]; + public function getTable(string $tableName, string $schema = null) : Object\TableObject; + + public function getViewNames(string $schema = null) : string[]; + public function getViews(string $schema = null) : Object\ViewObject[]; + public function getView(string $viewName, string $schema = null) : Object\ViewObject; + + public function getColumnNames(string string $table, $schema = null) : string[]; + public function getColumns(string $table, string $schema = null) : Object\ColumnObject[]; + public function getColumn(string $columnName, string $table, string $schema = null) Object\ColumnObject; + + public function getConstraints(string $table, $string schema = null) : Object\ConstraintObject[]; + public function getConstraint(string $constraintName, string $table, string $schema = null) : Object\ConstraintObject; + public function getConstraintKeys(string $constraint, string $table, string $schema = null) : Object\ConstraintKeyObject[]; + + public function getTriggerNames(string $schema = null) : string[]; + public function getTriggers(string $schema = null) : Object\TriggerObject[]; + public function getTrigger(string $triggerName, string $schema = null) : Object\TriggerObject; +} +``` + +## Basic Usage + +Usage of `Zend\Db\Metadata` involves: + +- Constructing a `Zend\Db\Metadata\Metadata` instance with an `Adapter`. +- Choosing a strategy for retrieving metadata, based on the database platform + used. In most cases, information will come from querying the + `INFORMATION_SCHEMA` tables for the currently accessible schema. + +The `Metadata::get*Names()` methods will return arrays of strings, while the +other methods will return value objects specific to the type queried. + +```php +$metadata = new Zend\Db\Metadata\Metadata($adapter); + +// get the table names +$tableNames = $metadata->getTableNames(); + +foreach ($tableNames as $tableName) { + echo 'In Table ' . $tableName . PHP_EOL; + + $table = $metadata->getTable($tableName); + + echo ' With columns: ' . PHP_EOL; + foreach ($table->getColumns() as $column) { + echo ' ' . $column->getName() + . ' -> ' . $column->getDataType() + . PHP_EOL; + } + + echo PHP_EOL; + echo ' With constraints: ' . PHP_EOL; + + foreach ($metadata->getConstraints($tableName) as $constraint) { + echo ' ' . $constraint->getName() + . ' -> ' . $constraint->getType() + . PHP_EOL; + + if (! $constraint->hasColumns()) { + continue; + } + + echo ' column: ' . implode(', ', $constraint->getColumns()); + if ($constraint->isForeignKey()) { + $fkCols = []; + foreach ($constraint->getReferencedColumns() as $refColumn) { + $fkCols[] = $constraint->getReferencedTableName() . '.' . $refColumn; + } + echo ' => ' . implode(', ', $fkCols); + } + + echo PHP_EOL; + } + + echo '----' . PHP_EOL; +} +``` + +## Metadata value objects + +Metadata returns value objects that provide an interface to help developers +better explore the metadata. Below is the API for the various value objects: + +### TableObject + +```php +class Zend\Db\Metadata\Object\TableObject +{ + public function __construct($name); + public function setColumns(array $columns); + public function getColumns(); + public function setConstraints($constraints); + public function getConstraints(); + public function setName($name); + public function getName(); +} +``` + +### ColumnObject + +```php +class Zend\Db\Metadata\Object\ColumnObject +{ + public function __construct($name, $tableName, $schemaName = null); + public function setName($name); + public function getName(); + public function getTableName(); + public function setTableName($tableName); + public function setSchemaName($schemaName); + public function getSchemaName(); + public function getOrdinalPosition(); + public function setOrdinalPosition($ordinalPosition); + public function getColumnDefault(); + public function setColumnDefault($columnDefault); + public function getIsNullable(); + public function setIsNullable($isNullable); + public function isNullable(); + public function getDataType(); + public function setDataType($dataType); + public function getCharacterMaximumLength(); + public function setCharacterMaximumLength($characterMaximumLength); + public function getCharacterOctetLength(); + public function setCharacterOctetLength($characterOctetLength); + public function getNumericPrecision(); + public function setNumericPrecision($numericPrecision); + public function getNumericScale(); + public function setNumericScale($numericScale); + public function getNumericUnsigned(); + public function setNumericUnsigned($numericUnsigned); + public function isNumericUnsigned(); + public function getErratas(); + public function setErratas(array $erratas); + public function getErrata($errataName); + public function setErrata($errataName, $errataValue); +} +``` + +### ConstraintObject + +```php +class Zend\Db\Metadata\Object\ConstraintObject +{ + public function __construct($name, $tableName, $schemaName = null); + public function setName($name); + public function getName(); + public function setSchemaName($schemaName); + public function getSchemaName(); + public function getTableName(); + public function setTableName($tableName); + public function setType($type); + public function getType(); + public function hasColumns(); + public function getColumns(); + public function setColumns(array $columns); + public function getReferencedTableSchema(); + public function setReferencedTableSchema($referencedTableSchema); + public function getReferencedTableName(); + public function setReferencedTableName($referencedTableName); + public function getReferencedColumns(); + public function setReferencedColumns(array $referencedColumns); + public function getMatchOption(); + public function setMatchOption($matchOption); + public function getUpdateRule(); + public function setUpdateRule($updateRule); + public function getDeleteRule(); + public function setDeleteRule($deleteRule); + public function getCheckClause(); + public function setCheckClause($checkClause); + public function isPrimaryKey(); + public function isUnique(); + public function isForeignKey(); + public function isCheck(); + +} +``` + +### TriggerObject + +```php +class Zend\Db\Metadata\Object\TriggerObject +{ + public function getName(); + public function setName($name); + public function getEventManipulation(); + public function setEventManipulation($eventManipulation); + public function getEventObjectCatalog(); + public function setEventObjectCatalog($eventObjectCatalog); + public function getEventObjectSchema(); + public function setEventObjectSchema($eventObjectSchema); + public function getEventObjectTable(); + public function setEventObjectTable($eventObjectTable); + public function getActionOrder(); + public function setActionOrder($actionOrder); + public function getActionCondition(); + public function setActionCondition($actionCondition); + public function getActionStatement(); + public function setActionStatement($actionStatement); + public function getActionOrientation(); + public function setActionOrientation($actionOrientation); + public function getActionTiming(); + public function setActionTiming($actionTiming); + public function getActionReferenceOldTable(); + public function setActionReferenceOldTable($actionReferenceOldTable); + public function getActionReferenceNewTable(); + public function setActionReferenceNewTable($actionReferenceNewTable); + public function getActionReferenceOldRow(); + public function setActionReferenceOldRow($actionReferenceOldRow); + public function getActionReferenceNewRow(); + public function setActionReferenceNewRow($actionReferenceNewRow); + public function getCreated(); + public function setCreated($created); +} +``` diff --git a/bundled-libs/zendframework/zend-db/docs/book/result-set.md b/bundled-libs/zendframework/zend-db/docs/book/result-set.md new file mode 100644 index 00000000..9e6b5aaa --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/result-set.md @@ -0,0 +1,157 @@ +# Result Sets + +`Zend\Db\ResultSet` is a sub-component of zend-db for abstracting the iteration +of results returned from queries producing rowsets. While data sources for this +can be anything that is iterable, generally these will be populated from +`Zend\Db\Adapter\Driver\ResultInterface` instances. + +Result sets must implement the `Zend\Db\ResultSet\ResultSetInterface`, and all +sub-components of zend-db that return a result set as part of their API will +assume an instance of a `ResultSetInterface` should be returned. In most cases, +the prototype pattern will be used by consuming object to clone a prototype of +a `ResultSet` and return a specialized `ResultSet` with a specific data source +injected. `ResultSetInterface` is defined as follows: + +```php +use Countable; +use Traversable; + +interface ResultSetInterface extends Traversable, Countable +{ + public function initialize(mixed $dataSource) : void; + public function getFieldCount() : int; +} +``` + +## Quick start + +`Zend\Db\ResultSet\ResultSet` is the most basic form of a `ResultSet` object +that will expose each row as either an `ArrayObject`-like object or an array of +row data. By default, `Zend\Db\Adapter\Adapter` will use a prototypical +`Zend\Db\ResultSet\ResultSet` object for iterating when using the +`Zend\Db\Adapter\Adapter::query()` method. + +The following is an example workflow similar to what one might find inside +`Zend\Db\Adapter\Adapter::query()`: + +```php +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\ResultSet\ResultSet; + +$statement = $driver->createStatement('SELECT * FROM users'); +$statement->prepare(); +$result = $statement->execute($parameters); + +if ($result instanceof ResultInterface && $result->isQueryResult()) { + $resultSet = new ResultSet; + $resultSet->initialize($result); + + foreach ($resultSet as $row) { + echo $row->my_column . PHP_EOL; + } +} +``` + +## Zend\\Db\\ResultSet\\ResultSet and Zend\\Db\\ResultSet\\AbstractResultSet + +For most purposes, either an instance of `Zend\Db\ResultSet\ResultSet` or a +derivative of `Zend\Db\ResultSet\AbstractResultSet` will be used. The +implementation of the `AbstractResultSet` offers the following core +functionality: + +```php +namespace Zend\Db\ResultSet; + +use Iterator; + +abstract class AbstractResultSet implements Iterator, ResultSetInterface +{ + public function initialize(array|Iterator|IteratorAggregate|ResultInterface $dataSource) : self; + public function getDataSource() : Iterator|IteratorAggregate|ResultInterface; + public function getFieldCount() : int; + + /** Iterator */ + public function next() : mixed; + public function key() : string|int; + public function current() : mixed; + public function valid() : bool; + public function rewind() : void; + + /** countable */ + public function count() : int; + + /** get rows as array */ + public function toArray() : array; +} +``` + +## Zend\\Db\\ResultSet\\HydratingResultSet + +`Zend\Db\ResultSet\HydratingResultSet` is a more flexible `ResultSet` object +that allows the developer to choose an appropriate "hydration strategy" for +getting row data into a target object. While iterating over results, +`HydratingResultSet` will take a prototype of a target object and clone it once +for each row. The `HydratingResultSet` will then hydrate that clone with the +row data. + +The `HydratingResultSet` depends on +[zend-hydrator](https://docs.zendframework.com/zend-hydrator), which you will +need to install: + +```bash +$ composer require zendframework/zend-hydrator +``` + +In the example below, rows from the database will be iterated, and during +iteration, `HydratingResultSet` will use the `Reflection` based hydrator to +inject the row data directly into the protected members of the cloned +`UserEntity` object: + +```php +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\ResultSet\HydratingResultSet; +use Zend\Hydrator\Reflection as ReflectionHydrator; + +class UserEntity +{ + protected $first_name; + protected $last_name; + + public function getFirstName() + { + return $this->first_name; + } + + public function getLastName() + { + return $this->last_name; + } + + public function setFirstName($firstName) + { + $this->first_name = $firstName; + } + + public function setLastName($lastName) + { + $this->last_name = $lastName; + } +} + +$statement = $driver->createStatement($sql); +$statement->prepare($parameters); +$result = $statement->execute(); + +if ($result instanceof ResultInterface && $result->isQueryResult()) { + $resultSet = new HydratingResultSet(new ReflectionHydrator, new UserEntity); + $resultSet->initialize($result); + + foreach ($resultSet as $user) { + echo $user->getFirstName() . ' ' . $user->getLastName() . PHP_EOL; + } +} +``` + +For more information, see the [zend-hydrator](https://docs.zendframework.com/zend-hydrator/) +documentation to get a better sense of the different strategies that can be +employed in order to populate a target object. diff --git a/bundled-libs/zendframework/zend-db/docs/book/row-gateway.md b/bundled-libs/zendframework/zend-db/docs/book/row-gateway.md new file mode 100644 index 00000000..4b986003 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/row-gateway.md @@ -0,0 +1,98 @@ +# Row Gateways + +`Zend\Db\RowGateway` is a sub-component of zend-db that implements the Row Data +Gateway pattern described in the book [Patterns of Enterprise Application +Architecture](http://www.martinfowler.com/books/eaa.html). Row Data Gateways +model individual rows of a database table, and provide methods such as `save()` +and `delete()` that persist the row to the database. Likewise, after a row from +the database is retrieved, it can then be manipulated and `save()`'d back to +the database in the same position (row), or it can be `delete()`'d from the +table. + +`RowGatewayInterface` defines the methods `save()` and `delete()`: + +```php +namespace Zend\Db\RowGateway; + +interface RowGatewayInterface +{ + public function save(); + public function delete(); +} +``` + +## Quick start + +`RowGateway` is generally used in conjunction with objects that produce +`Zend\Db\ResultSet`s, though it may also be used standalone. To use it +standalone, you need an `Adapter` instance and a set of data to work with. + +The following demonstrates a basic use case. + +```php +use Zend\Db\RowGateway\RowGateway; + +// Query the database: +$resultSet = $adapter->query('SELECT * FROM `user` WHERE `id` = ?', [2]); + +// Get array of data: +$rowData = $resultSet->current()->getArrayCopy(); + +// Create a row gateway: +$rowGateway = new RowGateway('id', 'my_table', $adapter); +$rowGateway->populate($rowData, true); + +// Manipulate the row and persist it: +$rowGateway->first_name = 'New Name'; +$rowGateway->save(); + +// Or delete this row: +$rowGateway->delete(); +``` + +The workflow described above is greatly simplified when `RowGateway` is used in +conjunction with the [TableGateway RowGatewayFeature](table-gateway.md#tablegateway-features). +In that paradigm, `select()` operations will produce a `ResultSet` that iterates +`RowGateway` instances. + +As an example: + +```php +use Zend\Db\TableGateway\Feature\RowGatewayFeature; +use Zend\Db\TableGateway\TableGateway; + +$table = new TableGateway('artist', $adapter, new RowGatewayFeature('id')); +$results = $table->select(['id' => 2]); + +$artistRow = $results->current(); +$artistRow->name = 'New Name'; +$artistRow->save(); +``` + +## ActiveRecord Style Objects + +If you wish to have custom behaviour in your `RowGateway` objects — +essentially making them behave similarly to the +[ActiveRecord](http://www.martinfowler.com/eaaCatalog/activeRecord.html) +pattern), pass a prototype object implementing the `RowGatewayInterface` to the +`RowGatewayFeature` constructor instead of a primary key: + +```php +use Zend\Db\TableGateway\Feature\RowGatewayFeature; +use Zend\Db\TableGateway\TableGateway; +use Zend\Db\RowGateway\RowGatewayInterface; + +class Artist implements RowGatewayInterface +{ + protected $adapter; + + public function __construct($adapter) + { + $this->adapter = $adapter; + } + + // ... save() and delete() implementations +} + +$table = new TableGateway('artist', $adapter, new RowGatewayFeature(new Artist($adapter))); +``` diff --git a/bundled-libs/zendframework/zend-db/docs/book/sql-ddl.md b/bundled-libs/zendframework/zend-db/docs/book/sql-ddl.md new file mode 100644 index 00000000..0daac436 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/sql-ddl.md @@ -0,0 +1,201 @@ +# DDL Abstraction + +`Zend\Db\Sql\Ddl` is a sub-component of `Zend\Db\Sql` allowing creation of DDL +(Data Definition Language) SQL statements. When combined with a platform +specific `Zend\Db\Sql\Sql` object, DDL objects are capable of producing +platform-specific `CREATE TABLE` statements, with specialized data types, +constraints, and indexes for a database/schema. + +The following platforms have platform specializations for DDL: + +- MySQL +- All databases compatible with ANSI SQL92 + +## Creating Tables + +Like `Zend\Db\Sql` objects, each statement type is represented by a class. For +example, `CREATE TABLE` is modeled by the `CreateTable` class; this is likewise +the same for `ALTER TABLE` (as `AlterTable`), and `DROP TABLE` (as +`DropTable`). You can create instances using a number of approaches: + +```php +use Zend\Db\Sql\Ddl; +use Zend\Db\Sql\TableIdentifier; + +$table = new Ddl\CreateTable(); + +// With a table name: +$table = new Ddl\CreateTable('bar'); + +// With a schema name "foo": +$table = new Ddl\CreateTable(new TableIdentifier('bar', 'foo')); + +// Optionally, as a temporary table: +$table = new Ddl\CreateTable('bar', true); +``` + +You can also set the table after instantiation: + +```php +$table->setTable('bar'); +``` + +Currently, columns are added by creating a column object (described in the +[data type table below](#currently-supported-data-types)): + +```php +use Zend\Db\Sql\Ddl\Column; + +$table->addColumn(new Column\Integer('id')); +$table->addColumn(new Column\Varchar('name', 255)); +``` + +Beyond adding columns to a table, you may also add constraints: + +```php +use Zend\Db\Sql\Ddl\Constraint; + +$table->addConstraint(new Constraint\PrimaryKey('id')); +$table->addConstraint( + new Constraint\UniqueKey(['name', 'foo'], 'my_unique_key') +); +``` +You can also use the `AUTO_INCREMENT` attribute for MySQL: +```php +use Zend\Db\Sql\Ddl\Column; + +$column = new Column\Integer('id'); +$column->setOption('AUTO_INCREMENT', true); +``` + +## Altering Tables + +Similar to `CreateTable`, you may also use `AlterTable` instances: + +```php +use Zend\Db\Sql\Ddl; +use Zend\Db\Sql\TableIdentifier; + +$table = new Ddl\AlterTable(); + +// With a table name: +$table = new Ddl\AlterTable('bar'); + +// With a schema name "foo": +$table = new Ddl\AlterTable(new TableIdentifier('bar', 'foo')); + +// Optionally, as a temporary table: +$table = new Ddl\AlterTable('bar', true); +``` + +The primary difference between a `CreateTable` and `AlterTable` is that the +`AlterTable` takes into account that the table and its assets already exist. +Therefore, while you still have `addColumn()` and `addConstraint()`, you will +also have the ability to *alter* existing columns: + +```php +use Zend\Db\Sql\Ddl\Column; + +$table->changeColumn('name', Column\Varchar('new_name', 50)); +``` + +You may also *drop* existing columns or constraints: + +```php +$table->dropColumn('foo'); +$table->dropConstraint('my_index'); +``` + +## Dropping Tables + +To drop a table, create a `DropTable` instance: + +```php +use Zend\Db\Sql\Ddl; +use Zend\Db\Sql\TableIdentifier; + +// With a table name: +$drop = new Ddl\DropTable('bar'); + +// With a schema name "foo": +$drop = new Ddl\DropTable(new TableIdentifier('bar', 'foo')); +``` + +## Executing DDL Statements + +After a DDL statement object has been created and configured, at some point you +will need to execute the statement. This requires an `Adapter` instance and a +properly seeded `Sql` instance. + +The workflow looks something like this, with `$ddl` being a `CreateTable`, +`AlterTable`, or `DropTable` instance: + +```php +use Zend\Db\Sql\Sql; + +// Existence of $adapter is assumed. +$sql = new Sql($adapter); + +$adapter->query( + $sql->getSqlStringForSqlObject($ddl), + $adapter::QUERY_MODE_EXECUTE +); +``` + +By passing the `$ddl` object through the `$sql` instance's +`getSqlStringForSqlObject()` method, we ensure that any platform specific +specializations/modifications are utilized to create a platform specific SQL +statement. + +Next, using the constant `Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE` ensures +that the SQL statement is not prepared, as most DDL statements on most +platforms cannot be prepared, only executed. + +## Currently Supported Data Types + +These types exist in the `Zend\Db\Sql\Ddl\Column` namespace. Data types must +implement `Zend\Db\Sql\Ddl\Column\ColumnInterface`. + +In alphabetical order: + +Type | Arguments For Construction +-----------------|--------------------------- +BigInteger | `$name`, `$nullable = false`, `$default = null`, `array $options = array()` +Binary | `$name`, `$length`, `nullable = false`, `$default = null`, `array $options = array()` +Blob | `$name`, `$length`, `nullable = false`, `$default = null`, `array $options = array()` +Boolean | `$name` +Char | `$name`, `length` +Column (generic) | `$name = null` +Date | `$name` +DateTime | `$name` +Decimal | `$name`, `$precision`, `$scale = null` +Float | `$name`, `$digits`, `$decimal` (Note: this class is deprecated as of 2.4.0; use Floating instead) +Floating | `$name`, `$digits`, `$decimal` +Integer | `$name`, `$nullable = false`, `default = null`, `array $options = array()` +Text | `$name`, `$length`, `nullable = false`, `$default = null`, `array $options = array()` +Time | `$name` +Timestamp | `$name` +Varbinary | `$name`, `$length` +Varchar | `$name`, `$length` + +Each of the above types can be utilized in any place that accepts a `Column\ColumnInterface` +instance. Currently, this is primarily in `CreateTable::addColumn()` and `AlterTable`'s +`addColumn()` and `changeColumn()` methods. + +## Currently Supported Constraint Types + +These types exist in the `Zend\Db\Sql\Ddl\Constraint` namespace. Data types +must implement `Zend\Db\Sql\Ddl\Constraint\ConstraintInterface`. + +In alphabetical order: + +Type | Arguments For Construction +-----------|--------------------------- +Check | `$expression`, `$name` +ForeignKey | `$name`, `$column`, `$referenceTable`, `$referenceColumn`, `$onDeleteRule = null`, `$onUpdateRule = null` +PrimaryKey | `$columns` +UniqueKey | `$column`, `$name = null` + +Each of the above types can be utilized in any place that accepts a +`Column\ConstraintInterface` instance. Currently, this is primarily in +`CreateTable::addConstraint()` and `AlterTable::addConstraint()`. diff --git a/bundled-libs/zendframework/zend-db/docs/book/sql.md b/bundled-libs/zendframework/zend-db/docs/book/sql.md new file mode 100644 index 00000000..52f5ab8b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/sql.md @@ -0,0 +1,741 @@ +# SQL Abstraction + +`Zend\Db\Sql` is a SQL abstraction layer for building platform-specific SQL +queries via an object-oriented API. The end result of a `Zend\Db\Sql` object +will be to either produce a `Statement` and `ParameterContainer` that +represents the target query, or a full string that can be directly executed +against the database platform. To achieve this, `Zend\Db\Sql` objects require a +`Zend\Db\Adapter\Adapter` object in order to produce the desired results. + +## Quick start + +There are four primary tasks associated with interacting with a database +defined by Data Manipulation Language (DML): selecting, inserting, updating, +and deleting. As such, there are four primary classes that developers can +interact with in order to build queries in the `Zend\Db\Sql` namespace: +`Select`, `Insert`, `Update`, and `Delete`. + +Since these four tasks are so closely related and generally used together +within the same application, the `Zend\Db\Sql\Sql` class helps you create them +and produce the result you are attempting to achieve. + +```php +use Zend\Db\Sql\Sql; + +$sql = new Sql($adapter); +$select = $sql->select(); // returns a Zend\Db\Sql\Select instance +$insert = $sql->insert(); // returns a Zend\Db\Sql\Insert instance +$update = $sql->update(); // returns a Zend\Db\Sql\Update instance +$delete = $sql->delete(); // returns a Zend\Db\Sql\Delete instance +``` + +As a developer, you can now interact with these objects, as described in the +sections below, to customize each query. Once they have been populated with +values, they are ready to either be prepared or executed. + +To prepare (using a Select object): + +```php +use Zend\Db\Sql\Sql; + +$sql = new Sql($adapter); +$select = $sql->select(); +$select->from('foo'); +$select->where(['id' => 2]); + +$statement = $sql->prepareStatementForSqlObject($select); +$results = $statement->execute(); +``` + +To execute (using a Select object) + +```php +use Zend\Db\Sql\Sql; + +$sql = new Sql($adapter); +$select = $sql->select(); +$select->from('foo'); +$select->where(['id' => 2]); + +$selectString = $sql->buildSqlString($select); +$results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE); +``` + +`Zend\\Db\\Sql\\Sql` objects can also be bound to a particular table so that in +obtaining a `Select`, `Insert`, `Update`, or `Delete` instance, the object will be +seeded with the table: + +```php +use Zend\Db\Sql\Sql; + +$sql = new Sql($adapter, 'foo'); +$select = $sql->select(); +$select->where(['id' => 2]); // $select already has from('foo') applied +``` + +## Common interfaces for SQL implementations + +Each of these objects implements the following two interfaces: + +```php +interface PreparableSqlInterface +{ + public function prepareStatement(Adapter $adapter, StatementInterface $statement) : void; +} + +interface SqlInterface +{ + public function getSqlString(PlatformInterface $adapterPlatform = null) : string; +} +``` + +Use these functions to produce either (a) a prepared statement, or (b) a string +to execute. + +## Select + +`Zend\Db\Sql\Select` presents a unified API for building platform-specific SQL +SELECT queries. Instances may be created and consumed without +`Zend\Db\Sql\Sql`: + +```php +use Zend\Db\Sql\Select; + +$select = new Select(); +// or, to produce a $select bound to a specific table +$select = new Select('foo'); +``` + +If a table is provided to the `Select` object, then `from()` cannot be called +later to change the name of the table. + +Once you have a valid `Select` object, the following API can be used to further +specify various select statement parts: + +```php +class Select extends AbstractSql implements SqlInterface, PreparableSqlInterface +{ + const JOIN_INNER = 'inner'; + const JOIN_OUTER = 'outer'; + const JOIN_LEFT = 'left'; + const JOIN_RIGHT = 'right'; + const SQL_STAR = '*'; + const ORDER_ASCENDING = 'ASC'; + const ORDER_DESCENDING = 'DESC'; + + public $where; // @param Where $where + + public function __construct(string|array|TableIdentifier $table = null); + public function from(string|array|TableIdentifier $table) : self; + public function columns(array $columns, bool $prefixColumnsWithTable = true) : self; + public function join(string|array $name, string $on, string|array $columns = self::SQL_STAR, string $type = self::JOIN_INNER) : self; + public function where(Where|callable|string|array|PredicateInterface $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self; + public function group(string|array $group); + public function having(Having|callable|string|array $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self; + public function order(string|array $order) : self; + public function limit(int $limit) : self; + public function offset(int $offset) : self; +} +``` + +### from() + +```php +// As a string: +$select->from('foo'); + +// As an array to specify an alias +// (produces SELECT "t".* FROM "table" AS "t") +$select->from(['t' => 'table']); + +// Using a Sql\TableIdentifier: +// (same output as above) +$select->from(['t' => new TableIdentifier('table')]); +``` + +### columns() + +```php +// As an array of names +$select->columns(['foo', 'bar']); + +// As an associative array with aliases as the keys +// (produces 'bar' AS 'foo', 'bax' AS 'baz') +$select->columns([ + 'foo' => 'bar', + 'baz' => 'bax' +]); + +// Sql function call on the column +// (produces CONCAT_WS('/', 'bar', 'bax') AS 'foo') +$select->columns([ + 'foo' => new \Zend\Db\Sql\Expression("CONCAT_WS('/', 'bar', 'bax')") +]); +``` + +### join() + +```php +$select->join( + 'foo', // table name + 'id = bar.id', // expression to join on (will be quoted by platform object before insertion), + ['bar', 'baz'], // (optional) list of columns, same requirements as columns() above + $select::JOIN_OUTER // (optional), one of inner, outer, left, right also represented by constants in the API +); + +$select + ->from(['f' => 'foo']) // base table + ->join( + ['b' => 'bar'], // join table with alias + 'f.foo_id = b.foo_id' // join expression + ); +``` + +### where(), having() + +`Zend\Db\Sql\Select` provides bit of flexibility as it regards to what kind of +parameters are acceptable when calling `where()` or `having()`. The method +signature is listed as: + +```php +/** + * Create where clause + * + * @param Where|callable|string|array $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @return Select + */ +public function where($predicate, $combination = Predicate\PredicateSet::OP_AND); +``` + +If you provide a `Zend\Db\Sql\Where` instance to `where()` or a +`Zend\Db\Sql\Having` instance to `having()`, any previous internal instances +will be replaced completely. When either instance is processed, this object will +be iterated to produce the WHERE or HAVING section of the SELECT statement. + +If you provide a PHP callable to `where()` or `having()`, this function will be +called with the `Select`'s `Where`/`Having` instance as the only parameter. +This enables code like the following: + +```php +$select->where(function (Where $where) { + $where->like('username', 'ralph%'); +}); +``` + +If you provide a *string*, this string will be used to create a +`Zend\Db\Sql\Predicate\Expression` instance, and its contents will be applied +as-is, with no quoting: + +```php +// SELECT "foo".* FROM "foo" WHERE x = 5 +$select->from('foo')->where('x = 5'); +``` + +If you provide an array with integer indices, the value can be one of: + +- a string; this will be used to build a `Predicate\Expression`. +- any object implementing `Predicate\PredicateInterface`. + +In either case, the instances are pushed onto the `Where` stack with the +`$combination` provided (defaulting to `AND`). + +As an example: + +```php +// SELECT "foo".* FROM "foo" WHERE x = 5 AND y = z +$select->from('foo')->where(['x = 5', 'y = z']); +``` + +If you provide an associative array with string keys, any value with a string +key will be cast as follows: + +PHP value | Predicate type +--------- | -------------- +`null` | `Predicate\IsNull` +`array` | `Predicate\In` +`string` | `Predicate\Operator`, where the key is the identifier. + +As an example: + +```php +// SELECT "foo".* FROM "foo" WHERE "c1" IS NULL AND "c2" IN (?, ?, ?) AND "c3" IS NOT NULL +$select->from('foo')->where([ + 'c1' => null, + 'c2' => [1, 2, 3], + new \Zend\Db\Sql\Predicate\IsNotNull('c3'), +]); +``` + +As another example of complex queries with nested conditions e.g. + +```sql +SELECT * WHERE (column1 is null or column1 = 2) AND (column2 = 3) +``` + +you need to use the `nest()` and `unnest()` methods, as follows: + +```php +$select->where->nest() // bracket opened + ->isNull('column1') + ->or + ->equalTo('column1', '2') + ->unnest(); // bracket closed + ->equalTo('column2', '3'); +``` + +### order() + +```php +$select = new Select; +$select->order('id DESC'); // produces 'id' DESC + +$select = new Select; +$select + ->order('id DESC') + ->order('name ASC, age DESC'); // produces 'id' DESC, 'name' ASC, 'age' DESC + +$select = new Select; +$select->order(['name ASC', 'age DESC']); // produces 'name' ASC, 'age' DESC +``` + +### limit() and offset() + +```php +$select = new Select; +$select->limit(5); // always takes an integer/numeric +$select->offset(10); // similarly takes an integer/numeric +``` + +## Insert + +The Insert API: + +```php +class Insert implements SqlInterface, PreparableSqlInterface +{ + const VALUES_MERGE = 'merge'; + const VALUES_SET = 'set'; + + public function __construct(string|TableIdentifier $table = null); + public function into(string|TableIdentifier $table) : self; + public function columns(array $columns) : self; + public function values(array $values, string $flag = self::VALUES_SET) : self; +} +``` + +As with `Select`, the table may be provided during instantiation or via the +`into()` method. + +### columns() + +```php +$insert->columns(['foo', 'bar']); // set the valid columns +``` + +### values() + +```php +// The default behavior of values is to set the values; +// successive calls will not preserve values from previous calls. +$insert->values([ + 'col_1' => 'value1', + 'col_2' => 'value2', +]); +``` + +```php +// To merge values with previous calls, provide the appropriate flag: +$insert->values(['col_2' => 'value2'], $insert::VALUES_MERGE); +``` + +## Update + +```php +class Update +{ + const VALUES_MERGE = 'merge'; + const VALUES_SET = 'set'; + + public $where; // @param Where $where + public function __construct(string|TableIdentifier $table = null); + public function table(string|TableIdentifier $table) : self; + public function set(array $values, string $flag = self::VALUES_SET) : self; + public function where(Where|callable|string|array|PredicateInterface $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self; +} +``` + +### set() + +```php +$update->set(['foo' => 'bar', 'baz' => 'bax']); +``` + +### where() + +See the [section on Where and Having](#where-and-having). + +## Delete + +```php +class Delete +{ + public $where; // @param Where $where + + public function __construct(string|TableIdentifier $table = null); + public function from(string|TableIdentifier $table); + public function where(Where|callable|string|array|PredicateInterface $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self; +} +``` + +### where() + +See the [section on Where and Having](#where-and-having). + +## Where and Having + +In the following, we will talk about `Where`; note, however, that `Having` +utilizes the same API. + +Effectively, `Where` and `Having` extend from the same base object, a +`Predicate` (and `PredicateSet`). All of the parts that make up a WHERE or +HAVING clause that are AND'ed or OR'd together are called *predicates*. The +full set of predicates is called a `PredicateSet`. A `Predicate` generally +contains the values (and identifiers) separate from the fragment they belong to +until the last possible moment when the statement is either prepared +(parameteritized) or executed. In parameterization, the parameters will be +replaced with their proper placeholder (a named or positional parameter), and +the values stored inside an `Adapter\ParameterContainer`. When executed, the +values will be interpolated into the fragments they belong to and properly +quoted. + +In the `Where`/`Having` API, a distinction is made between what elements are +considered identifiers (`TYPE_IDENTIFIER`) and which are values (`TYPE_VALUE`). +There is also a special use case type for literal values (`TYPE_LITERAL`). All +element types are expressed via the `Zend\Db\Sql\ExpressionInterface` +interface. + +> ### Literals +> +> In ZF 2.1, an actual `Literal` type was added. `Zend\Db\Sql` now makes the +> distinction that literals will not have any parameters that need +> interpolating, while `Expression` objects *might* have parameters that need +> interpolating. In cases where there are parameters in an `Expression`, +> `Zend\Db\Sql\AbstractSql` will do its best to identify placeholders when the +> `Expression` is processed during statement creation. In short, if you don't +> have parameters, use `Literal` objects. + +The `Where` and `Having` API is that of `Predicate` and `PredicateSet`: + +```php +// Where & Having extend Predicate: +class Predicate extends PredicateSet +{ + public $and; + public $or; + public $AND; + public $OR; + public $NEST; + public $UNNEST; + + public function nest() : Predicate; + public function setUnnest(Predicate $predicate) : void; + public function unnest() : Predicate; + public function equalTo( + int|float|bool|string $left, + int|float|bool|string $right, + string $leftType = self::TYPE_IDENTIFIER, + string $rightType = self::TYPE_VALUE + ) : self; + public function notEqualTo( + int|float|bool|string $left, + int|float|bool|string $right, + string $leftType = self::TYPE_IDENTIFIER, + string $rightType = self::TYPE_VALUE + ) : self; + public function lessThan( + int|float|bool|string $left, + int|float|bool|string $right, + string $leftType = self::TYPE_IDENTIFIER, + string $rightType = self::TYPE_VALUE + ) : self; + public function greaterThan( + int|float|bool|string $left, + int|float|bool|string $right, + string $leftType = self::TYPE_IDENTIFIER, + string $rightType = self::TYPE_VALUE + ) : self; + public function lessThanOrEqualTo( + int|float|bool|string $left, + int|float|bool|string $right, + string $leftType = self::TYPE_IDENTIFIER, + string $rightType = self::TYPE_VALUE + ) : self; + public function greaterThanOrEqualTo( + int|float|bool|string $left, + int|float|bool|string $right, + string $leftType = self::TYPE_IDENTIFIER, + string $rightType = self::TYPE_VALUE + ) : self; + public function like(string $identifier, string $like) : self; + public function notLike(string $identifier, string $notLike) : self; + public function literal(string $literal) : self; + public function expression(string $expression, array $parameters = null) : self; + public function isNull(string $identifier) : self; + public function isNotNull(string $identifier) : self; + public function in(string $identifier, array $valueSet = []) : self; + public function notIn(string $identifier, array $valueSet = []) : self; + public function between( + string $identifier, + int|float|string $minValue, + int|float|string $maxValue + ) : self; + public function notBetween( + string $identifier, + int|float|string $minValue, + int|float|string $maxValue + ) : self; + public function predicate(PredicateInterface $predicate) : self; + + // Inherited From PredicateSet + + public function addPredicate(PredicateInterface $predicate, $combination = null) : self; + public function getPredicates() PredicateInterface[]; + public function orPredicate(PredicateInterface $predicate) : self; + public function andPredicate(PredicateInterface $predicate) : self; + public function getExpressionData() : array; + public function count() : int; +} +``` + +Each method in the API will produce a corresponding `Predicate` object of a similarly named +type, as described below. + +### equalTo(), lessThan(), greaterThan(), lessThanOrEqualTo(), greaterThanOrEqualTo() + +```php +$where->equalTo('id', 5); + +// The above is equivalent to: +$where->addPredicate( + new Predicate\Operator($left, Operator::OPERATOR_EQUAL_TO, $right, $leftType, $rightType) +); +``` + +Operators use the following API: + +```php +class Operator implements PredicateInterface +{ + const OPERATOR_EQUAL_TO = '='; + const OP_EQ = '='; + const OPERATOR_NOT_EQUAL_TO = '!='; + const OP_NE = '!='; + const OPERATOR_LESS_THAN = '<'; + const OP_LT = '<'; + const OPERATOR_LESS_THAN_OR_EQUAL_TO = '<='; + const OP_LTE = '<='; + const OPERATOR_GREATER_THAN = '>'; + const OP_GT = '>'; + const OPERATOR_GREATER_THAN_OR_EQUAL_TO = '>='; + const OP_GTE = '>='; + + public function __construct( + int|float|bool|string $left = null, + string $operator = self::OPERATOR_EQUAL_TO, + int|float|bool|string $right = null, + string $leftType = self::TYPE_IDENTIFIER, + string $rightType = self::TYPE_VALUE + ); + public function setLeft(int|float|bool|string $left); + public function getLeft() : int|float|bool|string; + public function setLeftType(string $type) : self; + public function getLeftType() : string; + public function setOperator(string $operator); + public function getOperator() : string; + public function setRight(int|float|bool|string $value) : self; + public function getRight() : int|float|bool|string; + public function setRightType(string $type) : self; + public function getRightType() : string; + public function getExpressionData() : array; +} +``` + +### like($identifier, $like), notLike($identifier, $notLike) + +```php +$where->like($identifier, $like): + +// The above is equivalent to: +$where->addPredicate( + new Predicate\Like($identifier, $like) +); +``` + +The following is the `Like` API: + +```php +class Like implements PredicateInterface +{ + public function __construct(string $identifier = null, string $like = null); + public function setIdentifier(string $identifier) : self; + public function getIdentifier() : string; + public function setLike(string $like) : self; + public function getLike() : string; +} +``` + +### literal($literal) + +```php +$where->literal($literal); + +// The above is equivalent to: +$where->addPredicate( + new Predicate\Literal($literal) +); +``` + +The following is the `Literal` API: + +```php +class Literal implements ExpressionInterface, PredicateInterface +{ + const PLACEHOLDER = '?'; + public function __construct(string $literal = ''); + public function setLiteral(string $literal) : self; + public function getLiteral() : string; +} +``` + +### expression($expression, $parameter) + +```php +$where->expression($expression, $parameter); + +// The above is equivalent to: +$where->addPredicate( + new Predicate\Expression($expression, $parameter) +); +``` + +The following is the `Expression` API: + +```php +class Expression implements ExpressionInterface, PredicateInterface +{ + const PLACEHOLDER = '?'; + + public function __construct( + string $expression = null, + int|float|bool|string|array $valueParameter = null + /* [, $valueParameter, ... ] */ + ); + public function setExpression(string $expression) : self; + public function getExpression() : string; + public function setParameters(int|float|bool|string|array $parameters) : self; + public function getParameters() : array; +} +``` + +### isNull($identifier) + +```php +$where->isNull($identifier); + +// The above is equivalent to: +$where->addPredicate( + new Predicate\IsNull($identifier) +); +``` + +The following is the `IsNull` API: + +```php +class IsNull implements PredicateInterface +{ + public function __construct(string $identifier = null); + public function setIdentifier(string $identifier) : self; + public function getIdentifier() : string; +} +``` + +### isNotNull($identifier) + +```php +$where->isNotNull($identifier); + +// The above is equivalent to: +$where->addPredicate( + new Predicate\IsNotNull($identifier) +); +``` + +The following is the `IsNotNull` API: + +```php +class IsNotNull implements PredicateInterface +{ + public function __construct(string $identifier = null); + public function setIdentifier(string $identifier) : self; + public function getIdentifier() : string; +} +``` + +### in($identifier, $valueSet), notIn($identifier, $valueSet) + +```php +$where->in($identifier, $valueSet); + +// The above is equivalent to: +$where->addPredicate( + new Predicate\In($identifier, $valueSet) +); +``` + +The following is the `In` API: + +```php +class In implements PredicateInterface +{ + public function __construct( + string|array $identifier = null, + array|Select $valueSet = null + ); + public function setIdentifier(string|array $identifier) : self; + public function getIdentifier() : string|array; + public function setValueSet(array|Select $valueSet) : self; + public function getValueSet() : array|Select; +} +``` + +### between($identifier, $minValue, $maxValue), notBetween($identifier, $minValue, $maxValue) + +```php +$where->between($identifier, $minValue, $maxValue); + +// The above is equivalent to: +$where->addPredicate( + new Predicate\Between($identifier, $minValue, $maxValue) +); +``` + +The following is the `Between` API: + +```php +class Between implements PredicateInterface +{ + public function __construct( + string $identifier = null, + int|float|string $minValue = null, + int|float|string $maxValue = null + ); + public function setIdentifier(string $identifier) : self; + public function getIdentifier() : string; + public function setMinValue(int|float|string $minValue) : self; + public function getMinValue() : int|float|string; + public function setMaxValue(int|float|string $maxValue) : self; + public function getMaxValue() : int|float|string; + public function setSpecification(string $specification); +} +``` diff --git a/bundled-libs/zendframework/zend-db/docs/book/table-gateway.md b/bundled-libs/zendframework/zend-db/docs/book/table-gateway.md new file mode 100644 index 00000000..8e51138c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/docs/book/table-gateway.md @@ -0,0 +1,217 @@ +# Table Gateways + +The Table Gateway subcomponent provides an object-oriented representation of a +database table; its methods mirror the most common table operations. In code, +the interface resembles: + +```php +namespace Zend\Db\TableGateway; + +use Zend\Db\ResultSet\ResultSetInterface; +use Zend\Db\Sql\Where; + +interface TableGatewayInterface +{ + public function getTable() : string; + public function select(Where|callable|string|array $where = null) : ResultSetInterface; + public function insert(array $set) : int; + public function update( + array $set, + Where|callable|string|array $where = null, + array $joins = null + ) : int; + public function delete(Where|callable|string|array $where) : int; +} +``` + +There are two primary implementations of the `TableGatewayInterface`, +`AbstractTableGateway` and `TableGateway`. The `AbstractTableGateway` is an +abstract basic implementation that provides functionality for `select()`, +`insert()`, `update()`, `delete()`, as well as an additional API for doing +these same kinds of tasks with explicit `Zend\Db\Sql` objects: `selectWith()`, +`insertWith()`, `updateWith()`, and `deleteWith()`. In addition, +AbstractTableGateway also implements a "Feature" API, that allows for expanding +the behaviors of the base `TableGateway` implementation without having to +extend the class with this new functionality. The `TableGateway` concrete +implementation simply adds a sensible constructor to the `AbstractTableGateway` +class so that out-of-the-box, `TableGateway` does not need to be extended in +order to be consumed and utilized to its fullest. + +## Quick start + +The following example uses `Zend\Db\TableGateway\TableGateway`, which defines +the following API: + +```php +namespace Zend\Db\TableGateway; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\ResultSet\ResultSet; +use Zend\Db\ResultSet\ResultSetInterface; +use Zend\Db\Sql; +use Zend\Db\Sql\TableIdentifier; + +class TableGateway extends AbstractTableGateway +{ + public $lastInsertValue; + public $table; + public $adapter; + + public function __construct( + string|TableIdentifier $table, + AdapterInterface $adapter, + Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[] $features = null, + ResultSetInterface $resultSetPrototype = null, + Sql\Sql $sql = null + ); + + /** Inherited from AbstractTableGateway */ + + public function isInitialized() : bool; + public function initialize() : void; + public function getTable() : string; + public function getAdapter() : AdapterInterface; + public function getColumns() : array; + public function getFeatureSet() Feature\FeatureSet; + public function getResultSetPrototype() : ResultSetInterface; + public function getSql() | Sql\Sql; + public function select(Sql\Where|callable|string|array $where = null) : ResultSetInterface; + public function selectWith(Sql\Select $select) : ResultSetInterface; + public function insert(array $set) : int; + public function insertWith(Sql\Insert $insert) | int; + public function update( + array $set, + Sql\Where|callable|string|array $where = null, + array $joins = null + ) : int; + public function updateWith(Sql\Update $update) : int; + public function delete(Sql\Where|callable|string|array $where) : int; + public function deleteWith(Sql\Delete $delete) : int; + public function getLastInsertValue() : int; +} +``` + +The concrete `TableGateway` object uses constructor injection for getting +dependencies and options into the instance. The table name and an instance of +an `Adapter` are all that is required to create an instance. + +Out of the box, this implementation makes no assumptions about table structure +or metadata, and when `select()` is executed, a simple `ResultSet` object with +the populated `Adapter`'s `Result` (the datasource) will be returned and ready +for iteration. + +```php +use Zend\Db\TableGateway\TableGateway; + +$projectTable = new TableGateway('project', $adapter); +$rowset = $projectTable->select(['type' => 'PHP']); + +echo 'Projects of type PHP: ' . PHP_EOL; +foreach ($rowset as $projectRow) { + echo $projectRow['name'] . PHP_EOL; +} + +// Or, when expecting a single row: +$artistTable = new TableGateway('artist', $adapter); +$rowset = $artistTable->select(['id' => 2]); +$artistRow = $rowset->current(); + +var_dump($artistRow); +``` + +The `select()` method takes the same arguments as +`Zend\Db\Sql\Select::where()`; arguments will be passed to the `Select` +instance used to build the SELECT query. This means the following is possible: + +```php +use Zend\Db\TableGateway\TableGateway; +use Zend\Db\Sql\Select; + +$artistTable = new TableGateway('artist', $adapter); + +// Search for at most 2 artists who's name starts with Brit, ascending: +$rowset = $artistTable->select(function (Select $select) { + $select->where->like('name', 'Brit%'); + $select->order('name ASC')->limit(2); +}); +``` + +## TableGateway Features + +The Features API allows for extending the functionality of the base +`TableGateway` object without having to polymorphically extend the base class. +This allows for a wider array of possible mixing and matching of features to +achieve a particular behavior that needs to be attained to make the base +implementation of `TableGateway` useful for a particular problem. + +With the `TableGateway` object, features should be injected through the +constructor. The constructor can take features in 3 different forms: + +- as a single `Feature` instance +- as a `FeatureSet` instance +- as an array of `Feature` instances + +There are a number of features built-in and shipped with zend-db: + +- `GlobalAdapterFeature`: the ability to use a global/static adapter without + needing to inject it into a `TableGateway` instance. This is only useful when + you are extending the `AbstractTableGateway` implementation: + + ```php + use Zend\Db\TableGateway\AbstractTableGateway; + use Zend\Db\TableGateway\Feature; + + class MyTableGateway extends AbstractTableGateway + { + public function __construct() + { + $this->table = 'my_table'; + $this->featureSet = new Feature\FeatureSet(); + $this->featureSet->addFeature(new Feature\GlobalAdapterFeature()); + $this->initialize(); + } + } + + // elsewhere in code, in a bootstrap + Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter); + + // in a controller, or model somewhere + $table = new MyTableGateway(); // adapter is statically loaded + ``` + +- `MasterSlaveFeature`: the ability to use a master adapter for `insert()`, + `update()`, and `delete()`, but switch to a slave adapter for all `select()` + operations. + + ```php + $table = new TableGateway('artist', $adapter, new Feature\MasterSlaveFeature($slaveAdapter)); + ``` + +- `MetadataFeature`: the ability populate `TableGateway` with column + information from a `Metadata` object. It will also store the primary key + information in case the `RowGatewayFeature` needs to consume this information. + + ```php + $table = new TableGateway('artist', $adapter, new Feature\MetadataFeature()); + ``` + +- `EventFeature`: the ability to compose a + [zend-eventmanager](https://github.com/zendframework/zend-eventmanager) + `EventManager` instance within your `TableGateway` instance, and attach + listeners to the various events of its lifecycle. + + ```php + $table = new TableGateway('artist', $adapter, new Feature\EventFeature($eventManagerInstance)); + ``` + +- `RowGatewayFeature`: the ability for `select()` to return a `ResultSet` object that upon iteration + will return a `RowGateway` instance for each row. + + ```php + $table = new TableGateway('artist', $adapter, new Feature\RowGatewayFeature('id')); + $results = $table->select(['id' => 2]); + + $artistRow = $results->current(); + $artistRow->name = 'New Name'; + $artistRow->save(); + ``` diff --git a/bundled-libs/zendframework/zend-db/phpcs.xml b/bundled-libs/zendframework/zend-db/phpcs.xml new file mode 100644 index 00000000..e55dab38 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/phpcs.xml @@ -0,0 +1,11 @@ + + + + + */test/unit/Adapter/Driver/IbmDb2/StatementTest.php + + + + src + test + diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Adapter.php b/bundled-libs/zendframework/zend-db/src/Adapter/Adapter.php similarity index 73% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Adapter.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Adapter.php index 8a948b67..e356ff9a 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Adapter.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Adapter.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -67,10 +67,14 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface * @param Profiler\ProfilerInterface $profiler * @throws Exception\InvalidArgumentException */ - public function __construct($driver, Platform\PlatformInterface $platform = null, ResultSet\ResultSetInterface $queryResultPrototype = null, Profiler\ProfilerInterface $profiler = null) - { + public function __construct( + $driver, + Platform\PlatformInterface $platform = null, + ResultSet\ResultSetInterface $queryResultPrototype = null, + Profiler\ProfilerInterface $profiler = null + ) { // first argument can be an array of parameters - $parameters = array(); + $parameters = []; if (is_array($driver)) { $parameters = $driver; @@ -78,7 +82,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface $profiler = $this->createProfiler($parameters); } $driver = $this->createDriver($parameters); - } elseif (!$driver instanceof Driver\DriverInterface) { + } elseif (! $driver instanceof Driver\DriverInterface) { throw new Exception\InvalidArgumentException( 'The supplied or instantiated driver object does not implement Zend\Db\Adapter\Driver\DriverInterface' ); @@ -87,7 +91,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface $driver->checkEnvironment(); $this->driver = $driver; - if ($platform == null) { + if ($platform === null) { $platform = $this->createPlatform($parameters); } @@ -101,7 +105,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Adapter + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -128,7 +132,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; @@ -160,19 +164,27 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface * * @param string $sql * @param string|array|ParameterContainer $parametersOrQueryMode + * @param \Zend\Db\ResultSet\ResultSetInterface $resultPrototype * @throws Exception\InvalidArgumentException * @return Driver\StatementInterface|ResultSet\ResultSet */ - public function query($sql, $parametersOrQueryMode = self::QUERY_MODE_PREPARE) - { - if (is_string($parametersOrQueryMode) && in_array($parametersOrQueryMode, array(self::QUERY_MODE_PREPARE, self::QUERY_MODE_EXECUTE))) { + public function query( + $sql, + $parametersOrQueryMode = self::QUERY_MODE_PREPARE, + ResultSet\ResultSetInterface $resultPrototype = null + ) { + if (is_string($parametersOrQueryMode) + && in_array($parametersOrQueryMode, [self::QUERY_MODE_PREPARE, self::QUERY_MODE_EXECUTE]) + ) { $mode = $parametersOrQueryMode; $parameters = null; } elseif (is_array($parametersOrQueryMode) || $parametersOrQueryMode instanceof ParameterContainer) { $mode = self::QUERY_MODE_PREPARE; $parameters = $parametersOrQueryMode; } else { - throw new Exception\InvalidArgumentException('Parameter 2 to this method must be a flag, an array, or ParameterContainer'); + throw new Exception\InvalidArgumentException( + 'Parameter 2 to this method must be a flag, an array, or ParameterContainer' + ); } if ($mode == self::QUERY_MODE_PREPARE) { @@ -180,7 +192,11 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface $this->lastPreparedStatement = $this->driver->createStatement($sql); $this->lastPreparedStatement->prepare(); if (is_array($parameters) || $parameters instanceof ParameterContainer) { - $this->lastPreparedStatement->setParameterContainer((is_array($parameters)) ? new ParameterContainer($parameters) : $parameters); + if (is_array($parameters)) { + $this->lastPreparedStatement->setParameterContainer(new ParameterContainer($parameters)); + } else { + $this->lastPreparedStatement->setParameterContainer($parameters); + } $result = $this->lastPreparedStatement->execute(); } else { return $this->lastPreparedStatement; @@ -190,7 +206,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface } if ($result instanceof Driver\ResultInterface && $result->isQueryResult()) { - $resultSet = clone $this->queryResultSetPrototype; + $resultSet = clone ($resultPrototype ?: $this->queryResultSetPrototype); $resultSet->initialize($result); return $resultSet; } @@ -208,26 +224,32 @@ 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)) { - $initialParameters = new ParameterContainer((is_array($initialParameters) ? $initialParameters : array())); + if ($initialParameters === null + || ! $initialParameters instanceof ParameterContainer + && is_array($initialParameters) + ) { + $initialParameters = new ParameterContainer((is_array($initialParameters) ? $initialParameters : [])); } $statement->setParameterContainer($initialParameters); return $statement; } - public function getHelpers(/* $functions */) + public function getHelpers() { - $functions = array(); + $functions = []; $platform = $this->platform; foreach (func_get_args() as $arg) { switch ($arg) { case self::FUNCTION_QUOTE_IDENTIFIER: - $functions[] = function ($value) use ($platform) { return $platform->quoteIdentifier($value); }; + $functions[] = function ($value) use ($platform) { + return $platform->quoteIdentifier($value); + }; break; case self::FUNCTION_QUOTE_VALUE: - $functions[] = function ($value) use ($platform) { return $platform->quoteValue($value); }; + $functions[] = function ($value) use ($platform) { + return $platform->quoteValue($value); + }; break; - } } } @@ -247,7 +269,6 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface default: throw new Exception\InvalidArgumentException('Invalid magic property on adapter'); } - } /** @@ -258,19 +279,23 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface */ protected function createDriver($parameters) { - if (!isset($parameters['driver'])) { - throw new Exception\InvalidArgumentException(__FUNCTION__ . ' expects a "driver" key to be present inside the parameters'); + if (! isset($parameters['driver'])) { + throw new Exception\InvalidArgumentException( + __FUNCTION__ . ' expects a "driver" key to be present inside the parameters' + ); } if ($parameters['driver'] instanceof Driver\DriverInterface) { return $parameters['driver']; } - if (!is_string($parameters['driver'])) { - throw new Exception\InvalidArgumentException(__FUNCTION__ . ' expects a "driver" to be a string or instance of DriverInterface'); + if (! is_string($parameters['driver'])) { + throw new Exception\InvalidArgumentException( + __FUNCTION__ . ' expects a "driver" to be a string or instance of DriverInterface' + ); } - $options = array(); + $options = []; if (isset($parameters['options'])) { $options = (array) $parameters['options']; unset($parameters['options']); @@ -300,7 +325,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface } } - if (!isset($driver) || !$driver instanceof Driver\DriverInterface) { + if (! isset($driver) || ! $driver instanceof Driver\DriverInterface) { throw new Exception\InvalidArgumentException('DriverInterface expected', null, null); } @@ -308,39 +333,56 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface } /** - * @param Driver\DriverInterface $driver + * @param array $parameters * @return Platform\PlatformInterface */ - protected function createPlatform($parameters) + protected function createPlatform(array $parameters) { if (isset($parameters['platform'])) { $platformName = $parameters['platform']; } elseif ($this->driver instanceof Driver\DriverInterface) { $platformName = $this->driver->getDatabasePlatformName(Driver\DriverInterface::NAME_FORMAT_CAMELCASE); } else { - throw new Exception\InvalidArgumentException('A platform could not be determined from the provided configuration'); + throw new Exception\InvalidArgumentException( + 'A platform could not be determined from the provided configuration' + ); } // currently only supported by the IbmDb2 & Oracle concrete implementations - $options = (isset($parameters['platform_options'])) ? $parameters['platform_options'] : array(); + $options = (isset($parameters['platform_options'])) ? $parameters['platform_options'] : []; switch ($platformName) { case 'Mysql': // mysqli or pdo_mysql driver - $driver = ($this->driver instanceof Driver\Mysqli\Mysqli || $this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null; + if ($this->driver instanceof Driver\Mysqli\Mysqli || $this->driver instanceof Driver\Pdo\Pdo) { + $driver = $this->driver; + } else { + $driver = null; + } return new Platform\Mysql($driver); case 'SqlServer': // PDO is only supported driver for quoting values in this platform return new Platform\SqlServer(($this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null); case 'Oracle': - // oracle does not accept a driver as an option, no driver specific quoting available - return new Platform\Oracle($options); + if ($this->driver instanceof Driver\Oci8\Oci8 || $this->driver instanceof Driver\Pdo\Pdo) { + $driver = $this->driver; + } else { + $driver = null; + } + return new Platform\Oracle($options, $driver); case 'Sqlite': // PDO is only supported driver for quoting values in this platform - return new Platform\Sqlite(($this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null); + if ($this->driver instanceof Driver\Pdo\Pdo) { + return new Platform\Sqlite($this->driver); + } + return new Platform\Sqlite(null); case 'Postgresql': // pgsql or pdo postgres driver - $driver = ($this->driver instanceof Driver\Pgsql\Pgsql || $this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null; + if ($this->driver instanceof Driver\Pgsql\Pgsql || $this->driver instanceof Driver\Pdo\Pdo) { + $driver = $this->driver; + } else { + $driver = null; + } return new Platform\Postgresql($driver); case 'IbmDb2': // ibm_db2 driver escaping does not need an action connection @@ -350,6 +392,12 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface } } + /** + * + * @param array $parameters + * @return Profiler\ProfilerInterface + * @throws Exception\InvalidArgumentException + */ protected function createProfiler($parameters) { if ($parameters['profiler'] instanceof Profiler\ProfilerInterface) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAbstractServiceFactory.php b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterAbstractServiceFactory.php similarity index 50% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAbstractServiceFactory.php rename to bundled-libs/zendframework/zend-db/src/Adapter/AdapterAbstractServiceFactory.php index db99251f..314202fd 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAbstractServiceFactory.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterAbstractServiceFactory.php @@ -3,12 +3,13 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter; +use Interop\Container\ContainerInterface; use Zend\ServiceManager\AbstractFactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -27,14 +28,13 @@ class AdapterAbstractServiceFactory implements AbstractFactoryInterface /** * Can we create an adapter by the requested name? * - * @param ServiceLocatorInterface $services - * @param string $name + * @param ContainerInterface $container * @param string $requestedName * @return bool */ - public function canCreateServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) + public function canCreate(ContainerInterface $container, $requestedName) { - $config = $this->getConfig($services); + $config = $this->getConfig($container); if (empty($config)) { return false; } @@ -42,54 +42,80 @@ class AdapterAbstractServiceFactory implements AbstractFactoryInterface return ( isset($config[$requestedName]) && is_array($config[$requestedName]) - && !empty($config[$requestedName]) + && ! empty($config[$requestedName]) ); } + /** + * Determine if we can create a service with name (SM v2 compatibility) + * + * @param ServiceLocatorInterface $serviceLocator + * @param string $name + * @param string $requestedName + * @return bool + */ + public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) + { + return $this->canCreate($serviceLocator, $requestedName); + } + /** * Create a DB adapter * - * @param ServiceLocatorInterface $services - * @param string $name + * @param ContainerInterface $container * @param string $requestedName + * @param array $options * @return Adapter */ - public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $config = $this->getConfig($services); + $config = $this->getConfig($container); return new Adapter($config[$requestedName]); } + /** + * Create service with name + * + * @param ServiceLocatorInterface $serviceLocator + * @param string $name + * @param string $requestedName + * @return Adapter + */ + public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) + { + return $this($serviceLocator, $requestedName); + } + /** * Get db configuration, if any * - * @param ServiceLocatorInterface $services + * @param ContainerInterface $container * @return array */ - protected function getConfig(ServiceLocatorInterface $services) + protected function getConfig(ContainerInterface $container) { if ($this->config !== null) { return $this->config; } - if (!$services->has('Config')) { - $this->config = array(); + if (! $container->has('config')) { + $this->config = []; return $this->config; } - $config = $services->get('Config'); - if (!isset($config['db']) - || !is_array($config['db']) + $config = $container->get('config'); + if (! isset($config['db']) + || ! is_array($config['db']) ) { - $this->config = array(); + $this->config = []; return $this->config; } $config = $config['db']; - if (!isset($config['adapters']) - || !is_array($config['adapters']) + if (! isset($config['adapters']) + || ! is_array($config['adapters']) ) { - $this->config = array(); + $this->config = []; return $this->config; } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterAwareInterface.php similarity index 88% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/AdapterAwareInterface.php index 92cbbe39..8df8ca62 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterAwareInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareTrait.php b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterAwareTrait.php similarity index 83% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareTrait.php rename to bundled-libs/zendframework/zend-db/src/Adapter/AdapterAwareTrait.php index b0d9c497..509817a6 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareTrait.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterAwareTrait.php @@ -3,14 +3,12 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter; -use Zend\Db\Adapter\Adapter; - trait AdapterAwareTrait { /** @@ -22,7 +20,7 @@ trait AdapterAwareTrait * Set db adapter * * @param Adapter $adapter - * @return mixed + * @return self Provides a fluent interface */ public function setDbAdapter(Adapter $adapter) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterInterface.php similarity index 90% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/AdapterInterface.php index 1af603e1..692ac56e 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/AdapterInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -25,5 +25,4 @@ interface AdapterInterface * @return Platform\PlatformInterface */ public function getPlatform(); - } diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/AdapterServiceFactory.php b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterServiceFactory.php new file mode 100644 index 00000000..b57e7538 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/AdapterServiceFactory.php @@ -0,0 +1,42 @@ +get('config'); + return new Adapter($config['db']); + } + + /** + * Create db adapter service (v2) + * + * @param ServiceLocatorInterface $container + * @return Adapter + */ + public function createService(ServiceLocatorInterface $container) + { + return $this($container, Adapter::class); + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Driver/AbstractConnection.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/AbstractConnection.php new file mode 100644 index 00000000..98f3a89e --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/AbstractConnection.php @@ -0,0 +1,135 @@ +isConnected()) { + $this->resource = null; + } + + return $this; + } + + /** + * Get connection parameters + * + * @return array + */ + public function getConnectionParameters() + { + return $this->connectionParameters; + } + + /** + * Get driver name + * + * @return null|string + */ + public function getDriverName() + { + return $this->driverName; + } + + /** + * @return null|ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * {@inheritDoc} + * + * @return resource + */ + public function getResource() + { + if (! $this->isConnected()) { + $this->connect(); + } + + return $this->resource; + } + + /** + * Checks whether the connection is in transaction state. + * + * @return boolean + */ + public function inTransaction() + { + return $this->inTransaction; + } + + /** + * @param array $connectionParameters + * @return self Provides a fluent interface + */ + public function setConnectionParameters(array $connectionParameters) + { + $this->connectionParameters = $connectionParameters; + + return $this; + } + + /** + * {@inheritDoc} + * + * @return self Provides a fluent interface + */ + public function setProfiler(ProfilerInterface $profiler) + { + $this->profiler = $profiler; + + return $this; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/ConnectionInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/ConnectionInterface.php similarity index 95% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/ConnectionInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/ConnectionInterface.php index 1beb4fb2..847d6773 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/ConnectionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/ConnectionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/DriverInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/DriverInterface.php similarity index 95% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/DriverInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/DriverInterface.php index 98d6b3ad..615dbb72 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/DriverInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/DriverInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -57,7 +57,7 @@ interface DriverInterface /** * Get prepare type * - * @return array + * @return string */ public function getPrepareType(); diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/AbstractFeature.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Feature/AbstractFeature.php similarity index 91% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/AbstractFeature.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Feature/AbstractFeature.php index 82529234..d919ac8b 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/AbstractFeature.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Feature/AbstractFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,7 +13,6 @@ use Zend\Db\Adapter\Driver\DriverInterface; abstract class AbstractFeature { - /** * @var DriverInterface */ @@ -36,5 +35,4 @@ abstract class AbstractFeature * @return string */ abstract public function getName(); - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/DriverFeatureInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Feature/DriverFeatureInterface.php similarity index 92% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/DriverFeatureInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Feature/DriverFeatureInterface.php index 5e2146f4..6437c3af 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/DriverFeatureInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Feature/DriverFeatureInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Connection.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Connection.php similarity index 51% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Connection.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Connection.php index ab99d05d..8c7a68bd 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Connection.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Connection.php @@ -3,40 +3,40 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\IbmDb2; -use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Driver\AbstractConnection; use Zend\Db\Adapter\Exception; -use Zend\Db\Adapter\Profiler; -class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +class Connection extends AbstractConnection { - /** @var IbmDb2 */ + /** + * @var IbmDb2 + */ protected $driver = null; /** - * @var array + * i5 OS + * + * @var bool */ - protected $connectionParameters = null; + protected $i5; /** - * @var resource + * Previous autocommit set + * + * @var mixed */ - protected $resource = null; - - /** - * @var Profiler\ProfilerInterface - */ - protected $profiler = null; + protected $prevAutocommit; /** * Constructor * - * @param array|resource|null $connectionParameters (ibm_db2 connection resource) + * @param array|resource|null $connectionParameters (ibm_db2 connection resource) * @throws Exception\InvalidArgumentException */ public function __construct($connectionParameters = null) @@ -55,93 +55,46 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface /** * Set driver * - * @param IbmDb2 $driver - * @return Connection + * @param IbmDb2 $driver + * @return self Provides a fluent interface */ public function setDriver(IbmDb2 $driver) { $this->driver = $driver; + return $this; } - /** - * @param Profiler\ProfilerInterface $profiler - * @return Connection - */ - public function setProfiler(Profiler\ProfilerInterface $profiler) - { - $this->profiler = $profiler; - return $this; - } - - /** - * @return null|Profiler\ProfilerInterface - */ - public function getProfiler() - { - return $this->profiler; - } - - /** - * @param array $connectionParameters - * @return Connection - */ - public function setConnectionParameters(array $connectionParameters) - { - $this->connectionParameters = $connectionParameters; - return $this; - } - - /** - * @return array - */ - public function getConnectionParameters() - { - return $this->connectionParameters; - } - /** * @param resource $resource DB2 resource - * @return Connection + * @return self Provides a fluent interface */ public function setResource($resource) { - if (!is_resource($resource) || get_resource_type($resource) !== 'DB2 Connection') { + if (! is_resource($resource) || get_resource_type($resource) !== 'DB2 Connection') { throw new Exception\InvalidArgumentException('The resource provided must be of type "DB2 Connection"'); } $this->resource = $resource; + return $this; } /** - * Get current schema - * - * @return string + * {@inheritDoc} */ public function getCurrentSchema() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } $info = db2_server_info($this->resource); + return (isset($info->DB_NAME) ? $info->DB_NAME : ''); } /** - * Get resource - * - * @return mixed - */ - public function getResource() - { - return $this->resource; - } - - /** - * Connect - * - * @return ConnectionInterface + * {@inheritDoc} */ public function connect() { @@ -153,27 +106,24 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface $p = $this->connectionParameters; // given a list of key names, test for existence in $p - $findParameterValue = function(array $names) use ($p) { + $findParameterValue = function (array $names) use ($p) { foreach ($names as $name) { if (isset($p[$name])) { return $p[$name]; } } - return null; + + return; }; - $connection = array(); - $connection['database'] = $findParameterValue(array('database', 'db')); - $connection['username'] = $findParameterValue(array('username', 'uid', 'UID')); - $connection['password'] = $findParameterValue(array('password', 'pwd', 'PWD')); - $connection['options'] = (isset($p['driver_options']) ? $p['driver_options'] : array()); + $database = $findParameterValue(['database', 'db']); + $username = $findParameterValue(['username', 'uid', 'UID']); + $password = $findParameterValue(['password', 'pwd', 'PWD']); + $isPersistent = $findParameterValue(['persistent', 'PERSISTENT', 'Persistent']); + $options = (isset($p['driver_options']) ? $p['driver_options'] : []); + $connect = ((bool) $isPersistent) ? 'db2_pconnect' : 'db2_connect'; - $this->resource = db2_connect( - $connection['database'], - $connection['username'], - $connection['password'], - $connection['options'] - ); + $this->resource = $connect($database, $username, $password, $options); if ($this->resource === false) { throw new Exception\RuntimeException(sprintf( @@ -181,13 +131,12 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface __METHOD__ )); } + return $this; } /** - * Is connected - * - * @return bool + * {@inheritDoc} */ public function isConnected() { @@ -195,9 +144,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Disconnect - * - * @return ConnectionInterface + * {@inheritDoc} */ public function disconnect() { @@ -205,48 +152,89 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface db2_close($this->resource); $this->resource = null; } + return $this; } /** - * Begin transaction - * - * @return ConnectionInterface + * {@inheritDoc} */ public function beginTransaction() { - // TODO: Implement beginTransaction() method. + if ($this->isI5() && ! ini_get('ibm_db2.i5_allow_commit')) { + throw new Exception\RuntimeException( + 'DB2 transactions are not enabled, you need to set the ibm_db2.i5_allow_commit=1 in your php.ini' + ); + } + + if (! $this->isConnected()) { + $this->connect(); + } + + $this->prevAutocommit = db2_autocommit($this->resource); + db2_autocommit($this->resource, DB2_AUTOCOMMIT_OFF); + $this->inTransaction = true; + + return $this; } /** - * Commit - * - * @return ConnectionInterface + * {@inheritDoc} */ public function commit() { - // TODO: Implement commit() method. + if (! $this->isConnected()) { + $this->connect(); + } + + if (! db2_commit($this->resource)) { + throw new Exception\RuntimeException("The commit has not been successful"); + } + + if ($this->prevAutocommit) { + db2_autocommit($this->resource, $this->prevAutocommit); + } + + $this->inTransaction = false; + + return $this; } /** * Rollback * - * @return ConnectionInterface + * @return self Provides a fluent interface + * @throws Exception\RuntimeException */ public function rollback() { - // TODO: Implement rollback() method. + if (! $this->isConnected()) { + throw new Exception\RuntimeException('Must be connected before you can rollback.'); + } + + if (! $this->inTransaction()) { + throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback.'); + } + + if (! db2_rollback($this->resource)) { + throw new Exception\RuntimeException('The rollback has not been successful'); + } + + if ($this->prevAutocommit) { + db2_autocommit($this->resource, $this->prevAutocommit); + } + + $this->inTransaction = false; + + return $this; } /** - * Execute - * - * @param string $sql - * @return Result + * {@inheritDoc} */ public function execute($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } @@ -254,7 +242,8 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface $this->profiler->profilerStart($sql); } - set_error_handler(function () {}, E_WARNING); // suppress warnings + set_error_handler(function () { + }, E_WARNING); // suppress warnings $resultResource = db2_exec($this->resource, $sql); restore_error_handler(); @@ -267,18 +256,30 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface throw new Exception\InvalidQueryException(db2_stmt_errormsg()); } - $resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource); - return $resultPrototype; + return $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource); } /** - * Get last generated id - * - * @param null $name Ignored - * @return int + * {@inheritDoc} */ public function getLastGeneratedValue($name = null) { return db2_last_insert_id($this->resource); } + + /** + * Determine if the OS is OS400 (AS400, IBM i) + * + * @return bool + */ + protected function isI5() + { + if (isset($this->i5)) { + return $this->i5; + } + + $this->i5 = (php_uname('s') == 'OS400'); + + return $this->i5; + } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/IbmDb2.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/IbmDb2.php similarity index 92% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/IbmDb2.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/IbmDb2.php index fab7c5b7..11a064cc 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/IbmDb2.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/IbmDb2.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -38,7 +38,7 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface */ public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null) { - if (!$connection instanceof Connection) { + if (! $connection instanceof Connection) { $connection = new Connection($connection); } @@ -49,7 +49,7 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return IbmDb2 + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -73,7 +73,7 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface /** * @param Connection $connection - * @return IbmDb2 + * @return self Provides a fluent interface */ public function registerConnection(Connection $connection) { @@ -84,7 +84,7 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface /** * @param Statement $statementPrototype - * @return IbmDb2 + * @return self Provides a fluent interface */ public function registerStatementPrototype(Statement $statementPrototype) { @@ -95,7 +95,7 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface /** * @param Result $resultPrototype - * @return IbmDb2 + * @return self Provides a fluent interface */ public function registerResultPrototype(Result $resultPrototype) { @@ -125,7 +125,7 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface */ public function checkEnvironment() { - if (!extension_loaded('ibm_db2')) { + if (! extension_loaded('ibm_db2')) { throw new Exception\RuntimeException('The ibm_db2 extension is required by this driver.'); } } @@ -156,10 +156,10 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface $statement->setSql($sqlOrResource); } elseif ($sqlOrResource !== null) { throw new Exception\InvalidArgumentException( - __FUNCTION__ . ' only accepts an SQL string or a ibm_db2 resource' + __FUNCTION__ . ' only accepts an SQL string or an ibm_db2 resource' ); } - if (!$this->connection->isConnected()) { + if (! $this->connection->isConnected()) { $this->connection->connect(); } $statement->initialize($this->connection->getResource()); @@ -183,7 +183,7 @@ class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface /** * Get prepare type * - * @return array + * @return string */ public function getPrepareType() { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Result.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Result.php similarity index 96% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Result.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Result.php index 711917c5..2c8c900f 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Result.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Result.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -42,7 +42,7 @@ class Result implements ResultInterface /** * @param resource $resource * @param mixed $generatedValue - * @return Result + * @return self Provides a fluent interface */ public function initialize($resource, $generatedValue = null) { @@ -119,7 +119,7 @@ class Result implements ResultInterface */ public function buffer() { - return null; + return; } /** @@ -187,6 +187,6 @@ class Result implements ResultInterface */ public function count() { - return null; + return; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Statement.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Statement.php similarity index 71% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Statement.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Statement.php index 362f7a88..a3b213d2 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Statement.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/IbmDb2/Statement.php @@ -3,12 +3,13 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\IbmDb2; +use ErrorException; use Zend\Db\Adapter\Driver\StatementInterface; use Zend\Db\Adapter\Exception; use Zend\Db\Adapter\ParameterContainer; @@ -53,7 +54,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param $resource - * @return Statement + * @return self Provides a fluent interface */ public function initialize($resource) { @@ -63,7 +64,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param IbmDb2 $driver - * @return Statement + * @return self Provides a fluent interface */ public function setDriver(IbmDb2 $driver) { @@ -73,7 +74,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Statement + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -93,7 +94,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set sql * * @param $sql - * @return mixed + * @return self Provides a fluent interface */ public function setSql($sql) { @@ -115,7 +116,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set parameter container * * @param ParameterContainer $parameterContainer - * @return mixed + * @return self Provides a fluent interface */ public function setParameterContainer(ParameterContainer $parameterContainer) { @@ -159,7 +160,8 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Prepare sql * * @param string|null $sql - * @return Statement + * @return self Provides a fluent interface + * @throws Exception\RuntimeException */ public function prepare($sql = null) { @@ -167,11 +169,18 @@ 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; } - $this->resource = db2_prepare($this->db2, $sql); + try { + set_error_handler($this->createErrorHandler()); + $this->resource = db2_prepare($this->db2, $sql); + } catch (ErrorException $e) { + throw new Exception\RuntimeException($e->getMessage() . '. ' . db2_stmt_errormsg(), db2_stmt_error(), $e); + } finally { + restore_error_handler(); + } if ($this->resource === false) { throw new Exception\RuntimeException(db2_stmt_errormsg(), db2_stmt_error()); @@ -194,17 +203,17 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * Execute * - * @param null $parameters + * @param null|array|ParameterContainer $parameters * @return Result */ public function execute($parameters = null) { - if (!$this->isPrepared) { + if (! $this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ - if (!$this->parameterContainer instanceof ParameterContainer) { + if (! $this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; @@ -222,7 +231,8 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface $this->profiler->profilerStart($this); } - set_error_handler(function () {}, E_WARNING); // suppress warnings + set_error_handler(function () { + }, E_WARNING); // suppress warnings $response = db2_execute($this->resource, $this->parameterContainer->getPositionalArray()); restore_error_handler(); @@ -237,4 +247,31 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface $result = $this->driver->createResult($this->resource); return $result; } + + /** + * Creates and returns a callable error handler that raises exceptions. + * + * Only raises exceptions for errors that are within the error_reporting mask. + * + * @return callable + */ + private function createErrorHandler() + { + /** + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + * @return void + * @throws ErrorException if error is not within the error_reporting mask. + */ + return function ($errno, $errstr, $errfile, $errline) { + if (! (error_reporting() & $errno)) { + // error_reporting does not include this error + return; + } + + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }; + } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Connection.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Connection.php similarity index 60% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Connection.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Connection.php index 190000de..c94e0096 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Connection.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Connection.php @@ -3,48 +3,28 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\Mysqli; -use Zend\Db\Adapter\Driver\ConnectionInterface; +use Exception as GenericException; +use Zend\Db\Adapter\Driver\AbstractConnection; use Zend\Db\Adapter\Exception; -use Zend\Db\Adapter\Profiler; -class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +class Connection extends AbstractConnection { - /** * @var Mysqli */ protected $driver = null; - /** - * @var Profiler\ProfilerInterface - */ - protected $profiler = null; - - /** - * Connection parameters - * - * @var array - */ - protected $connectionParameters = array(); - /** * @var \mysqli */ protected $resource = null; - /** - * In transaction - * - * @var bool - */ - protected $inTransaction = false; - /** * Constructor * @@ -58,74 +38,35 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } elseif ($connectionInfo instanceof \mysqli) { $this->setResource($connectionInfo); } elseif (null !== $connectionInfo) { - throw new Exception\InvalidArgumentException('$connection must be an array of parameters, a mysqli object or null'); + throw new Exception\InvalidArgumentException( + '$connection must be an array of parameters, a mysqli object or null' + ); } } /** - * @param Mysqli $driver - * @return Connection + * @param Mysqli $driver + * @return self Provides a fluent interface */ public function setDriver(Mysqli $driver) { $this->driver = $driver; + return $this; } /** - * @param Profiler\ProfilerInterface $profiler - * @return Connection - */ - public function setProfiler(Profiler\ProfilerInterface $profiler) - { - $this->profiler = $profiler; - return $this; - } - - /** - * @return null|Profiler\ProfilerInterface - */ - public function getProfiler() - { - return $this->profiler; - } - - /** - * Set connection parameters - * - * @param array $connectionParameters - * @return Connection - */ - public function setConnectionParameters(array $connectionParameters) - { - $this->connectionParameters = $connectionParameters; - return $this; - } - - /** - * Get connection parameters - * - * @return array - */ - public function getConnectionParameters() - { - return $this->connectionParameters; - } - - /** - * Get current schema - * - * @return string + * {@inheritDoc} */ public function getCurrentSchema() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } - /** @var $result \mysqli_result */ $result = $this->resource->query('SELECT DATABASE()'); $r = $result->fetch_row(); + return $r[0]; } @@ -133,30 +74,17 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface * Set resource * * @param \mysqli $resource - * @return Connection + * @return self Provides a fluent interface */ public function setResource(\mysqli $resource) { $this->resource = $resource; + return $this; } /** - * Get resource - * - * @return \mysqli - */ - public function getResource() - { - $this->connect(); - return $this->resource; - } - - /** - * Connect - * - * @throws Exception\RuntimeException - * @return Connection + * {@inheritDoc} */ public function connect() { @@ -174,24 +102,32 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface return $p[$name]; } } + return; }; - $hostname = $findParameterValue(array('hostname', 'host')); - $username = $findParameterValue(array('username', 'user')); - $password = $findParameterValue(array('password', 'passwd', 'pw')); - $database = $findParameterValue(array('database', 'dbname', 'db', 'schema')); + $hostname = $findParameterValue(['hostname', 'host']); + $username = $findParameterValue(['username', 'user']); + $password = $findParameterValue(['password', 'passwd', 'pw']); + $database = $findParameterValue(['database', 'dbname', 'db', 'schema']); $port = (isset($p['port'])) ? (int) $p['port'] : null; $socket = (isset($p['socket'])) ? $p['socket'] : null; + $useSSL = (isset($p['use_ssl'])) ? $p['use_ssl'] : 0; + $clientKey = (isset($p['client_key'])) ? $p['client_key'] : null; + $clientCert = (isset($p['client_cert'])) ? $p['client_cert'] : null; + $caCert = (isset($p['ca_cert'])) ? $p['ca_cert'] : null; + $caPath = (isset($p['ca_path'])) ? $p['ca_path'] : null; + $cipher = (isset($p['cipher'])) ? $p['cipher'] : null; + $this->resource = new \mysqli(); $this->resource->init(); - if (!empty($p['driver_options'])) { + if (! empty($p['driver_options'])) { foreach ($p['driver_options'] as $option => $value) { if (is_string($option)) { $option = strtoupper($option); - if (!defined($option)) { + if (! defined($option)) { continue; } $option = constant($option); @@ -200,7 +136,28 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } } - $this->resource->real_connect($hostname, $username, $password, $database, $port, $socket); + $flags = null; + + if ($useSSL && ! $socket) { + $this->resource->ssl_set($clientKey, $clientCert, $caCert, $caPath, $cipher); + //MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT is not valid option, needs to be set as flag + if (isset($p['driver_options']) + && isset($p['driver_options'][MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT]) + ) { + $flags = MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; + } + } + + + try { + $this->resource->real_connect($hostname, $username, $password, $database, $port, $socket, $flags); + } catch (GenericException $e) { + throw new Exception\RuntimeException( + 'Connection error', + null, + new Exception\ErrorException($this->resource->connect_error, $this->resource->connect_errno) + ); + } if ($this->resource->connect_error) { throw new Exception\RuntimeException( @@ -210,7 +167,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface ); } - if (!empty($p['charset'])) { + if (! empty($p['charset'])) { $this->resource->set_charset($p['charset']); } @@ -218,9 +175,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Is connected - * - * @return bool + * {@inheritDoc} */ public function isConnected() { @@ -228,80 +183,75 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Disconnect - * - * @return void + * {@inheritDoc} */ public function disconnect() { if ($this->resource instanceof \mysqli) { $this->resource->close(); } - unset($this->resource); + $this->resource = null; } /** - * Begin transaction - * - * @return void + * {@inheritDoc} */ public function beginTransaction() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } $this->resource->autocommit(false); $this->inTransaction = true; + + return $this; } /** - * Commit - * - * @return void + * {@inheritDoc} */ public function commit() { - if (!$this->resource) { + if (! $this->isConnected()) { $this->connect(); } $this->resource->commit(); $this->inTransaction = false; $this->resource->autocommit(true); - } - /** - * Rollback - * - * @throws Exception\RuntimeException - * @return Connection - */ - public function rollback() - { - if (!$this->resource) { - throw new Exception\RuntimeException('Must be connected before you can rollback.'); - } - - if (!$this->inTransaction) { - throw new Exception\RuntimeException('Must call commit() before you can rollback.'); - } - - $this->resource->rollback(); - $this->resource->autocommit(true); return $this; } /** - * Execute + * {@inheritDoc} + */ + public function rollback() + { + if (! $this->isConnected()) { + throw new Exception\RuntimeException('Must be connected before you can rollback.'); + } + + if (! $this->inTransaction) { + throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback.'); + } + + $this->resource->rollback(); + $this->resource->autocommit(true); + $this->inTransaction = false; + + return $this; + } + + /** + * {@inheritDoc} * - * @param string $sql * @throws Exception\InvalidQueryException - * @return Result */ public function execute($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } @@ -321,14 +271,12 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } $resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource); + return $resultPrototype; } /** - * Get last generated id - * - * @param null $name Ignored - * @return int + * {@inheritDoc} */ public function getLastGeneratedValue($name = null) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Mysqli.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Mysqli.php similarity index 89% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Mysqli.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Mysqli.php index 4199d600..c1f3da51 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Mysqli.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Mysqli.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,7 +16,6 @@ use Zend\Db\Adapter\Profiler; class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface { - /** * @var Connection */ @@ -40,9 +39,9 @@ class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface /** * @var array */ - protected $options = array( + protected $options = [ 'buffer_results' => false - ); + ]; /** * Constructor @@ -52,9 +51,13 @@ class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface * @param null|Result $resultPrototype * @param array $options */ - public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, array $options = array()) - { - if (!$connection instanceof Connection) { + public function __construct( + $connection, + Statement $statementPrototype = null, + Result $resultPrototype = null, + array $options = [] + ) { + if (! $connection instanceof Connection) { $connection = new Connection($connection); } @@ -67,7 +70,7 @@ class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Mysqli + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -93,7 +96,7 @@ class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface * Register connection * * @param Connection $connection - * @return Mysqli + * @return self Provides a fluent interface */ public function registerConnection(Connection $connection) { @@ -164,8 +167,10 @@ class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface */ public function checkEnvironment() { - if (!extension_loaded('mysqli')) { - throw new Exception\RuntimeException('The Mysqli extension is required for this adapter but the extension is not loaded'); + if (! extension_loaded('mysqli')) { + throw new Exception\RuntimeException( + 'The Mysqli extension is required for this adapter but the extension is not loaded' + ); } } @@ -201,7 +206,7 @@ class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface if (is_string($sqlOrResource)) { $statement->setSql($sqlOrResource); } - if (!$this->connection->isConnected()) { + if (! $this->connection->isConnected()) { $this->connection->connect(); } $statement->initialize($this->connection->getResource()); @@ -226,7 +231,7 @@ class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface /** * Get prepare type * - * @return array + * @return string */ public function getPrepareType() { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Result.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Result.php similarity index 90% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Result.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Result.php index d0ec8191..eb388eeb 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Result.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Result.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -17,7 +17,6 @@ class Result implements Iterator, ResultInterface { - /** * @var \mysqli|\mysqli_result|\mysqli_stmt */ @@ -52,15 +51,15 @@ class Result implements protected $nextComplete = false; /** - * @var bool + * @var mixed */ - protected $currentData = false; + protected $currentData = null; /** * * @var array */ - protected $statementBindValues = array('keys' => null, 'values' => array()); + protected $statementBindValues = ['keys' => null, 'values' => []]; /** * @var mixed @@ -73,12 +72,15 @@ class Result implements * @param mixed $resource * @param mixed $generatedValue * @param bool|null $isBuffered + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException - * @return Result */ public function initialize($resource, $generatedValue, $isBuffered = null) { - if (!$resource instanceof \mysqli && !$resource instanceof \mysqli_result && !$resource instanceof \mysqli_stmt) { + if (! $resource instanceof \mysqli + && ! $resource instanceof \mysqli_result + && ! $resource instanceof \mysqli_stmt + ) { throw new Exception\InvalidArgumentException('Invalid resource provided.'); } @@ -188,24 +190,23 @@ class Result implements */ protected function loadDataFromMysqliStatement() { - $data = null; // build the default reference based bind structure, if it does not already exist if ($this->statementBindValues['keys'] === null) { - $this->statementBindValues['keys'] = array(); + $this->statementBindValues['keys'] = []; $resultResource = $this->resource->result_metadata(); foreach ($resultResource->fetch_fields() as $col) { $this->statementBindValues['keys'][] = $col->name; } $this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null); - $refs = array(); + $refs = []; foreach ($this->statementBindValues['values'] as $i => &$f) { $refs[$i] = &$f; } - call_user_func_array(array($this->resource, 'bind_result'), $this->statementBindValues['values']); + call_user_func_array([$this->resource, 'bind_result'], $this->statementBindValues['values']); } if (($r = $this->resource->fetch()) === null) { - if (!$this->isBuffered) { + if (! $this->isBuffered) { $this->resource->close(); } return false; @@ -278,11 +279,10 @@ class Result implements */ public function rewind() { - if ($this->position !== 0) { - if ($this->isBuffered === false) { - throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations'); - } + if (0 !== $this->position && false === $this->isBuffered) { + throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations'); } + $this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt $this->currentComplete = false; $this->position = 0; diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Statement.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Statement.php similarity index 89% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Statement.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Statement.php index 2ca9f430..140d4aac 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Statement.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Mysqli/Statement.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,7 +16,6 @@ use Zend\Db\Adapter\Profiler; class Statement implements StatementInterface, Profiler\ProfilerAwareInterface { - /** * @var \mysqli */ @@ -73,7 +72,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set driver * * @param Mysqli $driver - * @return Statement + * @return self Provides a fluent interface */ public function setDriver(Mysqli $driver) { @@ -83,7 +82,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Statement + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -103,7 +102,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Initialize * * @param \mysqli $mysqli - * @return Statement + * @return self Provides a fluent interface */ public function initialize(\mysqli $mysqli) { @@ -115,7 +114,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set sql * * @param string $sql - * @return Statement + * @return self Provides a fluent interface */ public function setSql($sql) { @@ -127,7 +126,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set Parameter container * * @param ParameterContainer $parameterContainer - * @return Statement + * @return self Provides a fluent interface */ public function setParameterContainer(ParameterContainer $parameterContainer) { @@ -149,7 +148,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set resource * * @param \mysqli_stmt $mysqliStatement - * @return Statement + * @return self Provides a fluent interface */ public function setResource(\mysqli_stmt $mysqliStatement) { @@ -192,9 +191,9 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Prepare * * @param string $sql + * @return self Provides a fluent interface * @throws Exception\InvalidQueryException * @throws Exception\RuntimeException - * @return Statement */ public function prepare($sql = null) { @@ -204,8 +203,8 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface $sql = ($sql) ?: $this->sql; - $this->resource = $this->mysqli->prepare($this->sql); - if (!$this->resource instanceof \mysqli_stmt) { + $this->resource = $this->mysqli->prepare($sql); + if (! $this->resource instanceof \mysqli_stmt) { throw new Exception\InvalidQueryException( 'Statement couldn\'t be produced with sql: ' . $sql, null, @@ -220,18 +219,18 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * Execute * - * @param ParameterContainer|array $parameters + * @param null|array|ParameterContainer $parameters * @throws Exception\RuntimeException * @return mixed */ public function execute($parameters = null) { - if (!$this->isPrepared) { + if (! $this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ - if (!$this->parameterContainer instanceof ParameterContainer) { + if (! $this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; @@ -284,7 +283,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface { $parameters = $this->parameterContainer->getNamedArray(); $type = ''; - $args = array(); + $args = []; foreach ($parameters as $name => &$value) { if ($this->parameterContainer->offsetHasErrata($name)) { @@ -310,7 +309,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface if ($args) { array_unshift($args, $type); - call_user_func_array(array($this->resource, 'bind_param'), $args); + call_user_func_array([$this->resource, 'bind_param'], $args); } } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Connection.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Connection.php similarity index 59% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Connection.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Connection.php index 6ff5817e..761a2a6c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Connection.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Connection.php @@ -3,51 +3,26 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\Oci8; -use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Driver\AbstractConnection; use Zend\Db\Adapter\Exception; -use Zend\Db\Adapter\Profiler; -class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +class Connection extends AbstractConnection { /** * @var Oci8 */ protected $driver = null; - /** - * @var Profiler\ProfilerInterface - */ - protected $profiler = null; - - /** - * Connection parameters - * - * @var array - */ - protected $connectionParameters = array(); - - /** - * @var - */ - protected $resource = null; - - /** - * In transaction - * - * @var bool - */ - protected $inTransaction = false; - /** * Constructor * - * @param array|resource|null $connectionInfo + * @param array|resource|null $connectionInfo * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException */ public function __construct($connectionInfo = null) @@ -57,68 +32,29 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } elseif ($connectionInfo instanceof \oci8) { $this->setResource($connectionInfo); } elseif (null !== $connectionInfo) { - throw new Exception\InvalidArgumentException('$connection must be an array of parameters, a oci8 resource or null'); + throw new Exception\InvalidArgumentException( + '$connection must be an array of parameters, an oci8 resource or null' + ); } } /** - * @param Oci8 $driver - * @return Connection + * @param Oci8 $driver + * @return self Provides a fluent interface */ public function setDriver(Oci8 $driver) { $this->driver = $driver; + return $this; } /** - * @param Profiler\ProfilerInterface $profiler - * @return Connection - */ - public function setProfiler(Profiler\ProfilerInterface $profiler) - { - $this->profiler = $profiler; - return $this; - } - - /** - * @return null|Profiler\ProfilerInterface - */ - public function getProfiler() - { - return $this->profiler; - } - - /** - * Set connection parameters - * - * @param array $connectionParameters - * @return Connection - */ - public function setConnectionParameters(array $connectionParameters) - { - $this->connectionParameters = $connectionParameters; - return $this; - } - - /** - * Get connection parameters - * - * @return array - */ - public function getConnectionParameters() - { - return $this->connectionParameters; - } - - /** - * Get current schema - * - * @return string + * {@inheritDoc} */ public function getCurrentSchema() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } @@ -126,6 +62,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface $stmt = oci_parse($this->resource, $query); oci_execute($stmt); $dbNameArray = oci_fetch_array($stmt, OCI_ASSOC); + return $dbNameArray['current_schema']; } @@ -133,32 +70,20 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface * Set resource * * @param resource $resource - * @return Connection + * @return self Provides a fluent interface */ public function setResource($resource) { - if (!is_resource($resource) || get_resource_type($resource) !== 'oci8 connection') { + if (! is_resource($resource) || get_resource_type($resource) !== 'oci8 connection') { throw new Exception\InvalidArgumentException('A resource of type "oci8 connection" was expected'); } $this->resource = $resource; + return $this; } /** - * Get resource - * - * @return \oci8 - */ - public function getResource() - { - $this->connect(); - return $this->resource; - } - - /** - * Connect - * - * @return Connection + * {@inheritDoc} */ public function connect() { @@ -170,34 +95,42 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface $p = $this->connectionParameters; // given a list of key names, test for existence in $p - $findParameterValue = function(array $names) use ($p) { + $findParameterValue = function (array $names) use ($p) { foreach ($names as $name) { if (isset($p[$name])) { return $p[$name]; } } - return null; + + return; }; // http://www.php.net/manual/en/function.oci-connect.php - $username = $findParameterValue(array('username')); - $password = $findParameterValue(array('password')); - $connectionString = $findParameterValue(array('connection_string', 'connectionstring', 'connection', 'hostname', 'instance')); - $characterSet = $findParameterValue(array('character_set', 'charset', 'encoding')); + $username = $findParameterValue(['username']); + $password = $findParameterValue(['password']); + $connectionString = $findParameterValue([ + 'connection_string', + 'connectionstring', + 'connection', + 'hostname', + 'instance' + ]); + $characterSet = $findParameterValue(['character_set', 'charset', 'encoding']); + $sessionMode = $findParameterValue(['session_mode']); // connection modifiers - $isUnique = $findParameterValue(array('unique')); - $isPersistent = $findParameterValue(array('persistent')); + $isUnique = $findParameterValue(['unique']); + $isPersistent = $findParameterValue(['persistent']); if ($isUnique == true) { - $this->resource = oci_new_connect($username, $password, $connectionString, $characterSet); + $this->resource = oci_new_connect($username, $password, $connectionString, $characterSet, $sessionMode); } elseif ($isPersistent == true) { - $this->resource = oci_pconnect($username, $password, $connectionString, $characterSet); + $this->resource = oci_pconnect($username, $password, $connectionString, $characterSet, $sessionMode); } else { - $this->resource = oci_connect($username, $password, $connectionString, $characterSet); + $this->resource = oci_connect($username, $password, $connectionString, $characterSet, $sessionMode); } - if (!$this->resource) { + if (! $this->resource) { $e = oci_error(); throw new Exception\RuntimeException( 'Connection error', @@ -210,9 +143,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Is connected - * - * @return bool + * {@inheritDoc} */ public function isConnected() { @@ -220,7 +151,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Disconnect + * {@inheritDoc} */ public function disconnect() { @@ -230,58 +161,53 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Begin transaction + * {@inheritDoc} */ public function beginTransaction() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } - // A transaction begins when the first SQL statement that changes data is executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag. + // A transaction begins when the first SQL statement that changes data is executed with oci_execute() using + // the OCI_NO_AUTO_COMMIT flag. $this->inTransaction = true; + + return $this; } /** - * In transaction - * - * @return bool - */ - public function inTransaction() - { - return $this->inTransaction; - } - - /** - * Commit + * {@inheritDoc} */ public function commit() { - if (!$this->resource) { + if (! $this->isConnected()) { $this->connect(); } - if ($this->inTransaction) { + if ($this->inTransaction()) { $valid = oci_commit($this->resource); if ($valid === false) { $e = oci_error($this->resource); throw new Exception\InvalidQueryException($e['message'], $e['code']); } + + $this->inTransaction = false; } + + return $this; } /** - * Rollback - * - * @return Connection + * {@inheritDoc} */ public function rollback() { - if (!$this->resource) { + if (! $this->isConnected()) { throw new Exception\RuntimeException('Must be connected before you can rollback.'); } - if (!$this->inTransaction) { + if (! $this->inTransaction()) { throw new Exception\RuntimeException('Must call commit() before you can rollback.'); } @@ -291,18 +217,17 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface throw new Exception\InvalidQueryException($e['message'], $e['code']); } + $this->inTransaction = false; + return $this; } /** - * Execute - * - * @param string $sql - * @return Result + * {@inheritDoc} */ public function execute($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } @@ -328,18 +253,16 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } $resultPrototype = $this->driver->createResult($ociStmt); + return $resultPrototype; } /** - * Get last generated id - * - * @param null $name Ignored - * @return int + * {@inheritDoc} */ public function getLastGeneratedValue($name = null) { // @todo Get Last Generated Value in Connection (this might not apply) - return null; + return; } } diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Feature/RowCounter.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Feature/RowCounter.php new file mode 100644 index 00000000..bd55f065 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Feature/RowCounter.php @@ -0,0 +1,75 @@ +getSql(); + if ($sql == '' || stripos(strtolower($sql), 'select') === false) { + return; + } + $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')'; + $countStmt->prepare($countSql); + $result = $countStmt->execute(); + $countRow = $result->current(); + return $countRow['count']; + } + + /** + * @param string $sql + * @return null|int + */ + public function getCountForSql($sql) + { + if (stripos(strtolower($sql), 'select') === false) { + return; + } + $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')'; + $result = $this->driver->getConnection()->execute($countSql); + $countRow = $result->current(); + return $countRow['count']; + } + + /** + * @param \Zend\Db\Adapter\Driver\Oci8\Statement|string $context + * @return callable + */ + public function getRowCountClosure($context) + { + $rowCounter = $this; + return function () use ($rowCounter, $context) { + /** @var $rowCounter RowCounter */ + return ($context instanceof Statement) + ? $rowCounter->getCountForStatement($context) + : $rowCounter->getCountForSql($context); + }; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Oci8.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Oci8.php similarity index 63% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Oci8.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Oci8.php index 0e8d49e3..3f0ba5af 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Oci8.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Oci8.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -12,9 +12,11 @@ namespace Zend\Db\Adapter\Driver\Oci8; use Zend\Db\Adapter\Driver\DriverInterface; use Zend\Db\Adapter\Exception; use Zend\Db\Adapter\Profiler; +use Zend\Db\Adapter\Driver\Feature\AbstractFeature; class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface { + const FEATURES_DEFAULT = 'default'; /** * @var Connection @@ -39,32 +41,49 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface /** * @var array */ - protected $options = array( + protected $options = []; - ); + /** + * @var array + */ + protected $features = []; /** * @param array|Connection|\oci8 $connection * @param null|Statement $statementPrototype * @param null|Result $resultPrototype * @param array $options + * @param string $features */ - public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, array $options = array()) - { - if (!$connection instanceof Connection) { + public function __construct( + $connection, + Statement $statementPrototype = null, + Result $resultPrototype = null, + array $options = [], + $features = self::FEATURES_DEFAULT + ) { + if (! $connection instanceof Connection) { $connection = new Connection($connection); } $options = array_intersect_key(array_merge($this->options, $options), $this->options); - $this->registerConnection($connection); $this->registerStatementPrototype(($statementPrototype) ?: new Statement()); $this->registerResultPrototype(($resultPrototype) ?: new Result()); + if (is_array($features)) { + foreach ($features as $name => $feature) { + $this->addFeature($name, $feature); + } + } elseif ($features instanceof AbstractFeature) { + $this->addFeature($features->getName(), $features); + } elseif ($features === self::FEATURES_DEFAULT) { + $this->setupDefaultFeatures(); + } } /** * @param Profiler\ProfilerInterface $profiler - * @return Oci8 + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -90,7 +109,7 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface * Register connection * * @param Connection $connection - * @return Oci8 + * @return self Provides a fluent interface */ public function registerConnection(Connection $connection) { @@ -103,7 +122,7 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface * Register statement prototype * * @param Statement $statementPrototype - * @return Oci8 + * @return self Provides a fluent interface */ public function registerStatementPrototype(Statement $statementPrototype) { @@ -124,7 +143,7 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface * Register result prototype * * @param Result $resultPrototype - * @return Oci8 + * @return self Provides a fluent interface */ public function registerResultPrototype(Result $resultPrototype) { @@ -140,6 +159,48 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface return $this->resultPrototype; } + /** + * Add feature + * + * @param string $name + * @param AbstractFeature $feature + * @return self Provides a fluent interface + */ + public function addFeature($name, $feature) + { + if ($feature instanceof AbstractFeature) { + $name = $feature->getName(); // overwrite the name, just in case + $feature->setDriver($this); + } + $this->features[$name] = $feature; + return $this; + } + + /** + * Setup the default features for Pdo + * + * @return self Provides a fluent interface + */ + public function setupDefaultFeatures() + { + $this->addFeature(null, new Feature\RowCounter()); + return $this; + } + + /** + * Get feature + * + * @param string $name + * @return AbstractFeature|false + */ + public function getFeature($name) + { + if (isset($this->features[$name])) { + return $this->features[$name]; + } + return false; + } + /** * Get database platform name * @@ -156,8 +217,10 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface */ public function checkEnvironment() { - if (!extension_loaded('oci8')) { - throw new Exception\RuntimeException('The Oci8 extension is required for this adapter but the extension is not loaded'); + if (! extension_loaded('oci8')) { + throw new Exception\RuntimeException( + 'The Oci8 extension is required for this adapter but the extension is not loaded' + ); } } @@ -183,10 +246,10 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface $statement->setSql($sqlOrResource); } elseif ($sqlOrResource !== null) { throw new Exception\InvalidArgumentException( - 'Oci8 only accepts an SQL string or a oci8 resource in ' . __FUNCTION__ + 'Oci8 only accepts an SQL string or an oci8 resource in ' . __FUNCTION__ ); } - if (!$this->connection->isConnected()) { + if (! $this->connection->isConnected()) { $this->connection->connect(); } $statement->initialize($this->connection->getResource()); @@ -196,18 +259,23 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface /** * @param resource $resource - * @param null $isBuffered + * @param null $context * @return Result */ - public function createResult($resource, $isBuffered = null) + public function createResult($resource, $context = null) { $result = clone $this->resultPrototype; - $result->initialize($resource, $this->connection->getLastGeneratedValue(), $isBuffered); + $rowCount = null; + // special feature, oracle Oci counter + if ($context && ($rowCounter = $this->getFeature('RowCounter')) && oci_num_fields($resource) > 0) { + $rowCount = $rowCounter->getRowCountClosure($context); + } + $result->initialize($resource, null, $rowCount); return $result; } /** - * @return array + * @return string */ public function getPrepareType() { @@ -231,5 +299,4 @@ class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface { return $this->getConnection()->getLastGeneratedValue(); } - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Result.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Result.php similarity index 79% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Result.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Result.php index 375dc370..4f27adce 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Result.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Result.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -15,16 +15,15 @@ use Zend\Db\Adapter\Exception; class Result implements Iterator, ResultInterface { - /** * @var resource */ protected $resource = null; /** - * @var bool + * @var null|int */ - protected $isBuffered = null; + protected $rowCount = null; /** * Cursor position @@ -45,7 +44,7 @@ class Result implements Iterator, ResultInterface protected $currentComplete = false; /** - * @var bool + * @var bool|array */ protected $currentData = false; @@ -53,7 +52,7 @@ class Result implements Iterator, ResultInterface * * @var array */ - protected $statementBindValues = array('keys' => null, 'values' => array()); + protected $statementBindValues = ['keys' => null, 'values' => []]; /** * @var mixed @@ -63,14 +62,18 @@ class Result implements Iterator, ResultInterface /** * Initialize * @param resource $resource - * @return Result + * @param null|int $generatedValue + * @param null|int $rowCount + * @return self Provides a fluent interface */ - public function initialize($resource /*, $generatedValue, $isBuffered = null*/) + public function initialize($resource, $generatedValue = null, $rowCount = null) { - if (!is_resource($resource) && get_resource_type($resource) !== 'oci8 statement') { + if (! is_resource($resource) && get_resource_type($resource) !== 'oci8 statement') { throw new Exception\InvalidArgumentException('Invalid resource provided.'); } $this->resource = $resource; + $this->generatedValue = $generatedValue; + $this->rowCount = $rowCount; return $this; } @@ -83,7 +86,7 @@ class Result implements Iterator, ResultInterface */ public function buffer() { - return null; + return; } /** @@ -135,7 +138,6 @@ class Result implements Iterator, ResultInterface return false; } } - return $this->currentData; } @@ -148,7 +150,6 @@ class Result implements Iterator, ResultInterface { $this->currentComplete = true; $this->currentData = oci_fetch_assoc($this->resource); - if ($this->currentData !== false) { $this->position++; return true; @@ -192,18 +193,23 @@ class Result implements Iterator, ResultInterface if ($this->currentComplete) { return ($this->currentData !== false); } - return $this->loadData(); } /** * Count - * @return int + * @return null|int */ public function count() { - // @todo OCI8 row count in Driver Result - return null; + if (is_int($this->rowCount)) { + return $this->rowCount; + } + if (is_callable($this->rowCount)) { + $this->rowCount = (int) call_user_func($this->rowCount); + return $this->rowCount; + } + return; } /** @@ -215,12 +221,11 @@ class Result implements Iterator, ResultInterface } /** - * @return mixed|null + * @return null */ public function getGeneratedValue() { // @todo OCI8 generated value in Driver Result - return null; + return; } - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Statement.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Statement.php similarity index 80% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Statement.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Statement.php index 8dc7388b..2d8ca1ee 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Statement.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Oci8/Statement.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,7 +16,6 @@ use Zend\Db\Adapter\Profiler; class Statement implements StatementInterface, Profiler\ProfilerAwareInterface { - /** * @var resource */ @@ -65,7 +64,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set driver * * @param Oci8 $driver - * @return Statement + * @return self Provides a fluent interface */ public function setDriver($driver) { @@ -75,7 +74,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Statement + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -95,7 +94,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Initialize * * @param resource $oci8 - * @return Statement + * @return self Provides a fluent interface */ public function initialize($oci8) { @@ -107,7 +106,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set sql * * @param string $sql - * @return Statement + * @return self Provides a fluent interface */ public function setSql($sql) { @@ -119,7 +118,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set Parameter container * * @param ParameterContainer $parameterContainer - * @return Statement + * @return self Provides a fluent interface */ public function setParameterContainer(ParameterContainer $parameterContainer) { @@ -141,7 +140,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set resource * * @param resource $oci8Statement - * @return Statement + * @return self Provides a fluent interface */ public function setResource($oci8Statement) { @@ -185,7 +184,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param string $sql - * @return Statement + * @return self Provides a fluent interface */ public function prepare($sql = null) { @@ -198,7 +197,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface // get oci8 statement resource $this->resource = oci_parse($this->oci8, $sql); - if (!$this->resource) { + if (! $this->resource) { $e = oci_error($this->oci8); throw new Exception\InvalidQueryException( 'Statement couldn\'t be produced with sql: ' . $sql, @@ -214,17 +213,17 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * Execute * - * @param ParameterContainer $parameters + * @param null|array|ParameterContainer $parameters * @return mixed */ public function execute($parameters = null) { - if (!$this->isPrepared) { + if (! $this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ - if (!$this->parameterContainer instanceof ParameterContainer) { + if (! $this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; @@ -261,14 +260,12 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface throw new Exception\RuntimeException($e['message'], $e['code']); } - $result = $this->driver->createResult($this->resource); + $result = $this->driver->createResult($this->resource, $this); return $result; } /** * Bind parameters from container - * - * @param ParameterContainer $pContainer */ protected function bindParametersFromContainer() { @@ -291,6 +288,12 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface case ParameterContainer::TYPE_BINARY: $type = SQLT_BIN; break; + case ParameterContainer::TYPE_LOB: + $type = OCI_B_CLOB; + $clob = oci_new_descriptor($this->driver->getConnection()->getResource(), OCI_DTYPE_LOB); + $clob->writetemporary($value, OCI_TEMP_CLOB); + $value = $clob; + break; case ParameterContainer::TYPE_STRING: default: $type = SQLT_CHR; @@ -300,8 +303,25 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface $type = SQLT_CHR; } - oci_bind_by_name($this->resource, $name, $value, -1, $type); + $maxLength = -1; + if ($this->parameterContainer->offsetHasMaxLength($name)) { + $maxLength = $this->parameterContainer->offsetGetMaxLength($name); + } + + oci_bind_by_name($this->resource, $name, $value, $maxLength, $type); } } + /** + * Perform a deep clone + */ + public function __clone() + { + $this->isPrepared = false; + $this->parametersBound = false; + $this->resource = null; + if ($this->parameterContainer) { + $this->parameterContainer = clone $this->parameterContainer; + } + } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Connection.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Connection.php similarity index 63% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Connection.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Connection.php index 2ece6759..5f2f6174 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Connection.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Connection.php @@ -3,52 +3,36 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\Pdo; -use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Driver\AbstractConnection; use Zend\Db\Adapter\Exception; -use Zend\Db\Adapter\Profiler; -class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +class Connection extends AbstractConnection { /** * @var Pdo */ protected $driver = null; - /** - * @var Profiler\ProfilerInterface - */ - protected $profiler = null; - - /** - * @var string - */ - protected $driverName = null; - - /** - * @var array - */ - protected $connectionParameters = array(); - /** * @var \PDO */ protected $resource = null; /** - * @var bool + * @var string */ - protected $inTransaction = false; + protected $dsn = null; /** * Constructor * - * @param array|\PDO|null $connectionParameters + * @param array|\PDO|null $connectionParameters * @throws Exception\InvalidArgumentException */ public function __construct($connectionParameters = null) @@ -58,7 +42,9 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } elseif ($connectionParameters instanceof \PDO) { $this->setResource($connectionParameters); } elseif (null !== $connectionParameters) { - throw new Exception\InvalidArgumentException('$connection must be an array of parameters, a PDO object or null'); + throw new Exception\InvalidArgumentException( + '$connection must be an array of parameters, a PDO object or null' + ); } } @@ -66,83 +52,59 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface * Set driver * * @param Pdo $driver - * @return Connection + * @return self Provides a fluent interface */ public function setDriver(Pdo $driver) { $this->driver = $driver; + return $this; } /** - * @param Profiler\ProfilerInterface $profiler - * @return Connection - */ - public function setProfiler(Profiler\ProfilerInterface $profiler) - { - $this->profiler = $profiler; - return $this; - } - - /** - * @return null|Profiler\ProfilerInterface - */ - public function getProfiler() - { - return $this->profiler; - } - - /** - * Get driver name - * - * @return null|string - */ - public function getDriverName() - { - return $this->driverName; - } - - /** - * Set connection parameters - * - * @param array $connectionParameters - * @return void + * {@inheritDoc} */ public function setConnectionParameters(array $connectionParameters) { $this->connectionParameters = $connectionParameters; if (isset($connectionParameters['dsn'])) { - $this->driverName = substr($connectionParameters['dsn'], 0, + $this->driverName = substr( + $connectionParameters['dsn'], + 0, strpos($connectionParameters['dsn'], ':') ); } elseif (isset($connectionParameters['pdodriver'])) { $this->driverName = strtolower($connectionParameters['pdodriver']); } elseif (isset($connectionParameters['driver'])) { $this->driverName = strtolower(substr( - str_replace(array('-', '_', ' '), '', $connectionParameters['driver']), + str_replace(['-', '_', ' '], '', $connectionParameters['driver']), 3 )); } } /** - * Get connection parameters - * - * @return array + * Get the dsn string for this connection + * @throws \Zend\Db\Adapter\Exception\RunTimeException + * @return string */ - public function getConnectionParameters() + public function getDsn() { - return $this->connectionParameters; + if (! $this->dsn) { + throw new Exception\RuntimeException( + 'The DSN has not been set or constructed from parameters in connect() for this Connection' + ); + } + + return $this->dsn; } /** - * Get current schema - * - * @return string + * {@inheritDoc} */ public function getCurrentSchema() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } @@ -152,6 +114,10 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface break; case 'sqlite': return 'main'; + case 'sqlsrv': + case 'dblib': + $sql = 'SELECT SCHEMA_NAME()'; + break; case 'pgsql': default: $sql = 'SELECT CURRENT_SCHEMA'; @@ -163,6 +129,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface if ($result instanceof \PDOStatement) { return $result->fetchColumn(); } + return false; } @@ -170,32 +137,19 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface * Set resource * * @param \PDO $resource - * @return Connection + * @return self Provides a fluent interface */ public function setResource(\PDO $resource) { $this->resource = $resource; $this->driverName = strtolower($this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME)); + return $this; } /** - * Get resource + * {@inheritDoc} * - * @return \PDO - */ - public function getResource() - { - if (!$this->isConnected()) { - $this->connect(); - } - return $this->resource; - } - - /** - * Connect - * - * @return Connection * @throws Exception\InvalidConnectionParametersException * @throws Exception\RuntimeException */ @@ -206,16 +160,17 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } $dsn = $username = $password = $hostname = $database = null; - $options = array(); + $options = []; foreach ($this->connectionParameters as $key => $value) { switch (strtolower($key)) { case 'dsn': $dsn = $value; break; case 'driver': - $value = strtolower($value); + $value = strtolower((string) $value); if (strpos($value, 'pdo') === 0) { - $pdoDriver = strtolower(substr(str_replace(array('-', '_', ' '), '', $value), 3)); + $pdoDriver = str_replace(['-', '_', ' '], '', $value); + $pdoDriver = substr($pdoDriver, 3) ?: ''; } break; case 'pdodriver': @@ -240,6 +195,15 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface case 'dbname': $database = (string) $value; break; + case 'charset': + $charset = (string) $value; + break; + case 'unix_socket': + $unix_socket = (string) $value; + break; + case 'version': + $version = (string) $value; + break; case 'driver_options': case 'options': $value = (array) $value; @@ -251,12 +215,27 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } } - if (!isset($dsn) && isset($pdoDriver)) { - $dsn = array(); + if (isset($hostname) && isset($unix_socket)) { + throw new Exception\InvalidConnectionParametersException( + 'Ambiguous connection parameters, both hostname and unix_socket parameters were set', + $this->connectionParameters + ); + } + + if (! isset($dsn) && isset($pdoDriver)) { + $dsn = []; switch ($pdoDriver) { case 'sqlite': $dsn[] = $database; break; + case 'sqlsrv': + if (isset($database)) { + $dsn[] = "database={$database}"; + } + if (isset($hostname)) { + $dsn[] = "server={$hostname}"; + } + break; default: if (isset($database)) { $dsn[] = "dbname={$database}"; @@ -267,23 +246,37 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface if (isset($port)) { $dsn[] = "port={$port}"; } + if (isset($charset) && $pdoDriver != 'pgsql') { + $dsn[] = "charset={$charset}"; + } + if (isset($unix_socket)) { + $dsn[] = "unix_socket={$unix_socket}"; + } + if (isset($version)) { + $dsn[] = "version={$version}"; + } break; } $dsn = $pdoDriver . ':' . implode(';', $dsn); - } elseif (!isset($dsn)) { + } elseif (! isset($dsn)) { throw new Exception\InvalidConnectionParametersException( 'A dsn was not provided or could not be constructed from your parameters', $this->connectionParameters ); } + $this->dsn = $dsn; + try { $this->resource = new \PDO($dsn, $username, $password, $options); $this->resource->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + if (isset($charset) && $pdoDriver == 'pgsql') { + $this->resource->exec('SET NAMES ' . $this->resource->quote($charset)); + } $this->driverName = strtolower($this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME)); } catch (\PDOException $e) { $code = $e->getCode(); - if (!is_long($code)) { + if (! is_long($code)) { $code = null; } throw new Exception\RuntimeException('Connect Error: ' . $e->getMessage(), $code, $e); @@ -293,9 +286,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Is connected - * - * @return bool + * {@inheritDoc} */ public function isConnected() { @@ -303,79 +294,80 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Disconnect - * - * @return Connection - */ - public function disconnect() - { - if ($this->isConnected()) { - $this->resource = null; - } - return $this; - } - - /** - * Begin transaction - * - * @return Connection + * {@inheritDoc} */ public function beginTransaction() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } - $this->resource->beginTransaction(); - $this->inTransaction = true; + + if (0 === $this->nestedTransactionsCount) { + $this->resource->beginTransaction(); + $this->inTransaction = true; + } + + $this->nestedTransactionsCount ++; + return $this; } /** - * Commit - * - * @return Connection + * {@inheritDoc} */ public function commit() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } - $this->resource->commit(); - $this->inTransaction = false; + if ($this->inTransaction) { + $this->nestedTransactionsCount -= 1; + } + + /* + * This shouldn't check for being in a transaction since + * after issuing a SET autocommit=0; we have to commit too. + */ + if (0 === $this->nestedTransactionsCount) { + $this->resource->commit(); + $this->inTransaction = false; + } + return $this; } /** - * Rollback + * {@inheritDoc} * - * @return Connection * @throws Exception\RuntimeException */ public function rollback() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { throw new Exception\RuntimeException('Must be connected before you can rollback'); } - if (!$this->inTransaction) { + if (! $this->inTransaction()) { throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback'); } $this->resource->rollBack(); + + $this->inTransaction = false; + $this->nestedTransactionsCount = 0; + return $this; } /** - * Execute + * {@inheritDoc} * - * @param $sql - * @return Result * @throws Exception\InvalidQueryException */ public function execute($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } @@ -395,36 +387,38 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } $result = $this->driver->createResult($resultResource, $sql); - return $result; + return $result; } /** * Prepare * - * @param string $sql + * @param string $sql * @return Statement */ public function prepare($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } $statement = $this->driver->createStatement($sql); + return $statement; } /** - * Get last generated id + * {@inheritDoc} * - * @param string $name - * @return int|null|false + * @param string $name + * @return string|null|false */ public function getLastGeneratedValue($name = null) { - if ($name === null && $this->driverName == 'pgsql') { - return null; + if ($name === null + && ($this->driverName == 'pgsql' || $this->driverName == 'firebird')) { + return; } try { @@ -432,6 +426,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } catch (\Exception $e) { // do nothing } + return false; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/OracleRowCounter.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/OracleRowCounter.php similarity index 76% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/OracleRowCounter.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/OracleRowCounter.php index 1d614606..e913ee90 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/OracleRowCounter.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/OracleRowCounter.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -17,7 +17,6 @@ use Zend\Db\Adapter\Driver\Pdo; */ class OracleRowCounter extends AbstractFeature { - /** * @return string */ @@ -35,7 +34,7 @@ class OracleRowCounter extends AbstractFeature $countStmt = clone $statement; $sql = $statement->getSql(); if ($sql == '' || stripos($sql, 'select') === false) { - return null; + return; } $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')'; $countStmt->prepare($countSql); @@ -51,12 +50,12 @@ class OracleRowCounter extends AbstractFeature */ public function getCountForSql($sql) { - if (!stripos($sql, 'select')) { - return null; + if (stripos($sql, 'select') === false) { + return; } $countSql = 'SELECT COUNT(*) as count FROM (' . $sql . ')'; /** @var $pdo \PDO */ - $pdo = $this->pdoDriver->getConnection()->getResource(); + $pdo = $this->driver->getConnection()->getResource(); $result = $pdo->query($countSql); $countRow = $result->fetch(\PDO::FETCH_ASSOC); return $countRow['count']; @@ -64,17 +63,14 @@ class OracleRowCounter extends AbstractFeature /** * @param $context - * @return closure + * @return \Closure */ public function getRowCountClosure($context) { - $oracleRowCounter = $this; - return function () use ($oracleRowCounter, $context) { - /** @var $oracleRowCounter OracleRowCounter */ + return function () use ($context) { return ($context instanceof Pdo\Statement) - ? $oracleRowCounter->getCountForStatement($context) - : $oracleRowCounter->getCountForSql($context); + ? $this->getCountForStatement($context) + : $this->getCountForSql($context); }; } - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php similarity index 76% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php index 08f80b71..deb0ba3c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -17,7 +17,6 @@ use Zend\Db\Adapter\Driver\Pdo; */ class SqliteRowCounter extends AbstractFeature { - /** * @return string */ @@ -35,7 +34,7 @@ class SqliteRowCounter extends AbstractFeature $countStmt = clone $statement; $sql = $statement->getSql(); if ($sql == '' || stripos($sql, 'select') === false) { - return null; + return; } $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')'; $countStmt->prepare($countSql); @@ -51,12 +50,12 @@ class SqliteRowCounter extends AbstractFeature */ public function getCountForSql($sql) { - if (!stripos($sql, 'select')) { - return null; + if (stripos($sql, 'select') === false) { + return; } $countSql = 'SELECT COUNT(*) as count FROM (' . $sql . ')'; /** @var $pdo \PDO */ - $pdo = $this->pdoDriver->getConnection()->getResource(); + $pdo = $this->driver->getConnection()->getResource(); $result = $pdo->query($countSql); $countRow = $result->fetch(\PDO::FETCH_ASSOC); return $countRow['count']; @@ -64,16 +63,14 @@ class SqliteRowCounter extends AbstractFeature /** * @param $context - * @return closure + * @return \Closure */ public function getRowCountClosure($context) { - $sqliteRowCounter = $this; - return function () use ($sqliteRowCounter, $context) { - /** @var $sqliteRowCounter SqliteRowCounter */ + return function () use ($context) { return ($context instanceof Pdo\Statement) - ? $sqliteRowCounter->getCountForStatement($context) - : $sqliteRowCounter->getCountForSql($context); + ? $this->getCountForStatement($context) + : $this->getCountForSql($context); }; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Pdo.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Pdo.php similarity index 82% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Pdo.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Pdo.php index bcae2c6f..daf4075c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Pdo.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Pdo.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -41,7 +41,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA /** * @var array */ - protected $features = array(); + protected $features = []; /** * @param array|Connection|\PDO $connection @@ -49,9 +49,13 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA * @param null|Result $resultPrototype * @param string $features */ - public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, $features = self::FEATURES_DEFAULT) - { - if (!$connection instanceof Connection) { + public function __construct( + $connection, + Statement $statementPrototype = null, + Result $resultPrototype = null, + $features = self::FEATURES_DEFAULT + ) { + if (! $connection instanceof Connection) { $connection = new Connection($connection); } @@ -71,7 +75,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA /** * @param Profiler\ProfilerInterface $profiler - * @return Pdo + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -97,7 +101,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA * Register connection * * @param Connection $connection - * @return Pdo + * @return self Provides a fluent interface */ public function registerConnection(Connection $connection) { @@ -132,7 +136,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA * * @param string $name * @param AbstractFeature $feature - * @return Pdo + * @return self Provides a fluent interface */ public function addFeature($name, $feature) { @@ -147,7 +151,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA /** * Setup the default features for Pdo * - * @return Pdo + * @return self Provides a fluent interface */ public function setupDefaultFeatures() { @@ -189,7 +193,9 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA return 'Postgresql'; case 'oci': return 'Oracle'; - + case 'dblib': + case 'sqlsrv': + return 'SqlServer'; default: return ucfirst($name); } @@ -203,6 +209,9 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA return 'PostgreSQL'; case 'oci': return 'Oracle'; + case 'dblib': + case 'sqlsrv': + return 'SQLServer'; default: return ucfirst($name); } @@ -214,8 +223,10 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA */ public function checkEnvironment() { - if (!extension_loaded('PDO')) { - throw new Exception\RuntimeException('The PDO extension is required for this adapter but the extension is not loaded'); + if (! extension_loaded('PDO')) { + throw new Exception\RuntimeException( + 'The PDO extension is required for this adapter but the extension is not loaded' + ); } } @@ -240,7 +251,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA if (is_string($sqlOrResource)) { $statement->setSql($sqlOrResource); } - if (!$this->connection->isConnected()) { + if (! $this->connection->isConnected()) { $this->connection->connect(); } $statement->initialize($this->connection->getResource()); @@ -278,7 +289,7 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA } /** - * @return array + * @return string */ public function getPrepareType() { @@ -292,7 +303,17 @@ 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) { + $name = ltrim($name, ':'); + // @see https://bugs.php.net/bug.php?id=43130 + if (preg_match('/[^a-zA-Z0-9_]/', $name)) { + throw new Exception\RuntimeException(sprintf( + 'The PDO param %s contains invalid characters.' + . ' Only alphabetic characters, digits, and underscores (_)' + . ' are allowed.', + $name + )); + } return ':' . $name; } @@ -300,7 +321,8 @@ class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerA } /** - * @return mixed + * @param string|null $name + * @return string|null|false */ public function getLastGeneratedValue($name = null) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Result.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Result.php similarity index 80% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Result.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Result.php index b73c5b5d..ec4cdc65 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Result.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Result.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,7 +16,6 @@ use Zend\Db\Adapter\Exception; class Result implements Iterator, ResultInterface { - const STATEMENT_MODE_SCROLLABLE = 'scrollable'; const STATEMENT_MODE_FORWARD = 'forward'; @@ -27,7 +26,12 @@ class Result implements Iterator, ResultInterface protected $statementMode = self::STATEMENT_MODE_FORWARD; /** - * @var \PDOStatement + * @var int + */ + protected $fetchMode = \PDO::FETCH_ASSOC; + + /** + * @var PDOStatement */ protected $resource = null; @@ -70,13 +74,14 @@ class Result implements Iterator, ResultInterface * @param PDOStatement $resource * @param $generatedValue * @param int $rowCount - * @return Result + * @return self Provides a fluent interface */ public function initialize(PDOStatement $resource, $generatedValue, $rowCount = null) { $this->resource = $resource; $this->generatedValue = $generatedValue; $this->rowCount = $rowCount; + return $this; } @@ -85,7 +90,7 @@ class Result implements Iterator, ResultInterface */ public function buffer() { - return null; + return; } /** @@ -96,6 +101,29 @@ class Result implements Iterator, ResultInterface return false; } + /** + * @param int $fetchMode + * @throws Exception\InvalidArgumentException on invalid fetch mode + */ + public function setFetchMode($fetchMode) + { + if ($fetchMode < 1 || $fetchMode > 10) { + throw new Exception\InvalidArgumentException( + 'The fetch mode must be one of the PDO::FETCH_* constants.' + ); + } + + $this->fetchMode = (int) $fetchMode; + } + + /** + * @return int + */ + public function getFetchMode() + { + return $this->fetchMode; + } + /** * Get resource * @@ -116,7 +144,8 @@ class Result implements Iterator, ResultInterface return $this->currentData; } - $this->currentData = $this->resource->fetch(\PDO::FETCH_ASSOC); + $this->currentData = $this->resource->fetch($this->fetchMode); + $this->currentComplete = true; return $this->currentData; } @@ -127,7 +156,7 @@ class Result implements Iterator, ResultInterface */ public function next() { - $this->currentData = $this->resource->fetch(\PDO::FETCH_ASSOC); + $this->currentData = $this->resource->fetch($this->fetchMode); $this->currentComplete = true; $this->position++; return $this->currentData; @@ -154,7 +183,7 @@ class Result implements Iterator, ResultInterface 'This result is a forward only result set, calling rewind() after moving forward is not supported' ); } - $this->currentData = $this->resource->fetch(\PDO::FETCH_ASSOC); + $this->currentData = $this->resource->fetch($this->fetchMode); $this->currentComplete = true; $this->position = 0; } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Statement.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Statement.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php index ae22ed54..97c9e191 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Statement.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,7 +16,6 @@ use Zend\Db\Adapter\Profiler; class Statement implements StatementInterface, Profiler\ProfilerAwareInterface { - /** * @var \PDO */ @@ -70,7 +69,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set driver * * @param Pdo $driver - * @return Statement + * @return self Provides a fluent interface */ public function setDriver(Pdo $driver) { @@ -80,7 +79,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Statement + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -100,7 +99,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Initialize * * @param \PDO $connectionResource - * @return Statement + * @return self Provides a fluent interface */ public function initialize(\PDO $connectionResource) { @@ -112,7 +111,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set resource * * @param \PDOStatement $pdoStatement - * @return Statement + * @return self Provides a fluent interface */ public function setResource(\PDOStatement $pdoStatement) { @@ -134,7 +133,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set sql * * @param string $sql - * @return Statement + * @return self Provides a fluent interface */ public function setSql($sql) { @@ -154,7 +153,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param ParameterContainer $parameterContainer - * @return Statement + * @return self Provides a fluent interface */ public function setParameterContainer(ParameterContainer $parameterContainer) { @@ -180,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; } @@ -203,18 +202,18 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface } /** - * @param mixed $parameters + * @param null|array|ParameterContainer $parameters * @throws Exception\InvalidQueryException * @return Result */ public function execute($parameters = null) { - if (!$this->isPrepared) { + if (! $this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ - if (!$this->parameterContainer instanceof ParameterContainer) { + if (! $this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; @@ -242,7 +241,11 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface if ($this->profiler) { $this->profiler->profilerFinish(); } - throw new Exception\InvalidQueryException('Statement could not be executed', null, $e); + throw new Exception\InvalidQueryException( + 'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')', + null, + $e + ); } if ($this->profiler) { @@ -264,7 +267,13 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface $parameters = $this->parameterContainer->getNamedArray(); foreach ($parameters as $name => &$value) { - $type = \PDO::PARAM_STR; + if (is_bool($value)) { + $type = \PDO::PARAM_BOOL; + } elseif (is_int($value)) { + $type = \PDO::PARAM_INT; + } else { + $type = \PDO::PARAM_STR; + } if ($this->parameterContainer->offsetHasErrata($name)) { switch ($this->parameterContainer->offsetGetErrata($name)) { case ParameterContainer::TYPE_INTEGER: @@ -276,17 +285,13 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface case ParameterContainer::TYPE_LOB: $type = \PDO::PARAM_LOB; break; - case (is_bool($value)): - $type = \PDO::PARAM_BOOL; - break; } } // parameter is named or positional, value is reference - $parameter = is_int($name) ? ($name + 1) : $name; + $parameter = is_int($name) ? ($name + 1) : $this->driver->formatParameterName($name); $this->resource->bindParam($parameter, $value, $type); } - } /** @@ -301,6 +306,5 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface if ($this->parameterContainer) { $this->parameterContainer = clone $this->parameterContainer; } - } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Connection.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Connection.php similarity index 58% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Connection.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Connection.php index 96906793..a13321a9 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Connection.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Connection.php @@ -3,46 +3,31 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\Pgsql; -use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Driver\AbstractConnection; use Zend\Db\Adapter\Exception; -use Zend\Db\Adapter\Profiler; -class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +class Connection extends AbstractConnection { /** * @var Pgsql */ protected $driver = null; - /** - * @var Profiler\ProfilerInterface - */ - protected $profiler = null; - - /** - * Connection parameters - * - * @var array - */ - protected $connectionParameters = array(); - /** * @var resource */ protected $resource = null; /** - * In transaction - * - * @var bool + * @var null|int PostgreSQL connection type */ - protected $inTransaction = false; + protected $type = null; /** * Constructor @@ -59,94 +44,76 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Set connection parameters + * Set resource * - * @param array $connectionParameters - * @return Connection + * @param resource $resource + * @return self Provides a fluent interface */ - public function setConnectionParameters(array $connectionParameters) + public function setResource($resource) { - $this->connectionParameters = $connectionParameters; + $this->resource = $resource; + return $this; } + /** * Set driver * * @param Pgsql $driver - * @return Connection + * @return self Provides a fluent interface */ public function setDriver(Pgsql $driver) { $this->driver = $driver; + return $this; } /** - * @param Profiler\ProfilerInterface $profiler - * @return Connection + * @param int|null $type + * @return self Provides a fluent interface */ - public function setProfiler(Profiler\ProfilerInterface $profiler) + public function setType($type) { - $this->profiler = $profiler; + $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; } /** - * @return null|Profiler\ProfilerInterface - */ - public function getProfiler() - { - return $this->profiler; - } - - /** - * Set resource - * - * @param resource $resource - * @return Connection - */ - public function setResource($resource) - { - $this->resource = $resource; - return; - } - - /** - * Get current schema + * {@inheritDoc} * * @return null|string */ public function getCurrentSchema() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } $result = pg_query($this->resource, 'SELECT CURRENT_SCHEMA AS "currentschema"'); if ($result == false) { - return null; + return; } + return pg_fetch_result($result, 0, 'currentschema'); } /** - * Get resource + * {@inheritDoc} * - * @return resource - */ - public function getResource() - { - if (!$this->isConnected()) { - $this->connect(); - } - return $this->resource; - } - - /** - * Connect to the database - * - * @return Connection * @throws Exception\RuntimeException on failure */ public function connect() @@ -155,33 +122,12 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface return $this; } - // localize - $p = $this->connectionParameters; - - // given a list of key names, test for existence in $p - $findParameterValue = function (array $names) use ($p) { - foreach ($names as $name) { - if (isset($p[$name])) { - return $p[$name]; - } - } - return null; - }; - - $connection = array(); - $connection['host'] = $findParameterValue(array('hostname', 'host')); - $connection['user'] = $findParameterValue(array('username', 'user')); - $connection['password'] = $findParameterValue(array('password', 'passwd', 'pw')); - $connection['dbname'] = $findParameterValue(array('database', 'dbname', 'db', 'schema')); - $connection['port'] = (isset($p['port'])) ? (int) $p['port'] : null; - $connection['socket'] = (isset($p['socket'])) ? $p['socket'] : null; - - $connection = array_filter($connection); // remove nulls - $connection = http_build_query($connection, null, ' '); // @link http://php.net/pg_connect - + $connection = $this->getConnectionString(); set_error_handler(function ($number, $string) { throw new Exception\RuntimeException( - __METHOD__ . ': Unable to connect to database', null, new Exception\ErrorException($string, $number) + __METHOD__ . ': Unable to connect to database', + null, + new Exception\ErrorException($string, $number) ); }); $this->resource = pg_connect($connection); @@ -194,11 +140,23 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface )); } + $p = $this->connectionParameters; + + if (! empty($p['charset'])) { + if (-1 === pg_set_client_encoding($this->resource, $p['charset'])) { + throw new Exception\RuntimeException(sprintf( + "%s: Unable to set client encoding '%s'", + __METHOD__, + $p['charset'] + )); + } + } + return $this; } /** - * @return bool + * {@inheritDoc} */ public function isConnected() { @@ -206,64 +164,80 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * @return void + * {@inheritDoc} */ public function disconnect() { pg_close($this->resource); + return $this; } /** - * @return void + * {@inheritDoc} */ public function beginTransaction() { - if ($this->inTransaction) { + if ($this->inTransaction()) { throw new Exception\RuntimeException('Nested transactions are not supported'); } - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } pg_query($this->resource, 'BEGIN'); $this->inTransaction = true; + + return $this; } /** - * @return void + * {@inheritDoc} */ public function commit() { - if (!$this->inTransaction) { + if (! $this->isConnected()) { + $this->connect(); + } + + if (! $this->inTransaction()) { return; // We ignore attempts to commit non-existing transaction } pg_query($this->resource, 'COMMIT'); $this->inTransaction = false; + + return $this; } /** - * @return void + * {@inheritDoc} */ public function rollback() { - if (!$this->inTransaction) { - return; + if (! $this->isConnected()) { + throw new Exception\RuntimeException('Must be connected before you can rollback'); + } + + if (! $this->inTransaction()) { + throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback'); } pg_query($this->resource, 'ROLLBACK'); $this->inTransaction = false; + + return $this; } /** - * @param string $sql + * {@inheritDoc} + * * @throws Exception\InvalidQueryException * @return resource|\Zend\Db\ResultSet\ResultSetInterface */ public function execute($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } @@ -277,27 +251,63 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface $this->profiler->profilerFinish($sql); } - //var_dump(pg_result_status($resultResource)); - // if the returnValue is something other than a pg result resource, bypass wrapping it if ($resultResource === false) { throw new Exception\InvalidQueryException(pg_errormessage()); } $resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource); + return $resultPrototype; } /** - * @param null $name Ignored + * {@inheritDoc} + * * @return string */ public function getLastGeneratedValue($name = null) { - if ($name == null) { - return null; + if ($name === null) { + return; } - $result = pg_query($this->resource, 'SELECT CURRVAL(\'' . str_replace('\'', '\\\'', $name) . '\') as "currval"'); + $result = pg_query( + $this->resource, + 'SELECT CURRVAL(\'' . str_replace('\'', '\\\'', $name) . '\') as "currval"' + ); + return pg_fetch_result($result, 0, 'currval'); } + + /** + * Get Connection String + * + * @return string + */ + private function getConnectionString() + { + // localize + $p = $this->connectionParameters; + + // given a list of key names, test for existence in $p + $findParameterValue = function (array $names) use ($p) { + foreach ($names as $name) { + if (isset($p[$name])) { + return $p[$name]; + } + } + return; + }; + + $connectionParameters = [ + 'host' => $findParameterValue(['hostname', 'host']), + 'user' => $findParameterValue(['username', 'user']), + 'password' => $findParameterValue(['password', 'passwd', 'pw']), + 'dbname' => $findParameterValue(['database', 'dbname', 'db', 'schema']), + 'port' => isset($p['port']) ? (int) $p['port'] : null, + 'socket' => isset($p['socket']) ? $p['socket'] : null, + ]; + + return urldecode(http_build_query(array_filter($connectionParameters), null, ' ')); + } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Pgsql.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Pgsql.php similarity index 82% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Pgsql.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Pgsql.php index f30255e9..b99b641e 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Pgsql.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Pgsql.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -38,9 +38,9 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface /** * @var array */ - protected $options = array( + protected $options = [ 'buffer_results' => false - ); + ]; /** * Constructor @@ -50,9 +50,13 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface * @param null|Result $resultPrototype * @param array $options */ - public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, $options = null) - { - if (!$connection instanceof Connection) { + public function __construct( + $connection, + Statement $statementPrototype = null, + Result $resultPrototype = null, + $options = null + ) { + if (! $connection instanceof Connection) { $connection = new Connection($connection); } @@ -61,6 +65,10 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface $this->registerResultPrototype(($resultPrototype) ?: new Result()); } + /** + * @param Profiler\ProfilerInterface $profiler + * @return self Provides a fluent interface + */ public function setProfiler(Profiler\ProfilerInterface $profiler) { $this->profiler = $profiler; @@ -85,7 +93,7 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface * Register connection * * @param Connection $connection - * @return Pgsql + * @return self Provides a fluent interface */ public function registerConnection(Connection $connection) { @@ -98,7 +106,7 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface * Register statement prototype * * @param Statement $statement - * @return Pgsql + * @return self Provides a fluent interface */ public function registerStatementPrototype(Statement $statement) { @@ -111,7 +119,7 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface * Register result prototype * * @param Result $result - * @return Pgsql + * @return self Provides a fluent interface */ public function registerResultPrototype(Result $result) { @@ -142,8 +150,10 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface */ public function checkEnvironment() { - if (!extension_loaded('pgsql')) { - throw new Exception\RuntimeException('The PostgreSQL (pgsql) extension is required for this adapter but the extension is not loaded'); + if (! extension_loaded('pgsql')) { + throw new Exception\RuntimeException( + 'The PostgreSQL (pgsql) extension is required for this adapter but the extension is not loaded' + ); } } @@ -171,7 +181,7 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface $statement->setSql($sqlOrResource); } - if (!$this->connection->isConnected()) { + if (! $this->connection->isConnected()) { $this->connection->connect(); } @@ -195,7 +205,7 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface /** * Get prepare Type * - * @return array + * @return string */ public function getPrepareType() { @@ -217,10 +227,11 @@ class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface /** * Get last generated value * + * @param string $name * @return mixed */ - public function getLastGeneratedValue() + public function getLastGeneratedValue($name = null) { - return $this->connection->getLastGeneratedValue(); + return $this->connection->getLastGeneratedValue($name); } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Result.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Result.php similarity index 94% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Result.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Result.php index b007bc4a..918f5c68 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Result.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Result.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ use Zend\Db\Adapter\Exception; class Result implements ResultInterface { - /** * @var resource */ @@ -45,7 +44,7 @@ class Result implements ResultInterface */ public function initialize($resource, $generatedValue) { - if (!is_resource($resource) || get_resource_type($resource) != 'pgsql result') { + if (! is_resource($resource) || get_resource_type($resource) != 'pgsql result') { throw new Exception\InvalidArgumentException('Resource not of the correct type.'); } @@ -114,7 +113,7 @@ class Result implements ResultInterface */ public function buffer() { - return null; + return; } /** diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Statement.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Statement.php similarity index 89% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Statement.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Statement.php index 9b2eb501..c7e84506 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Statement.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Pgsql/Statement.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -58,7 +58,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param Pgsql $driver - * @return Statement + * @return self Provides a fluent interface */ public function setDriver(Pgsql $driver) { @@ -68,7 +68,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Statement + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -93,7 +93,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface */ public function initialize($pgsql) { - if (!is_resource($pgsql) || get_resource_type($pgsql) !== 'pgsql link') { + if (! is_resource($pgsql) || get_resource_type($pgsql) !== 'pgsql link') { throw new Exception\RuntimeException(sprintf( '%s: Invalid or missing postgresql connection; received "%s"', __METHOD__, @@ -117,7 +117,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set sql * * @param string $sql - * @return Statement + * @return self Provides a fluent interface */ public function setSql($sql) { @@ -139,7 +139,7 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface * Set parameter container * * @param ParameterContainer $parameterContainer - * @return Statement + * @return self Provides a fluent interface */ public function setParameterContainer(ParameterContainer $parameterContainer) { @@ -168,7 +168,8 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface $pCount = 1; $sql = preg_replace_callback( - '#\$\##', function ($foo) use (&$pCount) { + '#\$\##', + function () use (&$pCount) { return '$' . $pCount++; }, $sql @@ -192,18 +193,18 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * Execute * - * @param ParameterContainer|null $parameters + * @param null|array|ParameterContainer $parameters * @throws Exception\InvalidQueryException * @return Result */ public function execute($parameters = null) { - if (!$this->isPrepared()) { + if (! $this->isPrepared()) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ - if (!$this->parameterContainer instanceof ParameterContainer) { + if (! $this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/ResultInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/ResultInterface.php similarity index 94% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/ResultInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/ResultInterface.php index e0fa5954..486b40f1 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/ResultInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/ResultInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Connection.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Connection.php similarity index 68% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Connection.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Connection.php index ac790652..8839e1d1 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Connection.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Connection.php @@ -3,48 +3,27 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver\Sqlsrv; -use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Driver\AbstractConnection; use Zend\Db\Adapter\Driver\Sqlsrv\Exception\ErrorException; use Zend\Db\Adapter\Exception; -use Zend\Db\Adapter\Profiler; -class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +class Connection extends AbstractConnection { /** * @var Sqlsrv */ protected $driver = null; - /** - * @var Profiler\ProfilerInterface - */ - protected $profiler = null; - - /** - * @var array - */ - protected $connectionParameters = array(); - - /** - * @var resource - */ - protected $resource = null; - - /** - * @var bool - */ - protected $inTransaction = false; - /** * Constructor * - * @param array|resource $connectionInfo + * @param array|resource $connectionInfo * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException */ public function __construct($connectionInfo) @@ -62,67 +41,27 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface * Set driver * * @param Sqlsrv $driver - * @return Connection + * @return self Provides a fluent interface */ public function setDriver(Sqlsrv $driver) { $this->driver = $driver; + return $this; } /** - * @param Profiler\ProfilerInterface $profiler - * @return Connection - */ - public function setProfiler(Profiler\ProfilerInterface $profiler) - { - $this->profiler = $profiler; - return $this; - } - - /** - * @return null|Profiler\ProfilerInterface - */ - public function getProfiler() - { - return $this->profiler; - } - - /** - * Set connection parameters - * - * @param array $connectionParameters - * @return Connection - */ - public function setConnectionParameters(array $connectionParameters) - { - $this->connectionParameters = $connectionParameters; - return $this; - } - - /** - * Get connection parameters - * - * @return array - */ - public function getConnectionParameters() - { - return $this->connectionParameters; - } - - /** - * Get current schema - * - * @return string + * {@inheritDoc} */ public function getCurrentSchema() { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } $result = sqlsrv_query($this->resource, 'SELECT SCHEMA_NAME()'); $r = sqlsrv_fetch_array($result); + return $r[0]; } @@ -130,8 +69,8 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface * Set resource * * @param resource $resource + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException - * @return Connection */ public function setResource($resource) { @@ -139,25 +78,14 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface throw new Exception\InvalidArgumentException('Resource provided was not of type SQL Server Connection'); } $this->resource = $resource; + return $this; } /** - * @return resource - */ - public function getResource() - { - if (!$this->isConnected()) { - $this->connect(); - } - return $this->resource; - } - - /** - * Connect + * {@inheritDoc} * * @throws Exception\RuntimeException - * @return Connection */ public function connect() { @@ -166,9 +94,9 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } $serverName = '.'; - $params = array( + $params = [ 'ReturnDatesAsStrings' => true - ); + ]; foreach ($this->connectionParameters as $key => $value) { switch (strtolower($key)) { case 'hostname': @@ -187,17 +115,19 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface case 'dbname': $params['Database'] = (string) $value; break; + case 'charset': + $params['CharacterSet'] = (string) $value; + break; case 'driver_options': case 'options': $params = array_merge($params, (array) $value); break; - } } $this->resource = sqlsrv_connect($serverName, $params); - if (!$this->resource) { + if (! $this->resource) { throw new Exception\RuntimeException( 'Connect Error', null, @@ -209,8 +139,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Is connected - * @return bool + * {@inheritDoc} */ public function isConnected() { @@ -218,7 +147,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Disconnect + * {@inheritDoc} */ public function disconnect() { @@ -227,68 +156,72 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } /** - * Begin transaction + * {@inheritDoc} */ public function beginTransaction() { - // http://msdn.microsoft.com/en-us/library/cc296151.aspx - /* - $this->resource->autocommit(false); + if (! $this->isConnected()) { + $this->connect(); + } + + if (sqlsrv_begin_transaction($this->resource) === false) { + throw new Exception\RuntimeException( + new ErrorException(sqlsrv_errors()) + ); + } + $this->inTransaction = true; - */ + + return $this; } /** - * Commit + * {@inheritDoc} */ public function commit() { // http://msdn.microsoft.com/en-us/library/cc296194.aspx - /* - if (!$this->resource) { + + if (! $this->isConnected()) { $this->connect(); } - $this->resource->commit(); + sqlsrv_commit($this->resource); $this->inTransaction = false; - */ + + return $this; } /** - * Rollback + * {@inheritDoc} */ public function rollback() { // http://msdn.microsoft.com/en-us/library/cc296176.aspx - /* - if (!$this->resource) { - throw new \Exception('Must be connected before you can rollback.'); + + if (! $this->isConnected()) { + throw new Exception\RuntimeException('Must be connected before you can rollback.'); } - if (!$this->_inCommit) { - throw new \Exception('Must call commit() before you can rollback.'); - } + sqlsrv_rollback($this->resource); + $this->inTransaction = false; - $this->resource->rollback(); return $this; - */ } /** - * Execute + * {@inheritDoc} * - * @param string $sql * @throws Exception\RuntimeException - * @return mixed */ public function execute($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } - if (!$this->driver instanceof Sqlsrv) { + if (! $this->driver instanceof Sqlsrv) { throw new Exception\RuntimeException('Connection is missing an instance of Sqlsrv'); } @@ -316,6 +249,7 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface } $result = $this->driver->createResult($returnValue); + return $result; } @@ -327,28 +261,29 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface */ public function prepare($sql) { - if (!$this->isConnected()) { + if (! $this->isConnected()) { $this->connect(); } $statement = $this->driver->createStatement($sql); + return $statement; } /** - * Get last generated id + * {@inheritDoc} * - * @param string $name * @return mixed */ public function getLastGeneratedValue($name = null) { - if (!$this->resource) { + if (! $this->resource) { $this->connect(); } $sql = 'SELECT @@IDENTITY as Current_Identity'; $result = sqlsrv_query($this->resource, $sql); $row = sqlsrv_fetch_array($result); + return $row['Current_Identity']; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ErrorException.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ErrorException.php similarity index 87% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ErrorException.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ErrorException.php index f5ee3bc9..afc31427 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ErrorException.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ErrorException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,13 +13,12 @@ use Zend\Db\Adapter\Exception; class ErrorException extends Exception\ErrorException implements ExceptionInterface { - /** * Errors * * @var array */ - protected $errors = array(); + protected $errors = []; /** * Construct diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php index 221d330e..b260fca6 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Result.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Result.php similarity index 96% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Result.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Result.php index 77a22d8f..b9cf1c07 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Result.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Result.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ use Zend\Db\Adapter\Driver\ResultInterface; class Result implements Iterator, ResultInterface { - /** * @var resource */ @@ -47,7 +46,7 @@ class Result implements Iterator, ResultInterface * * @param resource $resource * @param mixed $generatedValue - * @return Result + * @return self Provides a fluent interface */ public function initialize($resource, $generatedValue = null) { @@ -61,7 +60,7 @@ class Result implements Iterator, ResultInterface */ public function buffer() { - return null; + return; } /** diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Sqlsrv.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Sqlsrv.php index ea7dcb35..9a712905 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Sqlsrv.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -15,7 +15,6 @@ use Zend\Db\Adapter\Profiler; class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface { - /** * @var Connection */ @@ -43,7 +42,7 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface */ public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null) { - if (!$connection instanceof Connection) { + if (! $connection instanceof Connection) { $connection = new Connection($connection); } @@ -54,7 +53,7 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface /** * @param Profiler\ProfilerInterface $profiler - * @return Sqlsrv + * @return self Provides a fluent interface */ public function setProfiler(Profiler\ProfilerInterface $profiler) { @@ -80,7 +79,7 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface * Register connection * * @param Connection $connection - * @return Sqlsrv + * @return self Provides a fluent interface */ public function registerConnection(Connection $connection) { @@ -93,7 +92,7 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface * Register statement prototype * * @param Statement $statementPrototype - * @return Sqlsrv + * @return self Provides a fluent interface */ public function registerStatementPrototype(Statement $statementPrototype) { @@ -106,7 +105,7 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface * Register result prototype * * @param Result $resultPrototype - * @return Sqlsrv + * @return self Provides a fluent interface */ public function registerResultPrototype(Result $resultPrototype) { @@ -137,8 +136,10 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface */ public function checkEnvironment() { - if (!extension_loaded('sqlsrv')) { - throw new Exception\RuntimeException('The Sqlsrv extension is required for this adapter but the extension is not loaded'); + if (! extension_loaded('sqlsrv')) { + throw new Exception\RuntimeException( + 'The Sqlsrv extension is required for this adapter but the extension is not loaded' + ); } } @@ -160,14 +161,16 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface if (is_resource($sqlOrResource)) { $statement->initialize($sqlOrResource); } else { - if (!$this->connection->isConnected()) { + if (! $this->connection->isConnected()) { $this->connection->connect(); } $statement->initialize($this->connection->getResource()); if (is_string($sqlOrResource)) { $statement->setSql($sqlOrResource); - } elseif ($sqlOrResource != null) { - throw new Exception\InvalidArgumentException('createStatement() only accepts an SQL string or a Sqlsrv resource'); + } elseif ($sqlOrResource !== null) { + throw new Exception\InvalidArgumentException( + 'createStatement() only accepts an SQL string or a Sqlsrv resource' + ); } } return $statement; @@ -185,7 +188,7 @@ class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface } /** - * @return array + * @return string */ public function getPrepareType() { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Statement.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Statement.php similarity index 78% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Statement.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Statement.php index 43a1e00d..ffc922ac 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Statement.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/Sqlsrv/Statement.php @@ -1,9 +1,10 @@ isPrepared) { throw new Exception\RuntimeException('Already prepared'); } $sql = ($sql) ?: $this->sql; + $options = ($options) ?: $this->prepareOptions; $pRef = &$this->parameterReferences; for ($position = 0, $count = substr_count($sql, '?'); $position < $count; $position++) { - $pRef[$position] = array('', SQLSRV_PARAM_IN, null, null); + if (! isset($this->prepareParams[$position])) { + $pRef[$position] = [&$this->parameterReferenceValues[$position], SQLSRV_PARAM_IN, null, null]; + } else { + $pRef[$position] = &$this->prepareParams[$position]; + } } - $this->resource = sqlsrv_prepare($this->sqlsrv, $sql, $pRef); + $this->resource = sqlsrv_prepare($this->sqlsrv, $sql, $pRef, $options); $this->isPrepared = true; + return $this; } @@ -214,18 +236,19 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface /** * Execute * - * @param array|ParameterContainer $parameters + * @param null|array|ParameterContainer $parameters * @throws Exception\RuntimeException * @return Result */ public function execute($parameters = null) { - if (!$this->isPrepared) { + /** END Standard ParameterContainer Merging Block */ + if (! $this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ - if (!$this->parameterContainer instanceof ParameterContainer) { + if (! $this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; @@ -241,7 +264,6 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface if ($this->parameterContainer->count() > 0) { $this->bindParametersFromContainer(); } - /** END Standard ParameterContainer Merging Block */ if ($this->profiler) { $this->profiler->profilerStart($this); @@ -276,14 +298,21 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface foreach ($values as $value) { $this->parameterReferences[$position++][0] = $value; } + } - // @todo bind errata - //foreach ($this->parameterContainer as $name => &$value) { - // $p[$position][0] = $value; - // $position++; - // if ($this->parameterContainer->offsetHasErrata($name)) { - // $p[$position][3] = $this->parameterContainer->offsetGetErrata($name); - // } - //} + /** + * @param array $prepareParams + */ + public function setPrepareParams(array $prepareParams) + { + $this->prepareParams = $prepareParams; + } + + /** + * @param array $prepareOptions + */ + public function setPrepareOptions(array $prepareOptions) + { + $this->prepareOptions = $prepareOptions; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/StatementInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/StatementInterface.php similarity index 83% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/StatementInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Driver/StatementInterface.php index afb37f2e..cb4eea85 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Driver/StatementInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Driver/StatementInterface.php @@ -3,17 +3,17 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Adapter\Driver; +use Zend\Db\Adapter\ParameterContainer; use Zend\Db\Adapter\StatementContainerInterface; interface StatementInterface extends StatementContainerInterface { - /** * Get resource * @@ -38,9 +38,8 @@ interface StatementInterface extends StatementContainerInterface /** * Execute * - * @param null $parameters + * @param null|array|ParameterContainer $parameters * @return ResultInterface */ public function execute($parameters = null); - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/ErrorException.php b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/ErrorException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/ErrorException.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Exception/ErrorException.php index 5c63b3e8..3cada086 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/ErrorException.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/ErrorException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/ExceptionInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/ExceptionInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/ExceptionInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Exception/ExceptionInterface.php index 32263c84..bf9e4c23 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/ExceptionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidArgumentException.php b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidArgumentException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidArgumentException.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidArgumentException.php index 50dea0db..d892c749 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidArgumentException.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidConnectionParametersException.php b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidConnectionParametersException.php similarity index 91% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidConnectionParametersException.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidConnectionParametersException.php index 53487be5..e468b704 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidConnectionParametersException.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidConnectionParametersException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,7 +11,6 @@ namespace Zend\Db\Adapter\Exception; class InvalidConnectionParametersException extends RuntimeException implements ExceptionInterface { - /** * @var int */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidQueryException.php b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidQueryException.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidQueryException.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidQueryException.php index ebda2c6d..3fbb486f 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidQueryException.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/InvalidQueryException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/RuntimeException.php b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/RuntimeException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/RuntimeException.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Exception/RuntimeException.php index cfe1c3e6..f817e110 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/RuntimeException.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/RuntimeException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/UnexpectedValueException.php b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/UnexpectedValueException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/UnexpectedValueException.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Exception/UnexpectedValueException.php index 72eccb24..0e31e4be 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Exception/UnexpectedValueException.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Exception/UnexpectedValueException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/ParameterContainer.php b/bundled-libs/zendframework/zend-db/src/Adapter/ParameterContainer.php similarity index 67% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/ParameterContainer.php rename to bundled-libs/zendframework/zend-db/src/Adapter/ParameterContainer.php index cefe0eea..c6308377 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/ParameterContainer.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/ParameterContainer.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -15,7 +15,6 @@ use Iterator; class ParameterContainer implements Iterator, ArrayAccess, Countable { - const TYPE_AUTO = 'auto'; const TYPE_NULL = 'null'; const TYPE_DOUBLE = 'double'; @@ -29,26 +28,33 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable * * @var array */ - protected $data = array(); + protected $data = []; /** * @var array */ - protected $positions = array(); + protected $positions = []; /** * Errata * * @var array */ - protected $errata = array(); + protected $errata = []; + + /** + * Max length + * + * @var array + */ + protected $maxLength = []; /** * Constructor * * @param array $data */ - public function __construct(array $data = array()) + public function __construct(array $data = []) { if ($data) { $this->setFromArray($data); @@ -92,8 +98,10 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable * @param string|int $name * @param mixed $value * @param mixed $errata + * @param mixed $maxLength + * @throws Exception\InvalidArgumentException */ - public function offsetSet($name, $value, $errata = null) + public function offsetSet($name, $value, $errata = null, $maxLength = null) { $position = false; @@ -107,8 +115,7 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable } } elseif (is_string($name)) { // is a string: - $currentNames = array_keys($this->data); - $position = array_search($name, $currentNames, true); + $position = array_key_exists($name, $this->data); } elseif ($name === null) { $name = (string) count($this->data); } else { @@ -124,13 +131,17 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable if ($errata) { $this->offsetSetErrata($name, $errata); } + + if ($maxLength) { + $this->offsetSetMaxLength($name, $maxLength); + } } /** * Offset unset * * @param string $name - * @return ParameterContainer + * @return self Provides a fluent interface */ public function offsetUnset($name) { @@ -145,9 +156,9 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable * Set from array * * @param array $data - * @return ParameterContainer + * @return self Provides a fluent interface */ - public function setFromArray(Array $data) + public function setFromArray(array $data) { foreach ($data as $n => $v) { $this->offsetSet($n, $v); @@ -155,6 +166,79 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable return $this; } + /** + * Offset set max length + * + * @param string|int $name + * @param mixed $maxLength + */ + public function offsetSetMaxLength($name, $maxLength) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + $this->maxLength[$name] = $maxLength; + } + + /** + * Offset get max length + * + * @param string|int $name + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function offsetGetMaxLength($name) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + if (! array_key_exists($name, $this->data)) { + throw new Exception\InvalidArgumentException('Data does not exist for this name/position'); + } + return $this->maxLength[$name]; + } + + /** + * Offset has max length + * + * @param string|int $name + * @return bool + */ + public function offsetHasMaxLength($name) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + return (isset($this->maxLength[$name])); + } + + /** + * Offset unset max length + * + * @param string|int $name + * @throws Exception\InvalidArgumentException + */ + public function offsetUnsetMaxLength($name) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + if (! array_key_exists($name, $this->maxLength)) { + throw new Exception\InvalidArgumentException('Data does not exist for this name/position'); + } + $this->maxLength[$name] = null; + } + + /** + * Get max length iterator + * + * @return \ArrayIterator + */ + public function getMaxLengthIterator() + { + return new \ArrayIterator($this->maxLength); + } + /** * Offset set errata * @@ -181,7 +265,7 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable if (is_int($name)) { $name = $this->positions[$name]; } - if (!array_key_exists($name, $this->data)) { + if (! array_key_exists($name, $this->data)) { throw new Exception\InvalidArgumentException('Data does not exist for this name/position'); } return $this->errata[$name]; @@ -212,7 +296,7 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable if (is_int($name)) { $name = $this->positions[$name]; } - if (!array_key_exists($name, $this->errata)) { + if (! array_key_exists($name, $this->errata)) { throw new Exception\InvalidArgumentException('Data does not exist for this name/position'); } $this->errata[$name] = null; @@ -308,13 +392,15 @@ class ParameterContainer implements Iterator, ArrayAccess, Countable /** * @param array|ParameterContainer $parameters + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException - * @return ParameterContainer */ public function merge($parameters) { - if (!is_array($parameters) && !$parameters instanceof ParameterContainer) { - throw new Exception\InvalidArgumentException('$parameters must be an array or an instance of ParameterContainer'); + if (! is_array($parameters) && ! $parameters instanceof ParameterContainer) { + throw new Exception\InvalidArgumentException( + '$parameters must be an array or an instance of ParameterContainer' + ); } if (count($parameters) == 0) { diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Platform/AbstractPlatform.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/AbstractPlatform.php new file mode 100644 index 00000000..42b88575 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/AbstractPlatform.php @@ -0,0 +1,142 @@ +quoteIdentifiers) { + return $identifier; + } + + $safeWordsInt = ['*' => true, ' ' => true, '.' => true, 'as' => true]; + + foreach ($safeWords as $sWord) { + $safeWordsInt[strtolower($sWord)] = true; + } + + $parts = preg_split( + $this->quoteIdentifierFragmentPattern, + $identifier, + -1, + PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY + ); + + $identifier = ''; + + foreach ($parts as $part) { + $identifier .= isset($safeWordsInt[strtolower($part)]) + ? $part + : $this->quoteIdentifier[0] + . str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $part) + . $this->quoteIdentifier[1]; + } + + return $identifier; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifier($identifier) + { + if (! $this->quoteIdentifiers) { + return $identifier; + } + + return $this->quoteIdentifier[0] + . str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $identifier) + . $this->quoteIdentifier[1]; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifierChain($identifierChain) + { + return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"'; + } + + /** + * {@inheritDoc} + */ + public function getQuoteIdentifierSymbol() + { + return $this->quoteIdentifier[0]; + } + + /** + * {@inheritDoc} + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * {@inheritDoc} + */ + public function quoteValue($value) + { + trigger_error( + 'Attempting to quote a value in ' . get_class($this) . + ' without extension/driver support can introduce security vulnerabilities in a production environment' + ); + return '\'' . addcslashes((string) $value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * {@inheritDoc} + */ + public function quoteTrustedValue($value) + { + return '\'' . addcslashes((string) $value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * {@inheritDoc} + */ + public function quoteValueList($valueList) + { + return implode(', ', array_map([$this, 'quoteValue'], (array) $valueList)); + } + + /** + * {@inheritDoc} + */ + public function getIdentifierSeparator() + { + return '.'; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Platform/IbmDb2.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/IbmDb2.php new file mode 100644 index 00000000..7b22b0fa --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/IbmDb2.php @@ -0,0 +1,125 @@ +quoteIdentifiers = false; + } + + if (isset($options['identifier_separator'])) { + $this->identifierSeparator = $options['identifier_separator']; + } + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'IBM DB2'; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = []) + { + if (! $this->quoteIdentifiers) { + return $identifier; + } + $safeWordsInt = ['*' => true, ' ' => true, '.' => true, 'as' => true]; + foreach ($safeWords as $sWord) { + $safeWordsInt[strtolower($sWord)] = true; + } + $parts = preg_split( + '/([^0-9,a-z,A-Z$#_:])/i', + $identifier, + -1, + PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY + ); + $identifier = ''; + foreach ($parts as $part) { + $identifier .= isset($safeWordsInt[strtolower($part)]) + ? $part + : $this->quoteIdentifier[0] + . str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $part) + . $this->quoteIdentifier[1]; + } + return $identifier; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifierChain($identifierChain) + { + if ($this->quoteIdentifiers === false) { + if (is_array($identifierChain)) { + return implode($this->identifierSeparator, $identifierChain); + } else { + return $identifierChain; + } + } + $identifierChain = str_replace('"', '\\"', $identifierChain); + if (is_array($identifierChain)) { + $identifierChain = implode('"' . $this->identifierSeparator . '"', $identifierChain); + } + return '"' . $identifierChain . '"'; + } + + /** + * {@inheritDoc} + */ + public function quoteValue($value) + { + if (function_exists('db2_escape_string')) { + return '\'' . db2_escape_string($value) . '\''; + } + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + return '\'' . str_replace("'", "''", $value) . '\''; + } + + /** + * {@inheritDoc} + */ + public function quoteTrustedValue($value) + { + if (function_exists('db2_escape_string')) { + return '\'' . db2_escape_string($value) . '\''; + } + return '\'' . str_replace("'", "''", $value) . '\''; + } + + /** + * {@inheritDoc} + */ + public function getIdentifierSeparator() + { + return $this->identifierSeparator; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Mysql.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Mysql.php new file mode 100644 index 00000000..3aae7bbc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Mysql.php @@ -0,0 +1,122 @@ +setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo|\mysqli|\PDO $driver + * @return self Provides a fluent interface + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function setDriver($driver) + { + // handle Zend\Db drivers + if ($driver instanceof Mysqli\Mysqli + || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Mysql') + || ($driver instanceof \mysqli) + || ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql') + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException( + '$driver must be a Mysqli or Mysql PDO Zend\Db\Adapter\Driver, Mysqli instance or MySQL PDO instance' + ); + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'MySQL'; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifierChain($identifierChain) + { + return '`' . implode('`.`', (array) str_replace('`', '``', $identifierChain)) . '`'; + } + + /** + * {@inheritDoc} + */ + public function quoteValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \mysqli) { + return '\'' . $this->resource->real_escape_string($value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return parent::quoteValue($value); + } + + /** + * {@inheritDoc} + */ + public function quoteTrustedValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \mysqli) { + return '\'' . $this->resource->real_escape_string($value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return parent::quoteTrustedValue($value); + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Oracle.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Oracle.php new file mode 100644 index 00000000..7d66f937 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Oracle.php @@ -0,0 +1,129 @@ +quoteIdentifiers = false; + } + + if ($driver) { + $this->setDriver($driver); + } + } + + /** + * @param Pdo|Oci8 $driver + * @return self Provides a fluent interface + * @throws InvalidArgumentException + */ + public function setDriver($driver) + { + if ($driver instanceof Oci8 + || ($driver instanceof Pdo && $driver->getDatabasePlatformName() == 'Oracle') + || ($driver instanceof Pdo && $driver->getDatabasePlatformName() == 'Sqlite') + || ($driver instanceof \oci8) + || ($driver instanceof PDO && $driver->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') + ) { + $this->resource = $driver; + return $this; + } + + throw new InvalidArgumentException( + '$driver must be a Oci8 or Oracle PDO Zend\Db\Adapter\Driver, ' + . 'Oci8 instance, or Oci PDO instance' + ); + } + + /** + * @return null|Pdo|Oci8 + */ + public function getDriver() + { + return $this->resource; + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'Oracle'; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifierChain($identifierChain) + { + if ($this->quoteIdentifiers === false) { + return implode('.', (array) $identifierChain); + } + + return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"'; + } + + /** + * {@inheritDoc} + */ + public function quoteValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + + if ($this->resource) { + if ($this->resource instanceof PDO) { + return $this->resource->quote($value); + } + + if (get_resource_type($this->resource) == 'oci8 connection' + || get_resource_type($this->resource) == 'oci8 persistent connection' + ) { + return "'" . addcslashes(str_replace("'", "''", $value), "\x00\n\r\"\x1a") . "'"; + } + } + + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + + return "'" . addcslashes(str_replace("'", "''", $value), "\x00\n\r\"\x1a") . "'"; + } + + /** + * {@inheritDoc} + */ + public function quoteTrustedValue($value) + { + return "'" . addcslashes(str_replace('\'', '\'\'', $value), "\x00\n\r\"\x1a") . "'"; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/PlatformInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/PlatformInterface.php similarity index 95% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/PlatformInterface.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Platform/PlatformInterface.php index 2eddb8e7..917fccf9 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Platform/PlatformInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/PlatformInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -90,5 +90,5 @@ interface PlatformInterface * @param array $additionalSafeWords * @return string */ - public function quoteIdentifierInFragment($identifier, array $additionalSafeWords = array()); + public function quoteIdentifierInFragment($identifier, array $additionalSafeWords = []); } diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Postgresql.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Postgresql.php new file mode 100644 index 00000000..b844f2ef --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Postgresql.php @@ -0,0 +1,112 @@ +setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Pgsql\Pgsql|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver + * @return self Provides a fluent interface + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function setDriver($driver) + { + if ($driver instanceof Pgsql\Pgsql + || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Postgresql') + || (is_resource($driver) && (in_array(get_resource_type($driver), ['pgsql link', 'pgsql link persistent']))) + || ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql') + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException( + '$driver must be a Pgsql or Postgresql PDO Zend\Db\Adapter\Driver, pgsql link resource or Postgresql PDO ' + . 'instance' + ); + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'PostgreSQL'; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifierChain($identifierChain) + { + return '"' . implode('"."', (array) str_replace('"', '""', $identifierChain)) . '"'; + } + + /** + * {@inheritDoc} + */ + public function quoteValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if (is_resource($this->resource)) { + return '\'' . pg_escape_string($this->resource, $value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return 'E' . parent::quoteValue($value); + } + + /** + * {@inheritDoc} + */ + public function quoteTrustedValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if (is_resource($this->resource)) { + return '\'' . pg_escape_string($this->resource, $value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return 'E' . parent::quoteTrustedValue($value); + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sql92.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sql92.php new file mode 100644 index 00000000..81b7e0a2 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sql92.php @@ -0,0 +1,33 @@ +setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver + * @return self Provides a fluent interface + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function setDriver($driver) + { + // handle Zend\Db drivers + if (($driver instanceof Pdo\Pdo && in_array($driver->getDatabasePlatformName(), ['SqlServer', 'Dblib'])) + || ($driver instanceof \PDO && in_array($driver->getAttribute(\PDO::ATTR_DRIVER_NAME), ['sqlsrv', 'dblib'])) + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException( + '$driver must be a Sqlsrv PDO Zend\Db\Adapter\Driver or Sqlsrv PDO instance' + ); + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'SQLServer'; + } + + /** + * {@inheritDoc} + */ + public function getQuoteIdentifierSymbol() + { + return $this->quoteIdentifier; + } + + /** + * {@inheritDoc} + */ + public function quoteIdentifierChain($identifierChain) + { + return '[' . implode('].[', (array) $identifierChain) . ']'; + } + + /** + * {@inheritDoc} + */ + public function quoteValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + + return '\'' . str_replace('\'', '\'\'', addcslashes($value, "\000\032")) . '\''; + } + + /** + * {@inheritDoc} + */ + public function quoteTrustedValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return '\'' . str_replace('\'', '\'\'', $value) . '\''; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sqlite.php b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sqlite.php new file mode 100644 index 00000000..9253baba --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Platform/Sqlite.php @@ -0,0 +1,105 @@ +setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Pdo\Pdo|\PDO $driver + * @return self Provides a fluent interface + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function setDriver($driver) + { + if (($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlite') + || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlite') + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException( + '$driver must be a Sqlite PDO Zend\Db\Adapter\Driver, Sqlite PDO instance' + ); + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'SQLite'; + } + + /** + * {@inheritDoc} + */ + public function quoteValue($value) + { + $resource = $this->resource; + + if ($resource instanceof DriverInterface) { + $resource = $resource->getConnection()->getResource(); + } + + if ($resource instanceof \PDO) { + return $resource->quote($value); + } + + return parent::quoteValue($value); + } + + /** + * {@inheritDoc} + */ + public function quoteTrustedValue($value) + { + $resource = $this->resource; + + if ($resource instanceof DriverInterface) { + $resource = $resource->getConnection()->getResource(); + } + + if ($resource instanceof \PDO) { + return $resource->quote($value); + } + + return parent::quoteTrustedValue($value); + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/Profiler.php b/bundled-libs/zendframework/zend-db/src/Adapter/Profiler/Profiler.php similarity index 65% rename from bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/Profiler.php rename to bundled-libs/zendframework/zend-db/src/Adapter/Profiler/Profiler.php index 504f8226..a853e83d 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Adapter/Profiler/Profiler.php +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Profiler/Profiler.php @@ -1,4 +1,11 @@ '', 'parameters' => null, 'start' => microtime(true), 'end' => null, 'elapse' => null - ); + ]; if ($target instanceof StatementContainerInterface) { $profileInformation['sql'] = $target->getSql(); $profileInformation['parameters'] = clone $target->getParameterContainer(); } elseif (is_string($target)) { $profileInformation['sql'] = $target; } else { - throw new Exception\InvalidArgumentException(__FUNCTION__ . ' takes either a StatementContainer or a string'); + throw new Exception\InvalidArgumentException( + __FUNCTION__ . ' takes either a StatementContainer or a string' + ); } $this->profiles[$this->currentIndex] = $profileInformation; @@ -46,12 +55,14 @@ class Profiler implements ProfilerInterface } /** - * @return Profiler + * @return self Provides a fluent interface */ public function profilerFinish() { - if (!isset($this->profiles[$this->currentIndex])) { - throw new Exception\RuntimeException('A profile must be started before ' . __FUNCTION__ . ' can be called.'); + if (! isset($this->profiles[$this->currentIndex])) { + throw new Exception\RuntimeException( + 'A profile must be started before ' . __FUNCTION__ . ' can be called.' + ); } $current = &$this->profiles[$this->currentIndex]; $current['end'] = microtime(true); diff --git a/bundled-libs/zendframework/zend-db/src/Adapter/Profiler/ProfilerAwareInterface.php b/bundled-libs/zendframework/zend-db/src/Adapter/Profiler/ProfilerAwareInterface.php new file mode 100644 index 00000000..ce47219b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Adapter/Profiler/ProfilerAwareInterface.php @@ -0,0 +1,18 @@ + $this->getDependencyConfig(), + ]; + } + + /** + * Retrieve zend-db default dependency configuration. + * + * @return array + */ + public function getDependencyConfig() + { + return [ + 'abstract_factories' => [ + Adapter\AdapterAbstractServiceFactory::class, + ], + 'factories' => [ + Adapter\AdapterInterface::class => Adapter\AdapterServiceFactory::class, + ], + 'aliases' => [ + Adapter\Adapter::class => Adapter\AdapterInterface::class, + ], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/ErrorException.php b/bundled-libs/zendframework/zend-db/src/Exception/ErrorException.php similarity index 84% rename from bundled-libs/zendframework/zend-db/Zend/Db/Exception/ErrorException.php rename to bundled-libs/zendframework/zend-db/src/Exception/ErrorException.php index 478ac1f9..95860433 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/ErrorException.php +++ b/bundled-libs/zendframework/zend-db/src/Exception/ErrorException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/ExceptionInterface.php b/bundled-libs/zendframework/zend-db/src/Exception/ExceptionInterface.php similarity index 82% rename from bundled-libs/zendframework/zend-db/Zend/Db/Exception/ExceptionInterface.php rename to bundled-libs/zendframework/zend-db/src/Exception/ExceptionInterface.php index 17e22a03..cf364c4c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/ExceptionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/InvalidArgumentException.php b/bundled-libs/zendframework/zend-db/src/Exception/InvalidArgumentException.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Exception/InvalidArgumentException.php rename to bundled-libs/zendframework/zend-db/src/Exception/InvalidArgumentException.php index f48c46bf..040788a4 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/InvalidArgumentException.php +++ b/bundled-libs/zendframework/zend-db/src/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/RuntimeException.php b/bundled-libs/zendframework/zend-db/src/Exception/RuntimeException.php similarity index 84% rename from bundled-libs/zendframework/zend-db/Zend/Db/Exception/RuntimeException.php rename to bundled-libs/zendframework/zend-db/src/Exception/RuntimeException.php index 7f6517ad..63d07130 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/RuntimeException.php +++ b/bundled-libs/zendframework/zend-db/src/Exception/RuntimeException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/UnexpectedValueException.php b/bundled-libs/zendframework/zend-db/src/Exception/UnexpectedValueException.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Exception/UnexpectedValueException.php rename to bundled-libs/zendframework/zend-db/src/Exception/UnexpectedValueException.php index 2b80c015..9de43efa 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Exception/UnexpectedValueException.php +++ b/bundled-libs/zendframework/zend-db/src/Exception/UnexpectedValueException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Metadata.php b/bundled-libs/zendframework/zend-db/src/Metadata/Metadata.php similarity index 50% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Metadata.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Metadata.php index 4ad80169..c00cdfcf 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Metadata.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Metadata.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,15 +11,11 @@ namespace Zend\Db\Metadata; use Zend\Db\Adapter\Adapter; +/** + * @deprecated Use Zend\Db\Metadata\Source\Factory::createSourceFromAdapter($adapter) + */ class Metadata implements MetadataInterface { - /** - * Adapter - * - * @var Adapter - */ - protected $adapter = null; - /** * @var MetadataInterface */ @@ -32,40 +28,11 @@ class Metadata implements MetadataInterface */ public function __construct(Adapter $adapter) { - $this->adapter = $adapter; - $this->source = $this->createSourceFromAdapter($adapter); + $this->source = Source\Factory::createSourceFromAdapter($adapter); } /** - * Create source from adapter - * - * @param Adapter $adapter - * @return Source\AbstractSource - */ - protected function createSourceFromAdapter(Adapter $adapter) - { - switch ($adapter->getPlatform()->getName()) { - case 'MySQL': - return new Source\MysqlMetadata($adapter); - case 'SQLServer': - return new Source\SqlServerMetadata($adapter); - case 'SQLite': - return new Source\SqliteMetadata($adapter); - case 'PostgreSQL': - return new Source\PostgresqlMetadata($adapter); - } - - throw new \Exception('cannot create source from adapter'); - } - - // @todo methods - - /** - * Get base tables and views - * - * @param string $schema - * @param bool $includeViews - * @return Object\TableObject[] + * {@inheritdoc} */ public function getTables($schema = null, $includeViews = false) { @@ -73,10 +40,7 @@ class Metadata implements MetadataInterface } /** - * Get base tables and views - * - * @param string $schema - * @return Object\TableObject[] + * {@inheritdoc} */ public function getViews($schema = null) { @@ -84,10 +48,7 @@ class Metadata implements MetadataInterface } /** - * Get triggers - * - * @param string $schema - * @return array + * {@inheritdoc} */ public function getTriggers($schema = null) { @@ -95,11 +56,7 @@ class Metadata implements MetadataInterface } /** - * Get constraints - * - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getConstraints($table, $schema = null) { @@ -107,11 +64,7 @@ class Metadata implements MetadataInterface } /** - * Get columns - * - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getColumns($table, $schema = null) { @@ -119,12 +72,7 @@ class Metadata implements MetadataInterface } /** - * Get constraint keys - * - * @param string $constraint - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getConstraintKeys($constraint, $table, $schema = null) { @@ -132,12 +80,7 @@ class Metadata implements MetadataInterface } /** - * Get constraints - * - * @param string $constraintName - * @param string $table - * @param string $schema - * @return Object\ConstraintObject + * {@inheritdoc} */ public function getConstraint($constraintName, $table, $schema = null) { @@ -145,7 +88,7 @@ class Metadata implements MetadataInterface } /** - * Get schemas + * {@inheritdoc} */ public function getSchemas() { @@ -153,11 +96,7 @@ class Metadata implements MetadataInterface } /** - * Get table names - * - * @param string $schema - * @param bool $includeViews - * @return array + * {@inheritdoc} */ public function getTableNames($schema = null, $includeViews = false) { @@ -165,11 +104,7 @@ class Metadata implements MetadataInterface } /** - * Get table - * - * @param string $tableName - * @param string $schema - * @return Object\TableObject + * {@inheritdoc} */ public function getTable($tableName, $schema = null) { @@ -177,22 +112,15 @@ class Metadata implements MetadataInterface } /** - * Get views names - * - * @param string $schema - * @return \Zend\Db\Metadata\Object\TableObject + * {@inheritdoc} */ public function getViewNames($schema = null) { - return $this->source->getTable($schema); + return $this->source->getViewNames($schema); } /** - * Get view - * - * @param string $viewName - * @param string $schema - * @return \Zend\Db\Metadata\Object\TableObject + * {@inheritdoc} */ public function getView($viewName, $schema = null) { @@ -200,10 +128,7 @@ class Metadata implements MetadataInterface } /** - * Get trigger names - * - * @param string $schema - * @return array + * {@inheritdoc} */ public function getTriggerNames($schema = null) { @@ -211,11 +136,7 @@ class Metadata implements MetadataInterface } /** - * Get trigger - * - * @param string $triggerName - * @param string $schema - * @return \Zend\Db\Metadata\Object\TriggerObject + * {@inheritdoc} */ public function getTrigger($triggerName, $schema = null) { @@ -223,11 +144,7 @@ class Metadata implements MetadataInterface } /** - * Get column names - * - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getColumnNames($table, $schema = null) { @@ -235,12 +152,7 @@ class Metadata implements MetadataInterface } /** - * Get column - * - * @param string $columnName - * @param string $table - * @param string $schema - * @return \Zend\Db\Metadata\Object\ColumnObject + * {@inheritdoc} */ public function getColumn($columnName, $table, $schema = null) { diff --git a/bundled-libs/zendframework/zend-db/src/Metadata/MetadataInterface.php b/bundled-libs/zendframework/zend-db/src/Metadata/MetadataInterface.php new file mode 100644 index 00000000..5a395be2 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Metadata/MetadataInterface.php @@ -0,0 +1,154 @@ +errata)) { return $this->errata[$errataName]; } - return null; + return; } /** * @param string $errataName * @param mixed $errataValue - * @return ColumnObject + * @return self Provides a fluent interface */ public function setErrata($errataName, $errataValue) { diff --git a/bundled-libs/zendframework/zend-db/src/Metadata/Object/ConstraintKeyObject.php b/bundled-libs/zendframework/zend-db/src/Metadata/Object/ConstraintKeyObject.php new file mode 100644 index 00000000..9bed4bff --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Object/ConstraintKeyObject.php @@ -0,0 +1,249 @@ +setColumnName($column); + } + + /** + * Get column name + * + * @return string + */ + public function getColumnName() + { + return $this->columnName; + } + + /** + * Set column name + * + * @param string $columnName + * @return self Provides a fluent interface + */ + public function setColumnName($columnName) + { + $this->columnName = $columnName; + return $this; + } + + /** + * Get ordinal position + * + * @return int + */ + public function getOrdinalPosition() + { + return $this->ordinalPosition; + } + + /** + * Set ordinal position + * + * @param int $ordinalPosition + * @return self Provides a fluent interface + */ + public function setOrdinalPosition($ordinalPosition) + { + $this->ordinalPosition = $ordinalPosition; + return $this; + } + + /** + * Get position in unique constraint + * + * @return bool + */ + public function getPositionInUniqueConstraint() + { + return $this->positionInUniqueConstraint; + } + + /** + * Set position in unique constraint + * + * @param bool $positionInUniqueConstraint + * @return self Provides a fluent interface + */ + public function setPositionInUniqueConstraint($positionInUniqueConstraint) + { + $this->positionInUniqueConstraint = $positionInUniqueConstraint; + return $this; + } + + /** + * Get referencred table schema + * + * @return string + */ + public function getReferencedTableSchema() + { + return $this->referencedTableSchema; + } + + /** + * Set referenced table schema + * + * @param string $referencedTableSchema + * @return self Provides a fluent interface + */ + public function setReferencedTableSchema($referencedTableSchema) + { + $this->referencedTableSchema = $referencedTableSchema; + return $this; + } + + /** + * Get referenced table name + * + * @return string + */ + public function getReferencedTableName() + { + return $this->referencedTableName; + } + + /** + * Set Referenced table name + * + * @param string $referencedTableName + * @return self Provides a fluent interface + */ + public function setReferencedTableName($referencedTableName) + { + $this->referencedTableName = $referencedTableName; + return $this; + } + + /** + * Get referenced column name + * + * @return string + */ + public function getReferencedColumnName() + { + return $this->referencedColumnName; + } + + /** + * Set referenced column name + * + * @param string $referencedColumnName + * @return self Provides a fluent interface + */ + public function setReferencedColumnName($referencedColumnName) + { + $this->referencedColumnName = $referencedColumnName; + return $this; + } + + /** + * set foreign key update rule + * + * @param string $foreignKeyUpdateRule + */ + public function setForeignKeyUpdateRule($foreignKeyUpdateRule) + { + $this->foreignKeyUpdateRule = $foreignKeyUpdateRule; + } + + /** + * Get foreign key update rule + * + * @return string + */ + public function getForeignKeyUpdateRule() + { + return $this->foreignKeyUpdateRule; + } + + /** + * Set foreign key delete rule + * + * @param string $foreignKeyDeleteRule + */ + public function setForeignKeyDeleteRule($foreignKeyDeleteRule) + { + $this->foreignKeyDeleteRule = $foreignKeyDeleteRule; + } + + /** + * get foreign key delete rule + * + * @return string + */ + public function getForeignKeyDeleteRule() + { + return $this->foreignKeyDeleteRule; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintObject.php b/bundled-libs/zendframework/zend-db/src/Metadata/Object/ConstraintObject.php similarity index 92% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintObject.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Object/ConstraintObject.php index 655dd974..15f79729 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintObject.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Object/ConstraintObject.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -41,7 +41,7 @@ class ConstraintObject * * @var string[] */ - protected $columns = array(); + protected $columns = []; /** * @@ -160,7 +160,7 @@ class ConstraintObject * Set table name * * @param string $tableName - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setTableName($tableName) { @@ -190,7 +190,7 @@ class ConstraintObject public function hasColumns() { - return (!empty($this->columns)); + return (! empty($this->columns)); } /** @@ -207,7 +207,7 @@ class ConstraintObject * Set Columns. * * @param string[] $columns - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setColumns(array $columns) { @@ -229,7 +229,7 @@ class ConstraintObject * Set Referenced Table Schema. * * @param string $referencedTableSchema - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setReferencedTableSchema($referencedTableSchema) { @@ -251,7 +251,7 @@ class ConstraintObject * Set Referenced Table Name. * * @param string $referencedTableName - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setReferencedTableName($referencedTableName) { @@ -273,7 +273,7 @@ class ConstraintObject * Set Referenced Columns. * * @param string[] $referencedColumns - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setReferencedColumns(array $referencedColumns) { @@ -295,7 +295,7 @@ class ConstraintObject * Set Match Option. * * @param string $matchOption - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setMatchOption($matchOption) { @@ -317,7 +317,7 @@ class ConstraintObject * Set Update Rule. * * @param string $updateRule - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setUpdateRule($updateRule) { @@ -339,7 +339,7 @@ class ConstraintObject * Set Delete Rule. * * @param string $deleteRule - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setDeleteRule($deleteRule) { @@ -361,7 +361,7 @@ class ConstraintObject * Set Check Clause. * * @param string $checkClause - * @return ConstraintObject + * @return self Provides a fluent interface */ public function setCheckClause($checkClause) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/TableObject.php b/bundled-libs/zendframework/zend-db/src/Metadata/Object/TableObject.php similarity index 83% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/TableObject.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Object/TableObject.php index cc5ea2e3..291796ea 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/TableObject.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Object/TableObject.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/TriggerObject.php b/bundled-libs/zendframework/zend-db/src/Metadata/Object/TriggerObject.php similarity index 90% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/TriggerObject.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Object/TriggerObject.php index 360e0dec..62a00286 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/TriggerObject.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Object/TriggerObject.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -130,7 +130,7 @@ class TriggerObject * Set Name. * * @param string $name - * @return TriggerObject + * @return self Provides a fluent interface */ public function setName($name) { @@ -152,7 +152,7 @@ class TriggerObject * Set Event Manipulation. * * @param string $eventManipulation - * @return TriggerObject + * @return self Provides a fluent interface */ public function setEventManipulation($eventManipulation) { @@ -174,7 +174,7 @@ class TriggerObject * Set Event Object Catalog. * * @param string $eventObjectCatalog - * @return TriggerObject + * @return self Provides a fluent interface */ public function setEventObjectCatalog($eventObjectCatalog) { @@ -196,7 +196,7 @@ class TriggerObject * Set Event Object Schema. * * @param string $eventObjectSchema - * @return TriggerObject + * @return self Provides a fluent interface */ public function setEventObjectSchema($eventObjectSchema) { @@ -218,7 +218,7 @@ class TriggerObject * Set Event Object Table. * * @param string $eventObjectTable - * @return TriggerObject + * @return self Provides a fluent interface */ public function setEventObjectTable($eventObjectTable) { @@ -240,7 +240,7 @@ class TriggerObject * Set Action Order. * * @param string $actionOrder - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionOrder($actionOrder) { @@ -262,7 +262,7 @@ class TriggerObject * Set Action Condition. * * @param string $actionCondition - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionCondition($actionCondition) { @@ -284,7 +284,7 @@ class TriggerObject * Set Action Statement. * * @param string $actionStatement - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionStatement($actionStatement) { @@ -306,7 +306,7 @@ class TriggerObject * Set Action Orientation. * * @param string $actionOrientation - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionOrientation($actionOrientation) { @@ -328,7 +328,7 @@ class TriggerObject * Set Action Timing. * * @param string $actionTiming - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionTiming($actionTiming) { @@ -350,7 +350,7 @@ class TriggerObject * Set Action Reference Old Table. * * @param string $actionReferenceOldTable - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionReferenceOldTable($actionReferenceOldTable) { @@ -372,7 +372,7 @@ class TriggerObject * Set Action Reference New Table. * * @param string $actionReferenceNewTable - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionReferenceNewTable($actionReferenceNewTable) { @@ -394,7 +394,7 @@ class TriggerObject * Set Action Reference Old Row. * * @param string $actionReferenceOldRow - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionReferenceOldRow($actionReferenceOldRow) { @@ -416,7 +416,7 @@ class TriggerObject * Set Action Reference New Row. * * @param string $actionReferenceNewRow - * @return TriggerObject + * @return self Provides a fluent interface */ public function setActionReferenceNewRow($actionReferenceNewRow) { @@ -438,7 +438,7 @@ class TriggerObject * Set Created. * * @param \DateTime $created - * @return TriggerObject + * @return self Provides a fluent interface */ public function setCreated($created) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/ViewObject.php b/bundled-libs/zendframework/zend-db/src/Metadata/Object/ViewObject.php similarity index 87% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/ViewObject.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Object/ViewObject.php index f4b29ec6..e0b5bde1 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Object/ViewObject.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Object/ViewObject.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -25,7 +25,7 @@ class ViewObject extends AbstractTableObject /** * @param string $viewDefinition to set - * @return ViewObject + * @return self Provides a fluent interface */ public function setViewDefinition($viewDefinition) { @@ -43,7 +43,7 @@ class ViewObject extends AbstractTableObject /** * @param string $checkOption to set - * @return ViewObject + * @return self Provides a fluent interface */ public function setCheckOption($checkOption) { @@ -61,7 +61,7 @@ class ViewObject extends AbstractTableObject /** * @param bool $isUpdatable to set - * @return ViewObject + * @return self Provides a fluent interface */ public function setIsUpdatable($isUpdatable) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/AbstractSource.php b/bundled-libs/zendframework/zend-db/src/Metadata/Source/AbstractSource.php similarity index 81% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/AbstractSource.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Source/AbstractSource.php index 9e6c614b..0bd5c162 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/AbstractSource.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Source/AbstractSource.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,7 +11,12 @@ namespace Zend\Db\Metadata\Source; use Zend\Db\Adapter\Adapter; use Zend\Db\Metadata\MetadataInterface; -use Zend\Db\Metadata\Object; +use Zend\Db\Metadata\Object\TableObject; +use Zend\Db\Metadata\Object\ViewObject; +use Zend\Db\Metadata\Object\ColumnObject; +use Zend\Db\Metadata\Object\ConstraintObject; +use Zend\Db\Metadata\Object\ConstraintKeyObject; +use Zend\Db\Metadata\Object\TriggerObject; abstract class AbstractSource implements MetadataInterface { @@ -33,7 +38,7 @@ abstract class AbstractSource implements MetadataInterface * * @var array */ - protected $data = array(); + protected $data = []; /** * Constructor @@ -58,11 +63,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get table names - * - * @param string $schema - * @param bool $includeViews - * @return string[] + * {@inheritdoc} */ public function getTableNames($schema = null, $includeViews = false) { @@ -76,22 +77,17 @@ abstract class AbstractSource implements MetadataInterface return array_keys($this->data['table_names'][$schema]); } - $tableNames = array(); + $tableNames = []; foreach ($this->data['table_names'][$schema] as $tableName => $data) { if ('BASE TABLE' == $data['table_type']) { $tableNames[] = $tableName; } } return $tableNames; - } /** - * Get tables - * - * @param string $schema - * @param bool $includeViews - * @return Object\TableObject[] + * {@inheritdoc} */ public function getTables($schema = null, $includeViews = false) { @@ -99,7 +95,7 @@ abstract class AbstractSource implements MetadataInterface $schema = $this->defaultSchema; } - $tables = array(); + $tables = []; foreach ($this->getTableNames($schema, $includeViews) as $tableName) { $tables[] = $this->getTable($tableName, $schema); } @@ -107,11 +103,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get table - * - * @param string $tableName - * @param string $schema - * @return Object\TableObject + * {@inheritdoc} */ public function getTable($tableName, $schema = null) { @@ -121,23 +113,25 @@ abstract class AbstractSource implements MetadataInterface $this->loadTableNameData($schema); - if (!isset($this->data['table_names'][$schema][$tableName])) { + if (! isset($this->data['table_names'][$schema][$tableName])) { throw new \Exception('Table "' . $tableName . '" does not exist'); } $data = $this->data['table_names'][$schema][$tableName]; switch ($data['table_type']) { case 'BASE TABLE': - $table = new Object\TableObject($tableName); + $table = new TableObject($tableName); break; case 'VIEW': - $table = new Object\ViewObject($tableName); + $table = new ViewObject($tableName); $table->setViewDefinition($data['view_definition']); $table->setCheckOption($data['check_option']); $table->setIsUpdatable($data['is_updatable']); break; default: - throw new \Exception('Table "' . $tableName . '" is of an unsupported type "' . $data['table_type'] . '"'); + throw new \Exception( + 'Table "' . $tableName . '" is of an unsupported type "' . $data['table_type'] . '"' + ); } $table->setColumns($this->getColumns($tableName, $schema)); $table->setConstraints($this->getConstraints($tableName, $schema)); @@ -145,10 +139,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get view names - * - * @param string $schema - * @return array + * {@inheritdoc} */ public function getViewNames($schema = null) { @@ -158,7 +149,7 @@ abstract class AbstractSource implements MetadataInterface $this->loadTableNameData($schema); - $viewNames = array(); + $viewNames = []; foreach ($this->data['table_names'][$schema] as $tableName => $data) { if ('VIEW' == $data['table_type']) { $viewNames[] = $tableName; @@ -168,10 +159,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get views - * - * @param string $schema - * @return array + * {@inheritdoc} */ public function getViews($schema = null) { @@ -179,7 +167,7 @@ abstract class AbstractSource implements MetadataInterface $schema = $this->defaultSchema; } - $views = array(); + $views = []; foreach ($this->getViewNames($schema) as $tableName) { $views[] = $this->getTable($tableName, $schema); } @@ -187,11 +175,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get view - * - * @param string $viewName - * @param string $schema - * @return \Zend\Db\Metadata\Object\TableObject + * {@inheritdoc} */ public function getView($viewName, $schema = null) { @@ -209,11 +193,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Gt column names - * - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getColumnNames($table, $schema = null) { @@ -223,7 +203,7 @@ abstract class AbstractSource implements MetadataInterface $this->loadColumnData($table, $schema); - if (!isset($this->data['columns'][$schema][$table])) { + if (! isset($this->data['columns'][$schema][$table])) { throw new \Exception('"' . $table . '" does not exist'); } @@ -231,11 +211,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get columns - * - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getColumns($table, $schema = null) { @@ -245,7 +221,7 @@ abstract class AbstractSource implements MetadataInterface $this->loadColumnData($table, $schema); - $columns = array(); + $columns = []; foreach ($this->getColumnNames($table, $schema) as $columnName) { $columns[] = $this->getColumn($columnName, $table, $schema); } @@ -253,12 +229,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get column - * - * @param string $columnName - * @param string $table - * @param string $schema - * @return Object\ColumnObject + * {@inheritdoc} */ public function getColumn($columnName, $table, $schema = null) { @@ -268,19 +239,19 @@ abstract class AbstractSource implements MetadataInterface $this->loadColumnData($table, $schema); - if (!isset($this->data['columns'][$schema][$table][$columnName])) { + if (! isset($this->data['columns'][$schema][$table][$columnName])) { throw new \Exception('A column by that name was not found.'); } $info = $this->data['columns'][$schema][$table][$columnName]; - $column = new Object\ColumnObject($columnName, $table, $schema); - $props = array( + $column = new ColumnObject($columnName, $table, $schema); + $props = [ 'ordinal_position', 'column_default', 'is_nullable', 'data_type', 'character_maximum_length', 'character_octet_length', 'numeric_precision', 'numeric_scale', 'numeric_unsigned', 'erratas' - ); + ]; foreach ($props as $prop) { if (isset($info[$prop])) { $column->{'set' . str_replace('_', '', $prop)}($info[$prop]); @@ -302,11 +273,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get constraints - * - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getConstraints($table, $schema = null) { @@ -316,7 +283,7 @@ abstract class AbstractSource implements MetadataInterface $this->loadConstraintData($table, $schema); - $constraints = array(); + $constraints = []; foreach (array_keys($this->data['constraints'][$schema][$table]) as $constraintName) { $constraints[] = $this->getConstraint($constraintName, $table, $schema); } @@ -325,12 +292,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get constraint - * - * @param string $constraintName - * @param string $table - * @param string $schema - * @return Object\ConstraintObject + * {@inheritdoc} */ public function getConstraint($constraintName, $table, $schema = null) { @@ -340,14 +302,14 @@ abstract class AbstractSource implements MetadataInterface $this->loadConstraintData($table, $schema); - if (!isset($this->data['constraints'][$schema][$table][$constraintName])) { + if (! isset($this->data['constraints'][$schema][$table][$constraintName])) { throw new \Exception('Cannot find a constraint by that name in this table'); } $info = $this->data['constraints'][$schema][$table][$constraintName]; - $constraint = new Object\ConstraintObject($constraintName, $table, $schema); + $constraint = new ConstraintObject($constraintName, $table, $schema); - foreach (array( + foreach ([ 'constraint_type' => 'setType', 'match_option' => 'setMatchOption', 'update_rule' => 'setUpdateRule', @@ -357,7 +319,7 @@ abstract class AbstractSource implements MetadataInterface 'referenced_table_name' => 'setReferencedTableName', 'referenced_columns' => 'setReferencedColumns', 'check_clause' => 'setCheckClause', - ) as $key => $setMethod) { + ] as $key => $setMethod) { if (isset($info[$key])) { $constraint->{$setMethod}($info[$key]); } @@ -367,12 +329,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get constraint keys - * - * @param string $constraint - * @param string $table - * @param string $schema - * @return array + * {@inheritdoc} */ public function getConstraintKeys($constraint, $table, $schema = null) { @@ -383,7 +340,7 @@ abstract class AbstractSource implements MetadataInterface $this->loadConstraintReferences($table, $schema); // organize references first - $references = array(); + $references = []; foreach ($this->data['constraint_references'][$schema] as $refKeyInfo) { if ($refKeyInfo['constraint_name'] == $constraint) { $references[$refKeyInfo['constraint_name']] = $refKeyInfo; @@ -392,10 +349,10 @@ abstract class AbstractSource implements MetadataInterface $this->loadConstraintDataKeys($schema); - $keys = array(); + $keys = []; foreach ($this->data['constraint_keys'][$schema] as $constraintKeyInfo) { if ($constraintKeyInfo['table_name'] == $table && $constraintKeyInfo['constraint_name'] === $constraint) { - $keys[] = $key = new Object\ConstraintKeyObject($constraintKeyInfo['column_name']); + $keys[] = $key = new ConstraintKeyObject($constraintKeyInfo['column_name']); $key->setOrdinalPosition($constraintKeyInfo['ordinal_position']); if (isset($references[$constraint])) { //$key->setReferencedTableSchema($constraintKeyInfo['referenced_table_schema']); @@ -412,10 +369,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get trigger names - * - * @param string $schema - * @return array + * {@inheritdoc} */ public function getTriggerNames($schema = null) { @@ -429,10 +383,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get triggers - * - * @param string $schema - * @return array + * {@inheritdoc} */ public function getTriggers($schema = null) { @@ -440,7 +391,7 @@ abstract class AbstractSource implements MetadataInterface $schema = $this->defaultSchema; } - $triggers = array(); + $triggers = []; foreach ($this->getTriggerNames($schema) as $triggerName) { $triggers[] = $this->getTrigger($triggerName, $schema); } @@ -448,11 +399,7 @@ abstract class AbstractSource implements MetadataInterface } /** - * Get trigger - * - * @param string $triggerName - * @param string $schema - * @return Object\TriggerObject + * {@inheritdoc} */ public function getTrigger($triggerName, $schema = null) { @@ -462,13 +409,13 @@ abstract class AbstractSource implements MetadataInterface $this->loadTriggerData($schema); - if (!isset($this->data['triggers'][$schema][$triggerName])) { + if (! isset($this->data['triggers'][$schema][$triggerName])) { throw new \Exception('Trigger "' . $triggerName . '" does not exist'); } $info = $this->data['triggers'][$schema][$triggerName]; - $trigger = new Object\TriggerObject(); + $trigger = new TriggerObject(); $trigger->setName($triggerName); $trigger->setEventManipulation($info['event_manipulation']); @@ -499,8 +446,8 @@ abstract class AbstractSource implements MetadataInterface { $data = &$this->data; foreach (func_get_args() as $key) { - if (!isset($data[$key])) { - $data[$key] = array(); + if (! isset($data[$key])) { + $data[$key] = []; } $data = &$data[$key]; } diff --git a/bundled-libs/zendframework/zend-db/src/Metadata/Source/Factory.php b/bundled-libs/zendframework/zend-db/src/Metadata/Source/Factory.php new file mode 100644 index 00000000..fb8ec718 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Source/Factory.php @@ -0,0 +1,47 @@ +getPlatform()->getName(); + + switch ($platformName) { + case 'MySQL': + return new MysqlMetadata($adapter); + case 'SQLServer': + return new SqlServerMetadata($adapter); + case 'SQLite': + return new SqliteMetadata($adapter); + case 'PostgreSQL': + return new PostgresqlMetadata($adapter); + case 'Oracle': + return new OracleMetadata($adapter); + default: + throw new InvalidArgumentException("Unknown adapter platform '{$platformName}'"); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/MysqlMetadata.php b/bundled-libs/zendframework/zend-db/src/Metadata/Source/MysqlMetadata.php similarity index 52% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/MysqlMetadata.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Source/MysqlMetadata.php index 180e37da..c366fe99 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/MysqlMetadata.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Source/MysqlMetadata.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -23,13 +23,13 @@ class MysqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); $sql = 'SELECT ' . $p->quoteIdentifier('SCHEMA_NAME') - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'SCHEMATA')) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'SCHEMATA']) . ' WHERE ' . $p->quoteIdentifier('SCHEMA_NAME') . ' != \'INFORMATION_SCHEMA\''; $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $schemas = array(); + $schemas = []; foreach ($results->toArray() as $row) { $schemas[] = $row['SCHEMA_NAME']; } @@ -46,46 +46,48 @@ class MysqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( - array('T', 'TABLE_NAME'), - array('T', 'TABLE_TYPE'), - array('V', 'VIEW_DEFINITION'), - array('V', 'CHECK_OPTION'), - array('V', 'IS_UPDATABLE'), - ); + $isColumns = [ + ['T', 'TABLE_NAME'], + ['T', 'TABLE_TYPE'], + ['V', 'VIEW_DEFINITION'], + ['V', 'CHECK_OPTION'], + ['V', 'IS_UPDATABLE'], + ]; - array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'VIEWS')) . ' V' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_NAME')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'VIEWS']) . ' V' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['V', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['V', 'TABLE_NAME']) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $tables = array(); + $tables = []; foreach ($results->toArray() as $row) { - $tables[$row['TABLE_NAME']] = array( + $tables[$row['TABLE_NAME']] = [ 'table_type' => $row['TABLE_TYPE'], 'view_definition' => $row['VIEW_DEFINITION'], 'check_option' => $row['CHECK_OPTION'], 'is_updatable' => ('YES' == $row['IS_UPDATABLE']), - ); + ]; } $this->data['table_names'][$schema] = $tables; @@ -99,56 +101,64 @@ class MysqlMetadata extends AbstractSource $this->prepareDataHierarchy('columns', $schema, $table); $p = $this->adapter->getPlatform(); - $isColumns = array( - array('C', 'ORDINAL_POSITION'), - array('C', 'COLUMN_DEFAULT'), - array('C', 'IS_NULLABLE'), - array('C', 'DATA_TYPE'), - array('C', 'CHARACTER_MAXIMUM_LENGTH'), - array('C', 'CHARACTER_OCTET_LENGTH'), - array('C', 'NUMERIC_PRECISION'), - array('C', 'NUMERIC_SCALE'), - array('C', 'COLUMN_NAME'), - array('C', 'COLUMN_TYPE'), - ); + $isColumns = [ + ['C', 'ORDINAL_POSITION'], + ['C', 'COLUMN_DEFAULT'], + ['C', 'IS_NULLABLE'], + ['C', 'DATA_TYPE'], + ['C', 'CHARACTER_MAXIMUM_LENGTH'], + ['C', 'CHARACTER_OCTET_LENGTH'], + ['C', 'NUMERIC_PRECISION'], + ['C', 'NUMERIC_SCALE'], + ['C', 'COLUMN_NAME'], + ['C', 'COLUMN_TYPE'], + ]; - array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'COLUMNS')) . 'C' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_NAME')) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'COLUMNS']) . 'C' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['C', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['C', 'TABLE_NAME']) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')' - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) . ' = ' . $p->quoteTrustedValue($table); if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $columns = array(); + $columns = []; foreach ($results->toArray() as $row) { - $erratas = array(); - $matches = array(); + $erratas = []; + $matches = []; if (preg_match('/^(?:enum|set)\((.+)\)$/i', $row['COLUMN_TYPE'], $matches)) { $permittedValues = $matches[1]; - if (preg_match_all("/\\s*'((?:[^']++|'')*+)'\\s*(?:,|\$)/", $permittedValues, $matches, PREG_PATTERN_ORDER)) { + if (preg_match_all( + "/\\s*'((?:[^']++|'')*+)'\\s*(?:,|\$)/", + $permittedValues, + $matches, + PREG_PATTERN_ORDER + ) + ) { $permittedValues = str_replace("''", "'", $matches[1]); } else { - $permittedValues = array($permittedValues); + $permittedValues = [$permittedValues]; } $erratas['permitted_values'] = $permittedValues; } - $columns[$row['COLUMN_NAME']] = array( + $columns[$row['COLUMN_NAME']] = [ 'ordinal_position' => $row['ORDINAL_POSITION'], 'column_default' => $row['COLUMN_DEFAULT'], 'is_nullable' => ('YES' == $row['IS_NULLABLE']), @@ -159,7 +169,7 @@ class MysqlMetadata extends AbstractSource 'numeric_scale' => $row['NUMERIC_SCALE'], 'numeric_unsigned' => (false !== strpos($row['COLUMN_TYPE'], 'unsigned')), 'erratas' => $erratas, - ); + ]; } $this->data['columns'][$schema][$table] = $columns; @@ -173,18 +183,18 @@ class MysqlMetadata extends AbstractSource $this->prepareDataHierarchy('constraints', $schema, $table); - $isColumns = array( - array('T', 'TABLE_NAME'), - array('TC', 'CONSTRAINT_NAME'), - array('TC', 'CONSTRAINT_TYPE'), - array('KCU', 'COLUMN_NAME'), - array('RC', 'MATCH_OPTION'), - array('RC', 'UPDATE_RULE'), - array('RC', 'DELETE_RULE'), - array('KCU', 'REFERENCED_TABLE_SCHEMA'), - array('KCU', 'REFERENCED_TABLE_NAME'), - array('KCU', 'REFERENCED_COLUMN_NAME'), - ); + $isColumns = [ + ['T', 'TABLE_NAME'], + ['TC', 'CONSTRAINT_NAME'], + ['TC', 'CONSTRAINT_TYPE'], + ['KCU', 'COLUMN_NAME'], + ['RC', 'MATCH_OPTION'], + ['RC', 'UPDATE_RULE'], + ['RC', 'DELETE_RULE'], + ['KCU', 'REFERENCED_TABLE_SCHEMA'], + ['KCU', 'REFERENCED_TABLE_NAME'], + ['KCU', 'REFERENCED_COLUMN_NAME'], + ]; $p = $this->adapter->getPlatform(); @@ -193,54 +203,54 @@ class MysqlMetadata extends AbstractSource }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . ' T' + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . ' T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS')) . ' TC' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS']) . ' TC' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_NAME']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . ' KCU' - . ' ON ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) - . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'CONSTRAINT_NAME')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE']) . ' KCU' + . ' ON ' . $p->quoteIdentifierChain(['TC', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['TC', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_NAME']) + . ' AND ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'CONSTRAINT_NAME']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS')) . ' RC' - . ' ON ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_NAME')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS']) . ' RC' + . ' ON ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['RC', 'CONSTRAINT_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_NAME']) + . ' = ' . $p->quoteIdentifierChain(['RC', 'CONSTRAINT_NAME']) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) . ' = ' . $p->quoteTrustedValue($table) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } - $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_TYPE')) + $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_TYPE']) . " WHEN 'PRIMARY KEY' THEN 1" . " WHEN 'UNIQUE' THEN 2" . " WHEN 'FOREIGN KEY' THEN 3" . " ELSE 4 END" - . ', ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) - . ', ' . $p->quoteIdentifierChain(array('KCU', 'ORDINAL_POSITION')); + . ', ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_NAME']) + . ', ' . $p->quoteIdentifierChain(['KCU', 'ORDINAL_POSITION']); $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); $realName = null; - $constraints = array(); + $constraints = []; foreach ($results->toArray() as $row) { if ($row['CONSTRAINT_NAME'] !== $realName) { $realName = $row['CONSTRAINT_NAME']; @@ -250,16 +260,16 @@ class MysqlMetadata extends AbstractSource } else { $name = '_zf_' . $row['TABLE_NAME'] . '_' . $realName; } - $constraints[$name] = array( + $constraints[$name] = [ 'constraint_name' => $name, 'constraint_type' => $row['CONSTRAINT_TYPE'], 'table_name' => $row['TABLE_NAME'], - 'columns' => array(), - ); + 'columns' => [], + ]; if ($isFK) { $constraints[$name]['referenced_table_schema'] = $row['REFERENCED_TABLE_SCHEMA']; $constraints[$name]['referenced_table_name'] = $row['REFERENCED_TABLE_NAME']; - $constraints[$name]['referenced_columns'] = array(); + $constraints[$name]['referenced_columns'] = []; $constraints[$name]['match_option'] = $row['MATCH_OPTION']; $constraints[$name]['update_rule'] = $row['UPDATE_RULE']; $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; @@ -284,37 +294,37 @@ class MysqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( - array('TC', 'TABLE_NAME'), - array('TC', 'CONSTRAINT_NAME'), - array('TC', 'CONSTRAINT_TYPE'), - ); + $isColumns = [ + ['TC', 'TABLE_NAME'], + ['TC', 'CONSTRAINT_NAME'], + ['TC', 'CONSTRAINT_TYPE'], + ]; array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS')) . 'TC' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS']) . 'TC' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_NAME']) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $data = array(); + $data = []; foreach ($results->toArray() as $row) { $data[] = array_change_key_case($row, CASE_LOWER); } @@ -332,40 +342,40 @@ class MysqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( - array('T', 'TABLE_NAME'), - array('KCU', 'CONSTRAINT_NAME'), - array('KCU', 'COLUMN_NAME'), - array('KCU', 'ORDINAL_POSITION'), - ); + $isColumns = [ + ['T', 'TABLE_NAME'], + ['KCU', 'CONSTRAINT_NAME'], + ['KCU', 'COLUMN_NAME'], + ['KCU', 'ORDINAL_POSITION'], + ]; array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . 'KCU' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE']) . 'KCU' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_NAME']) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $data = array(); + $data = []; foreach ($results->toArray() as $row) { $data[] = array_change_key_case($row, CASE_LOWER); } @@ -379,51 +389,51 @@ class MysqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( - array('RC', 'TABLE_NAME'), - array('RC', 'CONSTRAINT_NAME'), - array('RC', 'UPDATE_RULE'), - array('RC', 'DELETE_RULE'), - array('KCU', 'REFERENCED_TABLE_SCHEMA'), - array('KCU', 'REFERENCED_TABLE_NAME'), - array('KCU', 'REFERENCED_COLUMN_NAME'), - ); + $isColumns = [ + ['RC', 'TABLE_NAME'], + ['RC', 'CONSTRAINT_NAME'], + ['RC', 'UPDATE_RULE'], + ['RC', 'DELETE_RULE'], + ['KCU', 'REFERENCED_TABLE_SCHEMA'], + ['KCU', 'REFERENCED_TABLE_NAME'], + ['KCU', 'REFERENCED_COLUMN_NAME'], + ]; array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); $sql = 'SELECT ' . implode(', ', $isColumns) - . 'FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + . 'FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS')) . 'RC' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('RC', 'TABLE_NAME')) + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS']) . 'RC' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['RC', 'CONSTRAINT_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['RC', 'TABLE_NAME']) - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . 'KCU' - . ' ON ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('RC', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) - . ' AND ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'CONSTRAINT_NAME')) + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE']) . 'KCU' + . ' ON ' . $p->quoteIdentifierChain(['RC', 'CONSTRAINT_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['RC', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_NAME']) + . ' AND ' . $p->quoteIdentifierChain(['RC', 'CONSTRAINT_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'CONSTRAINT_NAME']) - . 'WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . 'WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $data = array(); + $data = []; foreach ($results->toArray() as $row) { $data[] = array_change_key_case($row, CASE_LOWER); } @@ -441,7 +451,7 @@ class MysqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( + $isColumns = [ // 'TRIGGER_CATALOG', // 'TRIGGER_SCHEMA', 'TRIGGER_NAME', @@ -459,14 +469,14 @@ class MysqlMetadata extends AbstractSource 'ACTION_REFERENCE_OLD_ROW', 'ACTION_REFERENCE_NEW_ROW', 'CREATED', - ); + ]; array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifier($c); }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TRIGGERS')) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TRIGGERS']) . ' WHERE '; if ($schema != self::DEFAULT_SCHEMA) { @@ -479,7 +489,7 @@ class MysqlMetadata extends AbstractSource $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $data = array(); + $data = []; foreach ($results->toArray() as $row) { $row = array_change_key_case($row, CASE_LOWER); if (null !== $row['created']) { diff --git a/bundled-libs/zendframework/zend-db/src/Metadata/Source/OracleMetadata.php b/bundled-libs/zendframework/zend-db/src/Metadata/Source/OracleMetadata.php new file mode 100644 index 00000000..0ffa743d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Source/OracleMetadata.php @@ -0,0 +1,256 @@ + 'CHECK', + 'P' => 'PRIMARY KEY', + 'R' => 'FOREIGN_KEY' + ]; + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadColumnData() + */ + protected function loadColumnData($table, $schema) + { + if (isset($this->data['columns'][$schema][$table])) { + return; + } + + $isColumns = [ + 'COLUMN_ID', + 'COLUMN_NAME', + 'DATA_DEFAULT', + 'NULLABLE', + 'DATA_TYPE', + 'DATA_LENGTH', + 'DATA_PRECISION', + 'DATA_SCALE' + ]; + + $this->prepareDataHierarchy('columns', $schema, $table); + $parameters = [ + ':ownername' => $schema, + ':tablename' => $table + ]; + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM all_tab_columns' + . ' WHERE owner = :ownername AND table_name = :tablename'; + + $result = $this->adapter->query($sql)->execute($parameters); + $columns = []; + + foreach ($result as $row) { + $columns[$row['COLUMN_NAME']] = [ + 'ordinal_position' => $row['COLUMN_ID'], + 'column_default' => $row['DATA_DEFAULT'], + 'is_nullable' => ('Y' == $row['NULLABLE']), + 'data_type' => $row['DATA_TYPE'], + 'character_maximum_length' => $row['DATA_LENGTH'], + 'character_octet_length' => null, + 'numeric_precision' => $row['DATA_PRECISION'], + 'numeric_scale' => $row['DATA_SCALE'], + 'numeric_unsigned' => false, + 'erratas' => [], + ]; + } + + $this->data['columns'][$schema][$table] = $columns; + return $this; + } + + /** + * Constraint type + * + * @param string $type + * @return string + */ + protected function getConstraintType($type) + { + if (isset($this->constraintTypeMap[$type])) { + return $this->constraintTypeMap[$type]; + } + + return $type; + } + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadConstraintData() + */ + protected function loadConstraintData($table, $schema) + { + if (isset($this->data['constraints'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('constraints', $schema, $table); + $sql = ' + SELECT + ac.owner, + ac.constraint_name, + ac.constraint_type, + ac.search_condition check_clause, + ac.table_name, + ac.delete_rule, + cc1.column_name, + cc2.table_name as ref_table, + cc2.column_name as ref_column, + cc2.owner as ref_owner + FROM all_constraints ac + INNER JOIN all_cons_columns cc1 + ON cc1.constraint_name = ac.constraint_name + LEFT JOIN all_cons_columns cc2 + ON cc2.constraint_name = ac.r_constraint_name + AND cc2.position = cc1.position + + WHERE + ac.owner = :ownername AND ac.table_name = :tablename + + ORDER BY ac.constraint_name + '; + + $parameters = [ + ':ownername' => $schema, + ':tablename' => $table + ]; + + $results = $this->adapter->query($sql)->execute($parameters); + $isFK = false; + $name = null; + $constraints = []; + + foreach ($results as $row) { + if ($row['CONSTRAINT_NAME'] !== $name) { + $name = $row['CONSTRAINT_NAME']; + $constraints[$name] = [ + 'constraint_name' => $name, + 'constraint_type' => $this->getConstraintType($row['CONSTRAINT_TYPE']), + 'table_name' => $row['TABLE_NAME'], + ]; + + if ('C' == $row['CONSTRAINT_TYPE']) { + $constraints[$name]['CHECK_CLAUSE'] = $row['CHECK_CLAUSE']; + continue; + } + + $constraints[$name]['columns'] = []; + + $isFK = ('R' == $row['CONSTRAINT_TYPE']); + if ($isFK) { + $constraints[$name]['referenced_table_schema'] = $row['REF_OWNER']; + $constraints[$name]['referenced_table_name'] = $row['REF_TABLE']; + $constraints[$name]['referenced_columns'] = []; + $constraints[$name]['match_option'] = 'NONE'; + $constraints[$name]['update_rule'] = null; + $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; + } + } + + $constraints[$name]['columns'][] = $row['COLUMN_NAME']; + if ($isFK) { + $constraints[$name]['referenced_columns'][] = $row['REF_COLUMN']; + } + } + + return $this; + } + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadSchemaData() + */ + protected function loadSchemaData() + { + if (isset($this->data['schemas'])) { + return; + } + + $this->prepareDataHierarchy('schemas'); + $sql = 'SELECT USERNAME FROM ALL_USERS'; + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $schemas = []; + foreach ($results->toArray() as $row) { + $schemas[] = $row['USERNAME']; + } + + $this->data['schemas'] = $schemas; + } + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadTableNameData() + */ + protected function loadTableNameData($schema) + { + if (isset($this->data['table_names'][$schema])) { + return $this; + } + + $this->prepareDataHierarchy('table_names', $schema); + $tables = []; + + // Tables + $bind = [':OWNER' => strtoupper($schema)]; + $result = $this->adapter->query('SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER=:OWNER')->execute($bind); + + foreach ($result as $row) { + $tables[$row['TABLE_NAME']] = [ + 'table_type' => 'BASE TABLE', + 'view_definition' => null, + 'check_option' => null, + 'is_updatable' => false, + ]; + } + + // Views + $result = $this->adapter->query('SELECT VIEW_NAME, TEXT FROM ALL_VIEWS WHERE OWNER=:OWNER', $bind); + foreach ($result as $row) { + $tables[$row['VIEW_NAME']] = [ + 'table_type' => 'VIEW', + 'view_definition' => null, + 'check_option' => 'NONE', + 'is_updatable' => false, + ]; + } + + $this->data['table_names'][$schema] = $tables; + return $this; + } + + /** + * FIXME: load trigger data + * + * {@inheritdoc} + * + * @see \Zend\Db\Metadata\Source\AbstractSource::loadTriggerData() + */ + protected function loadTriggerData($schema) + { + if (isset($this->data['triggers'][$schema])) { + return; + } + + $this->prepareDataHierarchy('triggers', $schema); + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/PostgresqlMetadata.php b/bundled-libs/zendframework/zend-db/src/Metadata/Source/PostgresqlMetadata.php similarity index 58% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/PostgresqlMetadata.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Source/PostgresqlMetadata.php index b7545b00..8b43c7ef 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/PostgresqlMetadata.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Source/PostgresqlMetadata.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,7 +13,6 @@ use Zend\Db\Adapter\Adapter; class PostgresqlMetadata extends AbstractSource { - protected function loadSchemaData() { if (isset($this->data['schemas'])) { @@ -24,14 +23,14 @@ class PostgresqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); $sql = 'SELECT ' . $p->quoteIdentifier('schema_name') - . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'schemata')) + . ' FROM ' . $p->quoteIdentifierChain(['information_schema', 'schemata']) . ' WHERE ' . $p->quoteIdentifier('schema_name') . ' != \'information_schema\'' . ' AND ' . $p->quoteIdentifier('schema_name') . " NOT LIKE 'pg_%'"; $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $schemas = array(); + $schemas = []; foreach ($results->toArray() as $row) { $schemas[] = $row['schema_name']; } @@ -48,46 +47,48 @@ class PostgresqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( - array('t', 'table_name'), - array('t', 'table_type'), - array('v', 'view_definition'), - array('v', 'check_option'), - array('v', 'is_updatable'), - ); + $isColumns = [ + ['t', 'table_name'], + ['t', 'table_type'], + ['v', 'view_definition'], + ['v', 'check_option'], + ['v', 'is_updatable'], + ]; - array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'tables')) . ' t' + . ' FROM ' . $p->quoteIdentifierChain(['information_schema', 'tables']) . ' t' - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'views')) . ' v' - . ' ON ' . $p->quoteIdentifierChain(array('t', 'table_schema')) - . ' = ' . $p->quoteIdentifierChain(array('v', 'table_schema')) - . ' AND ' . $p->quoteIdentifierChain(array('t', 'table_name')) - . ' = ' . $p->quoteIdentifierChain(array('v', 'table_name')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['information_schema', 'views']) . ' v' + . ' ON ' . $p->quoteIdentifierChain(['t', 'table_schema']) + . ' = ' . $p->quoteIdentifierChain(['v', 'table_schema']) + . ' AND ' . $p->quoteIdentifierChain(['t', 'table_name']) + . ' = ' . $p->quoteIdentifierChain(['v', 'table_name']) - . ' WHERE ' . $p->quoteIdentifierChain(array('t', 'table_type')) + . ' WHERE ' . $p->quoteIdentifierChain(['t', 'table_type']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['t', 'table_schema']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['t', 'table_schema']) . ' != \'information_schema\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $tables = array(); + $tables = []; foreach ($results->toArray() as $row) { - $tables[$row['table_name']] = array( + $tables[$row['table_name']] = [ 'table_type' => $row['table_type'], 'view_definition' => $row['view_definition'], 'check_option' => $row['check_option'], 'is_updatable' => ('YES' == $row['is_updatable']), - ); + ]; } $this->data['table_names'][$schema] = $tables; @@ -103,7 +104,7 @@ class PostgresqlMetadata extends AbstractSource $platform = $this->adapter->getPlatform(); - $isColumns = array( + $isColumns = [ 'table_name', 'column_name', 'ordinal_position', @@ -114,9 +115,11 @@ class PostgresqlMetadata extends AbstractSource 'character_octet_length', 'numeric_precision', 'numeric_scale', - ); + ]; - array_walk($isColumns, function (&$c) use ($platform) { $c = $platform->quoteIdentifier($c); }); + array_walk($isColumns, function (&$c) use ($platform) { + $c = $platform->quoteIdentifier($c); + }); $sql = 'SELECT ' . implode(', ', $isColumns) . ' FROM ' . $platform->quoteIdentifier('information_schema') @@ -132,9 +135,9 @@ class PostgresqlMetadata extends AbstractSource } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $columns = array(); + $columns = []; foreach ($results->toArray() as $row) { - $columns[$row['column_name']] = array( + $columns[$row['column_name']] = [ 'ordinal_position' => $row['ordinal_position'], 'column_default' => $row['column_default'], 'is_nullable' => ('YES' == $row['is_nullable']), @@ -144,8 +147,8 @@ class PostgresqlMetadata extends AbstractSource 'numeric_precision' => $row['numeric_precision'], 'numeric_scale' => $row['numeric_scale'], 'numeric_unsigned' => null, - 'erratas' => array(), - ); + 'erratas' => [], + ]; } $this->data['columns'][$schema][$table] = $columns; @@ -159,19 +162,19 @@ class PostgresqlMetadata extends AbstractSource $this->prepareDataHierarchy('constraints', $schema, $table); - $isColumns = array( - array('t', 'table_name'), - array('tc', 'constraint_name'), - array('tc', 'constraint_type'), - array('kcu', 'column_name'), - array('cc', 'check_clause'), - array('rc', 'match_option'), - array('rc', 'update_rule'), - array('rc', 'delete_rule'), - array('referenced_table_schema' => 'kcu2', 'table_schema'), - array('referenced_table_name' => 'kcu2', 'table_name'), - array('referenced_column_name' => 'kcu2', 'column_name'), - ); + $isColumns = [ + ['t', 'table_name'], + ['tc', 'constraint_name'], + ['tc', 'constraint_type'], + ['kcu', 'column_name'], + ['cc', 'check_clause'], + ['rc', 'match_option'], + ['rc', 'update_rule'], + ['rc', 'delete_rule'], + ['referenced_table_schema' => 'kcu2', 'table_schema'], + ['referenced_table_name' => 'kcu2', 'table_name'], + ['referenced_column_name' => 'kcu2', 'column_name'], + ]; $p = $this->adapter->getPlatform(); @@ -184,86 +187,86 @@ class PostgresqlMetadata extends AbstractSource }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'tables')) . ' t' + . ' FROM ' . $p->quoteIdentifierChain(['information_schema', 'tables']) . ' t' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'table_constraints')) . ' tc' - . ' ON ' . $p->quoteIdentifierChain(array('t', 'table_schema')) - . ' = ' . $p->quoteIdentifierChain(array('tc', 'table_schema')) - . ' AND ' . $p->quoteIdentifierChain(array('t', 'table_name')) - . ' = ' . $p->quoteIdentifierChain(array('tc', 'table_name')) + . ' INNER JOIN ' . $p->quoteIdentifierChain(['information_schema', 'table_constraints']) . ' tc' + . ' ON ' . $p->quoteIdentifierChain(['t', 'table_schema']) + . ' = ' . $p->quoteIdentifierChain(['tc', 'table_schema']) + . ' AND ' . $p->quoteIdentifierChain(['t', 'table_name']) + . ' = ' . $p->quoteIdentifierChain(['tc', 'table_name']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'key_column_usage')) . ' kcu' - . ' ON ' . $p->quoteIdentifierChain(array('tc', 'table_schema')) - . ' = ' . $p->quoteIdentifierChain(array('kcu', 'table_schema')) - . ' AND ' . $p->quoteIdentifierChain(array('tc', 'table_name')) - . ' = ' . $p->quoteIdentifierChain(array('kcu', 'table_name')) - . ' AND ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) - . ' = ' . $p->quoteIdentifierChain(array('kcu', 'constraint_name')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['information_schema', 'key_column_usage']) . ' kcu' + . ' ON ' . $p->quoteIdentifierChain(['tc', 'table_schema']) + . ' = ' . $p->quoteIdentifierChain(['kcu', 'table_schema']) + . ' AND ' . $p->quoteIdentifierChain(['tc', 'table_name']) + . ' = ' . $p->quoteIdentifierChain(['kcu', 'table_name']) + . ' AND ' . $p->quoteIdentifierChain(['tc', 'constraint_name']) + . ' = ' . $p->quoteIdentifierChain(['kcu', 'constraint_name']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'check_constraints')) . ' cc' - . ' ON ' . $p->quoteIdentifierChain(array('tc', 'constraint_schema')) - . ' = ' . $p->quoteIdentifierChain(array('cc', 'constraint_schema')) - . ' AND ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) - . ' = ' . $p->quoteIdentifierChain(array('cc', 'constraint_name')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['information_schema', 'check_constraints']) . ' cc' + . ' ON ' . $p->quoteIdentifierChain(['tc', 'constraint_schema']) + . ' = ' . $p->quoteIdentifierChain(['cc', 'constraint_schema']) + . ' AND ' . $p->quoteIdentifierChain(['tc', 'constraint_name']) + . ' = ' . $p->quoteIdentifierChain(['cc', 'constraint_name']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'referential_constraints')) . ' rc' - . ' ON ' . $p->quoteIdentifierChain(array('tc', 'constraint_schema')) - . ' = ' . $p->quoteIdentifierChain(array('rc', 'constraint_schema')) - . ' AND ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) - . ' = ' . $p->quoteIdentifierChain(array('rc', 'constraint_name')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['information_schema', 'referential_constraints']) . ' rc' + . ' ON ' . $p->quoteIdentifierChain(['tc', 'constraint_schema']) + . ' = ' . $p->quoteIdentifierChain(['rc', 'constraint_schema']) + . ' AND ' . $p->quoteIdentifierChain(['tc', 'constraint_name']) + . ' = ' . $p->quoteIdentifierChain(['rc', 'constraint_name']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'key_column_usage')) . ' kcu2' - . ' ON ' . $p->quoteIdentifierChain(array('rc', 'unique_constraint_schema')) - . ' = ' . $p->quoteIdentifierChain(array('kcu2', 'constraint_schema')) - . ' AND ' . $p->quoteIdentifierChain(array('rc', 'unique_constraint_name')) - . ' = ' . $p->quoteIdentifierChain(array('kcu2', 'constraint_name')) - . ' AND ' . $p->quoteIdentifierChain(array('kcu', 'position_in_unique_constraint')) - . ' = ' . $p->quoteIdentifierChain(array('kcu2', 'ordinal_position')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['information_schema', 'key_column_usage']) . ' kcu2' + . ' ON ' . $p->quoteIdentifierChain(['rc', 'unique_constraint_schema']) + . ' = ' . $p->quoteIdentifierChain(['kcu2', 'constraint_schema']) + . ' AND ' . $p->quoteIdentifierChain(['rc', 'unique_constraint_name']) + . ' = ' . $p->quoteIdentifierChain(['kcu2', 'constraint_name']) + . ' AND ' . $p->quoteIdentifierChain(['kcu', 'position_in_unique_constraint']) + . ' = ' . $p->quoteIdentifierChain(['kcu2', 'ordinal_position']) - . ' WHERE ' . $p->quoteIdentifierChain(array('t', 'table_name')) + . ' WHERE ' . $p->quoteIdentifierChain(['t', 'table_name']) . ' = ' . $p->quoteTrustedValue($table) - . ' AND ' . $p->quoteIdentifierChain(array('t', 'table_type')) + . ' AND ' . $p->quoteIdentifierChain(['t', 'table_type']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['t', 'table_schema']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['t', 'table_schema']) . ' != \'information_schema\''; } - $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(array('tc', 'constraint_type')) + $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(['tc', 'constraint_type']) . " WHEN 'PRIMARY KEY' THEN 1" . " WHEN 'UNIQUE' THEN 2" . " WHEN 'FOREIGN KEY' THEN 3" . " WHEN 'CHECK' THEN 4" . " ELSE 5 END" - . ', ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) - . ', ' . $p->quoteIdentifierChain(array('kcu', 'ordinal_position')); + . ', ' . $p->quoteIdentifierChain(['tc', 'constraint_name']) + . ', ' . $p->quoteIdentifierChain(['kcu', 'ordinal_position']); $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); $name = null; - $constraints = array(); + $constraints = []; foreach ($results->toArray() as $row) { if ($row['constraint_name'] !== $name) { $name = $row['constraint_name']; - $constraints[$name] = array( + $constraints[$name] = [ 'constraint_name' => $name, 'constraint_type' => $row['constraint_type'], 'table_name' => $row['table_name'], - ); + ]; if ('CHECK' == $row['constraint_type']) { $constraints[$name]['check_clause'] = $row['check_clause']; continue; } - $constraints[$name]['columns'] = array(); + $constraints[$name]['columns'] = []; $isFK = ('FOREIGN KEY' == $row['constraint_type']); if ($isFK) { $constraints[$name]['referenced_table_schema'] = $row['referenced_table_schema']; $constraints[$name]['referenced_table_name'] = $row['referenced_table_name']; - $constraints[$name]['referenced_columns'] = array(); + $constraints[$name]['referenced_columns'] = []; $constraints[$name]['match_option'] = $row['match_option']; $constraints[$name]['update_rule'] = $row['update_rule']; $constraints[$name]['delete_rule'] = $row['delete_rule']; @@ -288,7 +291,7 @@ class PostgresqlMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( + $isColumns = [ 'trigger_name', 'event_manipulation', 'event_object_catalog', @@ -298,11 +301,11 @@ class PostgresqlMetadata extends AbstractSource 'action_condition', 'action_statement', 'action_orientation', - array('action_timing' => 'condition_timing'), - array('action_reference_old_table' => 'condition_reference_old_table'), - array('action_reference_new_table' => 'condition_reference_new_table'), + ['action_timing' => 'condition_timing'], + ['action_reference_old_table' => 'condition_reference_old_table'], + ['action_reference_new_table' => 'condition_reference_new_table'], 'created', - ); + ]; array_walk($isColumns, function (&$c) use ($p) { if (is_array($c)) { @@ -317,7 +320,7 @@ class PostgresqlMetadata extends AbstractSource }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'triggers')) + . ' FROM ' . $p->quoteIdentifierChain(['information_schema', 'triggers']) . ' WHERE '; if ($schema != self::DEFAULT_SCHEMA) { @@ -330,7 +333,7 @@ class PostgresqlMetadata extends AbstractSource $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $data = array(); + $data = []; foreach ($results->toArray() as $row) { $row = array_change_key_case($row, CASE_LOWER); $row['action_reference_old_row'] = 'OLD'; @@ -343,6 +346,4 @@ class PostgresqlMetadata extends AbstractSource $this->data['triggers'][$schema] = $data; } - - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/SqlServerMetadata.php b/bundled-libs/zendframework/zend-db/src/Metadata/Source/SqlServerMetadata.php similarity index 52% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/SqlServerMetadata.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Source/SqlServerMetadata.php index 186ef944..9cdad7f8 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/SqlServerMetadata.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Source/SqlServerMetadata.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,8 +13,6 @@ use Zend\Db\Adapter\Adapter; class SqlServerMetadata extends AbstractSource { - - protected function loadSchemaData() { if (isset($this->data['schemas'])) { @@ -25,13 +23,13 @@ class SqlServerMetadata extends AbstractSource $p = $this->adapter->getPlatform(); $sql = 'SELECT ' . $p->quoteIdentifier('SCHEMA_NAME') - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'SCHEMATA')) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'SCHEMATA']) . ' WHERE ' . $p->quoteIdentifier('SCHEMA_NAME') . ' != \'INFORMATION_SCHEMA\''; $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $schemas = array(); + $schemas = []; foreach ($results->toArray() as $row) { $schemas[] = $row['SCHEMA_NAME']; } @@ -48,46 +46,48 @@ class SqlServerMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( - array('T', 'TABLE_NAME'), - array('T', 'TABLE_TYPE'), - array('V', 'VIEW_DEFINITION'), - array('V', 'CHECK_OPTION'), - array('V', 'IS_UPDATABLE'), - ); + $isColumns = [ + ['T', 'TABLE_NAME'], + ['T', 'TABLE_TYPE'], + ['V', 'VIEW_DEFINITION'], + ['V', 'CHECK_OPTION'], + ['V', 'IS_UPDATABLE'], + ]; - array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . ' t' + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . ' t' - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'VIEWS')) . ' v' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_NAME')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'VIEWS']) . ' v' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['V', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['V', 'TABLE_NAME']) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $tables = array(); + $tables = []; foreach ($results->toArray() as $row) { - $tables[$row['TABLE_NAME']] = array( + $tables[$row['TABLE_NAME']] = [ 'table_type' => $row['TABLE_TYPE'], 'view_definition' => $row['VIEW_DEFINITION'], 'check_option' => $row['CHECK_OPTION'], 'is_updatable' => ('YES' == $row['IS_UPDATABLE']), - ); + ]; } $this->data['table_names'][$schema] = $tables; @@ -101,44 +101,46 @@ class SqlServerMetadata extends AbstractSource $this->prepareDataHierarchy('columns', $schema, $table); $p = $this->adapter->getPlatform(); - $isColumns = array( - array('C', 'ORDINAL_POSITION'), - array('C', 'COLUMN_DEFAULT'), - array('C', 'IS_NULLABLE'), - array('C', 'DATA_TYPE'), - array('C', 'CHARACTER_MAXIMUM_LENGTH'), - array('C', 'CHARACTER_OCTET_LENGTH'), - array('C', 'NUMERIC_PRECISION'), - array('C', 'NUMERIC_SCALE'), - array('C', 'COLUMN_NAME'), - ); + $isColumns = [ + ['C', 'ORDINAL_POSITION'], + ['C', 'COLUMN_DEFAULT'], + ['C', 'IS_NULLABLE'], + ['C', 'DATA_TYPE'], + ['C', 'CHARACTER_MAXIMUM_LENGTH'], + ['C', 'CHARACTER_OCTET_LENGTH'], + ['C', 'NUMERIC_PRECISION'], + ['C', 'NUMERIC_SCALE'], + ['C', 'COLUMN_NAME'], + ]; - array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'COLUMNS')) . 'C' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_NAME')) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'COLUMNS']) . 'C' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['C', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['C', 'TABLE_NAME']) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')' - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) . ' = ' . $p->quoteTrustedValue($table); if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $columns = array(); + $columns = []; foreach ($results->toArray() as $row) { - $columns[$row['COLUMN_NAME']] = array( + $columns[$row['COLUMN_NAME']] = [ 'ordinal_position' => $row['ORDINAL_POSITION'], 'column_default' => $row['COLUMN_DEFAULT'], 'is_nullable' => ('YES' == $row['IS_NULLABLE']), @@ -148,8 +150,8 @@ class SqlServerMetadata extends AbstractSource 'numeric_precision' => $row['NUMERIC_PRECISION'], 'numeric_scale' => $row['NUMERIC_SCALE'], 'numeric_unsigned' => null, - 'erratas' => array(), - ); + 'erratas' => [], + ]; } $this->data['columns'][$schema][$table] = $columns; @@ -163,19 +165,19 @@ class SqlServerMetadata extends AbstractSource $this->prepareDataHierarchy('constraints', $schema, $table); - $isColumns = array( - array('T', 'TABLE_NAME'), - array('TC', 'CONSTRAINT_NAME'), - array('TC', 'CONSTRAINT_TYPE'), - array('KCU', 'COLUMN_NAME'), - array('CC', 'CHECK_CLAUSE'), - array('RC', 'MATCH_OPTION'), - array('RC', 'UPDATE_RULE'), - array('RC', 'DELETE_RULE'), - array('REFERENCED_TABLE_SCHEMA' => 'KCU2', 'TABLE_SCHEMA'), - array('REFERENCED_TABLE_NAME' => 'KCU2', 'TABLE_NAME'), - array('REFERENCED_COLUMN_NAME' => 'KCU2', 'COLUMN_NAME'), - ); + $isColumns = [ + ['T', 'TABLE_NAME'], + ['TC', 'CONSTRAINT_NAME'], + ['TC', 'CONSTRAINT_TYPE'], + ['KCU', 'COLUMN_NAME'], + ['CC', 'CHECK_CLAUSE'], + ['RC', 'MATCH_OPTION'], + ['RC', 'UPDATE_RULE'], + ['RC', 'DELETE_RULE'], + ['REFERENCED_TABLE_SCHEMA' => 'KCU2', 'TABLE_SCHEMA'], + ['REFERENCED_TABLE_NAME' => 'KCU2', 'TABLE_NAME'], + ['REFERENCED_COLUMN_NAME' => 'KCU2', 'COLUMN_NAME'], + ]; $p = $this->adapter->getPlatform(); @@ -188,87 +190,87 @@ class SqlServerMetadata extends AbstractSource }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . ' T' + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . ' T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS')) . ' TC' - . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS']) . ' TC' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_NAME']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . ' KCU' - . ' ON ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) - . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU', 'CONSTRAINT_NAME')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE']) . ' KCU' + . ' ON ' . $p->quoteIdentifierChain(['TC', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['TC', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'TABLE_NAME']) + . ' AND ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU', 'CONSTRAINT_NAME']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'CHECK_CONSTRAINTS')) . ' CC' - . ' ON ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('CC', 'CONSTRAINT_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('CC', 'CONSTRAINT_NAME')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'CHECK_CONSTRAINTS']) . ' CC' + . ' ON ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['CC', 'CONSTRAINT_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_NAME']) + . ' = ' . $p->quoteIdentifierChain(['CC', 'CONSTRAINT_NAME']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS')) . ' RC' - . ' ON ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_NAME')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS']) . ' RC' + . ' ON ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['RC', 'CONSTRAINT_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_NAME']) + . ' = ' . $p->quoteIdentifierChain(['RC', 'CONSTRAINT_NAME']) - . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . ' KCU2' - . ' ON ' . $p->quoteIdentifierChain(array('RC', 'UNIQUE_CONSTRAINT_SCHEMA')) - . ' = ' . $p->quoteIdentifierChain(array('KCU2', 'CONSTRAINT_SCHEMA')) - . ' AND ' . $p->quoteIdentifierChain(array('RC', 'UNIQUE_CONSTRAINT_NAME')) - . ' = ' . $p->quoteIdentifierChain(array('KCU2', 'CONSTRAINT_NAME')) - . ' AND ' . $p->quoteIdentifierChain(array('KCU', 'ORDINAL_POSITION')) - . ' = ' . $p->quoteIdentifierChain(array('KCU2', 'ORDINAL_POSITION')) + . ' LEFT JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE']) . ' KCU2' + . ' ON ' . $p->quoteIdentifierChain(['RC', 'UNIQUE_CONSTRAINT_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['KCU2', 'CONSTRAINT_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['RC', 'UNIQUE_CONSTRAINT_NAME']) + . ' = ' . $p->quoteIdentifierChain(['KCU2', 'CONSTRAINT_NAME']) + . ' AND ' . $p->quoteIdentifierChain(['KCU', 'ORDINAL_POSITION']) + . ' = ' . $p->quoteIdentifierChain(['KCU2', 'ORDINAL_POSITION']) - . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) . ' = ' . $p->quoteTrustedValue($table) - . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; if ($schema != self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' != \'INFORMATION_SCHEMA\''; } - $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_TYPE')) + $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_TYPE']) . " WHEN 'PRIMARY KEY' THEN 1" . " WHEN 'UNIQUE' THEN 2" . " WHEN 'FOREIGN KEY' THEN 3" . " WHEN 'CHECK' THEN 4" . " ELSE 5 END" - . ', ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) - . ', ' . $p->quoteIdentifierChain(array('KCU', 'ORDINAL_POSITION')); + . ', ' . $p->quoteIdentifierChain(['TC', 'CONSTRAINT_NAME']) + . ', ' . $p->quoteIdentifierChain(['KCU', 'ORDINAL_POSITION']); $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); $name = null; - $constraints = array(); + $constraints = []; $isFK = false; foreach ($results->toArray() as $row) { if ($row['CONSTRAINT_NAME'] !== $name) { $name = $row['CONSTRAINT_NAME']; - $constraints[$name] = array( + $constraints[$name] = [ 'constraint_name' => $name, 'constraint_type' => $row['CONSTRAINT_TYPE'], 'table_name' => $row['TABLE_NAME'], - ); + ]; if ('CHECK' == $row['CONSTRAINT_TYPE']) { $constraints[$name]['check_clause'] = $row['CHECK_CLAUSE']; continue; } - $constraints[$name]['columns'] = array(); + $constraints[$name]['columns'] = []; $isFK = ('FOREIGN KEY' == $row['CONSTRAINT_TYPE']); if ($isFK) { $constraints[$name]['referenced_table_schema'] = $row['REFERENCED_TABLE_SCHEMA']; $constraints[$name]['referenced_table_name'] = $row['REFERENCED_TABLE_NAME']; - $constraints[$name]['referenced_columns'] = array(); + $constraints[$name]['referenced_columns'] = []; $constraints[$name]['match_option'] = $row['MATCH_OPTION']; $constraints[$name]['update_rule'] = $row['UPDATE_RULE']; $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; @@ -293,7 +295,7 @@ class SqlServerMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $isColumns = array( + $isColumns = [ 'TRIGGER_NAME', 'EVENT_MANIPULATION', 'EVENT_OBJECT_CATALOG', @@ -309,14 +311,14 @@ class SqlServerMetadata extends AbstractSource 'ACTION_REFERENCE_OLD_ROW', 'ACTION_REFERENCE_NEW_ROW', 'CREATED', - ); + ]; array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifier($c); }); $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TRIGGERS')) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TRIGGERS']) . ' WHERE '; if ($schema != self::DEFAULT_SCHEMA) { @@ -329,7 +331,7 @@ class SqlServerMetadata extends AbstractSource $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $data = array(); + $data = []; foreach ($results->toArray() as $row) { $row = array_change_key_case($row, CASE_LOWER); if (null !== $row['created']) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/SqliteMetadata.php b/bundled-libs/zendframework/zend-db/src/Metadata/Source/SqliteMetadata.php similarity index 83% rename from bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/SqliteMetadata.php rename to bundled-libs/zendframework/zend-db/src/Metadata/Source/SqliteMetadata.php index 46ef4f8b..b189c3b2 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Metadata/Source/SqliteMetadata.php +++ b/bundled-libs/zendframework/zend-db/src/Metadata/Source/SqliteMetadata.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -39,26 +39,26 @@ class SqliteMetadata extends AbstractSource $p = $this->adapter->getPlatform(); - $sql = 'SELECT "name", "type", "sql" FROM ' . $p->quoteIdentifierChain(array($schema, 'sqlite_master')) + $sql = 'SELECT "name", "type", "sql" FROM ' . $p->quoteIdentifierChain([$schema, 'sqlite_master']) . ' WHERE "type" IN (\'table\',\'view\') AND "name" NOT LIKE \'sqlite_%\''; $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $tables = array(); + $tables = []; foreach ($results->toArray() as $row) { if ('table' == $row['type']) { - $table = array( + $table = [ 'table_type' => 'BASE TABLE', 'view_definition' => null, // VIEW only 'check_option' => null, // VIEW only 'is_updatable' => null, // VIEW only - ); + ]; } else { - $table = array( + $table = [ 'table_type' => 'VIEW', 'view_definition' => null, 'check_option' => 'NONE', 'is_updatable' => false, - ); + ]; // Parse out extra data if (null !== ($data = $this->parseView($row['sql']))) { @@ -78,27 +78,24 @@ class SqliteMetadata extends AbstractSource $this->prepareDataHierarchy('columns', $schema, $table); $this->prepareDataHierarchy('sqlite_columns', $schema, $table); - $p = $this->adapter->getPlatform(); - - $results = $this->fetchPragma('table_info', $table, $schema); - $columns = array(); + $columns = []; foreach ($results as $row) { - $columns[$row['name']] = array( + $columns[$row['name']] = [ // cid appears to be zero-based, ordinal position needs to be one-based 'ordinal_position' => $row['cid'] + 1, 'column_default' => $row['dflt_value'], - 'is_nullable' => !((bool) $row['notnull']), + 'is_nullable' => ! ((bool) $row['notnull']), 'data_type' => $row['type'], 'character_maximum_length' => null, 'character_octet_length' => null, 'numeric_precision' => null, 'numeric_scale' => null, 'numeric_unsigned' => null, - 'erratas' => array(), - ); + 'erratas' => [], + ]; // TODO: populate character_ and numeric_values with correct info } @@ -115,7 +112,7 @@ class SqliteMetadata extends AbstractSource $this->prepareDataHierarchy('constraints', $schema, $table); $this->loadColumnData($table, $schema); - $primaryKey = array(); + $primaryKey = []; foreach ($this->data['sqlite_columns'][$schema][$table] as $col) { if ((bool) $col['pk']) { @@ -126,18 +123,18 @@ class SqliteMetadata extends AbstractSource if (empty($primaryKey)) { $primaryKey = null; } - $constraints = array(); + $constraints = []; $indexes = $this->fetchPragma('index_list', $table, $schema); foreach ($indexes as $index) { - if (!((bool) $index['unique'])) { + if (! ((bool) $index['unique'])) { continue; } - $constraint = array( + $constraint = [ 'constraint_name' => $index['name'], 'constraint_type' => 'UNIQUE', 'table_name' => $table, - 'columns' => array(), - ); + 'columns' => [], + ]; $info = $this->fetchPragma('index_info', $index['name'], $schema); @@ -153,12 +150,12 @@ class SqliteMetadata extends AbstractSource if (null !== $primaryKey) { $constraintName = '_zf_' . $table . '_PRIMARY'; - $constraints[$constraintName] = array( + $constraints[$constraintName] = [ 'constraint_name' => $constraintName, 'constraint_type' => 'PRIMARY KEY', 'table_name' => $table, 'columns' => $primaryKey, - ); + ]; } $foreignKeys = $this->fetchPragma('foreign_key_list', $table, $schema); @@ -168,19 +165,19 @@ class SqliteMetadata extends AbstractSource if ($id !== $fk['id']) { $id = $fk['id']; $name = '_zf_' . $table . '_FOREIGN_KEY_' . ($id + 1); - $constraints[$name] = array( + $constraints[$name] = [ 'constraint_name' => $name, 'constraint_type' => 'FOREIGN KEY', 'table_name' => $table, - 'columns' => array(), + 'columns' => [], 'referenced_table_schema' => $schema, 'referenced_table_name' => $fk['table'], - 'referenced_columns' => array(), + 'referenced_columns' => [], // TODO: Verify match, on_update, and on_delete values conform to SQL Standard 'match_option' => strtoupper($fk['match']), 'update_rule' => strtoupper($fk['on_update']), 'delete_rule' => strtoupper($fk['on_delete']), - ); + ]; } $constraints[$name]['columns'][] = $fk['from']; $constraints[$name]['referenced_columns'][] = $fk['to']; @@ -200,13 +197,13 @@ class SqliteMetadata extends AbstractSource $p = $this->adapter->getPlatform(); $sql = 'SELECT "name", "tbl_name", "sql" FROM ' - . $p->quoteIdentifierChain(array($schema, 'sqlite_master')) + . $p->quoteIdentifierChain([$schema, 'sqlite_master']) . ' WHERE "type" = \'trigger\''; $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); - $triggers = array(); + $triggers = []; foreach ($results->toArray() as $row) { - $trigger = array( + $trigger = [ 'trigger_name' => $row['name'], 'event_manipulation' => null, // in $row['sql'] 'event_object_catalog' => null, @@ -222,7 +219,7 @@ class SqliteMetadata extends AbstractSource 'action_reference_old_row' => 'OLD', 'action_reference_new_row' => 'NEW', 'created' => null, - ); + ]; // Parse out extra data if (null !== ($data = $this->parseTrigger($row['sql']))) { @@ -253,34 +250,32 @@ class SqliteMetadata extends AbstractSource if ($results instanceof ResultSetInterface) { return $results->toArray(); } - return array(); + return []; } protected function parseView($sql) { static $re = null; if (null === $re) { - $identifier = $this->getIdentifierRegularExpression(); - $identifierList = $this->getIdentifierListRegularExpression(); $identifierChain = $this->getIdentifierChainRegularExpression(); - $re = $this->buildRegularExpression(array( + $re = $this->buildRegularExpression([ 'CREATE', - array('TEMP|TEMPORARY'), + ['TEMP|TEMPORARY'], 'VIEW', - array('IF', 'NOT', 'EXISTS'), + ['IF', 'NOT', 'EXISTS'], $identifierChain, 'AS', '(?.+)', - array(';'), - )); + [';'], + ]); } - if (!preg_match($re, $sql, $matches)) { - return null; + if (! preg_match($re, $sql, $matches)) { + return; } - return array( + return [ 'view_definition' => $matches['view_definition'], - ); + ]; } protected function parseTrigger($sql) @@ -290,30 +285,30 @@ class SqliteMetadata extends AbstractSource $identifier = $this->getIdentifierRegularExpression(); $identifierList = $this->getIdentifierListRegularExpression(); $identifierChain = $this->getIdentifierChainRegularExpression(); - $re = $this->buildRegularExpression(array( + $re = $this->buildRegularExpression([ 'CREATE', - array('TEMP|TEMPORARY'), + ['TEMP|TEMPORARY'], 'TRIGGER', - array('IF', 'NOT', 'EXISTS'), + ['IF', 'NOT', 'EXISTS'], $identifierChain, - array('(?BEFORE|AFTER|INSTEAD\\s+OF)',), + ['(?BEFORE|AFTER|INSTEAD\\s+OF)', ], '(?DELETE|INSERT|UPDATE)', - array('OF', '(?' . $identifierList . ')'), + ['OF', '(?' . $identifierList . ')'], 'ON', '(?' . $identifier . ')', - array('FOR', 'EACH', 'ROW'), - array('WHEN', '(?.+)'), + ['FOR', 'EACH', 'ROW'], + ['WHEN', '(?.+)'], '(?BEGIN', '.+', 'END)', - array(';'), - )); + [';'], + ]); } - if (!preg_match($re, $sql, $matches)) { - return null; + if (! preg_match($re, $sql, $matches)) { + return; } - $data = array(); + $data = []; foreach ($matches as $key => $value) { if (is_string($key)) { @@ -327,7 +322,7 @@ class SqliteMetadata extends AbstractSource if (empty($data['action_condition'])) { $data['action_condition'] = null; } - if (!empty($data['action_timing'])) { + if (! empty($data['action_timing'])) { $data['action_timing'] = strtoupper($data['action_timing']); if ('I' == $data['action_timing'][0]) { // normalize the white-space between the two words @@ -359,12 +354,12 @@ class SqliteMetadata extends AbstractSource { static $re = null; if (null === $re) { - $re = '(?:' . implode('|', array( + $re = '(?:' . implode('|', [ '"(?:[^"\\\\]++|\\\\.)*+"', '`(?:[^`]++|``)*+`', '\\[[^\\]]+\\]', '[^\\s\\.]+', - )) . ')'; + ]) . ')'; } return $re; diff --git a/bundled-libs/zendframework/zend-db/src/Module.php b/bundled-libs/zendframework/zend-db/src/Module.php new file mode 100644 index 00000000..498c7dbf --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Module.php @@ -0,0 +1,24 @@ + $provider->getDependencyConfig(), + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/AbstractResultSet.php b/bundled-libs/zendframework/zend-db/src/ResultSet/AbstractResultSet.php similarity index 83% rename from bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/AbstractResultSet.php rename to bundled-libs/zendframework/zend-db/src/ResultSet/AbstractResultSet.php index 2e783738..912902ab 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/AbstractResultSet.php +++ b/bundled-libs/zendframework/zend-db/src/ResultSet/AbstractResultSet.php @@ -3,14 +3,13 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\ResultSet; use ArrayIterator; -use ArrayObject; use Countable; use Iterator; use IteratorAggregate; @@ -51,19 +50,18 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface /** * Set the data source for the result set * - * @param Iterator|IteratorAggregate|ResultInterface $dataSource - * @return ResultSet + * @param array|Iterator|IteratorAggregate|ResultInterface $dataSource + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException */ public function initialize($dataSource) { // reset buffering if (is_array($this->buffer)) { - $this->buffer = array(); + $this->buffer = []; } if ($dataSource instanceof ResultInterface) { - $this->count = $dataSource->count(); $this->fieldCount = $dataSource->getFieldCount(); $this->dataSource = $dataSource; if ($dataSource->isBuffered()) { @@ -79,8 +77,7 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface // its safe to get numbers from an array $first = current($dataSource); reset($dataSource); - $this->count = count($dataSource); - $this->fieldCount = count($first); + $this->fieldCount = $first === false ? 0 : count($first); $this->dataSource = new ArrayIterator($dataSource); $this->buffer = -1; // array's are a natural buffer } elseif ($dataSource instanceof IteratorAggregate) { @@ -88,22 +85,24 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface } elseif ($dataSource instanceof Iterator) { $this->dataSource = $dataSource; } else { - 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) { - $this->count = $this->dataSource->count(); + throw new Exception\InvalidArgumentException( + 'DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate' + ); } return $this; } + /** + * @return self Provides a fluent interface + * @throws Exception\RuntimeException + */ public function buffer() { if ($this->buffer === -2) { throw new Exception\RuntimeException('Buffering must be enabled before iteration is started'); } elseif ($this->buffer === null) { - $this->buffer = array(); + $this->buffer = []; if ($this->dataSource instanceof ResultInterface) { $this->dataSource->rewind(); } @@ -146,7 +145,7 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface } $dataSource->rewind(); - if (!$dataSource->valid()) { + if (! $dataSource->valid()) { $this->fieldCount = 0; return 0; } @@ -172,7 +171,9 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface if ($this->buffer === null) { $this->buffer = -2; // implicitly disable buffering from here on } - $this->dataSource->next(); + if (! is_array($this->buffer) || $this->position == $this->dataSource->key()) { + $this->dataSource->next(); + } $this->position++; } @@ -189,10 +190,15 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface /** * Iterator: get current item * - * @return array + * @return array|null */ public function current() { + if (-1 === $this->buffer) { + // datasource was an array when the resultset was initialized + return $this->dataSource->current(); + } + if ($this->buffer === null) { $this->buffer = -2; // implicitly disable buffering from here on } elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) { @@ -202,7 +208,7 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface if (is_array($this->buffer)) { $this->buffer[$this->position] = $data; } - return $data; + return is_array($data) ? $data : null; } /** @@ -230,7 +236,7 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface */ public function rewind() { - if (!is_array($this->buffer)) { + if (! is_array($this->buffer)) { if ($this->dataSource instanceof Iterator) { $this->dataSource->rewind(); } else { @@ -250,7 +256,11 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface if ($this->count !== null) { return $this->count; } - $this->count = count($this->dataSource); + + if ($this->dataSource instanceof Countable) { + $this->count = count($this->dataSource); + } + return $this->count; } @@ -262,13 +272,13 @@ abstract class AbstractResultSet implements Iterator, ResultSetInterface */ public function toArray() { - $return = array(); + $return = []; foreach ($this as $row) { if (is_array($row)) { $return[] = $row; } elseif (method_exists($row, 'toArray')) { $return[] = $row->toArray(); - } elseif ($row instanceof ArrayObject) { + } elseif (method_exists($row, 'getArrayCopy')) { $return[] = $row->getArrayCopy(); } else { throw new Exception\RuntimeException( diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/ExceptionInterface.php b/bundled-libs/zendframework/zend-db/src/ResultSet/Exception/ExceptionInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/ExceptionInterface.php rename to bundled-libs/zendframework/zend-db/src/ResultSet/Exception/ExceptionInterface.php index b54ce884..646aec4c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/ExceptionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/ResultSet/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/InvalidArgumentException.php b/bundled-libs/zendframework/zend-db/src/ResultSet/Exception/InvalidArgumentException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/InvalidArgumentException.php rename to bundled-libs/zendframework/zend-db/src/ResultSet/Exception/InvalidArgumentException.php index c50a5dc0..00d37614 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/InvalidArgumentException.php +++ b/bundled-libs/zendframework/zend-db/src/ResultSet/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/RuntimeException.php b/bundled-libs/zendframework/zend-db/src/ResultSet/Exception/RuntimeException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/RuntimeException.php rename to bundled-libs/zendframework/zend-db/src/ResultSet/Exception/RuntimeException.php index 081f4028..cd46b497 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/Exception/RuntimeException.php +++ b/bundled-libs/zendframework/zend-db/src/ResultSet/Exception/RuntimeException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/HydratingResultSet.php b/bundled-libs/zendframework/zend-db/src/ResultSet/HydratingResultSet.php similarity index 76% rename from bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/HydratingResultSet.php rename to bundled-libs/zendframework/zend-db/src/ResultSet/HydratingResultSet.php index d4d7b963..a30d4f57 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/HydratingResultSet.php +++ b/bundled-libs/zendframework/zend-db/src/ResultSet/HydratingResultSet.php @@ -3,15 +3,16 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\ResultSet; use ArrayObject; -use Zend\Stdlib\Hydrator\ArraySerializable; -use Zend\Stdlib\Hydrator\HydratorInterface; +use Zend\Hydrator\ArraySerializable; +use Zend\Hydrator\ArraySerializableHydrator; +use Zend\Hydrator\HydratorInterface; class HydratingResultSet extends AbstractResultSet { @@ -21,7 +22,7 @@ class HydratingResultSet extends AbstractResultSet protected $hydrator = null; /** - * @var null + * @var null|object */ protected $objectPrototype = null; @@ -33,7 +34,10 @@ class HydratingResultSet extends AbstractResultSet */ public function __construct(HydratorInterface $hydrator = null, $objectPrototype = null) { - $this->setHydrator(($hydrator) ?: new ArraySerializable); + $defaultHydratorClass = class_exists(ArraySerializableHydrator::class) + ? ArraySerializableHydrator::class + : ArraySerializable::class; + $this->setHydrator($hydrator ?: new $defaultHydratorClass()); $this->setObjectPrototype(($objectPrototype) ?: new ArrayObject); } @@ -41,12 +45,12 @@ class HydratingResultSet extends AbstractResultSet * Set the row object prototype * * @param object $objectPrototype + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException - * @return ResultSet */ public function setObjectPrototype($objectPrototype) { - if (!is_object($objectPrototype)) { + if (! is_object($objectPrototype)) { throw new Exception\InvalidArgumentException( 'An object must be set as the object prototype, a ' . gettype($objectPrototype) . ' was provided.' ); @@ -55,11 +59,21 @@ class HydratingResultSet extends AbstractResultSet return $this; } + /** + * Get the row object prototype + * + * @return object + */ + public function getObjectPrototype() + { + return $this->objectPrototype; + } + /** * Set the hydrator to use for each row object * * @param HydratorInterface $hydrator - * @return HydratingResultSet + * @return self Provides a fluent interface */ public function setHydrator(HydratorInterface $hydrator) { @@ -107,9 +121,9 @@ class HydratingResultSet extends AbstractResultSet */ public function toArray() { - $return = array(); + $return = []; foreach ($this as $row) { - $return[] = $this->getHydrator()->extract($row); + $return[] = $this->hydrator->extract($row); } return $return; } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/ResultSet.php b/bundled-libs/zendframework/zend-db/src/ResultSet/ResultSet.php similarity index 75% rename from bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/ResultSet.php rename to bundled-libs/zendframework/zend-db/src/ResultSet/ResultSet.php index f212a25d..ebbb455c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/ResultSet.php +++ b/bundled-libs/zendframework/zend-db/src/ResultSet/ResultSet.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -21,10 +21,10 @@ class ResultSet extends AbstractResultSet * * @var array */ - protected $allowedReturnTypes = array( + protected $allowedReturnTypes = [ self::TYPE_ARRAYOBJECT, self::TYPE_ARRAY, - ); + ]; /** * @var ArrayObject @@ -46,9 +46,13 @@ class ResultSet extends AbstractResultSet */ public function __construct($returnType = self::TYPE_ARRAYOBJECT, $arrayObjectPrototype = null) { - $this->returnType = (in_array($returnType, array(self::TYPE_ARRAY, self::TYPE_ARRAYOBJECT))) ? $returnType : self::TYPE_ARRAYOBJECT; + if (in_array($returnType, [self::TYPE_ARRAY, self::TYPE_ARRAYOBJECT])) { + $this->returnType = $returnType; + } else { + $this->returnType = self::TYPE_ARRAYOBJECT; + } if ($this->returnType === self::TYPE_ARRAYOBJECT) { - $this->setArrayObjectPrototype(($arrayObjectPrototype) ?: new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS)); + $this->setArrayObjectPrototype(($arrayObjectPrototype) ?: new ArrayObject([], ArrayObject::ARRAY_AS_PROPS)); } } @@ -56,16 +60,20 @@ class ResultSet extends AbstractResultSet * Set the row object prototype * * @param ArrayObject $arrayObjectPrototype + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException - * @return ResultSet */ public function setArrayObjectPrototype($arrayObjectPrototype) { - if (!is_object($arrayObjectPrototype) - || (!$arrayObjectPrototype instanceof ArrayObject && !method_exists($arrayObjectPrototype, 'exchangeArray')) - + if (! is_object($arrayObjectPrototype) + || ( + ! $arrayObjectPrototype instanceof ArrayObject + && ! method_exists($arrayObjectPrototype, 'exchangeArray') + ) ) { - throw new Exception\InvalidArgumentException('Object must be of type ArrayObject, or at least implement exchangeArray'); + throw new Exception\InvalidArgumentException( + 'Object must be of type ArrayObject, or at least implement exchangeArray' + ); } $this->arrayObjectPrototype = $arrayObjectPrototype; return $this; diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/ResultSetInterface.php b/bundled-libs/zendframework/zend-db/src/ResultSet/ResultSetInterface.php similarity index 82% rename from bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/ResultSetInterface.php rename to bundled-libs/zendframework/zend-db/src/ResultSet/ResultSetInterface.php index ca393e6b..5891dbfc 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/ResultSet/ResultSetInterface.php +++ b/bundled-libs/zendframework/zend-db/src/ResultSet/ResultSetInterface.php @@ -3,13 +3,16 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\ResultSet; -interface ResultSetInterface extends \Traversable, \Countable +use Countable; +use Traversable; + +interface ResultSetInterface extends Traversable, Countable { /** * Can be anything traversable|array diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/AbstractRowGateway.php b/bundled-libs/zendframework/zend-db/src/RowGateway/AbstractRowGateway.php similarity index 81% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/AbstractRowGateway.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/AbstractRowGateway.php index ffb816e0..89b2068f 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/AbstractRowGateway.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/AbstractRowGateway.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,7 +16,6 @@ use Zend\Db\Sql\TableIdentifier; abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayInterface { - /** * @var bool */ @@ -40,7 +39,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI /** * @var array */ - protected $data = array(); + protected $data = []; /** * @var Sql @@ -61,28 +60,28 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI return; } - if (!$this->featureSet instanceof Feature\FeatureSet) { + if (! $this->featureSet instanceof Feature\FeatureSet) { $this->featureSet = new Feature\FeatureSet; } $this->featureSet->setRowGateway($this); - $this->featureSet->apply('preInitialize', array()); + $this->featureSet->apply('preInitialize', []); - if (!is_string($this->table) && !$this->table instanceof TableIdentifier) { + if (! is_string($this->table) && ! $this->table instanceof TableIdentifier) { 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; } - if (!$this->sql instanceof Sql) { + if (! $this->sql instanceof Sql) { throw new Exception\RuntimeException('This row object does not have a Sql object set.'); } - $this->featureSet->apply('postInitialize', array()); + $this->featureSet->apply('postInitialize', []); $this->isInitialized = true; } @@ -92,7 +91,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI * * @param array $rowData * @param bool $rowExistsInDatabase - * @return AbstractRowGateway + * @return self Provides a fluent interface */ public function populate(array $rowData, $rowExistsInDatabase = false) { @@ -110,7 +109,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI /** * @param mixed $array - * @return array|void + * @return AbstractRowGateway */ public function exchangeArray($array) { @@ -127,17 +126,19 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI $this->initialize(); if ($this->rowExistsInDatabase()) { - // UPDATE $data = $this->data; - $where = array(); + $where = []; + $isPkModified = false; // primary key is always an array even if its a single column foreach ($this->primaryKeyColumn as $pkColumn) { $where[$pkColumn] = $this->primaryKeyData[$pkColumn]; if ($data[$pkColumn] == $this->primaryKeyData[$pkColumn]) { unset($data[$pkColumn]); + } else { + $isPkModified = true; } } @@ -146,8 +147,15 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI $rowsAffected = $result->getAffectedRows(); unset($statement, $result); // cleanup + // If one or more primary keys are modified, we update the where clause + if ($isPkModified) { + foreach ($this->primaryKeyColumn as $pkColumn) { + if ($data[$pkColumn] != $this->primaryKeyData[$pkColumn]) { + $where[$pkColumn] = $data[$pkColumn]; + } + } + } } else { - // INSERT $insert = $this->sql->insert(); $insert->values($this->data); @@ -156,7 +164,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI $result = $statement->execute(); if (($primaryKeyValue = $result->getGeneratedValue()) && count($this->primaryKeyColumn) == 1) { - $this->primaryKeyData = array($this->primaryKeyColumn[0] => $primaryKeyValue); + $this->primaryKeyData = [$this->primaryKeyColumn[0] => $primaryKeyValue]; } else { // make primary key data available so that $where can be complete $this->processPrimaryKeyData(); @@ -164,12 +172,11 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI $rowsAffected = $result->getAffectedRows(); unset($statement, $result); // cleanup - $where = array(); + $where = []; // primary key is always an array even if its a single column foreach ($this->primaryKeyColumn as $pkColumn) { $where[$pkColumn] = $this->primaryKeyData[$pkColumn]; } - } // refresh data @@ -194,7 +201,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI { $this->initialize(); - $where = array(); + $where = []; // primary key is always an array even if its a single column foreach ($this->primaryKeyColumn as $pkColumn) { $where[$pkColumn] = $this->primaryKeyData[$pkColumn]; @@ -241,7 +248,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI * * @param string $offset * @param mixed $value - * @return RowGateway + * @return self Provides a fluent interface */ public function offsetSet($offset, $value) { @@ -253,7 +260,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI * Offset unset * * @param string $offset - * @return AbstractRowGateway + * @return self Provides a fluent interface */ public function offsetUnset($offset) { @@ -283,6 +290,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI * __get * * @param string $name + * @throws Exception\InvalidArgumentException * @return mixed */ public function __get($name) @@ -290,7 +298,7 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI if (array_key_exists($name, $this->data)) { return $this->data[$name]; } else { - throw new \InvalidArgumentException('Not a valid column in this row: ' . $name); + throw new Exception\InvalidArgumentException('Not a valid column in this row: ' . $name); } } @@ -341,10 +349,12 @@ abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayI */ protected function processPrimaryKeyData() { - $this->primaryKeyData = array(); + $this->primaryKeyData = []; foreach ($this->primaryKeyColumn as $column) { - if (!isset($this->data[$column])) { - throw new Exception\RuntimeException('While processing primary key data, a known key ' . $column . ' was not found in the data array'); + if (! isset($this->data[$column])) { + throw new Exception\RuntimeException( + 'While processing primary key data, a known key ' . $column . ' was not found in the data array' + ); } $this->primaryKeyData[$column] = $this->data[$column]; } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/ExceptionInterface.php b/bundled-libs/zendframework/zend-db/src/RowGateway/Exception/ExceptionInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/ExceptionInterface.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/Exception/ExceptionInterface.php index c100f338..b3d11b4a 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/ExceptionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/InvalidArgumentException.php b/bundled-libs/zendframework/zend-db/src/RowGateway/Exception/InvalidArgumentException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/InvalidArgumentException.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/Exception/InvalidArgumentException.php index 1ae3e702..4b34d353 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/InvalidArgumentException.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/RuntimeException.php b/bundled-libs/zendframework/zend-db/src/RowGateway/Exception/RuntimeException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/RuntimeException.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/Exception/RuntimeException.php index a006f9db..6e53975b 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Exception/RuntimeException.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/Exception/RuntimeException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Feature/AbstractFeature.php b/bundled-libs/zendframework/zend-db/src/RowGateway/Feature/AbstractFeature.php similarity index 90% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Feature/AbstractFeature.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/Feature/AbstractFeature.php index 0bb91a66..9ff69c57 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Feature/AbstractFeature.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/Feature/AbstractFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ use Zend\Db\RowGateway\Exception; abstract class AbstractFeature extends AbstractRowGateway { - /** * @var AbstractRowGateway */ @@ -23,7 +22,7 @@ abstract class AbstractFeature extends AbstractRowGateway /** * @var array */ - protected $sharedData = array(); + protected $sharedData = []; /** * @return string @@ -54,6 +53,6 @@ abstract class AbstractFeature extends AbstractRowGateway */ public function getMagicMethodSpecifications() { - return array(); + return []; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Feature/FeatureSet.php b/bundled-libs/zendframework/zend-db/src/RowGateway/Feature/FeatureSet.php similarity index 83% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Feature/FeatureSet.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/Feature/FeatureSet.php index 9ded5351..f3c36a07 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/Feature/FeatureSet.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/Feature/FeatureSet.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -23,23 +23,27 @@ class FeatureSet /** * @var AbstractFeature[] */ - protected $features = array(); + protected $features = []; /** * @var array */ - protected $magicSpecifications = array(); + protected $magicSpecifications = []; /** * @param array $features */ - public function __construct(array $features = array()) + public function __construct(array $features = []) { if ($features) { $this->addFeatures($features); } } + /** + * @param AbstractRowGateway $rowGateway + * @return self Provides a fluent interface + */ public function setRowGateway(AbstractRowGateway $rowGateway) { $this->rowGateway = $rowGateway; @@ -61,6 +65,10 @@ class FeatureSet return $feature; } + /** + * @param array $features + * @return self Provides a fluent interface + */ public function addFeatures(array $features) { foreach ($features as $feature) { @@ -69,6 +77,10 @@ class FeatureSet return $this; } + /** + * @param AbstractFeature $feature + * @return self Provides a fluent interface + */ public function addFeature(AbstractFeature $feature) { $this->features[] = $feature; @@ -80,7 +92,7 @@ class FeatureSet { foreach ($this->features as $feature) { if (method_exists($feature, $method)) { - $return = call_user_func_array(array($feature, $method), $args); + $return = call_user_func_array([$feature, $method], $args); if ($return === self::APPLY_HALT) { break; } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/RowGateway.php b/bundled-libs/zendframework/zend-db/src/RowGateway/RowGateway.php similarity index 79% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/RowGateway.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/RowGateway.php index 7c9fc775..2248538e 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/RowGateway.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/RowGateway.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ use Zend\Db\Sql\Sql; class RowGateway extends AbstractRowGateway { - /** * Constructor * @@ -26,7 +25,7 @@ class RowGateway extends AbstractRowGateway public function __construct($primaryKeyColumn, $table, $adapterOrSql = null) { // setup primary key - $this->primaryKeyColumn = (array) $primaryKeyColumn; + $this->primaryKeyColumn = empty($primaryKeyColumn) ? null : (array) $primaryKeyColumn; // set table $this->table = $table; @@ -41,7 +40,9 @@ class RowGateway extends AbstractRowGateway } if ($this->sql->getTable() !== $this->table) { - throw new Exception\InvalidArgumentException('The Sql object provided does not have a table that matches this row object'); + throw new Exception\InvalidArgumentException( + 'The Sql object provided does not have a table that matches this row object' + ); } $this->initialize(); diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/RowGatewayInterface.php b/bundled-libs/zendframework/zend-db/src/RowGateway/RowGatewayInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/RowGatewayInterface.php rename to bundled-libs/zendframework/zend-db/src/RowGateway/RowGatewayInterface.php index 3ffb5d68..b623c4ed 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/RowGateway/RowGatewayInterface.php +++ b/bundled-libs/zendframework/zend-db/src/RowGateway/RowGatewayInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/src/Sql/AbstractExpression.php b/bundled-libs/zendframework/zend-db/src/Sql/AbstractExpression.php new file mode 100644 index 00000000..3fbee7c1 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/AbstractExpression.php @@ -0,0 +1,93 @@ +buildNormalizedArgument($argument, self::TYPE_VALUE); + } + + if (is_scalar($argument) || $argument === null) { + return $this->buildNormalizedArgument($argument, $defaultType); + } + + if (is_array($argument)) { + $value = current($argument); + + if ($value instanceof ExpressionInterface || $value instanceof SqlInterface) { + return $this->buildNormalizedArgument($value, self::TYPE_VALUE); + } + + $key = key($argument); + + if (is_integer($key) && ! in_array($value, $this->allowedTypes)) { + return $this->buildNormalizedArgument($value, $defaultType); + } + + return $this->buildNormalizedArgument($key, $value); + } + + throw new Exception\InvalidArgumentException(sprintf( + '$argument should be %s or %s or %s or %s or %s, "%s" given', + 'null', + 'scalar', + 'array', + 'Zend\Db\Sql\ExpressionInterface', + 'Zend\Db\Sql\SqlInterface', + is_object($argument) ? get_class($argument) : gettype($argument) + )); + } + + /** + * @param mixed $argument + * @param string $argumentType + * + * @return array + * + * @throws Exception\InvalidArgumentException + */ + private function buildNormalizedArgument($argument, $argumentType) + { + if (! in_array($argumentType, $this->allowedTypes)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Argument type should be in array(%s)', + implode(',', $this->allowedTypes) + )); + } + + return [ + $argument, + $argumentType, + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/AbstractPreparableSql.php b/bundled-libs/zendframework/zend-db/src/Sql/AbstractPreparableSql.php new file mode 100644 index 00000000..6d95f90d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/AbstractPreparableSql.php @@ -0,0 +1,39 @@ +getParameterContainer(); + + if (! $parameterContainer instanceof ParameterContainer) { + $parameterContainer = new ParameterContainer(); + + $statementContainer->setParameterContainer($parameterContainer); + } + + $statementContainer->setSql( + $this->buildSqlString($adapter->getPlatform(), $adapter->getDriver(), $parameterContainer) + ); + + return $statementContainer; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/AbstractSql.php b/bundled-libs/zendframework/zend-db/src/Sql/AbstractSql.php new file mode 100644 index 00000000..f8935ca4 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/AbstractSql.php @@ -0,0 +1,479 @@ + '', 'subselectCount' => 0]; + + /** + * @var array + */ + protected $instanceParameterIndex = []; + + /** + * {@inheritDoc} + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + $adapterPlatform = ($adapterPlatform) ?: new DefaultAdapterPlatform; + return $this->buildSqlString($adapterPlatform); + } + + /** + * @param PlatformInterface $platform + * @param null|DriverInterface $driver + * @param null|ParameterContainer $parameterContainer + * @return string + */ + protected function buildSqlString( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + $this->localizeVariables(); + + $sqls = []; + $parameters = []; + + foreach ($this->specifications as $name => $specification) { + $parameters[$name] = $this->{'process' . $name}( + $platform, + $driver, + $parameterContainer, + $sqls, + $parameters + ); + + if ($specification && is_array($parameters[$name])) { + $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); + + continue; + } + + if (is_string($parameters[$name])) { + $sqls[$name] = $parameters[$name]; + } + } + + return rtrim(implode(' ', $sqls), "\n ,"); + } + + /** + * Render table with alias in from/join parts + * + * @todo move TableIdentifier concatenation here + * @param string $table + * @param string $alias + * @return string + */ + protected function renderTable($table, $alias = null) + { + return $table . ($alias ? ' AS ' . $alias : ''); + } + + /** + * @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; + // 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 = ''; + + // initialize variables + $parts = $expression->getExpressionData(); + + if (! isset($this->instanceParameterIndex[$namedParameterPrefix])) { + $this->instanceParameterIndex[$namedParameterPrefix] = 1; + } + + $expressionParamIndex = &$this->instanceParameterIndex[$namedParameterPrefix]; + + foreach ($parts as $part) { + // #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; + } + + if (! is_array($part)) { + throw new Exception\RuntimeException( + 'Elements returned from getExpressionData() array must be a string or array.' + ); + } + + // Process values and types (the middle and last position of the + // expression data) + $values = $part[1]; + $types = isset($part[2]) ? $part[2] : []; + foreach ($values as $vIndex => $value) { + if (! isset($types[$vIndex])) { + continue; + } + $type = $types[$vIndex]; + if ($value instanceof Select) { + // process sub-select + $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' + ); + } elseif ($type == ExpressionInterface::TYPE_IDENTIFIER) { + $values[$vIndex] = $platform->quoteIdentifierInFragment($value); + } elseif ($type == ExpressionInterface::TYPE_VALUE) { + // if prepareType is set, it means that this particular value must be + // passed back to the statement in a way it can be used as a placeholder value + if ($parameterContainer) { + $name = $namedParameterPrefix . $expressionParamIndex++; + $parameterContainer->offsetSet($name, $value); + $values[$vIndex] = $driver->formatParameterName($name); + continue; + } + + // if not a preparable statement, simply quote the value and move on + $values[$vIndex] = $platform->quoteValue($value); + } elseif ($type == ExpressionInterface::TYPE_LITERAL) { + $values[$vIndex] = $value; + } + } + + // After looping the values, interpolate them into the sql string + // (they might be placeholder names, or values) + $sql .= vsprintf($part[0], $values); + } + + return $sql; + } + + /** + * @param string|array $specifications + * @param array $parameters + * + * @return string + * + * @throws Exception\RuntimeException + */ + protected function createSqlFromSpecificationAndParameters($specifications, $parameters) + { + if (is_string($specifications)) { + return vsprintf($specifications, $parameters); + } + + $parametersCount = count($parameters); + + foreach ($specifications as $specificationString => $paramSpecs) { + if ($parametersCount == count($paramSpecs)) { + break; + } + + unset($specificationString, $paramSpecs); + } + + if (! isset($specificationString)) { + throw new Exception\RuntimeException( + 'A number of parameters was found that is not supported by this specification' + ); + } + + $topParameters = []; + foreach ($parameters as $position => $paramsForPosition) { + if (isset($paramSpecs[$position]['combinedby'])) { + $multiParamValues = []; + foreach ($paramsForPosition as $multiParamsForPosition) { + if (is_array($multiParamsForPosition)) { + $ppCount = count($multiParamsForPosition); + } else { + $ppCount = 1; + } + + if (! isset($paramSpecs[$position][$ppCount])) { + 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); + } + $topParameters[] = implode($paramSpecs[$position]['combinedby'], $multiParamValues); + } elseif ($paramSpecs[$position] !== null) { + $ppCount = count($paramsForPosition); + if (! isset($paramSpecs[$position][$ppCount])) { + 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 { + $topParameters[] = $paramsForPosition; + } + } + return vsprintf($specificationString, $topParameters); + } + + /** + * @param Select $subselect + * @param PlatformInterface $platform + * @param null|DriverInterface $driver + * @param null|ParameterContainer $parameterContainer + * @return string + */ + protected function processSubSelect( + Select $subselect, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this instanceof PlatformDecoratorInterface) { + $decorator = clone $this; + $decorator->setSubject($subselect); + } else { + $decorator = $subselect; + } + + if ($parameterContainer) { + // Track subselect prefix and count for parameters + $processInfoContext = ($decorator instanceof PlatformDecoratorInterface) ? $subselect : $decorator; + $this->processInfo['subselectCount']++; + $processInfoContext->processInfo['subselectCount'] = $this->processInfo['subselectCount']; + $processInfoContext->processInfo['paramPrefix'] = 'subselect' + . $processInfoContext->processInfo['subselectCount']; + + $sql = $decorator->buildSqlString($platform, $driver, $parameterContainer); + + // copy count + $this->processInfo['subselectCount'] = $decorator->processInfo['subselectCount']; + return $sql; + } + + return $decorator->buildSqlString($platform, $driver, $parameterContainer); + } + + /** + * @param Join[] $joins + * @param PlatformInterface $platform + * @param null|DriverInterface $driver + * @param null|ParameterContainer $parameterContainer + * @return null|string[] Null if no joins present, array of JOIN statements + * otherwise + * @throws Exception\InvalidArgumentException for invalid JOIN table names. + */ + protected function processJoin( + Join $joins, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if (! $joins->count()) { + return; + } + + // process joins + $joinSpecArgArray = []; + foreach ($joins->getJoins() as $j => $join) { + $joinName = null; + $joinAs = null; + + // table name + if (is_array($join['name'])) { + $joinName = current($join['name']); + $joinAs = $platform->quoteIdentifier(key($join['name'])); + } else { + $joinName = $join['name']; + } + + if ($joinName instanceof Expression) { + $joinName = $joinName->getExpression(); + } elseif ($joinName instanceof TableIdentifier) { + $joinName = $joinName->getTableAndSchema(); + $joinName = ($joinName[1] + ? $platform->quoteIdentifier($joinName[1]) . $platform->getIdentifierSeparator() + : '') . $platform->quoteIdentifier($joinName[0]); + } elseif ($joinName instanceof Select) { + $joinName = '(' . $this->processSubSelect($joinName, $platform, $driver, $parameterContainer) . ')'; + } elseif (is_string($joinName) || (is_object($joinName) && is_callable([$joinName, '__toString']))) { + $joinName = $platform->quoteIdentifier($joinName); + } else { + throw new Exception\InvalidArgumentException(sprintf( + 'Join name expected to be Expression|TableIdentifier|Select|string, "%s" given', + gettype($joinName) + )); + } + + $joinSpecArgArray[$j] = [ + strtoupper($join['type']), + $this->renderTable($joinName, $joinAs), + ]; + + // on expression + // note: for Expression objects, pass them to processExpression with a prefix specific to each join + // (used for named parameters) + if (($join['on'] instanceof ExpressionInterface)) { + $joinSpecArgArray[$j][] = $this->processExpression( + $join['on'], + $platform, + $driver, + $parameterContainer, + 'join' . ($j + 1) . 'part' + ); + } else { + // on + $joinSpecArgArray[$j][] = $platform->quoteIdentifierInFragment( + $join['on'], + ['=', 'AND', 'OR', '(', ')', 'BETWEEN', '<', '>'] + ); + } + } + + return [$joinSpecArgArray]; + } + + /** + * @param null|array|ExpressionInterface|Select $column + * @param PlatformInterface $platform + * @param null|DriverInterface $driver + * @param null|string $namedParameterPrefix + * @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; + $isIdentifier = false; + $fromTable = ''; + if (is_array($column)) { + if (isset($column['isIdentifier'])) { + $isIdentifier = (bool) $column['isIdentifier']; + } + if (isset($column['fromTable']) && $column['fromTable'] !== null) { + $fromTable = $column['fromTable']; + } + $column = $column['column']; + } + + if ($column instanceof ExpressionInterface) { + return $this->processExpression($column, $platform, $driver, $parameterContainer, $namedParameterPrefix); + } + if ($column instanceof Select) { + return '(' . $this->processSubSelect($column, $platform, $driver, $parameterContainer) . ')'; + } + if ($column === null) { + return 'NULL'; + } + return $isIdentifier + ? $fromTable . $platform->quoteIdentifierInFragment($column) + : $platform->quoteValue($column); + } + + /** + * @param string|TableIdentifier|Select $table + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @return string + */ + protected function resolveTable( + $table, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + $schema = null; + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + if ($table instanceof Select) { + $table = '(' . $this->processSubselect($table, $platform, $driver, $parameterContainer) . ')'; + } elseif ($table) { + $table = $platform->quoteIdentifier($table); + } + + if ($schema && $table) { + $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; + } + return $table; + } + + /** + * Copy variables from the subject into the local properties + */ + protected function localizeVariables() + { + if (! $this instanceof PlatformDecoratorInterface) { + return; + } + + foreach (get_object_vars($this->subject) as $name => $value) { + $this->{$name} = $value; + } + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Combine.php b/bundled-libs/zendframework/zend-db/src/Sql/Combine.php new file mode 100644 index 00000000..bedb170f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Combine.php @@ -0,0 +1,212 @@ + '%1$s (%2$s) ', + ]; + + /** + * @var Select[][] + */ + private $combine = []; + + /** + * @param Select|array|null $select + * @param string $type + * @param string $modifier + */ + public function __construct($select = null, $type = self::COMBINE_UNION, $modifier = '') + { + if ($select) { + $this->combine($select, $type, $modifier); + } + } + + /** + * Create combine clause + * + * @param Select|array $select + * @param string $type + * @param string $modifier + * + * @return self Provides a fluent interface + * + * @throws Exception\InvalidArgumentException + */ + public function combine($select, $type = self::COMBINE_UNION, $modifier = '') + { + if (is_array($select)) { + foreach ($select as $combine) { + if ($combine instanceof Select) { + $combine = [$combine]; + } + + $this->combine( + $combine[0], + isset($combine[1]) ? $combine[1] : $type, + isset($combine[2]) ? $combine[2] : $modifier + ); + } + return $this; + } + + if (! $select instanceof Select) { + throw new Exception\InvalidArgumentException(sprintf( + '$select must be a array or instance of Select, "%s" given', + is_object($select) ? get_class($select) : gettype($select) + )); + } + + $this->combine[] = [ + 'select' => $select, + 'type' => $type, + 'modifier' => $modifier + ]; + return $this; + } + + /** + * Create union clause + * + * @param Select|array $select + * @param string $modifier + * + * @return self + */ + public function union($select, $modifier = '') + { + return $this->combine($select, self::COMBINE_UNION, $modifier); + } + + /** + * Create except clause + * + * @param Select|array $select + * @param string $modifier + * + * @return self + */ + public function except($select, $modifier = '') + { + return $this->combine($select, self::COMBINE_EXCEPT, $modifier); + } + + /** + * Create intersect clause + * + * @param Select|array $select + * @param string $modifier + * @return self + */ + public function intersect($select, $modifier = '') + { + return $this->combine($select, self::COMBINE_INTERSECT, $modifier); + } + + /** + * Build sql string + * + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * + * @return string + */ + protected function buildSqlString( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if (! $this->combine) { + return; + } + + $sql = ''; + foreach ($this->combine as $i => $combine) { + $type = $i == 0 + ? '' + : strtoupper($combine['type'] . ($combine['modifier'] ? ' ' . $combine['modifier'] : '')); + $select = $this->processSubSelect($combine['select'], $platform, $driver, $parameterContainer); + $sql .= sprintf( + $this->specifications[self::COMBINE], + $type, + $select + ); + } + return trim($sql, ' '); + } + + /** + * @return self Provides a fluent interface + */ + public function alignColumns() + { + if (! $this->combine) { + return $this; + } + + $allColumns = []; + foreach ($this->combine as $combine) { + $allColumns = array_merge( + $allColumns, + $combine['select']->getRawState(self::COLUMNS) + ); + } + + foreach ($this->combine as $combine) { + $combineColumns = $combine['select']->getRawState(self::COLUMNS); + $aligned = []; + foreach ($allColumns as $alias => $column) { + $aligned[$alias] = isset($combineColumns[$alias]) + ? $combineColumns[$alias] + : new Predicate\Expression('NULL'); + } + $combine['select']->columns($aligned, false); + } + return $this; + } + + /** + * Get raw state + * + * @param string $key + * + * @return array + */ + public function getRawState($key = null) + { + $rawState = [ + self::COMBINE => $this->combine, + self::COLUMNS => $this->combine + ? $this->combine[0]['select']->getRawState(self::COLUMNS) + : [], + ]; + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/AlterTable.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/AlterTable.php similarity index 58% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/AlterTable.php rename to bundled-libs/zendframework/zend-db/src/Sql/Ddl/AlterTable.php index 60fb4b08..bee08f99 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/AlterTable.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/AlterTable.php @@ -3,15 +3,15 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql\Ddl; use Zend\Db\Adapter\Platform\PlatformInterface; -use Zend\Db\Adapter\Platform\Sql92 as AdapterSql92Platform; use Zend\Db\Sql\AbstractSql; +use Zend\Db\Sql\TableIdentifier; class AlterTable extends AbstractSql implements SqlInterface { @@ -25,60 +25,60 @@ class AlterTable extends AbstractSql implements SqlInterface /** * @var array */ - protected $addColumns = array(); + protected $addColumns = []; /** * @var array */ - protected $addConstraints = array(); + protected $addConstraints = []; /** * @var array */ - protected $changeColumns = array(); + protected $changeColumns = []; /** * @var array */ - protected $dropColumns = array(); + protected $dropColumns = []; /** * @var array */ - protected $dropConstraints = array(); + protected $dropConstraints = []; /** * Specifications for Sql String generation * @var array */ - protected $specifications = array( + protected $specifications = [ self::TABLE => "ALTER TABLE %1\$s\n", - self::ADD_COLUMNS => array( - "%1\$s" => array( - array(1 => 'ADD COLUMN %1$s', 'combinedby' => ",\n") - ) - ), - self::CHANGE_COLUMNS => array( - "%1\$s" => array( - array(2 => 'CHANGE COLUMN %1$s %2$s', 'combinedby' => ",\n"), - ) - ), - self::DROP_COLUMNS => array( - "%1\$s" => array( - array(1 => 'DROP COLUMN %1$s', 'combinedby' => ",\n"), - ) - ), - self::ADD_CONSTRAINTS => array( - "%1\$s" => array( - array(1 => 'ADD %1$s', 'combinedby' => ",\n"), - ) - ), - self::DROP_CONSTRAINTS => array( - "%1\$s" => array( - array(1 => 'DROP CONSTRAINT %1$s', 'combinedby' => ",\n"), - ) - ) - ); + self::ADD_COLUMNS => [ + "%1\$s" => [ + [1 => "ADD COLUMN %1\$s,\n", 'combinedby' => ""] + ] + ], + self::CHANGE_COLUMNS => [ + "%1\$s" => [ + [2 => "CHANGE COLUMN %1\$s %2\$s,\n", 'combinedby' => ""], + ] + ], + self::DROP_COLUMNS => [ + "%1\$s" => [ + [1 => "DROP COLUMN %1\$s,\n", 'combinedby' => ""], + ] + ], + self::ADD_CONSTRAINTS => [ + "%1\$s" => [ + [1 => "ADD %1\$s,\n", 'combinedby' => ""], + ] + ], + self::DROP_CONSTRAINTS => [ + "%1\$s" => [ + [1 => "DROP CONSTRAINT %1\$s,\n", 'combinedby' => ""], + ] + ] + ]; /** * @var string @@ -86,7 +86,7 @@ class AlterTable extends AbstractSql implements SqlInterface protected $table = ''; /** - * @param string $table + * @param string|TableIdentifier $table */ public function __construct($table = '') { @@ -95,7 +95,7 @@ class AlterTable extends AbstractSql implements SqlInterface /** * @param string $name - * @return self + * @return self Provides a fluent interface */ public function setTable($name) { @@ -106,7 +106,7 @@ class AlterTable extends AbstractSql implements SqlInterface /** * @param Column\ColumnInterface $column - * @return self + * @return self Provides a fluent interface */ public function addColumn(Column\ColumnInterface $column) { @@ -118,7 +118,7 @@ class AlterTable extends AbstractSql implements SqlInterface /** * @param string $name * @param Column\ColumnInterface $column - * @return self + * @return self Provides a fluent interface */ public function changeColumn($name, Column\ColumnInterface $column) { @@ -129,7 +129,7 @@ class AlterTable extends AbstractSql implements SqlInterface /** * @param string $name - * @return self + * @return self Provides a fluent interface */ public function dropColumn($name) { @@ -140,7 +140,7 @@ class AlterTable extends AbstractSql implements SqlInterface /** * @param string $name - * @return self + * @return self Provides a fluent interface */ public function dropConstraint($name) { @@ -151,7 +151,7 @@ class AlterTable extends AbstractSql implements SqlInterface /** * @param Constraint\ConstraintInterface $constraint - * @return self + * @return self Provides a fluent interface */ public function addConstraint(Constraint\ConstraintInterface $constraint) { @@ -166,103 +166,73 @@ class AlterTable extends AbstractSql implements SqlInterface */ public function getRawState($key = null) { - $rawState = array( + $rawState = [ self::TABLE => $this->table, self::ADD_COLUMNS => $this->addColumns, self::DROP_COLUMNS => $this->dropColumns, self::CHANGE_COLUMNS => $this->changeColumns, self::ADD_CONSTRAINTS => $this->addConstraints, self::DROP_CONSTRAINTS => $this->dropConstraints, - ); + ]; return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; } - /** - * @param PlatformInterface $adapterPlatform - * @return string - */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - // get platform, or create default - $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; - - $sqls = array(); - $parameters = array(); - - foreach ($this->specifications as $name => $specification) { - $parameters[$name] = $this->{'process' . $name}($adapterPlatform, null, null, $sqls, $parameters); - if ($specification && is_array($parameters[$name]) && ($parameters[$name] != array(array()))) { - $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); - } - if (stripos($name, 'table') === false && $parameters[$name] !== array(array())) { - $sqls[] = ",\n"; - } - } - - // remove last ,\n - array_pop($sqls); - - $sql = implode('', $sqls); - - return $sql; - } - protected function processTable(PlatformInterface $adapterPlatform = null) { - return array($adapterPlatform->quoteIdentifier($this->table)); + return [$this->resolveTable($this->table, $adapterPlatform)]; } protected function processAddColumns(PlatformInterface $adapterPlatform = null) { - $sqls = array(); + $sqls = []; foreach ($this->addColumns as $column) { - $sqls[] = $this->processExpression($column, $adapterPlatform)->getSql(); + $sqls[] = $this->processExpression($column, $adapterPlatform); } - return array($sqls); + return [$sqls]; } protected function processChangeColumns(PlatformInterface $adapterPlatform = null) { - $sqls = array(); + $sqls = []; foreach ($this->changeColumns as $name => $column) { - $sqls[] = array( + $sqls[] = [ $adapterPlatform->quoteIdentifier($name), - $this->processExpression($column, $adapterPlatform)->getSql() - ); + $this->processExpression($column, $adapterPlatform) + ]; } - return array($sqls); + return [$sqls]; } protected function processDropColumns(PlatformInterface $adapterPlatform = null) { - $sqls = array(); + $sqls = []; foreach ($this->dropColumns as $column) { - $sqls[] = $adapterPlatform->quoteIdentifier($column); + $sqls[] = $adapterPlatform->quoteIdentifier($column); } - return array($sqls); + return [$sqls]; } protected function processAddConstraints(PlatformInterface $adapterPlatform = null) { - $sqls = array(); + $sqls = []; foreach ($this->addConstraints as $constraint) { $sqls[] = $this->processExpression($constraint, $adapterPlatform); } - return array($sqls); + return [$sqls]; } protected function processDropConstraints(PlatformInterface $adapterPlatform = null) { - $sqls = array(); + $sqls = []; foreach ($this->dropConstraints as $constraint) { $sqls[] = $adapterPlatform->quoteIdentifier($constraint); } - return array($sqls); + return [$sqls]; } } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractLengthColumn.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractLengthColumn.php new file mode 100644 index 00000000..59e499d1 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractLengthColumn.php @@ -0,0 +1,71 @@ +setLength($length); + + parent::__construct($name, $nullable, $default, $options); + } + + /** + * @param int $length + * @return self Provides a fluent interface + */ + public function setLength($length) + { + $this->length = (int) $length; + + return $this; + } + + /** + * @return int + */ + public function getLength() + { + return $this->length; + } + + /** + * @return string + */ + protected function getLengthExpression() + { + return (string) $this->length; + } + + /** + * @return array + */ + public function getExpressionData() + { + $data = parent::getExpressionData(); + + if ($this->getLengthExpression()) { + $data[0][1][1] .= '(' . $this->getLengthExpression() . ')'; + } + + return $data; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractPrecisionColumn.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractPrecisionColumn.php new file mode 100644 index 00000000..3edba684 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractPrecisionColumn.php @@ -0,0 +1,86 @@ +setDecimal($decimal); + + parent::__construct($name, $digits, $nullable, $default, $options); + } + + /** + * @param int $digits + * + * @return self + */ + public function setDigits($digits) + { + return $this->setLength($digits); + } + + /** + * @return int + */ + public function getDigits() + { + return $this->getLength(); + } + + /** + * @param int|null $decimal + * @return self Provides a fluent interface + */ + public function setDecimal($decimal) + { + $this->decimal = null === $decimal ? null : (int) $decimal; + + return $this; + } + + /** + * @return int|null + */ + public function getDecimal() + { + return $this->decimal; + } + + /** + * {@inheritDoc} + */ + protected function getLengthExpression() + { + if ($this->decimal !== null) { + return $this->length . ',' . $this->decimal; + } + + return $this->length; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractTimestampColumn.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractTimestampColumn.php new file mode 100644 index 00000000..e71d3791 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/AbstractTimestampColumn.php @@ -0,0 +1,63 @@ +specification; + + $params = []; + $params[] = $this->name; + $params[] = $this->type; + + $types = [self::TYPE_IDENTIFIER, self::TYPE_LITERAL]; + + if (! $this->isNullable) { + $spec .= ' NOT NULL'; + } + + if ($this->default !== null) { + $spec .= ' DEFAULT %s'; + $params[] = $this->default; + $types[] = self::TYPE_VALUE; + } + + $options = $this->getOptions(); + + if (isset($options['on_update'])) { + $spec .= ' %s'; + $params[] = 'ON UPDATE CURRENT_TIMESTAMP'; + $types[] = self::TYPE_LITERAL; + } + + $data = [[ + $spec, + $params, + $types, + ]]; + + foreach ($this->constraints as $constraint) { + $data[] = ' '; + $data = array_merge($data, $constraint->getExpressionData()); + } + + return $data; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/BigInteger.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/BigInteger.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/BigInteger.php rename to bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/BigInteger.php index 53ae6ee1..83463381 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/BigInteger.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/BigInteger.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Binary.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Binary.php new file mode 100644 index 00000000..b0351308 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Binary.php @@ -0,0 +1,18 @@ +setName($name); + $this->setName($name); + $this->setNullable($nullable); + $this->setDefault($default); + $this->setOptions($options); } /** * @param string $name - * @return self + * @return self Provides a fluent interface */ public function setName($name) { - $this->name = $name; + $this->name = (string) $name; return $this; } @@ -69,7 +82,7 @@ class Column implements ColumnInterface /** * @param bool $nullable - * @return self + * @return self Provides a fluent interface */ public function setNullable($nullable) { @@ -87,7 +100,7 @@ class Column implements ColumnInterface /** * @param null|string|int $default - * @return self + * @return self Provides a fluent interface */ public function setDefault($default) { @@ -105,7 +118,7 @@ class Column implements ColumnInterface /** * @param array $options - * @return self + * @return self Provides a fluent interface */ public function setOptions(array $options) { @@ -116,7 +129,7 @@ class Column implements ColumnInterface /** * @param string $name * @param string $value - * @return self + * @return self Provides a fluent interface */ public function setOption($name, $value) { @@ -132,6 +145,18 @@ class Column implements ColumnInterface return $this->options; } + /** + * @param ConstraintInterface $constraint + * + * @return self Provides a fluent interface + */ + public function addConstraint(ConstraintInterface $constraint) + { + $this->constraints[] = $constraint; + + return $this; + } + /** * @return array */ @@ -139,14 +164,14 @@ class Column implements ColumnInterface { $spec = $this->specification; - $params = array(); + $params = []; $params[] = $this->name; $params[] = $this->type; - $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + $types = [self::TYPE_IDENTIFIER, self::TYPE_LITERAL]; - if (!$this->isNullable) { - $params[1] .= ' NOT NULL'; + if (! $this->isNullable) { + $spec .= ' NOT NULL'; } if ($this->default !== null) { @@ -155,10 +180,17 @@ class Column implements ColumnInterface $types[] = self::TYPE_VALUE; } - return array(array( + $data = [[ $spec, $params, $types, - )); + ]]; + + foreach ($this->constraints as $constraint) { + $data[] = ' '; + $data = array_merge($data, $constraint->getExpressionData()); + } + + return $data; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/ColumnInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/ColumnInterface.php similarity index 59% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/ColumnInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/ColumnInterface.php index 3ea33e66..ff38b5a0 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/ColumnInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/ColumnInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,10 +11,30 @@ namespace Zend\Db\Sql\Ddl\Column; use Zend\Db\Sql\ExpressionInterface; +/** + * Interface ColumnInterface describes the protocol on how Column objects interact + * + * @package Zend\Db\Sql\Ddl\Column + */ interface ColumnInterface extends ExpressionInterface { + /** + * @return string + */ public function getName(); + + /** + * @return bool + */ public function isNullable(); + + /** + * @return null|string|int + */ public function getDefault(); + + /** + * @return array + */ public function getOptions(); } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Date.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Date.php new file mode 100644 index 00000000..7fe39699 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Date.php @@ -0,0 +1,18 @@ +getOptions(); + + if (isset($options['length'])) { + $data[0][1][1] .= '(' . $options['length'] . ')'; + } + + return $data; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Text.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Text.php new file mode 100644 index 00000000..53ceafaa --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Column/Text.php @@ -0,0 +1,18 @@ +setColumns($columns); + } + + $this->setName($name); + } + + /** + * @param string $name + * @return self Provides a fluent interface + */ + public function setName($name) + { + $this->name = (string) $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param null|string|array $columns + * @return self Provides a fluent interface + */ + public function setColumns($columns) + { + $this->columns = (array) $columns; + + return $this; + } + + /** + * @param string $column + * @return self Provides a fluent interface + */ + public function addColumn($column) + { + $this->columns[] = $column; + return $this; + } + + /** + * {@inheritDoc} + */ + public function getColumns() + { + return $this->columns; + } + + /** + * {@inheritDoc} + */ + public function getExpressionData() + { + $colCount = count($this->columns); + $newSpecTypes = []; + $values = []; + $newSpec = ''; + + if ($this->name) { + $newSpec .= $this->namedSpecification; + $values[] = $this->name; + $newSpecTypes[] = self::TYPE_IDENTIFIER; + } + + $newSpec .= $this->specification; + + if ($colCount) { + $values = array_merge($values, $this->columns); + $newSpecParts = array_fill(0, $colCount, '%s'); + $newSpecTypes = array_merge($newSpecTypes, array_fill(0, $colCount, self::TYPE_IDENTIFIER)); + $newSpec .= sprintf($this->columnSpecification, implode(', ', $newSpecParts)); + } + + return [[ + $newSpec, + $values, + $newSpecTypes, + ]]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/Check.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/Check.php similarity index 56% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/Check.php rename to bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/Check.php index c0fa1ff7..df3917b0 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/Check.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/Check.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -17,9 +17,9 @@ class Check extends AbstractConstraint protected $expression; /** - * @var string + * {@inheritDoc} */ - protected $specification = 'CONSTRAINT %s CHECK (%s)'; + protected $specification = 'CHECK (%s)'; /** * @param string|\Zend\Db\Sql\ExpressionInterface $expression @@ -32,14 +32,25 @@ class Check extends AbstractConstraint } /** - * @return array + * {@inheritDoc} */ public function getExpressionData() { - return array(array( - $this->specification, - array($this->name, $this->expression), - array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL), - )); + $newSpecTypes = [self::TYPE_LITERAL]; + $values = [$this->expression]; + $newSpec = ''; + + if ($this->name) { + $newSpec .= $this->namedSpecification; + + array_unshift($values, $this->name); + array_unshift($newSpecTypes, self::TYPE_IDENTIFIER); + } + + return [[ + $newSpec . $this->specification, + $values, + $newSpecTypes, + ]]; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ConstraintInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/ConstraintInterface.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ConstraintInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/ConstraintInterface.php index 73fd2768..aaa09202 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ConstraintInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/ConstraintInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/ForeignKey.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/ForeignKey.php new file mode 100644 index 00000000..e834d3d9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/ForeignKey.php @@ -0,0 +1,184 @@ +setName($name); + $this->setColumns($columns); + $this->setReferenceTable($referenceTable); + $this->setReferenceColumn($referenceColumn); + + if ($onDeleteRule) { + $this->setOnDeleteRule($onDeleteRule); + } + + if ($onUpdateRule) { + $this->setOnUpdateRule($onUpdateRule); + } + } + + /** + * @param string $referenceTable + * @return self Provides a fluent interface + */ + public function setReferenceTable($referenceTable) + { + $this->referenceTable = (string) $referenceTable; + return $this; + } + + /** + * @return string + */ + public function getReferenceTable() + { + return $this->referenceTable; + } + + /** + * @param null|string|array $referenceColumn + * @return self Provides a fluent interface + */ + public function setReferenceColumn($referenceColumn) + { + $this->referenceColumn = (array) $referenceColumn; + + return $this; + } + + /** + * @return array + */ + public function getReferenceColumn() + { + return $this->referenceColumn; + } + + /** + * @param string $onDeleteRule + * @return self Provides a fluent interface + */ + public function setOnDeleteRule($onDeleteRule) + { + $this->onDeleteRule = (string) $onDeleteRule; + + return $this; + } + + /** + * @return string + */ + public function getOnDeleteRule() + { + return $this->onDeleteRule; + } + + /** + * @param string $onUpdateRule + * @return self Provides a fluent interface + */ + public function setOnUpdateRule($onUpdateRule) + { + $this->onUpdateRule = (string) $onUpdateRule; + + return $this; + } + + /** + * @return string + */ + public function getOnUpdateRule() + { + return $this->onUpdateRule; + } + + /** + * @return array + */ + public function getExpressionData() + { + $data = parent::getExpressionData(); + $colCount = count($this->referenceColumn); + $newSpecTypes = [self::TYPE_IDENTIFIER]; + $values = [$this->referenceTable]; + + $data[0][0] .= $this->referenceSpecification[0]; + + if ($colCount) { + $values = array_merge($values, $this->referenceColumn); + $newSpecParts = array_fill(0, $colCount, '%s'); + $newSpecTypes = array_merge($newSpecTypes, array_fill(0, $colCount, self::TYPE_IDENTIFIER)); + + $data[0][0] .= sprintf('(%s) ', implode(', ', $newSpecParts)); + } + + $data[0][0] .= $this->referenceSpecification[1]; + + $values[] = $this->onDeleteRule; + $values[] = $this->onUpdateRule; + $newSpecTypes[] = self::TYPE_LITERAL; + $newSpecTypes[] = self::TYPE_LITERAL; + + $data[0][1] = array_merge($data[0][1], $values); + $data[0][2] = array_merge($data[0][2], $newSpecTypes); + + return $data; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/PrimaryKey.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/PrimaryKey.php new file mode 100644 index 00000000..9775bb01 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Constraint/PrimaryKey.php @@ -0,0 +1,18 @@ + 'CREATE TABLE %1$s (', - self::COLUMNS => array( - "\n %1\$s" => array( - array(1 => '%1$s', 'combinedby' => ",\n ") - ) - ), - self::CONSTRAINTS => array( - "\n %1\$s" => array( - array(1 => '%1$s', 'combinedby' => ",\n ") - ) - ), - ); + protected $specifications = [ + self::TABLE => 'CREATE %1$sTABLE %2$s (', + self::COLUMNS => [ + "\n %1\$s" => [ + [1 => '%1$s', 'combinedby' => ",\n "] + ] + ], + 'combinedBy' => ",", + self::CONSTRAINTS => [ + "\n %1\$s" => [ + [1 => '%1$s', 'combinedby' => ",\n "] + ] + ], + 'statementEnd' => '%1$s', + ]; /** * @var string @@ -58,7 +59,7 @@ class CreateTable extends AbstractSql implements SqlInterface protected $table = ''; /** - * @param string $table + * @param string|TableIdentifier $table * @param bool $isTemporary */ public function __construct($table = '', $isTemporary = false) @@ -69,7 +70,7 @@ class CreateTable extends AbstractSql implements SqlInterface /** * @param bool $temporary - * @return self + * @return self Provides a fluent interface */ public function setTemporary($temporary) { @@ -87,7 +88,7 @@ class CreateTable extends AbstractSql implements SqlInterface /** * @param string $name - * @return self + * @return self Provides a fluent interface */ public function setTable($name) { @@ -97,7 +98,7 @@ class CreateTable extends AbstractSql implements SqlInterface /** * @param Column\ColumnInterface $column - * @return self + * @return self Provides a fluent interface */ public function addColumn(Column\ColumnInterface $column) { @@ -107,7 +108,7 @@ class CreateTable extends AbstractSql implements SqlInterface /** * @param Constraint\ConstraintInterface $constraint - * @return self + * @return self Provides a fluent interface */ public function addConstraint(Constraint\ConstraintInterface $constraint) { @@ -121,93 +122,87 @@ class CreateTable extends AbstractSql implements SqlInterface */ public function getRawState($key = null) { - $rawState = array( + $rawState = [ self::COLUMNS => $this->columns, self::CONSTRAINTS => $this->constraints, self::TABLE => $this->table, - ); + ]; return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; } /** - * @param PlatformInterface $adapterPlatform - * @return string + * @param PlatformInterface $adapterPlatform + * + * @return string[] */ - public function getSqlString(PlatformInterface $adapterPlatform = null) - { - // get platform, or create default - $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; - - $sqls = array(); - $parameters = array(); - - foreach ($this->specifications as $name => $specification) { - if (is_int($name)) { - $sqls[] = $specification; - continue; - } - - $parameters[$name] = $this->{'process' . $name}( - $adapterPlatform, - null, - null, - $sqls, - $parameters - ); - - if ($specification - && is_array($parameters[$name]) - && ($parameters[$name] != array(array())) - ) { - $sqls[$name] = $this->createSqlFromSpecificationAndParameters( - $specification, - $parameters[$name] - ); - } - - if (stripos($name, 'table') === false - && $parameters[$name] !== array(array()) - ) { - $sqls[] = ",\n"; - } - } - - // remove last , - if (count($sqls) > 2) { - array_pop($sqls); - } - - $sql = implode('', $sqls) . "\n)"; - - return $sql; - } - protected function processTable(PlatformInterface $adapterPlatform = null) { - $ret = array(); - if ($this->isTemporary) { - $ret[] = 'TEMPORARY'; - } - $ret[] = $adapterPlatform->quoteIdentifier($this->table); - return $ret; + return [ + $this->isTemporary ? 'TEMPORARY ' : '', + $this->resolveTable($this->table, $adapterPlatform), + ]; } + /** + * @param PlatformInterface $adapterPlatform + * + * @return string[][]|null + */ protected function processColumns(PlatformInterface $adapterPlatform = null) { - $sqls = array(); - foreach ($this->columns as $column) { - $sqls[] = $this->processExpression($column, $adapterPlatform)->getSql(); + if (! $this->columns) { + return; } - return array($sqls); + + $sqls = []; + + foreach ($this->columns as $column) { + $sqls[] = $this->processExpression($column, $adapterPlatform); + } + + return [$sqls]; } + /** + * @param PlatformInterface $adapterPlatform + * + * @return array|string + */ + protected function processCombinedby(PlatformInterface $adapterPlatform = null) + { + if ($this->constraints && $this->columns) { + return $this->specifications['combinedBy']; + } + } + + /** + * @param PlatformInterface $adapterPlatform + * + * @return string[][]|null + */ protected function processConstraints(PlatformInterface $adapterPlatform = null) { - $sqls = array(); - foreach ($this->constraints as $constraint) { - $sqls[] = $this->processExpression($constraint, $adapterPlatform)->getSql(); + if (! $this->constraints) { + return; } - return array($sqls); + + $sqls = []; + + foreach ($this->constraints as $constraint) { + $sqls[] = $this->processExpression($constraint, $adapterPlatform); + } + + return [$sqls]; + } + + /** + * @param PlatformInterface $adapterPlatform + * + * @return string[] + */ + protected function processStatementEnd(PlatformInterface $adapterPlatform = null) + { + return ["\n)"]; } } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/DropTable.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/DropTable.php new file mode 100644 index 00000000..c42f8399 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/DropTable.php @@ -0,0 +1,44 @@ + 'DROP TABLE %1$s' + ]; + + /** + * @var string + */ + protected $table = ''; + + /** + * @param string|TableIdentifier $table + */ + public function __construct($table = '') + { + $this->table = $table; + } + + protected function processTable(PlatformInterface $adapterPlatform = null) + { + return [$this->resolveTable($this->table, $adapterPlatform)]; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Index/AbstractIndex.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Index/AbstractIndex.php new file mode 100644 index 00000000..c11efb5d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/Index/AbstractIndex.php @@ -0,0 +1,16 @@ +setColumns($columns); + + $this->name = null === $name ? null : (string) $name; + $this->lengths = $lengths; + } + + /** + * + * @return array of array|string should return an array in the format: + * + * array ( + * // a sprintf formatted string + * string $specification, + * + * // the values for the above sprintf formatted string + * array $values, + * + * // an array of equal length of the $values array, with either TYPE_IDENTIFIER or TYPE_VALUE for each value + * array $types, + * ) + * + */ + public function getExpressionData() + { + $colCount = count($this->columns); + $values = []; + $values[] = $this->name ?: ''; + $newSpecTypes = [self::TYPE_IDENTIFIER]; + $newSpecParts = []; + + for ($i = 0; $i < $colCount; $i++) { + $specPart = '%s'; + + if (isset($this->lengths[$i])) { + $specPart .= "({$this->lengths[$i]})"; + } + + $newSpecParts[] = $specPart; + $newSpecTypes[] = self::TYPE_IDENTIFIER; + } + + $newSpec = str_replace('...', implode(', ', $newSpecParts), $this->specification); + + return [[ + $newSpec, + array_merge($values, $this->columns), + $newSpecTypes, + ]]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/SqlInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/SqlInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/SqlInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/Ddl/SqlInterface.php index d9111346..0f8660f4 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Ddl/SqlInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Ddl/SqlInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Delete.php b/bundled-libs/zendframework/zend-db/src/Sql/Delete.php new file mode 100644 index 00000000..9e70e5fc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Delete.php @@ -0,0 +1,172 @@ + 'DELETE FROM %1$s', + self::SPECIFICATION_WHERE => 'WHERE %1$s' + ]; + + /** + * @var string|TableIdentifier + */ + protected $table = ''; + + /** + * @var bool + */ + protected $emptyWhereProtection = true; + + /** + * @var array + */ + protected $set = []; + + /** + * @var null|string|Where + */ + protected $where = null; + + /** + * Constructor + * + * @param null|string|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->from($table); + } + $this->where = new Where(); + } + + /** + * Create from statement + * + * @param string|TableIdentifier $table + * @return self Provides a fluent interface + */ + public function from($table) + { + $this->table = $table; + return $this; + } + + /** + * @param null $key + * + * @return mixed + */ + public function getRawState($key = null) + { + $rawState = [ + 'emptyWhereProtection' => $this->emptyWhereProtection, + 'table' => $this->table, + 'set' => $this->set, + 'where' => $this->where + ]; + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * Create where clause + * + * @param Where|\Closure|string|array $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * + * @return self Provides a fluent interface + */ + public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Where) { + $this->where = $predicate; + } else { + $this->where->addPredicates($predicate, $combination); + } + return $this; + } + + /** + * @param PlatformInterface $platform + * @param DriverInterface|null $driver + * @param ParameterContainer|null $parameterContainer + * + * @return string + */ + protected function processDelete( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return sprintf( + $this->specifications[static::SPECIFICATION_DELETE], + $this->resolveTable($this->table, $platform, $driver, $parameterContainer) + ); + } + + /** + * @param PlatformInterface $platform + * @param DriverInterface|null $driver + * @param ParameterContainer|null $parameterContainer + * + * @return null|string + */ + protected function processWhere( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->where->count() == 0) { + return; + } + + return sprintf( + $this->specifications[static::SPECIFICATION_WHERE], + $this->processExpression($this->where, $platform, $driver, $parameterContainer, 'where') + ); + } + + /** + * Property overloading + * + * Overloads "where" only. + * + * @param string $name + * + * @return Where|null + */ + public function __get($name) + { + switch (strtolower($name)) { + case 'where': + return $this->where; + } + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/ExceptionInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/Exception/ExceptionInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/ExceptionInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/Exception/ExceptionInterface.php index 63c77e81..138f7e4d 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/ExceptionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/InvalidArgumentException.php b/bundled-libs/zendframework/zend-db/src/Sql/Exception/InvalidArgumentException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/InvalidArgumentException.php rename to bundled-libs/zendframework/zend-db/src/Sql/Exception/InvalidArgumentException.php index c22196b2..6e400031 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/InvalidArgumentException.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/RuntimeException.php b/bundled-libs/zendframework/zend-db/src/Sql/Exception/RuntimeException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/RuntimeException.php rename to bundled-libs/zendframework/zend-db/src/Sql/Exception/RuntimeException.php index 7c1550cb..82b3aab9 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Exception/RuntimeException.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Exception/RuntimeException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Expression.php b/bundled-libs/zendframework/zend-db/src/Sql/Expression.php similarity index 52% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Expression.php rename to bundled-libs/zendframework/zend-db/src/Sql/Expression.php index 1a40441e..496cda92 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Expression.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Expression.php @@ -3,13 +3,13 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql; -class Expression implements ExpressionInterface +class Expression extends AbstractExpression { /** * @const @@ -24,39 +24,51 @@ class Expression implements ExpressionInterface /** * @var array */ - protected $parameters = array(); + protected $parameters = []; /** * @var array */ - protected $types = array(); + protected $types = []; /** * @param string $expression * @param string|array $parameters - * @param array $types + * @param array $types @deprecated will be dropped in version 3.0.0 */ - public function __construct($expression = '', $parameters = null, array $types = array()) + public function __construct($expression = '', $parameters = null, array $types = []) { - if ($expression) { + if ($expression !== '') { $this->setExpression($expression); } + + if ($types) { // should be deprecated and removed version 3.0.0 + if (is_array($parameters)) { + foreach ($parameters as $i => $parameter) { + $parameters[$i] = [ + $parameter => isset($types[$i]) ? $types[$i] : self::TYPE_VALUE, + ]; + } + } elseif (is_scalar($parameters)) { + $parameters = [ + $parameters => $types[0], + ]; + } + } + if ($parameters) { $this->setParameters($parameters); } - if ($types) { - $this->setTypes($types); - } } /** * @param $expression - * @return Expression + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException */ public function setExpression($expression) { - if (!is_string($expression) || $expression == '') { + if (! is_string($expression) || $expression == '') { throw new Exception\InvalidArgumentException('Supplied expression must be a string.'); } $this->expression = $expression; @@ -73,12 +85,12 @@ class Expression implements ExpressionInterface /** * @param $parameters - * @return Expression + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException */ public function setParameters($parameters) { - if (!is_scalar($parameters) && !is_array($parameters)) { + if (! is_scalar($parameters) && ! is_array($parameters)) { throw new Exception\InvalidArgumentException('Expression parameters must be a scalar or array.'); } $this->parameters = $parameters; @@ -94,8 +106,9 @@ class Expression implements ExpressionInterface } /** + * @deprecated * @param array $types - * @return Expression + * @return self Provides a fluent interface */ public function setTypes(array $types) { @@ -104,6 +117,7 @@ class Expression implements ExpressionInterface } /** + * @deprecated * @return array */ public function getTypes() @@ -117,37 +131,34 @@ class Expression implements ExpressionInterface */ public function getExpressionData() { - $parameters = (is_scalar($this->parameters)) ? array($this->parameters) : $this->parameters; - - $types = array(); + $parameters = (is_scalar($this->parameters)) ? [$this->parameters] : $this->parameters; $parametersCount = count($parameters); + $expression = str_replace('%', '%%', $this->expression); - if ($parametersCount == 0 && strpos($this->expression, self::PLACEHOLDER) !== false) { - // if there are no parameters, but there is a placeholder - $parametersCount = substr_count($this->expression, self::PLACEHOLDER); - $parameters = array_fill(0, $parametersCount, null); - } - - for ($i = 0; $i < $parametersCount; $i++) { - $types[$i] = (isset($this->types[$i]) && ($this->types[$i] == self::TYPE_IDENTIFIER || $this->types[$i] == self::TYPE_LITERAL)) - ? $this->types[$i] : self::TYPE_VALUE; + if ($parametersCount == 0) { + return [ + str_ireplace(self::PLACEHOLDER, '', $expression) + ]; } // assign locally, escaping % signs - $expression = str_replace('%', '%%', $this->expression); + $expression = str_replace(self::PLACEHOLDER, '%s', $expression, $count); - if ($parametersCount > 0) { - $count = 0; - $expression = str_replace(self::PLACEHOLDER, '%s', $expression, $count); - if ($count !== $parametersCount) { - throw new Exception\RuntimeException('The number of replacements in the expression does not match the number of parameters'); - } + // test number of replacements without considering same variable begin used many times first, which is + // faster, if the test fails then resort to regex which are slow and used rarely + if ($count !== $parametersCount && $parametersCount === preg_match_all('/\:[a-zA-Z0-9_]*/', $expression)) { + throw new Exception\RuntimeException( + 'The number of replacements in the expression does not match the number of parameters' + ); } - return array(array( + foreach ($parameters as $parameter) { + list($values[], $types[]) = $this->normalizeArgument($parameter, self::TYPE_VALUE); + } + return [[ $expression, - $parameters, + $values, $types - )); + ]]; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/ExpressionInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/ExpressionInterface.php similarity index 88% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/ExpressionInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/ExpressionInterface.php index 2777ba3b..282b4086 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/ExpressionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/ExpressionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,10 +14,6 @@ interface ExpressionInterface const TYPE_IDENTIFIER = 'identifier'; const TYPE_VALUE = 'value'; const TYPE_LITERAL = 'literal'; - - /** - * @deprecated This will go away in 2.1 - */ const TYPE_SELECT = 'select'; /** diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Having.php b/bundled-libs/zendframework/zend-db/src/Sql/Having.php similarity index 82% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Having.php rename to bundled-libs/zendframework/zend-db/src/Sql/Having.php index d3bb4911..b95d9d59 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Having.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Having.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,5 +11,4 @@ namespace Zend\Db\Sql; class Having extends Predicate\Predicate { - } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Insert.php b/bundled-libs/zendframework/zend-db/src/Sql/Insert.php new file mode 100644 index 00000000..ad5ce899 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Insert.php @@ -0,0 +1,300 @@ + 'INSERT INTO %1$s (%2$s) VALUES (%3$s)', + self::SPECIFICATION_SELECT => 'INSERT INTO %1$s %2$s %3$s', + ]; + + /** + * @var string|TableIdentifier + */ + protected $table = null; + protected $columns = []; + + /** + * @var array|Select + */ + protected $select = null; + + /** + * Constructor + * + * @param null|string|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->into($table); + } + } + + /** + * Create INTO clause + * + * @param string|TableIdentifier $table + * @return self Provides a fluent interface + */ + public function into($table) + { + $this->table = $table; + return $this; + } + + /** + * Specify columns + * + * @param array $columns + * @return self Provides a fluent interface + */ + public function columns(array $columns) + { + $this->columns = array_flip($columns); + return $this; + } + + /** + * Specify values to insert + * + * @param array|Select $values + * @param string $flag one of VALUES_MERGE or VALUES_SET; defaults to VALUES_SET + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function values($values, $flag = self::VALUES_SET) + { + if ($values instanceof Select) { + if ($flag == self::VALUES_MERGE) { + throw new Exception\InvalidArgumentException( + 'A Zend\Db\Sql\Select instance cannot be provided with the merge flag' + ); + } + $this->select = $values; + return $this; + } + + if (! is_array($values)) { + throw new Exception\InvalidArgumentException( + 'values() expects an array of values or Zend\Db\Sql\Select instance' + ); + } + + if ($this->select && $flag == self::VALUES_MERGE) { + throw new Exception\InvalidArgumentException( + 'An array of values cannot be provided with the merge flag when a Zend\Db\Sql\Select instance already ' + . 'exists as the value source' + ); + } + + if ($flag == self::VALUES_SET) { + $this->columns = $this->isAssocativeArray($values) + ? $values + : array_combine(array_keys($this->columns), array_values($values)); + } else { + foreach ($values as $column => $value) { + $this->columns[$column] = $value; + } + } + return $this; + } + + + /** + * Simple test for an associative array + * + * @link http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential + * @param array $array + * @return bool + */ + private function isAssocativeArray(array $array) + { + return array_keys($array) !== range(0, count($array) - 1); + } + + /** + * Create INTO SELECT clause + * + * @param Select $select + * @return self + */ + public function select(Select $select) + { + return $this->values($select); + } + + /** + * Get raw state + * + * @param string $key + * @return mixed + */ + public function getRawState($key = null) + { + $rawState = [ + 'table' => $this->table, + 'columns' => array_keys($this->columns), + 'values' => array_values($this->columns) + ]; + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + protected function processInsert( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->select) { + return; + } + if (! $this->columns) { + throw new Exception\InvalidArgumentException('values or select should be present'); + } + + $columns = []; + $values = []; + $i = 0; + + foreach ($this->columns as $column => $value) { + $columns[] = $platform->quoteIdentifier($column); + if (is_scalar($value) && $parameterContainer) { + // use incremental value instead of column name for PDO + // @see https://github.com/zendframework/zend-db/issues/35 + if ($driver instanceof Pdo) { + $column = 'c_' . $i++; + } + $values[] = $driver->formatParameterName($column); + $parameterContainer->offsetSet($column, $value); + } else { + $values[] = $this->resolveColumnValue( + $value, + $platform, + $driver, + $parameterContainer + ); + } + } + return sprintf( + $this->specifications[static::SPECIFICATION_INSERT], + $this->resolveTable($this->table, $platform, $driver, $parameterContainer), + implode(', ', $columns), + implode(', ', $values) + ); + } + + protected function processSelect( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if (! $this->select) { + return; + } + $selectSql = $this->processSubSelect($this->select, $platform, $driver, $parameterContainer); + + $columns = array_map([$platform, 'quoteIdentifier'], array_keys($this->columns)); + $columns = implode(', ', $columns); + + return sprintf( + $this->specifications[static::SPECIFICATION_SELECT], + $this->resolveTable($this->table, $platform, $driver, $parameterContainer), + $columns ? "($columns)" : "", + $selectSql + ); + } + + /** + * Overloading: variable setting + * + * Proxies to values, using VALUES_MERGE strategy + * + * @param string $name + * @param mixed $value + * @return self Provides a fluent interface + */ + public function __set($name, $value) + { + $this->columns[$name] = $value; + return $this; + } + + /** + * Overloading: variable unset + * + * Proxies to values and columns + * + * @param string $name + * @throws Exception\InvalidArgumentException + * @return void + */ + public function __unset($name) + { + if (! array_key_exists($name, $this->columns)) { + throw new Exception\InvalidArgumentException( + 'The key ' . $name . ' was not found in this objects column list' + ); + } + + unset($this->columns[$name]); + } + + /** + * Overloading: variable isset + * + * Proxies to columns; does a column of that name exist? + * + * @param string $name + * @return bool + */ + public function __isset($name) + { + return array_key_exists($name, $this->columns); + } + + /** + * Overloading: variable retrieval + * + * Retrieves value by column name + * + * @param string $name + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function __get($name) + { + if (! array_key_exists($name, $this->columns)) { + throw new Exception\InvalidArgumentException( + 'The key ' . $name . ' was not found in this objects column list' + ); + } + return $this->columns[$name]; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Join.php b/bundled-libs/zendframework/zend-db/src/Sql/Join.php new file mode 100644 index 00000000..12e85996 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Join.php @@ -0,0 +1,163 @@ +position = 0; + } + + /** + * Rewind iterator. + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Return current join specification. + * + * @return array + */ + public function current() + { + return $this->joins[$this->position]; + } + + /** + * Return the current iterator index. + * + * @return int + */ + public function key() + { + return $this->position; + } + + /** + * Advance to the next JOIN specification. + */ + public function next() + { + ++$this->position; + } + + /** + * Is the iterator at a valid position? + * + * @return bool + */ + public function valid() + { + return isset($this->joins[$this->position]); + } + + /** + * @return array + */ + public function getJoins() + { + return $this->joins; + } + + /** + * @param string|array|TableIdentifier $name A table name on which to join, or a single + * element associative array, of the form alias => table, or TableIdentifier instance + * @param string|Predicate\Expression $on A specification describing the fields to join on. + * @param string|string[]|int|int[] $columns A single column name, an array + * of column names, or (a) specification(s) such as SQL_STAR representing + * the columns to join. + * @param string $type The JOIN type to use; see the JOIN_* constants. + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException for invalid $name values. + */ + public function join($name, $on, $columns = [Select::SQL_STAR], $type = Join::JOIN_INNER) + { + if (is_array($name) && (! is_string(key($name)) || count($name) !== 1)) { + throw new Exception\InvalidArgumentException( + sprintf("join() expects '%s' as a single element associative array", array_shift($name)) + ); + } + + if (! is_array($columns)) { + $columns = [$columns]; + } + + $this->joins[] = [ + 'name' => $name, + 'on' => $on, + 'columns' => $columns, + 'type' => $type ? $type : Join::JOIN_INNER + ]; + + return $this; + } + + /** + * Reset to an empty list of JOIN specifications. + * + * @return self Provides a fluent interface + */ + public function reset() + { + $this->joins = []; + return $this; + } + + /** + * Get count of attached predicates + * + * @return int + */ + public function count() + { + return count($this->joins); + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Literal.php b/bundled-libs/zendframework/zend-db/src/Sql/Literal.php similarity index 62% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Literal.php rename to bundled-libs/zendframework/zend-db/src/Sql/Literal.php index 48722b1b..a04b0f16 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Literal.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Literal.php @@ -1,4 +1,11 @@ literal), - array(), - array() - )); + [], + [] + ]]; } } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/AbstractPlatform.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/AbstractPlatform.php new file mode 100644 index 00000000..6d0b040b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/AbstractPlatform.php @@ -0,0 +1,112 @@ +subject = $subject; + + return $this; + } + + /** + * @param string $type + * @param PlatformDecoratorInterface $decorator + * + * @return void + */ + public function setTypeDecorator($type, PlatformDecoratorInterface $decorator) + { + $this->decorators[$type] = $decorator; + } + + /** + * @param PreparableSqlInterface|SqlInterface $subject + * @return PlatformDecoratorInterface|PreparableSqlInterface|SqlInterface + */ + public function getTypeDecorator($subject) + { + foreach ($this->decorators as $type => $decorator) { + if ($subject instanceof $type) { + $decorator->setSubject($subject); + + return $decorator; + } + } + + return $subject; + } + + /** + * @return array|PlatformDecoratorInterface[] + */ + public function getDecorators() + { + return $this->decorators; + } + + /** + * {@inheritDoc} + * + * @throws Exception\RuntimeException + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + if (! $this->subject instanceof PreparableSqlInterface) { + throw new Exception\RuntimeException( + 'The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling ' + . 'prepareStatement() has no effect' + ); + } + + $this->getTypeDecorator($this->subject)->prepareStatement($adapter, $statementContainer); + + return $statementContainer; + } + + /** + * {@inheritDoc} + * + * @throws Exception\RuntimeException + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + if (! $this->subject instanceof SqlInterface) { + throw new Exception\RuntimeException( + 'The subject does not appear to implement Zend\Db\Sql\SqlInterface, thus calling ' + . 'prepareStatement() has no effect' + ); + } + + return $this->getTypeDecorator($this->subject)->getSqlString($adapterPlatform); + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/IbmDb2.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/IbmDb2.php new file mode 100644 index 00000000..35ddc2c7 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/IbmDb2.php @@ -0,0 +1,23 @@ +setTypeDecorator('Zend\Db\Sql\Select', ($selectDecorator) ?: new SelectDecorator()); + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/SelectDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/SelectDecorator.php new file mode 100644 index 00000000..f1988c09 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/IbmDb2/SelectDecorator.php @@ -0,0 +1,212 @@ +isSelectContainDistinct; + } + + /** + * @param boolean $isSelectContainDistinct + */ + public function setIsSelectContainDistinct($isSelectContainDistinct) + { + $this->isSelectContainDistinct = $isSelectContainDistinct; + } + + /** + * @param Select $select + */ + public function setSubject($select) + { + $this->subject = $select; + } + + /** + * @return bool + */ + public function getSupportsLimitOffset() + { + return $this->supportsLimitOffset; + } + + /** + * @param bool $supportsLimitOffset + */ + public function setSupportsLimitOffset($supportsLimitOffset) + { + $this->supportsLimitOffset = $supportsLimitOffset; + } + + /** + * @see Select::renderTable + */ + protected function renderTable($table, $alias = null) + { + return $table . ' ' . $alias; + } + + protected function localizeVariables() + { + parent::localizeVariables(); + // set specifications + unset($this->specifications[self::LIMIT]); + unset($this->specifications[self::OFFSET]); + + $this->specifications['LIMITOFFSET'] = null; + } + + /** + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @param array $sqls + * @param array $parameters + */ + protected function processLimitOffset( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null, + &$sqls, + &$parameters + ) { + if ($this->limit === null && $this->offset === null) { + return; + } + + if ($this->supportsLimitOffset) { + // Note: db2_prepare/db2_execute fails with positional parameters, for LIMIT & OFFSET + $limit = (int) $this->limit; + if (! $limit) { + return; + } + + $offset = (int) $this->offset; + if ($offset) { + array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset)); + return; + } + + array_push($sqls, sprintf("LIMIT %s", $limit)); + return; + } + + $selectParameters = $parameters[self::SELECT]; + + $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; + foreach ($selectParameters[0] as $i => $columnParameters) { + if ($columnParameters[0] == self::SQL_STAR + || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) + || strpos($columnParameters[0], $starSuffix) + ) { + $selectParameters[0] = [[self::SQL_STAR]]; + break; + } + + if (isset($columnParameters[1])) { + array_shift($columnParameters); + $selectParameters[0][$i] = $columnParameters; + } + } + + // first, produce column list without compound names (using the AS portion only) + array_unshift($sqls, $this->createSqlFromSpecificationAndParameters( + ['SELECT %1$s FROM (' => current($this->specifications[self::SELECT])], + $selectParameters + )); + + if (preg_match('/DISTINCT/i', $sqls[0])) { + $this->setIsSelectContainDistinct(true); + } + + if ($parameterContainer) { + // create bottom part of query, with offset and limit using row_number + $limitParamName = $driver->formatParameterName('limit'); + $offsetParamName = $driver->formatParameterName('offset'); + + array_push($sqls, sprintf( + // @codingStandardsIgnoreStart + ") AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN %s AND %s", + // @codingStandardsIgnoreEnd + $offsetParamName, + $limitParamName + )); + + if ((int) $this->offset > 0) { + $parameterContainer->offsetSet('offset', (int) $this->offset + 1); + } else { + $parameterContainer->offsetSet('offset', (int) $this->offset); + } + + $parameterContainer->offsetSet('limit', (int) $this->limit + (int) $this->offset); + } else { + if ((int) $this->offset > 0) { + $offset = (int) $this->offset + 1; + } else { + $offset = (int) $this->offset; + } + + array_push($sqls, sprintf( + // @codingStandardsIgnoreStart + ") AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN %d AND %d", + // @codingStandardsIgnoreEnd + $offset, + (int) $this->limit + (int) $this->offset + )); + } + + if (isset($sqls[self::ORDER])) { + $orderBy = $sqls[self::ORDER]; + unset($sqls[self::ORDER]); + } else { + $orderBy = ''; + } + + // add a column for row_number() using the order specification //dense_rank() + if ($this->getIsSelectContainDistinct()) { + $parameters[self::SELECT][0][] = ['DENSE_RANK() OVER (' . $orderBy . ')', 'ZEND_DB_ROWNUM']; + } else { + $parameters[self::SELECT][0][] = ['ROW_NUMBER() OVER (' . $orderBy . ')', 'ZEND_DB_ROWNUM']; + } + + $sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters( + $this->specifications[self::SELECT], + $parameters[self::SELECT] + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php new file mode 100644 index 00000000..ea317653 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php @@ -0,0 +1,251 @@ + 0, + 'zerofill' => 1, + 'identity' => 2, + 'serial' => 2, + 'autoincrement' => 2, + 'comment' => 3, + 'columnformat' => 4, + 'format' => 4, + 'storage' => 5, + 'after' => 6 + ]; + + /** + * @param AlterTable $subject + * @return self Provides a fluent interface + */ + public function setSubject($subject) + { + $this->subject = $subject; + + return $this; + } + + /** + * @param string $sql + * @return array + */ + protected function getSqlInsertOffsets($sql) + { + $sqlLength = strlen($sql); + $insertStart = []; + + foreach (['NOT NULL', 'NULL', 'DEFAULT', 'UNIQUE', 'PRIMARY', 'REFERENCES'] as $needle) { + $insertPos = strpos($sql, ' ' . $needle); + + if ($insertPos !== false) { + switch ($needle) { + case 'REFERENCES': + $insertStart[2] = ! isset($insertStart[2]) ? $insertPos : $insertStart[2]; + // no break + case 'PRIMARY': + case 'UNIQUE': + $insertStart[1] = ! isset($insertStart[1]) ? $insertPos : $insertStart[1]; + // no break + default: + $insertStart[0] = ! isset($insertStart[0]) ? $insertPos : $insertStart[0]; + } + } + } + + foreach (range(0, 3) as $i) { + $insertStart[$i] = isset($insertStart[$i]) ? $insertStart[$i] : $sqlLength; + } + + return $insertStart; + } + + /** + * @param PlatformInterface $adapterPlatform + * @return array + */ + protected function processAddColumns(PlatformInterface $adapterPlatform = null) + { + $sqls = []; + + foreach ($this->addColumns as $i => $column) { + $sql = $this->processExpression($column, $adapterPlatform); + $insertStart = $this->getSqlInsertOffsets($sql); + $columnOptions = $column->getOptions(); + + uksort($columnOptions, [$this, 'compareColumnOptions']); + + foreach ($columnOptions as $coName => $coValue) { + $insert = ''; + + if (! $coValue) { + continue; + } + + switch ($this->normalizeColumnOption($coName)) { + case 'unsigned': + $insert = ' UNSIGNED'; + $j = 0; + break; + case 'zerofill': + $insert = ' ZEROFILL'; + $j = 0; + break; + case 'identity': + case 'serial': + case 'autoincrement': + $insert = ' AUTO_INCREMENT'; + $j = 1; + break; + case 'comment': + $insert = ' COMMENT ' . $adapterPlatform->quoteValue($coValue); + $j = 2; + break; + case 'columnformat': + case 'format': + $insert = ' COLUMN_FORMAT ' . strtoupper($coValue); + $j = 2; + break; + case 'storage': + $insert = ' STORAGE ' . strtoupper($coValue); + $j = 2; + break; + case 'after': + $insert = ' AFTER ' . $adapterPlatform->quoteIdentifier($coValue); + $j = 2; + } + + if ($insert) { + $j = isset($j) ? $j : 0; + $sql = substr_replace($sql, $insert, $insertStart[$j], 0); + $insertStartCount = count($insertStart); + for (; $j < $insertStartCount; ++$j) { + $insertStart[$j] += strlen($insert); + } + } + } + $sqls[$i] = $sql; + } + return [$sqls]; + } + + /** + * @param PlatformInterface $adapterPlatform + * @return array + */ + protected function processChangeColumns(PlatformInterface $adapterPlatform = null) + { + $sqls = []; + foreach ($this->changeColumns as $name => $column) { + $sql = $this->processExpression($column, $adapterPlatform); + $insertStart = $this->getSqlInsertOffsets($sql); + $columnOptions = $column->getOptions(); + + uksort($columnOptions, [$this, 'compareColumnOptions']); + + foreach ($columnOptions as $coName => $coValue) { + $insert = ''; + + if (! $coValue) { + continue; + } + + switch ($this->normalizeColumnOption($coName)) { + case 'unsigned': + $insert = ' UNSIGNED'; + $j = 0; + break; + case 'zerofill': + $insert = ' ZEROFILL'; + $j = 0; + break; + case 'identity': + case 'serial': + case 'autoincrement': + $insert = ' AUTO_INCREMENT'; + $j = 1; + break; + case 'comment': + $insert = ' COMMENT ' . $adapterPlatform->quoteValue($coValue); + $j = 2; + break; + case 'columnformat': + case 'format': + $insert = ' COLUMN_FORMAT ' . strtoupper($coValue); + $j = 2; + break; + case 'storage': + $insert = ' STORAGE ' . strtoupper($coValue); + $j = 2; + break; + } + + if ($insert) { + $j = isset($j) ? $j : 0; + $sql = substr_replace($sql, $insert, $insertStart[$j], 0); + $insertStartCount = count($insertStart); + for (; $j < $insertStartCount; ++$j) { + $insertStart[$j] += strlen($insert); + } + } + } + $sqls[] = [ + $adapterPlatform->quoteIdentifier($name), + $sql + ]; + } + + return [$sqls]; + } + + /** + * @param string $name + * + * @return string + */ + private function normalizeColumnOption($name) + { + return strtolower(str_replace(['-', '_', ' '], '', $name)); + } + + /** + * + * @param string $columnA + * @param string $columnB + * + * @return int + */ + private function compareColumnOptions($columnA, $columnB) + { + $columnA = $this->normalizeColumnOption($columnA); + $columnA = isset($this->columnOptionSortOrder[$columnA]) + ? $this->columnOptionSortOrder[$columnA] : count($this->columnOptionSortOrder); + + $columnB = $this->normalizeColumnOption($columnB); + $columnB = isset($this->columnOptionSortOrder[$columnB]) + ? $this->columnOptionSortOrder[$columnB] : count($this->columnOptionSortOrder); + + return $columnA - $columnB; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php new file mode 100644 index 00000000..fa8815a9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php @@ -0,0 +1,184 @@ + 0, + 'zerofill' => 1, + 'identity' => 2, + 'serial' => 2, + 'autoincrement' => 2, + 'comment' => 3, + 'columnformat' => 4, + 'format' => 4, + 'storage' => 5, + ]; + + /** + * @param CreateTable $subject + * + * @return self Provides a fluent interface + */ + public function setSubject($subject) + { + $this->subject = $subject; + + return $this; + } + + /** + * @param string $sql + * @return array + */ + protected function getSqlInsertOffsets($sql) + { + $sqlLength = strlen($sql); + $insertStart = []; + + foreach (['NOT NULL', 'NULL', 'DEFAULT', 'UNIQUE', 'PRIMARY', 'REFERENCES'] as $needle) { + $insertPos = strpos($sql, ' ' . $needle); + + if ($insertPos !== false) { + switch ($needle) { + case 'REFERENCES': + $insertStart[2] = ! isset($insertStart[2]) ? $insertPos : $insertStart[2]; + // no break + case 'PRIMARY': + case 'UNIQUE': + $insertStart[1] = ! isset($insertStart[1]) ? $insertPos : $insertStart[1]; + // no break + default: + $insertStart[0] = ! isset($insertStart[0]) ? $insertPos : $insertStart[0]; + } + } + } + + foreach (range(0, 3) as $i) { + $insertStart[$i] = isset($insertStart[$i]) ? $insertStart[$i] : $sqlLength; + } + + return $insertStart; + } + + /** + * {@inheritDoc} + */ + protected function processColumns(PlatformInterface $platform = null) + { + if (! $this->columns) { + return; + } + + $sqls = []; + + foreach ($this->columns as $i => $column) { + $sql = $this->processExpression($column, $platform); + $insertStart = $this->getSqlInsertOffsets($sql); + $columnOptions = $column->getOptions(); + + uksort($columnOptions, [$this, 'compareColumnOptions']); + + foreach ($columnOptions as $coName => $coValue) { + $insert = ''; + + if (! $coValue) { + continue; + } + + switch ($this->normalizeColumnOption($coName)) { + case 'unsigned': + $insert = ' UNSIGNED'; + $j = 0; + break; + case 'zerofill': + $insert = ' ZEROFILL'; + $j = 0; + break; + case 'identity': + case 'serial': + case 'autoincrement': + $insert = ' AUTO_INCREMENT'; + $j = 1; + break; + case 'comment': + $insert = ' COMMENT ' . $platform->quoteValue($coValue); + $j = 2; + break; + case 'columnformat': + case 'format': + $insert = ' COLUMN_FORMAT ' . strtoupper($coValue); + $j = 2; + break; + case 'storage': + $insert = ' STORAGE ' . strtoupper($coValue); + $j = 2; + break; + } + + if ($insert) { + $j = isset($j) ? $j : 0; + $sql = substr_replace($sql, $insert, $insertStart[$j], 0); + $insertStartCount = count($insertStart); + for (; $j < $insertStartCount; ++$j) { + $insertStart[$j] += strlen($insert); + } + } + } + + $sqls[$i] = $sql; + } + + return [$sqls]; + } + + /** + * @param string $name + * + * @return string + */ + private function normalizeColumnOption($name) + { + return strtolower(str_replace(['-', '_', ' '], '', $name)); + } + + /** + * + * @param string $columnA + * @param string $columnB + * + * @return int + */ + private function compareColumnOptions($columnA, $columnB) + { + $columnA = $this->normalizeColumnOption($columnA); + $columnA = isset($this->columnOptionSortOrder[$columnA]) + ? $this->columnOptionSortOrder[$columnA] : count($this->columnOptionSortOrder); + + $columnB = $this->normalizeColumnOption($columnB); + $columnB = isset($this->columnOptionSortOrder[$columnB]) + ? $this->columnOptionSortOrder[$columnB] : count($this->columnOptionSortOrder); + + return $columnA - $columnB; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Mysql.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Mysql.php similarity index 78% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Mysql.php rename to bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Mysql.php index fbf974a7..3e1611b8 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Mysql.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/Mysql.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -17,5 +17,6 @@ class Mysql extends AbstractPlatform { $this->setTypeDecorator('Zend\Db\Sql\Select', new SelectDecorator()); $this->setTypeDecorator('Zend\Db\Sql\Ddl\CreateTable', new Ddl\CreateTableDecorator()); + $this->setTypeDecorator('Zend\Db\Sql\Ddl\AlterTable', new Ddl\AlterTableDecorator()); } } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/SelectDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/SelectDecorator.php new file mode 100644 index 00000000..3ef7655c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Mysql/SelectDecorator.php @@ -0,0 +1,77 @@ +subject = $select; + } + + protected function localizeVariables() + { + parent::localizeVariables(); + if ($this->limit === null && $this->offset !== null) { + $this->specifications[self::LIMIT] = 'LIMIT 18446744073709551615'; + } + } + + protected function processLimit( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->limit === null && $this->offset !== null) { + return ['']; + } + if ($this->limit === null) { + return; + } + if ($parameterContainer) { + $paramPrefix = $this->processInfo['paramPrefix']; + $parameterContainer->offsetSet($paramPrefix . 'limit', $this->limit, ParameterContainer::TYPE_INTEGER); + return [$driver->formatParameterName($paramPrefix . 'limit')]; + } + + return [$this->limit]; + } + + protected function processOffset( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->offset === null) { + return; + } + if ($parameterContainer) { + $paramPrefix = $this->processInfo['paramPrefix']; + $parameterContainer->offsetSet($paramPrefix . 'offset', $this->offset, ParameterContainer::TYPE_INTEGER); + return [$driver->formatParameterName($paramPrefix . 'offset')]; + } + + return [$this->offset]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/Oracle.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Oracle/Oracle.php similarity index 89% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/Oracle.php rename to bundled-libs/zendframework/zend-db/src/Sql/Platform/Oracle/Oracle.php index c3f7b51b..bf1dc31d 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/Oracle.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Oracle/Oracle.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,10 +13,8 @@ use Zend\Db\Sql\Platform\AbstractPlatform; class Oracle extends AbstractPlatform { - public function __construct(SelectDecorator $selectDecorator = null) { $this->setTypeDecorator('Zend\Db\Sql\Select', ($selectDecorator) ?: new SelectDecorator()); } - } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/Oracle/SelectDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Oracle/SelectDecorator.php new file mode 100644 index 00000000..9961b4dc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Oracle/SelectDecorator.php @@ -0,0 +1,155 @@ +subject = $select; + } + + /** + * @see \Zend\Db\Sql\Select::renderTable + */ + protected function renderTable($table, $alias = null) + { + return $table . ($alias ? ' ' . $alias : ''); + } + + protected function localizeVariables() + { + parent::localizeVariables(); + unset($this->specifications[self::LIMIT]); + unset($this->specifications[self::OFFSET]); + + $this->specifications['LIMITOFFSET'] = null; + } + + /** + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @param array $sqls + * @param array $parameters + * @return null + */ + protected function processLimitOffset( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null, + &$sqls = [], + &$parameters = [] + ) { + if ($this->limit === null && $this->offset === null) { + return; + } + + $selectParameters = $parameters[self::SELECT]; + $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; + + foreach ($selectParameters[0] as $i => $columnParameters) { + if ($columnParameters[0] == self::SQL_STAR + || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) + || strpos($columnParameters[0], $starSuffix) + ) { + $selectParameters[0] = [[self::SQL_STAR]]; + break; + } + + if (isset($columnParameters[1])) { + array_shift($columnParameters); + $selectParameters[0][$i] = $columnParameters; + } + } + + if ($this->offset === null) { + $this->offset = 0; + } + + // first, produce column list without compound names (using the AS portion only) + array_unshift($sqls, $this->createSqlFromSpecificationAndParameters([ + 'SELECT %1$s FROM (SELECT b.%1$s, rownum b_rownum FROM (' => current($this->specifications[self::SELECT]), + ], $selectParameters)); + + if ($parameterContainer) { + $number = $this->processInfo['subselectCount'] ? $this->processInfo['subselectCount'] : ''; + + if ($this->limit === null) { + array_push( + $sqls, + ') b ) WHERE b_rownum > (:offset' . $number . ')' + ); + $parameterContainer->offsetSet( + 'offset' . $number, + $this->offset, + $parameterContainer::TYPE_INTEGER + ); + } else { + // create bottom part of query, with offset and limit using row_number + array_push( + $sqls, + ') b WHERE rownum <= (:offset' + . $number + . '+:limit' + . $number + . ')) WHERE b_rownum >= (:offset' + . $number + . ' + 1)' + ); + $parameterContainer->offsetSet( + 'offset' . $number, + $this->offset, + $parameterContainer::TYPE_INTEGER + ); + $parameterContainer->offsetSet( + 'limit' . $number, + $this->limit, + $parameterContainer::TYPE_INTEGER + ); + } + $this->processInfo['subselectCount']++; + } else { + if ($this->limit === null) { + array_push($sqls, ') b ) WHERE b_rownum > (' . (int) $this->offset . ')'); + } else { + array_push( + $sqls, + ') b WHERE rownum <= (' + . (int) $this->offset + . '+' + . (int) $this->limit + . ')) WHERE b_rownum >= (' + . (int) $this->offset + . ' + 1)' + ); + } + } + + $sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters( + $this->specifications[self::SELECT], + $parameters[self::SELECT] + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/Platform.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Platform.php new file mode 100644 index 00000000..e702caac --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Platform.php @@ -0,0 +1,173 @@ +defaultPlatform = $adapter->getPlatform(); + + $mySqlPlatform = new Mysql\Mysql(); + $sqlServerPlatform = new SqlServer\SqlServer(); + $oraclePlatform = new Oracle\Oracle(); + $ibmDb2Platform = new IbmDb2\IbmDb2(); + $sqlitePlatform = new Sqlite\Sqlite(); + + $this->decorators['mysql'] = $mySqlPlatform->getDecorators(); + $this->decorators['sqlserver'] = $sqlServerPlatform->getDecorators(); + $this->decorators['oracle'] = $oraclePlatform->getDecorators(); + $this->decorators['ibmdb2'] = $ibmDb2Platform->getDecorators(); + $this->decorators['sqlite'] = $sqlitePlatform->getDecorators(); + } + + /** + * @param string $type + * @param PlatformDecoratorInterface $decorator + * @param AdapterInterface|PlatformInterface $adapterOrPlatform + */ + public function setTypeDecorator($type, PlatformDecoratorInterface $decorator, $adapterOrPlatform = null) + { + $platformName = $this->resolvePlatformName($adapterOrPlatform); + $this->decorators[$platformName][$type] = $decorator; + } + + /** + * @param PreparableSqlInterface|SqlInterface $subject + * @param AdapterInterface|PlatformInterface|null $adapterOrPlatform + * @return PlatformDecoratorInterface|PreparableSqlInterface|SqlInterface + */ + public function getTypeDecorator($subject, $adapterOrPlatform = null) + { + $platformName = $this->resolvePlatformName($adapterOrPlatform); + + if (isset($this->decorators[$platformName])) { + foreach ($this->decorators[$platformName] as $type => $decorator) { + if ($subject instanceof $type && is_a($decorator, $type, true)) { + $decorator->setSubject($subject); + return $decorator; + } + } + } + + return $subject; + } + + /** + * @return array|PlatformDecoratorInterface[] + */ + public function getDecorators() + { + $platformName = $this->resolvePlatformName($this->getDefaultPlatform()); + return $this->decorators[$platformName]; + } + + /** + * {@inheritDoc} + * + * @throws Exception\RuntimeException + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + if (! $this->subject instanceof PreparableSqlInterface) { + throw new Exception\RuntimeException( + 'The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling ' + . 'prepareStatement() has no effect' + ); + } + + $this->getTypeDecorator($this->subject, $adapter)->prepareStatement($adapter, $statementContainer); + + return $statementContainer; + } + + /** + * {@inheritDoc} + * + * @throws Exception\RuntimeException + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + if (! $this->subject instanceof SqlInterface) { + throw new Exception\RuntimeException( + 'The subject does not appear to implement Zend\Db\Sql\SqlInterface, thus calling ' + . 'prepareStatement() has no effect' + ); + } + + $adapterPlatform = $this->resolvePlatform($adapterPlatform); + + return $this->getTypeDecorator($this->subject, $adapterPlatform)->getSqlString($adapterPlatform); + } + + protected function resolvePlatformName($adapterOrPlatform) + { + $platformName = $this->resolvePlatform($adapterOrPlatform)->getName(); + return str_replace([' ', '_'], '', strtolower($platformName)); + } + /** + * @param null|PlatformInterface|AdapterInterface $adapterOrPlatform + * + * @return PlatformInterface + * + * @throws Exception\InvalidArgumentException + */ + protected function resolvePlatform($adapterOrPlatform) + { + if (! $adapterOrPlatform) { + return $this->getDefaultPlatform(); + } + + if ($adapterOrPlatform instanceof AdapterInterface) { + return $adapterOrPlatform->getPlatform(); + } + + if ($adapterOrPlatform instanceof PlatformInterface) { + return $adapterOrPlatform; + } + + throw new Exception\InvalidArgumentException(sprintf( + '$adapterOrPlatform should be null, %s, or %s', + 'Zend\Db\Adapter\AdapterInterface', + 'Zend\Db\Adapter\Platform\PlatformInterface' + )); + } + + /** + * @return PlatformInterface + * + * @throws Exception\RuntimeException + */ + protected function getDefaultPlatform() + { + if (! $this->defaultPlatform) { + throw new Exception\RuntimeException('$this->defaultPlatform was not set'); + } + + return $this->defaultPlatform; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/PlatformDecoratorInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/PlatformDecoratorInterface.php similarity index 73% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/PlatformDecoratorInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/Platform/PlatformDecoratorInterface.php index c1daba74..f06c4340 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/PlatformDecoratorInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/PlatformDecoratorInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,5 +11,10 @@ namespace Zend\Db\Sql\Platform; interface PlatformDecoratorInterface { + /** + * @param $subject + * + * @return self + */ public function setSubject($subject); } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php new file mode 100644 index 00000000..0618682b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php @@ -0,0 +1,45 @@ +subject = $subject; + return $this; + } + + /** + * @param PlatformInterface $adapterPlatform + * @return array + */ + protected function processTable(PlatformInterface $adapterPlatform = null) + { + $table = ($this->isTemporary ? '#' : '') . ltrim($this->table, '#'); + return [ + '', + $adapterPlatform->quoteIdentifier($table), + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SelectDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/SelectDecorator.php similarity index 61% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SelectDecorator.php rename to bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/SelectDecorator.php index 2b649cdc..642d10b5 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SelectDecorator.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/SelectDecorator.php @@ -3,17 +3,15 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql\Platform\SqlServer; -use Zend\Db\Adapter\AdapterInterface; use Zend\Db\Adapter\Driver\DriverInterface; use Zend\Db\Adapter\ParameterContainer; use Zend\Db\Adapter\Platform\PlatformInterface; -use Zend\Db\Adapter\StatementContainerInterface; use Zend\Db\Sql\Platform\PlatformDecoratorInterface; use Zend\Db\Sql\Select; @@ -22,52 +20,24 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface /** * @var Select */ - protected $select = null; + protected $subject = null; /** * @param Select $select */ public function setSubject($select) { - $this->select = $select; + $this->subject = $select; } - /** - * @param AdapterInterface $adapter - * @param StatementContainerInterface $statementContainer - */ - public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + protected function localizeVariables() { - // localize variables - foreach (get_object_vars($this->select) as $name => $value) { - $this->{$name} = $value; - } - + parent::localizeVariables(); // set specifications unset($this->specifications[self::LIMIT]); unset($this->specifications[self::OFFSET]); $this->specifications['LIMITOFFSET'] = null; - parent::prepareStatement($adapter, $statementContainer); - } - - /** - * @param PlatformInterface $platform - * @return string - */ - public function getSqlString(PlatformInterface $platform = null) - { - // localize variables - foreach (get_object_vars($this->select) as $name => $value) { - $this->{$name} = $value; - } - - // set specifications - unset($this->specifications[self::LIMIT]); - unset($this->specifications[self::OFFSET]); - - $this->specifications['LIMITOFFSET'] = null; - return parent::getSqlString($platform); } /** @@ -78,18 +48,34 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface * @param $parameters * @return null */ - protected function processLimitOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, &$sqls, &$parameters) - { + protected function processLimitOffset( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null, + &$sqls, + &$parameters + ) { if ($this->limit === null && $this->offset === null) { - return null; + return; } $selectParameters = $parameters[self::SELECT]; + /** if this is a DISTINCT query then real SELECT part goes to second element in array **/ + $parameterIndex = 0; + if ($selectParameters[0] === 'DISTINCT') { + unset($selectParameters[0]); + $selectParameters = array_values($selectParameters); + $parameterIndex = 1; + } + $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; foreach ($selectParameters[0] as $i => $columnParameters) { - if ($columnParameters[0] == self::SQL_STAR || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) || strpos($columnParameters[0], $starSuffix)) { - $selectParameters[0] = array(array(self::SQL_STAR)); + if ($columnParameters[0] == self::SQL_STAR + || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) + || strpos($columnParameters[0], $starSuffix) + ) { + $selectParameters[0] = [[self::SQL_STAR]]; break; } if (isset($columnParameters[1])) { @@ -100,21 +86,28 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface // first, produce column list without compound names (using the AS portion only) array_unshift($sqls, $this->createSqlFromSpecificationAndParameters( - array('SELECT %1$s FROM (' => current($this->specifications[self::SELECT])), + ['SELECT %1$s FROM (' => current($this->specifications[self::SELECT])], $selectParameters )); if ($parameterContainer) { // create bottom part of query, with offset and limit using row_number - array_push($sqls, ') AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?'); + $limitParamName = $driver->formatParameterName('limit'); + $offsetParamName = $driver->formatParameterName('offset'); + $offsetForSumParamName = $driver->formatParameterName('offsetForSum'); + // @codingStandardsIgnoreStart + array_push($sqls, ') AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ' + . $offsetParamName . '+1 AND ' . $limitParamName . '+' . $offsetForSumParamName); + // @codingStandardsIgnoreEnd $parameterContainer->offsetSet('offset', $this->offset); $parameterContainer->offsetSet('limit', $this->limit); $parameterContainer->offsetSetReference('offsetForSum', 'offset'); } else { + // @codingStandardsIgnoreStart array_push($sqls, ') AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ' . (int) $this->offset . '+1 AND ' - . (int) $this->limit . '+' . (int) $this->offset - ); + . (int) $this->limit . '+' . (int) $this->offset); + // @codingStandardsIgnoreEnd } if (isset($sqls[self::ORDER])) { @@ -125,12 +118,11 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface } // add a column for row_number() using the order specification - $parameters[self::SELECT][0][] = array('ROW_NUMBER() OVER (' . $orderBy . ')', '[__ZEND_ROW_NUMBER]'); + $parameters[self::SELECT][$parameterIndex][] = ['ROW_NUMBER() OVER (' . $orderBy . ')', '[__ZEND_ROW_NUMBER]']; $sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters( $this->specifications[self::SELECT], $parameters[self::SELECT] ); - } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SqlServer.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/SqlServer.php similarity index 77% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SqlServer.php rename to bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/SqlServer.php index 3ee9d7c1..0dc383d0 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SqlServer.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/SqlServer/SqlServer.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,9 +13,9 @@ use Zend\Db\Sql\Platform\AbstractPlatform; class SqlServer extends AbstractPlatform { - public function __construct(SelectDecorator $selectDecorator = null) { $this->setTypeDecorator('Zend\Db\Sql\Select', ($selectDecorator) ?: new SelectDecorator()); + $this->setTypeDecorator('Zend\Db\Sql\Ddl\CreateTable', new Ddl\CreateTableDecorator()); } } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/SelectDecorator.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/SelectDecorator.php new file mode 100644 index 00000000..a1b3d6c5 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/SelectDecorator.php @@ -0,0 +1,105 @@ +subject = $select; + + return $this; + } + + /** + * {@inheritDoc} + */ + protected function localizeVariables() + { + parent::localizeVariables(); + $this->specifications[self::COMBINE] = '%1$s %2$s'; + } + + /** + * {@inheritDoc} + */ + protected function processStatementStart( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return ''; + } + + protected function processLimit( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->limit === null && $this->offset !== null) { + return ['']; + } + if ($this->limit === null) { + return; + } + if ($parameterContainer) { + $paramPrefix = $this->processInfo['paramPrefix']; + $parameterContainer->offsetSet($paramPrefix . 'limit', $this->limit, ParameterContainer::TYPE_INTEGER); + return [$driver->formatParameterName('limit')]; + } + + return [$this->limit]; + } + + protected function processOffset( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->offset === null) { + return; + } + if ($parameterContainer) { + $paramPrefix = $this->processInfo['paramPrefix']; + $parameterContainer->offsetSet($paramPrefix . 'offset', $this->offset, ParameterContainer::TYPE_INTEGER); + return [$driver->formatParameterName('offset')]; + } + + return [$this->offset]; + } + + /** + * {@inheritDoc} + */ + protected function processStatementEnd( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return ''; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/Sqlite.php b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/Sqlite.php new file mode 100644 index 00000000..00712dde --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Platform/Sqlite/Sqlite.php @@ -0,0 +1,25 @@ +setTypeDecorator('Zend\Db\Sql\Select', new SelectDecorator()); + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Between.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Between.php similarity index 78% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Between.php rename to bundled-libs/zendframework/zend-db/src/Sql/Predicate/Between.php index 4516c9e2..4b1545eb 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Between.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Between.php @@ -3,13 +3,15 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql\Predicate; -class Between implements PredicateInterface +use Zend\Db\Sql\AbstractExpression; + +class Between extends AbstractExpression implements PredicateInterface { protected $specification = '%1$s BETWEEN %2$s AND %3$s'; protected $identifier = null; @@ -40,7 +42,7 @@ class Between implements PredicateInterface * Set identifier for comparison * * @param string $identifier - * @return Between + * @return self Provides a fluent interface */ public function setIdentifier($identifier) { @@ -62,7 +64,7 @@ class Between implements PredicateInterface * Set minimum boundary for comparison * * @param int|float|string $minValue - * @return Between + * @return self Provides a fluent interface */ public function setMinValue($minValue) { @@ -84,7 +86,7 @@ class Between implements PredicateInterface * Set maximum boundary for comparison * * @param int|float|string $maxValue - * @return Between + * @return self Provides a fluent interface */ public function setMaxValue($maxValue) { @@ -106,7 +108,7 @@ class Between implements PredicateInterface * Set specification string to use in forming SQL predicate * * @param string $specification - * @return Between + * @return self Provides a fluent interface */ public function setSpecification($specification) { @@ -131,12 +133,15 @@ class Between implements PredicateInterface */ public function getExpressionData() { - return array( - array( + list($values[], $types[]) = $this->normalizeArgument($this->identifier, self::TYPE_IDENTIFIER); + list($values[], $types[]) = $this->normalizeArgument($this->minValue, self::TYPE_VALUE); + list($values[], $types[]) = $this->normalizeArgument($this->maxValue, self::TYPE_VALUE); + return [ + [ $this->getSpecification(), - array($this->identifier, $this->minValue, $this->maxValue), - array(self::TYPE_IDENTIFIER, self::TYPE_VALUE, self::TYPE_VALUE), - ), - ); + $values, + $types, + ], + ]; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Expression.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Expression.php similarity index 59% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Expression.php rename to bundled-libs/zendframework/zend-db/src/Sql/Predicate/Expression.php index 042c4d90..e9b5363f 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Expression.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Expression.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,7 +13,6 @@ use Zend\Db\Sql\Expression as BaseExpression; class Expression extends BaseExpression implements PredicateInterface { - /** * Constructor * @@ -26,17 +25,6 @@ class Expression extends BaseExpression implements PredicateInterface $this->setExpression($expression); } - if (is_array($valueParameter)) { - $this->setParameters($valueParameter); - } else { - $argNum = func_num_args(); - if ($argNum > 2 || is_scalar($valueParameter)) { - $parameters = array(); - for ($i = 1; $i < $argNum; $i++) { - $parameters[] = func_get_arg($i); - } - $this->setParameters($parameters); - } - } + $this->setParameters(is_array($valueParameter) ? $valueParameter : array_slice(func_get_args(), 1)); } } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Predicate/In.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/In.php new file mode 100644 index 00000000..0c62189c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/In.php @@ -0,0 +1,140 @@ +setIdentifier($identifier); + } + if ($valueSet !== null) { + $this->setValueSet($valueSet); + } + } + + /** + * Set identifier for comparison + * + * @param string|array $identifier + * @return self Provides a fluent interface + */ + public function setIdentifier($identifier) + { + $this->identifier = $identifier; + + return $this; + } + + /** + * Get identifier of comparison + * + * @return null|string|array + */ + public function getIdentifier() + { + return $this->identifier; + } + + /** + * Set set of values for IN comparison + * + * @param array|Select $valueSet + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function setValueSet($valueSet) + { + if (! is_array($valueSet) && ! $valueSet instanceof Select) { + throw new Exception\InvalidArgumentException( + '$valueSet must be either an array or a Zend\Db\Sql\Select object, ' . gettype($valueSet) . ' given' + ); + } + $this->valueSet = $valueSet; + + return $this; + } + + /** + * Gets set of values in IN comparison + * + * @return array|Select + */ + public function getValueSet() + { + return $this->valueSet; + } + + /** + * Return array of parts for where statement + * + * @return array + */ + public function getExpressionData() + { + $identifier = $this->getIdentifier(); + $values = $this->getValueSet(); + $replacements = []; + + if (is_array($identifier)) { + $countIdentifier = count($identifier); + $identifierSpecFragment = '(' . implode(', ', array_fill(0, $countIdentifier, '%s')) . ')'; + $types = array_fill(0, $countIdentifier, self::TYPE_IDENTIFIER); + $replacements = $identifier; + } else { + $identifierSpecFragment = '%s'; + $replacements[] = $identifier; + $types = [self::TYPE_IDENTIFIER]; + } + + if ($values instanceof Select) { + $specification = vsprintf( + $this->specification, + [$identifierSpecFragment, '%s'] + ); + $replacements[] = $values; + $types[] = self::TYPE_VALUE; + } else { + foreach ($values as $argument) { + list($replacements[], $types[]) = $this->normalizeArgument($argument, self::TYPE_VALUE); + } + $countValues = count($values); + $valuePlaceholders = $countValues > 0 ? array_fill(0, $countValues, '%s') : []; + $specification = vsprintf( + $this->specification, + [$identifierSpecFragment, '(' . implode(', ', $valuePlaceholders) . ')'] + ); + } + + return [[ + $specification, + $replacements, + $types, + ]]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNotNull.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/IsNotNull.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNotNull.php rename to bundled-libs/zendframework/zend-db/src/Sql/Predicate/IsNotNull.php index 137b8f78..e42c9aa5 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNotNull.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/IsNotNull.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNull.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/IsNull.php similarity index 78% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNull.php rename to bundled-libs/zendframework/zend-db/src/Sql/Predicate/IsNull.php index f53f94ca..daf45f3c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNull.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/IsNull.php @@ -3,15 +3,16 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql\Predicate; -class IsNull implements PredicateInterface -{ +use Zend\Db\Sql\AbstractExpression; +class IsNull extends AbstractExpression implements PredicateInterface +{ /** * @var string */ @@ -38,7 +39,7 @@ class IsNull implements PredicateInterface * Set identifier for comparison * * @param string $identifier - * @return IsNull + * @return self Provides a fluent interface */ public function setIdentifier($identifier) { @@ -60,7 +61,7 @@ class IsNull implements PredicateInterface * Set specification string to use in forming SQL predicate * * @param string $specification - * @return IsNull + * @return self Provides a fluent interface */ public function setSpecification($specification) { @@ -85,10 +86,11 @@ class IsNull implements PredicateInterface */ public function getExpressionData() { - return array(array( + $identifier = $this->normalizeArgument($this->identifier, self::TYPE_IDENTIFIER); + return [[ $this->getSpecification(), - array($this->identifier), - array(self::TYPE_IDENTIFIER), - )); + [$identifier[0]], + [$identifier[1]], + ]]; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Like.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Like.php similarity index 66% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Like.php rename to bundled-libs/zendframework/zend-db/src/Sql/Predicate/Like.php index 6e4658da..2f1ffde7 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Like.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Like.php @@ -3,15 +3,16 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql\Predicate; -class Like implements PredicateInterface -{ +use Zend\Db\Sql\AbstractExpression; +class Like extends AbstractExpression implements PredicateInterface +{ /** * @var string */ @@ -42,11 +43,13 @@ class Like implements PredicateInterface } /** - * @param $identifier + * @param string $identifier + * @return self Provides a fluent interface */ public function setIdentifier($identifier) { $this->identifier = $identifier; + return $this; } /** @@ -58,11 +61,13 @@ class Like implements PredicateInterface } /** - * @param $like + * @param string $like + * @return self Provides a fluent interface */ public function setLike($like) { $this->like = $like; + return $this; } /** @@ -74,11 +79,13 @@ class Like implements PredicateInterface } /** - * @param $specification + * @param string $specification + * @return self Provides a fluent interface */ public function setSpecification($specification) { $this->specification = $specification; + return $this; } /** @@ -94,8 +101,14 @@ class Like implements PredicateInterface */ public function getExpressionData() { - return array( - array($this->specification, array($this->identifier, $this->like), array(self::TYPE_IDENTIFIER, self::TYPE_VALUE)) - ); + list($values[], $types[]) = $this->normalizeArgument($this->identifier, self::TYPE_IDENTIFIER); + list($values[], $types[]) = $this->normalizeArgument($this->like, self::TYPE_VALUE); + return [ + [ + $this->specification, + $values, + $types, + ] + ]; } } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Literal.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Literal.php new file mode 100644 index 00000000..d4b509fc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Literal.php @@ -0,0 +1,16 @@ +='; const OP_GTE = '>='; - protected $allowedTypes = array( + /** + * {@inheritDoc} + */ + protected $allowedTypes = [ self::TYPE_IDENTIFIER, self::TYPE_VALUE, - ); + ]; - protected $left = null; - protected $leftType = self::TYPE_IDENTIFIER; - protected $operator = self::OPERATOR_EQUAL_TO; - protected $right = null; - protected $rightType = self::TYPE_VALUE; + /** + * @var int|float|bool|string + */ + protected $left; + + /** + * @var int|float|bool|string + */ + protected $right; + + /** + * @var string + */ + protected $leftType = self::TYPE_IDENTIFIER; + + /** + * @var string + */ + protected $rightType = self::TYPE_VALUE; + + /** + * @var string + */ + protected $operator = self::OPERATOR_EQUAL_TO; /** * Constructor * - * @param int|float|bool|string $left - * @param string $operator - * @param int|float|bool|string $right - * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} - * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + * @param int|float|bool|string $left + * @param string $operator + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} */ - public function __construct($left = null, $operator = self::OPERATOR_EQUAL_TO, $right = null, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) - { + public function __construct( + $left = null, + $operator = self::OPERATOR_EQUAL_TO, + $right = null, + $leftType = self::TYPE_IDENTIFIER, + $rightType = self::TYPE_VALUE + ) { if ($left !== null) { $this->setLeft($left); } @@ -78,11 +106,18 @@ class Operator implements PredicateInterface * Set left side of operator * * @param int|float|bool|string $left - * @return Operator + * + * @return self Provides a fluent interface */ public function setLeft($left) { $this->left = $left; + + if (is_array($left)) { + $left = $this->normalizeArgument($left, $this->leftType); + $this->leftType = $left[1]; + } + return $this; } @@ -100,12 +135,14 @@ class Operator implements PredicateInterface * Set parameter type for left side of operator * * @param string $type TYPE_IDENTIFIER or TYPE_VALUE {@see allowedTypes} + * + * @return self Provides a fluent interface + * * @throws Exception\InvalidArgumentException - * @return Operator */ public function setLeftType($type) { - if (!in_array($type, $this->allowedTypes)) { + if (! in_array($type, $this->allowedTypes)) { throw new Exception\InvalidArgumentException(sprintf( 'Invalid type "%s" provided; must be of type "%s" or "%s"', $type, @@ -113,7 +150,9 @@ class Operator implements PredicateInterface __CLASS__ . '::TYPE_VALUE' )); } + $this->leftType = $type; + return $this; } @@ -131,11 +170,12 @@ class Operator implements PredicateInterface * Set operator string * * @param string $operator - * @return Operator + * @return self Provides a fluent interface */ public function setOperator($operator) { $this->operator = $operator; + return $this; } @@ -152,12 +192,19 @@ class Operator implements PredicateInterface /** * Set right side of operator * - * @param int|float|bool|string $value - * @return Operator + * @param int|float|bool|string $right + * + * @return self Provides a fluent interface */ - public function setRight($value) + public function setRight($right) { - $this->right = $value; + $this->right = $right; + + if (is_array($right)) { + $right = $this->normalizeArgument($right, $this->rightType); + $this->rightType = $right[1]; + } + return $this; } @@ -175,12 +222,12 @@ class Operator implements PredicateInterface * Set parameter type for right side of operator * * @param string $type TYPE_IDENTIFIER or TYPE_VALUE {@see allowedTypes} + * @return self Provides a fluent interface * @throws Exception\InvalidArgumentException - * @return Operator */ public function setRightType($type) { - if (!in_array($type, $this->allowedTypes)) { + if (! in_array($type, $this->allowedTypes)) { throw new Exception\InvalidArgumentException(sprintf( 'Invalid type "%s" provided; must be of type "%s" or "%s"', $type, @@ -188,7 +235,9 @@ class Operator implements PredicateInterface __CLASS__ . '::TYPE_VALUE' )); } + $this->rightType = $type; + return $this; } @@ -209,10 +258,13 @@ class Operator implements PredicateInterface */ public function getExpressionData() { - return array(array( + list($values[], $types[]) = $this->normalizeArgument($this->left, $this->leftType); + list($values[], $types[]) = $this->normalizeArgument($this->right, $this->rightType); + + return [[ '%s ' . $this->operator . ' %s', - array($this->left, $this->right), - array($this->leftType, $this->rightType) - )); + $values, + $types + ]]; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Predicate.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Predicate.php similarity index 72% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Predicate.php rename to bundled-libs/zendframework/zend-db/src/Sql/Predicate/Predicate.php index 7581e2a7..a7d901d7 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/Predicate.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/Predicate.php @@ -3,12 +3,14 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql\Predicate; +use Zend\Db\Sql\Exception\RuntimeException; + /** * @property Predicate $and * @property Predicate $or @@ -51,16 +53,16 @@ class Predicate extends PredicateSet * Indicate end of nested predicate * * @return Predicate - * @throws \RuntimeException + * @throws RuntimeException */ public function unnest() { - if ($this->unnest == null) { - throw new \RuntimeException('Not nested'); + if ($this->unnest === null) { + throw new RuntimeException('Not nested'); } - $unnset = $this->unnest; + $unnest = $this->unnest; $this->unnest = null; - return $unnset; + return $unnest; } /** @@ -72,7 +74,7 @@ class Predicate extends PredicateSet * @param int|float|bool|string $right * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} - * @return Predicate + * @return self Provides a fluent interface */ public function equalTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) { @@ -94,7 +96,7 @@ class Predicate extends PredicateSet * @param int|float|bool|string $right * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} - * @return Predicate + * @return self Provides a fluent interface */ public function notEqualTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) { @@ -116,7 +118,7 @@ class Predicate extends PredicateSet * @param int|float|bool|string $right * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} - * @return Predicate + * @return self Provides a fluent interface */ public function lessThan($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) { @@ -138,7 +140,7 @@ class Predicate extends PredicateSet * @param int|float|bool|string $right * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} - * @return Predicate + * @return self Provides a fluent interface */ public function greaterThan($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) { @@ -160,7 +162,7 @@ class Predicate extends PredicateSet * @param int|float|bool|string $right * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} - * @return Predicate + * @return self Provides a fluent interface */ public function lessThanOrEqualTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) { @@ -182,10 +184,14 @@ class Predicate extends PredicateSet * @param int|float|bool|string $right * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} - * @return Predicate + * @return self Provides a fluent interface */ - public function greaterThanOrEqualTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) - { + public function greaterThanOrEqualTo( + $left, + $right, + $leftType = self::TYPE_IDENTIFIER, + $rightType = self::TYPE_VALUE + ) { $this->addPredicate( new Operator($left, Operator::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $right, $leftType, $rightType), ($this->nextPredicateCombineOperator) ?: $this->defaultCombination @@ -200,9 +206,9 @@ class Predicate extends PredicateSet * * Utilizes Like predicate * - * @param string $identifier + * @param string|Expression $identifier * @param string $like - * @return Predicate + * @return self Provides a fluent interface */ public function like($identifier, $like) { @@ -214,15 +220,33 @@ class Predicate extends PredicateSet return $this; } + /** + * Create "notLike" predicate + * + * Utilizes In predicate + * + * @param string|Expression $identifier + * @param string $notLike + * @return self Provides a fluent interface + */ + public function notLike($identifier, $notLike) + { + $this->addPredicate( + new NotLike($identifier, $notLike), + ($this->nextPredicateCombineOperator) ? : $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + return $this; + } /** * Create an expression, with parameter placeholders * * @param $expression * @param $parameters - * @return $this + * @return self Provides a fluent interface */ - public function expression($expression, $parameters) + public function expression($expression, $parameters = null) { $this->addPredicate( new Expression($expression, $parameters), @@ -239,7 +263,7 @@ class Predicate extends PredicateSet * Literal predicate, for parameters, use expression() * * @param string $literal - * @return Predicate + * @return self Provides a fluent interface */ public function literal($literal) { @@ -250,7 +274,7 @@ class Predicate extends PredicateSet } // normal workflow for "Literals" here - if (!isset($predicate)) { + if (! isset($predicate)) { $predicate = new Literal($literal); } @@ -268,8 +292,8 @@ class Predicate extends PredicateSet * * Utilizes IsNull predicate * - * @param string $identifier - * @return Predicate + * @param string|Expression $identifier + * @return self Provides a fluent interface */ public function isNull($identifier) { @@ -287,8 +311,8 @@ class Predicate extends PredicateSet * * Utilizes IsNotNull predicate * - * @param string $identifier - * @return Predicate + * @param string|Expression $identifier + * @return self Provides a fluent interface */ public function isNotNull($identifier) { @@ -302,13 +326,13 @@ class Predicate extends PredicateSet } /** - * Create "in" predicate + * Create "IN" predicate * * Utilizes In predicate * - * @param string $identifier + * @param string|Expression $identifier * @param array|\Zend\Db\Sql\Select $valueSet - * @return Predicate + * @return self Provides a fluent interface */ public function in($identifier, $valueSet = null) { @@ -321,15 +345,35 @@ class Predicate extends PredicateSet return $this; } + /** + * Create "NOT IN" predicate + * + * Utilizes NotIn predicate + * + * @param string|Expression $identifier + * @param array|\Zend\Db\Sql\Select $valueSet + * @return self Provides a fluent interface + */ + public function notIn($identifier, $valueSet = null) + { + $this->addPredicate( + new NotIn($identifier, $valueSet), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + /** * Create "between" predicate * * Utilizes Between predicate * - * @param string $identifier + * @param string|Expression $identifier * @param int|float|string $minValue * @param int|float|string $maxValue - * @return Predicate + * @return self Provides a fluent interface */ public function between($identifier, $minValue, $maxValue) { @@ -342,13 +386,55 @@ class Predicate extends PredicateSet return $this; } + /** + * Create "NOT BETWEEN" predicate + * + * Utilizes NotBetween predicate + * + * @param string|Expression $identifier + * @param int|float|string $minValue + * @param int|float|string $maxValue + * @return self Provides a fluent interface + */ + public function notBetween($identifier, $minValue, $maxValue) + { + $this->addPredicate( + new NotBetween($identifier, $minValue, $maxValue), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Use given predicate directly + * + * Contrary to {@link addPredicate()} this method respects formerly set + * AND / OR combination operator, thus allowing generic predicates to be + * used fluently within where chains as any other concrete predicate. + * + * @param PredicateInterface $predicate + * @return self Provides a fluent interface + */ + public function predicate(PredicateInterface $predicate) + { + $this->addPredicate( + $predicate, + $this->nextPredicateCombineOperator ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + /** * Overloading * * Overloads "or", "and", "nest", and "unnest" * * @param string $name - * @return Predicate + * @return self Provides a fluent interface */ public function __get($name) { diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/PredicateInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/Predicate/PredicateInterface.php index 203f4707..b8d6c84b 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/PredicateInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,5 +13,4 @@ use Zend\Db\Sql\ExpressionInterface; interface PredicateInterface extends ExpressionInterface { - } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Predicate/PredicateSet.php b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/PredicateSet.php new file mode 100644 index 00000000..9bf545dc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Predicate/PredicateSet.php @@ -0,0 +1,201 @@ +defaultCombination = $defaultCombination; + if ($predicates) { + foreach ($predicates as $predicate) { + $this->addPredicate($predicate); + } + } + } + + /** + * Add predicate to set + * + * @param PredicateInterface $predicate + * @param string $combination + * @return self Provides a fluent interface + */ + public function addPredicate(PredicateInterface $predicate, $combination = null) + { + if ($combination === null || ! in_array($combination, [self::OP_AND, self::OP_OR])) { + $combination = $this->defaultCombination; + } + + if ($combination == self::OP_OR) { + $this->orPredicate($predicate); + return $this; + } + + $this->andPredicate($predicate); + return $this; + } + + /** + * Add predicates to set + * + * @param PredicateInterface|\Closure|string|array $predicates + * @param string $combination + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function addPredicates($predicates, $combination = self::OP_AND) + { + if ($predicates === null) { + throw new Exception\InvalidArgumentException('Predicate cannot be null'); + } + if ($predicates instanceof PredicateInterface) { + $this->addPredicate($predicates, $combination); + return $this; + } + if ($predicates instanceof \Closure) { + $predicates($this); + return $this; + } + if (is_string($predicates)) { + // String $predicate should be passed as an expression + $predicates = (strpos($predicates, Expression::PLACEHOLDER) !== false) + ? new Expression($predicates) : new Literal($predicates); + $this->addPredicate($predicates, $combination); + return $this; + } + if (is_array($predicates)) { + foreach ($predicates as $pkey => $pvalue) { + // loop through predicates + if (is_string($pkey)) { + if (strpos($pkey, '?') !== false) { + // First, process strings that the abstraction replacement character ? + // as an Expression predicate + $predicates = new Expression($pkey, $pvalue); + } elseif ($pvalue === null) { + // Otherwise, if still a string, do something intelligent with the PHP type provided + // map PHP null to SQL IS NULL expression + $predicates = new IsNull($pkey); + } elseif (is_array($pvalue)) { + // if the value is an array, assume IN() is desired + $predicates = new In($pkey, $pvalue); + } elseif ($pvalue instanceof PredicateInterface) { + throw new Exception\InvalidArgumentException( + 'Using Predicate must not use string keys' + ); + } else { + // otherwise assume that array('foo' => 'bar') means "foo" = 'bar' + $predicates = new Operator($pkey, Operator::OP_EQ, $pvalue); + } + } elseif ($pvalue instanceof PredicateInterface) { + // Predicate type is ok + $predicates = $pvalue; + } else { + // must be an array of expressions (with int-indexed array) + $predicates = (strpos($pvalue, Expression::PLACEHOLDER) !== false) + ? new Expression($pvalue) : new Literal($pvalue); + } + $this->addPredicate($predicates, $combination); + } + } + return $this; + } + + /** + * Return the predicates + * + * @return PredicateInterface[] + */ + public function getPredicates() + { + return $this->predicates; + } + + /** + * Add predicate using OR operator + * + * @param PredicateInterface $predicate + * @return self Provides a fluent interface + */ + public function orPredicate(PredicateInterface $predicate) + { + $this->predicates[] = [self::OP_OR, $predicate]; + return $this; + } + + /** + * Add predicate using AND operator + * + * @param PredicateInterface $predicate + * @return self Provides a fluent interface + */ + public function andPredicate(PredicateInterface $predicate) + { + $this->predicates[] = [self::OP_AND, $predicate]; + return $this; + } + + /** + * Get predicate parts for where statement + * + * @return array + */ + public function getExpressionData() + { + $parts = []; + for ($i = 0, $count = count($this->predicates); $i < $count; $i++) { + /** @var $predicate PredicateInterface */ + $predicate = $this->predicates[$i][1]; + + if ($predicate instanceof PredicateSet) { + $parts[] = '('; + } + + $parts = array_merge($parts, $predicate->getExpressionData()); + + if ($predicate instanceof PredicateSet) { + $parts[] = ')'; + } + + if (isset($this->predicates[$i + 1])) { + $parts[] = sprintf(' %s ', $this->predicates[$i + 1][0]); + } + } + return $parts; + } + + /** + * Get count of attached predicates + * + * @return int + */ + public function count() + { + return count($this->predicates); + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/PreparableSqlInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/PreparableSqlInterface.php similarity index 83% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/PreparableSqlInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/PreparableSqlInterface.php index b20bb2e2..f937e07b 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/PreparableSqlInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/PreparableSqlInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,10 +14,10 @@ use Zend\Db\Adapter\StatementContainerInterface; interface PreparableSqlInterface { - /** - * @param AdapterInterface $adapter + * @param AdapterInterface $adapter * @param StatementContainerInterface $statementContainer + * * @return void */ public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer); diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Select.php b/bundled-libs/zendframework/zend-db/src/Sql/Select.php new file mode 100644 index 00000000..c0d360e7 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Select.php @@ -0,0 +1,836 @@ + '%1$s', + self::SELECT => [ + 'SELECT %1$s FROM %2$s' => [ + [1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '], + null + ], + 'SELECT %1$s %2$s FROM %3$s' => [ + null, + [1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '], + null + ], + 'SELECT %1$s' => [ + [1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '], + ], + ], + self::JOINS => [ + '%1$s' => [ + [3 => '%1$s JOIN %2$s ON %3$s', 'combinedby' => ' '] + ] + ], + self::WHERE => 'WHERE %1$s', + self::GROUP => [ + 'GROUP BY %1$s' => [ + [1 => '%1$s', 'combinedby' => ', '] + ] + ], + self::HAVING => 'HAVING %1$s', + self::ORDER => [ + 'ORDER BY %1$s' => [ + [1 => '%1$s', 2 => '%1$s %2$s', 'combinedby' => ', '] + ] + ], + self::LIMIT => 'LIMIT %1$s', + self::OFFSET => 'OFFSET %1$s', + 'statementEnd' => '%1$s', + self::COMBINE => '%1$s ( %2$s )', + ]; + + /** + * @var bool + */ + protected $tableReadOnly = false; + + /** + * @var bool + */ + protected $prefixColumnsWithTable = true; + + /** + * @var string|array|TableIdentifier + */ + protected $table = null; + + /** + * @var null|string|Expression + */ + protected $quantifier = null; + + /** + * @var array + */ + protected $columns = [self::SQL_STAR]; + + /** + * @var null|Join + */ + protected $joins = null; + + /** + * @var Where + */ + protected $where = null; + + /** + * @var array + */ + protected $order = []; + + /** + * @var null|array + */ + protected $group = null; + + /** + * @var null|string|array + */ + protected $having = null; + + /** + * @var int|null + */ + protected $limit = null; + + /** + * @var int|null + */ + protected $offset = null; + + /** + * @var array + */ + protected $combine = []; + + /** + * Constructor + * + * @param null|string|array|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->from($table); + $this->tableReadOnly = true; + } + + $this->where = new Where; + $this->joins = new Join; + $this->having = new Having; + } + + /** + * Create from clause + * + * @param string|array|TableIdentifier $table + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function from($table) + { + if ($this->tableReadOnly) { + throw new Exception\InvalidArgumentException( + 'Since this object was created with a table and/or schema in the constructor, it is read only.' + ); + } + + if (! is_string($table) && ! is_array($table) && ! $table instanceof TableIdentifier) { + throw new Exception\InvalidArgumentException( + '$table must be a string, array, or an instance of TableIdentifier' + ); + } + + if (is_array($table) && (! is_string(key($table)) || count($table) !== 1)) { + throw new Exception\InvalidArgumentException( + 'from() expects $table as an array is a single element associative array' + ); + } + + $this->table = $table; + return $this; + } + + /** + * @param string|Expression $quantifier DISTINCT|ALL + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function quantifier($quantifier) + { + if (! is_string($quantifier) && ! $quantifier instanceof ExpressionInterface) { + throw new Exception\InvalidArgumentException( + 'Quantifier must be one of DISTINCT, ALL, or some platform specific object implementing ' + . 'ExpressionInterface' + ); + } + $this->quantifier = $quantifier; + return $this; + } + + /** + * Specify columns from which to select + * + * Possible valid states: + * + * array(*) + * + * array(value, ...) + * value can be strings or Expression objects + * + * array(string => value, ...) + * key string will be use as alias, + * value can be string or Expression objects + * + * @param array $columns + * @param bool $prefixColumnsWithTable + * @return self Provides a fluent interface + */ + public function columns(array $columns, $prefixColumnsWithTable = true) + { + $this->columns = $columns; + $this->prefixColumnsWithTable = (bool) $prefixColumnsWithTable; + return $this; + } + + /** + * Create join clause + * + * @param string|array|TableIdentifier $name + * @param string|Predicate\Expression $on + * @param string|array $columns + * @param string $type one of the JOIN_* constants + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function join($name, $on, $columns = self::SQL_STAR, $type = self::JOIN_INNER) + { + $this->joins->join($name, $on, $columns, $type); + + return $this; + } + + /** + * Create where clause + * + * @param Where|\Closure|string|array|Predicate\PredicateInterface $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Where) { + $this->where = $predicate; + } else { + $this->where->addPredicates($predicate, $combination); + } + return $this; + } + + /** + * @param mixed $group + * @return self Provides a fluent interface + */ + public function group($group) + { + if (is_array($group)) { + foreach ($group as $o) { + $this->group[] = $o; + } + } else { + $this->group[] = $group; + } + return $this; + } + + /** + * Create having clause + * + * @param Where|\Closure|string|array $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @return self Provides a fluent interface + */ + public function having($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Having) { + $this->having = $predicate; + } else { + $this->having->addPredicates($predicate, $combination); + } + return $this; + } + + /** + * @param string|array|Expression $order + * @return self Provides a fluent interface + */ + public function order($order) + { + if (is_string($order)) { + if (strpos($order, ',') !== false) { + $order = preg_split('#,\s+#', $order); + } else { + $order = (array) $order; + } + } elseif (! is_array($order)) { + $order = [$order]; + } + foreach ($order as $k => $v) { + if (is_string($k)) { + $this->order[$k] = $v; + } else { + $this->order[] = $v; + } + } + return $this; + } + + /** + * @param int $limit + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function limit($limit) + { + if (! is_numeric($limit)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects parameter to be numeric, "%s" given', + __METHOD__, + (is_object($limit) ? get_class($limit) : gettype($limit)) + )); + } + + $this->limit = $limit; + return $this; + } + + /** + * @param int $offset + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function offset($offset) + { + if (! is_numeric($offset)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects parameter to be numeric, "%s" given', + __METHOD__, + (is_object($offset) ? get_class($offset) : gettype($offset)) + )); + } + + $this->offset = $offset; + return $this; + } + + /** + * @param Select $select + * @param string $type + * @param string $modifier + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function combine(Select $select, $type = self::COMBINE_UNION, $modifier = '') + { + if ($this->combine !== []) { + throw new Exception\InvalidArgumentException( + 'This Select object is already combined and cannot be combined with multiple Selects objects' + ); + } + $this->combine = [ + 'select' => $select, + 'type' => $type, + 'modifier' => $modifier + ]; + return $this; + } + + /** + * @param string $part + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function reset($part) + { + switch ($part) { + case self::TABLE: + if ($this->tableReadOnly) { + throw new Exception\InvalidArgumentException( + 'Since this object was created with a table and/or schema in the constructor, it is read only.' + ); + } + $this->table = null; + break; + case self::QUANTIFIER: + $this->quantifier = null; + break; + case self::COLUMNS: + $this->columns = []; + break; + case self::JOINS: + $this->joins = new Join; + break; + case self::WHERE: + $this->where = new Where; + break; + case self::GROUP: + $this->group = null; + break; + case self::HAVING: + $this->having = new Having; + break; + case self::LIMIT: + $this->limit = null; + break; + case self::OFFSET: + $this->offset = null; + break; + case self::ORDER: + $this->order = []; + break; + case self::COMBINE: + $this->combine = []; + break; + } + return $this; + } + + /** + * @param $index + * @param $specification + * @return self Provides a fluent interface + */ + public function setSpecification($index, $specification) + { + if (! method_exists($this, 'process' . $index)) { + throw new Exception\InvalidArgumentException('Not a valid specification name.'); + } + $this->specifications[$index] = $specification; + return $this; + } + + public function getRawState($key = null) + { + $rawState = [ + self::TABLE => $this->table, + self::QUANTIFIER => $this->quantifier, + self::COLUMNS => $this->columns, + self::JOINS => $this->joins, + self::WHERE => $this->where, + self::ORDER => $this->order, + self::GROUP => $this->group, + self::HAVING => $this->having, + self::LIMIT => $this->limit, + self::OFFSET => $this->offset, + self::COMBINE => $this->combine + ]; + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * Returns whether the table is read only or not. + * + * @return bool + */ + public function isTableReadOnly() + { + return $this->tableReadOnly; + } + + protected function processStatementStart( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->combine !== []) { + return ['(']; + } + } + + protected function processStatementEnd( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->combine !== []) { + return [')']; + } + } + + /** + * Process the select part + * + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @return null|array + */ + protected function processSelect( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + $expr = 1; + + list($table, $fromTable) = $this->resolveTable($this->table, $platform, $driver, $parameterContainer); + // process table columns + $columns = []; + foreach ($this->columns as $columnIndexOrAs => $column) { + if ($column === self::SQL_STAR) { + $columns[] = [$fromTable . self::SQL_STAR]; + continue; + } + + $columnName = $this->resolveColumnValue( + [ + 'column' => $column, + 'fromTable' => $fromTable, + 'isIdentifier' => true, + ], + $platform, + $driver, + $parameterContainer, + (is_string($columnIndexOrAs) ? $columnIndexOrAs : 'column') + ); + // process As portion + if (is_string($columnIndexOrAs)) { + $columnAs = $platform->quoteIdentifier($columnIndexOrAs); + } elseif (stripos($columnName, ' as ') === false) { + $columnAs = (is_string($column)) ? $platform->quoteIdentifier($column) : 'Expression' . $expr++; + } + $columns[] = (isset($columnAs)) ? [$columnName, $columnAs] : [$columnName]; + } + + // process join columns + foreach ($this->joins->getJoins() as $join) { + $joinName = (is_array($join['name'])) ? key($join['name']) : $join['name']; + $joinName = parent::resolveTable($joinName, $platform, $driver, $parameterContainer); + + foreach ($join['columns'] as $jKey => $jColumn) { + $jColumns = []; + $jFromTable = is_scalar($jColumn) + ? $joinName . $platform->getIdentifierSeparator() + : ''; + $jColumns[] = $this->resolveColumnValue( + [ + 'column' => $jColumn, + 'fromTable' => $jFromTable, + 'isIdentifier' => true, + ], + $platform, + $driver, + $parameterContainer, + (is_string($jKey) ? $jKey : 'column') + ); + if (is_string($jKey)) { + $jColumns[] = $platform->quoteIdentifier($jKey); + } elseif ($jColumn !== self::SQL_STAR) { + $jColumns[] = $platform->quoteIdentifier($jColumn); + } + $columns[] = $jColumns; + } + } + + if ($this->quantifier) { + $quantifier = ($this->quantifier instanceof ExpressionInterface) + ? $this->processExpression($this->quantifier, $platform, $driver, $parameterContainer, 'quantifier') + : $this->quantifier; + } + + if (! isset($table)) { + return [$columns]; + } elseif (isset($quantifier)) { + return [$quantifier, $columns, $table]; + } else { + return [$columns, $table]; + } + } + + protected function processJoins( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return $this->processJoin($this->joins, $platform, $driver, $parameterContainer); + } + + protected function processWhere( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->where->count() == 0) { + return; + } + return [ + $this->processExpression($this->where, $platform, $driver, $parameterContainer, 'where') + ]; + } + + protected function processGroup( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->group === null) { + return; + } + // process table columns + $groups = []; + foreach ($this->group as $column) { + $groups[] = $this->resolveColumnValue( + [ + 'column' => $column, + 'isIdentifier' => true, + ], + $platform, + $driver, + $parameterContainer, + 'group' + ); + } + return [$groups]; + } + + protected function processHaving( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->having->count() == 0) { + return; + } + return [ + $this->processExpression($this->having, $platform, $driver, $parameterContainer, 'having') + ]; + } + + protected function processOrder( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if (empty($this->order)) { + return; + } + $orders = []; + foreach ($this->order as $k => $v) { + if ($v instanceof ExpressionInterface) { + $orders[] = [ + $this->processExpression($v, $platform, $driver, $parameterContainer) + ]; + continue; + } + if (is_int($k)) { + if (strpos($v, ' ') !== false) { + list($k, $v) = preg_split('# #', $v, 2); + } else { + $k = $v; + $v = self::ORDER_ASCENDING; + } + } + if (strcasecmp(trim($v), self::ORDER_DESCENDING) === 0) { + $orders[] = [$platform->quoteIdentifierInFragment($k), self::ORDER_DESCENDING]; + } else { + $orders[] = [$platform->quoteIdentifierInFragment($k), self::ORDER_ASCENDING]; + } + } + return [$orders]; + } + + protected function processLimit( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->limit === null) { + return; + } + if ($parameterContainer) { + $paramPrefix = $this->processInfo['paramPrefix']; + $parameterContainer->offsetSet($paramPrefix . 'limit', $this->limit, ParameterContainer::TYPE_INTEGER); + return [$driver->formatParameterName($paramPrefix . 'limit')]; + } + return [$platform->quoteValue($this->limit)]; + } + + protected function processOffset( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->offset === null) { + return; + } + if ($parameterContainer) { + $paramPrefix = $this->processInfo['paramPrefix']; + $parameterContainer->offsetSet($paramPrefix . 'offset', $this->offset, ParameterContainer::TYPE_INTEGER); + return [$driver->formatParameterName($paramPrefix . 'offset')]; + } + + return [$platform->quoteValue($this->offset)]; + } + + protected function processCombine( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->combine == []) { + return; + } + + $type = $this->combine['type']; + if ($this->combine['modifier']) { + $type .= ' ' . $this->combine['modifier']; + } + + return [ + strtoupper($type), + $this->processSubSelect($this->combine['select'], $platform, $driver, $parameterContainer), + ]; + } + + /** + * Variable overloading + * + * @param string $name + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function __get($name) + { + switch (strtolower($name)) { + case 'where': + return $this->where; + case 'having': + return $this->having; + case 'joins': + return $this->joins; + default: + throw new Exception\InvalidArgumentException('Not a valid magic property for this object'); + } + } + + /** + * __clone + * + * Resets the where object each time the Select is cloned. + * + * @return void + */ + public function __clone() + { + $this->where = clone $this->where; + $this->joins = clone $this->joins; + $this->having = clone $this->having; + } + + /** + * @param string|TableIdentifier|Select $table + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @return string + */ + protected function resolveTable( + $table, + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + $alias = null; + + if (is_array($table)) { + $alias = key($table); + $table = current($table); + } + + $table = parent::resolveTable($table, $platform, $driver, $parameterContainer); + + if ($alias) { + $fromTable = $platform->quoteIdentifier($alias); + $table = $this->renderTable($table, $fromTable); + } else { + $fromTable = $table; + } + + if ($this->prefixColumnsWithTable && $fromTable) { + $fromTable .= $platform->getIdentifierSeparator(); + } else { + $fromTable = ''; + } + + return [ + $table, + $fromTable + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Sql.php b/bundled-libs/zendframework/zend-db/src/Sql/Sql.php similarity index 61% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Sql.php rename to bundled-libs/zendframework/zend-db/src/Sql/Sql.php index 940ba464..2cc14282 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Sql.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Sql.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -24,13 +24,18 @@ class Sql /** @var Platform\Platform */ protected $sqlPlatform = null; + /** + * @param AdapterInterface $adapter + * @param null|string|array|TableIdentifier $table + * @param null|Platform\AbstractPlatform $sqlPlatform @deprecated since version 3.0 + */ public function __construct(AdapterInterface $adapter, $table = null, Platform\AbstractPlatform $sqlPlatform = null) { $this->adapter = $adapter; if ($table) { $this->setTable($table); } - $this->sqlPlatform = ($sqlPlatform) ?: new Platform\Platform($adapter); + $this->sqlPlatform = $sqlPlatform ?: new Platform\Platform($adapter); } /** @@ -43,15 +48,22 @@ class Sql public function hasTable() { - return ($this->table != null); + return ($this->table !== null); } + /** + * @param string|array|TableIdentifier $table + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ public function setTable($table) { if (is_string($table) || is_array($table) || $table instanceof TableIdentifier) { $this->table = $table; } else { - throw new Exception\InvalidArgumentException('Table must be a string, array or instance of TableIdentifier.'); + throw new Exception\InvalidArgumentException( + 'Table must be a string, array or instance of TableIdentifier.' + ); } return $this; } @@ -112,34 +124,51 @@ class Sql /** * @param PreparableSqlInterface $sqlObject - * @param StatementInterface|null $statement + * @param StatementInterface $statement + * @param AdapterInterface $adapter + * * @return StatementInterface */ - public function prepareStatementForSqlObject(PreparableSqlInterface $sqlObject, StatementInterface $statement = null) - { - $statement = ($statement) ?: $this->adapter->getDriver()->createStatement(); + public function prepareStatementForSqlObject( + PreparableSqlInterface $sqlObject, + StatementInterface $statement = null, + AdapterInterface $adapter = null + ) { + $adapter = $adapter ?: $this->adapter; + $statement = $statement ?: $adapter->getDriver()->createStatement(); - if ($this->sqlPlatform) { - $this->sqlPlatform->setSubject($sqlObject); - $this->sqlPlatform->prepareStatement($this->adapter, $statement); - } else { - $sqlObject->prepareStatement($this->adapter, $statement); - } - - return $statement; + return $this->sqlPlatform->setSubject($sqlObject)->prepareStatement($adapter, $statement); } + /** + * Get sql string using platform or sql object + * + * @param SqlInterface $sqlObject + * @param PlatformInterface|null $platform + * + * @return string + * + * @deprecated Deprecated in 2.4. Use buildSqlString() instead + */ public function getSqlStringForSqlObject(SqlInterface $sqlObject, PlatformInterface $platform = null) { $platform = ($platform) ?: $this->adapter->getPlatform(); + return $this->sqlPlatform->setSubject($sqlObject)->getSqlString($platform); + } - if ($this->sqlPlatform) { - $this->sqlPlatform->setSubject($sqlObject); - $sqlString = $this->sqlPlatform->getSqlString($platform); - } else { - $sqlString = $sqlObject->getSqlString($platform); - } - - return $sqlString; + /** + * @param SqlInterface $sqlObject + * @param AdapterInterface $adapter + * + * @return string + * + * @throws Exception\InvalidArgumentException + */ + public function buildSqlString(SqlInterface $sqlObject, AdapterInterface $adapter = null) + { + return $this + ->sqlPlatform + ->setSubject($sqlObject) + ->getSqlString($adapter ? $adapter->getPlatform() : $this->adapter->getPlatform()); } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/SqlInterface.php b/bundled-libs/zendframework/zend-db/src/Sql/SqlInterface.php similarity index 67% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/SqlInterface.php rename to bundled-libs/zendframework/zend-db/src/Sql/SqlInterface.php index 90268025..551a458c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/SqlInterface.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/SqlInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,5 +13,12 @@ use Zend\Db\Adapter\Platform\PlatformInterface; interface SqlInterface { + /** + * Get SQL string for statement + * + * @param null|PlatformInterface $adapterPlatform + * + * @return string + */ public function getSqlString(PlatformInterface $adapterPlatform = null); } diff --git a/bundled-libs/zendframework/zend-db/src/Sql/TableIdentifier.php b/bundled-libs/zendframework/zend-db/src/Sql/TableIdentifier.php new file mode 100644 index 00000000..85cb10e7 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/TableIdentifier.php @@ -0,0 +1,113 @@ +table = (string) $table; + + if ('' === $this->table) { + throw new Exception\InvalidArgumentException('$table must be a valid table name, empty string given'); + } + + if (null === $schema) { + $this->schema = null; + } else { + if (! (is_string($schema) || is_callable([$schema, '__toString']))) { + throw new Exception\InvalidArgumentException(sprintf( + '$schema must be a valid schema name, parameter of type %s given', + is_object($schema) ? get_class($schema) : gettype($schema) + )); + } + + $this->schema = (string) $schema; + + if ('' === $this->schema) { + throw new Exception\InvalidArgumentException( + '$schema must be a valid schema name or null, empty string given' + ); + } + } + } + + /** + * @param string $table + * + * @deprecated please use the constructor and build a new {@see TableIdentifier} instead + */ + public function setTable($table) + { + $this->table = $table; + } + + /** + * @return string + */ + public function getTable() + { + return $this->table; + } + + /** + * @return bool + */ + public function hasSchema() + { + return ($this->schema !== null); + } + + /** + * @param $schema + * + * @deprecated please use the constructor and build a new {@see TableIdentifier} instead + */ + public function setSchema($schema) + { + $this->schema = $schema; + } + + /** + * @return null|string + */ + public function getSchema() + { + return $this->schema; + } + + public function getTableAndSchema() + { + return [$this->table, $this->schema]; + } +} diff --git a/bundled-libs/zendframework/zend-db/src/Sql/Update.php b/bundled-libs/zendframework/zend-db/src/Sql/Update.php new file mode 100644 index 00000000..09563cf5 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/Sql/Update.php @@ -0,0 +1,277 @@ + 'UPDATE %1$s', + self::SPECIFICATION_JOIN => [ + '%1$s' => [ + [3 => '%1$s JOIN %2$s ON %3$s', 'combinedby' => ' '] + ] + ], + self::SPECIFICATION_SET => 'SET %1$s', + self::SPECIFICATION_WHERE => 'WHERE %1$s', + ]; + + /** + * @var string|TableIdentifier + */ + protected $table = ''; + + /** + * @var bool + */ + protected $emptyWhereProtection = true; + + /** + * @var PriorityList + */ + protected $set; + + /** + * @var string|Where + */ + protected $where = null; + + /** + * @var null|Join + */ + protected $joins = null; + + /** + * Constructor + * + * @param null|string|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->table($table); + } + $this->where = new Where(); + $this->joins = new Join(); + $this->set = new PriorityList(); + $this->set->isLIFO(false); + } + + /** + * Specify table for statement + * + * @param string|TableIdentifier $table + * @return self Provides a fluent interface + */ + public function table($table) + { + $this->table = $table; + return $this; + } + + /** + * Set key/value pairs to update + * + * @param array $values Associative array of key values + * @param string $flag One of the VALUES_* constants + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function set(array $values, $flag = self::VALUES_SET) + { + if ($values === null) { + throw new Exception\InvalidArgumentException('set() expects an array of values'); + } + + if ($flag == self::VALUES_SET) { + $this->set->clear(); + } + $priority = is_numeric($flag) ? $flag : 0; + foreach ($values as $k => $v) { + if (! is_string($k)) { + throw new Exception\InvalidArgumentException('set() expects a string for the value key'); + } + $this->set->insert($k, $v, $priority); + } + return $this; + } + + /** + * Create where clause + * + * @param Where|\Closure|string|array $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Where) { + $this->where = $predicate; + } else { + $this->where->addPredicates($predicate, $combination); + } + return $this; + } + + /** + * Create join clause + * + * @param string|array $name + * @param string $on + * @param string $type one of the JOIN_* constants + * @return self Provides a fluent interface + * @throws Exception\InvalidArgumentException + */ + public function join($name, $on, $type = Join::JOIN_INNER) + { + $this->joins->join($name, $on, [], $type); + + return $this; + } + + public function getRawState($key = null) + { + $rawState = [ + 'emptyWhereProtection' => $this->emptyWhereProtection, + 'table' => $this->table, + 'set' => $this->set->toArray(), + 'where' => $this->where, + 'joins' => $this->joins + ]; + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + protected function processUpdate( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return sprintf( + $this->specifications[static::SPECIFICATION_UPDATE], + $this->resolveTable($this->table, $platform, $driver, $parameterContainer) + ); + } + + protected function processSet( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + $setSql = []; + $i = 0; + foreach ($this->set as $column => $value) { + $prefix = $this->resolveColumnValue( + [ + 'column' => $column, + 'fromTable' => '', + 'isIdentifier' => true, + ], + $platform, + $driver, + $parameterContainer, + 'column' + ); + $prefix .= ' = '; + if (is_scalar($value) && $parameterContainer) { + // use incremental value instead of column name for PDO + // @see https://github.com/zendframework/zend-db/issues/35 + if ($driver instanceof Pdo) { + $column = 'c_' . $i++; + } + $setSql[] = $prefix . $driver->formatParameterName($column); + $parameterContainer->offsetSet($column, $value); + } else { + $setSql[] = $prefix . $this->resolveColumnValue( + $value, + $platform, + $driver, + $parameterContainer + ); + } + } + + return sprintf( + $this->specifications[static::SPECIFICATION_SET], + implode(', ', $setSql) + ); + } + + protected function processWhere( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + if ($this->where->count() == 0) { + return; + } + return sprintf( + $this->specifications[static::SPECIFICATION_WHERE], + $this->processExpression($this->where, $platform, $driver, $parameterContainer, 'where') + ); + } + + protected function processJoins( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return $this->processJoin($this->joins, $platform, $driver, $parameterContainer); + } + + /** + * Variable overloading + * + * Proxies to "where" only + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + if (strtolower($name) == 'where') { + return $this->where; + } + } + + /** + * __clone + * + * Resets the where object each time the Update is cloned. + * + * @return void + */ + public function __clone() + { + $this->where = clone $this->where; + $this->set = clone $this->set; + } +} diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Where.php b/bundled-libs/zendframework/zend-db/src/Sql/Where.php similarity index 82% rename from bundled-libs/zendframework/zend-db/Zend/Db/Sql/Where.php rename to bundled-libs/zendframework/zend-db/src/Sql/Where.php index 8e9705b6..68166d52 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/Sql/Where.php +++ b/bundled-libs/zendframework/zend-db/src/Sql/Where.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -11,5 +11,4 @@ namespace Zend\Db\Sql; class Where extends Predicate\Predicate { - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/AbstractTableGateway.php b/bundled-libs/zendframework/zend-db/src/TableGateway/AbstractTableGateway.php similarity index 66% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/AbstractTableGateway.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/AbstractTableGateway.php index 26ed20ce..b97a0dc2 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/AbstractTableGateway.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/AbstractTableGateway.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,11 +14,13 @@ use Zend\Db\ResultSet\ResultSet; use Zend\Db\ResultSet\ResultSetInterface; use Zend\Db\Sql\Delete; use Zend\Db\Sql\Insert; +use Zend\Db\Sql\Join; use Zend\Db\Sql\Select; use Zend\Db\Sql\Sql; use Zend\Db\Sql\TableIdentifier; use Zend\Db\Sql\Update; use Zend\Db\Sql\Where; +use Zend\Db\TableGateway\Feature\EventFeatureEventsInterface; /** * @@ -28,7 +30,6 @@ use Zend\Db\Sql\Where; */ abstract class AbstractTableGateway implements TableGatewayInterface { - /** * @var bool */ @@ -40,14 +41,14 @@ abstract class AbstractTableGateway implements TableGatewayInterface protected $adapter = null; /** - * @var string + * @var string|array|TableIdentifier */ protected $table = null; /** * @var array */ - protected $columns = array(); + protected $columns = []; /** * @var Feature\FeatureSet @@ -90,30 +91,30 @@ abstract class AbstractTableGateway implements TableGatewayInterface return; } - if (!$this->featureSet instanceof Feature\FeatureSet) { + if (! $this->featureSet instanceof Feature\FeatureSet) { $this->featureSet = new Feature\FeatureSet; } $this->featureSet->setTableGateway($this); - $this->featureSet->apply('preInitialize', array()); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_INITIALIZE, []); - if (!$this->adapter instanceof AdapterInterface) { + if (! $this->adapter instanceof AdapterInterface) { throw new Exception\RuntimeException('This table does not have an Adapter setup'); } - if (!is_string($this->table) && !$this->table instanceof TableIdentifier) { + if (! is_string($this->table) && ! $this->table instanceof TableIdentifier && ! is_array($this->table)) { throw new Exception\RuntimeException('This table object does not have a valid table set.'); } - if (!$this->resultSetPrototype instanceof ResultSetInterface) { + if (! $this->resultSetPrototype instanceof ResultSetInterface) { $this->resultSetPrototype = new ResultSet; } - if (!$this->sql instanceof Sql) { + if (! $this->sql instanceof Sql) { $this->sql = new Sql($this->adapter, $this->table); } - $this->featureSet->apply('postInitialize', array()); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_INITIALIZE, []); $this->isInitialized = true; } @@ -157,7 +158,7 @@ abstract class AbstractTableGateway implements TableGatewayInterface /** * Get select result prototype * - * @return ResultSet + * @return ResultSetInterface */ public function getResultSetPrototype() { @@ -176,11 +177,11 @@ abstract class AbstractTableGateway implements TableGatewayInterface * Select * * @param Where|\Closure|string|array $where - * @return ResultSet + * @return ResultSetInterface */ public function select($where = null) { - if (!$this->isInitialized) { + if (! $this->isInitialized) { $this->initialize(); } @@ -197,12 +198,11 @@ abstract class AbstractTableGateway implements TableGatewayInterface /** * @param Select $select - * @return null|ResultSetInterface - * @throws \RuntimeException + * @return ResultSetInterface */ public function selectWith(Select $select) { - if (!$this->isInitialized) { + if (! $this->isInitialized) { $this->initialize(); } return $this->executeSelect($select); @@ -210,23 +210,28 @@ abstract class AbstractTableGateway implements TableGatewayInterface /** * @param Select $select - * @return ResultSet - * @throws \RuntimeException + * @return ResultSetInterface + * @throws Exception\RuntimeException */ protected function executeSelect(Select $select) { $selectState = $select->getRawState(); - if ($selectState['table'] != $this->table) { - throw new \RuntimeException('The table name of the provided select object must match that of the table'); + if ($selectState['table'] != $this->table + && (is_array($selectState['table']) + && end($selectState['table']) != $this->table) + ) { + throw new Exception\RuntimeException( + 'The table name of the provided Select object must match that of the table' + ); } - if ($selectState['columns'] == array(Select::SQL_STAR) - && $this->columns !== array()) { + if ($selectState['columns'] == [Select::SQL_STAR] + && $this->columns !== []) { $select->columns($this->columns); } // apply preSelect features - $this->featureSet->apply('preSelect', array($select)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_SELECT, [$select]); // prepare and execute $statement = $this->sql->prepareStatementForSqlObject($select); @@ -237,7 +242,7 @@ abstract class AbstractTableGateway implements TableGatewayInterface $resultSet->initialize($result); // apply postSelect features - $this->featureSet->apply('postSelect', array($statement, $result, $resultSet)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_SELECT, [$statement, $result, $resultSet]); return $resultSet; } @@ -250,7 +255,7 @@ abstract class AbstractTableGateway implements TableGatewayInterface */ public function insert($set) { - if (!$this->isInitialized) { + if (! $this->isInitialized) { $this->initialize(); } $insert = $this->sql->insert(); @@ -260,11 +265,11 @@ abstract class AbstractTableGateway implements TableGatewayInterface /** * @param Insert $insert - * @return mixed + * @return int */ public function insertWith(Insert $insert) { - if (!$this->isInitialized) { + if (! $this->isInitialized) { $this->initialize(); } return $this->executeInsert($insert); @@ -274,25 +279,41 @@ abstract class AbstractTableGateway implements TableGatewayInterface * @todo add $columns support * * @param Insert $insert - * @return mixed + * @return int * @throws Exception\RuntimeException */ protected function executeInsert(Insert $insert) { $insertState = $insert->getRawState(); if ($insertState['table'] != $this->table) { - throw new Exception\RuntimeException('The table name of the provided Insert object must match that of the table'); + throw new Exception\RuntimeException( + 'The table name of the provided Insert object must match that of the table' + ); } // apply preInsert features - $this->featureSet->apply('preInsert', array($insert)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_INSERT, [$insert]); + + // Most RDBMS solutions do not allow using table aliases in INSERTs + // See https://github.com/zendframework/zf2/issues/7311 + $unaliasedTable = false; + if (is_array($insertState['table'])) { + $tableData = array_values($insertState['table']); + $unaliasedTable = array_shift($tableData); + $insert->into($unaliasedTable); + } $statement = $this->sql->prepareStatementForSqlObject($insert); $result = $statement->execute(); $this->lastInsertValue = $this->adapter->getDriver()->getConnection()->getLastGeneratedValue(); // apply postInsert features - $this->featureSet->apply('postInsert', array($statement, $result)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_INSERT, [$statement, $result]); + + // Reset original table information in Insert instance, if necessary + if ($unaliasedTable) { + $insert->into($insertState['table']); + } return $result->getAffectedRows(); } @@ -301,12 +322,13 @@ abstract class AbstractTableGateway implements TableGatewayInterface * Update * * @param array $set - * @param string|array|closure $where + * @param string|array|\Closure $where + * @param null|array $joins * @return int */ - public function update($set, $where = null) + public function update($set, $where = null, array $joins = null) { - if (!$this->isInitialized) { + if (! $this->isInitialized) { $this->initialize(); } $sql = $this->sql; @@ -315,16 +337,24 @@ abstract class AbstractTableGateway implements TableGatewayInterface if ($where !== null) { $update->where($where); } + + if ($joins) { + foreach ($joins as $join) { + $type = isset($join['type']) ? $join['type'] : Join::JOIN_INNER; + $update->join($join['name'], $join['on'], $type); + } + } + return $this->executeUpdate($update); } /** * @param \Zend\Db\Sql\Update $update - * @return mixed + * @return int */ public function updateWith(Update $update) { - if (!$this->isInitialized) { + if (! $this->isInitialized) { $this->initialize(); } return $this->executeUpdate($update); @@ -334,24 +364,38 @@ abstract class AbstractTableGateway implements TableGatewayInterface * @todo add $columns support * * @param Update $update - * @return mixed + * @return int * @throws Exception\RuntimeException */ protected function executeUpdate(Update $update) { $updateState = $update->getRawState(); if ($updateState['table'] != $this->table) { - throw new Exception\RuntimeException('The table name of the provided Update object must match that of the table'); + throw new Exception\RuntimeException( + 'The table name of the provided Update object must match that of the table' + ); } // apply preUpdate features - $this->featureSet->apply('preUpdate', array($update)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_UPDATE, [$update]); + + $unaliasedTable = false; + if (is_array($updateState['table'])) { + $tableData = array_values($updateState['table']); + $unaliasedTable = array_shift($tableData); + $update->table($unaliasedTable); + } $statement = $this->sql->prepareStatementForSqlObject($update); $result = $statement->execute(); // apply postUpdate features - $this->featureSet->apply('postUpdate', array($statement, $result)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_UPDATE, [$statement, $result]); + + // Reset original table information in Update instance, if necessary + if ($unaliasedTable) { + $update->table($updateState['table']); + } return $result->getAffectedRows(); } @@ -364,7 +408,7 @@ abstract class AbstractTableGateway implements TableGatewayInterface */ public function delete($where) { - if (!$this->isInitialized) { + if (! $this->isInitialized) { $this->initialize(); } $delete = $this->sql->delete(); @@ -378,7 +422,7 @@ abstract class AbstractTableGateway implements TableGatewayInterface /** * @param Delete $delete - * @return mixed + * @return int */ public function deleteWith(Delete $delete) { @@ -390,24 +434,26 @@ abstract class AbstractTableGateway implements TableGatewayInterface * @todo add $columns support * * @param Delete $delete - * @return mixed + * @return int * @throws Exception\RuntimeException */ protected function executeDelete(Delete $delete) { $deleteState = $delete->getRawState(); if ($deleteState['table'] != $this->table) { - throw new Exception\RuntimeException('The table name of the provided Update object must match that of the table'); + throw new Exception\RuntimeException( + 'The table name of the provided Delete object must match that of the table' + ); } // pre delete update - $this->featureSet->apply('preDelete', array($delete)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_DELETE, [$delete]); $statement = $this->sql->prepareStatementForSqlObject($delete); $result = $statement->execute(); // apply postDelete features - $this->featureSet->apply('postDelete', array($statement, $result)); + $this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_DELETE, [$statement, $result]); return $result->getAffectedRows(); } @@ -470,7 +516,11 @@ abstract class AbstractTableGateway implements TableGatewayInterface if ($this->featureSet->canCallMagicCall($method)) { return $this->featureSet->callMagicCall($method, $arguments); } - throw new Exception\InvalidArgumentException('Invalid method (' . $method . ') called, caught by ' . __CLASS__ . '::__call()'); + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid method (%s) called, caught by %s::__call()', + $method, + __CLASS__ + )); } /** @@ -482,7 +532,13 @@ abstract class AbstractTableGateway implements TableGatewayInterface $this->sql = clone $this->sql; if (is_object($this->table)) { $this->table = clone $this->table; + } elseif (is_array($this->table) + && count($this->table) == 1 + && is_object(reset($this->table)) + ) { + foreach ($this->table as $alias => &$tableObject) { + $tableObject = clone $tableObject; + } } } - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/ExceptionInterface.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Exception/ExceptionInterface.php similarity index 85% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/ExceptionInterface.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Exception/ExceptionInterface.php index 240922db..7410e597 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/ExceptionInterface.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/InvalidArgumentException.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Exception/InvalidArgumentException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/InvalidArgumentException.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Exception/InvalidArgumentException.php index 11ae9223..fe299481 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/InvalidArgumentException.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/RuntimeException.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Exception/RuntimeException.php similarity index 86% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/RuntimeException.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Exception/RuntimeException.php index 56d3a96f..b9b4470e 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Exception/RuntimeException.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Exception/RuntimeException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/AbstractFeature.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/AbstractFeature.php similarity index 92% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/AbstractFeature.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/AbstractFeature.php index 4d9503e5..e73779be 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/AbstractFeature.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/AbstractFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,13 +14,12 @@ use Zend\Db\TableGateway\Exception; abstract class AbstractFeature extends AbstractTableGateway { - /** * @var AbstractTableGateway */ protected $tableGateway = null; - protected $sharedData = array(); + protected $sharedData = []; public function getName() { @@ -39,7 +38,7 @@ abstract class AbstractFeature extends AbstractTableGateway public function getMagicMethodSpecifications() { - return array(); + return []; } @@ -55,5 +54,4 @@ abstract class AbstractFeature extends AbstractTableGateway public function preDelete(Delete $delete); public function postDelete(StatementInterface $statement, ResultInterface $result); */ - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeature.php similarity index 74% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeature.php index b0699be6..ea3c70e4 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -20,7 +20,9 @@ use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\EventsCapableInterface; -class EventFeature extends AbstractFeature implements EventsCapableInterface +class EventFeature extends AbstractFeature implements + EventFeatureEventsInterface, + EventsCapableInterface { /** * @var EventManagerInterface @@ -44,9 +46,9 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface ? $eventManager : new EventManager; - $this->eventManager->addIdentifiers(array( + $this->eventManager->addIdentifiers([ 'Zend\Db\TableGateway\TableGateway', - )); + ]); $this->event = ($tableGatewayEvent) ?: new EventFeature\TableGatewayEvent(); } @@ -83,12 +85,12 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface public function preInitialize() { if (get_class($this->tableGateway) != 'Zend\Db\TableGateway\TableGateway') { - $this->eventManager->addIdentifiers(get_class($this->tableGateway)); + $this->eventManager->addIdentifiers([get_class($this->tableGateway)]); } $this->event->setTarget($this->tableGateway); - $this->event->setName(__FUNCTION__); - $this->eventManager->trigger($this->event); + $this->event->setName(static::EVENT_PRE_INITIALIZE); + $this->eventManager->triggerEvent($this->event); } /** @@ -98,8 +100,8 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function postInitialize() { - $this->event->setName(__FUNCTION__); - $this->eventManager->trigger($this->event); + $this->event->setName(static::EVENT_POST_INITIALIZE); + $this->eventManager->triggerEvent($this->event); } /** @@ -113,9 +115,9 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function preSelect(Select $select) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array('select' => $select)); - $this->eventManager->trigger($this->event); + $this->event->setName(static::EVENT_PRE_SELECT); + $this->event->setParams(['select' => $select]); + $this->eventManager->triggerEvent($this->event); } /** @@ -133,13 +135,13 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function postSelect(StatementInterface $statement, ResultInterface $result, ResultSetInterface $resultSet) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array( + $this->event->setName(static::EVENT_POST_SELECT); + $this->event->setParams([ 'statement' => $statement, 'result' => $result, 'result_set' => $resultSet - )); - $this->eventManager->trigger($this->event); + ]); + $this->eventManager->triggerEvent($this->event); } /** @@ -153,9 +155,9 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function preInsert(Insert $insert) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array('insert' => $insert)); - $this->eventManager->trigger($this->event); + $this->event->setName(static::EVENT_PRE_INSERT); + $this->event->setParams(['insert' => $insert]); + $this->eventManager->triggerEvent($this->event); } /** @@ -171,12 +173,12 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function postInsert(StatementInterface $statement, ResultInterface $result) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array( + $this->event->setName(static::EVENT_POST_INSERT); + $this->event->setParams([ 'statement' => $statement, 'result' => $result, - )); - $this->eventManager->trigger($this->event); + ]); + $this->eventManager->triggerEvent($this->event); } /** @@ -190,9 +192,9 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function preUpdate(Update $update) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array('update' => $update)); - $this->eventManager->trigger($this->event); + $this->event->setName(static::EVENT_PRE_UPDATE); + $this->event->setParams(['update' => $update]); + $this->eventManager->triggerEvent($this->event); } /** @@ -208,12 +210,12 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function postUpdate(StatementInterface $statement, ResultInterface $result) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array( + $this->event->setName(static::EVENT_POST_UPDATE); + $this->event->setParams([ 'statement' => $statement, 'result' => $result, - )); - $this->eventManager->trigger($this->event); + ]); + $this->eventManager->triggerEvent($this->event); } /** @@ -227,9 +229,9 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function preDelete(Delete $delete) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array('delete' => $delete)); - $this->eventManager->trigger($this->event); + $this->event->setName(static::EVENT_PRE_DELETE); + $this->event->setParams(['delete' => $delete]); + $this->eventManager->triggerEvent($this->event); } /** @@ -245,11 +247,11 @@ class EventFeature extends AbstractFeature implements EventsCapableInterface */ public function postDelete(StatementInterface $statement, ResultInterface $result) { - $this->event->setName(__FUNCTION__); - $this->event->setParams(array( + $this->event->setName(static::EVENT_POST_DELETE); + $this->event->setParams([ 'statement' => $statement, 'result' => $result, - )); - $this->eventManager->trigger($this->event); + ]); + $this->eventManager->triggerEvent($this->event); } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature/TableGatewayEvent.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeature/TableGatewayEvent.php similarity index 96% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature/TableGatewayEvent.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeature/TableGatewayEvent.php index af7531ee..f014faa4 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature/TableGatewayEvent.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeature/TableGatewayEvent.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ use Zend\EventManager\EventInterface; class TableGatewayEvent implements EventInterface { - /** * @var AbstractTableGateway */ @@ -28,7 +27,7 @@ class TableGatewayEvent implements EventInterface /** * @var array|\ArrayAccess */ - protected $params = array(); + protected $params = []; /** * Get event name diff --git a/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeatureEventsInterface.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeatureEventsInterface.php new file mode 100644 index 00000000..291ebcd0 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/EventFeatureEventsInterface.php @@ -0,0 +1,36 @@ +addFeatures($features); } } + /** + * @param AbstractTableGateway $tableGateway + * @return self Provides a fluent interface + */ public function setTableGateway(AbstractTableGateway $tableGateway) { $this->tableGateway = $tableGateway; @@ -55,6 +60,10 @@ class FeatureSet return $feature; } + /** + * @param array $features + * @return self Provides a fluent interface + */ public function addFeatures(array $features) { foreach ($features as $feature) { @@ -63,10 +72,16 @@ class FeatureSet return $this; } + /** + * @param AbstractFeature $feature + * @return self Provides a fluent interface + */ public function addFeature(AbstractFeature $feature) { + if ($this->tableGateway instanceof TableGatewayInterface) { + $feature->setTableGateway($this->tableGateway); + } $this->features[] = $feature; - $feature->setTableGateway($feature); return $this; } @@ -74,7 +89,7 @@ class FeatureSet { foreach ($this->features as $feature) { if (method_exists($feature, $method)) { - $return = call_user_func_array(array($feature, $method), $args); + $return = call_user_func_array([$feature, $method], $args); if ($return === self::APPLY_HALT) { break; } @@ -122,22 +137,36 @@ class FeatureSet } /** + * Is the method requested available in one of the added features * @param string $method * @return bool */ public function canCallMagicCall($method) { + if (! empty($this->features)) { + foreach ($this->features as $feature) { + if (method_exists($feature, $method)) { + return true; + } + } + } return false; } /** + * Call method of on added feature as though it were a local method * @param string $method * @param array $arguments * @return mixed */ public function callMagicCall($method, $arguments) { - $return = null; - return $return; + foreach ($this->features as $feature) { + if (method_exists($feature, $method)) { + return $feature->$method($arguments); + } + } + + return; } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/GlobalAdapterFeature.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/GlobalAdapterFeature.php similarity index 93% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/GlobalAdapterFeature.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/GlobalAdapterFeature.php index 94b847f8..7eccdcb2 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/GlobalAdapterFeature.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/GlobalAdapterFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,11 +14,10 @@ use Zend\Db\TableGateway\Exception; class GlobalAdapterFeature extends AbstractFeature { - /** * @var Adapter[] */ - protected static $staticAdapters = array(); + protected static $staticAdapters = []; /** * Set static adapter @@ -65,6 +64,4 @@ class GlobalAdapterFeature extends AbstractFeature { $this->tableGateway->adapter = self::getStaticAdapter(); } - - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/MasterSlaveFeature.php similarity index 94% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/MasterSlaveFeature.php index 77902c53..07d36f95 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/MasterSlaveFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -14,7 +14,6 @@ use Zend\Db\Sql\Sql; class MasterSlaveFeature extends AbstractFeature { - /** * @var AdapterInterface */ @@ -63,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(), @@ -89,5 +88,4 @@ class MasterSlaveFeature extends AbstractFeature { $this->tableGateway->sql = $this->masterSql; } - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/MetadataFeature.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/MetadataFeature.php similarity index 76% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/MetadataFeature.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/MetadataFeature.php index 3bd74f20..9a78f60a 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/MetadataFeature.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/MetadataFeature.php @@ -3,20 +3,19 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\TableGateway\Feature; -use Zend\Db\Metadata\Metadata; use Zend\Db\Metadata\MetadataInterface; use Zend\Db\TableGateway\Exception; use Zend\Db\Metadata\Object\TableObject; +use Zend\Db\Metadata\Source\Factory as SourceFactory; class MetadataFeature extends AbstractFeature { - /** * @var MetadataInterface */ @@ -32,16 +31,16 @@ class MetadataFeature extends AbstractFeature if ($metadata) { $this->metadata = $metadata; } - $this->sharedData['metadata'] = array( + $this->sharedData['metadata'] = [ 'primaryKey' => null, - 'columns' => array() - ); + 'columns' => [] + ]; } public function postInitialize() { - if ($this->metadata == null) { - $this->metadata = new Metadata($this->tableGateway->adapter); + if ($this->metadata === null) { + $this->metadata = SourceFactory::createSourceFromAdapter($this->tableGateway->adapter); } // localize variable for brevity @@ -56,7 +55,7 @@ class MetadataFeature extends AbstractFeature $this->sharedData['metadata']['columns'] = $columns; // process primary key only if table is a table; there are no PK constraints on views - if (!($m->getTable($t->table) instanceof TableObject)) { + if (! ($m->getTable($t->table) instanceof TableObject)) { return; } @@ -74,15 +73,13 @@ class MetadataFeature extends AbstractFeature throw new Exception\RuntimeException('A primary key for this column could not be found in the metadata.'); } - if (count($pkc->getColumns()) == 1) { - $pkck = $pkc->getColumns(); - $primaryKey = $pkck[0]; + $pkcColumns = $pkc->getColumns(); + if (count($pkcColumns) === 1) { + $primaryKey = $pkcColumns[0]; } else { - $primaryKey = $pkc->getColumns(); + $primaryKey = $pkcColumns; } $this->sharedData['metadata']['primaryKey'] = $primaryKey; } - - } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/RowGatewayFeature.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/RowGatewayFeature.php similarity index 68% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/RowGatewayFeature.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/RowGatewayFeature.php index 13f92391..a1482922 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/RowGatewayFeature.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/RowGatewayFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -16,11 +16,10 @@ use Zend\Db\TableGateway\Exception; class RowGatewayFeature extends AbstractFeature { - /** * @var array */ - protected $constructorArguments = array(); + protected $constructorArguments = []; /** * @param null $primaryKey @@ -37,7 +36,7 @@ class RowGatewayFeature extends AbstractFeature /** @var $resultSetPrototype ResultSet */ $resultSetPrototype = $this->tableGateway->resultSetPrototype; - if (!$this->tableGateway->resultSetPrototype instanceof ResultSet) { + if (! $this->tableGateway->resultSetPrototype instanceof ResultSet) { throw new Exception\RuntimeException( 'This feature ' . __CLASS__ . ' expects the ResultSet to be an instance of Zend\Db\ResultSet\ResultSet' ); @@ -46,7 +45,11 @@ class RowGatewayFeature extends AbstractFeature if (isset($args[0])) { if (is_string($args[0])) { $primaryKey = $args[0]; - $rowGatewayPrototype = new RowGateway($primaryKey, $this->tableGateway->table, $this->tableGateway->adapter, $this->tableGateway->sql); + $rowGatewayPrototype = new RowGateway( + $primaryKey, + $this->tableGateway->table, + $this->tableGateway->adapter + ); $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype); } elseif ($args[0] instanceof RowGatewayInterface) { $rowGatewayPrototype = $args[0]; @@ -54,14 +57,21 @@ class RowGatewayFeature extends AbstractFeature } } else { // get from metadata feature - $metadata = $this->tableGateway->featureSet->getFeatureByClassName('Zend\Db\TableGateway\Feature\MetadataFeature'); - if ($metadata === false || !isset($metadata->sharedData['metadata'])) { + $metadata = $this->tableGateway->featureSet->getFeatureByClassName( + 'Zend\Db\TableGateway\Feature\MetadataFeature' + ); + if ($metadata === false || ! isset($metadata->sharedData['metadata'])) { throw new Exception\RuntimeException( - 'No information was provided to the RowGatewayFeature and/or no MetadataFeature could be consulted to find the primary key necessary for RowGateway object creation.' + 'No information was provided to the RowGatewayFeature and/or no MetadataFeature could be consulted ' + . 'to find the primary key necessary for RowGateway object creation.' ); } $primaryKey = $metadata->sharedData['metadata']['primaryKey']; - $rowGatewayPrototype = new RowGateway($primaryKey, $this->tableGateway->table, $this->tableGateway->adapter, $this->tableGateway->sql); + $rowGatewayPrototype = new RowGateway( + $primaryKey, + $this->tableGateway->table, + $this->tableGateway->adapter + ); $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype); } } diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/SequenceFeature.php b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/SequenceFeature.php similarity index 84% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/SequenceFeature.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/Feature/SequenceFeature.php index b5d8ab6c..014171c2 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/Feature/SequenceFeature.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/Feature/SequenceFeature.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -42,7 +42,8 @@ class SequenceFeature extends AbstractFeature } /** - * @param Insert $insert + * @param Insert $insert + * @return Insert */ public function preInsert(Insert $insert) { @@ -59,10 +60,14 @@ class SequenceFeature extends AbstractFeature return $insert; } - $insert->values(array($this->primaryKeyField => $this->sequenceValue), Insert::VALUES_MERGE); + $insert->values([$this->primaryKeyField => $this->sequenceValue], Insert::VALUES_MERGE); return $insert; } + /** + * @param StatementInterface $statement + * @param ResultInterface $result + */ public function postInsert(StatementInterface $statement, ResultInterface $result) { if ($this->sequenceValue !== null) { @@ -81,13 +86,13 @@ class SequenceFeature extends AbstractFeature switch ($platformName) { case 'Oracle': - $sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.NEXTVAL FROM dual'; + $sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.NEXTVAL as "nextval" FROM dual'; break; case 'PostgreSQL': - $sql = 'SELECT NEXTVAL(\'' . $this->sequenceName . '\')'; + $sql = 'SELECT NEXTVAL(\'"' . $this->sequenceName . '"\')'; break; - default : - return null; + default: + return; } $statement = $this->tableGateway->adapter->createStatement(); @@ -109,13 +114,13 @@ class SequenceFeature extends AbstractFeature switch ($platformName) { case 'Oracle': - $sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.CURRVAL FROM dual'; + $sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.CURRVAL as "currval" FROM dual'; break; case 'PostgreSQL': $sql = 'SELECT CURRVAL(\'' . $this->sequenceName . '\')'; break; - default : - return null; + default: + return; } $statement = $this->tableGateway->adapter->createStatement(); diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/TableGateway.php b/bundled-libs/zendframework/zend-db/src/TableGateway/TableGateway.php similarity index 58% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/TableGateway.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/TableGateway.php index 781646f2..3bfbf213 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/TableGateway.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/TableGateway.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -17,22 +17,29 @@ use Zend\Db\Sql\TableIdentifier; class TableGateway extends AbstractTableGateway { - /** * Constructor * - * @param string $table - * @param AdapterInterface $adapter - * @param Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[] $features - * @param ResultSetInterface $resultSetPrototype - * @param Sql $sql + * @param string|TableIdentifier|array $table + * @param AdapterInterface $adapter + * @param Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[]|null $features + * @param ResultSetInterface|null $resultSetPrototype + * @param Sql|null $sql + * * @throws Exception\InvalidArgumentException */ - public function __construct($table, AdapterInterface $adapter, $features = null, ResultSetInterface $resultSetPrototype = null, Sql $sql = null) - { + public function __construct( + $table, + AdapterInterface $adapter, + $features = null, + ResultSetInterface $resultSetPrototype = null, + Sql $sql = null + ) { // table - if (!(is_string($table) || $table instanceof TableIdentifier)) { - throw new Exception\InvalidArgumentException('Table name must be a string or an instance of Zend\Db\Sql\TableIdentifier'); + if (! (is_string($table) || $table instanceof TableIdentifier || is_array($table))) { + throw new Exception\InvalidArgumentException( + 'Table name must be a string or an instance of Zend\Db\Sql\TableIdentifier' + ); } $this->table = $table; @@ -42,7 +49,7 @@ class TableGateway extends AbstractTableGateway // process features if ($features !== null) { if ($features instanceof Feature\AbstractFeature) { - $features = array($features); + $features = [$features]; } if (is_array($features)) { $this->featureSet = new Feature\FeatureSet($features); @@ -50,7 +57,8 @@ class TableGateway extends AbstractTableGateway $this->featureSet = $features; } else { throw new Exception\InvalidArgumentException( - 'TableGateway expects $feature to be an instance of an AbstractFeature or a FeatureSet, or an array of AbstractFeatures' + 'TableGateway expects $feature to be an instance of an AbstractFeature or a FeatureSet, or an ' + . 'array of AbstractFeatures' ); } } else { @@ -65,7 +73,9 @@ class TableGateway extends AbstractTableGateway // check sql object bound to same table if ($this->sql->getTable() != $this->table) { - throw new Exception\InvalidArgumentException('The table inside the provided Sql object must match the table of this TableGateway'); + throw new Exception\InvalidArgumentException( + 'The table inside the provided Sql object must match the table of this TableGateway' + ); } $this->initialize(); diff --git a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/TableGatewayInterface.php b/bundled-libs/zendframework/zend-db/src/TableGateway/TableGatewayInterface.php similarity index 88% rename from bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/TableGatewayInterface.php rename to bundled-libs/zendframework/zend-db/src/TableGateway/TableGatewayInterface.php index a7f2b45c..58c7759c 100644 --- a/bundled-libs/zendframework/zend-db/Zend/Db/TableGateway/TableGatewayInterface.php +++ b/bundled-libs/zendframework/zend-db/src/TableGateway/TableGatewayInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/bundled-libs/zendframework/zend-db/test/autoload.php b/bundled-libs/zendframework/zend-db/test/autoload.php new file mode 100644 index 00000000..e4685188 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/autoload.php @@ -0,0 +1,26 @@ +variables); + $connection->connect(); + + self::assertTrue($connection->isConnected()); + $connection->disconnect(); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php new file mode 100644 index 00000000..d46b83bf --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TableGatewayTest.php @@ -0,0 +1,50 @@ + 'mysqli', + 'database' => $this->variables['database'], + 'hostname' => $this->variables['hostname'], + 'username' => $this->variables['username'], + 'password' => $this->variables['password'], + 'options' => ['buffer_results' => true] + ]); + $tableGateway = new TableGateway('test', $adapter); + $rowset = $tableGateway->select('id = 0'); + + $this->assertNull($rowset->current()); + } + + /** + * @see https://github.com/zendframework/zend-db/issues/330 + */ + public function testSelectWithEmptyCurrentWithoutBufferResult() + { + $adapter = new Adapter([ + 'driver' => 'mysqli', + 'database' => $this->variables['database'], + 'hostname' => $this->variables['hostname'], + 'username' => $this->variables['username'], + 'password' => $this->variables['password'], + 'options' => ['buffer_results' => false] + ]); + $tableGateway = new TableGateway('test', $adapter); + $rowset = $tableGateway->select('id = 0'); + + $this->assertNull($rowset->current()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TraitSetup.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TraitSetup.php new file mode 100644 index 00000000..a5ee41a5 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Mysqli/TraitSetup.php @@ -0,0 +1,43 @@ + 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME', + 'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME', + 'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD', + 'database' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE', + ]; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + if (! getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL')) { + $this->markTestSkipped('Mysqli integration test disabled'); + } + + if (! extension_loaded('mysqli')) { + $this->fail('The phpunit group integration-mysqli was enabled, but the extension is not loaded.'); + } + + foreach ($this->variables as $name => $value) { + if (! getenv($value)) { + $this->markTestSkipped(sprintf( + 'Missing required variable %s from phpunit.xml for this integration test', + $value + )); + } + $this->variables[$name] = getenv($value); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php new file mode 100644 index 00000000..e6a5c2a6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTest.php @@ -0,0 +1,20 @@ +assertInstanceOf(Adapter::class, $this->adapter); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php new file mode 100644 index 00000000..34f950b7 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/AdapterTrait.php @@ -0,0 +1,23 @@ +markTestSkipped('pdo_mysql integration tests are not enabled!'); + } + + $this->adapter = new Adapter([ + 'driver' => 'pdo_mysql', + 'database' => getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE'), + 'hostname' => getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME'), + 'username' => getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME'), + 'password' => getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD') + ]); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php new file mode 100644 index 00000000..5c7dae39 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/QueryTest.php @@ -0,0 +1,57 @@ + 1, 'name' => 'foo', 'value' => 'bar']], + ['SELECT * FROM test WHERE id = :id', [':id' => 1], ['id' => 1, 'name' => 'foo', 'value' => 'bar']], + ['SELECT * FROM test WHERE id = :id', ['id' => 1], ['id' => 1, 'name' => 'foo', 'value' => 'bar']] + ]; + } + + /** + * @dataProvider getQueriesWithRowResult + * @covers \Zend\Db\Adapter\Adapter::query + * @covers \Zend\Db\ResultSet\ResultSet::current + */ + public function testQuery($query, $params, $expected) + { + $result = $this->adapter->query($query, $params); + $this->assertInstanceOf(ResultSet::class, $result); + $current = $result->current(); + // test as array value + $this->assertEquals($expected, (array) $current); + // test as object value + foreach ($expected as $key => $value) { + $this->assertEquals($value, $current->$key); + } + } + + /** + * @see https://github.com/zendframework/zend-db/issues/288 + */ + public function testSetSessionTimeZone() + { + $result = $this->adapter->query('SET @@session.time_zone = :tz', [':tz' => 'SYSTEM']); + $this->assertInstanceOf(PdoResult::class, $result); + } + + /** + * @expectedException Zend\Db\Adapter\Exception\RuntimeException + */ + public function testSelectWithNotPermittedBindParamName() + { + $result = $this->adapter->query('SET @@session.time_zone = :tz$', [':tz$' => 'SYSTEM']); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php new file mode 100644 index 00000000..d9c90ab8 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayTest.php @@ -0,0 +1,98 @@ +adapter); + $this->assertInstanceOf(TableGateway::class, $tableGateway); + } + + /** + * @covers \Zend\Db\TableGateway\TableGateway::select + */ + public function testSelect() + { + $tableGateway = new TableGateway('test', $this->adapter); + $rowset = $tableGateway->select(); + + $this->assertTrue(count($rowset) > 0); + foreach ($rowset as $row) { + $this->assertTrue(isset($row->id)); + $this->assertNotEmpty(isset($row->name)); + $this->assertNotEmpty(isset($row->value)); + } + } + + /** + * @covers \Zend\Db\TableGateway\TableGateway::insert + * @covers \Zend\Db\TableGateway\TableGateway::select + */ + public function testInsert() + { + $tableGateway = new TableGateway('test', $this->adapter); + + $rowset = $tableGateway->select(); + $data = [ + 'name' => 'test_name', + 'value' => 'test_value' + ]; + $affectedRows = $tableGateway->insert($data); + $this->assertEquals(1, $affectedRows); + + $rowSet = $tableGateway->select(['id' => $tableGateway->getLastInsertValue()]); + $row = $rowSet->current(); + + foreach ($data as $key => $value) { + $this->assertEquals($row->$key, $value); + } + } + + /** + * @see https://github.com/zendframework/zend-db/issues/35 + * @see https://github.com/zendframework/zend-db/pull/178 + */ + public function testInsertWithExtendedCharsetFieldName() + { + $tableGateway = new TableGateway('test_charset', $this->adapter); + + $affectedRows = $tableGateway->insert([ + 'field$' => 'test_value1', + 'field_' => 'test_value2' + ]); + $this->assertEquals(1, $affectedRows); + return $tableGateway->getLastInsertValue(); + } + + /** + * @depends testInsertWithExtendedCharsetFieldName + */ + public function testUpdateWithExtendedCharsetFieldName($id) + { + $tableGateway = new TableGateway('test_charset', $this->adapter); + + $data = [ + 'field$' => 'test_value3', + 'field_' => 'test_value4' + ]; + $affectedRows = $tableGateway->update($data, ['id' => $id]); + $this->assertEquals(1, $affectedRows); + + $rowSet = $tableGateway->select(['id' => $id]); + $row = $rowSet->current(); + + foreach ($data as $key => $value) { + $this->assertEquals($row->$key, $value); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/MysqlTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/MysqlTest.php new file mode 100644 index 00000000..bba0e800 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/MysqlTest.php @@ -0,0 +1,75 @@ +markTestSkipped(__CLASS__ . ' integration tests are not enabled!'); + } + if (extension_loaded('mysqli')) { + $this->adapters['mysqli'] = new \mysqli( + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE') + ); + } + if (extension_loaded('pdo')) { + $this->adapters['pdo_mysql'] = new \PDO( + 'mysql:host=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME') . ';dbname=' + . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD') + ); + } + } + + public function testQuoteValueWithMysqli() + { + if (! $this->adapters['mysqli'] instanceof \Mysqli) { + $this->markTestSkipped('MySQL (Mysqli) not configured in unit test configuration file'); + } + $mysql = new Mysql($this->adapters['mysqli']); + $value = $mysql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + + $mysql = new Mysql(new Mysqli\Mysqli(new Mysqli\Connection($this->adapters['mysqli']))); + $value = $mysql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + } + + public function testQuoteValueWithPdoMysql() + { + if (! $this->adapters['pdo_mysql'] instanceof \PDO) { + $this->markTestSkipped('MySQL (PDO_Mysql) not configured in unit test configuration file'); + } + $mysql = new Mysql($this->adapters['pdo_mysql']); + $value = $mysql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + + $mysql = new Mysql(new Pdo\Pdo(new Pdo\Connection($this->adapters['pdo_mysql']))); + $value = $mysql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/PostgresqlTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/PostgresqlTest.php new file mode 100644 index 00000000..e690d561 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/PostgresqlTest.php @@ -0,0 +1,75 @@ +markTestSkipped(__CLASS__ . ' integration tests are not enabled!'); + } + if (extension_loaded('pgsql')) { + $this->adapters['pgsql'] = \pg_connect( + 'host=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME') + . ' dbname=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE') + . ' user=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_USERNAME') + . ' password=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD') + ); + } + if (extension_loaded('pdo')) { + $this->adapters['pdo_pgsql'] = new \PDO( + 'pgsql:host=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME') . ';dbname=' + . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_USERNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD') + ); + } + } + + public function testQuoteValueWithPgsql() + { + if (! is_resource($this->adapters['pgsql'])) { + $this->markTestSkipped('Postgres (pgsql) not configured in unit test configuration file'); + } + $pgsql = new Postgresql($this->adapters['pgsql']); + $value = $pgsql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + + $pgsql = new Postgresql(new Pgsql\Pgsql(new Pgsql\Connection($this->adapters['pgsql']))); + $value = $pgsql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + } + + public function testQuoteValueWithPdoPgsql() + { + if (! $this->adapters['pdo_pgsql'] instanceof \PDO) { + $this->markTestSkipped('Postgres (PDO_PGSQL) not configured in unit test configuration file'); + } + $pgsql = new Postgresql($this->adapters['pdo_pgsql']); + $value = $pgsql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + + $pgsql = new Postgresql(new Pdo\Pdo(new Pdo\Connection($this->adapters['pdo_pgsql']))); + $value = $pgsql->quoteValue('value'); + self::assertEquals('\'value\'', $value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqlServerTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqlServerTest.php new file mode 100644 index 00000000..1cd97214 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqlServerTest.php @@ -0,0 +1,61 @@ +markTestSkipped(__CLASS__ . ' integration tests are not enabled!'); + } + if (extension_loaded('sqlsrv')) { + $this->adapters['sqlsrv'] = \sqlsrv_connect( + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME'), + [ + 'UID' => getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_USERNAME'), + 'PWD' => getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD'), + 'Database' => (getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_DATABASE') ? : null), + ] + ); + if (! $this->adapters['sqlsrv']) { + var_dump(sqlsrv_errors()); + exit; + } + } + if (extension_loaded('pdo')) { + $this->adapters['pdo_sqlsrv'] = new \PDO( + 'sqlsrv:Server=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME') + . ';Database=' . (getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_DATABASE') ? : null), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_USERNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD') + ); + } + } + + public function testQuoteValueWithSqlServer() + { + if (! $this->adapters['pdo_sqlsrv']) { + $this->markTestSkipped('SQLServer (pdo_sqlsrv) not configured in unit test configuration file'); + } + $sqlite = new SqlServer($this->adapters['pdo_sqlsrv']); + $value = $sqlite->quoteValue('value'); + self::assertEquals('\'value\'', $value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqliteTest.php b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqliteTest.php new file mode 100644 index 00000000..92b059bc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Adapter/Platform/SqliteTest.php @@ -0,0 +1,49 @@ +markTestSkipped(__CLASS__ . ' integration tests are not enabled!'); + } + if (extension_loaded('pdo')) { + $this->adapters['pdo_sqlite'] = new \PDO( + 'sqlite::memory:' + ); + } + } + + public function testQuoteValueWithPdoSqlite() + { + if (! $this->adapters['pdo_sqlite'] instanceof \PDO) { + $this->markTestSkipped('SQLite (PDO_SQLITE) not configured in unit test configuration file'); + } + $sqlite = new Sqlite($this->adapters['pdo_sqlite']); + $value = $sqlite->quoteValue('value'); + self::assertEquals('\'value\'', $value); + + $sqlite = new Sqlite(new Pdo\Pdo(new Pdo\Connection($this->adapters['pdo_sqlite']))); + $value = $sqlite->quoteValue('value'); + self::assertEquals('\'value\'', $value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/IntegrationTestListener.php b/bundled-libs/zendframework/zend-db/test/integration/IntegrationTestListener.php new file mode 100644 index 00000000..9bb4dcaa --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/IntegrationTestListener.php @@ -0,0 +1,62 @@ +getName() !== 'integration test') { + return; + } + + if (getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL')) { + $this->fixtureLoader = new \ZendIntegrationTest\Db\Platform\MysqlFixtureLoader(); + } + if (getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL')) { + $this->fixtureLoader = new \ZendIntegrationTest\Db\Platform\PgsqlFixtureLoader(); + } + + if (! isset($this->fixtureLoader)) { + return; + } + printf("\nIntegration test started.\n"); + $this->fixtureLoader->createDatabase(); + } + + public function endTestSuite(TestSuite $suite) + { + if ($suite->getName() !== 'integration test' + || ! isset($this->fixtureLoader) + ) { + return; + } + printf("\nIntegration test ended.\n"); + + $this->fixtureLoader->dropDatabase(); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Platform/FixtureLoader.php b/bundled-libs/zendframework/zend-db/test/integration/Platform/FixtureLoader.php new file mode 100644 index 00000000..98593dd5 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Platform/FixtureLoader.php @@ -0,0 +1,16 @@ +pdo = new \PDO( + 'mysql:host=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_HOSTNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_USERNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_PASSWORD') + ); + if (false === $this->pdo->exec(sprintf( + "CREATE DATABASE IF NOT EXISTS %s", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE') + ))) { + throw new \Exception(sprintf( + "I cannot create the MySQL %s test database: %s", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE'), + print_r($this->pdo->errorInfo(), true) + )); + } + + $this->pdo->exec('USE ' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE')); + + if (false === $this->pdo->exec(file_get_contents($this->fixtureFile))) { + throw new \Exception(sprintf( + "I cannot create the table for %s database. Check the %s file. %s ", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE'), + $this->fixtureFile, + print_r($this->pdo->errorInfo(), true) + )); + } + } + + public function dropDatabase() + { + $this->pdo->exec(sprintf( + "DROP DATABASE IF EXISTS %s", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE') + )); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/Platform/PgsqlFixtureLoader.php b/bundled-libs/zendframework/zend-db/test/integration/Platform/PgsqlFixtureLoader.php new file mode 100644 index 00000000..80e2cb44 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/Platform/PgsqlFixtureLoader.php @@ -0,0 +1,76 @@ +pdo = new \PDO( + 'pgsql:host=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_USERNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD') + ); + + $this->dropDatabase(); + if (false === $this->pdo->exec(sprintf( + "CREATE DATABASE %s", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE') + ))) { + throw new \Exception(sprintf( + "I cannot create the PostgreSQL %s test database: %s", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE'), + print_r($this->pdo->errorInfo(), true) + )); + } + + // PostgreSQL cannot switch database on same connection. + unset($this->pdo); + $this->pdo = new \PDO( + 'pgsql:host=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME') . ';' . + 'dbname=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_MYSQL_DATABASE'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_USERNAME'), + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD') + ); + + if (false === $this->pdo->exec(file_get_contents($this->fixtureFile))) { + throw new \Exception(sprintf( + "I cannot create the table for %s database. Check the %s file. %s ", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE'), + $this->fixtureFile, + print_r($this->pdo->errorInfo(), true) + )); + } + } + + public function dropDatabase() + { + if (! $this->initialRun) { + // Not possible to drop in PostgreSQL. + // Connection is locking the database and trying to close it with unset() + // does not trigger garbage collector on time to actually close it to free the lock. + return; + } + $this->initialRun = false; + + $this->pdo->exec(sprintf( + "DROP DATABASE IF EXISTS %s", + getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE') + )); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/integration/TestFixtures/mysql.sql b/bundled-libs/zendframework/zend-db/test/integration/TestFixtures/mysql.sql new file mode 100644 index 00000000..a429ff5e --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/TestFixtures/mysql.sql @@ -0,0 +1,21 @@ +CREATE TABLE IF NOT EXISTS test ( + id INT NOT NULL AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + value VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +); + +INSERT INTO test (name, value) VALUES +('foo', 'bar'), +('bar', 'baz'); + +CREATE TABLE IF NOT EXISTS test_charset ( + id INT NOT NULL AUTO_INCREMENT, + field$ VARCHAR(255) NOT NULL, + field_ VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +); + +INSERT INTO test_charset (field$, field_) VALUES +('foo', 'bar'), +('bar', 'baz'); diff --git a/bundled-libs/zendframework/zend-db/test/integration/TestFixtures/pgsql.sql b/bundled-libs/zendframework/zend-db/test/integration/TestFixtures/pgsql.sql new file mode 100644 index 00000000..f6b10048 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/integration/TestFixtures/pgsql.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS test ( + id SERIAL PRIMARY KEY, + name VARCHAR(255) NOT NULL, + value VARCHAR(255) NOT NULL +); + +INSERT INTO test (name, value) VALUES +('foo', 'bar'), +('bar', 'baz'); + +CREATE TABLE IF NOT EXISTS test_charset ( + id SERIAL PRIMARY KEY, + field$ VARCHAR(255) NOT NULL, + field_ VARCHAR(255) NOT NULL +); + +INSERT INTO test_charset (field$, field_) VALUES +('foo', 'bar'), +('bar', 'baz'); diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php new file mode 100644 index 00000000..978eb1e8 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php @@ -0,0 +1,88 @@ +serviceManager = new ServiceManager(); + + $config = new Config([ + 'abstract_factories' => ['Zend\Db\Adapter\AdapterAbstractServiceFactory'], + ]); + $config->configureServiceManager($this->serviceManager); + + $this->serviceManager->setService('config', [ + 'db' => [ + 'adapters' => [ + 'Zend\Db\Adapter\Writer' => [ + 'driver' => 'mysqli', + ], + 'Zend\Db\Adapter\Reader' => [ + 'driver' => 'mysqli', + ], + ], + ], + ]); + } + + /** + * @return array + */ + public function providerValidService() + { + return [ + ['Zend\Db\Adapter\Writer'], + ['Zend\Db\Adapter\Reader'], + ]; + } + + /** + * @return array + */ + public function providerInvalidService() + { + return [ + ['Zend\Db\Adapter\Unknown'], + ]; + } + + /** + * @param string $service + * @dataProvider providerValidService + * @requires extension mysqli + */ + public function testValidService($service) + { + $actual = $this->serviceManager->get($service); + self::assertInstanceOf('Zend\Db\Adapter\Adapter', $actual); + } + + /** + * @dataProvider providerInvalidService + * + * @param string $service + */ + public function testInvalidService($service) + { + $this->expectException('\Zend\ServiceManager\Exception\ServiceNotFoundException'); + $this->serviceManager->get($service); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAwareTraitTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAwareTraitTest.php new file mode 100644 index 00000000..ef62f518 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterAwareTraitTest.php @@ -0,0 +1,32 @@ +getObjectForTrait('\Zend\Db\Adapter\AdapterAwareTrait'); + + self::assertAttributeEquals(null, 'adapter', $object); + + $driver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $platform = $this->getMockBuilder('Zend\Db\Adapter\Platform\PlatformInterface')->getMock(); + + $adapter = new Adapter($driver, $platform); + + $object->setDbAdapter($adapter); + + self::assertAttributeEquals($adapter, 'adapter', $object); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterServiceFactoryTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterServiceFactoryTest.php new file mode 100644 index 00000000..5bceeb53 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterServiceFactoryTest.php @@ -0,0 +1,57 @@ +markTestSkipped('Adapter factory tests require pdo_sqlite'); + } + + $this->services = $this->prophesize(ServiceLocatorInterface::class); + $this->services->willImplement(ContainerInterface::class); + + $this->factory = new AdapterServiceFactory(); + } + + public function testV2FactoryReturnsAdapter() + { + $this->services->get('config')->willReturn([ + 'db' => [ + 'driver' => 'Pdo_Sqlite', + 'database' => 'sqlite::memory:', + ], + ]); + + $adapter = $this->factory->createService($this->services->reveal()); + self::assertInstanceOf(Adapter::class, $adapter); + } + + public function testV3FactoryReturnsAdapter() + { + $this->services->get('config')->willReturn([ + 'db' => [ + 'driver' => 'Pdo_Sqlite', + 'database' => 'sqlite::memory:', + ], + ]); + + $adapter = $this->factory->__invoke($this->services->reveal(), Adapter::class); + self::assertInstanceOf(Adapter::class, $adapter); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterTest.php new file mode 100644 index 00000000..21f295d4 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/AdapterTest.php @@ -0,0 +1,316 @@ +mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $this->mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $this->mockDriver->expects($this->any())->method('checkEnvironment')->will($this->returnValue(true)); + $this->mockDriver->expects($this->any())->method('getConnection') + ->will($this->returnValue($this->mockConnection)); + $this->mockPlatform = $this->getMockBuilder('Zend\Db\Adapter\Platform\PlatformInterface')->getMock(); + $this->mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $this->mockDriver->expects($this->any())->method('createStatement') + ->will($this->returnValue($this->mockStatement)); + + $this->adapter = new Adapter($this->mockDriver, $this->mockPlatform); + } + + /** + * @testdox unit test: Test setProfiler() will store profiler + * @covers \Zend\Db\Adapter\Adapter::setProfiler + */ + public function testSetProfiler() + { + $ret = $this->adapter->setProfiler(new Profiler\Profiler()); + self::assertSame($this->adapter, $ret); + } + + /** + * @testdox unit test: Test getProfiler() will store profiler + * @covers \Zend\Db\Adapter\Adapter::getProfiler + */ + public function testGetProfiler() + { + $this->adapter->setProfiler($profiler = new Profiler\Profiler()); + self::assertSame($profiler, $this->adapter->getProfiler()); + + $adapter = new Adapter(['driver' => $this->mockDriver, 'profiler' => true], $this->mockPlatform); + self::assertInstanceOf('Zend\Db\Adapter\Profiler\Profiler', $adapter->getProfiler()); + } + + /** + * @testdox unit test: Test createDriverFromParameters() will create proper driver type + * @covers \Zend\Db\Adapter\Adapter::createDriver + */ + public function testCreateDriver() + { + if (extension_loaded('mysqli')) { + $adapter = new Adapter(['driver' => 'mysqli'], $this->mockPlatform); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Mysqli\Mysqli', $adapter->driver); + unset($adapter); + } + + if (extension_loaded('pgsql')) { + $adapter = new Adapter(['driver' => 'pgsql'], $this->mockPlatform); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Pgsql\Pgsql', $adapter->driver); + unset($adapter); + } + + if (extension_loaded('sqlsrv')) { + $adapter = new Adapter(['driver' => 'sqlsrv'], $this->mockPlatform); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv', $adapter->driver); + unset($adapter); + } + + if (extension_loaded('pdo')) { + $adapter = new Adapter(['driver' => 'pdo_sqlite'], $this->mockPlatform); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Pdo\Pdo', $adapter->driver); + unset($adapter); + } + } + + /** + * @testdox unit test: Test createPlatformFromDriver() will create proper platform from driver + * @covers \Zend\Db\Adapter\Adapter::createPlatform + */ + public function testCreatePlatform() + { + $driver = clone $this->mockDriver; + $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Mysql')); + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\Mysql', $adapter->platform); + unset($adapter, $driver); + + $driver = clone $this->mockDriver; + $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('SqlServer')); + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\SqlServer', $adapter->platform); + unset($adapter, $driver); + + $driver = clone $this->mockDriver; + $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Postgresql')); + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\Postgresql', $adapter->platform); + unset($adapter, $driver); + + $driver = clone $this->mockDriver; + $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Sqlite')); + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\Sqlite', $adapter->platform); + unset($adapter, $driver); + + $driver = clone $this->mockDriver; + $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('IbmDb2')); + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\IbmDb2', $adapter->platform); + unset($adapter, $driver); + + $driver = clone $this->mockDriver; + $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Oracle')); + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\Oracle', $adapter->platform); + unset($adapter, $driver); + + $driver = clone $this->mockDriver; + $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Foo')); + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\Sql92', $adapter->platform); + unset($adapter, $driver); + + // ensure platform can created via string, and also that it passed in options to platform object + $driver = [ + 'driver' => 'pdo_sqlite', + 'platform' => 'Oracle', + 'platform_options' => ['quote_identifiers' => false], + ]; + $adapter = new Adapter($driver); + self::assertInstanceOf('Zend\Db\Adapter\Platform\Oracle', $adapter->platform); + self::assertEquals('foo', $adapter->getPlatform()->quoteIdentifier('foo')); + unset($adapter, $driver); + } + + + /** + * @testdox unit test: Test getDriver() will return driver object + * @covers \Zend\Db\Adapter\Adapter::getDriver + */ + public function testGetDriver() + { + self::assertSame($this->mockDriver, $this->adapter->getDriver()); + } + + /** + * @testdox unit test: Test getPlatform() returns platform object + * @covers \Zend\Db\Adapter\Adapter::getPlatform + */ + public function testGetPlatform() + { + self::assertSame($this->mockPlatform, $this->adapter->getPlatform()); + } + + /** + * @testdox unit test: Test getPlatform() returns platform object + * @covers \Zend\Db\Adapter\Adapter::getQueryResultSetPrototype + */ + public function testGetQueryResultSetPrototype() + { + self::assertInstanceOf('Zend\Db\ResultSet\ResultSetInterface', $this->adapter->getQueryResultSetPrototype()); + } + + /** + * @testdox unit test: Test getCurrentSchema() returns current schema from connection object + * @covers \Zend\Db\Adapter\Adapter::getCurrentSchema + */ + public function testGetCurrentSchema() + { + $this->mockConnection->expects($this->any())->method('getCurrentSchema')->will($this->returnValue('FooSchema')); + self::assertEquals('FooSchema', $this->adapter->getCurrentSchema()); + } + + /** + * @testdox unit test: Test query() in prepare mode produces a statement object + * @covers \Zend\Db\Adapter\Adapter::query + */ + public function testQueryWhenPreparedProducesStatement() + { + $s = $this->adapter->query('SELECT foo'); + self::assertSame($this->mockStatement, $s); + } + + /** + * @testdox unit test: Test query() in prepare mode, with array of parameters, produces a result object + * @covers \Zend\Db\Adapter\Adapter::query + */ + public function testQueryWhenPreparedWithParameterArrayProducesResult() + { + $parray = ['bar' => 'foo']; + $sql = 'SELECT foo, :bar'; + $statement = $this->getMockBuilder('\Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $this->mockDriver->expects($this->any())->method('createStatement') + ->with($sql)->will($this->returnValue($statement)); + $this->mockStatement->expects($this->any())->method('execute')->will($this->returnValue($result)); + + $r = $this->adapter->query($sql, $parray); + self::assertSame($result, $r); + } + + /** + * @testdox unit test: Test query() in prepare mode, with ParameterContainer, produces a result object + * @covers \Zend\Db\Adapter\Adapter::query + */ + public function testQueryWhenPreparedWithParameterContainerProducesResult() + { + $sql = 'SELECT foo'; + $parameterContainer = $this->getMockBuilder('Zend\Db\Adapter\ParameterContainer')->getMock(); + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $this->mockDriver->expects($this->any())->method('createStatement') + ->with($sql)->will($this->returnValue($this->mockStatement)); + $this->mockStatement->expects($this->any())->method('execute')->will($this->returnValue($result)); + $result->expects($this->any())->method('isQueryResult')->will($this->returnValue(true)); + + $r = $this->adapter->query($sql, $parameterContainer); + self::assertInstanceOf('Zend\Db\ResultSet\ResultSet', $r); + } + + /** + * @testdox unit test: Test query() in execute mode produces a driver result object + * @covers \Zend\Db\Adapter\Adapter::query + */ + public function testQueryWhenExecutedProducesAResult() + { + $sql = 'SELECT foo'; + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $this->mockConnection->expects($this->any())->method('execute')->with($sql)->will($this->returnValue($result)); + + $r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + self::assertSame($result, $r); + } + + /** + * @testdox unit test: Test query() in execute mode produces a resultset object + * @covers \Zend\Db\Adapter\Adapter::query + */ + public function testQueryWhenExecutedProducesAResultSetObjectWhenResultIsQuery() + { + $sql = 'SELECT foo'; + + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $this->mockConnection->expects($this->any())->method('execute')->with($sql)->will($this->returnValue($result)); + $result->expects($this->any())->method('isQueryResult')->will($this->returnValue(true)); + + $r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + self::assertInstanceOf('Zend\Db\ResultSet\ResultSet', $r); + + $r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE, new TemporaryResultSet()); + self::assertInstanceOf('ZendTest\Db\TestAsset\TemporaryResultSet', $r); + } + + /** + * @testdox unit test: Test createStatement() produces a statement object + * @covers \Zend\Db\Adapter\Adapter::createStatement + */ + public function testCreateStatement() + { + self::assertSame($this->mockStatement, $this->adapter->createStatement()); + } + + /** + * @testdox unit test: Test __get() works + * @covers \Zend\Db\Adapter\Adapter::__get + */ + // @codingStandardsIgnoreStart + public function test__get() + { + // @codingStandardsIgnoreEnd + self::assertSame($this->mockDriver, $this->adapter->driver); + self::assertSame($this->mockDriver, $this->adapter->DrivER); + self::assertSame($this->mockPlatform, $this->adapter->PlatForm); + self::assertSame($this->mockPlatform, $this->adapter->platform); + + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid magic'); + $this->adapter->foo; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php new file mode 100644 index 00000000..86d9284a --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php @@ -0,0 +1,44 @@ + 'TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_DATABASE', + 'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_USERNAME', + 'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD', + ]; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + foreach ($this->variables as $name => $value) { + if (! getenv($value)) { + $this->markTestSkipped( + 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' + ); + } + $this->variables[$name] = getenv($value); + } + + if (! extension_loaded('ibm_db2')) { + $this->fail('The phpunit group integration-ibm_db2 was enabled, but the extension is not loaded.'); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php new file mode 100644 index 00000000..d30508d1 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php @@ -0,0 +1,213 @@ +variables); + self::assertInternalType('string', $connection->getCurrentSchema()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::setResource + */ + public function testSetResource() + { + $resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + $connection = new Connection([]); + self::assertSame($connection, $connection->setResource($resource)); + + $connection->disconnect(); + unset($connection); + unset($resource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::getResource + */ + public function testGetResource() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertInternalType('resource', $connection->getResource()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::connect + */ + public function testConnect() + { + $connection = new Connection($this->variables); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::isConnected + */ + public function testIsConnected() + { + $connection = new Connection($this->variables); + self::assertFalse($connection->isConnected()); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::disconnect + */ + public function testDisconnect() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertTrue($connection->isConnected()); + $connection->disconnect(); + self::assertFalse($connection->isConnected()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::beginTransaction + */ + public function testBeginTransaction() + { + if (! $this->isTransactionEnabled()) { + $this->markTestIncomplete( + 'I cannot test without the DB2 transactions enabled' + ); + } + $connection = new Connection($this->variables); + $connection->beginTransaction(); + self::assertTrue($connection->inTransaction()); + self::assertEquals(0, db2_autocommit($connection->getResource())); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::commit + */ + public function testCommit() + { + if (! $this->isTransactionEnabled()) { + $this->markTestIncomplete( + 'I cannot test without the DB2 transactions enabled' + ); + } + $connection = new Connection($this->variables); + $connection->beginTransaction(); + + $oldValue = db2_autocommit($connection->getResource()); + $connection->beginTransaction(); + self::assertTrue($connection->inTransaction()); + $connection->commit(); + self::assertFalse($connection->inTransaction()); + self::assertEquals($oldValue, db2_autocommit($connection->getResource())); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::rollback + */ + public function testRollback() + { + if (! $this->isTransactionEnabled()) { + $this->markTestIncomplete( + 'I cannot test without the DB2 transactions enabled' + ); + } + $connection = new Connection($this->variables); + $connection->beginTransaction(); + + $oldValue = db2_autocommit($connection->getResource()); + $connection->beginTransaction(); + self::assertTrue($connection->inTransaction()); + $connection->rollback(); + self::assertFalse($connection->inTransaction()); + self::assertEquals($oldValue, db2_autocommit($connection->getResource())); + } + + /** + * Return true if the transaction is enabled for DB2 + * + * @return bool + */ + protected function isTransactionEnabled() + { + $os = (php_uname('s') == 'OS400'); + if ($os) { + return ini_get('ibm_db2.i5_allow_commit') == 1; + } + + return true; + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::execute + */ + public function testExecute() + { + $ibmdb2 = new IbmDb2($this->variables); + $connection = $ibmdb2->getConnection(); + + $result = $connection->execute('SELECT \'foo\' FROM SYSIBM.SYSDUMMY1'); + self::assertInstanceOf('Zend\Db\Adapter\Driver\IbmDb2\Result', $result); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::getLastGeneratedValue + */ + public function testGetLastGeneratedValue() + { + $this->markTestIncomplete('Need to create a temporary sequence.'); + $connection = new Connection($this->variables); + $connection->getLastGeneratedValue(); + } + + /** + * @group zf3469 + */ + public function testConnectReturnsConnectionWhenResourceSet() + { + $resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + $connection = new Connection([]); + $connection->setResource($resource); + self::assertSame($connection, $connection->connect()); + + $connection->disconnect(); + unset($connection); + unset($resource); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php new file mode 100644 index 00000000..b305b75d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php @@ -0,0 +1,64 @@ +connection = new Connection([]); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->connection, $this->connection->setDriver(new IbmDb2([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::setConnectionParameters + */ + public function testSetConnectionParameters() + { + self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Connection::getConnectionParameters + */ + public function testGetConnectionParameters() + { + $this->connection->setConnectionParameters(['foo' => 'bar']); + self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php new file mode 100644 index 00000000..239be251 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php @@ -0,0 +1,55 @@ +checkEnvironment()); + } + + public function testCreateStatement() + { + $driver = new IbmDb2([]); + + $resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + + $stmtResource = db2_prepare($resource, 'SELECT 1 FROM SYSIBM.SYSDUMMY1'); + + $driver->getConnection()->setResource($resource); + + $stmt = $driver->createStatement('SELECT 1 FROM SYSIBM.SYSDUMMY1'); + self::assertInstanceOf('Zend\Db\Adapter\Driver\IbmDb2\Statement', $stmt); + $stmt = $driver->createStatement($stmtResource); + self::assertInstanceOf('Zend\Db\Adapter\Driver\IbmDb2\Statement', $stmt); + $stmt = $driver->createStatement(); + self::assertInstanceOf('Zend\Db\Adapter\Driver\IbmDb2\Statement', $stmt); + + $this->expectException('Zend\Db\Adapter\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('only accepts an SQL string or an ibm_db2 resource'); + $driver->createStatement(new \stdClass); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php new file mode 100644 index 00000000..3ff53538 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php @@ -0,0 +1,166 @@ +ibmdb2 = new IbmDb2([]); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::registerConnection + */ + public function testRegisterConnection() + { + $mockConnection = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\IbmDb2\Connection', + [[]], + '', + true, + true, + true, + ['setDriver'] + ); + $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->ibmdb2)); + self::assertSame($this->ibmdb2, $this->ibmdb2->registerConnection($mockConnection)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::registerStatementPrototype + */ + public function testRegisterStatementPrototype() + { + $this->ibmdb2 = new IbmDb2([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\IbmDb2\Statement', + [], + '', + true, + true, + true, + ['setDriver'] + ); + $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->ibmdb2)); + self::assertSame($this->ibmdb2, $this->ibmdb2->registerStatementPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::registerResultPrototype + */ + public function testRegisterResultPrototype() + { + $this->ibmdb2 = new IbmDb2([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\IbmDb2\Result', + [], + '', + true, + true, + true, + ['setDriver'] + ); + self::assertSame($this->ibmdb2, $this->ibmdb2->registerResultPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::getDatabasePlatformName + */ + public function testGetDatabasePlatformName() + { + $this->ibmdb2 = new IbmDb2([]); + self::assertEquals('IbmDb2', $this->ibmdb2->getDatabasePlatformName()); + self::assertEquals('IBM DB2', $this->ibmdb2->getDatabasePlatformName(IbmDb2::NAME_FORMAT_NATURAL)); + } + + /** + * @depends testRegisterConnection + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::getConnection + */ + public function testGetConnection($mockConnection) + { + $conn = new \Zend\Db\Adapter\Driver\IbmDb2\Connection([]); + $this->ibmdb2->registerConnection($conn); + self::assertSame($conn, $this->ibmdb2->getConnection()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::createStatement + * @todo Implement testGetPrepareType(). + */ + public function testCreateStatement() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::createResult + * @todo Implement testGetPrepareType(). + */ + public function testCreateResult() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::getPrepareType + * @todo Implement testGetPrepareType(). + */ + public function testGetPrepareType() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::formatParameterName + * @todo Implement testFormatParameterName(). + */ + public function testFormatParameterName() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::getLastGeneratedValue + * @todo Implement testGetLastGeneratedValue(). + */ + public function testGetLastGeneratedValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php new file mode 100644 index 00000000..affa836a --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php @@ -0,0 +1,198 @@ +object = new Result; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::initialize + * @todo Implement testInitialize(). + */ + public function testInitialize() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::buffer + * @todo Implement testBuffer(). + */ + public function testBuffer() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::getResource + * @todo Implement testGetResource(). + */ + public function testGetResource() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::current + * @todo Implement testCurrent(). + */ + public function testCurrent() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::next + * @todo Implement testNext(). + */ + public function testNext() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::key + * @todo Implement testKey(). + */ + public function testKey() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::rewind + * @todo Implement testRewind(). + */ + public function testRewind() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::valid + * @todo Implement testValid(). + */ + public function testValid() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::count + * @todo Implement testCount(). + */ + public function testCount() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::getFieldCount + * @todo Implement testGetFieldCount(). + */ + public function testGetFieldCount() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::isQueryResult + * @todo Implement testIsQueryResult(). + */ + public function testIsQueryResult() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::getAffectedRows + * @todo Implement testGetAffectedRows(). + */ + public function testGetAffectedRows() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Result::getGeneratedValue + * @todo Implement testGetGeneratedValue(). + */ + public function testGetGeneratedValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php new file mode 100644 index 00000000..0b9960e9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php @@ -0,0 +1,134 @@ + 'TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_DATABASE', + 'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_USERNAME', + 'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD', + ]; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + foreach ($this->variables as $name => $value) { + if (! getenv($value)) { + $this->markTestSkipped( + 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' + ); + } + $this->variables[$name] = getenv($value); + } + + if (! extension_loaded('ibm_db2')) { + $this->fail('The phpunit group integration-ibm_db2 was enabled, but the extension is not loaded.'); + } + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::initialize + */ + public function testInitialize() + { + $db2Resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + + $statement = new Statement; + self::assertSame($statement, $statement->initialize($db2Resource)); + unset($stmtResource, $db2Resource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::getResource + */ + public function testGetResource() + { + $db2Resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + + $statement = new Statement; + $statement->initialize($db2Resource); + $statement->prepare("SELECT 'foo' FROM sysibm.sysdummy1"); + $resource = $statement->getResource(); + self::assertEquals('DB2 Statement', get_resource_type($resource)); + unset($resource, $db2Resource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::isPrepared + */ + public function testPrepare() + { + $db2Resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + + $statement = new Statement; + $statement->initialize($db2Resource); + self::assertFalse($statement->isPrepared()); + self::assertSame($statement, $statement->prepare("SELECT 'foo' FROM SYSIBM.SYSDUMMY1")); + self::assertTrue($statement->isPrepared()); + unset($resource, $db2Resource); + } + + /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + */ + public function testPrepareThrowsAnExceptionOnFailure() + { + $db2Resource = db2_connect( + $this->variables['database'], + $this->variables['username'], + $this->variables['password'] + ); + $statement = new Statement; + $statement->initialize($db2Resource); + $this->setExpectedException(RuntimeException::class); + $statement->prepare("SELECT"); + } + + /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::execute + */ + public function testExecute() + { + $ibmdb2 = new IbmDb2($this->variables); + $statement = $ibmdb2->createStatement("SELECT 'foo' FROM SYSIBM.SYSDUMMY1"); + self::assertSame($statement, $statement->prepare()); + + $result = $statement->execute(); + self::assertInstanceOf('Zend\Db\Adapter\Driver\IbmDb2\Result', $result); + + unset($resource, $ibmdb2); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementTest.php new file mode 100644 index 00000000..8c600219 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/StatementTest.php @@ -0,0 +1,188 @@ +currentErrorReporting = error_reporting(); + $this->statement = new Statement; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + // ensure error_reporting is set back to correct value + error_reporting($this->currentErrorReporting); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->statement, $this->statement->setDriver(new IbmDb2([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::setParameterContainer + */ + public function testSetParameterContainer() + { + self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::getParameterContainer + * @todo Implement testGetParameterContainer(). + */ + public function testGetParameterContainer() + { + $container = new ParameterContainer; + $this->statement->setParameterContainer($container); + self::assertSame($container, $this->statement->getParameterContainer()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::getResource + * @todo Implement testGetResource(). + */ + public function testGetResource() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::setSql + * @todo Implement testSetSql(). + */ + public function testSetSql() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::getSql + * @todo Implement testGetSql(). + */ + public function testGetSql() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::isPrepared + */ + public function testPrepare() + { + $sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1"; + $this->statement->prepare($sql); + $this->assertTrue($this->statement->isPrepared()); + } + + /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::isPrepared + */ + public function testPreparingTwiceErrors() + { + $sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1"; + $this->statement->prepare($sql); + $this->assertTrue($this->statement->isPrepared()); + + $this->expectException( + RuntimeException::class, + 'This statement has been prepared already' + ); + $this->statement->prepare($sql); + } + + /** + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::setSql + */ + public function testPrepareThrowsRuntimeExceptionOnInvalidSql() + { + $sql = "INVALID SQL"; + $this->statement->setSql($sql); + + $this->expectException( + RuntimeException::class, + 'SQL is invalid. Error message' + ); + $this->statement->prepare(); + } + + /** + * If error_reporting() is turned off, then the error handler will not + * be called, but a RuntimeException will still be generated as the + * resource is false + * + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare + * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::setSql + */ + public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingDisabled() + { + error_reporting(0); + $sql = "INVALID SQL"; + $this->statement->setSql($sql); + + $this->expectException( + RuntimeException::class, + 'Error message' + ); + $this->statement->prepare(); + } + + /** + * @covers \Zend\Db\Adapter\Driver\IbmDb2\Statement::execute + * @todo Implement testExecute(). + */ + public function testExecute() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php new file mode 100644 index 00000000..7ac4cace --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php @@ -0,0 +1,57 @@ +markTestSkipped('Mysqli test disabled'); + } + $this->connection = new Connection([]); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Mysqli\Connection::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->connection, $this->connection->setDriver(new Mysqli([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Mysqli\Connection::setConnectionParameters + */ + public function testSetConnectionParameters() + { + self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Mysqli\Connection::getConnectionParameters + */ + public function testGetConnectionParameters() + { + $this->connection->setConnectionParameters(['foo' => 'bar']); + self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); + } + + public function testConnectionFails() + { + $connection = new Connection([]); + + $this->expectException('\Zend\Db\Adapter\Exception\RuntimeException'); + $this->expectExceptionMessage('Connection error'); + $connection->connect(); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php new file mode 100644 index 00000000..ca818cd8 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php @@ -0,0 +1,41 @@ + 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_HOSTNAME', + 'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_USERNAME', + 'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_PASSWORD', + ]; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + foreach ($this->variables as $name => $value) { + if (! getenv($value)) { + $this->markTestSkipped( + 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' + ); + } + $this->variables[$name] = getenv($value); + } + + if (! extension_loaded('oci8')) { + $this->fail('The phpunit group integration-oci8 was enabled, but the extension is not loaded.'); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php new file mode 100644 index 00000000..8b3d7081 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php @@ -0,0 +1,180 @@ +variables); + self::assertInternalType('string', $connection->getCurrentSchema()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::setResource + */ + public function testSetResource() + { + $this->markTestIncomplete('edit this'); + $resource = oci_connect( + $this->variables['username'], + $this->variables['password'], + $this->variables['hostname'] + ); + + $connection = new Connection([]); + self::assertSame($connection, $connection->setResource($resource)); + + $connection->disconnect(); + unset($connection); + unset($resource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::getResource + */ + public function testGetResource() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertInternalType('resource', $connection->getResource()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::connect + */ + public function testConnect() + { + $connection = new Connection($this->variables); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::isConnected + */ + public function testIsConnected() + { + $connection = new Connection($this->variables); + self::assertFalse($connection->isConnected()); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::disconnect + */ + public function testDisconnect() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertTrue($connection->isConnected()); + $connection->disconnect(); + self::assertFalse($connection->isConnected()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::beginTransaction + * @todo Implement testBeginTransaction(). + */ + public function testBeginTransaction() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::commit + * @todo Implement testCommit(). + */ + public function testCommit() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::rollback + * @todo Implement testRollback(). + */ + public function testRollback() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::execute + */ + public function testExecute() + { + $oci8 = new Oci8($this->variables); + $connection = $oci8->getConnection(); + + $result = $connection->execute('SELECT \'foo\' FROM DUAL'); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Oci8\Result', $result); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::getLastGeneratedValue + */ + public function testGetLastGeneratedValue() + { + $this->markTestIncomplete('Need to create a temporary sequence.'); + $connection = new Connection($this->variables); + $connection->getLastGeneratedValue(); + } + + /** + * @group zf3469 + */ + public function testConnectReturnsConnectionWhenResourceSet() + { + $this->markTestIncomplete('edit this'); + $resource = oci_connect( + $this->variables['username'], + $this->variables['password'], + $this->variables['hostname'] + ); + + $connection = new Connection([]); + $connection->setResource($resource); + self::assertSame($connection, $connection->connect()); + + $connection->disconnect(); + unset($connection); + unset($resource); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionTest.php new file mode 100644 index 00000000..426f3c1f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ConnectionTest.php @@ -0,0 +1,64 @@ +connection = new Connection([]); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->connection, $this->connection->setDriver(new Oci8([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::setConnectionParameters + */ + public function testSetConnectionParameters() + { + self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Connection::getConnectionParameters + */ + public function testGetConnectionParameters() + { + $this->connection->setConnectionParameters(['foo' => 'bar']); + self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php new file mode 100644 index 00000000..8a2602ff --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php @@ -0,0 +1,113 @@ +rowCounter = new RowCounter(); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Feature\RowCounter::getName + */ + public function testGetName() + { + self::assertEquals('RowCounter', $this->rowCounter->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Feature\RowCounter::getCountForStatement + */ + public function testGetCountForStatement() + { + $statement = $this->getMockStatement('SELECT XXX', 5); + $statement->expects($this->once()) + ->method('prepare') + ->with($this->equalTo('SELECT COUNT(*) as "count" FROM (SELECT XXX)')); + $count = $this->rowCounter->getCountForStatement($statement); + self::assertEquals(5, $count); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Feature\RowCounter::getCountForSql + */ + public function testGetCountForSql() + { + $this->rowCounter->setDriver($this->getMockDriver(5)); + $count = $this->rowCounter->getCountForSql('SELECT XXX'); + self::assertEquals(5, $count); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Feature\RowCounter::getRowCountClosure + */ + public function testGetRowCountClosure() + { + $stmt = $this->getMockStatement('SELECT XXX', 5); + /** @var \Closure $closure */ + $closure = $this->rowCounter->getRowCountClosure($stmt); + self::assertInstanceOf('Closure', $closure); + self::assertEquals(5, $closure()); + } + + protected function getMockStatement($sql, $returnValue) + { + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\Oci8\Statement') + ->setMethods(['prepare', 'execute']) + ->disableOriginalConstructor() + ->getMock(); + + // mock the result + $result = $this->getMockBuilder('stdClass') + ->setMethods(['current']) + ->getMock(); + $result->expects($this->once()) + ->method('current') + ->will($this->returnValue(['count' => $returnValue])); + $statement->setSql($sql); + $statement->expects($this->once()) + ->method('execute') + ->will($this->returnValue($result)); + return $statement; + } + + protected function getMockDriver($returnValue) + { + $oci8Statement = $this->getMockBuilder('stdClass') + ->setMethods(['current']) + ->disableOriginalConstructor() + ->getMock(); // stdClass can be used here + $oci8Statement->expects($this->once()) + ->method('current') + ->will($this->returnValue(['count' => $returnValue])); + $connection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $connection->expects($this->once()) + ->method('execute') + ->will($this->returnValue($oci8Statement)); + $driver = $this->getMockBuilder('Zend\Db\Adapter\Driver\Oci8\Oci8') + ->setMethods(['getConnection']) + ->disableOriginalConstructor() + ->getMock(); + $driver->expects($this->once()) + ->method('getConnection') + ->will($this->returnValue($connection)); + return $driver; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php new file mode 100644 index 00000000..3d816fab --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php @@ -0,0 +1,50 @@ +checkEnvironment()); + } + + public function testCreateStatement() + { + $driver = new Oci8([]); + $resource = oci_connect( + $this->variables['username'], + $this->variables['password'], + $this->variables['hostname'] + ); + + $driver->getConnection()->setResource($resource); + + $stmt = $driver->createStatement('SELECT * FROM DUAL'); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Oci8\Statement', $stmt); + $stmt = $driver->createStatement(); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Oci8\Statement', $stmt); + + $this->expectException('Zend\Db\Adapter\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('only accepts an SQL string or an oci8 resource'); + $driver->createStatement(new \stdClass); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8Test.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8Test.php new file mode 100644 index 00000000..c85c5623 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/Oci8Test.php @@ -0,0 +1,166 @@ +oci8 = new Oci8([]); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::registerConnection + */ + public function testRegisterConnection() + { + $mockConnection = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Oci8\Connection', + [[]], + '', + true, + true, + true, + ['setDriver'] + ); + $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->oci8)); + self::assertSame($this->oci8, $this->oci8->registerConnection($mockConnection)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::registerStatementPrototype + */ + public function testRegisterStatementPrototype() + { + $this->oci8 = new Oci8([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Oci8\Statement', + [], + '', + true, + true, + true, + ['setDriver'] + ); + $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->oci8)); + self::assertSame($this->oci8, $this->oci8->registerStatementPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::registerResultPrototype + */ + public function testRegisterResultPrototype() + { + $this->oci8 = new Oci8([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Oci8\Result', + [], + '', + true, + true, + true, + ['setDriver'] + ); + self::assertSame($this->oci8, $this->oci8->registerResultPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::getDatabasePlatformName + */ + public function testGetDatabasePlatformName() + { + $this->oci8 = new Oci8([]); + self::assertEquals('Oracle', $this->oci8->getDatabasePlatformName()); + self::assertEquals('Oracle', $this->oci8->getDatabasePlatformName(Oci8::NAME_FORMAT_NATURAL)); + } + + /** + * @depends testRegisterConnection + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::getConnection + */ + public function testGetConnection($mockConnection) + { + $conn = new \Zend\Db\Adapter\Driver\Oci8\Connection([]); + $this->oci8->registerConnection($conn); + self::assertSame($conn, $this->oci8->getConnection()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::createStatement + * @todo Implement testGetPrepareType(). + */ + public function testCreateStatement() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::createResult + * @todo Implement testGetPrepareType(). + */ + public function testCreateResult() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::getPrepareType + * @todo Implement testGetPrepareType(). + */ + public function testGetPrepareType() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::formatParameterName + * @todo Implement testFormatParameterName(). + */ + public function testFormatParameterName() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Oci8::getLastGeneratedValue + * @todo Implement testGetLastGeneratedValue(). + */ + public function testGetLastGeneratedValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php new file mode 100644 index 00000000..69f7ca98 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php @@ -0,0 +1,198 @@ +object = new Result; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::initialize + * @todo Implement testInitialize(). + */ + public function testInitialize() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::buffer + * @todo Implement testBuffer(). + */ + public function testBuffer() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::getResource + * @todo Implement testGetResource(). + */ + public function testGetResource() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::current + * @todo Implement testCurrent(). + */ + public function testCurrent() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::next + * @todo Implement testNext(). + */ + public function testNext() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::key + * @todo Implement testKey(). + */ + public function testKey() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::rewind + * @todo Implement testRewind(). + */ + public function testRewind() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::valid + * @todo Implement testValid(). + */ + public function testValid() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::count + * @todo Implement testCount(). + */ + public function testCount() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::getFieldCount + * @todo Implement testGetFieldCount(). + */ + public function testGetFieldCount() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::isQueryResult + * @todo Implement testIsQueryResult(). + */ + public function testIsQueryResult() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::getAffectedRows + * @todo Implement testGetAffectedRows(). + */ + public function testGetAffectedRows() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::getGeneratedValue + * @todo Implement testGetGeneratedValue(). + */ + public function testGetGeneratedValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultTest.php new file mode 100644 index 00000000..4e3a0cd9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/ResultTest.php @@ -0,0 +1,90 @@ +getResource()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::buffer + */ + public function testBuffer() + { + $result = new Result(); + self::assertNull($result->buffer()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::isBuffered + */ + public function testIsBuffered() + { + $result = new Result(); + self::assertFalse($result->isBuffered()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::getGeneratedValue + */ + public function testGetGeneratedValue() + { + $result = new Result(); + self::assertNull($result->getGeneratedValue()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::key + */ + public function testKey() + { + $result = new Result(); + self::assertEquals(0, $result->key()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::next + */ + public function testNext() + { + $mockResult = $this->getMockBuilder('Zend\Db\Adapter\Driver\Oci8\Result') + ->setMethods(['loadData']) + ->getMock(); + $mockResult->expects($this->any()) + ->method('loadData') + ->will($this->returnValue(true)); + self::assertTrue($mockResult->next()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Result::rewind + */ + public function testRewind() + { + $result = new Result(); + self::assertNull($result->rewind()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php new file mode 100644 index 00000000..e91b827d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php @@ -0,0 +1,117 @@ + 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_HOSTNAME', + 'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_USERNAME', + 'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_PASSWORD', + ]; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + foreach ($this->variables as $name => $value) { + if (! getenv($value)) { + $this->markTestSkipped( + 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' + ); + } + $this->variables[$name] = getenv($value); + } + + if (! extension_loaded('oci8')) { + $this->fail('The phpunit group integration-oracle was enabled, but the extension is not loaded.'); + } + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::initialize + */ + public function testInitialize() + { + $ociResource = oci_connect( + $this->variables['username'], + $this->variables['password'], + $this->variables['hostname'] + ); + + $statement = new Statement; + self::assertSame($statement, $statement->initialize($ociResource)); + unset($stmtResource, $ociResource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::getResource + */ + public function testGetResource() + { + $ociResource = oci_connect( + $this->variables['username'], + $this->variables['password'], + $this->variables['hostname'] + ); + + $statement = new Statement; + $statement->initialize($ociResource); + $statement->prepare('SELECT * FROM DUAL'); + $resource = $statement->getResource(); + self::assertEquals('oci8 statement', get_resource_type($resource)); + unset($resource, $ociResource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::prepare + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::isPrepared + */ + public function testPrepare() + { + $ociResource = oci_connect( + $this->variables['username'], + $this->variables['password'], + $this->variables['hostname'] + ); + + $statement = new Statement; + $statement->initialize($ociResource); + self::assertFalse($statement->isPrepared()); + self::assertSame($statement, $statement->prepare('SELECT * FROM DUAL')); + self::assertTrue($statement->isPrepared()); + unset($resource, $ociResource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::execute + */ + public function testExecute() + { + $oci8 = new Oci8($this->variables); + $statement = $oci8->createStatement('SELECT * FROM DUAL'); + self::assertSame($statement, $statement->prepare()); + + $result = $statement->execute(); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Oci8\Result', $result); + + unset($resource, $oci8); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementTest.php new file mode 100644 index 00000000..b563a2c9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Oci8/StatementTest.php @@ -0,0 +1,161 @@ +statement = new Statement; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->statement, $this->statement->setDriver(new Oci8([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::setProfiler + */ + public function testSetProfiler() + { + self::assertEquals($this->statement, $this->statement->setProfiler(new Profiler())); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::getProfiler + */ + public function testGetProfiler() + { + $profiler = new Profiler(); + $this->statement->setProfiler($profiler); + self::assertEquals($profiler, $this->statement->getProfiler()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::initialize + */ + public function testInitialize() + { + $oci8 = new Oci8([]); + self::assertEquals($this->statement, $this->statement->initialize($oci8)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::setSql + */ + public function testSetSql() + { + self::assertEquals($this->statement, $this->statement->setSql('select * from table')); + self::assertEquals('select * from table', $this->statement->getSql()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::setParameterContainer + */ + public function testSetParameterContainer() + { + self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::getParameterContainer + * @todo Implement testGetParameterContainer(). + */ + public function testGetParameterContainer() + { + $container = new ParameterContainer; + $this->statement->setParameterContainer($container); + self::assertSame($container, $this->statement->getParameterContainer()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::getResource + * @todo Implement testGetResource(). + */ + public function testGetResource() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::getSql + * @todo Implement testGetSql(). + */ + public function testGetSql() + { + self::assertEquals($this->statement, $this->statement->setSql('select * from table')); + self::assertEquals('select * from table', $this->statement->getSql()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::prepare + * @todo Implement testPrepare(). + */ + public function testPrepare() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::isPrepared + */ + public function testIsPrepared() + { + self::assertFalse($this->statement->isPrepared()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Oci8\Statement::execute + * @todo Implement testExecute(). + */ + public function testExecute() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php new file mode 100644 index 00000000..80547ad2 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php @@ -0,0 +1,183 @@ + 'sqlite', 'database' => ':memory:']; + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::getCurrentSchema + */ + public function testGetCurrentSchema() + { + $connection = new Connection($this->variables); + self::assertInternalType('string', $connection->getCurrentSchema()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::setResource + */ + public function testSetResource() + { + $resource = new TestAsset\SqliteMemoryPdo(); + $connection = new Connection([]); + self::assertSame($connection, $connection->setResource($resource)); + + $connection->disconnect(); + unset($connection); + unset($resource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::getResource + */ + public function testGetResource() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertInstanceOf('PDO', $connection->getResource()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::connect + */ + public function testConnect() + { + $connection = new Connection($this->variables); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::isConnected + */ + public function testIsConnected() + { + $connection = new Connection($this->variables); + self::assertFalse($connection->isConnected()); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::disconnect + */ + public function testDisconnect() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertTrue($connection->isConnected()); + $connection->disconnect(); + self::assertFalse($connection->isConnected()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::beginTransaction + * @todo Implement testBeginTransaction(). + */ + public function testBeginTransaction() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::commit + * @todo Implement testCommit(). + */ + public function testCommit() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::rollback + * @todo Implement testRollback(). + */ + public function testRollback() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::execute + */ + public function testExecute() + { + $sqlsrv = new Pdo($this->variables); + $connection = $sqlsrv->getConnection(); + + $result = $connection->execute('SELECT \'foo\''); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Pdo\Result', $result); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::prepare + */ + public function testPrepare() + { + $sqlsrv = new Pdo($this->variables); + $connection = $sqlsrv->getConnection(); + + $statement = $connection->prepare('SELECT \'foo\''); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Pdo\Statement', $statement); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::getLastGeneratedValue + */ + public function testGetLastGeneratedValue() + { + $this->markTestIncomplete('Need to create a temporary sequence.'); + $connection = new Connection($this->variables); + $connection->getLastGeneratedValue(); + } + + /** + * @group zf3469 + */ + public function testConnectReturnsConnectionWhenResourceSet() + { + $resource = new TestAsset\SqliteMemoryPdo(); + $connection = new Connection([]); + $connection->setResource($resource); + self::assertSame($connection, $connection->connect()); + + $connection->disconnect(); + unset($connection); + unset($resource); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTest.php new file mode 100644 index 00000000..9987c513 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTest.php @@ -0,0 +1,123 @@ +connection = new Connection(); + } + + /** + * Test getResource method tries to connect to the database, it should never return null + * + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::getResource + */ + public function testResource() + { + $this->expectException('Zend\Db\Adapter\Exception\InvalidConnectionParametersException'); + $this->connection->getResource(); + } + + /** + * Test getConnectedDsn returns a DSN string if it has been set + * + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::getDsn + */ + public function testGetDsn() + { + $dsn = "sqlite::memory:"; + $this->connection->setConnectionParameters(['dsn' => $dsn]); + try { + $this->connection->connect(); + } catch (\Exception $e) { + } + $responseString = $this->connection->getDsn(); + + self::assertEquals($dsn, $responseString); + } + + /** + * @group 2622 + */ + public function testArrayOfConnectionParametersCreatesCorrectDsn() + { + $this->connection->setConnectionParameters([ + 'driver' => 'pdo_mysql', + 'charset' => 'utf8', + 'dbname' => 'foo', + 'port' => '3306', + 'unix_socket' => '/var/run/mysqld/mysqld.sock', + ]); + try { + $this->connection->connect(); + } catch (\Exception $e) { + } + $responseString = $this->connection->getDsn(); + + self::assertStringStartsWith('mysql:', $responseString); + self::assertContains('charset=utf8', $responseString); + self::assertContains('dbname=foo', $responseString); + self::assertContains('port=3306', $responseString); + self::assertContains('unix_socket=/var/run/mysqld/mysqld.sock', $responseString); + } + + public function testHostnameAndUnixSocketThrowsInvalidConnectionParametersException() + { + $this->expectException('Zend\Db\Adapter\Exception\InvalidConnectionParametersException'); + $this->expectExceptionMessage( + 'Ambiguous connection parameters, both hostname and unix_socket parameters were set' + ); + + $this->connection->setConnectionParameters([ + 'driver' => 'pdo_mysql', + 'host' => '127.0.0.1', + 'dbname' => 'foo', + 'port' => '3306', + 'unix_socket' => '/var/run/mysqld/mysqld.sock', + ]); + $this->connection->connect(); + } + + public function testDblibArrayOfConnectionParametersCreatesCorrectDsn() + { + $this->connection->setConnectionParameters([ + 'driver' => 'pdo_dblib', + 'charset' => 'UTF-8', + 'dbname' => 'foo', + 'port' => '1433', + 'version' => '7.3', + ]); + try { + $this->connection->connect(); + } catch (\Exception $e) { + } + $responseString = $this->connection->getDsn(); + + $this->assertStringStartsWith('dblib:', $responseString); + $this->assertContains('charset=UTF-8', $responseString); + $this->assertContains('dbname=foo', $responseString); + $this->assertContains('port=1433', $responseString); + $this->assertContains('version=7.3', $responseString); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php new file mode 100644 index 00000000..1864cb67 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php @@ -0,0 +1,201 @@ +wrapper = new ConnectionWrapper(); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::beginTransaction() + */ + public function testBeginTransactionReturnsInstanceOfConnection() + { + self::assertInstanceOf('\Zend\Db\Adapter\Driver\Pdo\Connection', $this->wrapper->beginTransaction()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::beginTransaction() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::inTransaction() + */ + public function testBeginTransactionSetsInTransactionAtTrue() + { + $this->wrapper->beginTransaction(); + self::assertTrue($this->wrapper->inTransaction()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::commit() + */ + public function testCommitReturnsInstanceOfConnection() + { + $this->wrapper->beginTransaction(); + self::assertInstanceOf('\Zend\Db\Adapter\Driver\Pdo\Connection', $this->wrapper->commit()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::commit() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::inTransaction() + */ + public function testCommitSetsInTransactionAtFalse() + { + $this->wrapper->beginTransaction(); + $this->wrapper->commit(); + self::assertFalse($this->wrapper->inTransaction()); + } + + /** + * Standalone commit after a SET autocommit=0; + * + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::commit() + */ + public function testCommitWithoutBeginReturnsInstanceOfConnection() + { + self::assertInstanceOf('\Zend\Db\Adapter\Driver\Pdo\Connection', $this->wrapper->commit()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::inTransaction() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::beginTransaction() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::commit() + */ + public function testNestedTransactionsCommit() + { + $nested = 0; + + self::assertFalse($this->wrapper->inTransaction()); + + // 1st transaction + $this->wrapper->beginTransaction(); + self::assertTrue($this->wrapper->inTransaction()); + self::assertSame(++ $nested, $this->wrapper->getNestedTransactionsCount()); + + // 2nd transaction + $this->wrapper->beginTransaction(); + self::assertTrue($this->wrapper->inTransaction()); + self::assertSame(++ $nested, $this->wrapper->getNestedTransactionsCount()); + + // 1st commit + $this->wrapper->commit(); + self::assertTrue($this->wrapper->inTransaction()); + self::assertSame(-- $nested, $this->wrapper->getNestedTransactionsCount()); + + // 2nd commit + $this->wrapper->commit(); + self::assertFalse($this->wrapper->inTransaction()); + self::assertSame(-- $nested, $this->wrapper->getNestedTransactionsCount()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::inTransaction() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::beginTransaction() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::rollback() + */ + public function testNestedTransactionsRollback() + { + $nested = 0; + + self::assertFalse($this->wrapper->inTransaction()); + + // 1st transaction + $this->wrapper->beginTransaction(); + self::assertTrue($this->wrapper->inTransaction()); + self::assertSame(++ $nested, $this->wrapper->getNestedTransactionsCount()); + + // 2nd transaction + $this->wrapper->beginTransaction(); + self::assertTrue($this->wrapper->inTransaction()); + self::assertSame(++ $nested, $this->wrapper->getNestedTransactionsCount()); + + // Rollback + $this->wrapper->rollback(); + self::assertFalse($this->wrapper->inTransaction()); + self::assertSame(0, $this->wrapper->getNestedTransactionsCount()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::rollback() + */ + public function testRollbackDisconnectedThrowsException() + { + $this->wrapper->disconnect(); + + $this->expectException('\Zend\Db\Adapter\Exception\RuntimeException'); + $this->expectExceptionMessage('Must be connected before you can rollback'); + $this->wrapper->rollback(); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::rollback() + */ + public function testRollbackReturnsInstanceOfConnection() + { + $this->wrapper->beginTransaction(); + self::assertInstanceOf('\Zend\Db\Adapter\Driver\Pdo\Connection', $this->wrapper->rollback()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::rollback() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::inTransaction() + */ + public function testRollbackSetsInTransactionAtFalse() + { + $this->wrapper->beginTransaction(); + $this->wrapper->rollback(); + self::assertFalse($this->wrapper->inTransaction()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::rollback() + */ + public function testRollbackWithoutBeginThrowsException() + { + $this->expectException('\Zend\Db\Adapter\Exception\RuntimeException'); + $this->expectExceptionMessage('Must call beginTransaction() before you can rollback'); + $this->wrapper->rollback(); + } + + /** + * Standalone commit after a SET autocommit=0; + * + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::inTransaction() + * @covers \Zend\Db\Adapter\Driver\Pdo\Connection::commit() + */ + public function testStandaloneCommit() + { + self::assertFalse($this->wrapper->inTransaction()); + self::assertSame(0, $this->wrapper->getNestedTransactionsCount()); + + $this->wrapper->commit(); + + self::assertFalse($this->wrapper->inTransaction()); + self::assertSame(0, $this->wrapper->getNestedTransactionsCount()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php new file mode 100644 index 00000000..3e0b189b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php @@ -0,0 +1,133 @@ +rowCounter = new OracleRowCounter(); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getName + */ + public function testGetName() + { + self::assertEquals('OracleRowCounter', $this->rowCounter->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getCountForStatement + */ + public function testGetCountForStatement() + { + $statement = $this->getMockStatement('SELECT XXX', 5); + $statement->expects($this->once())->method('prepare') + ->with($this->equalTo('SELECT COUNT(*) as "count" FROM (SELECT XXX)')); + + $count = $this->rowCounter->getCountForStatement($statement); + self::assertEquals(5, $count); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getCountForSql + */ + public function testGetCountForSql() + { + $this->rowCounter->setDriver($this->getMockDriver(5)); + $count = $this->rowCounter->getCountForSql('SELECT XXX'); + self::assertEquals(5, $count); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getRowCountClosure + */ + public function testGetRowCountClosure() + { + $stmt = $this->getMockStatement('SELECT XXX', 5); + + /** @var \Closure $closure */ + $closure = $this->rowCounter->getRowCountClosure($stmt); + self::assertInstanceOf('Closure', $closure); + self::assertEquals(5, $closure()); + } + + protected function getMockStatement($sql, $returnValue) + { + /** @var \Zend\Db\Adapter\Driver\Pdo\Statement|\PHPUnit_Framework_MockObject_MockObject $statement */ + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\Pdo\Statement') + ->setMethods(['prepare', 'execute']) + ->disableOriginalConstructor() + ->getMock(); + + // mock PDOStatement with stdClass + $resource = $this->getMockBuilder('stdClass') + ->setMethods(['fetch']) + ->getMock(); + $resource->expects($this->once()) + ->method('fetch') + ->will($this->returnValue(['count' => $returnValue])); + + // mock the result + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $result->expects($this->once()) + ->method('getResource') + ->will($this->returnValue($resource)); + + $statement->setSql($sql); + $statement->expects($this->once()) + ->method('execute') + ->will($this->returnValue($result)); + + return $statement; + } + + protected function getMockDriver($returnValue) + { + $pdoStatement = $this->getMockBuilder('stdClass') + ->setMethods(['fetch']) + ->disableOriginalConstructor() + ->getMock(); // stdClass can be used here + $pdoStatement->expects($this->once()) + ->method('fetch') + ->will($this->returnValue(['count' => $returnValue])); + + $pdoConnection = $this->getMockBuilder('stdClass') + ->setMethods(['query']) + ->getMock(); + $pdoConnection->expects($this->once()) + ->method('query') + ->will($this->returnValue($pdoStatement)); + + $connection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $connection->expects($this->once()) + ->method('getResource') + ->will($this->returnValue($pdoConnection)); + + $driver = $this->getMockBuilder('Zend\Db\Adapter\Driver\Pdo\Pdo') + ->setMethods(['getConnection']) + ->disableOriginalConstructor() + ->getMock(); + $driver->expects($this->once()) + ->method('getConnection') + ->will($this->returnValue($connection)); + + return $driver; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php new file mode 100644 index 00000000..5823885a --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php @@ -0,0 +1,133 @@ +rowCounter = new SqliteRowCounter(); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getName + */ + public function testGetName() + { + self::assertEquals('SqliteRowCounter', $this->rowCounter->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getCountForStatement + */ + public function testGetCountForStatement() + { + $statement = $this->getMockStatement('SELECT XXX', 5); + $statement->expects($this->once())->method('prepare') + ->with($this->equalTo('SELECT COUNT(*) as "count" FROM (SELECT XXX)')); + + $count = $this->rowCounter->getCountForStatement($statement); + self::assertEquals(5, $count); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getCountForSql + */ + public function testGetCountForSql() + { + $this->rowCounter->setDriver($this->getMockDriver(5)); + $count = $this->rowCounter->getCountForSql('SELECT XXX'); + self::assertEquals(5, $count); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getRowCountClosure + */ + public function testGetRowCountClosure() + { + $stmt = $this->getMockStatement('SELECT XXX', 5); + + /** @var \Closure $closure */ + $closure = $this->rowCounter->getRowCountClosure($stmt); + self::assertInstanceOf('Closure', $closure); + self::assertEquals(5, $closure()); + } + + protected function getMockStatement($sql, $returnValue) + { + /** @var \Zend\Db\Adapter\Driver\Pdo\Statement|\PHPUnit_Framework_MockObject_MockObject $statement */ + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\Pdo\Statement') + ->setMethods(['prepare', 'execute']) + ->disableOriginalConstructor() + ->getMock(); + + // mock PDOStatement with stdClass + $resource = $this->getMockBuilder('stdClass') + ->setMethods(['fetch']) + ->getMock(); + $resource->expects($this->once()) + ->method('fetch') + ->will($this->returnValue(['count' => $returnValue])); + + // mock the result + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $result->expects($this->once()) + ->method('getResource') + ->will($this->returnValue($resource)); + + $statement->setSql($sql); + $statement->expects($this->once()) + ->method('execute') + ->will($this->returnValue($result)); + + return $statement; + } + + protected function getMockDriver($returnValue) + { + $pdoStatement = $this->getMockBuilder('stdClass') + ->setMethods(['fetch']) + ->disableOriginalConstructor() + ->getMock(); // stdClass can be used here + $pdoStatement->expects($this->once()) + ->method('fetch') + ->will($this->returnValue(['count' => $returnValue])); + + $pdoConnection = $this->getMockBuilder('stdClass') + ->setMethods(['query']) + ->getMock(); + $pdoConnection->expects($this->once()) + ->method('query') + ->will($this->returnValue($pdoStatement)); + + $connection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $connection->expects($this->once()) + ->method('getResource') + ->will($this->returnValue($pdoConnection)); + + $driver = $this->getMockBuilder('Zend\Db\Adapter\Driver\Pdo\Pdo') + ->setMethods(['getConnection']) + ->disableOriginalConstructor() + ->getMock(); + $driver->expects($this->once()) + ->method('getConnection') + ->will($this->returnValue($connection)); + + return $driver; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/PdoTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/PdoTest.php new file mode 100644 index 00000000..fb4f08d4 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/PdoTest.php @@ -0,0 +1,87 @@ +pdo = new Pdo([]); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Pdo::getDatabasePlatformName + */ + public function testGetDatabasePlatformName() + { + // Test platform name for SqlServer + $this->pdo->getConnection()->setConnectionParameters(['pdodriver' => 'sqlsrv']); + self::assertEquals('SqlServer', $this->pdo->getDatabasePlatformName()); + self::assertEquals('SQLServer', $this->pdo->getDatabasePlatformName(DriverInterface::NAME_FORMAT_NATURAL)); + } + + public function getParamsAndType() + { + return [ + [ 'foo', null, ':foo' ], + [ 'foo_bar', null, ':foo_bar' ], + [ '123foo', null, ':123foo' ], + [ 1, null, '?' ], + [ '1', null, '?' ], + [ 'foo', Pdo::PARAMETERIZATION_NAMED, ':foo' ], + [ 'foo_bar', Pdo::PARAMETERIZATION_NAMED, ':foo_bar' ], + [ '123foo', Pdo::PARAMETERIZATION_NAMED, ':123foo' ], + [ 1, Pdo::PARAMETERIZATION_NAMED, ':1' ], + [ '1', Pdo::PARAMETERIZATION_NAMED, ':1' ], + [ ':foo', null, ':foo' ], + ]; + } + + /** + * @dataProvider getParamsAndType + */ + public function testFormatParameterName($name, $type, $expected) + { + $result = $this->pdo->formatParameterName($name, $type); + $this->assertEquals($expected, $result); + } + + public function getInvalidParamName() + { + return [ + [ 'foo%' ], + [ 'foo-' ], + [ 'foo$' ], + [ 'foo0!' ] + ]; + } + + /** + * @dataProvider getInvalidParamName + * @expectedException Zend\Db\Exception\RuntimeException + */ + public function testFormatParameterNameWithInvalidCharacters($name) + { + $this->pdo->formatParameterName($name); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ResultTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ResultTest.php new file mode 100644 index 00000000..d806000d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/ResultTest.php @@ -0,0 +1,72 @@ +getMockBuilder('PDOStatement')->getMock(); + $stub->expects($this->any()) + ->method('fetch') + ->will($this->returnCallback(function () { + return uniqid(); + })); + + $result = new Result(); + $result->initialize($stub, null); + + self::assertEquals($result->current(), $result->current()); + } + + public function testFetchModeException() + { + $result = new Result(); + + $this->expectException('\Zend\Db\Adapter\Exception\InvalidArgumentException'); + $result->setFetchMode(11); + } + + /** + * Tests whether the fetch mode was set properly and + */ + public function testFetchModeAnonymousObject() + { + $stub = $this->getMockBuilder('PDOStatement')->getMock(); + $stub->expects($this->any()) + ->method('fetch') + ->will($this->returnCallback(function () { + return new stdClass; + })); + + $result = new Result(); + $result->initialize($stub, null); + $result->setFetchMode(\PDO::FETCH_OBJ); + + self::assertEquals(5, $result->getFetchMode()); + self::assertInstanceOf('stdClass', $result->current()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php new file mode 100644 index 00000000..a25f1286 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php @@ -0,0 +1,74 @@ +getMockBuilder('Zend\Db\Adapter\Driver\Pdo\Pdo') + ->setMethods(['createResult']) + ->disableOriginalConstructor() + ->getMock(); + + $this->statement = new Statement; + $this->statement->setDriver($driver); + $this->statement->initialize(new TestAsset\CtorlessPdo( + $this->pdoStatementMock = $this->getMockBuilder('PDOStatement') + ->setMethods(['execute', 'bindParam']) + ->getMock() + )); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + public function testStatementExecuteWillConvertPhpBoolToPdoBoolWhenBinding() + { + $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( + $this->equalTo(':foo'), + $this->equalTo(false), + $this->equalTo(\PDO::PARAM_BOOL) + ); + $this->statement->execute(['foo' => false]); + } + + public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding() + { + $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( + $this->equalTo(':foo'), + $this->equalTo('bar'), + $this->equalTo(\PDO::PARAM_STR) + ); + $this->statement->execute(['foo' => 'bar']); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementTest.php new file mode 100644 index 00000000..d103b494 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/StatementTest.php @@ -0,0 +1,131 @@ +statement = new Statement; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->statement, $this->statement->setDriver(new Pdo([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::setParameterContainer + */ + public function testSetParameterContainer() + { + self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::getParameterContainer + * @todo Implement testGetParameterContainer(). + */ + public function testGetParameterContainer() + { + $container = new ParameterContainer; + $this->statement->setParameterContainer($container); + self::assertSame($container, $this->statement->getParameterContainer()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::getResource + */ + public function testGetResource() + { + $pdo = new TestAsset\SqliteMemoryPdo(); + $stmt = $pdo->prepare('SELECT 1'); + $this->statement->setResource($stmt); + + self::assertSame($stmt, $this->statement->getResource()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::setSql + */ + public function testSetSql() + { + $this->statement->setSql('SELECT 1'); + self::assertEquals('SELECT 1', $this->statement->getSql()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::getSql + */ + public function testGetSql() + { + $this->statement->setSql('SELECT 1'); + self::assertEquals('SELECT 1', $this->statement->getSql()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::prepare + * @todo Implement testPrepare(). + */ + public function testPrepare() + { + $this->statement->initialize(new TestAsset\SqliteMemoryPdo()); + self::assertNull($this->statement->prepare('SELECT 1')); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::isPrepared + */ + public function testIsPrepared() + { + self::assertFalse($this->statement->isPrepared()); + $this->statement->initialize(new TestAsset\SqliteMemoryPdo()); + $this->statement->prepare('SELECT 1'); + self::assertTrue($this->statement->isPrepared()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pdo\Statement::execute + */ + public function testExecute() + { + $this->statement->setDriver(new Pdo(new Connection($pdo = new TestAsset\SqliteMemoryPdo()))); + $this->statement->initialize($pdo); + $this->statement->prepare('SELECT 1'); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Pdo\Result', $this->statement->execute()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php new file mode 100644 index 00000000..8acc9bc6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php @@ -0,0 +1,25 @@ +mockStatement = $mockStatement; + } + + public function prepare($sql, $options = null) + { + return $this->mockStatement; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php new file mode 100644 index 00000000..b1e28719 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php @@ -0,0 +1,31 @@ +exec($sql)) { + throw new \Exception(sprintf( + "Error: %s, %s", + $this->errorCode(), + implode(",", $this->errorInfo()) + )); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php new file mode 100644 index 00000000..7e5bca4a --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php @@ -0,0 +1,168 @@ +connection = new Connection(); + } + + /** + * Test getResource method if it tries to connect to the database. + * + * @covers \Zend\Db\Adapter\Driver\Pgsql\Connection::getResource + */ + public function testResource() + { + if (! extension_loaded('pgsql')) { + $this->markTestSkipped('pgsql extension not loaded'); + } + + try { + $resource = $this->connection->getResource(); + // connected with empty string + self::assertInternalType('resource', $resource); + } catch (AdapterException\RuntimeException $exc) { + // If it throws an exception it has failed to connect + $this->expectException('Zend\Db\Adapter\Exception\RuntimeException'); + throw $exc; + } + } + + /** + * Test disconnect method to return instance of ConnectionInterface + */ + public function testDisconnect() + { + include_once 'pgsqlMockFunctions.php'; + self::assertSame($this->connection, $this->connection->disconnect()); + } + + /** + * @group 6760 + * @group 6787 + */ + public function testGetConnectionStringEncodeSpecialSymbol() + { + $connectionParameters = [ + 'driver' => 'pgsql', + 'host' => 'localhost', + 'post' => '5432', + 'dbname' => 'test', + 'username' => 'test', + 'password' => 'test123!', + ]; + + $this->connection->setConnectionParameters($connectionParameters); + + $getConnectionString = new ReflectionMethod( + 'Zend\Db\Adapter\Driver\Pgsql\Connection', + 'getConnectionString' + ); + + $getConnectionString->setAccessible(true); + + self::assertEquals( + 'host=localhost user=test password=test123! dbname=test', + $getConnectionString->invoke($this->connection) + ); + } + + public function testSetConnectionTypeException() + { + if (! extension_loaded('pgsql')) { + $this->markTestSkipped('pgsql extension not loaded'); + } + + $this->expectException('\Zend\Db\Adapter\Exception\InvalidArgumentException'); + $this->connection->setType(3); + } + + /** + * Test the connection type setter + */ + public function testSetConnectionType() + { + if (! extension_loaded('pgsql')) { + $this->markTestSkipped('pgsql extension not loaded'); + } + $type = PGSQL_CONNECT_FORCE_NEW; + $this->connection->setType($type); + self::assertEquals($type, self::readAttribute($this->connection, 'type')); + } + + /** + * @runInSeparateProcess + */ + public function testSetCharset() + { + if (! extension_loaded('pgsql')) { + $this->markTestSkipped('pgsql extension not loaded'); + } + + $this->connection->setConnectionParameters([ + 'driver' => 'pgsql', + 'host' => 'localhost', + 'post' => '5432', + 'dbname' => 'zenddb_test', + 'username' => 'postgres', + 'password' => 'postgres', + 'charset' => 'SQL_ASCII', + ]); + + try { + $this->connection->connect(); + } catch (AdapterException\RuntimeException $e) { + $this->markTestSkipped('Skipping pgsql charset test due to inability to connecto to database'); + } + + self::assertEquals('SQL_ASCII', pg_client_encoding($this->connection->getResource())); + } + + /** + * @runInSeparateProcess + */ + public function testSetInvalidCharset() + { + if (! extension_loaded('pgsql')) { + $this->markTestSkipped('pgsql extension not loaded'); + } + + $this->expectException('Zend\Db\Adapter\Exception\RuntimeException'); + + $this->connection->setConnectionParameters([ + 'driver' => 'pgsql', + 'host' => 'localhost', + 'post' => '5432', + 'dbname' => 'zenddb_test', + 'username' => 'postgres', + 'password' => 'postgres', + 'charset' => 'FOOBAR', + ]); + + $this->connection->connect(); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php new file mode 100644 index 00000000..dd921108 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php @@ -0,0 +1,178 @@ +pgsql = new Pgsql([]); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::checkEnvironment + */ + public function testCheckEnvironment() + { + if (! extension_loaded('pgsql')) { + $this->expectException('Zend\Db\Adapter\Exception\RuntimeException'); + } + $this->pgsql->checkEnvironment(); + self::assertTrue(true, 'No exception was thrown'); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::registerConnection + */ + public function testRegisterConnection() + { + $mockConnection = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Pgsql\Connection', + [[]], + '', + true, + true, + true, + ['setDriver'] + ); + $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->pgsql)); + self::assertSame($this->pgsql, $this->pgsql->registerConnection($mockConnection)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::registerStatementPrototype + */ + public function testRegisterStatementPrototype() + { + $this->pgsql = new Pgsql([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Pgsql\Statement', + [], + '', + true, + true, + true, + ['setDriver'] + ); + $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->pgsql)); + self::assertSame($this->pgsql, $this->pgsql->registerStatementPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::registerResultPrototype + */ + public function testRegisterResultPrototype() + { + $this->pgsql = new Pgsql([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Pgsql\Result', + [], + '', + true, + true, + true, + ['setDriver'] + ); + self::assertSame($this->pgsql, $this->pgsql->registerResultPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::getDatabasePlatformName + */ + public function testGetDatabasePlatformName() + { + $this->pgsql = new Pgsql([]); + self::assertEquals('Postgresql', $this->pgsql->getDatabasePlatformName()); + self::assertEquals('PostgreSQL', $this->pgsql->getDatabasePlatformName(Pgsql::NAME_FORMAT_NATURAL)); + } + + /** + * @depends testRegisterConnection + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::getConnection + */ + public function testGetConnection($mockConnection) + { + $conn = new \Zend\Db\Adapter\Driver\Pgsql\Connection([]); + $this->pgsql->registerConnection($conn); + self::assertSame($conn, $this->pgsql->getConnection()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::createStatement + * @todo Implement testGetPrepareType(). + */ + public function testCreateStatement() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::createResult + * @todo Implement testGetPrepareType(). + */ + public function testCreateResult() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::getPrepareType + * @todo Implement testGetPrepareType(). + */ + public function testGetPrepareType() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::formatParameterName + * @todo Implement testFormatParameterName(). + */ + public function testFormatParameterName() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Pgsql\Pgsql::getLastGeneratedValue + * @todo Implement testGetLastGeneratedValue(). + */ + public function testGetLastGeneratedValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php new file mode 100644 index 00000000..40d408cf --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php @@ -0,0 +1,15 @@ + 'TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME', + 'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_USERNAME', + 'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD', + ]; + protected $adapters; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + if (! getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV')) { + $this->markTestSkipped('SQLSRV tests are not enabled'); + } + foreach ($this->variables as $name => $value) { + if (! getenv($value)) { + $this->markTestSkipped( + 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' + ); + } + $this->variables[$name] = getenv($value); + } + + if (! extension_loaded('sqlsrv')) { + $this->fail('The phpunit group integration-sqlsrv was enabled, but the extension is not loaded.'); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php new file mode 100644 index 00000000..92f54bbe --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php @@ -0,0 +1,192 @@ +variables); + self::assertInternalType('string', $connection->getCurrentSchema()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::setResource + */ + public function testSetResource() + { + $resource = sqlsrv_connect( + $this->variables['hostname'], + [ + 'UID' => $this->variables['username'], + 'PWD' => $this->variables['password'], + ] + ); + $connection = new Connection([]); + self::assertSame($connection, $connection->setResource($resource)); + + $connection->disconnect(); + unset($connection); + unset($resource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::getResource + */ + public function testGetResource() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertInternalType('resource', $connection->getResource()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::connect + */ + public function testConnect() + { + $connection = new Connection($this->variables); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::isConnected + */ + public function testIsConnected() + { + $connection = new Connection($this->variables); + self::assertFalse($connection->isConnected()); + self::assertSame($connection, $connection->connect()); + self::assertTrue($connection->isConnected()); + + $connection->disconnect(); + unset($connection); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::disconnect + */ + public function testDisconnect() + { + $connection = new Connection($this->variables); + $connection->connect(); + self::assertTrue($connection->isConnected()); + $connection->disconnect(); + self::assertFalse($connection->isConnected()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::beginTransaction + * @todo Implement testBeginTransaction(). + */ + public function testBeginTransaction() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::commit + * @todo Implement testCommit(). + */ + public function testCommit() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::rollback + * @todo Implement testRollback(). + */ + public function testRollback() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::execute + */ + public function testExecute() + { + $sqlsrv = new Sqlsrv($this->variables); + $connection = $sqlsrv->getConnection(); + + $result = $connection->execute('SELECT \'foo\''); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Result', $result); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::prepare + */ + public function testPrepare() + { + $sqlsrv = new Sqlsrv($this->variables); + $connection = $sqlsrv->getConnection(); + + $statement = $connection->prepare('SELECT \'foo\''); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Statement', $statement); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::getLastGeneratedValue + */ + public function testGetLastGeneratedValue() + { + $this->markTestIncomplete('Need to create a temporary sequence.'); + $connection = new Connection($this->variables); + $connection->getLastGeneratedValue(); + } + + /** + * @group zf3469 + */ + public function testConnectReturnsConnectionWhenResourceSet() + { + $resource = sqlsrv_connect( + $this->variables['hostname'], + [ + 'UID' => $this->variables['username'], + 'PWD' => $this->variables['password'], + ] + ); + $connection = new Connection([]); + $connection->setResource($resource); + self::assertSame($connection, $connection->connect()); + + $connection->disconnect(); + unset($connection); + unset($resource); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php new file mode 100644 index 00000000..d89015c0 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php @@ -0,0 +1,64 @@ +connection = new Connection([]); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->connection, $this->connection->setDriver(new Sqlsrv([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::setConnectionParameters + */ + public function testSetConnectionParameters() + { + self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Connection::getConnectionParameters + */ + public function testGetConnectionParameters() + { + $this->connection->setConnectionParameters(['foo' => 'bar']); + self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php new file mode 100644 index 00000000..7331e2b8 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php @@ -0,0 +1,29 @@ +adapters['pdo_sqlsrv']); + + $stmt = $driver->createStatement('SELECT ? as col_one'); + $result = $stmt->execute(['a']); + $row = $result->current(); + $this->assertEquals('a', $row['col_one']); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php new file mode 100644 index 00000000..d1f5407e --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php @@ -0,0 +1,198 @@ +object = new Result; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::initialize + * @todo Implement testInitialize(). + */ + public function testInitialize() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::buffer + * @todo Implement testBuffer(). + */ + public function testBuffer() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::getResource + * @todo Implement testGetResource(). + */ + public function testGetResource() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::current + * @todo Implement testCurrent(). + */ + public function testCurrent() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::next + * @todo Implement testNext(). + */ + public function testNext() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::key + * @todo Implement testKey(). + */ + public function testKey() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::rewind + * @todo Implement testRewind(). + */ + public function testRewind() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::valid + * @todo Implement testValid(). + */ + public function testValid() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::count + * @todo Implement testCount(). + */ + public function testCount() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::getFieldCount + * @todo Implement testGetFieldCount(). + */ + public function testGetFieldCount() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::isQueryResult + * @todo Implement testIsQueryResult(). + */ + public function testIsQueryResult() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::getAffectedRows + * @todo Implement testGetAffectedRows(). + */ + public function testGetAffectedRows() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Result::getGeneratedValue + * @todo Implement testGetGeneratedValue(). + */ + public function testGetGeneratedValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php new file mode 100644 index 00000000..33f9e5ad --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php @@ -0,0 +1,70 @@ +resource = $this->adapters['sqlsrv']; + $this->driver = new Sqlsrv($this->resource); + } + + /** + * @group integration-sqlserver + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::checkEnvironment + */ + public function testCheckEnvironment() + { + $sqlserver = new Sqlsrv([]); + self::assertNull($sqlserver->checkEnvironment()); + } + + public function testCreateStatement() + { + $stmt = $this->driver->createStatement('SELECT 1'); + $this->assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Statement', $stmt); + $stmt = $this->driver->createStatement($this->resource); + $this->assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Statement', $stmt); + $stmt = $this->driver->createStatement(); + $this->assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Statement', $stmt); + + $this->setExpectedException( + 'Zend\Db\Adapter\Exception\InvalidArgumentException', + 'only accepts an SQL string or a Sqlsrv resource' + ); + $this->driver->createStatement(new \stdClass); + } + + public function testParameterizedQuery() + { + $stmt = $this->driver->createStatement('SELECT ? as col_one'); + $result = $stmt->execute(['a']); + $row = $result->current(); + $this->assertEquals('a', $row['col_one']); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php new file mode 100644 index 00000000..a0782518 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php @@ -0,0 +1,166 @@ +sqlsrv = new Sqlsrv([]); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerConnection + */ + public function testRegisterConnection() + { + $mockConnection = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Sqlsrv\Connection', + [[]], + '', + true, + true, + true, + ['setDriver'] + ); + $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->sqlsrv)); + self::assertSame($this->sqlsrv, $this->sqlsrv->registerConnection($mockConnection)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerStatementPrototype + */ + public function testRegisterStatementPrototype() + { + $this->sqlsrv = new Sqlsrv([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Sqlsrv\Statement', + [], + '', + true, + true, + true, + ['setDriver'] + ); + $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->sqlsrv)); + self::assertSame($this->sqlsrv, $this->sqlsrv->registerStatementPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerResultPrototype + */ + public function testRegisterResultPrototype() + { + $this->sqlsrv = new Sqlsrv([]); + $mockStatement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Sqlsrv\Result', + [], + '', + true, + true, + true, + ['setDriver'] + ); + self::assertSame($this->sqlsrv, $this->sqlsrv->registerResultPrototype($mockStatement)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getDatabasePlatformName + */ + public function testGetDatabasePlatformName() + { + $this->sqlsrv = new Sqlsrv([]); + self::assertEquals('SqlServer', $this->sqlsrv->getDatabasePlatformName()); + self::assertEquals('SQLServer', $this->sqlsrv->getDatabasePlatformName(Sqlsrv::NAME_FORMAT_NATURAL)); + } + + /** + * @depends testRegisterConnection + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getConnection + */ + public function testGetConnection($mockConnection) + { + $conn = new \Zend\Db\Adapter\Driver\Sqlsrv\Connection([]); + $this->sqlsrv->registerConnection($conn); + self::assertSame($conn, $this->sqlsrv->getConnection()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::createStatement + * @todo Implement testGetPrepareType(). + */ + public function testCreateStatement() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::createResult + * @todo Implement testGetPrepareType(). + */ + public function testCreateResult() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getPrepareType + * @todo Implement testGetPrepareType(). + */ + public function testGetPrepareType() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::formatParameterName + * @todo Implement testFormatParameterName(). + */ + public function testFormatParameterName() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getLastGeneratedValue + * @todo Implement testGetLastGeneratedValue(). + */ + public function testGetLastGeneratedValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php new file mode 100644 index 00000000..9769553f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php @@ -0,0 +1,87 @@ +variables['hostname'], + ['UID' => $this->variables['username'], 'PWD' => $this->variables['password']] + ); + + $statement = new Statement; + self::assertSame($statement, $statement->initialize($sqlsrvResource)); + unset($stmtResource, $sqlsrvResource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::getResource + */ + public function testGetResource() + { + $sqlsrvResource = sqlsrv_connect( + $this->variables['hostname'], + ['UID' => $this->variables['username'], 'PWD' => $this->variables['password']] + ); + + $statement = new Statement; + $statement->initialize($sqlsrvResource); + $statement->prepare("SELECT 'foo'"); + $resource = $statement->getResource(); + self::assertEquals('SQL Server Statement', get_resource_type($resource)); + unset($resource, $sqlsrvResource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::prepare + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::isPrepared + */ + public function testPrepare() + { + $sqlsrvResource = sqlsrv_connect( + $this->variables['hostname'], + ['UID' => $this->variables['username'], 'PWD' => $this->variables['password']] + ); + + $statement = new Statement; + $statement->initialize($sqlsrvResource); + self::assertFalse($statement->isPrepared()); + self::assertSame($statement, $statement->prepare("SELECT 'foo'")); + self::assertTrue($statement->isPrepared()); + unset($resource, $sqlsrvResource); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::execute + */ + public function testExecute() + { + $sqlsrv = new Sqlsrv($this->variables); + $statement = $sqlsrv->createStatement("SELECT 'foo'"); + self::assertSame($statement, $statement->prepare()); + + $result = $statement->execute(); + self::assertInstanceOf('Zend\Db\Adapter\Driver\Sqlsrv\Result', $result); + + unset($resource, $sqlsrvResource); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php new file mode 100644 index 00000000..d9d1bbab --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php @@ -0,0 +1,138 @@ +statement = new Statement; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::setDriver + */ + public function testSetDriver() + { + self::assertEquals($this->statement, $this->statement->setDriver(new Sqlsrv([]))); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::setParameterContainer + */ + public function testSetParameterContainer() + { + self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer)); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::getParameterContainer + */ + public function testGetParameterContainer() + { + $container = new ParameterContainer; + $this->statement->setParameterContainer($container); + self::assertSame($container, $this->statement->getParameterContainer()); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::getResource + * @todo Implement testGetResource(). + */ + public function testGetResource() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::setSql + * @todo Implement testSetSql(). + */ + public function testSetSql() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::getSql + * @todo Implement testGetSql(). + */ + public function testGetSql() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::prepare + * @todo Implement testPrepare(). + */ + public function testPrepare() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::isPrepared + * @todo Implement testIsPrepared(). + */ + public function testIsPrepared() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers \Zend\Db\Adapter\Driver\Sqlsrv\Statement::execute + * @todo Implement testExecute(). + */ + public function testExecute() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/TestAsset/PdoMock.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/TestAsset/PdoMock.php new file mode 100644 index 00000000..da77ce79 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Driver/TestAsset/PdoMock.php @@ -0,0 +1,39 @@ +parameterContainer = new ParameterContainer(['foo' => 'bar']); + } + + /** + * @testdox unit test: Test offsetExists() returns proper values via method call and isset() + * @covers \Zend\Db\Adapter\ParameterContainer::offsetExists + */ + public function testOffsetExists() + { + self::assertTrue($this->parameterContainer->offsetExists('foo')); + self::assertTrue(isset($this->parameterContainer['foo'])); + self::assertFalse($this->parameterContainer->offsetExists('bar')); + self::assertFalse(isset($this->parameterContainer['bar'])); + } + + /** + * @testdox unit test: Test offsetGet() returns proper values via method call and array access + * @covers \Zend\Db\Adapter\ParameterContainer::offsetGet + */ + public function testOffsetGet() + { + self::assertEquals('bar', $this->parameterContainer->offsetGet('foo')); + self::assertEquals('bar', $this->parameterContainer['foo']); + + self::assertNull($this->parameterContainer->offsetGet('bar')); + // @todo determine what should come back here + } + + /** + * @testdox unit test: Test offsetSet() works via method call and array access + * @covers \Zend\Db\Adapter\ParameterContainer::offsetSet + */ + public function testOffsetSet() + { + $this->parameterContainer->offsetSet('boo', 'baz'); + self::assertEquals('baz', $this->parameterContainer->offsetGet('boo')); + + $this->parameterContainer->offsetSet('1', 'book', ParameterContainer::TYPE_STRING, 4); + self::assertEquals( + ['foo' => 'bar', 'boo' => 'baz', '1' => 'book'], + $this->parameterContainer->getNamedArray() + ); + + self::assertEquals('string', $this->parameterContainer->offsetGetErrata('1')); + self::assertEquals(4, $this->parameterContainer->offsetGetMaxLength('1')); + + // test that setting an index applies to correct named parameter + $this->parameterContainer[0] = 'Zero'; + $this->parameterContainer[1] = 'One'; + self::assertEquals( + ['foo' => 'Zero', 'boo' => 'One', '1' => 'book'], + $this->parameterContainer->getNamedArray() + ); + self::assertEquals( + [0 => 'Zero', 1 => 'One', 2 => 'book'], + $this->parameterContainer->getPositionalArray() + ); + + // test no-index applies + $this->parameterContainer['buffer'] = 'A buffer Element'; + $this->parameterContainer[] = 'Second To Last'; + $this->parameterContainer[] = 'Last'; + self::assertEquals( + [ + 'foo' => 'Zero', + 'boo' => 'One', + '1' => 'book', + 'buffer' => 'A buffer Element', + '4' => 'Second To Last', + '5' => 'Last', + ], + $this->parameterContainer->getNamedArray() + ); + self::assertEquals( + [0 => 'Zero', 1 => 'One', 2 => 'book', 3 => 'A buffer Element', 4 => 'Second To Last', 5 => 'Last'], + $this->parameterContainer->getPositionalArray() + ); + } + + /** + * @testdox unit test: Test offsetUnset() works via method call and array access + * @covers \Zend\Db\Adapter\ParameterContainer::offsetUnset + */ + public function testOffsetUnset() + { + $this->parameterContainer->offsetSet('boo', 'baz'); + self::assertTrue($this->parameterContainer->offsetExists('boo')); + + + $this->parameterContainer->offsetUnset('boo'); + self::assertFalse($this->parameterContainer->offsetExists('boo')); + } + + /** + * @testdox unit test: Test setFromArray() will populate the container + * @covers \Zend\Db\Adapter\ParameterContainer::setFromArray + */ + public function testSetFromArray() + { + $this->parameterContainer->setFromArray(['bar' => 'baz']); + self::assertEquals('baz', $this->parameterContainer['bar']); + } + + /** + * @testdox unit test: Test offsetSetMaxLength() will persist errata data + * @covers \Zend\Db\Adapter\ParameterContainer::offsetSetMaxLength + * @testdox unit test: Test offsetGetMaxLength() return persisted errata data, if it exists + * @covers \Zend\Db\Adapter\ParameterContainer::offsetGetMaxLength + */ + public function testOffsetSetAndGetMaxLength() + { + $this->parameterContainer->offsetSetMaxLength('foo', 100); + self::assertEquals(100, $this->parameterContainer->offsetGetMaxLength('foo')); + } + + /** + * @testdox unit test: Test offsetHasMaxLength() will check if errata exists for a particular key + * @covers \Zend\Db\Adapter\ParameterContainer::offsetHasMaxLength + */ + public function testOffsetHasMaxLength() + { + $this->parameterContainer->offsetSetMaxLength('foo', 100); + self::assertTrue($this->parameterContainer->offsetHasMaxLength('foo')); + } + + /** + * @testdox unit test: Test offsetUnsetMaxLength() will unset data for a particular key + * @covers \Zend\Db\Adapter\ParameterContainer::offsetUnsetMaxLength + */ + public function testOffsetUnsetMaxLength() + { + $this->parameterContainer->offsetSetMaxLength('foo', 100); + $this->parameterContainer->offsetUnsetMaxLength('foo'); + self::assertNull($this->parameterContainer->offsetGetMaxLength('foo')); + } + + /** + * @testdox unit test: Test getMaxLengthIterator() will return an iterator for the errata data + * @covers \Zend\Db\Adapter\ParameterContainer::getMaxLengthIterator + */ + public function testGetMaxLengthIterator() + { + $this->parameterContainer->offsetSetMaxLength('foo', 100); + $data = $this->parameterContainer->getMaxLengthIterator(); + self::assertInstanceOf('ArrayIterator', $data); + } + + /** + * @testdox unit test: Test offsetSetErrata() will persist errata data + * @covers \Zend\Db\Adapter\ParameterContainer::offsetSetErrata + */ + public function testOffsetSetErrata() + { + $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); + self::assertEquals(ParameterContainer::TYPE_INTEGER, $this->parameterContainer->offsetGetErrata('foo')); + } + + /** + * @testdox unit test: Test offsetGetErrata() return persisted errata data, if it exists + * @covers \Zend\Db\Adapter\ParameterContainer::offsetGetErrata + */ + public function testOffsetGetErrata() + { + $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); + self::assertEquals(ParameterContainer::TYPE_INTEGER, $this->parameterContainer->offsetGetErrata('foo')); + } + + /** + * @testdox unit test: Test offsetHasErrata() will check if errata exists for a particular key + * @covers \Zend\Db\Adapter\ParameterContainer::offsetHasErrata + */ + public function testOffsetHasErrata() + { + $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); + self::assertTrue($this->parameterContainer->offsetHasErrata('foo')); + } + + /** + * @testdox unit test: Test offsetUnsetErrata() will unset data for a particular key + * @covers \Zend\Db\Adapter\ParameterContainer::offsetUnsetErrata + */ + public function testOffsetUnsetErrata() + { + $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); + $this->parameterContainer->offsetUnsetErrata('foo'); + self::assertNull($this->parameterContainer->offsetGetErrata('foo')); + } + + /** + * @testdox unit test: Test getErrataIterator() will return an iterator for the errata data + * @covers \Zend\Db\Adapter\ParameterContainer::getErrataIterator + */ + public function testGetErrataIterator() + { + $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); + $data = $this->parameterContainer->getErrataIterator(); + self::assertInstanceOf('ArrayIterator', $data); + } + + /** + * @testdox unit test: Test getNamedArray() + * @covers \Zend\Db\Adapter\ParameterContainer::getNamedArray + */ + public function testGetNamedArray() + { + $data = $this->parameterContainer->getNamedArray(); + self::assertEquals(['foo' => 'bar'], $data); + } + + /** + * @testdox unit test: Test count() returns the proper count + * @covers \Zend\Db\Adapter\ParameterContainer::count + */ + public function testCount() + { + self::assertEquals(1, $this->parameterContainer->count()); + } + + /** + * @testdox unit test: Test current() returns the current element when used as an iterator + * @covers \Zend\Db\Adapter\ParameterContainer::current + */ + public function testCurrent() + { + $value = $this->parameterContainer->current(); + self::assertEquals('bar', $value); + } + + /** + * @testdox unit test: Test next() increases the pointer when used as an iterator + * @covers \Zend\Db\Adapter\ParameterContainer::next + */ + public function testNext() + { + $this->parameterContainer['bar'] = 'baz'; + $this->parameterContainer->next(); + self::assertEquals('baz', $this->parameterContainer->current()); + } + + /** + * @testdox unit test: Test key() returns the name of the current item's name + * @covers \Zend\Db\Adapter\ParameterContainer::key + */ + public function testKey() + { + self::assertEquals('foo', $this->parameterContainer->key()); + } + + /** + * @testdox unit test: Test valid() returns whether the iterators current position is valid + * @covers \Zend\Db\Adapter\ParameterContainer::valid + */ + public function testValid() + { + self::assertTrue($this->parameterContainer->valid()); + $this->parameterContainer->next(); + self::assertFalse($this->parameterContainer->valid()); + } + + /** + * @testdox unit test: Test rewind() resets the iterators pointer + * @covers \Zend\Db\Adapter\ParameterContainer::rewind + */ + public function testRewind() + { + $this->parameterContainer->offsetSet('bar', 'baz'); + $this->parameterContainer->next(); + self::assertEquals('bar', $this->parameterContainer->key()); + $this->parameterContainer->rewind(); + self::assertEquals('foo', $this->parameterContainer->key()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/IbmDb2Test.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/IbmDb2Test.php new file mode 100644 index 00000000..f3cf7934 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/IbmDb2Test.php @@ -0,0 +1,196 @@ +platform = new IbmDb2; + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::getName + */ + public function testGetName() + { + self::assertEquals('IBM DB2', $this->platform->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::getQuoteIdentifierSymbol + */ + public function testGetQuoteIdentifierSymbol() + { + self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::quoteIdentifier + */ + public function testQuoteIdentifier() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); + + $platform = new IbmDb2(['quote_identifiers' => false]); + self::assertEquals('identifier', $platform->quoteIdentifier('identifier')); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::quoteIdentifierChain + */ + public function testQuoteIdentifierChain() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); + + $platform = new IbmDb2(['quote_identifiers' => false]); + self::assertEquals('identifier', $platform->quoteIdentifierChain('identifier')); + self::assertEquals('identifier', $platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('schema.identifier', $platform->quoteIdentifierChain(['schema', 'identifier'])); + + $platform = new IbmDb2(['identifier_separator' => '\\']); + self::assertEquals('"schema"\"identifier"', $platform->quoteIdentifierChain(['schema', 'identifier'])); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::getQuoteValueSymbol + */ + public function testGetQuoteValueSymbol() + { + self::assertEquals("'", $this->platform->getQuoteValueSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::quoteValue + */ + public function testQuoteValueRaisesNoticeWithoutPlatformSupport() + { + if (! function_exists('db2_escape_string')) { + $this->expectException(Error\Notice::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\IbmDb2 without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + } + $this->platform->quoteValue('value'); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::quoteValue + */ + public function testQuoteValue() + { + self::assertEquals("'value'", @$this->platform->quoteValue('value')); + self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar")); + self::assertEquals( + "'''; DELETE FROM some_table; -- '", + @$this->platform->quoteValue("'; DELETE FROM some_table; -- ") + ); + self::assertEquals( + "'\\''; \nDELETE FROM some_table; -- '", + @$this->platform->quoteValue("\\'; \nDELETE FROM some_table; -- ") + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::quoteTrustedValue + */ + public function testQuoteTrustedValue() + { + self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); + self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); + self::assertEquals( + "'''; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue("'; DELETE FROM some_table; -- ") + ); + self::assertEquals( + "'\\''; \nDELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue("\\'; \nDELETE FROM some_table; -- ") + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::quoteValueList + */ + public function testQuoteValueList() + { + if (! function_exists('db2_escape_string')) { + $this->expectException(Error\Error::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\IbmDb2 without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + } + self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar")); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::getIdentifierSeparator + */ + public function testGetIdentifierSeparator() + { + self::assertEquals('.', $this->platform->getIdentifierSeparator()); + + $platform = new IbmDb2(['identifier_separator' => '\\']); + self::assertEquals('\\', $platform->getIdentifierSeparator()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\IbmDb2::quoteIdentifierInFragment + */ + public function testQuoteIdentifierInFragment() + { + self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); + + $platform = new IbmDb2(['quote_identifiers' => false]); + self::assertEquals('foo.bar', $platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('foo as bar', $platform->quoteIdentifierInFragment('foo as bar')); + + // single char words + self::assertEquals( + '("foo"."bar" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) + ); + + // case insensitive safe words + self::assertEquals( + '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and'] + ) + ); + + // case insensitive safe words in field + self::assertEquals( + '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and', 'bAz'] + ) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/MysqlTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/MysqlTest.php new file mode 100644 index 00000000..a5d8782f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/MysqlTest.php @@ -0,0 +1,242 @@ +platform = new Mysql; + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::getName + */ + public function testGetName() + { + self::assertEquals('MySQL', $this->platform->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::getQuoteIdentifierSymbol + */ + public function testGetQuoteIdentifierSymbol() + { + self::assertEquals('`', $this->platform->getQuoteIdentifierSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::quoteIdentifier + */ + public function testQuoteIdentifier() + { + self::assertEquals('`identifier`', $this->platform->quoteIdentifier('identifier')); + self::assertEquals('`ident``ifier`', $this->platform->quoteIdentifier('ident`ifier')); + self::assertEquals('`namespace:$identifier`', $this->platform->quoteIdentifier('namespace:$identifier')); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::quoteIdentifierChain + */ + public function testQuoteIdentifierChain() + { + self::assertEquals('`identifier`', $this->platform->quoteIdentifierChain('identifier')); + self::assertEquals('`identifier`', $this->platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('`schema`.`identifier`', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); + + self::assertEquals('`ident``ifier`', $this->platform->quoteIdentifierChain('ident`ifier')); + self::assertEquals('`ident``ifier`', $this->platform->quoteIdentifierChain(['ident`ifier'])); + self::assertEquals( + '`schema`.`ident``ifier`', + $this->platform->quoteIdentifierChain(['schema', 'ident`ifier']) + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::getQuoteValueSymbol + */ + public function testGetQuoteValueSymbol() + { + self::assertEquals("'", $this->platform->getQuoteValueSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::quoteValue + */ + public function testQuoteValueRaisesNoticeWithoutPlatformSupport() + { + $this->expectException(Error\Notice::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Mysql without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + $this->platform->quoteValue('value'); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::quoteValue + */ + public function testQuoteValue() + { + self::assertEquals("'value'", @$this->platform->quoteValue('value')); + self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); + self::assertEquals( + '\'\\\'; DELETE FROM some_table; -- \'', + @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') + ); + self::assertEquals( + "'\\\\\\'; DELETE FROM some_table; -- '", + @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::quoteTrustedValue + */ + public function testQuoteTrustedValue() + { + self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); + self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); + self::assertEquals( + '\'\\\'; DELETE FROM some_table; -- \'', + $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') + ); + + // '\\\'; DELETE FROM some_table; -- ' <- actual below + self::assertEquals( + "'\\\\\\'; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::quoteValueList + */ + public function testQuoteValueList() + { + $this->expectException(Error\Error::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Mysql without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::getIdentifierSeparator + */ + public function testGetIdentifierSeparator() + { + self::assertEquals('.', $this->platform->getIdentifierSeparator()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Mysql::quoteIdentifierInFragment + */ + public function testQuoteIdentifierInFragment() + { + self::assertEquals('`foo`.`bar`', $this->platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('`foo` as `bar`', $this->platform->quoteIdentifierInFragment('foo as bar')); + self::assertEquals('`$TableName`.`bar`', $this->platform->quoteIdentifierInFragment('$TableName.bar')); + self::assertEquals( + '`cmis:$TableName` as `cmis:TableAlias`', + $this->platform->quoteIdentifierInFragment('cmis:$TableName as cmis:TableAlias') + ); + + $this->assertEquals( + '`foo-bar`.`bar-foo`', + $this->platform->quoteIdentifierInFragment('foo-bar.bar-foo') + ); + $this->assertEquals( + '`foo-bar` as `bar-foo`', + $this->platform->quoteIdentifierInFragment('foo-bar as bar-foo') + ); + $this->assertEquals( + '`$TableName-$ColumnName`.`bar-foo`', + $this->platform->quoteIdentifierInFragment('$TableName-$ColumnName.bar-foo') + ); + $this->assertEquals( + '`cmis:$TableName-$ColumnName` as `cmis:TableAlias-ColumnAlias`', + $this->platform->quoteIdentifierInFragment('cmis:$TableName-$ColumnName as cmis:TableAlias-ColumnAlias') + ); + + // single char words + self::assertEquals( + '(`foo`.`bar` = `boo`.`baz`)', + $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) + ); + self::assertEquals( + '(`foo`.`bar`=`boo`.`baz`)', + $this->platform->quoteIdentifierInFragment('(foo.bar=boo.baz)', ['(', ')', '=']) + ); + self::assertEquals('`foo`=`bar`', $this->platform->quoteIdentifierInFragment('foo=bar', ['='])); + + $this->assertEquals( + '(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`)', + $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo)', ['(', ')', '=']) + ); + $this->assertEquals( + '(`foo-bar`.`bar-foo`=`boo-baz`.`baz-boo`)', + $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo=boo-baz.baz-boo)', ['(', ')', '=']) + ); + $this->assertEquals( + '`foo-bar`=`bar-foo`', + $this->platform->quoteIdentifierInFragment('foo-bar=bar-foo', ['=']) + ); + + // case insensitive safe words + self::assertEquals( + '(`foo`.`bar` = `boo`.`baz`) AND (`foo`.`baz` = `boo`.`baz`)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and'] + ) + ); + + $this->assertEquals( + '(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`) AND (`foo-baz`.`baz-foo` = `boo-baz`.`baz-boo`)', + $this->platform->quoteIdentifierInFragment( + '(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', + ['(', ')', '=', 'and'] + ) + ); + + // case insensitive safe words in field + self::assertEquals( + '(`foo`.`bar` = `boo`.baz) AND (`foo`.baz = `boo`.baz)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and', 'bAz'] + ) + ); + + // case insensitive safe words in field + $this->assertEquals( + '(`foo-bar`.`bar-foo` = `boo-baz`.baz-boo) AND (`foo-baz`.`baz-foo` = `boo-baz`.baz-boo)', + $this->platform->quoteIdentifierInFragment( + '(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', + ['(', ')', '=', 'and', 'bAz-BOo'] + ) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/OracleTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/OracleTest.php new file mode 100644 index 00000000..ed2d326f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/OracleTest.php @@ -0,0 +1,256 @@ +platform = new Oracle; + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::__construct + */ + public function testContructWithOptions() + { + self::assertEquals('"\'test\'.\'test\'"', $this->platform->quoteIdentifier('"test"."test"')); + $plataform1 = new Oracle(['quote_identifiers' => false]); + self::assertEquals('"test"."test"', $plataform1->quoteIdentifier('"test"."test"')); + $plataform2 = new Oracle(['quote_identifiers' => 'false']); + self::assertEquals('"test"."test"', $plataform2->quoteIdentifier('"test"."test"')); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::__construct + */ + public function testContructWithDriver() + { + $mockDriver = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Oci8\Oci8', + [[]], + '', + true, + true, + true, + [] + ); + $platform = new Oracle([], $mockDriver); + self::assertEquals($mockDriver, $platform->getDriver()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::setDriver + */ + public function testSetDriver() + { + $mockDriver = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\Oci8\Oci8', + [[]], + '', + true, + true, + true, + [] + ); + $platform = $this->platform->setDriver($mockDriver); + self::assertEquals($mockDriver, $platform->getDriver()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::setDriver + */ + public function testSetDriverInvalid() + { + $this->expectException('Zend\Db\Adapter\Exception\InvalidArgumentException'); + $this->expectExceptionMessage( + '$driver must be a Oci8 or Oracle PDO Zend\Db\Adapter\Driver, Oci8 instance, or Oci PDO instance' + ); + $this->platform->setDriver(null); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::getDriver + */ + public function testGetDriver() + { + self::assertNull($this->platform->getDriver()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::getName + */ + public function testGetName() + { + self::assertEquals('Oracle', $this->platform->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::getQuoteIdentifierSymbol + */ + public function testGetQuoteIdentifierSymbol() + { + self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::quoteIdentifier + */ + public function testQuoteIdentifier() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); + + $platform = new Oracle(['quote_identifiers' => false]); + self::assertEquals('identifier', $platform->quoteIdentifier('identifier')); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::quoteIdentifierChain + */ + public function testQuoteIdentifierChain() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); + + $platform = new Oracle(['quote_identifiers' => false]); + self::assertEquals('identifier', $platform->quoteIdentifierChain('identifier')); + self::assertEquals('identifier', $platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('schema.identifier', $platform->quoteIdentifierChain(['schema', 'identifier'])); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::getQuoteValueSymbol + */ + public function testGetQuoteValueSymbol() + { + self::assertEquals("'", $this->platform->getQuoteValueSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::quoteValue + */ + public function testQuoteValueRaisesNoticeWithoutPlatformSupport() + { + $this->expectException(Error\Notice::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Oracle without ' + . 'extension/driver support can introduce security vulnerabilities in a production environment' + ); + $this->platform->quoteValue('value'); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::quoteValue + */ + public function testQuoteValue() + { + self::assertEquals("'value'", @$this->platform->quoteValue('value')); + self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar")); + self::assertEquals( + '\'\'\'; DELETE FROM some_table; -- \'', + @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') + ); + self::assertEquals( + "'\\''; DELETE FROM some_table; -- '", + @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::quoteTrustedValue + */ + public function testQuoteTrustedValue() + { + self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); + self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); + self::assertEquals( + '\'\'\'; DELETE FROM some_table; -- \'', + $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') + ); + + // '\\\'; DELETE FROM some_table; -- ' <- actual below + self::assertEquals( + "'\\''; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::quoteValueList + */ + public function testQuoteValueList() + { + $this->expectException(Error\Error::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Oracle without ' + . 'extension/driver support can introduce security vulnerabilities in a production environment' + ); + self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar")); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::getIdentifierSeparator + */ + public function testGetIdentifierSeparator() + { + self::assertEquals('.', $this->platform->getIdentifierSeparator()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Oracle::quoteIdentifierInFragment + */ + public function testQuoteIdentifierInFragment() + { + self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); + + $platform = new Oracle(['quote_identifiers' => false]); + self::assertEquals('foo.bar', $platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('foo as bar', $platform->quoteIdentifierInFragment('foo as bar')); + + // single char words + self::assertEquals( + '("foo"."bar" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) + ); + + // case insensitive safe words + self::assertEquals( + '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and'] + ) + ); + + // case insensitive safe words in field + self::assertEquals( + '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and', 'bAz'] + ) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/PostgresqlTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/PostgresqlTest.php new file mode 100644 index 00000000..ed0bc01d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/PostgresqlTest.php @@ -0,0 +1,184 @@ +platform = new Postgresql; + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::getName + */ + public function testGetName() + { + self::assertEquals('PostgreSQL', $this->platform->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::getQuoteIdentifierSymbol + */ + public function testGetQuoteIdentifierSymbol() + { + self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::quoteIdentifier + */ + public function testQuoteIdentifier() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); + self::assertEquals( + '"identifier ""with"" double-quotes"', + $this->platform->quoteIdentifier('identifier "with" double-quotes') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::quoteIdentifierChain + */ + public function testQuoteIdentifierChain() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); + self::assertEquals( + '"schema"."identifier ""with"" double-quotes"', + $this->platform->quoteIdentifierChain(['schema', 'identifier "with" double-quotes']) + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::getQuoteValueSymbol + */ + public function testGetQuoteValueSymbol() + { + self::assertEquals("'", $this->platform->getQuoteValueSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::quoteValue + */ + public function testQuoteValueRaisesNoticeWithoutPlatformSupport() + { + $this->expectException(Error\Notice::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Postgresql without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + $this->platform->quoteValue('value'); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::quoteValue + */ + public function testQuoteValue() + { + self::assertEquals("E'value'", @$this->platform->quoteValue('value')); + self::assertEquals("E'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); + self::assertEquals( + 'E\'\\\'; DELETE FROM some_table; -- \'', + @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') + ); + self::assertEquals( + "E'\\\\\\'; DELETE FROM some_table; -- '", + @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::quoteTrustedValue + */ + public function testQuoteTrustedValue() + { + self::assertEquals("E'value'", $this->platform->quoteTrustedValue('value')); + self::assertEquals("E'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); + self::assertEquals( + 'E\'\\\'; DELETE FROM some_table; -- \'', + $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') + ); + + // '\\\'; DELETE FROM some_table; -- ' <- actual below + self::assertEquals( + "E'\\\\\\'; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::quoteValueList + */ + public function testQuoteValueList() + { + $this->expectException(Error\Error::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Postgresql without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + self::assertEquals("'Foo O\'\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::getIdentifierSeparator + */ + public function testGetIdentifierSeparator() + { + self::assertEquals('.', $this->platform->getIdentifierSeparator()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Postgresql::quoteIdentifierInFragment + */ + public function testQuoteIdentifierInFragment() + { + self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); + + // single char words + self::assertEquals( + '("foo"."bar" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) + ); + + // case insensitive safe words + self::assertEquals( + '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and'] + ) + ); + + // case insensitive safe words in field + self::assertEquals( + '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and', 'bAz'] + ) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/Sql92Test.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/Sql92Test.php new file mode 100644 index 00000000..994f95ce --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/Sql92Test.php @@ -0,0 +1,176 @@ +platform = new Sql92; + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::getName + */ + public function testGetName() + { + self::assertEquals('SQL92', $this->platform->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::getQuoteIdentifierSymbol + */ + public function testGetQuoteIdentifierSymbol() + { + self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::quoteIdentifier + */ + public function testQuoteIdentifier() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::quoteIdentifierChain + */ + public function testQuoteIdentifierChain() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::getQuoteValueSymbol + */ + public function testGetQuoteValueSymbol() + { + self::assertEquals("'", $this->platform->getQuoteValueSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::quoteValue + */ + public function testQuoteValueRaisesNoticeWithoutPlatformSupport() + { + $this->expectException(Error\Notice::class); + $this->expectExceptionMessage( + 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities ' + . 'in a production environment.' + ); + $this->platform->quoteValue('value'); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::quoteValue + */ + public function testQuoteValue() + { + self::assertEquals("'value'", @$this->platform->quoteValue('value')); + self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); + self::assertEquals( + '\'\\\'; DELETE FROM some_table; -- \'', + @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') + ); + self::assertEquals( + "'\\\\\\'; DELETE FROM some_table; -- '", + @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::quoteTrustedValue + */ + public function testQuoteTrustedValue() + { + self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); + self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); + self::assertEquals( + '\'\\\'; DELETE FROM some_table; -- \'', + $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') + ); + + // '\\\'; DELETE FROM some_table; -- ' <- actual below + self::assertEquals( + "'\\\\\\'; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::quoteValueList + */ + public function testQuoteValueList() + { + $this->expectException(Error\Error::class); + $this->expectExceptionMessage( + 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities ' + . 'in a production environment.' + ); + self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::getIdentifierSeparator + */ + public function testGetIdentifierSeparator() + { + self::assertEquals('.', $this->platform->getIdentifierSeparator()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sql92::quoteIdentifierInFragment + */ + public function testQuoteIdentifierInFragment() + { + self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); + + // single char words + self::assertEquals( + '("foo"."bar" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) + ); + + // case insensitive safe words + self::assertEquals( + '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and'] + ) + ); + + // case insensitive safe words in field + self::assertEquals( + '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and', 'bAz'] + ) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqlServerTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqlServerTest.php new file mode 100644 index 00000000..975c8e09 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqlServerTest.php @@ -0,0 +1,194 @@ +platform = new SqlServer; + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::getName + */ + public function testGetName() + { + self::assertEquals('SQLServer', $this->platform->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::getQuoteIdentifierSymbol + */ + public function testGetQuoteIdentifierSymbol() + { + self::assertEquals(['[', ']'], $this->platform->getQuoteIdentifierSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::quoteIdentifier + */ + public function testQuoteIdentifier() + { + self::assertEquals('[identifier]', $this->platform->quoteIdentifier('identifier')); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::quoteIdentifierChain + */ + public function testQuoteIdentifierChain() + { + self::assertEquals('[identifier]', $this->platform->quoteIdentifierChain('identifier')); + self::assertEquals('[identifier]', $this->platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('[schema].[identifier]', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::getQuoteValueSymbol + */ + public function testGetQuoteValueSymbol() + { + self::assertEquals("'", $this->platform->getQuoteValueSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::quoteValue + */ + public function testQuoteValueRaisesNoticeWithoutPlatformSupport() + { + $this->expectException(Error\Notice::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\SqlServer without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + $this->platform->quoteValue('value'); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::quoteValue + */ + public function testQuoteValue() + { + self::assertEquals("'value'", @$this->platform->quoteValue('value')); + self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar")); + self::assertEquals( + "'''; DELETE FROM some_table; -- '", + @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') + ); + self::assertEquals( + "'\\''; DELETE FROM some_table; -- '", + @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::quoteTrustedValue + */ + public function testQuoteTrustedValue() + { + self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); + self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); + self::assertEquals( + "'''; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') + ); + self::assertEquals( + "'\\''; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::quoteValueList + */ + public function testQuoteValueList() + { + $this->expectException(Error\Error::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\SqlServer without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar")); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::getIdentifierSeparator + */ + public function testGetIdentifierSeparator() + { + self::assertEquals('.', $this->platform->getIdentifierSeparator()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::quoteIdentifierInFragment + */ + public function testQuoteIdentifierInFragment() + { + self::assertEquals('[foo].[bar]', $this->platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('[foo] as [bar]', $this->platform->quoteIdentifierInFragment('foo as bar')); + + // single char words + self::assertEquals( + '([foo].[bar] = [boo].[baz])', + $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) + ); + + // case insensitive safe words + self::assertEquals( + '([foo].[bar] = [boo].[baz]) AND ([foo].[baz] = [boo].[baz])', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and'] + ) + ); + + // case insensitive safe words in field + self::assertEquals( + '([foo].[bar] = [boo].baz) AND ([foo].baz = [boo].baz)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and', 'bAz'] + ) + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\SqlServer::setDriver + */ + public function testSetDriver() + { + $driver = new Pdo(['pdodriver' => 'sqlsrv']); + $this->platform->setDriver($driver); + } + + public function testPlatformQuotesNullByteCharacter() + { + set_error_handler(function () { + }); + $string = "1\0"; + $value = $this->platform->quoteValue($string); + restore_error_handler(); + self::assertEquals("'1\\000'", $value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqliteTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqliteTest.php new file mode 100644 index 00000000..5e23176c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/SqliteTest.php @@ -0,0 +1,206 @@ +platform = new Sqlite; + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::getName + */ + public function testGetName() + { + self::assertEquals('SQLite', $this->platform->getName()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::getQuoteIdentifierSymbol + */ + public function testGetQuoteIdentifierSymbol() + { + self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteIdentifier + */ + public function testQuoteIdentifier() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteIdentifierChain + */ + public function testQuoteIdentifierChain() + { + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); + self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); + self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::getQuoteValueSymbol + */ + public function testGetQuoteValueSymbol() + { + self::assertEquals("'", $this->platform->getQuoteValueSymbol()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteValue + */ + public function testQuoteValueRaisesNoticeWithoutPlatformSupport() + { + $this->expectException(Error\Notice::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Sqlite without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + $this->platform->quoteValue('value'); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteValue + */ + public function testQuoteValue() + { + self::assertEquals("'value'", @$this->platform->quoteValue('value')); + self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); + self::assertEquals( + '\'\\\'; DELETE FROM some_table; -- \'', + @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') + ); + self::assertEquals( + "'\\\\\\'; DELETE FROM some_table; -- '", + @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteTrustedValue + */ + public function testQuoteTrustedValue() + { + self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); + self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); + self::assertEquals( + '\'\\\'; DELETE FROM some_table; -- \'', + $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') + ); + + // '\\\'; DELETE FROM some_table; -- ' <- actual below + self::assertEquals( + "'\\\\\\'; DELETE FROM some_table; -- '", + $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteValueList + */ + public function testQuoteValueList() + { + $this->expectException(Error\Error::class); + $this->expectExceptionMessage( + 'Attempting to quote a value in Zend\Db\Adapter\Platform\Sqlite without extension/driver support can ' + . 'introduce security vulnerabilities in a production environment' + ); + self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::getIdentifierSeparator + */ + public function testGetIdentifierSeparator() + { + self::assertEquals('.', $this->platform->getIdentifierSeparator()); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteIdentifierInFragment + */ + public function testQuoteIdentifierInFragment() + { + self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); + self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); + + // single char words + self::assertEquals( + '("foo"."bar" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) + ); + + // case insensitive safe words + self::assertEquals( + '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and'] + ) + ); + + // case insensitive safe words in field + self::assertEquals( + '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', + $this->platform->quoteIdentifierInFragment( + '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', + ['(', ')', '=', 'and', 'bAz'] + ) + ); + } + + /** + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteValue + * @covers \Zend\Db\Adapter\Platform\Sqlite::quoteTrustedValue + */ + public function testCanCloseConnectionAfterQuoteValue() + { + // Creating the SQLite database file + $filePath = realpath(__DIR__) . "/_files/sqlite.db"; + if (! file_exists($filePath)) { + touch($filePath); + } + + $driver = new \Zend\Db\Adapter\Driver\Pdo\Pdo([ + 'driver' => 'Pdo_Sqlite', + 'database' => $filePath, + ]); + + $this->platform->setDriver($driver); + + $this->platform->quoteValue("some; random]/ value"); + $this->platform->quoteTrustedValue("some; random]/ value"); + + // Closing the connection so we can delete the file + $driver->getConnection()->disconnect(); + + @unlink($filePath); + + self::assertFileNotExists($filePath); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/_files/.gitkeep b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Platform/_files/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-db/test/unit/Adapter/Profiler/ProfilerTest.php b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Profiler/ProfilerTest.php new file mode 100644 index 00000000..443b33f7 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Adapter/Profiler/ProfilerTest.php @@ -0,0 +1,89 @@ +profiler = new Profiler; + } + + /** + * @covers \Zend\Db\Adapter\Profiler\Profiler::profilerStart + */ + public function testProfilerStart() + { + $ret = $this->profiler->profilerStart('SELECT * FROM FOO'); + self::assertSame($this->profiler, $ret); + $ret = $this->profiler->profilerStart(new StatementContainer()); + self::assertSame($this->profiler, $ret); + + $this->expectException('Zend\Db\Adapter\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('profilerStart takes either a StatementContainer or a string'); + $this->profiler->profilerStart(5); + } + + /** + * @covers \Zend\Db\Adapter\Profiler\Profiler::profilerFinish + */ + public function testProfilerFinish() + { + $this->profiler->profilerStart('SELECT * FROM FOO'); + $ret = $this->profiler->profilerFinish(); + self::assertSame($this->profiler, $ret); + + $profiler = new Profiler; + $this->expectException('Zend\Db\Adapter\Exception\RuntimeException'); + $this->expectExceptionMessage('A profile must be started before profilerFinish can be called'); + $profiler->profilerFinish(); + } + + /** + * @covers \Zend\Db\Adapter\Profiler\Profiler::getLastProfile + */ + public function testGetLastProfile() + { + $this->profiler->profilerStart('SELECT * FROM FOO'); + $this->profiler->profilerFinish(); + $profile = $this->profiler->getLastProfile(); + self::assertEquals('SELECT * FROM FOO', $profile['sql']); + self::assertNull($profile['parameters']); + self::assertInternalType('float', $profile['start']); + self::assertInternalType('float', $profile['end']); + self::assertInternalType('float', $profile['elapse']); + } + + /** + * @covers \Zend\Db\Adapter\Profiler\Profiler::getProfiles + */ + public function testGetProfiles() + { + $this->profiler->profilerStart('SELECT * FROM FOO1'); + $this->profiler->profilerFinish(); + $this->profiler->profilerStart('SELECT * FROM FOO2'); + $this->profiler->profilerFinish(); + + self::assertCount(2, $this->profiler->getProfiles()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/ConfigProviderTest.php b/bundled-libs/zendframework/zend-db/test/unit/ConfigProviderTest.php new file mode 100644 index 00000000..f955bbc6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/ConfigProviderTest.php @@ -0,0 +1,42 @@ + [ + Adapter\AdapterAbstractServiceFactory::class, + ], + 'factories' => [ + Adapter\AdapterInterface::class => Adapter\AdapterServiceFactory::class, + ], + 'aliases' => [ + Adapter\Adapter::class => Adapter\AdapterInterface::class, + ], + ]; + + public function testProvidesExpectedConfiguration() + { + $provider = new ConfigProvider(); + self::assertEquals($this->config, $provider->getDependencyConfig()); + return $provider; + } + + /** + * @depends testProvidesExpectedConfiguration + */ + public function testInvocationProvidesDependencyConfiguration(ConfigProvider $provider) + { + self::assertEquals(['dependencies' => $provider->getDependencyConfig()], $provider()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/AbstractSourceTest.php b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/AbstractSourceTest.php new file mode 100644 index 00000000..5799c57c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/AbstractSourceTest.php @@ -0,0 +1,80 @@ +abstractSourceMock = $this->getMockForAbstractClass( + 'Zend\Db\Metadata\Source\AbstractSource', + [], + '', + false + ); + } + + public function testGetConstraintKeys() + { + $refProp = new \ReflectionProperty($this->abstractSourceMock, 'data'); + $refProp->setAccessible(true); + + // internal data + $data = [ + 'constraint_references' => [ + 'foo_schema' => [ + [ + 'constraint_name' => 'bam_constraint', + 'update_rule' => 'UP', + 'delete_rule' => 'DOWN', + 'referenced_table_name' => 'another_table', + 'referenced_column_name' => 'another_column', + ], + ], + ], + 'constraint_keys' => [ + 'foo_schema' => [ + [ + 'table_name' => 'bar_table', + 'constraint_name' => 'bam_constraint', + 'column_name' => 'a', + 'ordinal_position' => 1, + ], + ], + ], + ]; + + $refProp->setValue($this->abstractSourceMock, $data); + $constraints = $this->abstractSourceMock->getConstraintKeys('bam_constraint', 'bar_table', 'foo_schema'); + self::assertCount(1, $constraints); + + /** + * @var \Zend\Db\Metadata\Object\ConstraintKeyObject $constraintKeyObj + */ + $constraintKeyObj = $constraints[0]; + self::assertInstanceOf('Zend\Db\Metadata\Object\ConstraintKeyObject', $constraintKeyObj); + + // check value object is mapped correctly + self::assertEquals('a', $constraintKeyObj->getColumnName()); + self::assertEquals(1, $constraintKeyObj->getOrdinalPosition()); + self::assertEquals('another_table', $constraintKeyObj->getReferencedTableName()); + self::assertEquals('another_column', $constraintKeyObj->getReferencedColumnName()); + self::assertEquals('UP', $constraintKeyObj->getForeignKeyUpdateRule()); + self::assertEquals('DOWN', $constraintKeyObj->getForeignKeyDeleteRule()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/FactoryTest.php b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/FactoryTest.php new file mode 100644 index 00000000..5d70616d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/FactoryTest.php @@ -0,0 +1,65 @@ +getMockBuilder('Zend\Db\Adapter\Platform\PlatformInterface')->getMock(); + $platform + ->expects($this->any()) + ->method('getName') + ->willReturn($platformName) + ; + + $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->disableOriginalConstructor() + ->getMock() + ; + + $adapter + ->expects($this->any()) + ->method('getPlatform') + ->willReturn($platform) + ; + + return $adapter; + }; + + return [ + // Description => [adapter, expected return class] + 'MySQL' => [$createAdapterForPlatform('MySQL'), 'Zend\Db\Metadata\Source\MysqlMetadata'], + 'SQLServer' => [$createAdapterForPlatform('SQLServer'), 'Zend\Db\Metadata\Source\SqlServerMetadata'], + 'SQLite' => [$createAdapterForPlatform('SQLite'), 'Zend\Db\Metadata\Source\SqliteMetadata'], + 'PostgreSQL' => [$createAdapterForPlatform('PostgreSQL'), 'Zend\Db\Metadata\Source\PostgresqlMetadata'], + 'Oracle' => [$createAdapterForPlatform('Oracle'), 'Zend\Db\Metadata\Source\OracleMetadata'], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/OracleMetadataTest.php b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/OracleMetadataTest.php new file mode 100644 index 00000000..b5dea1fc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/OracleMetadataTest.php @@ -0,0 +1,55 @@ +markTestSkipped('I cannot test without the oci8 extension'); + } + parent::setUp(); + $this->variables['driver'] = 'OCI8'; + $this->adapter = new Adapter($this->variables); + $this->metadata = new OracleMetadata($this->adapter); + } + + public function testGetConstraints() + { + $constraints = $this->metadata->getConstraints(null, 'main'); + self::assertCount(0, $constraints); + self::assertContainsOnlyInstancesOf( + 'Zend\Db\Metadata\Object\ConstraintObject', + $constraints + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/SqliteMetadataTest.php b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/SqliteMetadataTest.php new file mode 100644 index 00000000..fb001a1c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Metadata/Source/SqliteMetadataTest.php @@ -0,0 +1,102 @@ +markTestSkipped('I cannot test without the pdo_sqlite extension'); + } + $this->adapter = new Adapter([ + 'driver' => 'Pdo', + 'dsn' => 'sqlite::memory:', + ]); + $this->metadata = new SqliteMetadata($this->adapter); + } + + public function testGetSchemas() + { + $schemas = $this->metadata->getSchemas(); + self::assertContains('main', $schemas); + self::assertCount(1, $schemas); + } + + public function testGetTableNames() + { + $tables = $this->metadata->getTableNames('main'); + self::assertCount(0, $tables); + } + + public function testGetColumnNames() + { + $columns = $this->metadata->getColumnNames(null, 'main'); + self::assertCount(0, $columns); + } + + public function testGetConstraints() + { + $constraints = $this->metadata->getConstraints(null, 'main'); + self::assertCount(0, $constraints); + self::assertContainsOnlyInstancesOf( + 'Zend\Db\Metadata\Object\ConstraintObject', + $constraints + ); + } + + /** + * @group ZF2-3719 + */ + public function testGetConstraintKeys() + { + $keys = $this->metadata->getConstraintKeys( + null, + null, + 'main' + ); + self::assertCount(0, $keys); + self::assertContainsOnlyInstancesOf( + 'Zend\Db\Metadata\Object\ConstraintKeyObject', + $keys + ); + } + + public function testGetTriggers() + { + $triggers = $this->metadata->getTriggers('main'); + self::assertCount(0, $triggers); + self::assertContainsOnlyInstancesOf( + 'Zend\Db\Metadata\Object\TriggerObject', + $triggers + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetIntegrationTest.php new file mode 100644 index 00000000..bce66a34 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetIntegrationTest.php @@ -0,0 +1,58 @@ +resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::current + */ + public function testCurrentCallsDataSourceCurrentAsManyTimesWithoutBuffer() + { + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $this->resultSet->initialize($result); + $result->expects($this->exactly(3))->method('current')->will($this->returnValue(['foo' => 'bar'])); + $value1 = $this->resultSet->current(); + $value2 = $this->resultSet->current(); + $this->resultSet->current(); + self::assertEquals($value1, $value2); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::current + */ + public function testCurrentCallsDataSourceCurrentOnceWithBuffer() + { + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $this->resultSet->buffer(); + $this->resultSet->initialize($result); + $result->expects($this->once())->method('current')->will($this->returnValue(['foo' => 'bar'])); + $value1 = $this->resultSet->current(); + $value2 = $this->resultSet->current(); + $this->resultSet->current(); + self::assertEquals($value1, $value2); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetTest.php b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetTest.php new file mode 100644 index 00000000..c4bd5753 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/AbstractResultSetTest.php @@ -0,0 +1,271 @@ +resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::initialize + */ + public function testInitialize() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + + self::assertSame($resultSet, $resultSet->initialize([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + + $this->expectException('Zend\Db\ResultSet\Exception\InvalidArgumentException'); + $this->expectExceptionMessage( + 'DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate' + ); + $resultSet->initialize('foo'); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::initialize + */ + public function testInitializeDoesNotCallCount() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $result = $this->getMockForAbstractClass('Zend\Db\Adapter\Driver\ResultInterface'); + $result->expects($this->never())->method('count'); + $resultSet->initialize($result); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::initialize + */ + public function testInitializeWithEmptyArray() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + self::assertSame($resultSet, $resultSet->initialize([])); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::buffer + */ + public function testBuffer() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + self::assertSame($resultSet, $resultSet->buffer()); + + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + $resultSet->next(); // start iterator + $this->expectException('Zend\Db\ResultSet\Exception\RuntimeException'); + $this->expectExceptionMessage('Buffering must be enabled before iteration is started'); + $resultSet->buffer(); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::isBuffered + */ + public function testIsBuffered() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + self::assertFalse($resultSet->isBuffered()); + $resultSet->buffer(); + self::assertTrue($resultSet->isBuffered()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::getDataSource + */ + public function testGetDataSource() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + self::assertInstanceOf('\ArrayIterator', $resultSet->getDataSource()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::getFieldCount + */ + public function testGetFieldCount() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ])); + self::assertEquals(2, $resultSet->getFieldCount()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::next + */ + public function testNext() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + self::assertNull($resultSet->next()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::key + */ + public function testKey() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + $resultSet->next(); + self::assertEquals(1, $resultSet->key()); + $resultSet->next(); + self::assertEquals(2, $resultSet->key()); + $resultSet->next(); + self::assertEquals(3, $resultSet->key()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::current + */ + public function testCurrent() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + self::assertEquals(['id' => 1, 'name' => 'one'], $resultSet->current()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::valid + */ + public function testValid() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + self::assertTrue($resultSet->valid()); + $resultSet->next(); + $resultSet->next(); + $resultSet->next(); + self::assertFalse($resultSet->valid()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::rewind + */ + public function testRewind() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + self::assertNull($resultSet->rewind()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::count + */ + public function testCount() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + self::assertEquals(3, $resultSet->count()); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::toArray + */ + public function testToArray() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + self::assertEquals( + [ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ], + $resultSet->toArray() + ); + } + + /** + * Test multiple iterations with buffer + * @group issue-6845 + */ + public function testBufferIterations() + { + $resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); + $resultSet->initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ['id' => 3, 'name' => 'three'], + ])); + $resultSet->buffer(); + + $data = $resultSet->current(); + self::assertEquals(1, $data['id']); + $resultSet->next(); + $data = $resultSet->current(); + self::assertEquals(2, $data['id']); + + $resultSet->rewind(); + $data = $resultSet->current(); + self::assertEquals(1, $data['id']); + $resultSet->next(); + $data = $resultSet->current(); + self::assertEquals(2, $data['id']); + $resultSet->next(); + $data = $resultSet->current(); + self::assertEquals(3, $data['id']); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetIntegrationTest.php new file mode 100644 index 00000000..7506e1c6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetIntegrationTest.php @@ -0,0 +1,33 @@ +initialize(new \ArrayIterator([ + ['id' => 1, 'name' => 'one'], + ['id' => 2, 'name' => 'two'], + ])); + $hydratingRs->buffer(); + $obj1 = $hydratingRs->current(); + $hydratingRs->rewind(); + $obj2 = $hydratingRs->current(); + self::assertSame($obj1, $obj2); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetTest.php b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetTest.php new file mode 100644 index 00000000..9b28b4ca --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/HydratingResultSetTest.php @@ -0,0 +1,102 @@ +arraySerializableHydratorClass = class_exists(ArraySerializableHydrator::class) + ? ArraySerializableHydrator::class + : ArraySerializable::class; + + $this->classMethodsHydratorClass = class_exists(ClassMethodsHydrator::class) + ? ClassMethodsHydrator::class + : ClassMethods::class; + } + + /** + * @covers \Zend\Db\ResultSet\HydratingResultSet::setObjectPrototype + */ + public function testSetObjectPrototype() + { + $prototype = new \stdClass; + $hydratingRs = new HydratingResultSet; + self::assertSame($hydratingRs, $hydratingRs->setObjectPrototype($prototype)); + } + + /** + * @covers \Zend\Db\ResultSet\HydratingResultSet::getObjectPrototype + */ + public function testGetObjectPrototype() + { + $hydratingRs = new HydratingResultSet; + self::assertInstanceOf('ArrayObject', $hydratingRs->getObjectPrototype()); + } + + /** + * @covers \Zend\Db\ResultSet\HydratingResultSet::setHydrator + */ + public function testSetHydrator() + { + $hydratingRs = new HydratingResultSet; + $hydratorClass = $this->classMethodsHydratorClass; + self::assertSame($hydratingRs, $hydratingRs->setHydrator(new $hydratorClass)); + } + + /** + * @covers \Zend\Db\ResultSet\HydratingResultSet::getHydrator + */ + public function testGetHydrator() + { + $hydratingRs = new HydratingResultSet; + self::assertInstanceOf($this->arraySerializableHydratorClass, $hydratingRs->getHydrator()); + } + + /** + * @covers \Zend\Db\ResultSet\HydratingResultSet::current + */ + public function testCurrent() + { + $hydratingRs = new HydratingResultSet; + $hydratingRs->initialize([ + ['id' => 1, 'name' => 'one'], + ]); + $obj = $hydratingRs->current(); + self::assertInstanceOf('ArrayObject', $obj); + } + + /** + * @covers \Zend\Db\ResultSet\HydratingResultSet::toArray + * @todo Implement testToArray(). + */ + public function testToArray() + { + $hydratingRs = new HydratingResultSet; + $hydratingRs->initialize([ + ['id' => 1, 'name' => 'one'], + ]); + $obj = $hydratingRs->toArray(); + self::assertInternalType('array', $obj); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/ResultSet/ResultSetIntegrationTest.php b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/ResultSetIntegrationTest.php new file mode 100644 index 00000000..b92dcbf9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/ResultSet/ResultSetIntegrationTest.php @@ -0,0 +1,251 @@ +resultSet = new ResultSet; + } + + public function testRowObjectPrototypeIsPopulatedByRowObjectByDefault() + { + $row = $this->resultSet->getArrayObjectPrototype(); + self::assertInstanceOf('ArrayObject', $row); + } + + public function testRowObjectPrototypeIsMutable() + { + $row = new \ArrayObject(); + $this->resultSet->setArrayObjectPrototype($row); + self::assertSame($row, $this->resultSet->getArrayObjectPrototype()); + } + + public function testRowObjectPrototypeMayBePassedToConstructor() + { + $row = new \ArrayObject(); + $resultSet = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, $row); + self::assertSame($row, $resultSet->getArrayObjectPrototype()); + } + + public function testReturnTypeIsObjectByDefault() + { + self::assertEquals(ResultSet::TYPE_ARRAYOBJECT, $this->resultSet->getReturnType()); + } + + public function invalidReturnTypes() + { + return [ + [1], + [1.0], + [true], + ['string'], + [['foo']], + [new stdClass], + ]; + } + + /** + * @dataProvider invalidReturnTypes + */ + public function testSettingInvalidReturnTypeRaisesException($type) + { + $this->expectException('Zend\Db\ResultSet\Exception\InvalidArgumentException'); + new ResultSet(ResultSet::TYPE_ARRAYOBJECT, $type); + } + + public function testDataSourceIsNullByDefault() + { + self::assertNull($this->resultSet->getDataSource()); + } + + public function testCanProvideIteratorAsDataSource() + { + $it = new SplStack; + $this->resultSet->initialize($it); + self::assertSame($it, $this->resultSet->getDataSource()); + } + + public function testCanProvideArrayAsDataSource() + { + $dataSource = [['foo']]; + $this->resultSet->initialize($dataSource); + $this->assertEquals($dataSource[0], (array) $this->resultSet->current()); + + $returnType = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS); + $dataSource = [$returnType]; + $this->resultSet->setArrayObjectPrototype($returnType); + $this->resultSet->initialize($dataSource); + $this->assertEquals($dataSource[0], $this->resultSet->current()); + $this->assertContains($dataSource[0], $this->resultSet); + } + + public function testCanProvideIteratorAggregateAsDataSource() + { + $iteratorAggregate = $this->getMockBuilder('IteratorAggregate') + ->setMethods(['getIterator']) + ->setConstructorArgs([new SplStack]) + ->getMock(); + $iteratorAggregate->expects($this->any())->method('getIterator')->will($this->returnValue($iteratorAggregate)); + $this->resultSet->initialize($iteratorAggregate); + self::assertSame($iteratorAggregate->getIterator(), $this->resultSet->getDataSource()); + } + + /** + * @dataProvider invalidReturnTypes + */ + public function testInvalidDataSourceRaisesException($dataSource) + { + if (is_array($dataSource)) { + // this is valid + return; + } + $this->expectException('Zend\Db\ResultSet\Exception\InvalidArgumentException'); + $this->resultSet->initialize($dataSource); + } + + public function testFieldCountIsZeroWithNoDataSourcePresent() + { + self::assertEquals(0, $this->resultSet->getFieldCount()); + } + + public function getArrayDataSource($count) + { + $array = []; + for ($i = 0; $i < $count; $i++) { + $array[] = [ + 'id' => $i, + 'title' => 'title ' . $i, + ]; + } + return new ArrayIterator($array); + } + + public function testFieldCountRepresentsNumberOfFieldsInARowOfData() + { + $resultSet = new ResultSet(ResultSet::TYPE_ARRAY); + $dataSource = $this->getArrayDataSource(10); + $resultSet->initialize($dataSource); + self::assertEquals(2, $resultSet->getFieldCount()); + } + + public function testWhenReturnTypeIsArrayThenIterationReturnsArrays() + { + $resultSet = new ResultSet(ResultSet::TYPE_ARRAY); + $dataSource = $this->getArrayDataSource(10); + $resultSet->initialize($dataSource); + foreach ($resultSet as $index => $row) { + self::assertEquals($dataSource[$index], $row); + } + } + + public function testWhenReturnTypeIsObjectThenIterationReturnsRowObjects() + { + $dataSource = $this->getArrayDataSource(10); + $this->resultSet->initialize($dataSource); + foreach ($this->resultSet as $index => $row) { + self::assertInstanceOf('ArrayObject', $row); + self::assertEquals($dataSource[$index], $row->getArrayCopy()); + } + } + + public function testCountReturnsCountOfRows() + { + $count = rand(3, 75); + $dataSource = $this->getArrayDataSource($count); + $this->resultSet->initialize($dataSource); + self::assertEquals($count, $this->resultSet->count()); + } + + public function testToArrayRaisesExceptionForRowsThatAreNotArraysOrArrayCastable() + { + $count = rand(3, 75); + $dataSource = $this->getArrayDataSource($count); + foreach ($dataSource as $index => $row) { + $dataSource[$index] = (object) $row; + } + $this->resultSet->initialize($dataSource); + $this->expectException('Zend\Db\ResultSet\Exception\RuntimeException'); + $this->resultSet->toArray(); + } + + public function testToArrayCreatesArrayOfArraysRepresentingRows() + { + $count = rand(3, 75); + $dataSource = $this->getArrayDataSource($count); + $this->resultSet->initialize($dataSource); + $test = $this->resultSet->toArray(); + self::assertEquals($dataSource->getArrayCopy(), $test, var_export($test, 1)); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::current + * @covers \Zend\Db\ResultSet\AbstractResultSet::buffer + */ + public function testCurrentWithBufferingCallsDataSourceCurrentOnce() + { + $mockResult = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $mockResult->expects($this->once())->method('current')->will($this->returnValue(['foo' => 'bar'])); + + $this->resultSet->initialize($mockResult); + $this->resultSet->buffer(); + $this->resultSet->current(); + + // assertion above will fail if this calls datasource current + $this->resultSet->current(); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::current + * @covers \Zend\Db\ResultSet\AbstractResultSet::buffer + */ + public function testBufferCalledAfterIterationThrowsException() + { + $this->resultSet->initialize( + $this->prophesize('Zend\Db\Adapter\Driver\ResultInterface')->reveal() + ); + $this->resultSet->current(); + + $this->expectException('Zend\Db\ResultSet\Exception\RuntimeException'); + $this->expectExceptionMessage('Buffering must be enabled before iteration is started'); + $this->resultSet->buffer(); + } + + /** + * @covers \Zend\Db\ResultSet\AbstractResultSet::current + */ + public function testCurrentReturnsNullForNonExistingValues() + { + $mockResult = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $mockResult->expects($this->once())->method('current')->will($this->returnValue("Not an Array")); + + $this->resultSet->initialize($mockResult); + $this->resultSet->buffer(); + + self::assertNull($this->resultSet->current()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/RowGateway/AbstractRowGatewayTest.php b/bundled-libs/zendframework/zend-db/test/unit/RowGateway/AbstractRowGatewayTest.php new file mode 100644 index 00000000..fca010e0 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/RowGateway/AbstractRowGatewayTest.php @@ -0,0 +1,316 @@ +getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(1)); + $this->mockResult = $mockResult; + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); + $mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); + + // setup mock adapter + $this->mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $this->rowGateway = $this->getMockForAbstractClass('Zend\Db\RowGateway\AbstractRowGateway'); + + $rgPropertyValues = [ + 'primaryKeyColumn' => 'id', + 'table' => 'foo', + 'sql' => new \Zend\Db\Sql\Sql($this->mockAdapter), + ]; + $this->setRowGatewayState($rgPropertyValues); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::offsetSet + */ + public function testOffsetSet() + { + // If we set with an index, both getters should retrieve the same value: + $this->rowGateway['testColumn'] = 'test'; + self::assertEquals('test', $this->rowGateway->testColumn); + self::assertEquals('test', $this->rowGateway['testColumn']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::__set + */ + // @codingStandardsIgnoreStart + public function test__set() + { + // @codingStandardsIgnoreEnd + // If we set with a property, both getters should retrieve the same value: + $this->rowGateway->testColumn = 'test'; + self::assertEquals('test', $this->rowGateway->testColumn); + self::assertEquals('test', $this->rowGateway['testColumn']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::__isset + */ + // @codingStandardsIgnoreStart + public function test__isset() + { + // @codingStandardsIgnoreEnd + // Test isset before and after assigning to a property: + self::assertFalse(isset($this->rowGateway->foo)); + $this->rowGateway->foo = 'bar'; + self::assertTrue(isset($this->rowGateway->foo)); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::offsetExists + */ + public function testOffsetExists() + { + // Test isset before and after assigning to an index: + self::assertFalse(isset($this->rowGateway['foo'])); + $this->rowGateway['foo'] = 'bar'; + self::assertTrue(isset($this->rowGateway['foo'])); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::__unset + */ + // @codingStandardsIgnoreStart + public function test__unset() + { + // @codingStandardsIgnoreEnd + $this->rowGateway->foo = 'bar'; + self::assertEquals('bar', $this->rowGateway->foo); + unset($this->rowGateway->foo); + self::assertEmpty($this->rowGateway->foo); + self::assertEmpty($this->rowGateway['foo']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::offsetUnset + */ + public function testOffsetUnset() + { + $this->rowGateway['foo'] = 'bar'; + self::assertEquals('bar', $this->rowGateway['foo']); + unset($this->rowGateway['foo']); + self::assertEmpty($this->rowGateway->foo); + self::assertEmpty($this->rowGateway['foo']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::offsetGet + */ + public function testOffsetGet() + { + // If we set with an index, both getters should retrieve the same value: + $this->rowGateway['testColumn'] = 'test'; + self::assertEquals('test', $this->rowGateway->testColumn); + self::assertEquals('test', $this->rowGateway['testColumn']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::__get + */ + // @codingStandardsIgnoreStart + public function test__get() + { + // @codingStandardsIgnoreEnd + // If we set with a property, both getters should retrieve the same value: + $this->rowGateway->testColumn = 'test'; + self::assertEquals('test', $this->rowGateway->testColumn); + self::assertEquals('test', $this->rowGateway['testColumn']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::save + */ + public function testSaveInsert() + { + // test insert + $this->mockResult->expects($this->any())->method('current') + ->will($this->returnValue(['id' => 5, 'name' => 'foo'])); + $this->mockResult->expects($this->any())->method('getGeneratedValue')->will($this->returnValue(5)); + $this->rowGateway->populate(['name' => 'foo']); + $this->rowGateway->save(); + self::assertEquals(5, $this->rowGateway->id); + self::assertEquals(5, $this->rowGateway['id']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::save + */ + public function testSaveInsertMultiKey() + { + $this->rowGateway = $this->getMockForAbstractClass('Zend\Db\RowGateway\AbstractRowGateway'); + + $mockSql = $this->getMockForAbstractClass('Zend\Db\Sql\Sql', [$this->mockAdapter]); + + $rgPropertyValues = [ + 'primaryKeyColumn' => ['one', 'two'], + 'table' => 'foo', + 'sql' => $mockSql, + ]; + $this->setRowGatewayState($rgPropertyValues); + + // test insert + $this->mockResult->expects($this->any())->method('current') + ->will($this->returnValue(['one' => 'foo', 'two' => 'bar'])); + + // @todo Need to assert that $where was filled in + + $refRowGateway = new \ReflectionObject($this->rowGateway); + $refRowGatewayProp = $refRowGateway->getProperty('primaryKeyData'); + $refRowGatewayProp->setAccessible(true); + + $this->rowGateway->populate(['one' => 'foo', 'two' => 'bar']); + + self::assertNull($refRowGatewayProp->getValue($this->rowGateway)); + + // save should setup the primaryKeyData + $this->rowGateway->save(); + + self::assertEquals(['one' => 'foo', 'two' => 'bar'], $refRowGatewayProp->getValue($this->rowGateway)); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::save + */ + public function testSaveUpdate() + { + // test update + $this->mockResult->expects($this->any())->method('current') + ->will($this->returnValue(['id' => 6, 'name' => 'foo'])); + $this->rowGateway->populate(['id' => 6, 'name' => 'foo'], true); + $this->rowGateway->save(); + self::assertEquals(6, $this->rowGateway['id']); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::save + */ + public function testSaveUpdateChangingPrimaryKey() + { + // this mock is the select to be used to re-fresh the rowobject's data + $selectMock = $this->getMockBuilder('Zend\Db\Sql\Select') + ->setMethods(['where']) + ->getMock(); + $selectMock->expects($this->once()) + ->method('where') + ->with($this->equalTo(['id' => 7])) + ->will($this->returnValue($selectMock)); + + $sqlMock = $this->getMockBuilder('Zend\Db\Sql\Sql') + ->setMethods(['select']) + ->setConstructorArgs([$this->mockAdapter]) + ->getMock(); + $sqlMock->expects($this->any()) + ->method('select') + ->will($this->returnValue($selectMock)); + + $this->setRowGatewayState(['sql' => $sqlMock]); + + // original mock returning updated data + $this->mockResult->expects($this->any()) + ->method('current') + ->will($this->returnValue(['id' => 7, 'name' => 'fooUpdated'])); + + // populate forces an update in save(), seeds with original data (from db) + $this->rowGateway->populate(['id' => 6, 'name' => 'foo'], true); + $this->rowGateway->id = 7; + $this->rowGateway->save(); + self::assertEquals(['id' => 7, 'name' => 'fooUpdated'], $this->rowGateway->toArray()); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::delete + */ + public function testDelete() + { + $this->rowGateway->foo = 'bar'; + $affectedRows = $this->rowGateway->delete(); + self::assertFalse($this->rowGateway->rowExistsInDatabase()); + self::assertEquals(1, $affectedRows); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::populate + * @covers \Zend\Db\RowGateway\RowGateway::rowExistsInDatabase + */ + public function testPopulate() + { + $this->rowGateway->populate(['id' => 5, 'name' => 'foo']); + self::assertEquals(5, $this->rowGateway['id']); + self::assertEquals('foo', $this->rowGateway['name']); + self::assertFalse($this->rowGateway->rowExistsInDatabase()); + + $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); + self::assertTrue($this->rowGateway->rowExistsInDatabase()); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::processPrimaryKeyData + */ + public function testProcessPrimaryKeyData() + { + $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); + + $this->expectException('Zend\Db\RowGateway\Exception\RuntimeException'); + $this->expectExceptionMessage('a known key id was not found'); + $this->rowGateway->populate(['boo' => 5, 'name' => 'foo'], true); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::count + */ + public function testCount() + { + $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); + self::assertEquals(2, $this->rowGateway->count()); + } + + /** + * @covers \Zend\Db\RowGateway\RowGateway::toArray + */ + public function testToArray() + { + $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); + self::assertEquals(['id' => 5, 'name' => 'foo'], $this->rowGateway->toArray()); + } + + protected function setRowGatewayState(array $properties) + { + $refRowGateway = new \ReflectionObject($this->rowGateway); + foreach ($properties as $rgPropertyName => $rgPropertyValue) { + $refRowGatewayProp = $refRowGateway->getProperty($rgPropertyName); + $refRowGatewayProp->setAccessible(true); + $refRowGatewayProp->setValue($this->rowGateway, $rgPropertyValue); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/RowGateway/RowGatewayTest.php b/bundled-libs/zendframework/zend-db/test/unit/RowGateway/RowGatewayTest.php new file mode 100644 index 00000000..a358f513 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/RowGateway/RowGatewayTest.php @@ -0,0 +1,49 @@ +getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(1)); + $this->mockResult = $mockResult; + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); + + $mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); + + // setup mock adapter + $this->mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + } + + public function testEmptyPrimaryKey() + { + $this->expectException('Zend\Db\RowGateway\Exception\RuntimeException'); + $this->expectExceptionMessage('This row object does not have a primary key column set.'); + $this->rowGateway = new RowGateway('', 'foo', $this->mockAdapter); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/AbstractSqlTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/AbstractSqlTest.php new file mode 100644 index 00000000..3f2bd4d4 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/AbstractSqlTest.php @@ -0,0 +1,187 @@ +abstractSql = $this->getMockForAbstractClass('Zend\Db\Sql\AbstractSql'); + + $this->mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $this->mockDriver + ->expects($this->any()) + ->method('getPrepareType') + ->will($this->returnValue(DriverInterface::PARAMETERIZATION_NAMED)); + $this->mockDriver + ->expects($this->any()) + ->method('formatParameterName') + ->will($this->returnCallback(function ($x) { + return ':' . $x; + })); + } + + /** + * @covers \Zend\Db\Sql\AbstractSql::processExpression + */ + public function testProcessExpressionWithoutParameterContainer() + { + $expression = new Expression('? > ? AND y < ?', ['x', 5, 10], [Expression::TYPE_IDENTIFIER]); + $sqlAndParams = $this->invokeProcessExpressionMethod($expression); + + self::assertEquals("\"x\" > '5' AND y < '10'", $sqlAndParams); + } + + /** + * @covers \Zend\Db\Sql\AbstractSql::processExpression + */ + public function testProcessExpressionWithParameterContainerAndParameterizationTypeNamed() + { + $parameterContainer = new ParameterContainer; + $expression = new Expression('? > ? AND y < ?', ['x', 5, 10], [Expression::TYPE_IDENTIFIER]); + $sqlAndParams = $this->invokeProcessExpressionMethod($expression, $parameterContainer); + + $parameters = $parameterContainer->getNamedArray(); + + self::assertRegExp('#"x" > :expr\d\d\d\dParam1 AND y < :expr\d\d\d\dParam2#', $sqlAndParams); + + // test keys and values + preg_match('#expr(\d\d\d\d)Param1#', key($parameters), $matches); + $expressionNumber = $matches[1]; + + self::assertRegExp('#expr\d\d\d\dParam1#', key($parameters)); + self::assertEquals(5, current($parameters)); + next($parameters); + self::assertRegExp('#expr\d\d\d\dParam2#', key($parameters)); + self::assertEquals(10, current($parameters)); + + // ensure next invocation increases number by 1 + $parameterContainer = new ParameterContainer; + $sqlAndParamsNext = $this->invokeProcessExpressionMethod($expression, $parameterContainer); + + $parameters = $parameterContainer->getNamedArray(); + + preg_match('#expr(\d\d\d\d)Param1#', key($parameters), $matches); + $expressionNumberNext = $matches[1]; + + self::assertEquals(1, (int) $expressionNumberNext - (int) $expressionNumber); + } + + /** + * @covers \Zend\Db\Sql\AbstractSql::processExpression + */ + public function testProcessExpressionWorksWithExpressionContainingStringParts() + { + $expression = new Predicate\Expression('x = ?', 5); + + $predicateSet = new Predicate\PredicateSet([new Predicate\PredicateSet([$expression])]); + $sqlAndParams = $this->invokeProcessExpressionMethod($predicateSet); + + self::assertEquals("(x = '5')", $sqlAndParams); + } + + /** + * @covers \Zend\Db\Sql\AbstractSql::processExpression + */ + public function testProcessExpressionWorksWithExpressionContainingSelectObject() + { + $select = new Select(); + $select->from('x')->where->like('bar', 'Foo%'); + $expression = new Predicate\In('x', $select); + + $predicateSet = new Predicate\PredicateSet([new Predicate\PredicateSet([$expression])]); + $sqlAndParams = $this->invokeProcessExpressionMethod($predicateSet); + + self::assertEquals('("x" IN (SELECT "x".* FROM "x" WHERE "bar" LIKE \'Foo%\'))', $sqlAndParams); + } + + public function testProcessExpressionWorksWithExpressionContainingExpressionObject() + { + $expression = new Predicate\Operator( + 'release_date', + '=', + new Expression('FROM_UNIXTIME(?)', 100000000) + ); + + $sqlAndParams = $this->invokeProcessExpressionMethod($expression); + self::assertEquals('"release_date" = FROM_UNIXTIME(\'100000000\')', $sqlAndParams); + } + + /** + * @group 7407 + */ + public function testProcessExpressionWorksWithExpressionObjectWithPercentageSigns() + { + $expressionString = 'FROM_UNIXTIME(date, "%Y-%m")'; + $expression = new Expression($expressionString); + $sqlString = $this->invokeProcessExpressionMethod($expression); + + self::assertSame($expressionString, $sqlString); + } + + public function testProcessExpressionWorksWithNamedParameterPrefix() + { + $parameterContainer = new ParameterContainer(); + $namedParameterPrefix = uniqid(); + $expression = new Expression('FROM_UNIXTIME(?)', [10000000]); + $this->invokeProcessExpressionMethod($expression, $parameterContainer, $namedParameterPrefix); + + self::assertSame($namedParameterPrefix . '1', key($parameterContainer->getNamedArray())); + } + + public function testProcessExpressionWorksWithNamedParameterPrefixContainingWhitespace() + { + $parameterContainer = new ParameterContainer(); + $namedParameterPrefix = "string\ncontaining white space"; + $expression = new Expression('FROM_UNIXTIME(?)', [10000000]); + $this->invokeProcessExpressionMethod($expression, $parameterContainer, $namedParameterPrefix); + + self::assertSame('string__containing__white__space1', key($parameterContainer->getNamedArray())); + } + + /** + * @param \Zend\Db\Sql\ExpressionInterface $expression + * @param \Zend\Db\Adapter\ParameterContainer $parameterContainer + * @param string $namedParameterPrefix + * @return \Zend\Db\Adapter\StatementContainer|string + */ + protected function invokeProcessExpressionMethod( + ExpressionInterface $expression, + $parameterContainer = null, + $namedParameterPrefix = null + ) { + $method = new \ReflectionMethod($this->abstractSql, 'processExpression'); + $method->setAccessible(true); + return $method->invoke( + $this->abstractSql, + $expression, + new TrustingSql92Platform, + $this->mockDriver, + $parameterContainer, + $namedParameterPrefix + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/CombineTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/CombineTest.php new file mode 100644 index 00000000..c844dee4 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/CombineTest.php @@ -0,0 +1,213 @@ +combine = new Combine; + } + + public function testRejectsInvalidStatement() + { + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + + $this->combine->combine('foo'); + } + + public function testGetSqlString() + { + $this->combine + ->union(new Select('t1')) + ->intersect(new Select('t2')) + ->except(new Select('t3')) + ->union(new Select('t4')); + + self::assertEquals( + // @codingStandardsIgnoreStart + '(SELECT "t1".* FROM "t1") INTERSECT (SELECT "t2".* FROM "t2") EXCEPT (SELECT "t3".* FROM "t3") UNION (SELECT "t4".* FROM "t4")', + // @codingStandardsIgnoreEnd + $this->combine->getSqlString() + ); + } + + public function testGetSqlStringWithModifier() + { + $this->combine + ->union(new Select('t1')) + ->union(new Select('t2'), 'ALL'); + + self::assertEquals( + '(SELECT "t1".* FROM "t1") UNION ALL (SELECT "t2".* FROM "t2")', + $this->combine->getSqlString() + ); + } + + public function testGetSqlStringFromArray() + { + $this->combine->combine([ + [new Select('t1')], + [new Select('t2'), Combine::COMBINE_INTERSECT, 'ALL'], + [new Select('t3'), Combine::COMBINE_EXCEPT], + ]); + + self::assertEquals( + '(SELECT "t1".* FROM "t1") INTERSECT ALL (SELECT "t2".* FROM "t2") EXCEPT (SELECT "t3".* FROM "t3")', + $this->combine->getSqlString() + ); + + $this->combine = new Combine(); + $this->combine->combine([ + new Select('t1'), + new Select('t2'), + new Select('t3'), + ]); + + self::assertEquals( + '(SELECT "t1".* FROM "t1") UNION (SELECT "t2".* FROM "t2") UNION (SELECT "t3".* FROM "t3")', + $this->combine->getSqlString() + ); + } + + public function testGetSqlStringEmpty() + { + self::assertNull($this->combine->getSqlString()); + } + + public function testPrepareStatementWithModifier() + { + $select1 = new Select('t1'); + $select1->where(['x1' => 10]); + $select2 = new Select('t2'); + $select2->where(['x2' => 20]); + + $this->combine->combine([ + $select1, + $select2, + ]); + + $adapter = $this->getMockAdapter(); + + $statement = $this->combine->prepareStatement($adapter, new StatementContainer); + self::assertInstanceOf('Zend\Db\Adapter\StatementContainerInterface', $statement); + self::assertEquals( + '(SELECT "t1".* FROM "t1" WHERE "x1" = ?) UNION (SELECT "t2".* FROM "t2" WHERE "x2" = ?)', + $statement->getSql() + ); + } + + public function testAlignColumns() + { + $select1 = new Select('t1'); + $select1->columns([ + 'c0' => 'c0', + 'c1' => 'c1', + ]); + $select2 = new Select('t2'); + $select2->columns([ + 'c1' => 'c1', + 'c2' => 'c2', + ]); + + $this->combine + ->union([$select1, $select2]) + ->alignColumns(); + + self::assertEquals( + [ + 'c0' => 'c0', + 'c1' => 'c1', + 'c2' => new Expression('NULL'), + ], + $select1->getRawState('columns') + ); + + self::assertEquals( + [ + 'c0' => new Expression('NULL'), + 'c1' => 'c1', + 'c2' => 'c2', + ], + $select2->getRawState('columns') + ); + } + + public function testGetRawState() + { + $select = new Select('t1'); + $this->combine->combine($select); + self::assertSame( + [ + 'combine' => [ + [ + 'select' => $select, + 'type' => Combine::COMBINE_UNION, + 'modifier' => '', + ], + ], + 'columns' => [ + '0' => '*', + ], + ], + $this->combine->getRawState() + ); + } + + /** + * + * @return \PHPUnit_Framework_MockObject_MockObject|\Zend\Db\Adapter\Adapter + */ + protected function getMockAdapter() + { + $parameterContainer = new ParameterContainer(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + + $setGetSqlFunction = function ($sql = null) use ($mockStatement) { + static $sqlValue; + if ($sql) { + $sqlValue = $sql; + return $mockStatement; + } + return $sqlValue; + }; + $mockStatement->expects($this->any())->method('setSql')->will($this->returnCallback($setGetSqlFunction)); + $mockStatement->expects($this->any())->method('getSql')->will($this->returnCallback($setGetSqlFunction)); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + + return $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/AlterTableTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/AlterTableTest.php new file mode 100644 index 00000000..1bd618b6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/AlterTableTest.php @@ -0,0 +1,122 @@ +getRawState('table')); + self::assertSame($at, $at->setTable('test')); + self::assertEquals('test', $at->getRawState('table')); + } + + /** + * @covers \Zend\Db\Sql\Ddl\AlterTable::addColumn + */ + public function testAddColumn() + { + $at = new AlterTable(); + /** @var \Zend\Db\Sql\Ddl\Column\ColumnInterface $colMock */ + $colMock = $this->getMockBuilder('Zend\Db\Sql\Ddl\Column\ColumnInterface')->getMock(); + self::assertSame($at, $at->addColumn($colMock)); + self::assertEquals([$colMock], $at->getRawState($at::ADD_COLUMNS)); + } + + /** + * @covers \Zend\Db\Sql\Ddl\AlterTable::changeColumn + */ + public function testChangeColumn() + { + $at = new AlterTable(); + /** @var \Zend\Db\Sql\Ddl\Column\ColumnInterface $colMock */ + $colMock = $this->getMockBuilder('Zend\Db\Sql\Ddl\Column\ColumnInterface')->getMock(); + self::assertSame($at, $at->changeColumn('newname', $colMock)); + self::assertEquals(['newname' => $colMock], $at->getRawState($at::CHANGE_COLUMNS)); + } + + /** + * @covers \Zend\Db\Sql\Ddl\AlterTable::dropColumn + */ + public function testDropColumn() + { + $at = new AlterTable(); + self::assertSame($at, $at->dropColumn('foo')); + self::assertEquals(['foo'], $at->getRawState($at::DROP_COLUMNS)); + } + + /** + * @covers \Zend\Db\Sql\Ddl\AlterTable::dropConstraint + */ + public function testDropConstraint() + { + $at = new AlterTable(); + self::assertSame($at, $at->dropConstraint('foo')); + self::assertEquals(['foo'], $at->getRawState($at::DROP_CONSTRAINTS)); + } + + /** + * @covers \Zend\Db\Sql\Ddl\AlterTable::addConstraint + */ + public function testAddConstraint() + { + $at = new AlterTable(); + /** @var \Zend\Db\Sql\Ddl\Constraint\ConstraintInterface $conMock */ + $conMock = $this->getMockBuilder('Zend\Db\Sql\Ddl\Constraint\ConstraintInterface')->getMock(); + self::assertSame($at, $at->addConstraint($conMock)); + self::assertEquals([$conMock], $at->getRawState($at::ADD_CONSTRAINTS)); + } + + /** + * @covers \Zend\Db\Sql\Ddl\AlterTable::getSqlString + * @todo Implement testGetSqlString(). + */ + public function testGetSqlString() + { + $at = new AlterTable('foo'); + $at->addColumn(new Column\Varchar('another', 255)); + $at->changeColumn('name', new Column\Varchar('new_name', 50)); + $at->dropColumn('foo'); + $at->addConstraint(new Constraint\ForeignKey('my_fk', 'other_id', 'other_table', 'id', 'CASCADE', 'CASCADE')); + $at->dropConstraint('my_index'); + $expected = <<getSqlString(); + self::assertEquals( + str_replace(["\r", "\n"], "", $expected), + str_replace(["\r", "\n"], "", $actual) + ); + + $at = new AlterTable(new TableIdentifier('foo')); + $at->addColumn(new Column\Column('bar')); + $this->assertEquals("ALTER TABLE \"foo\"\n ADD COLUMN \"bar\" INTEGER NOT NULL", $at->getSqlString()); + + $at = new AlterTable(new TableIdentifier('bar', 'foo')); + $at->addColumn(new Column\Column('baz')); + $this->assertEquals("ALTER TABLE \"foo\".\"bar\"\n ADD COLUMN \"baz\" INTEGER NOT NULL", $at->getSqlString()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php new file mode 100644 index 00000000..4ac3deaf --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractLengthColumnTest.php @@ -0,0 +1,48 @@ +getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractLengthColumn', ['foo', 55]); + self::assertEquals(55, $column->getLength()); + self::assertSame($column, $column->setLength(20)); + self::assertEquals(20, $column->getLength()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\AbstractLengthColumn::getLength + */ + public function testGetLength() + { + $column = $this->getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractLengthColumn', ['foo', 55]); + self::assertEquals(55, $column->getLength()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\AbstractLengthColumn::getExpressionData + */ + public function testGetExpressionData() + { + $column = $this->getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractLengthColumn', ['foo', 4]); + + self::assertEquals( + [['%s %s NOT NULL', ['foo', 'INTEGER(4)'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]], + $column->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php new file mode 100644 index 00000000..f81f7c8a --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/AbstractPrecisionColumnTest.php @@ -0,0 +1,68 @@ +getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn', ['foo', 10]); + self::assertEquals(10, $column->getDigits()); + self::assertSame($column, $column->setDigits(12)); + self::assertEquals(12, $column->getDigits()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn::getDigits + */ + public function testGetDigits() + { + $column = $this->getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn', ['foo', 10]); + self::assertEquals(10, $column->getDigits()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn::setDecimal + */ + public function testSetDecimal() + { + $column = $this->getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn', ['foo', 10, 5]); + self::assertEquals(5, $column->getDecimal()); + self::assertSame($column, $column->setDecimal(2)); + self::assertEquals(2, $column->getDecimal()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn::getDecimal + */ + public function testGetDecimal() + { + $column = $this->getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn', ['foo', 10, 5]); + self::assertEquals(5, $column->getDecimal()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn::getExpressionData + */ + public function testGetExpressionData() + { + $column = $this->getMockForAbstractClass('Zend\Db\Sql\Ddl\Column\AbstractPrecisionColumn', ['foo', 10, 5]); + + self::assertEquals( + [['%s %s NOT NULL', ['foo', 'INTEGER(10,5)'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]], + $column->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BigIntegerTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BigIntegerTest.php new file mode 100644 index 00000000..2c5db383 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BigIntegerTest.php @@ -0,0 +1,37 @@ +getName()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::getExpressionData + */ + public function testGetExpressionData() + { + $column = new BigInteger('foo'); + self::assertEquals( + [['%s %s NOT NULL', ['foo', 'BIGINT'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]], + $column->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BinaryTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BinaryTest.php new file mode 100644 index 00000000..33aff543 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BinaryTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BlobTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BlobTest.php new file mode 100644 index 00000000..724fb92c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BlobTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BooleanTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BooleanTest.php new file mode 100644 index 00000000..f0000d8f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/BooleanTest.php @@ -0,0 +1,44 @@ +getExpressionData() + ); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Boolean + * + * @group 6257 + */ + public function testIsAlwaysNotNullable() + { + $column = new Boolean('foo', true); + + self::assertFalse($column->isNullable()); + + $column->setNullable(true); + + self::assertFalse($column->isNullable()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/CharTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/CharTest.php new file mode 100644 index 00000000..e50a8e31 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/CharTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/ColumnTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/ColumnTest.php new file mode 100644 index 00000000..8ec32bcf --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/ColumnTest.php @@ -0,0 +1,132 @@ +setName('foo')); + return $column; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::getName + * @depends testSetName + */ + public function testGetName(Column $column) + { + self::assertEquals('foo', $column->getName()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::setNullable + */ + public function testSetNullable() + { + $column = new Column; + self::assertSame($column, $column->setNullable(true)); + return $column; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::isNullable + * @depends testSetNullable + */ + public function testIsNullable(Column $column) + { + self::assertTrue($column->isNullable()); + $column->setNullable(false); + self::assertFalse($column->isNullable()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::setDefault + */ + public function testSetDefault() + { + $column = new Column; + self::assertSame($column, $column->setDefault('foo bar')); + return $column; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::getDefault + * @depends testSetDefault + */ + public function testGetDefault(Column $column) + { + self::assertEquals('foo bar', $column->getDefault()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::setOptions + */ + public function testSetOptions() + { + $column = new Column; + self::assertSame($column, $column->setOptions(['autoincrement' => true])); + return $column; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::setOption + */ + public function testSetOption() + { + $column = new Column; + self::assertSame($column, $column->setOption('primary', true)); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::getOptions + * @depends testSetOptions + */ + public function testGetOptions(Column $column) + { + self::assertEquals(['autoincrement' => true], $column->getOptions()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::getExpressionData + */ + public function testGetExpressionData() + { + $column = new Column; + $column->setName('foo'); + self::assertEquals( + [['%s %s NOT NULL', ['foo', 'INTEGER'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]], + $column->getExpressionData() + ); + + $column->setNullable(true); + self::assertEquals( + [['%s %s', ['foo', 'INTEGER'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]], + $column->getExpressionData() + ); + + $column->setDefault('bar'); + self::assertEquals( + [[ + '%s %s DEFAULT %s', + ['foo', 'INTEGER', 'bar'], + [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL, $column::TYPE_VALUE], + ]], + $column->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DateTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DateTest.php new file mode 100644 index 00000000..76671afb --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DateTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DatetimeTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DatetimeTest.php new file mode 100644 index 00000000..e75e9502 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DatetimeTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DecimalTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DecimalTest.php new file mode 100644 index 00000000..2699ee15 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/DecimalTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatTest.php new file mode 100644 index 00000000..36f06e51 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatTest.php @@ -0,0 +1,29 @@ +=')) { + $this->markTestSkipped('Cannot test Float column under PHP 7; reserved keyword'); + } + } + + public function testRaisesDeprecationNoticeOnInstantiation() + { + $this->expectException('PHPUnit_Framework_Error_Deprecated'); + new FloatColumn('foo', 10, 5); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatingTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatingTest.php new file mode 100644 index 00000000..a530ea47 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/FloatingTest.php @@ -0,0 +1,32 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/IntegerTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/IntegerTest.php new file mode 100644 index 00000000..32729498 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/IntegerTest.php @@ -0,0 +1,49 @@ +getName()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Column\Column::getExpressionData + */ + public function testGetExpressionData() + { + $column = new Integer('foo'); + self::assertEquals( + [['%s %s NOT NULL', ['foo', 'INTEGER'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]], + $column->getExpressionData() + ); + + $column = new Integer('foo'); + $column->addConstraint(new PrimaryKey()); + self::assertEquals( + [ + ['%s %s NOT NULL', ['foo', 'INTEGER'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]], + ' ', + ['PRIMARY KEY', [], []], + ], + $column->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TextTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TextTest.php new file mode 100644 index 00000000..613c6f10 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TextTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimeTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimeTest.php new file mode 100644 index 00000000..91dc56f3 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimeTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimestampTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimestampTest.php new file mode 100644 index 00000000..fc5974b9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/TimestampTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarbinaryTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarbinaryTest.php new file mode 100644 index 00000000..d3189524 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarbinaryTest.php @@ -0,0 +1,28 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarcharTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarcharTest.php new file mode 100644 index 00000000..701c8106 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Column/VarcharTest.php @@ -0,0 +1,38 @@ +getExpressionData() + ); + + $column->setDefault('bar'); + self::assertEquals( + [[ + '%s %s NOT NULL DEFAULT %s', + ['foo', 'VARCHAR(20)', 'bar'], + [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL, $column::TYPE_VALUE], + ]], + $column->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php new file mode 100644 index 00000000..d58dc494 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/AbstractConstraintTest.php @@ -0,0 +1,50 @@ +ac = $this->getMockForAbstractClass('Zend\Db\Sql\Ddl\Constraint\AbstractConstraint'); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\AbstractConstraint::setColumns + */ + public function testSetColumns() + { + self::assertSame($this->ac, $this->ac->setColumns(['foo', 'bar'])); + self::assertEquals(['foo', 'bar'], $this->ac->getColumns()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\AbstractConstraint::addColumn + */ + public function testAddColumn() + { + self::assertSame($this->ac, $this->ac->addColumn('foo')); + self::assertEquals(['foo'], $this->ac->getColumns()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\AbstractConstraint::getColumns + */ + public function testGetColumns() + { + $this->ac->setColumns(['foo', 'bar']); + self::assertEquals(['foo', 'bar'], $this->ac->getColumns()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/CheckTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/CheckTest.php new file mode 100644 index 00000000..ed63f115 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/CheckTest.php @@ -0,0 +1,32 @@ +0', 'foo'); + self::assertEquals( + [[ + 'CONSTRAINT %s CHECK (%s)', + ['foo', 'id>0'], + [$check::TYPE_IDENTIFIER, $check::TYPE_LITERAL], + ]], + $check->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php new file mode 100644 index 00000000..d4272742 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/ForeignKeyTest.php @@ -0,0 +1,134 @@ +setName('xxxx')); + return $fk; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::getName + * @depends testSetName + */ + public function testGetName(ForeignKey $fk) + { + self::assertEquals('xxxx', $fk->getName()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::setReferenceTable + */ + public function testSetReferenceTable() + { + $fk = new ForeignKey('foo', 'bar', 'baz', 'bam'); + self::assertSame($fk, $fk->setReferenceTable('xxxx')); + return $fk; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::getReferenceTable + * @depends testSetReferenceTable + */ + public function testGetReferenceTable(ForeignKey $fk) + { + self::assertEquals('xxxx', $fk->getReferenceTable()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::setReferenceColumn + */ + public function testSetReferenceColumn() + { + $fk = new ForeignKey('foo', 'bar', 'baz', 'bam'); + self::assertSame($fk, $fk->setReferenceColumn('xxxx')); + return $fk; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::getReferenceColumn + * @depends testSetReferenceColumn + */ + public function testGetReferenceColumn(ForeignKey $fk) + { + self::assertEquals(['xxxx'], $fk->getReferenceColumn()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::setOnDeleteRule + */ + public function testSetOnDeleteRule() + { + $fk = new ForeignKey('foo', 'bar', 'baz', 'bam'); + self::assertSame($fk, $fk->setOnDeleteRule('CASCADE')); + return $fk; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::getOnDeleteRule + * @depends testSetOnDeleteRule + */ + public function testGetOnDeleteRule(ForeignKey $fk) + { + self::assertEquals('CASCADE', $fk->getOnDeleteRule()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::setOnUpdateRule + */ + public function testSetOnUpdateRule() + { + $fk = new ForeignKey('foo', 'bar', 'baz', 'bam'); + self::assertSame($fk, $fk->setOnUpdateRule('CASCADE')); + return $fk; + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::getOnUpdateRule + * @depends testSetOnUpdateRule + */ + public function testGetOnUpdateRule(ForeignKey $fk) + { + self::assertEquals('CASCADE', $fk->getOnUpdateRule()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Constraint\ForeignKey::getExpressionData + */ + public function testGetExpressionData() + { + $fk = new ForeignKey('foo', 'bar', 'baz', 'bam', 'CASCADE', 'SET NULL'); + self::assertEquals( + [[ + 'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s) ON DELETE %s ON UPDATE %s', + ['foo', 'bar', 'baz', 'bam', 'CASCADE', 'SET NULL'], + [ + $fk::TYPE_IDENTIFIER, + $fk::TYPE_IDENTIFIER, + $fk::TYPE_IDENTIFIER, + $fk::TYPE_IDENTIFIER, + $fk::TYPE_LITERAL, + $fk::TYPE_LITERAL, + ], + ]], + $fk->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php new file mode 100644 index 00000000..aef85425 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/PrimaryKeyTest.php @@ -0,0 +1,32 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php new file mode 100644 index 00000000..3fc8e9b2 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Constraint/UniqueKeyTest.php @@ -0,0 +1,32 @@ +getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/CreateTableTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/CreateTableTest.php new file mode 100644 index 00000000..5c49a3ca --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/CreateTableTest.php @@ -0,0 +1,175 @@ +getRawState($ct::TABLE)); + self::assertTrue($ct->isTemporary()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::setTemporary + */ + public function testSetTemporary() + { + $ct = new CreateTable(); + self::assertSame($ct, $ct->setTemporary(false)); + self::assertFalse($ct->isTemporary()); + $ct->setTemporary(true); + self::assertTrue($ct->isTemporary()); + $ct->setTemporary('yes'); + self::assertTrue($ct->isTemporary()); + + self::assertStringStartsWith("CREATE TEMPORARY TABLE", $ct->getSqlString()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::isTemporary + */ + public function testIsTemporary() + { + $ct = new CreateTable(); + self::assertFalse($ct->isTemporary()); + $ct->setTemporary(true); + self::assertTrue($ct->isTemporary()); + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::setTable + */ + public function testSetTable() + { + $ct = new CreateTable(); + self::assertEquals('', $ct->getRawState('table')); + $ct->setTable('test'); + return $ct; + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::getRawState + * @depends testSetTable + */ + public function testRawStateViaTable(CreateTable $ct) + { + self::assertEquals('test', $ct->getRawState('table')); + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::addColumn + */ + public function testAddColumn() + { + $column = $this->getMockBuilder('Zend\Db\Sql\Ddl\Column\ColumnInterface')->getMock(); + $ct = new CreateTable; + self::assertSame($ct, $ct->addColumn($column)); + return $ct; + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::getRawState + * @depends testAddColumn + */ + public function testRawStateViaColumn(CreateTable $ct) + { + $state = $ct->getRawState('columns'); + self::assertInternalType('array', $state); + $column = array_pop($state); + self::assertInstanceOf('Zend\Db\Sql\Ddl\Column\ColumnInterface', $column); + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::addConstraint + */ + public function testAddConstraint() + { + $constraint = $this->getMockBuilder('Zend\Db\Sql\Ddl\Constraint\ConstraintInterface')->getMock(); + $ct = new CreateTable; + self::assertSame($ct, $ct->addConstraint($constraint)); + return $ct; + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::getRawState + * @depends testAddConstraint + */ + public function testRawStateViaConstraint(CreateTable $ct) + { + $state = $ct->getRawState('constraints'); + self::assertInternalType('array', $state); + $constraint = array_pop($state); + self::assertInstanceOf('Zend\Db\Sql\Ddl\Constraint\ConstraintInterface', $constraint); + } + + /** + * @covers \Zend\Db\Sql\Ddl\CreateTable::getSqlString + */ + public function testGetSqlString() + { + $ct = new CreateTable('foo'); + self::assertEquals("CREATE TABLE \"foo\" ( \n)", $ct->getSqlString()); + + $ct = new CreateTable('foo', true); + self::assertEquals("CREATE TEMPORARY TABLE \"foo\" ( \n)", $ct->getSqlString()); + + $ct = new CreateTable('foo'); + $ct->addColumn(new Column('bar')); + self::assertEquals("CREATE TABLE \"foo\" ( \n \"bar\" INTEGER NOT NULL \n)", $ct->getSqlString()); + + $ct = new CreateTable('foo', true); + $ct->addColumn(new Column('bar')); + self::assertEquals("CREATE TEMPORARY TABLE \"foo\" ( \n \"bar\" INTEGER NOT NULL \n)", $ct->getSqlString()); + + $ct = new CreateTable('foo', true); + $ct->addColumn(new Column('bar')); + $ct->addColumn(new Column('baz')); + self::assertEquals( + "CREATE TEMPORARY TABLE \"foo\" ( \n \"bar\" INTEGER NOT NULL,\n \"baz\" INTEGER NOT NULL \n)", + $ct->getSqlString() + ); + + $ct = new CreateTable('foo'); + $ct->addColumn(new Column('bar')); + $ct->addConstraint(new Constraint\PrimaryKey('bat')); + self::assertEquals( + "CREATE TABLE \"foo\" ( \n \"bar\" INTEGER NOT NULL , \n PRIMARY KEY (\"bat\") \n)", + $ct->getSqlString() + ); + + $ct = new CreateTable('foo'); + $ct->addConstraint(new Constraint\PrimaryKey('bar')); + $ct->addConstraint(new Constraint\PrimaryKey('bat')); + self::assertEquals( + "CREATE TABLE \"foo\" ( \n PRIMARY KEY (\"bar\"),\n PRIMARY KEY (\"bat\") \n)", + $ct->getSqlString() + ); + + $ct = new CreateTable(new TableIdentifier('foo')); + $ct->addColumn(new Column('bar')); + self::assertEquals("CREATE TABLE \"foo\" ( \n \"bar\" INTEGER NOT NULL \n)", $ct->getSqlString()); + + $ct = new CreateTable(new TableIdentifier('bar', 'foo')); + $ct->addColumn(new Column('baz')); + self::assertEquals("CREATE TABLE \"foo\".\"bar\" ( \n \"baz\" INTEGER NOT NULL \n)", $ct->getSqlString()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/DropTableTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/DropTableTest.php new file mode 100644 index 00000000..91849e37 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/DropTableTest.php @@ -0,0 +1,32 @@ +getSqlString()); + + $dt = new DropTable(new TableIdentifier('foo')); + self::assertEquals('DROP TABLE "foo"', $dt->getSqlString()); + + $dt = new DropTable(new TableIdentifier('bar', 'foo')); + self::assertEquals('DROP TABLE "foo"."bar"', $dt->getSqlString()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Index/IndexTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Index/IndexTest.php new file mode 100644 index 00000000..41eb6c96 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Ddl/Index/IndexTest.php @@ -0,0 +1,64 @@ +getExpressionData() + ); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Index\Index::getExpressionData + */ + public function testGetExpressionDataWithLength() + { + $key = new Index(['foo', 'bar'], 'my_uk', [10, 5]); + self::assertEquals( + [[ + 'INDEX %s(%s(10), %s(5))', + ['my_uk', 'foo', 'bar'], + [$key::TYPE_IDENTIFIER, $key::TYPE_IDENTIFIER, $key::TYPE_IDENTIFIER], + ]], + $key->getExpressionData() + ); + } + + /** + * @covers \Zend\Db\Sql\Ddl\Index\Index::getExpressionData + */ + public function testGetExpressionDataWithLengthUnmatched() + { + $key = new Index(['foo', 'bar'], 'my_uk', [10]); + self::assertEquals( + [[ + 'INDEX %s(%s(10), %s)', + ['my_uk', 'foo', 'bar'], + [$key::TYPE_IDENTIFIER, $key::TYPE_IDENTIFIER, $key::TYPE_IDENTIFIER], + ]], + $key->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/DeleteTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/DeleteTest.php new file mode 100644 index 00000000..51ed727c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/DeleteTest.php @@ -0,0 +1,228 @@ +delete = new Delete; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Sql\Delete::from + */ + public function testFrom() + { + $this->delete->from('foo', 'bar'); + self::assertEquals('foo', $this->readAttribute($this->delete, 'table')); + + $tableIdentifier = new TableIdentifier('foo', 'bar'); + $this->delete->from($tableIdentifier); + self::assertEquals($tableIdentifier, $this->readAttribute($this->delete, 'table')); + } + + /** + * @covers \Zend\Db\Sql\Delete::where + * + * @todo REMOVE THIS IN 3.x + */ + public function testWhere() + { + $this->delete->where('x = y'); + $this->delete->where(['foo > ?' => 5]); + $this->delete->where(['id' => 2]); + $this->delete->where(['a = b'], Where::OP_OR); + $this->delete->where(['c1' => null]); + $this->delete->where(['c2' => [1, 2, 3]]); + $this->delete->where([new IsNotNull('c3')]); + $this->delete->where(['one' => 1, 'two' => 2]); + $where = $this->delete->where; + + $predicates = $this->readAttribute($where, 'predicates'); + self::assertEquals('AND', $predicates[0][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]); + + self::assertEquals('AND', $predicates[1][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[1][1]); + + self::assertEquals('AND', $predicates[2][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[2][1]); + + self::assertEquals('OR', $predicates[3][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[3][1]); + + self::assertEquals('AND', $predicates[4][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\IsNull', $predicates[4][1]); + + self::assertEquals('AND', $predicates[5][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\In', $predicates[5][1]); + + self::assertEquals('AND', $predicates[6][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\IsNotNull', $predicates[6][1]); + + self::assertEquals('AND', $predicates[7][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[7][1]); + + self::assertEquals('AND', $predicates[8][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[8][1]); + + $where = new Where; + $this->delete->where($where); + self::assertSame($where, $this->delete->where); + + $this->delete->where(function ($what) use ($where) { + self::assertSame($where, $what); + }); + } + + /** + * @covers \Zend\Db\Sql\Delete::prepareStatement + */ + public function testPrepareStatement() + { + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->at(2)) + ->method('setSql') + ->with($this->equalTo('DELETE FROM "foo" WHERE x = y')); + + $this->delete->from('foo') + ->where('x = y'); + + $this->delete->prepareStatement($mockAdapter, $mockStatement); + + // with TableIdentifier + $this->delete = new Delete; + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->at(2)) + ->method('setSql') + ->with($this->equalTo('DELETE FROM "sch"."foo" WHERE x = y')); + + $this->delete->from(new TableIdentifier('foo', 'sch')) + ->where('x = y'); + + $this->delete->prepareStatement($mockAdapter, $mockStatement); + } + + /** + * @covers \Zend\Db\Sql\Delete::getSqlString + */ + public function testGetSqlString() + { + $this->delete->from('foo') + ->where('x = y'); + self::assertEquals('DELETE FROM "foo" WHERE x = y', $this->delete->getSqlString()); + + // with TableIdentifier + $this->delete = new Delete; + $this->delete->from(new TableIdentifier('foo', 'sch')) + ->where('x = y'); + self::assertEquals('DELETE FROM "sch"."foo" WHERE x = y', $this->delete->getSqlString()); + } + + /** + * @coversNothing + */ + public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement() + { + $deleteIgnore = new DeleteIgnore(); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->at(2)) + ->method('setSql') + ->with($this->equalTo('DELETE IGNORE FROM "foo" WHERE x = y')); + + $deleteIgnore->from('foo') + ->where('x = y'); + + $deleteIgnore->prepareStatement($mockAdapter, $mockStatement); + + + + // with TableIdentifier + $deleteIgnore = new DeleteIgnore(); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->at(2)) + ->method('setSql') + ->with($this->equalTo('DELETE IGNORE FROM "sch"."foo" WHERE x = y')); + + $deleteIgnore->from(new TableIdentifier('foo', 'sch')) + ->where('x = y'); + + $deleteIgnore->prepareStatement($mockAdapter, $mockStatement); + } + + /** + * @coversNothing + */ + public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString() + { + $deleteIgnore = new DeleteIgnore(); + + $deleteIgnore->from('foo') + ->where('x = y'); + self::assertEquals('DELETE IGNORE FROM "foo" WHERE x = y', $deleteIgnore->getSqlString()); + + // with TableIdentifier + $deleteIgnore = new DeleteIgnore(); + $deleteIgnore->from(new TableIdentifier('foo', 'sch')) + ->where('x = y'); + self::assertEquals('DELETE IGNORE FROM "sch"."foo" WHERE x = y', $deleteIgnore->getSqlString()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/ExpressionTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/ExpressionTest.php new file mode 100644 index 00000000..25c12d4f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/ExpressionTest.php @@ -0,0 +1,182 @@ +setExpression('Foo Bar'); + self::assertSame($expression, $return); + return $return; + } + + /** + * @covers \Zend\Db\Sql\Expression::setExpression + */ + public function testSetExpressionException() + { + $expression = new Expression(); + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Supplied expression must be a string.'); + $expression->setExpression(null); + } + + /** + * @covers \Zend\Db\Sql\Expression::getExpression + * @depends testSetExpression + */ + public function testGetExpression(Expression $expression) + { + self::assertEquals('Foo Bar', $expression->getExpression()); + } + + /** + * @covers \Zend\Db\Sql\Expression::setParameters + */ + public function testSetParameters() + { + $expression = new Expression(); + $return = $expression->setParameters('foo'); + self::assertSame($expression, $return); + return $return; + } + + /** + * @covers \Zend\Db\Sql\Expression::setParameters + */ + public function testSetParametersException() + { + $expression = new Expression('', 'foo'); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Expression parameters must be a scalar or array.'); + $expression->setParameters(null); + } + + /** + * @covers \Zend\Db\Sql\Expression::getParameters + * @depends testSetParameters + */ + public function testGetParameters(Expression $expression) + { + self::assertEquals('foo', $expression->getParameters()); + } + + /** + * @covers \Zend\Db\Sql\Expression::setTypes + */ + public function testSetTypes() + { + $expression = new Expression(); + $return = $expression->setTypes([ + Expression::TYPE_IDENTIFIER, + Expression::TYPE_VALUE, + Expression::TYPE_LITERAL, + ]); + self::assertSame($expression, $return); + return $expression; + } + + /** + * @covers \Zend\Db\Sql\Expression::getTypes + * @depends testSetTypes + */ + public function testGetTypes(Expression $expression) + { + self::assertEquals( + [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE, Expression::TYPE_LITERAL], + $expression->getTypes() + ); + } + + /** + * @covers \Zend\Db\Sql\Expression::getExpressionData + */ + public function testGetExpressionData() + { + $expression = new Expression( + 'X SAME AS ? AND Y = ? BUT LITERALLY ?', + ['foo', 5, 'FUNC(FF%X)'], + [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE, Expression::TYPE_LITERAL] + ); + + self::assertEquals( + [[ + 'X SAME AS %s AND Y = %s BUT LITERALLY %s', + ['foo', 5, 'FUNC(FF%X)'], + [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE, Expression::TYPE_LITERAL], + ]], + $expression->getExpressionData() + ); + $expression = new Expression( + 'X SAME AS ? AND Y = ? BUT LITERALLY ?', + [ + ['foo' => Expression::TYPE_IDENTIFIER], + [5 => Expression::TYPE_VALUE], + ['FUNC(FF%X)' => Expression::TYPE_LITERAL], + ] + ); + + $expected = [[ + 'X SAME AS %s AND Y = %s BUT LITERALLY %s', + ['foo', 5, 'FUNC(FF%X)'], + [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE, Expression::TYPE_LITERAL], + ]]; + + self::assertEquals($expected, $expression->getExpressionData()); + } + + public function testGetExpressionDataWillEscapePercent() + { + $expression = new Expression('X LIKE "foo%"'); + self::assertEquals( + ['X LIKE "foo%%"'], + $expression->getExpressionData() + ); + } + + public function testConstructorWithLiteralZero() + { + $expression = new Expression('0'); + self::assertSame('0', $expression->getExpression()); + } + + /** + * @group 7407 + */ + public function testGetExpressionPreservesPercentageSignInFromUnixtime() + { + $expressionString = 'FROM_UNIXTIME(date, "%Y-%m")'; + $expression = new Expression($expressionString); + + self::assertSame($expressionString, $expression->getExpression()); + } + + public function testNumberOfReplacemensConsidersWhenSameVariableIsUsedManyTimes() + { + $expression = new Expression('uf.user_id = :user_id OR uf.friend_id = :user_id', ['user_id' => 1]); + $expression->getExpressionData(); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/InsertTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/InsertTest.php new file mode 100644 index 00000000..e16d4647 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/InsertTest.php @@ -0,0 +1,412 @@ +insert = new Insert; + } + + /** + * @covers \Zend\Db\Sql\Insert::into + */ + public function testInto() + { + $this->insert->into('table', 'schema'); + self::assertEquals('table', $this->insert->getRawState('table')); + + $tableIdentifier = new TableIdentifier('table', 'schema'); + $this->insert->into($tableIdentifier); + self::assertEquals($tableIdentifier, $this->insert->getRawState('table')); + } + + /** + * @covers \Zend\Db\Sql\Insert::columns + */ + public function testColumns() + { + $columns = ['foo', 'bar']; + $this->insert->columns($columns); + self::assertEquals($columns, $this->insert->getRawState('columns')); + } + + /** + * @covers \Zend\Db\Sql\Insert::values + */ + public function testValues() + { + $this->insert->values(['foo' => 'bar']); + self::assertEquals(['foo'], $this->insert->getRawState('columns')); + self::assertEquals(['bar'], $this->insert->getRawState('values')); + + // test will merge cols and values of previously set stuff + $this->insert->values(['foo' => 'bax'], Insert::VALUES_MERGE); + $this->insert->values(['boom' => 'bam'], Insert::VALUES_MERGE); + self::assertEquals(['foo', 'boom'], $this->insert->getRawState('columns')); + self::assertEquals(['bax', 'bam'], $this->insert->getRawState('values')); + + $this->insert->values(['foo' => 'bax']); + self::assertEquals(['foo'], $this->insert->getRawState('columns')); + self::assertEquals(['bax'], $this->insert->getRawState('values')); + } + + /** + * @covers \Zend\Db\Sql\Insert::values + */ + public function testValuesThrowsExceptionWhenNotArrayOrSelect() + { + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('values() expects an array of values or Zend\Db\Sql\Select instance'); + $this->insert->values(5); + } + + /** + * @covers \Zend\Db\Sql\Insert::values + */ + public function testValuesThrowsExceptionWhenSelectMergeOverArray() + { + $this->insert->values(['foo' => 'bar']); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('A Zend\Db\Sql\Select instance cannot be provided with the merge flag'); + $this->insert->values(new Select, Insert::VALUES_MERGE); + } + + /** + * @covers \Zend\Db\Sql\Insert::values + */ + public function testValuesThrowsExceptionWhenArrayMergeOverSelect() + { + $this->insert->values(new Select); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage( + 'An array of values cannot be provided with the merge flag when a Zend\Db\Sql\Select instance already ' + . 'exists as the value source' + ); + $this->insert->values(['foo' => 'bar'], Insert::VALUES_MERGE); + } + + /** + * @covers \Zend\Db\Sql\Insert::values + * @group ZF2-4926 + */ + public function testEmptyArrayValues() + { + $this->insert->values([]); + self::assertEquals([], $this->readAttribute($this->insert, 'columns')); + } + + /** + * @covers \Zend\Db\Sql\Insert::prepareStatement + */ + public function testPrepareStatement() + { + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $pContainer = new \Zend\Db\Adapter\ParameterContainer([]); + $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); + $mockStatement->expects($this->at(1)) + ->method('setSql') + ->with($this->equalTo('INSERT INTO "foo" ("bar", "boo") VALUES (?, NOW())')); + + $this->insert->into('foo') + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()')]); + + $this->insert->prepareStatement($mockAdapter, $mockStatement); + + // with TableIdentifier + $this->insert = new Insert; + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $pContainer = new \Zend\Db\Adapter\ParameterContainer([]); + $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); + $mockStatement->expects($this->at(1)) + ->method('setSql') + ->with($this->equalTo('INSERT INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())')); + + $this->insert->into(new TableIdentifier('foo', 'sch')) + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()')]); + + $this->insert->prepareStatement($mockAdapter, $mockStatement); + } + + /** + * @covers \Zend\Db\Sql\Insert::prepareStatement + */ + public function testPrepareStatementWithSelect() + { + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = new \Zend\Db\Adapter\StatementContainer(); + + $select = new Select('bar'); + $this->insert + ->into('foo') + ->columns(['col1']) + ->select($select->where(['x' => 5])) + ->prepareStatement($mockAdapter, $mockStatement); + + self::assertEquals( + 'INSERT INTO "foo" ("col1") SELECT "bar".* FROM "bar" WHERE "x" = ?', + $mockStatement->getSql() + ); + $parameters = $mockStatement->getParameterContainer()->getNamedArray(); + self::assertSame(['subselect1where1' => 5], $parameters); + } + + /** + * @covers \Zend\Db\Sql\Insert::getSqlString + */ + public function testGetSqlString() + { + $this->insert->into('foo') + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]); + + self::assertEquals( + 'INSERT INTO "foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', + $this->insert->getSqlString(new TrustingSql92Platform()) + ); + + // with TableIdentifier + $this->insert = new Insert; + $this->insert->into(new TableIdentifier('foo', 'sch')) + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]); + + self::assertEquals( + 'INSERT INTO "sch"."foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', + $this->insert->getSqlString(new TrustingSql92Platform()) + ); + + // with Select + $this->insert = new Insert; + $select = new Select(); + $this->insert->into('foo')->select($select->from('bar')); + + self::assertEquals( + 'INSERT INTO "foo" SELECT "bar".* FROM "bar"', + $this->insert->getSqlString(new TrustingSql92Platform()) + ); + + // with Select and columns + $this->insert->columns(['col1', 'col2']); + self::assertEquals( + 'INSERT INTO "foo" ("col1", "col2") SELECT "bar".* FROM "bar"', + $this->insert->getSqlString(new TrustingSql92Platform()) + ); + } + + public function testGetSqlStringUsingColumnsAndValuesMethods() + { + // With columns() and values() + $this->insert + ->into('foo') + ->columns(['col1', 'col2', 'col3']) + ->values(['val1', 'val2', 'val3']); + self::assertEquals( + 'INSERT INTO "foo" ("col1", "col2", "col3") VALUES (\'val1\', \'val2\', \'val3\')', + $this->insert->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @covers \Zend\Db\Sql\Insert::__set + */ + // @codingStandardsIgnoreStart + public function test__set() + { + // @codingStandardsIgnoreEnd + $this->insert->foo = 'bar'; + self::assertEquals(['foo'], $this->insert->getRawState('columns')); + self::assertEquals(['bar'], $this->insert->getRawState('values')); + } + + /** + * @covers \Zend\Db\Sql\Insert::__unset + */ + // @codingStandardsIgnoreStart + public function test__unset() + { + // @codingStandardsIgnoreEnd + $this->insert->foo = 'bar'; + self::assertEquals(['foo'], $this->insert->getRawState('columns')); + self::assertEquals(['bar'], $this->insert->getRawState('values')); + unset($this->insert->foo); + self::assertEquals([], $this->insert->getRawState('columns')); + self::assertEquals([], $this->insert->getRawState('values')); + + $this->insert->foo = null; + self::assertEquals(['foo'], $this->insert->getRawState('columns')); + self::assertEquals([null], $this->insert->getRawState('values')); + + unset($this->insert->foo); + self::assertEquals([], $this->insert->getRawState('columns')); + self::assertEquals([], $this->insert->getRawState('values')); + } + + /** + * @covers \Zend\Db\Sql\Insert::__isset + */ + // @codingStandardsIgnoreStart + public function test__isset() + { + // @codingStandardsIgnoreEnd + $this->insert->foo = 'bar'; + self::assertTrue(isset($this->insert->foo)); + + $this->insert->foo = null; + self::assertTrue(isset($this->insert->foo)); + } + + /** + * @covers \Zend\Db\Sql\Insert::__get + */ + // @codingStandardsIgnoreStart + public function test__get() + { + // @codingStandardsIgnoreEnd + $this->insert->foo = 'bar'; + self::assertEquals('bar', $this->insert->foo); + + $this->insert->foo = null; + self::assertNull($this->insert->foo); + } + + /** + * @group ZF2-536 + */ + public function testValuesMerge() + { + $this->insert->into('foo') + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]); + $this->insert->into('foo') + ->values(['qux' => 100], Insert::VALUES_MERGE); + + self::assertEquals( + 'INSERT INTO "foo" ("bar", "boo", "bam", "qux") VALUES (\'baz\', NOW(), NULL, \'100\')', + $this->insert->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @coversNothing + */ + public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement() + { + $replace = new Replace(); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $pContainer = new \Zend\Db\Adapter\ParameterContainer([]); + $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); + $mockStatement->expects($this->at(1)) + ->method('setSql') + ->with($this->equalTo('REPLACE INTO "foo" ("bar", "boo") VALUES (?, NOW())')); + + $replace->into('foo') + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()')]); + + $replace->prepareStatement($mockAdapter, $mockStatement); + + // with TableIdentifier + $replace = new Replace(); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $pContainer = new \Zend\Db\Adapter\ParameterContainer([]); + $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); + $mockStatement->expects($this->at(1)) + ->method('setSql') + ->with($this->equalTo('REPLACE INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())')); + + $replace->into(new TableIdentifier('foo', 'sch')) + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()')]); + + $replace->prepareStatement($mockAdapter, $mockStatement); + } + + /** + * @coversNothing + */ + public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString() + { + $replace = new Replace(); + $replace->into('foo') + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]); + + self::assertEquals( + 'REPLACE INTO "foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', + $replace->getSqlString(new TrustingSql92Platform()) + ); + + // with TableIdentifier + $replace = new Replace(); + $replace->into(new TableIdentifier('foo', 'sch')) + ->values(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]); + + self::assertEquals( + 'REPLACE INTO "sch"."foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', + $replace->getSqlString(new TrustingSql92Platform()) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/JoinTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/JoinTest.php new file mode 100644 index 00000000..18ca3b0c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/JoinTest.php @@ -0,0 +1,135 @@ +next(); + + self::assertAttributeEquals(1, 'position', $join); + } + + public function testRewindResetsPositionToZero() + { + $join = new Join(); + + $join->next(); + $join->next(); + self::assertAttributeEquals(2, 'position', $join); + + $join->rewind(); + self::assertAttributeEquals(0, 'position', $join); + } + + public function testKeyReturnsTheCurrentPosition() + { + $join = new Join(); + + $join->next(); + $join->next(); + $join->next(); + + self::assertEquals(3, $join->key()); + } + + public function testCurrentReturnsTheCurrentJoinSpecification() + { + $name = 'baz'; + $on = 'foo.id = baz.id'; + + $join = new Join(); + $join->join($name, $on); + + $expectedSpecification = [ + 'name' => $name, + 'on' => $on, + 'columns' => [Select::SQL_STAR], + 'type' => Join::JOIN_INNER, + ]; + + self::assertEquals($expectedSpecification, $join->current()); + } + + public function testValidReturnsTrueIfTheIteratorIsAtAValidPositionAndFalseIfNot() + { + $join = new Join(); + $join->join('baz', 'foo.id = baz.id'); + + self::assertTrue($join->valid()); + + $join->next(); + + self::assertFalse($join->valid()); + } + + /** + * @testdox unit test: Test join() returns Join object (is chainable) + * @covers \Zend\Db\Sql\Join::join + */ + public function testJoin() + { + $join = new Join; + $return = $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); + self::assertSame($join, $return); + } + + public function testJoinWillThrowAnExceptionIfNameIsNoValid() + { + $join = new Join(); + + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage("join() expects '' as a single element associative array"); + $join->join([], false); + } + + /** + * @testdox unit test: Test count() returns correct count + * @covers \Zend\Db\Sql\Join::count + * @covers \Zend\Db\Sql\Join::join + */ + public function testCount() + { + $join = new Join; + $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); + $join->join('bar', 'foo.fooId = bar.fooId', Join::JOIN_LEFT); + + self::assertEquals(2, $join->count()); + self::assertCount($join->count(), $join->getJoins()); + } + + /** + * @testdox unit test: Test reset() resets the joins + * @covers \Zend\Db\Sql\Join::count + * @covers \Zend\Db\Sql\Join::join + * @covers \Zend\Db\Sql\Join::reset + */ + public function testReset() + { + $join = new Join; + $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); + $join->join('bar', 'foo.fooId = bar.fooId', Join::JOIN_LEFT); + $join->reset(); + + self::assertEquals(0, $join->count()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/LiteralTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/LiteralTest.php new file mode 100644 index 00000000..d5541cd3 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/LiteralTest.php @@ -0,0 +1,47 @@ +setLiteral('foo')); + } + + public function testGetLiteral() + { + $literal = new Literal('bar'); + self::assertEquals('bar', $literal->getLiteral()); + } + + public function testGetExpressionData() + { + $literal = new Literal('bar'); + self::assertEquals([['bar', [], []]], $literal->getExpressionData()); + } + + public function testGetExpressionDataWillEscapePercent() + { + $expression = new Literal('X LIKE "foo%"'); + self::assertEquals( + [[ + 'X LIKE "foo%%"', + [], + [], + ]], + $expression->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php new file mode 100644 index 00000000..1ad37267 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/IbmDb2/SelectDecoratorTest.php @@ -0,0 +1,155 @@ +getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + + // test + $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([ + $driver, + new IbmDb2Platform(), + ]) + ->getMock(); + + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + $statement->expects($this->once())->method('setSql')->with($expectedPrepareSql); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + $selectDecorator->setSupportsLimitOffset($supportsLimitOffset); + $selectDecorator->prepareStatement($adapter, $statement); + + self::assertEquals($expectedParams, $parameterContainer->getNamedArray()); + } + + /** + * @testdox integration test: Testing SelectDecorator will use Select to produce properly Ibm DB2 + * dialect sql statements + * @covers \Zend\Db\Sql\Platform\IbmDb2\SelectDecorator::getSqlString + * @dataProvider dataProvider + */ + public function testGetSqlString(Select $select, $ignored0, $ignored1, $expectedSql, $supportsLimitOffset) + { + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + $selectDecorator->setSupportsLimitOffset($supportsLimitOffset); + + self::assertEquals($expectedSql, @$selectDecorator->getSqlString(new IbmDb2Platform)); + } + + /** + * Data provider for testGetSqlString + * + * @return array + */ + public function dataProvider() + { + $select0 = new Select; + $select0->from(['x' => 'foo'])->limit(5); + $expectedParams0 = [ 'limit' => 5, 'offset' => 0 ]; + // @codingStandardsIgnoreStart + $expectedPrepareSql0 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN ? AND ?'; + $expectedSql0 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN 0 AND 5'; + // @codingStandardsIgnoreEnd + + $select1 = new Select; + $select1->from(['x' => 'foo'])->limit(5)->offset(10); + $expectedParams1 = [ 'limit' => 15, 'offset' => 11 ]; + // @codingStandardsIgnoreStart + $expectedPrepareSql1 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN ? AND ?'; + $expectedSql1 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN 11 AND 15'; + // @codingStandardsIgnoreEnd + + $select2 = new Select; + $select2->columns([new Expression('DISTINCT(id) as id')])->from(['x' => 'foo'])->limit(5)->offset(10); + $expectedParams2 = [ 'limit' => 15, 'offset' => 11]; + // @codingStandardsIgnoreStart + $expectedPrepareSql2 = 'SELECT DISTINCT(id) as id FROM ( SELECT DISTINCT(id) as id, DENSE_RANK() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN ? AND ?'; + $expectedSql2 = 'SELECT DISTINCT(id) as id FROM ( SELECT DISTINCT(id) as id, DENSE_RANK() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN 11 AND 15'; + // @codingStandardsIgnoreEnd + + $select3 = new Select; + $where3 = new Where(); + $where3->greaterThan('x.id', '10')->AND->lessThan('x.id', '31'); + $select3->from(['x' => 'foo'])->where($where3)->limit(5)->offset(10); + $expectedParams3 = [ 'limit' => 15, 'offset' => 11, 'where1' => '10', 'where2' => '31' ]; + // @codingStandardsIgnoreStart + $expectedPrepareSql3 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" WHERE "x"."id" > ? AND "x"."id" < ? ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN ? AND ?'; + $expectedSql3 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" WHERE "x"."id" > \'10\' AND "x"."id" < \'31\' ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN 11 AND 15'; + // @codingStandardsIgnoreEnd + + $select4 = new Select; + $where4 = $where3; + $select4->from(['x' => 'foo'])->where($where4)->limit(5); + $expectedParams4 = [ 'limit' => 5, 'offset' => 0, 'where1' => 10, 'where2' => 31 ]; + // @codingStandardsIgnoreStart + $expectedPrepareSql4 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" WHERE "x"."id" > ? AND "x"."id" < ? ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN ? AND ?'; + $expectedSql4 = 'SELECT * FROM ( SELECT "x".*, ROW_NUMBER() OVER () AS ZEND_DB_ROWNUM FROM "foo" "x" WHERE "x"."id" > \'10\' AND "x"."id" < \'31\' ) AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN 0 AND 5'; + // @codingStandardsIgnoreEnd + + $select5 = new Select; + $select5->from(['x' => 'foo'])->limit(5); + $expectedParams5 = []; + $expectedPrepareSql5 = 'SELECT "x".* FROM "foo" "x" LIMIT 5'; + $expectedSql5 = 'SELECT "x".* FROM "foo" "x" LIMIT 5'; + + $select6 = new Select; + $select6->columns([new Expression('DISTINCT(id) as id')])->from(['x' => 'foo'])->limit(5)->offset(10); + $expectedParams6 = []; + $expectedPrepareSql6 = 'SELECT DISTINCT(id) as id FROM "foo" "x" LIMIT 5 OFFSET 10'; + $expectedSql6 = 'SELECT DISTINCT(id) as id FROM "foo" "x" LIMIT 5 OFFSET 10'; + + return [ + [$select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0, false], + [$select1, $expectedPrepareSql1, $expectedParams1, $expectedSql1, false], + [$select2, $expectedPrepareSql2, $expectedParams2, $expectedSql2, false], + [$select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3, false], + [$select4, $expectedPrepareSql4, $expectedParams4, $expectedSql4, false], + [$select5, $expectedPrepareSql5, $expectedParams5, $expectedSql5, true], + [$select6, $expectedPrepareSql6, $expectedParams6, $expectedSql6, true], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php new file mode 100644 index 00000000..5be80ff6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/AlterTableDecoratorTest.php @@ -0,0 +1,55 @@ +setSubject($ct)); + } + + /** + * @covers Zend\Db\Sql\Platform\Mysql\Ddl\AlterTableDecorator::getSqlString + */ + public function testGetSqlString() + { + $ctd = new AlterTableDecorator(); + $ct = new AlterTable('foo'); + $ctd->setSubject($ct); + + $col = new Column('bar'); + $col->setOption('zerofill', true); + $col->setOption('unsigned', true); + $col->setOption('identity', true); + $col->setOption('comment', 'baz'); + $col->setOption('after', 'bar'); + $col->addConstraint(new PrimaryKey()); + $ct->addColumn($col); + + self::assertEquals( + "ALTER TABLE `foo`\n ADD COLUMN `bar` INTEGER UNSIGNED ZEROFILL " . + "NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'baz' AFTER `bar`", + @$ctd->getSqlString(new Mysql()) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php new file mode 100644 index 00000000..bfb0bd45 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/Ddl/CreateTableDecoratorTest.php @@ -0,0 +1,57 @@ +setSubject($ct)); + } + + /** + * @covers \Zend\Db\Sql\Platform\Mysql\Ddl\CreateTableDecorator::getSqlString + */ + public function testGetSqlString() + { + $ctd = new CreateTableDecorator(); + $ct = new CreateTable('foo'); + $ctd->setSubject($ct); + + $col = new Column('bar'); + $col->setOption('zerofill', true); + $col->setOption('unsigned', true); + $col->setOption('identity', true); + $col->setOption('column-format', 'FIXED'); + $col->setOption('storage', 'memory'); + $col->setOption('comment', 'baz'); + $col->addConstraint(new PrimaryKey()); + $ct->addColumn($col); + + self::assertEquals( + // @codingStandardsIgnoreStart + "CREATE TABLE `foo` ( \n `bar` INTEGER UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'baz' COLUMN_FORMAT FIXED STORAGE MEMORY \n)", + // @codingStandardsIgnoreEnd + @$ctd->getSqlString(new Mysql()) + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/MysqlTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/MysqlTest.php new file mode 100644 index 00000000..abd7b570 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/MysqlTest.php @@ -0,0 +1,31 @@ +getDecorators(); + + $type = key($decorators); + $decorator = current($decorators); + self::assertEquals('Zend\Db\Sql\Select', $type); + self::assertInstanceOf('Zend\Db\Sql\Platform\Mysql\SelectDecorator', $decorator); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php new file mode 100644 index 00000000..abd8eca0 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Mysql/SelectDecoratorTest.php @@ -0,0 +1,249 @@ +getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + + // test + $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([ + $driver, + new MysqlPlatform(), + ]) + ->getMock(); + + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $statement->expects($this->once())->method('setSql')->with($expectedSql); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + $selectDecorator->prepareStatement($adapter, $statement); + + self::assertEquals($expectedParams, $parameterContainer->getNamedArray()); + } + + /** + * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare + * a proper limit/offset sql statement + * @covers \Zend\Db\Sql\Platform\Mysql\SelectDecorator::prepareStatement + * @covers \Zend\Db\Sql\Platform\Mysql\SelectDecorator::processLimit + * @covers \Zend\Db\Sql\Platform\Mysql\SelectDecorator::processOffset + * @dataProvider dataProvider + */ + public function testPrepareStatementForSqlObject( + Select $select, + $ignore, + $expectedParams, + $alsoIgnore, + $expectedPdoSql + ) { + // mock the adapter, driver, and parts + $newStatement = new \Zend\Db\Adapter\Driver\Mysqli\Statement(); + $driver = new \Zend\Db\Adapter\Driver\Pdo\Pdo(new \Zend\Db\Adapter\Driver\Pdo\Connection()); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setConstructorArgs([$driver, new TrustingMysqlPlatform()]) + ->getMock(); + $trustingPlatform = new TrustingMysqlPlatform(); + $mockAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue($trustingPlatform)); + $mockAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($driver)); + // setup mock adapter + $this->mockAdapter = $mockAdapter; + + $this->sql = new Sql($this->mockAdapter, 'foo'); + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + $statement = $this->sql->prepareStatementForSqlObject($select, $newStatement); + self::assertEquals($expectedPdoSql, $statement->getSql()); + } + + /** + * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare + * a proper limit/offset sql statement + * @covers \Zend\Db\Sql\Platform\Mysql\SelectDecorator::getSqlString + * @covers \Zend\Db\Sql\Platform\Mysql\SelectDecorator::processLimit + * @covers \Zend\Db\Sql\Platform\Mysql\SelectDecorator::processOffset + * @dataProvider dataProvider + */ + public function testGetSqlString(Select $select, $ignore, $alsoIgnore, $expectedSql) + { + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + self::assertEquals($expectedSql, $selectDecorator->getSqlString(new TrustingMysqlPlatform)); + } + + public function dataProvider() + { + $select0 = new Select; + $select0->from('foo')->limit(5)->offset(10); + $expectedPrepareSql0 = 'SELECT `foo`.* FROM `foo` LIMIT ? OFFSET ?'; + $expectedPrepareObjectSql0 = 'SELECT `foo`.* FROM `foo` LIMIT :limit OFFSET :offset'; + $expectedParams0 = ['offset' => 10, 'limit' => 5]; + $expectedSql0 = 'SELECT `foo`.* FROM `foo` LIMIT 5 OFFSET 10'; + + // offset without limit + $select1 = new Select; + $select1->from('foo')->offset(10); + $expectedPrepareSql1 = 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET ?'; + $expectedPrepareObjectSql1 = 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET :offset'; + $expectedParams1 = ['offset' => 10]; + $expectedSql1 = 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET 10'; + + // offset and limit are not type casted when injected into parameter container + $select2 = new Select; + $select2->from('foo')->limit('5')->offset('10000000000000000000'); + $expectedPrepareSql2 = 'SELECT `foo`.* FROM `foo` LIMIT ? OFFSET ?'; + $expectedPrepareObjectSql2 = 'SELECT `foo`.* FROM `foo` LIMIT :limit OFFSET :offset'; + $expectedParams2 = ['offset' => '10000000000000000000', 'limit' => '5']; + $expectedSql2 = 'SELECT `foo`.* FROM `foo` LIMIT 5 OFFSET 10000000000000000000'; + + // nested single limit & offset in field param + $nestedSelect0 = new Select; + $nestedSelect0->from('foo1') + ->columns([ + 'cnt' => new Expression('count(foo1.id)') + ])->limit(100)->offset(500); + + $select3 = new Select; + $select3->from('foo') + ->columns([ + 'res' => $nestedSelect0, + ]) + ->limit(10)->offset(50); + + $expectedPrepareSql3 = + "SELECT (SELECT count(foo1.id) AS `cnt` FROM `foo1` LIMIT ? OFFSET ?) AS `res`" + . " FROM `foo` LIMIT ? OFFSET ?"; + $expectedPrepareObjectSql3 = + "SELECT (SELECT count(foo1.id) AS `cnt` FROM `foo1` LIMIT :subselect1limit OFFSET :subselect1offset) AS `res`" + . " FROM `foo` LIMIT :limit OFFSET :offset"; + $expectedParams3 = [ + 'subselect1limit' => 100, + 'subselect1offset' => 500, + 'limit' => 10, + 'offset' => 50 + ]; + $expectedSql3 = "SELECT (SELECT count(foo1.id) AS `cnt`" + . " FROM `foo1` LIMIT 100 OFFSET 500) AS `res`" + . " FROM `foo` LIMIT 10 OFFSET 50"; + + // nested multiple limit & offset in field param + $nestedSelect0 = new Select; + $nestedSelect0->from('foo1') + ->columns([ + 'cnt' => new Expression('count(foo1.id)') + ])->limit(100)->offset(500); + + $nestedSelect1 = new Select; + $nestedSelect1->from('foo2') + ->columns([ + 'cnt' => new Expression('count(foo2.id)') + ])->limit(50)->offset(101); + + $select4 = new Select; + $select4->from('foo') + ->columns([ + 'res' => $nestedSelect0, + 'res0' => $nestedSelect1 + ]) + ->limit(10)->offset(5); + + $expectedPrepareSql4 = + "SELECT (SELECT count(foo1.id) AS `cnt` FROM `foo1` LIMIT ? OFFSET ?) AS `res`," + . " (SELECT count(foo2.id) AS `cnt` FROM `foo2` LIMIT ? OFFSET ?) AS `res0`" + . " FROM `foo` LIMIT ? OFFSET ?"; + $expectedPrepareObjectSql4 = + "SELECT (SELECT count(foo1.id) AS `cnt` FROM `foo1` LIMIT :subselect1limit OFFSET :subselect1offset)" + . " AS `res`, (SELECT count(foo2.id) AS `cnt` FROM `foo2` LIMIT :subselect2limit OFFSET :subselect2offset)" + . " AS `res0` FROM `foo` LIMIT :limit OFFSET :offset"; + $expectedParams4 = [ + 'subselect1limit' => 100, + 'subselect1offset' => 500, + 'subselect2limit' => 50, + 'subselect2offset' => 101, + 'limit' => 10, + 'offset' => 5 + ]; + $expectedSql4 = "SELECT (SELECT count(foo1.id) AS `cnt` FROM `foo1` LIMIT 100 OFFSET 500) AS `res`," + . " (SELECT count(foo2.id) AS `cnt` FROM `foo2` LIMIT 50 OFFSET 101) AS `res0`" + . " FROM `foo` LIMIT 10 OFFSET 5"; + + // nested limit in field param, no limit in containing select + $nestedSelect0 = new Select; + $nestedSelect0->from('foo1') + ->columns([ + 'cnt' => new Expression('count(foo1.id)') + ]); + $nestedSelect0->where->equalTo('foo2', 'ab'); + $nestedSelect0->limit(1); + + $select5 = new Select; + $select5->from('foo') + ->columns([ + 'res' => $nestedSelect0, + ]); + + $expectedPrepareSql5 = + "SELECT (SELECT count(foo1.id) AS `cnt` FROM `foo1` WHERE `foo2` = ? LIMIT ?) AS `res`" + . " FROM `foo`"; + $expectedPrepareObjectSql5 = + "SELECT (SELECT count(foo1.id) AS `cnt` FROM `foo1` WHERE `foo2` = :subselect1where1 LIMIT" + . " :subselect1limit) AS `res` FROM `foo`"; + $expectedParams5 = [ + 'subselect1limit' => 1, + 'subselect1where1' => 'ab' + ]; + $expectedSql5 = "SELECT (SELECT count(foo1.id) AS `cnt`" + . " FROM `foo1` WHERE `foo2` = 'ab' LIMIT 1) AS `res`" + . " FROM `foo`"; + + + return [ + [$select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0, $expectedPrepareObjectSql0], + [$select1, $expectedPrepareSql1, $expectedParams1, $expectedSql1, $expectedPrepareObjectSql1], + [$select2, $expectedPrepareSql2, $expectedParams2, $expectedSql2, $expectedPrepareObjectSql2], + [$select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3, $expectedPrepareObjectSql3], + [$select4, $expectedPrepareSql4, $expectedParams4, $expectedSql4, $expectedPrepareObjectSql4], + [$select5, $expectedPrepareSql5, $expectedParams5, $expectedSql5, $expectedPrepareObjectSql5], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/OracleTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/OracleTest.php new file mode 100644 index 00000000..1b1987b2 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/OracleTest.php @@ -0,0 +1,31 @@ +getDecorators(); + + $type = key($decorators); + $decorator = current($decorators); + self::assertEquals('Zend\Db\Sql\Select', $type); + self::assertInstanceOf('Zend\Db\Sql\Platform\Oracle\SelectDecorator', $decorator); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php new file mode 100644 index 00000000..03bb21f5 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Oracle/SelectDecoratorTest.php @@ -0,0 +1,144 @@ +getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $driver->expects($this->exactly($expectedFormatParamCount)) + ->method('formatParameterName') + ->will($this->returnValue('?')); + + // test + $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([ + $driver, + new OraclePlatform(), + ]) + ->getMock(); + + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any()) + ->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $statement->expects($this->once())->method('setSql')->with($expectedSql); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + $selectDecorator->prepareStatement($adapter, $statement); + + self::assertEquals($expectedParams, $parameterContainer->getNamedArray()); + } + + // @codingStandardsIgnoreStart + /** + * @testdox integration test: Testing SelectDecorator will use Select to produce properly Oracle + * dialect sql statements + * @covers \Zend\Db\Sql\Platform\Oracle\SelectDecorator::getSqlString + * @dataProvider dataProvider + */ + // @codingStandardsIgnoreEnd + public function testGetSqlString(Select $select, $ignored, $alsoIgnored, $expectedSql) + { + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any()) + ->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + self::assertEquals($expectedSql, $selectDecorator->getSqlString(new OraclePlatform)); + } + + /** + * Data provider for testGetSqlString + * + * @return array + */ + public function dataProvider() + { + $select0 = new Select; + $select0->from(['x' => 'foo']); + $expectedSql0 = 'SELECT "x".* FROM "foo" "x"'; + $expectedFormatParamCount0 = 0; + + $select1a = new Select('test'); + $select1b = new Select(['a' => $select1a]); + $select1 = new Select(['b' => $select1b]); + $expectedSql1 = 'SELECT "b".* FROM (SELECT "a".* FROM (SELECT "test".* FROM "test") "a") "b"'; + $expectedFormatParamCount1 = 0; + + $select2a = new Select('test'); + $select2a->limit(2); + $select2b = new Select(['a' => $select2a]); + $select2 = new Select(['b' => $select2b]); + // @codingStandardsIgnoreStart + $expectedSql2_1 = 'SELECT "b".* FROM (SELECT "a".* FROM (SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "test".* FROM "test" ) b WHERE rownum <= (:offset2+:limit2)) WHERE b_rownum >= (:offset2 + 1)) "a") "b"'; + $expectedSql2_2 = 'SELECT "b".* FROM (SELECT "a".* FROM (SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "test".* FROM "test" ) b WHERE rownum <= (0+2)) WHERE b_rownum >= (0 + 1)) "a") "b"'; + // @codingStandardsIgnoreEnd + $expectedFormatParamCount2 = 0; + $expectedParams2 = ['offset2' => 0, 'limit2' => 2]; + + $select3a = new Select('test'); + $select3a->offset(2); + $select3b = new Select(['a' => $select3a]); + $select3 = new Select(['b' => $select3b]); + // @codingStandardsIgnoreStart + $expectedSql3_1 = 'SELECT "b".* FROM (SELECT "a".* FROM (SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "test".* FROM "test" ) b ) WHERE b_rownum > (:offset2)) "a") "b"'; + $expectedSql3_2 = 'SELECT "b".* FROM (SELECT "a".* FROM (SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "test".* FROM "test" ) b ) WHERE b_rownum > (2)) "a") "b"'; + // @codingStandardsIgnoreEnd + $expectedFormatParamCount3 = 0; + $expectedParams3 = ['offset2' => 2]; + + $select4a = new Select('test'); + $select4a->limit(2); + $select4a->offset(2); + $select4b = new Select(['a' => $select4a]); + $select4 = new Select(['b' => $select4b]); + // @codingStandardsIgnoreStart + $expectedSql4_1 = 'SELECT "b".* FROM (SELECT "a".* FROM (SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "test".* FROM "test" ) b WHERE rownum <= (:offset2+:limit2)) WHERE b_rownum >= (:offset2 + 1)) "a") "b"'; + $expectedSql4_2 = 'SELECT "b".* FROM (SELECT "a".* FROM (SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "test".* FROM "test" ) b WHERE rownum <= (2+2)) WHERE b_rownum >= (2 + 1)) "a") "b"'; + // @codingStandardsIgnoreEnd + $expectedFormatParamCount4 = 0; + $expectedParams4 = ['offset2' => 2, 'limit2' => 2]; + + return [ + [$select0, $expectedSql0, [], $expectedSql0, $expectedFormatParamCount0], + [$select1, $expectedSql1, [], $expectedSql1, $expectedFormatParamCount1], + [$select2, $expectedSql2_1, $expectedParams2, $expectedSql2_2, $expectedFormatParamCount2], + [$select3, $expectedSql3_1, $expectedParams3, $expectedSql3_2, $expectedFormatParamCount3], + [$select4, $expectedSql4_1, $expectedParams4, $expectedSql4_2, $expectedFormatParamCount4], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/PlatformTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/PlatformTest.php new file mode 100644 index 00000000..574918ee --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/PlatformTest.php @@ -0,0 +1,126 @@ +resolveAdapter('sql92'); + $platform = new Platform($adapter); + + $reflectionMethod = new ReflectionMethod($platform, 'resolvePlatform'); + + $reflectionMethod->setAccessible(true); + + self::assertEquals($adapter->getPlatform(), $reflectionMethod->invoke($platform, null)); + } + + public function testResolvePlatformName() + { + $platform = new Platform($this->resolveAdapter('sql92')); + + $reflectionMethod = new ReflectionMethod($platform, 'resolvePlatformName'); + + $reflectionMethod->setAccessible(true); + + self::assertEquals('mysql', $reflectionMethod->invoke($platform, new TestAsset\TrustingMysqlPlatform())); + self::assertEquals('sqlserver', $reflectionMethod->invoke( + $platform, + new TestAsset\TrustingSqlServerPlatform() + )); + self::assertEquals('oracle', $reflectionMethod->invoke($platform, new TestAsset\TrustingOraclePlatform())); + self::assertEquals('sql92', $reflectionMethod->invoke($platform, new TestAsset\TrustingSql92Platform())); + } + + /** + * @group 6890 + */ + public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatform() + { + $adapter = $this->resolveAdapter('sql92'); + $reflectionProperty = new \ReflectionProperty($adapter, 'platform'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($adapter, null); + + $platform = new Platform($adapter); + $reflectionMethod = new ReflectionMethod($platform, 'resolvePlatform'); + + $reflectionMethod->setAccessible(true); + + $this->expectException('Zend\Db\Sql\Exception\RuntimeException'); + $this->expectExceptionMessage('$this->defaultPlatform was not set'); + + $reflectionMethod->invoke($platform, null); + } + + /** + * @group 6890 + */ + public function testAbstractPlatformCrashesGracefullyOnMissingDefaultPlatformWithGetDecorators() + { + $adapter = $this->resolveAdapter('sql92'); + $reflectionProperty = new \ReflectionProperty($adapter, 'platform'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($adapter, null); + + $platform = new Platform($adapter); + $reflectionMethod = new ReflectionMethod($platform, 'resolvePlatform'); + + $reflectionMethod->setAccessible(true); + + $this->expectException('Zend\Db\Sql\Exception\RuntimeException'); + $this->expectExceptionMessage('$this->defaultPlatform was not set'); + + $platform->getDecorators(); + } + + /** + * @param string $platformName + * + * @return Adapter + */ + protected function resolveAdapter($platformName) + { + $platform = null; + + switch ($platformName) { + case 'sql92': + $platform = new TestAsset\TrustingSql92Platform(); + break; + case 'MySql': + $platform = new TestAsset\TrustingMysqlPlatform(); + break; + case 'Oracle': + $platform = new TestAsset\TrustingOraclePlatform(); + break; + case 'SqlServer': + $platform = new TestAsset\TrustingSqlServerPlatform(); + break; + } + + /* @var $mockDriver \Zend\Db\Adapter\Driver\DriverInterface|\PHPUnit_Framework_MockObject_MockObject */ + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnCallback(function () { + return new StatementContainer(); + })); + + return new Adapter($mockDriver, $platform); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php new file mode 100644 index 00000000..00aff16e --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/Ddl/CreateTableDecoratorTest.php @@ -0,0 +1,46 @@ +setSubject($ct)->getSqlString()); + + $ct = new CreateTable('foo', true); + self::assertEquals("CREATE TABLE \"#foo\" ( \n)", $ctd->setSubject($ct)->getSqlString()); + + $ct = new CreateTable('foo'); + $ct->addColumn(new Column('bar')); + self::assertEquals( + "CREATE TABLE \"foo\" ( \n \"bar\" INTEGER NOT NULL \n)", + $ctd->setSubject($ct)->getSqlString() + ); + + $ct = new CreateTable('foo', true); + $ct->addColumn(new Column('bar')); + self::assertEquals( + "CREATE TABLE \"#foo\" ( \n \"bar\" INTEGER NOT NULL \n)", + $ctd->setSubject($ct)->getSqlString() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php new file mode 100644 index 00000000..fc84d661 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SelectDecoratorTest.php @@ -0,0 +1,142 @@ +getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $driver->expects($this->exactly($expectedFormatParamCount))->method('formatParameterName') + ->will($this->returnValue('?')); + + // test + $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([ + $driver, + new SqlServerPlatform(), + ]) + ->getMock(); + + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $statement->expects($this->once())->method('setSql')->with($expectedSql); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + $selectDecorator->prepareStatement($adapter, $statement); + + self::assertEquals($expectedParams, $parameterContainer->getNamedArray()); + } + + /** + * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare + * a proper limit/offset sql statement + * @covers \Zend\Db\Sql\Platform\SqlServer\SelectDecorator::getSqlString + * @covers \Zend\Db\Sql\Platform\SqlServer\SelectDecorator::processLimitOffset + * @dataProvider dataProvider + */ + public function testGetSqlString(Select $select, $ignored, $alsoIgnored, $expectedSql) + { + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + self::assertEquals($expectedSql, $selectDecorator->getSqlString(new SqlServerPlatform)); + } + + public function dataProvider() + { + $select0 = new Select; + $select0->from('foo')->columns(['bar', 'baz'])->order('bar')->limit(5)->offset(10); + // @codingStandardsIgnoreStart + $expectedPrepareSql0 = 'SELECT [bar], [baz] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [baz], ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?'; + // @codingStandardsIgnoreEnd + $expectedParams0 = ['offset' => 10, 'limit' => 5, 'offsetForSum' => 10]; + // @codingStandardsIgnoreStart + $expectedSql0 = 'SELECT [bar], [baz] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [baz], ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 5+10'; + // @codingStandardsIgnoreEnd + $expectedFormatParamCount0 = 3; + + $select1 = new Select; + $select1->from('foo')->columns(['bar', 'bam' => 'baz'])->limit(5)->offset(10); + // @codingStandardsIgnoreStart + $expectedPrepareSql1 = 'SELECT [bar], [bam] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [bam], ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?'; + // @codingStandardsIgnoreEnd + $expectedParams1 = ['offset' => 10, 'limit' => 5, 'offsetForSum' => 10]; + // @codingStandardsIgnoreStart + $expectedSql1 = 'SELECT [bar], [bam] FROM ( SELECT [foo].[bar] AS [bar], [foo].[baz] AS [bam], ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 5+10'; + // @codingStandardsIgnoreEnd + $expectedFormatParamCount1 = 3; + + $select2 = new Select; + $select2->from('foo')->order('bar')->limit(5)->offset(10); + // @codingStandardsIgnoreStart + $expectedPrepareSql2 = 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?'; + // @codingStandardsIgnoreEnd + $expectedParams2 = ['offset' => 10, 'limit' => 5, 'offsetForSum' => 10]; + // @codingStandardsIgnoreStart + $expectedSql2 = 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY [bar] ASC) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 5+10'; + // @codingStandardsIgnoreEnd + $expectedFormatParamCount2 = 3; + + $select3 = new Select; + $select3->from('foo'); + $expectedPrepareSql3 = 'SELECT [foo].* FROM [foo]'; + $expectedParams3 = []; + $expectedSql3 = 'SELECT [foo].* FROM [foo]'; + $expectedFormatParamCount3 = 0; + + $select4 = new Select; + $select4->from('foo')->columns([new Expression('DISTINCT(bar) as bar')])->limit(5)->offset(10); + // @codingStandardsIgnoreStart + $expectedPrepareSql4 = 'SELECT DISTINCT(bar) as bar FROM ( SELECT DISTINCT(bar) as bar, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?'; + // @codingStandardsIgnoreEnd + $expectedParams4 = ['offset' => 10, 'limit' => 5, 'offsetForSum' => 10]; + // @codingStandardsIgnoreStart + $expectedSql4 = 'SELECT DISTINCT(bar) as bar FROM ( SELECT DISTINCT(bar) as bar, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 5+10'; + // @codingStandardsIgnoreEnd + $expectedFormatParamCount4 = 3; + + return [ + [$select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0, $expectedFormatParamCount0], + [$select1, $expectedPrepareSql1, $expectedParams1, $expectedSql1, $expectedFormatParamCount1], + [$select2, $expectedPrepareSql2, $expectedParams2, $expectedSql2, $expectedFormatParamCount2], + [$select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3, $expectedFormatParamCount3], + [$select4, $expectedPrepareSql4, $expectedParams4, $expectedSql4, $expectedFormatParamCount4], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SqlServerTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SqlServerTest.php new file mode 100644 index 00000000..ff86eb7a --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/SqlServer/SqlServerTest.php @@ -0,0 +1,31 @@ +getDecorators(); + + $type = key($decorators); + $decorator = current($decorators); + self::assertEquals('Zend\Db\Sql\Select', $type); + self::assertInstanceOf('Zend\Db\Sql\Platform\SqlServer\SelectDecorator', $decorator); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php new file mode 100644 index 00000000..94edce2f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SelectDecoratorTest.php @@ -0,0 +1,160 @@ +getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $driver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + + // test + $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([ + $driver, + new SqlitePlatform(), + ]) + ->getMock(); + + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $statement->expects($this->once())->method('setSql')->with($expectedSql); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + $selectDecorator->prepareStatement($adapter, $statement); + + self::assertEquals($expectedParams, $parameterContainer->getNamedArray()); + } + + /** + * @testdox integration test: Testing SelectDecorator will use Select an internal state to prepare a proper combine + * statement + * @covers \Zend\Db\Sql\Platform\Sqlite\SelectDecorator::getSqlString + * @covers \Zend\Db\Sql\Platform\Sqlite\SelectDecorator::processCombine + * @dataProvider dataProviderUnionSyntaxFromCombine + */ + public function testGetSqlStringPreparesUnionSyntaxFromCombine(Select $select, $ignore, $alsoIgnore, $expectedSql) + { + $parameterContainer = new ParameterContainer; + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + + $selectDecorator = new SelectDecorator; + $selectDecorator->setSubject($select); + self::assertEquals($expectedSql, $selectDecorator->getSqlString(new SqlitePlatform)); + } + + /** + * Create a data provider for union syntax that would come from combine + * + * @return mixed[] + */ + public function dataProviderUnionSyntaxFromCombine() + { + $select0 = new Select; + $select0->from('foo'); + $select1 = clone $select0; + $select0->combine($select1); + + $expectedPrepareSql0 = ' SELECT "foo".* FROM "foo" UNION SELECT "foo".* FROM "foo"'; + $expectedParams0 = []; + $expectedSql0 = ' SELECT "foo".* FROM "foo" UNION SELECT "foo".* FROM "foo"'; + + // nested single limit & offset in field param + $nestedSelect0 = new Select; + $nestedSelect0->from('foo1') + ->columns([ + 'cnt' => new Expression('count(foo1.id)') + ])->limit(100)->offset(500); + + $select3 = new Select; + $select3->from('foo') + ->columns([ + 'res' => $nestedSelect0, + ]) + ->limit(10)->offset(50); + + $expectedPrepareSql3 = + ' SELECT ( SELECT count(foo1.id) AS "cnt" FROM "foo1" LIMIT ? OFFSET ?) AS "res"' + . ' FROM "foo" LIMIT ? OFFSET ?'; + $expectedParams3 = [ + 'subselect1limit' => 100, + 'subselect1offset' => 500, + 'limit' => 10, + 'offset' => 50 + ]; + $expectedSql3 = ' SELECT ( SELECT count(foo1.id) AS "cnt"' + . ' FROM "foo1" LIMIT 100 OFFSET 500) AS "res"' + . ' FROM "foo" LIMIT 10 OFFSET 50'; + // multiple nested query + $nestedSelect0 = new Select; + $nestedSelect0->from('foo1') + ->columns([ + 'cnt' => new Expression('count(foo1.id)') + ])->limit(100)->offset(500); + + $nestedSelect1 = new Select; + $nestedSelect1->from('foo2') + ->columns([ + 'cnt' => new Expression('count(foo2.id)') + ])->limit(50)->offset(101); + + $select4 = new Select; + $select4->from('foo') + ->columns([ + 'res' => $nestedSelect0, + 'res0' => $nestedSelect1 + ]) + ->limit(10)->offset(5); + + $expectedPrepareSql4 = + ' SELECT ( SELECT count(foo1.id) AS "cnt" FROM "foo1" LIMIT ? OFFSET ?) AS "res",' + . ' ( SELECT count(foo2.id) AS "cnt" FROM "foo2" LIMIT ? OFFSET ?) AS "res0"' + . ' FROM "foo" LIMIT ? OFFSET ?'; + $expectedParams4 = [ + 'subselect1limit' => 100, + 'subselect1offset' => 500, + 'subselect2limit' => 50, + 'subselect2offset' => 101, + 'limit' => 10, + 'offset' => 5 + ]; + $expectedSql4 = ' SELECT ( SELECT count(foo1.id) AS "cnt" FROM "foo1" LIMIT 100 OFFSET 500) AS "res",' + . ' ( SELECT count(foo2.id) AS "cnt" FROM "foo2" LIMIT 50 OFFSET 101) AS "res0"' + . ' FROM "foo" LIMIT 10 OFFSET 5'; + + return [ + [$select0, $expectedPrepareSql0, $expectedParams0, $expectedSql0], + [$select3, $expectedPrepareSql3, $expectedParams3, $expectedSql3], + [$select4, $expectedPrepareSql4, $expectedParams4, $expectedSql4], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SqliteTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SqliteTest.php new file mode 100644 index 00000000..4b312f0e --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Platform/Sqlite/SqliteTest.php @@ -0,0 +1,31 @@ +getDecorators(); + + $type = key($decorators); + $decorator = current($decorators); + self::assertEquals('Zend\Db\Sql\Select', $type); + self::assertInstanceOf('Zend\Db\Sql\Platform\Sqlite\SelectDecorator', $decorator); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/BetweenTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/BetweenTest.php new file mode 100644 index 00000000..c510bc55 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/BetweenTest.php @@ -0,0 +1,139 @@ +between = new Between(); + } + + /** + * @covers \Zend\Db\Sql\Predicate\Between::__construct + * @covers \Zend\Db\Sql\Predicate\Between::getIdentifier + * @covers \Zend\Db\Sql\Predicate\Between::getMinValue + * @covers \Zend\Db\Sql\Predicate\Between::getMaxValue + */ + public function testConstructorYieldsNullIdentifierMinimumAndMaximumValues() + { + self::assertNull($this->between->getIdentifier()); + self::assertNull($this->between->getMinValue()); + self::assertNull($this->between->getMaxValue()); + } + + /** + * @covers \Zend\Db\Sql\Predicate\Between::__construct + * @covers \Zend\Db\Sql\Predicate\Between::getIdentifier + * @covers \Zend\Db\Sql\Predicate\Between::getMinValue + * @covers \Zend\Db\Sql\Predicate\Between::getMaxValue + */ + public function testConstructorCanPassIdentifierMinimumAndMaximumValues() + { + $between = new Between('foo.bar', 1, 300); + self::assertEquals('foo.bar', $between->getIdentifier()); + self::assertSame(1, $between->getMinValue()); + self::assertSame(300, $between->getMaxValue()); + + $between = new Between('foo.bar', 0, 1); + self::assertEquals('foo.bar', $between->getIdentifier()); + self::assertSame(0, $between->getMinValue()); + self::assertSame(1, $between->getMaxValue()); + + $between = new Between('foo.bar', -1, 0); + self::assertEquals('foo.bar', $between->getIdentifier()); + self::assertSame(-1, $between->getMinValue()); + self::assertSame(0, $between->getMaxValue()); + } + + /** + * @covers \Zend\Db\Sql\Predicate\Between::getSpecification + */ + public function testSpecificationHasSaneDefaultValue() + { + self::assertEquals('%1$s BETWEEN %2$s AND %3$s', $this->between->getSpecification()); + } + + + + /** + * @covers \Zend\Db\Sql\Predicate\Between::setIdentifier + * @covers \Zend\Db\Sql\Predicate\Between::getIdentifier + */ + public function testIdentifierIsMutable() + { + $this->between->setIdentifier('foo.bar'); + self::assertEquals('foo.bar', $this->between->getIdentifier()); + } + + /** + * @covers \Zend\Db\Sql\Predicate\Between::setMinValue + * @covers \Zend\Db\Sql\Predicate\Between::getMinValue + */ + public function testMinValueIsMutable() + { + $this->between->setMinValue(10); + self::assertEquals(10, $this->between->getMinValue()); + } + + /** + * @covers \Zend\Db\Sql\Predicate\Between::setMaxValue + * @covers \Zend\Db\Sql\Predicate\Between::getMaxValue + */ + public function testMaxValueIsMutable() + { + $this->between->setMaxValue(10); + self::assertEquals(10, $this->between->getMaxValue()); + } + + /** + * @covers \Zend\Db\Sql\Predicate\Between::setSpecification + * @covers \Zend\Db\Sql\Predicate\Between::getSpecification + */ + public function testSpecificationIsMutable() + { + $this->between->setSpecification('%1$s IS INBETWEEN %2$s AND %3$s'); + self::assertEquals('%1$s IS INBETWEEN %2$s AND %3$s', $this->between->getSpecification()); + } + + /** + * @covers \Zend\Db\Sql\Predicate\Between::getExpressionData + */ + public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes() + { + $this->between->setIdentifier('foo.bar') + ->setMinValue(10) + ->setMaxValue(19); + $expected = [[ + $this->between->getSpecification(), + ['foo.bar', 10, 19], + [Between::TYPE_IDENTIFIER, Between::TYPE_VALUE, Between::TYPE_VALUE], + ]]; + self::assertEquals($expected, $this->between->getExpressionData()); + + $this->between->setIdentifier([10 => Between::TYPE_VALUE]) + ->setMinValue(['foo.bar' => Between::TYPE_IDENTIFIER]) + ->setMaxValue(['foo.baz' => Between::TYPE_IDENTIFIER]); + $expected = [[ + $this->between->getSpecification(), + [10, 'foo.bar', 'foo.baz'], + [Between::TYPE_VALUE, Between::TYPE_IDENTIFIER, Between::TYPE_IDENTIFIER], + ]]; + self::assertEquals($expected, $this->between->getExpressionData()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/ExpressionTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/ExpressionTest.php new file mode 100644 index 00000000..69140a77 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/ExpressionTest.php @@ -0,0 +1,183 @@ +getExpression()); + self::assertEmpty($expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassLiteralAndSingleScalarParameterToConstructor() + { + $expression = new Expression('foo.bar = ?', 'bar'); + self::assertEquals('foo.bar = ?', $expression->getExpression()); + self::assertEquals(['bar'], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassNoParameterToConstructor() + { + $expression = new Expression('foo.bar'); + self::assertEquals([], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassSingleNullParameterToConstructor() + { + $expression = new Expression('?', null); + self::assertEquals([null], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassSingleZeroParameterValueToConstructor() + { + $predicate = new Expression('?', 0); + self::assertEquals([0], $predicate->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassSinglePredicateParameterToConstructor() + { + $predicate = new IsNull('foo.baz'); + $expression = new Expression('?', $predicate); + self::assertEquals([$predicate], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassMultiScalarParametersToConstructor() + { + $expression = new Expression('? OR ?', 'foo', 'bar'); + self::assertEquals(['foo', 'bar'], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassMultiNullParametersToConstructor() + { + $expression = new Expression('? OR ?', null, null); + self::assertEquals([null, null], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassMultiPredicateParametersToConstructor() + { + $predicate = new IsNull('foo.baz'); + $expression = new Expression('? OR ?', $predicate, $predicate); + self::assertEquals([$predicate, $predicate], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassArrayOfOneScalarParameterToConstructor() + { + $expression = new Expression('?', ['foo']); + self::assertEquals(['foo'], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassArrayOfMultiScalarsParameterToConstructor() + { + $expression = new Expression('? OR ?', ['foo', 'bar']); + self::assertEquals(['foo', 'bar'], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassArrayOfOneNullParameterToConstructor() + { + $expression = new Expression('?', [null]); + self::assertEquals([null], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassArrayOfMultiNullsParameterToConstructor() + { + $expression = new Expression('? OR ?', [null, null]); + self::assertEquals([null, null], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassArrayOfOnePredicateParameterToConstructor() + { + $predicate = new IsNull('foo.baz'); + $expression = new Expression('?', [$predicate]); + self::assertEquals([$predicate], $expression->getParameters()); + } + + /** + * @group 6849 + */ + public function testCanPassArrayOfMultiPredicatesParameterToConstructor() + { + $predicate = new IsNull('foo.baz'); + $expression = new Expression('? OR ?', [$predicate, $predicate]); + self::assertEquals([$predicate, $predicate], $expression->getParameters()); + } + + public function testLiteralIsMutable() + { + $expression = new Expression(); + $expression->setExpression('foo.bar = ?'); + self::assertEquals('foo.bar = ?', $expression->getExpression()); + } + + public function testParameterIsMutable() + { + $expression = new Expression(); + $expression->setParameters(['foo', 'bar']); + self::assertEquals(['foo', 'bar'], $expression->getParameters()); + } + + public function testRetrievingWherePartsReturnsSpecificationArrayOfLiteralAndParametersAndArrayOfTypes() + { + $expression = new Expression(); + $expression->setExpression('foo.bar = ? AND id != ?') + ->setParameters(['foo', 'bar']); + $expected = [[ + 'foo.bar = %s AND id != %s', + ['foo', 'bar'], + [Expression::TYPE_VALUE, Expression::TYPE_VALUE], + ]]; + $test = $expression->getExpressionData(); + self::assertEquals($expected, $test, var_export($test, 1)); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/InTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/InTest.php new file mode 100644 index 00000000..58b78a7c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/InTest.php @@ -0,0 +1,127 @@ +getIdentifier()); + self::assertNull($in->getValueSet()); + } + + public function testCanPassIdentifierAndValueSetToConstructor() + { + $in = new In('foo.bar', [1, 2]); + self::assertEquals('foo.bar', $in->getIdentifier()); + self::assertEquals([1, 2], $in->getValueSet()); + } + + public function testCanPassIdentifierAndEmptyValueSetToConstructor() + { + $in = new In('foo.bar', []); + $this->assertEquals('foo.bar', $in->getIdentifier()); + $this->assertEquals([], $in->getValueSet()); + } + + public function testIdentifierIsMutable() + { + $in = new In(); + $in->setIdentifier('foo.bar'); + self::assertEquals('foo.bar', $in->getIdentifier()); + } + + public function testValueSetIsMutable() + { + $in = new In(); + $in->setValueSet([1, 2]); + self::assertEquals([1, 2], $in->getValueSet()); + } + + public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes() + { + $in = new In(); + $in->setIdentifier('foo.bar') + ->setValueSet([1, 2, 3]); + $expected = [[ + '%s IN (%s, %s, %s)', + ['foo.bar', 1, 2, 3], + [In::TYPE_IDENTIFIER, In::TYPE_VALUE, In::TYPE_VALUE, In::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + + $in->setIdentifier('foo.bar') + ->setValueSet([ + [1 => In::TYPE_LITERAL], + [2 => In::TYPE_VALUE], + [3 => In::TYPE_LITERAL], + ]); + $expected = [[ + '%s IN (%s, %s, %s)', + ['foo.bar', 1, 2, 3], + [In::TYPE_IDENTIFIER, In::TYPE_LITERAL, In::TYPE_VALUE, In::TYPE_LITERAL], + ]]; + $qqq = $in->getExpressionData(); + self::assertEquals($expected, $in->getExpressionData()); + } + + public function testGetExpressionDataWithSubselect() + { + $select = new Select; + $in = new In('foo', $select); + $expected = [[ + '%s IN %s', + ['foo', $select], + [$in::TYPE_IDENTIFIER, $in::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + } + + public function testGetExpressionDataWithEmptyValues() + { + $select = new Select; + $in = new In('foo', []); + $expected = [[ + '%s IN ()', + ['foo'], + [$in::TYPE_IDENTIFIER] + ]]; + $this->assertEquals($expected, $in->getExpressionData()); + } + + public function testGetExpressionDataWithSubselectAndIdentifier() + { + $select = new Select; + $in = new In('foo', $select); + $expected = [[ + '%s IN %s', + ['foo', $select], + [$in::TYPE_IDENTIFIER, $in::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + } + + public function testGetExpressionDataWithSubselectAndArrayIdentifier() + { + $select = new Select; + $in = new In(['foo', 'bar'], $select); + $expected = [[ + '(%s, %s) IN %s', + ['foo', 'bar', $select], + [$in::TYPE_IDENTIFIER, $in::TYPE_IDENTIFIER, $in::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/IsNullTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/IsNullTest.php new file mode 100644 index 00000000..810c6da9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/IsNullTest.php @@ -0,0 +1,61 @@ +getIdentifier()); + } + + public function testSpecificationHasSaneDefaultValue() + { + $isNotNull = new IsNotNull(); + self::assertEquals('%1$s IS NOT NULL', $isNotNull->getSpecification()); + } + + public function testCanPassIdentifierToConstructor() + { + $isNotNull = new IsNotNull(); + $isnull = new IsNotNull('foo.bar'); + self::assertEquals('foo.bar', $isnull->getIdentifier()); + } + + public function testIdentifierIsMutable() + { + $isNotNull = new IsNotNull(); + $isNotNull->setIdentifier('foo.bar'); + self::assertEquals('foo.bar', $isNotNull->getIdentifier()); + } + + public function testSpecificationIsMutable() + { + $isNotNull = new IsNotNull(); + $isNotNull->setSpecification('%1$s NOT NULL'); + self::assertEquals('%1$s NOT NULL', $isNotNull->getSpecification()); + } + + public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndArrayOfTypes() + { + $isNotNull = new IsNotNull(); + $isNotNull->setIdentifier('foo.bar'); + $expected = [[ + $isNotNull->getSpecification(), + ['foo.bar'], + [IsNotNull::TYPE_IDENTIFIER], + ]]; + self::assertEquals($expected, $isNotNull->getExpressionData()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LikeTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LikeTest.php new file mode 100644 index 00000000..9b3f781a --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LikeTest.php @@ -0,0 +1,68 @@ +getIdentifier()); + self::assertEquals('', $like->getLike()); + } + + public function testConstructWithArgs() + { + $like = new Like('bar', 'Foo%'); + self::assertEquals('bar', $like->getIdentifier()); + self::assertEquals('Foo%', $like->getLike()); + } + + public function testAccessorsMutators() + { + $like = new Like(); + $like->setIdentifier('bar'); + self::assertEquals('bar', $like->getIdentifier()); + $like->setLike('foo%'); + self::assertEquals('foo%', $like->getLike()); + $like->setSpecification('target = target'); + self::assertEquals('target = target', $like->getSpecification()); + } + + public function testGetExpressionData() + { + $like = new Like('bar', 'Foo%'); + self::assertEquals( + [ + ['%1$s LIKE %2$s', ['bar', 'Foo%'], [$like::TYPE_IDENTIFIER, $like::TYPE_VALUE]], + ], + $like->getExpressionData() + ); + + $like = new Like(['Foo%' => $like::TYPE_VALUE], ['bar' => $like::TYPE_IDENTIFIER]); + self::assertEquals( + [ + ['%1$s LIKE %2$s', ['Foo%', 'bar'], [$like::TYPE_VALUE, $like::TYPE_IDENTIFIER]], + ], + $like->getExpressionData() + ); + } + + public function testInstanceOfPerSetters() + { + $like = new Like(); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Like', $like->setIdentifier('bar')); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Like', $like->setSpecification('%1$s LIKE %2$s')); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Like', $like->setLike('foo%')); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LiteralTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LiteralTest.php new file mode 100644 index 00000000..955c0a9b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/LiteralTest.php @@ -0,0 +1,34 @@ +setLiteral('foo')); + } + + public function testGetLiteral() + { + $literal = new Literal('bar'); + self::assertEquals('bar', $literal->getLiteral()); + } + + public function testGetExpressionData() + { + $literal = new Literal('bar'); + self::assertEquals([['bar', [], []]], $literal->getExpressionData()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotBetweenTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotBetweenTest.php new file mode 100644 index 00000000..241fc71b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotBetweenTest.php @@ -0,0 +1,60 @@ +notBetween = new NotBetween(); + } + + /** + * @covers \Zend\Db\Sql\Predicate\NotBetween::getSpecification + */ + public function testSpecificationHasSameDefaultValue() + { + self::assertEquals('%1$s NOT BETWEEN %2$s AND %3$s', $this->notBetween->getSpecification()); + } + + /** + * @covers \Zend\Db\Sql\Predicate\NotBetween::getExpressionData + */ + public function testRetrievingWherePartsReturnsSpecificationArrayOfIdentifierAndValuesAndArrayOfTypes() + { + $this->notBetween->setIdentifier('foo.bar') + ->setMinValue(10) + ->setMaxValue(19); + $expected = [[ + $this->notBetween->getSpecification(), + ['foo.bar', 10, 19], + [NotBetween::TYPE_IDENTIFIER, NotBetween::TYPE_VALUE, NotBetween::TYPE_VALUE], + ]]; + self::assertEquals($expected, $this->notBetween->getExpressionData()); + + $this->notBetween->setIdentifier([10 => NotBetween::TYPE_VALUE]) + ->setMinValue(['foo.bar' => NotBetween::TYPE_IDENTIFIER]) + ->setMaxValue(['foo.baz' => NotBetween::TYPE_IDENTIFIER]); + $expected = [[ + $this->notBetween->getSpecification(), + [10, 'foo.bar', 'foo.baz'], + [NotBetween::TYPE_VALUE, NotBetween::TYPE_IDENTIFIER, NotBetween::TYPE_IDENTIFIER], + ]]; + self::assertEquals($expected, $this->notBetween->getExpressionData()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotInTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotInTest.php new file mode 100644 index 00000000..43f620a1 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotInTest.php @@ -0,0 +1,66 @@ +setIdentifier('foo.bar') + ->setValueSet([1, 2, 3]); + $expected = [[ + '%s NOT IN (%s, %s, %s)', + ['foo.bar', 1, 2, 3], + [NotIn::TYPE_IDENTIFIER, NotIn::TYPE_VALUE, NotIn::TYPE_VALUE, NotIn::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + } + + public function testGetExpressionDataWithSubselect() + { + $select = new Select; + $in = new NotIn('foo', $select); + $expected = [[ + '%s NOT IN %s', + ['foo', $select], + [$in::TYPE_IDENTIFIER, $in::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + } + + public function testGetExpressionDataWithSubselectAndIdentifier() + { + $select = new Select; + $in = new NotIn('foo', $select); + $expected = [[ + '%s NOT IN %s', + ['foo', $select], + [$in::TYPE_IDENTIFIER, $in::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + } + + public function testGetExpressionDataWithSubselectAndArrayIdentifier() + { + $select = new Select; + $in = new NotIn(['foo', 'bar'], $select); + $expected = [[ + '(%s, %s) NOT IN %s', + ['foo', 'bar', $select], + [$in::TYPE_IDENTIFIER, $in::TYPE_IDENTIFIER, $in::TYPE_VALUE], + ]]; + self::assertEquals($expected, $in->getExpressionData()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotLikeTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotLikeTest.php new file mode 100644 index 00000000..44d4614d --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/NotLikeTest.php @@ -0,0 +1,64 @@ +getIdentifier()); + self::assertEquals('', $notLike->getLike()); + } + + public function testConstructWithArgs() + { + $notLike = new NotLike('bar', 'Foo%'); + self::assertEquals('bar', $notLike->getIdentifier()); + self::assertEquals('Foo%', $notLike->getLike()); + } + + public function testAccessorsMutators() + { + $notLike = new NotLike(); + $notLike->setIdentifier('bar'); + self::assertEquals('bar', $notLike->getIdentifier()); + $notLike->setLike('foo%'); + self::assertEquals('foo%', $notLike->getLike()); + $notLike->setSpecification('target = target'); + self::assertEquals('target = target', $notLike->getSpecification()); + } + + public function testGetExpressionData() + { + $notLike = new NotLike('bar', 'Foo%'); + self::assertEquals( + [ + [ + '%1$s NOT LIKE %2$s', + ['bar', 'Foo%'], + [$notLike::TYPE_IDENTIFIER, $notLike::TYPE_VALUE], + ], + ], + $notLike->getExpressionData() + ); + } + + public function testInstanceOfPerSetters() + { + $notLike = new NotLike(); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Like', $notLike->setIdentifier('bar')); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Like', $notLike->setSpecification('%1$s NOT LIKE %2$s')); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Like', $notLike->setLike('foo%')); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/OperatorTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/OperatorTest.php new file mode 100644 index 00000000..3713e14f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/OperatorTest.php @@ -0,0 +1,103 @@ +getLeft()); + self::assertNull($operator->getRight()); + } + + public function testEmptyConstructorYieldsDefaultsForOperatorAndLeftAndRightTypes() + { + $operator = new Operator(); + self::assertEquals(Operator::OP_EQ, $operator->getOperator()); + self::assertEquals(Operator::TYPE_IDENTIFIER, $operator->getLeftType()); + self::assertEquals(Operator::TYPE_VALUE, $operator->getRightType()); + } + + public function testCanPassAllValuesToConstructor() + { + $operator = new Operator('bar', '>=', 'foo.bar', Operator::TYPE_VALUE, Operator::TYPE_IDENTIFIER); + self::assertEquals(Operator::OP_GTE, $operator->getOperator()); + self::assertEquals('bar', $operator->getLeft()); + self::assertEquals('foo.bar', $operator->getRight()); + self::assertEquals(Operator::TYPE_VALUE, $operator->getLeftType()); + self::assertEquals(Operator::TYPE_IDENTIFIER, $operator->getRightType()); + + $operator = new Operator(['bar' => Operator::TYPE_VALUE], '>=', ['foo.bar' => Operator::TYPE_IDENTIFIER]); + self::assertEquals(Operator::OP_GTE, $operator->getOperator()); + self::assertEquals(['bar' => Operator::TYPE_VALUE], $operator->getLeft()); + self::assertEquals(['foo.bar' => Operator::TYPE_IDENTIFIER], $operator->getRight()); + self::assertEquals(Operator::TYPE_VALUE, $operator->getLeftType()); + self::assertEquals(Operator::TYPE_IDENTIFIER, $operator->getRightType()); + + $operator = new Operator('bar', '>=', 0); + self::assertEquals(0, $operator->getRight()); + } + + public function testLeftIsMutable() + { + $operator = new Operator(); + $operator->setLeft('foo.bar'); + self::assertEquals('foo.bar', $operator->getLeft()); + } + + public function testRightIsMutable() + { + $operator = new Operator(); + $operator->setRight('bar'); + self::assertEquals('bar', $operator->getRight()); + } + + public function testLeftTypeIsMutable() + { + $operator = new Operator(); + $operator->setLeftType(Operator::TYPE_VALUE); + self::assertEquals(Operator::TYPE_VALUE, $operator->getLeftType()); + } + + public function testRightTypeIsMutable() + { + $operator = new Operator(); + $operator->setRightType(Operator::TYPE_IDENTIFIER); + self::assertEquals(Operator::TYPE_IDENTIFIER, $operator->getRightType()); + } + + public function testOperatorIsMutable() + { + $operator = new Operator(); + $operator->setOperator(Operator::OP_LTE); + self::assertEquals(Operator::OP_LTE, $operator->getOperator()); + } + + public function testRetrievingWherePartsReturnsSpecificationArrayOfLeftAndRightAndArrayOfTypes() + { + $operator = new Operator(); + $operator->setLeft('foo') + ->setOperator('>=') + ->setRight('foo.bar') + ->setLeftType(Operator::TYPE_VALUE) + ->setRightType(Operator::TYPE_IDENTIFIER); + $expected = [[ + '%s >= %s', + ['foo', 'foo.bar'], + [Operator::TYPE_VALUE, Operator::TYPE_IDENTIFIER], + ]]; + $test = $operator->getExpressionData(); + self::assertEquals($expected, $test, var_export($test, 1)); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateSetTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateSetTest.php new file mode 100644 index 00000000..08a73d8b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateSetTest.php @@ -0,0 +1,133 @@ +addPredicate(new IsNull('foo')) + ->addPredicate(new IsNull('bar')); + $parts = $predicateSet->getExpressionData(); + self::assertCount(3, $parts); + self::assertContains('AND', $parts[1]); + self::assertNotContains('OR', $parts[1]); + } + + public function testCanPassPredicatesAndDefaultCombinationViaConstructor() + { + $predicateSet = new PredicateSet(); + $set = new PredicateSet([ + new IsNull('foo'), + new IsNull('bar'), + ], 'OR'); + $parts = $set->getExpressionData(); + self::assertCount(3, $parts); + self::assertContains('OR', $parts[1]); + self::assertNotContains('AND', $parts[1]); + } + + public function testCanPassBothPredicateAndCombinationToAddPredicate() + { + $predicateSet = new PredicateSet(); + $predicateSet->addPredicate(new IsNull('foo'), 'OR') + ->addPredicate(new IsNull('bar'), 'AND') + ->addPredicate(new IsNull('baz'), 'OR') + ->addPredicate(new IsNull('bat'), 'AND'); + $parts = $predicateSet->getExpressionData(); + self::assertCount(7, $parts); + + self::assertNotContains('OR', $parts[1], var_export($parts, 1)); + self::assertContains('AND', $parts[1]); + + self::assertContains('OR', $parts[3]); + self::assertNotContains('AND', $parts[3]); + + self::assertNotContains('OR', $parts[5]); + self::assertContains('AND', $parts[5]); + } + + public function testCanUseOrPredicateAndAndPredicateMethods() + { + $predicateSet = new PredicateSet(); + $predicateSet->orPredicate(new IsNull('foo')) + ->andPredicate(new IsNull('bar')) + ->orPredicate(new IsNull('baz')) + ->andPredicate(new IsNull('bat')); + $parts = $predicateSet->getExpressionData(); + self::assertCount(7, $parts); + + self::assertNotContains('OR', $parts[1], var_export($parts, 1)); + self::assertContains('AND', $parts[1]); + + self::assertContains('OR', $parts[3]); + self::assertNotContains('AND', $parts[3]); + + self::assertNotContains('OR', $parts[5]); + self::assertContains('AND', $parts[5]); + } + + /** + * @covers \Zend\Db\Sql\Predicate\PredicateSet::addPredicates + */ + public function testAddPredicates() + { + $predicateSet = new PredicateSet(); + + $predicateSet->addPredicates('x = y'); + $predicateSet->addPredicates(['foo > ?' => 5]); + $predicateSet->addPredicates(['id' => 2]); + $predicateSet->addPredicates(['a = b'], PredicateSet::OP_OR); + $predicateSet->addPredicates(['c1' => null]); + $predicateSet->addPredicates(['c2' => [1, 2, 3]]); + $predicateSet->addPredicates([new \Zend\Db\Sql\Predicate\IsNotNull('c3')]); + + $predicates = $this->readAttribute($predicateSet, 'predicates'); + self::assertEquals('AND', $predicates[0][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]); + + self::assertEquals('AND', $predicates[1][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[1][1]); + + self::assertEquals('AND', $predicates[2][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[2][1]); + + self::assertEquals('OR', $predicates[3][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[3][1]); + + self::assertEquals('AND', $predicates[4][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\IsNull', $predicates[4][1]); + + self::assertEquals('AND', $predicates[5][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\In', $predicates[5][1]); + + self::assertEquals('AND', $predicates[6][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\IsNotNull', $predicates[6][1]); + + $predicateSet->addPredicates(function ($what) use ($predicateSet) { + self::assertSame($predicateSet, $what); + }); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Predicate cannot be null'); + $predicateSet->addPredicates(null); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateTest.php new file mode 100644 index 00000000..a81f0afa --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/Predicate/PredicateTest.php @@ -0,0 +1,287 @@ +equalTo('foo.bar', 'bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s = %s', $parts[0]); + self::assertContains(['foo.bar', 'bar'], $parts[0]); + } + + public function testNotEqualToCreatesOperatorPredicate() + { + $predicate = new Predicate(); + $predicate->notEqualTo('foo.bar', 'bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s != %s', $parts[0]); + self::assertContains(['foo.bar', 'bar'], $parts[0]); + } + + + public function testLessThanCreatesOperatorPredicate() + { + $predicate = new Predicate(); + $predicate->lessThan('foo.bar', 'bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s < %s', $parts[0]); + self::assertContains(['foo.bar', 'bar'], $parts[0]); + } + + public function testGreaterThanCreatesOperatorPredicate() + { + $predicate = new Predicate(); + $predicate->greaterThan('foo.bar', 'bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s > %s', $parts[0]); + self::assertContains(['foo.bar', 'bar'], $parts[0]); + } + + public function testLessThanOrEqualToCreatesOperatorPredicate() + { + $predicate = new Predicate(); + $predicate->lessThanOrEqualTo('foo.bar', 'bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s <= %s', $parts[0]); + self::assertContains(['foo.bar', 'bar'], $parts[0]); + } + + public function testGreaterThanOrEqualToCreatesOperatorPredicate() + { + $predicate = new Predicate(); + $predicate->greaterThanOrEqualTo('foo.bar', 'bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s >= %s', $parts[0]); + self::assertContains(['foo.bar', 'bar'], $parts[0]); + } + + public function testLikeCreatesLikePredicate() + { + $predicate = new Predicate(); + $predicate->like('foo.bar', 'bar%'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%1$s LIKE %2$s', $parts[0]); + self::assertContains(['foo.bar', 'bar%'], $parts[0]); + } + + public function testNotLikeCreatesLikePredicate() + { + $predicate = new Predicate(); + $predicate->notLike('foo.bar', 'bar%'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%1$s NOT LIKE %2$s', $parts[0]); + self::assertContains(['foo.bar', 'bar%'], $parts[0]); + } + + public function testLiteralCreatesLiteralPredicate() + { + $predicate = new Predicate(); + $predicate->literal('foo.bar = ?', 'bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('foo.bar = %s', $parts[0]); + self::assertContains(['bar'], $parts[0]); + } + + public function testIsNullCreatesIsNullPredicate() + { + $predicate = new Predicate(); + $predicate->isNull('foo.bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%1$s IS NULL', $parts[0]); + self::assertContains(['foo.bar'], $parts[0]); + } + + public function testIsNotNullCreatesIsNotNullPredicate() + { + $predicate = new Predicate(); + $predicate->isNotNull('foo.bar'); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%1$s IS NOT NULL', $parts[0]); + self::assertContains(['foo.bar'], $parts[0]); + } + + public function testInCreatesInPredicate() + { + $predicate = new Predicate(); + $predicate->in('foo.bar', ['foo', 'bar']); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s IN (%s, %s)', $parts[0]); + self::assertContains(['foo.bar', 'foo', 'bar'], $parts[0]); + } + + public function testNotInCreatesNotInPredicate() + { + $predicate = new Predicate(); + $predicate->notIn('foo.bar', ['foo', 'bar']); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%s NOT IN (%s, %s)', $parts[0]); + self::assertContains(['foo.bar', 'foo', 'bar'], $parts[0]); + } + + public function testBetweenCreatesBetweenPredicate() + { + $predicate = new Predicate(); + $predicate->between('foo.bar', 1, 10); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%1$s BETWEEN %2$s AND %3$s', $parts[0]); + self::assertContains(['foo.bar', 1, 10], $parts[0]); + } + + public function testBetweenCreatesNotBetweenPredicate() + { + $predicate = new Predicate(); + $predicate->notBetween('foo.bar', 1, 10); + $parts = $predicate->getExpressionData(); + self::assertCount(1, $parts); + self::assertContains('%1$s NOT BETWEEN %2$s AND %3$s', $parts[0]); + self::assertContains(['foo.bar', 1, 10], $parts[0]); + } + + public function testCanChainPredicateFactoriesBetweenOperators() + { + $predicate = new Predicate(); + $predicate->isNull('foo.bar') + ->or + ->isNotNull('bar.baz') + ->and + ->equalTo('baz.bat', 'foo'); + $parts = $predicate->getExpressionData(); + self::assertCount(5, $parts); + + self::assertContains('%1$s IS NULL', $parts[0]); + self::assertContains(['foo.bar'], $parts[0]); + + self::assertEquals(' OR ', $parts[1]); + + self::assertContains('%1$s IS NOT NULL', $parts[2]); + self::assertContains(['bar.baz'], $parts[2]); + + self::assertEquals(' AND ', $parts[3]); + + self::assertContains('%s = %s', $parts[4]); + self::assertContains(['baz.bat', 'foo'], $parts[4]); + } + + public function testCanNestPredicates() + { + $predicate = new Predicate(); + $predicate->isNull('foo.bar') + ->nest() + ->isNotNull('bar.baz') + ->and + ->equalTo('baz.bat', 'foo') + ->unnest(); + $parts = $predicate->getExpressionData(); + + self::assertCount(7, $parts); + + self::assertContains('%1$s IS NULL', $parts[0]); + self::assertContains(['foo.bar'], $parts[0]); + + self::assertEquals(' AND ', $parts[1]); + + self::assertEquals('(', $parts[2]); + + self::assertContains('%1$s IS NOT NULL', $parts[3]); + self::assertContains(['bar.baz'], $parts[3]); + + self::assertEquals(' AND ', $parts[4]); + + self::assertContains('%s = %s', $parts[5]); + self::assertContains(['baz.bat', 'foo'], $parts[5]); + + self::assertEquals(')', $parts[6]); + } + + /** + * @testdox Unit test: Test expression() is chainable and returns proper values + */ + public function testExpression() + { + $predicate = new Predicate; + + // is chainable + self::assertSame($predicate, $predicate->expression('foo = ?', 0)); + // with parameter + self::assertEquals( + [['foo = %s', [0], [Expression::TYPE_VALUE]]], + $predicate->getExpressionData() + ); + } + + /** + * @testdox Unit test: Test expression() allows null $parameters + */ + public function testExpressionNullParameters() + { + $predicate = new Predicate; + + $predicate->expression('foo = bar'); + $predicates = $predicate->getPredicates(); + $expression = $predicates[0][1]; + self::assertEquals([null], $expression->getParameters()); + } + + /** + * @testdox Unit test: Test literal() is chainable, returns proper values, and is backwards compatible with 2.0.* + */ + public function testLiteral() + { + $predicate = new Predicate; + + // is chainable + self::assertSame($predicate, $predicate->literal('foo = bar')); + // with parameter + self::assertEquals( + [['foo = bar', [], []]], + $predicate->getExpressionData() + ); + + // test literal() is backwards-compatible, and works with with parameters + $predicate = new Predicate; + $predicate->expression('foo = ?', 'bar'); + // with parameter + self::assertEquals( + [['foo = %s', ['bar'], [Expression::TYPE_VALUE]]], + $predicate->getExpressionData() + ); + + // test literal() is backwards-compatible, and works with with parameters, even 0 which tests as false + $predicate = new Predicate; + $predicate->expression('foo = ?', 0); + // with parameter + self::assertEquals( + [['foo = %s', [0], [Expression::TYPE_VALUE]]], + $predicate->getExpressionData() + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/SelectTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/SelectTest.php new file mode 100644 index 00000000..0054b429 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/SelectTest.php @@ -0,0 +1,1490 @@ +getRawState('table')); + } + + /** + * @testdox unit test: Test from() returns Select object (is chainable) + * @covers \Zend\Db\Sql\Select::from + */ + public function testFrom() + { + $select = new Select; + $return = $select->from('foo', 'bar'); + self::assertSame($select, $return); + + return $return; + } + + /** + * @testdox unit test: Test getRawState() returns information populated via from() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testFrom + */ + public function testGetRawStateViaFrom(Select $select) + { + self::assertEquals('foo', $select->getRawState('table')); + } + + /** + * @testdox unit test: Test quantifier() returns Select object (is chainable) + * @covers \Zend\Db\Sql\Select::quantifier + */ + public function testQuantifier() + { + $select = new Select; + $return = $select->quantifier($select::QUANTIFIER_DISTINCT); + self::assertSame($select, $return); + return $return; + } + + /** + * @testdox unit test: Test getRawState() returns information populated via quantifier() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testQuantifier + */ + public function testGetRawStateViaQuantifier(Select $select) + { + self::assertEquals(Select::QUANTIFIER_DISTINCT, $select->getRawState('quantifier')); + } + + /** + * @testdox unit test: Test quantifier() accepts expression + * @covers \Zend\Db\Sql\Select::quantifier + */ + public function testQuantifierParameterExpressionInterface() + { + $expr = $this->getMockBuilder('Zend\Db\Sql\ExpressionInterface')->getMock(); + $select = new Select; + $select->quantifier($expr); + self::assertSame( + $expr, + $select->getRawState(Select::QUANTIFIER) + ); + } + + /** + * @testdox unit test: Test columns() returns Select object (is chainable) + * @covers \Zend\Db\Sql\Select::columns + */ + public function testColumns() + { + $select = new Select; + $return = $select->columns(['foo', 'bar']); + self::assertSame($select, $return); + + return $select; + } + + /** + * @testdox unit test: Test isTableReadOnly() returns correct state for read only + * @covers \Zend\Db\Sql\Select::isTableReadOnly + */ + public function testIsTableReadOnly() + { + $select = new Select('foo'); + self::assertTrue($select->isTableReadOnly()); + + $select = new Select; + self::assertFalse($select->isTableReadOnly()); + } + + /** + * @testdox unit test: Test getRawState() returns information populated via columns() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testColumns + */ + public function testGetRawStateViaColumns(Select $select) + { + self::assertEquals(['foo', 'bar'], $select->getRawState('columns')); + } + + /** + * @testdox unit test: Test join() returns same Select object (is chainable) + * @covers \Zend\Db\Sql\Select::join + */ + public function testJoin() + { + $select = new Select; + $return = $select->join('foo', 'x = y', Select::SQL_STAR, Select::JOIN_INNER); + self::assertSame($select, $return); + + return $return; + } + + /** + * @testdox unit test: Test join() exception with bad join + * @covers \Zend\Db\Sql\Select::join + */ + public function testBadJoin() + { + $select = new Select; + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage("expects 'foo' as"); + $select->join(['foo'], 'x = y', Select::SQL_STAR, Select::JOIN_INNER); + } + + /** + * @testdox unit test: Test processJoins() exception with bad join name + * @covers \Zend\Db\Sql\Select::processJoins + */ + public function testBadJoinName() + { + $mockExpression = $this->getMockBuilder('Zend\Db\Sql\ExpressionInterface') + ->setConstructorArgs(['bar']) + ->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $parameterContainer = new ParameterContainer(); + + $select = new Select; + $select->join(['foo' => $mockExpression], 'x = y', Select::SQL_STAR, Select::JOIN_INNER); + + $sr = new ReflectionObject($select); + + $mr = $sr->getMethod('processJoins'); + + $mr->setAccessible(true); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + + $mr->invokeArgs($select, [new Sql92, $mockDriver, $parameterContainer]); + } + + /** + * @testdox unit test: Test getRawState() returns information populated via join() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testJoin + */ + public function testGetRawStateViaJoin(Select $select) + { + self::assertEquals( + [[ + 'name' => 'foo', + 'on' => 'x = y', + 'columns' => [Select::SQL_STAR], + 'type' => Select::JOIN_INNER, + ]], + $select->getRawState('joins')->getJoins() + ); + } + + /** + * @testdox unit test: Test where() returns Select object (is chainable) + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereReturnsSameSelectObject() + { + $select = new Select; + self::assertSame($select, $select->where('x = y')); + } + + /** + * @testdox unit test: Test where() will accept a string for the predicate to create an expression predicate + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsString() + { + $select = new Select; + $select->where('x = ?'); + + /** @var $where Where */ + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertCount(1, $predicates); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[0][1]); + self::assertEquals(Where::OP_AND, $predicates[0][0]); + self::assertEquals('x = ?', $predicates[0][1]->getExpression()); + + $select = new Select; + $select->where('x = y'); + + /** @var $where Where */ + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]); + } + + /** + * @testdox unit test: Test where() will accept an array with a string key (containing ?) used as an + * expression with placeholder + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsAssociativeArrayContainingReplacementCharacter() + { + $select = new Select; + $select->where(['foo > ?' => 5]); + + /** @var $where Where */ + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertCount(1, $predicates); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[0][1]); + self::assertEquals(Where::OP_AND, $predicates[0][0]); + self::assertEquals('foo > ?', $predicates[0][1]->getExpression()); + self::assertEquals([5], $predicates[0][1]->getParameters()); + } + + /** + * @testdox unit test: Test where() will accept any array with string key (without ?) to be used + * as Operator predicate + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsAssociativeArrayNotContainingReplacementCharacter() + { + $select = new Select; + $select->where(['name' => 'Ralph', 'age' => 33]); + + /** @var $where Where */ + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertCount(2, $predicates); + + self::assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[0][1]); + self::assertEquals(Where::OP_AND, $predicates[0][0]); + self::assertEquals('name', $predicates[0][1]->getLeft()); + self::assertEquals('Ralph', $predicates[0][1]->getRight()); + + self::assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[1][1]); + self::assertEquals(Where::OP_AND, $predicates[1][0]); + self::assertEquals('age', $predicates[1][1]->getLeft()); + self::assertEquals(33, $predicates[1][1]->getRight()); + + $select = new Select; + $select->where(['x = y']); + + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]); + } + + /** + * @testdox unit test: Test where() will accept any array with string key (without ?) with Predicate throw Exception + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsAssociativeArrayIsPredicate() + { + $select = new Select; + $where = [ + 'name' => new Predicate\Literal("name = 'Ralph'"), + 'age' => new Predicate\Expression('age = ?', 33), + ]; + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Using Predicate must not use string keys'); + $select->where($where); + } + + /** + * @testdox unit test: Test where() will accept an indexed array to be used by joining string expressions + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsIndexedArray() + { + $select = new Select; + $select->where(['name = "Ralph"']); + + /** @var $where Where */ + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertCount(1, $predicates); + + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]); + self::assertEquals(Where::OP_AND, $predicates[0][0]); + self::assertEquals('name = "Ralph"', $predicates[0][1]->getLiteral()); + } + + /** + * @testdox unit test: Test where() will accept an indexed array to be used by joining string expressions, + * combined by OR + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsIndexedArrayArgument2IsOr() + { + $select = new Select; + $select->where(['name = "Ralph"'], Where::OP_OR); + + /** @var $where Where */ + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertCount(1, $predicates); + + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]); + self::assertEquals(Where::OP_OR, $predicates[0][0]); + self::assertEquals('name = "Ralph"', $predicates[0][1]->getLiteral()); + } + + /** + * @testdox unit test: Test where() will accept a closure to be executed with Where object as argument + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsClosure() + { + $select = new Select; + $where = $select->getRawState('where'); + + $select->where(function ($what) use ($where) { + self::assertSame($where, $what); + }); + } + + /** + * @testdox unit test: Test where() will accept any Predicate object as-is + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsPredicate() + { + $select = new Select; + $predicate = new Predicate\Predicate([ + new Predicate\Expression('name = ?', 'Ralph'), + new Predicate\Expression('age = ?', 33), + ]); + $select->where($predicate); + + /** @var $where Where */ + $where = $select->getRawState('where'); + $predicates = $where->getPredicates(); + self::assertSame($predicate, $predicates[0][1]); + } + + /** + * @testdox unit test: Test where() will accept a Where object + * @covers \Zend\Db\Sql\Select::where + */ + public function testWhereArgument1IsWhereObject() + { + $select = new Select; + $select->where($newWhere = new Where); + self::assertSame($newWhere, $select->getRawState('where')); + } + + /** + * @author Rob Allen + * @testdox unit test: Test order() + * @covers \Zend\Db\Sql\Select::order + */ + public function testOrder() + { + $select = new Select; + $return = $select->order('id DESC'); + self::assertSame($select, $return); // test fluent interface + self::assertEquals(['id DESC'], $select->getRawState('order')); + + $select = new Select; + $select->order('id DESC') + ->order('name ASC, age DESC'); + self::assertEquals(['id DESC', 'name ASC', 'age DESC'], $select->getRawState('order')); + + $select = new Select; + $select->order(['name ASC', 'age DESC']); + self::assertEquals(['name ASC', 'age DESC'], $select->getRawState('order')); + + $select = new Select; + $select->order(new Expression('RAND()')); + $sr = new ReflectionObject($select); + $method = $sr->getMethod('processOrder'); + $method->setAccessible(true); + self::assertEquals( + [[['RAND()']]], + $method->invokeArgs($select, [new TrustingSql92Platform()]) + ); + + $select = new Select; + $select->order( + $this->getMockBuilder('Zend\Db\Sql\Predicate\Operator') + ->setMethods() + ->setConstructorArgs(['rating', '<', '10']) + ->getMock() + ); + $sr = new ReflectionObject($select); + $method = $sr->getMethod('processOrder'); + $method->setAccessible(true); + self::assertEquals( + [[['"rating" < \'10\'']]], + $method->invokeArgs($select, [new TrustingSql92Platform()]) + ); + } + + /** + * @testdox unit test: Test order() correctly splits parameters. + * @covers \Zend\Db\Sql\Select::order + */ + public function testOrderCorrectlySplitsParameter() + { + $select = new Select; + $select->order('name desc'); + self::assertEquals( + 'SELECT * ORDER BY "name" DESC', + $select->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @testdox: unit test: test limit() + * @covers \Zend\Db\Sql\Select::limit + */ + public function testLimit() + { + $select = new Select; + self::assertSame($select, $select->limit(5)); + return $select; + } + + /** + * @testdox: unit test: Test getRawState() returns information populated via limit() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testLimit + */ + public function testGetRawStateViaLimit(Select $select) + { + self::assertEquals(5, $select->getRawState($select::LIMIT)); + } + + /** + * @testdox: unit test: test limit() throws execption when invalid parameter passed + * @covers \Zend\Db\Sql\Select::limit + */ + public function testLimitExceptionOnInvalidParameter() + { + $select = new Select; + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Zend\Db\Sql\Select::limit expects parameter to be numeric'); + $select->limit('foobar'); + } + + /** + * @testdox: unit test: test offset() + * @covers \Zend\Db\Sql\Select::offset + */ + public function testOffset() + { + $select = new Select; + self::assertSame($select, $select->offset(10)); + return $select; + } + + /** + * @testdox: unit test: Test getRawState() returns information populated via offset() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testOffset + */ + public function testGetRawStateViaOffset(Select $select) + { + self::assertEquals(10, $select->getRawState($select::OFFSET)); + } + + /** + * @testdox: unit test: test offset() throws exception when invalid parameter passed + * @covers \Zend\Db\Sql\Select::offset + */ + public function testOffsetExceptionOnInvalidParameter() + { + $select = new Select; + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Zend\Db\Sql\Select::offset expects parameter to be numeric'); + $select->offset('foobar'); + } + + + /** + * @testdox unit test: Test group() returns same Select object (is chainable) + * @covers \Zend\Db\Sql\Select::group + */ + public function testGroup() + { + $select = new Select; + $return = $select->group(['col1', 'col2']); + self::assertSame($select, $return); + + return $return; + } + + /** + * @testdox unit test: Test getRawState() returns information populated via group() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testGroup + */ + public function testGetRawStateViaGroup(Select $select) + { + self::assertEquals( + ['col1', 'col2'], + $select->getRawState('group') + ); + } + + /** + * @testdox unit test: Test having() returns same Select object (is chainable) + * @covers \Zend\Db\Sql\Select::having + */ + public function testHaving() + { + $select = new Select; + $return = $select->having(['x = ?' => 5]); + self::assertSame($select, $return); + + return $return; + } + + /** + * @testdox unit test: Test having() returns same Select object (is chainable) + * @covers \Zend\Db\Sql\Select::having + */ + public function testHavingArgument1IsHavingObject() + { + $select = new Select; + $having = new Having(); + $return = $select->having($having); + self::assertSame($select, $return); + self::assertSame($having, $select->getRawState('having')); + + return $return; + } + + /** + * @testdox unit test: Test getRawState() returns information populated via having() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testHaving + */ + public function testGetRawStateViaHaving(Select $select) + { + self::assertInstanceOf('Zend\Db\Sql\Having', $select->getRawState('having')); + } + + /** + * @testdox unit test: Test combine() returns same Select object (is chainable) + * @covers \Zend\Db\Sql\Select::combine + */ + public function testCombine() + { + $select = new Select; + $combine = new Select; + $return = $select->combine($combine, $select::COMBINE_UNION, 'ALL'); + self::assertSame($select, $return); + + return $return; + } + + /** + * @testdox unit test: Test getRawState() returns information populated via combine() + * @covers \Zend\Db\Sql\Select::getRawState + * @depends testCombine + */ + public function testGetRawStateViaCombine(Select $select) + { + $state = $select->getRawState('combine'); + self::assertInstanceOf('Zend\Db\Sql\Select', $state['select']); + self::assertNotSame($select, $state['select']); + self::assertEquals(Select::COMBINE_UNION, $state['type']); + self::assertEquals('ALL', $state['modifier']); + } + + /** + * @testdox unit test: Test reset() resets internal stat of Select object, based on input + * @covers \Zend\Db\Sql\Select::reset + */ + public function testReset() + { + $select = new Select; + + // table + $select->from('foo'); + self::assertEquals('foo', $select->getRawState(Select::TABLE)); + $select->reset(Select::TABLE); + self::assertNull($select->getRawState(Select::TABLE)); + + // columns + $select->columns(['foo']); + self::assertEquals(['foo'], $select->getRawState(Select::COLUMNS)); + $select->reset(Select::COLUMNS); + self::assertEmpty($select->getRawState(Select::COLUMNS)); + + // joins + $select->join('foo', 'id = boo'); + self::assertEquals( + [['name' => 'foo', 'on' => 'id = boo', 'columns' => ['*'], 'type' => 'inner']], + $select->getRawState(Select::JOINS)->getJoins() + ); + $select->reset(Select::JOINS); + self::assertEmpty($select->getRawState(Select::JOINS)->getJoins()); + + // where + $select->where('foo = bar'); + $where1 = $select->getRawState(Select::WHERE); + self::assertEquals(1, $where1->count()); + $select->reset(Select::WHERE); + $where2 = $select->getRawState(Select::WHERE); + self::assertEquals(0, $where2->count()); + self::assertNotSame($where1, $where2); + + // group + $select->group(['foo']); + self::assertEquals(['foo'], $select->getRawState(Select::GROUP)); + $select->reset(Select::GROUP); + self::assertEmpty($select->getRawState(Select::GROUP)); + + // having + $select->having('foo = bar'); + $having1 = $select->getRawState(Select::HAVING); + self::assertEquals(1, $having1->count()); + $select->reset(Select::HAVING); + $having2 = $select->getRawState(Select::HAVING); + self::assertEquals(0, $having2->count()); + self::assertNotSame($having1, $having2); + + // limit + $select->limit(5); + self::assertEquals(5, $select->getRawState(Select::LIMIT)); + $select->reset(Select::LIMIT); + self::assertNull($select->getRawState(Select::LIMIT)); + + // offset + $select->offset(10); + self::assertEquals(10, $select->getRawState(Select::OFFSET)); + $select->reset(Select::OFFSET); + self::assertNull($select->getRawState(Select::OFFSET)); + + // order + $select->order('foo asc'); + self::assertEquals(['foo asc'], $select->getRawState(Select::ORDER)); + $select->reset(Select::ORDER); + self::assertEmpty($select->getRawState(Select::ORDER)); + } + + /** + * @testdox unit test: Test prepareStatement() will produce expected sql and parameters based on + * a variety of provided arguments [uses data provider] + * @covers \Zend\Db\Sql\Select::prepareStatement + * @dataProvider providerData + */ + public function testPrepareStatement( + Select $select, + $expectedSqlString, + $expectedParameters, + $unused1, + $unused2, + $useNamedParameters = false + ) { + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnCallback( + function ($name) use ($useNamedParameters) { + return (($useNamedParameters) ? ':' . $name : '?'); + } + )); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $parameterContainer = new ParameterContainer(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->any())->method('getParameterContainer') + ->will($this->returnValue($parameterContainer)); + $mockStatement->expects($this->any())->method('setSql')->with($this->equalTo($expectedSqlString)); + + $select->prepareStatement($mockAdapter, $mockStatement); + + if ($expectedParameters) { + self::assertEquals($expectedParameters, $parameterContainer->getNamedArray()); + } + } + + /** + * @group ZF2-5192 + */ + public function testSelectUsingTableIdentifierWithEmptyScheme() + { + $select = new Select; + $select->from(new TableIdentifier('foo')); + $select->join(new TableIdentifier('bar'), 'foo.id = bar.fooid'); + + self::assertEquals( + 'SELECT "foo".*, "bar".* FROM "foo" INNER JOIN "bar" ON "foo"."id" = "bar"."fooid"', + $select->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @testdox unit test: Test getSqlString() will produce expected sql and parameters based on + * a variety of provided arguments [uses data provider] + * @covers \Zend\Db\Sql\Select::getSqlString + * @dataProvider providerData + */ + public function testGetSqlString(Select $select, $unused, $unused2, $expectedSqlString) + { + self::assertEquals($expectedSqlString, $select->getSqlString(new TrustingSql92Platform())); + } + + /** + * @testdox unit test: Test __get() returns expected objects magically + * @covers \Zend\Db\Sql\Select::__get + */ + public function testMagicAccessor() + { + $select = new Select; + self::assertInstanceOf('Zend\Db\Sql\Where', $select->where); + } + + /** + * @testdox unit test: Test __clone() will clone the where object so that this select can be used + * in multiple contexts + * @covers \Zend\Db\Sql\Select::__clone + */ + public function testCloning() + { + $select = new Select; + $select1 = clone $select; + $select1->where('id = foo'); + $select1->having('id = foo'); + + self::assertEquals(0, $select->where->count()); + self::assertEquals(1, $select1->where->count()); + + self::assertEquals(0, $select->having->count()); + self::assertEquals(1, $select1->having->count()); + } + + /** + * @testdox unit test: Text process*() methods will return proper array when internally called, + * part of extension API + * @dataProvider providerData + * @covers \Zend\Db\Sql\Select::processSelect + * @covers \Zend\Db\Sql\Select::processJoins + * @covers \Zend\Db\Sql\Select::processWhere + * @covers \Zend\Db\Sql\Select::processGroup + * @covers \Zend\Db\Sql\Select::processHaving + * @covers \Zend\Db\Sql\Select::processOrder + * @covers \Zend\Db\Sql\Select::processLimit + * @covers \Zend\Db\Sql\Select::processOffset + * @covers \Zend\Db\Sql\Select::processCombine + */ + public function testProcessMethods(Select $select, $unused, $unused2, $unused3, $internalTests) + { + if (! $internalTests) { + return; + } + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $parameterContainer = new ParameterContainer(); + + $sr = new ReflectionObject($select); + + foreach ($internalTests as $method => $expected) { + $mr = $sr->getMethod($method); + $mr->setAccessible(true); + $return = $mr->invokeArgs($select, [new Sql92, $mockDriver, $parameterContainer]); + self::assertEquals($expected, $return); + } + } + + public function providerData() + { + // basic table + $select0 = new Select; + $select0->from('foo'); + $sqlPrep0 = // same + $sqlStr0 = 'SELECT "foo".* FROM "foo"'; + $internalTests0 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + ]; + + // table as TableIdentifier + $select1 = new Select; + $select1->from(new TableIdentifier('foo', 'bar')); + $sqlPrep1 = // same + $sqlStr1 = 'SELECT "bar"."foo".* FROM "bar"."foo"'; + $internalTests1 = [ + 'processSelect' => [[['"bar"."foo".*']], '"bar"."foo"'], + ]; + + // table with alias + $select2 = new Select; + $select2->from(['f' => 'foo']); + $sqlPrep2 = // same + $sqlStr2 = 'SELECT "f".* FROM "foo" AS "f"'; + $internalTests2 = [ + 'processSelect' => [[['"f".*']], '"foo" AS "f"'], + ]; + + // table with alias with table as TableIdentifier + $select3 = new Select; + $select3->from(['f' => new TableIdentifier('foo')]); + $sqlPrep3 = // same + $sqlStr3 = 'SELECT "f".* FROM "foo" AS "f"'; + $internalTests3 = [ + 'processSelect' => [[['"f".*']], '"foo" AS "f"'], + ]; + + // columns + $select4 = new Select; + $select4->from('foo')->columns(['bar', 'baz']); + $sqlPrep4 = // same + $sqlStr4 = 'SELECT "foo"."bar" AS "bar", "foo"."baz" AS "baz" FROM "foo"'; + $internalTests4 = [ + 'processSelect' => [[['"foo"."bar"', '"bar"'], ['"foo"."baz"', '"baz"']], '"foo"'], + ]; + + // columns with AS associative array + $select5 = new Select; + $select5->from('foo')->columns(['bar' => 'baz']); + $sqlPrep5 = // same + $sqlStr5 = 'SELECT "foo"."baz" AS "bar" FROM "foo"'; + $internalTests5 = [ + 'processSelect' => [[['"foo"."baz"', '"bar"']], '"foo"'], + ]; + + // columns with AS associative array mixed + $select6 = new Select; + $select6->from('foo')->columns(['bar' => 'baz', 'bam']); + $sqlPrep6 = // same + $sqlStr6 = 'SELECT "foo"."baz" AS "bar", "foo"."bam" AS "bam" FROM "foo"'; + $internalTests6 = [ + 'processSelect' => [[['"foo"."baz"', '"bar"'], ['"foo"."bam"', '"bam"'] ], '"foo"'], + ]; + + // columns where value is Expression, with AS + $select7 = new Select; + $select7->from('foo')->columns(['bar' => new Expression('COUNT(some_column)')]); + $sqlPrep7 = // same + $sqlStr7 = 'SELECT COUNT(some_column) AS "bar" FROM "foo"'; + $internalTests7 = [ + 'processSelect' => [[['COUNT(some_column)', '"bar"']], '"foo"'], + ]; + + // columns where value is Expression + $select8 = new Select; + $select8->from('foo')->columns([new Expression('COUNT(some_column) AS bar')]); + $sqlPrep8 = // same + $sqlStr8 = 'SELECT COUNT(some_column) AS bar FROM "foo"'; + $internalTests8 = [ + 'processSelect' => [[['COUNT(some_column) AS bar']], '"foo"'], + ]; + + // columns where value is Expression with parameters + $select9 = new Select; + $select9->from('foo')->columns( + [ + new Expression( + '(COUNT(?) + ?) AS ?', + ['some_column', 5, 'bar'], + [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE, Expression::TYPE_IDENTIFIER] + ), + ] + ); + $sqlPrep9 = 'SELECT (COUNT("some_column") + ?) AS "bar" FROM "foo"'; + $sqlStr9 = 'SELECT (COUNT("some_column") + \'5\') AS "bar" FROM "foo"'; + $params9 = ['column1' => 5]; + $internalTests9 = [ + 'processSelect' => [[['(COUNT("some_column") + ?) AS "bar"']], '"foo"'], + ]; + + // joins (plain) + $select10 = new Select; + $select10->from('foo')->join('zac', 'm = n'); + $sqlPrep10 = // same + $sqlStr10 = 'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON "m" = "n"'; + $internalTests10 = [ + 'processSelect' => [[['"foo".*'], ['"zac".*']], '"foo"'], + 'processJoins' => [[['INNER', '"zac"', '"m" = "n"']]], + ]; + + // join with columns + $select11 = new Select; + $select11->from('foo')->join('zac', 'm = n', ['bar', 'baz']); + // @codingStandardsIgnoreStart + $sqlPrep11 = // same + $sqlStr11 = 'SELECT "foo".*, "zac"."bar" AS "bar", "zac"."baz" AS "baz" FROM "foo" INNER JOIN "zac" ON "m" = "n"'; + // @codingStandardsIgnoreEnd + $internalTests11 = [ + 'processSelect' => [[['"foo".*'], ['"zac"."bar"', '"bar"'], ['"zac"."baz"', '"baz"']], '"foo"'], + 'processJoins' => [[['INNER', '"zac"', '"m" = "n"']]], + ]; + + // join with alternate type + $select12 = new Select; + $select12->from('foo')->join('zac', 'm = n', ['bar', 'baz'], Select::JOIN_OUTER); + // @codingStandardsIgnoreStart + $sqlPrep12 = // same + $sqlStr12 = 'SELECT "foo".*, "zac"."bar" AS "bar", "zac"."baz" AS "baz" FROM "foo" OUTER JOIN "zac" ON "m" = "n"'; + // @codingStandardsIgnoreEnd + $internalTests12 = [ + 'processSelect' => [[['"foo".*'], ['"zac"."bar"', '"bar"'], ['"zac"."baz"', '"baz"']], '"foo"'], + 'processJoins' => [[['OUTER', '"zac"', '"m" = "n"']]], + ]; + + // join with column aliases + $select13 = new Select; + $select13->from('foo')->join('zac', 'm = n', ['BAR' => 'bar', 'BAZ' => 'baz']); + // @codingStandardsIgnoreStart + $sqlPrep13 = // same + $sqlStr13 = 'SELECT "foo".*, "zac"."bar" AS "BAR", "zac"."baz" AS "BAZ" FROM "foo" INNER JOIN "zac" ON "m" = "n"'; + // @codingStandardsIgnoreEnd + $internalTests13 = [ + 'processSelect' => [[['"foo".*'], ['"zac"."bar"', '"BAR"'], ['"zac"."baz"', '"BAZ"']], '"foo"'], + 'processJoins' => [[['INNER', '"zac"', '"m" = "n"']]], + ]; + + // join with table aliases + $select14 = new Select; + $select14->from('foo')->join(['b' => 'bar'], 'b.foo_id = foo.foo_id'); + $sqlPrep14 = // same + $sqlStr14 = 'SELECT "foo".*, "b".* FROM "foo" INNER JOIN "bar" AS "b" ON "b"."foo_id" = "foo"."foo_id"'; + $internalTests14 = [ + 'processSelect' => [[['"foo".*'], ['"b".*']], '"foo"'], + 'processJoins' => [[['INNER', '"bar" AS "b"', '"b"."foo_id" = "foo"."foo_id"']]], + ]; + + // where (simple string) + $select15 = new Select; + $select15->from('foo')->where('x = 5'); + $sqlPrep15 = // same + $sqlStr15 = 'SELECT "foo".* FROM "foo" WHERE x = 5'; + $internalTests15 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processWhere' => ['x = 5'], + ]; + + // where (returning parameters) + $select16 = new Select; + $select16->from('foo')->where(['x = ?' => 5]); + $sqlPrep16 = 'SELECT "foo".* FROM "foo" WHERE x = ?'; + $sqlStr16 = 'SELECT "foo".* FROM "foo" WHERE x = \'5\''; + $params16 = ['where1' => 5]; + $internalTests16 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processWhere' => ['x = ?'], + ]; + + // group + $select17 = new Select; + $select17->from('foo')->group(['col1', 'col2']); + $sqlPrep17 = // same + $sqlStr17 = 'SELECT "foo".* FROM "foo" GROUP BY "col1", "col2"'; + $internalTests17 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processGroup' => [['"col1"', '"col2"']], + ]; + + $select18 = new Select; + $select18->from('foo')->group('col1')->group('col2'); + $sqlPrep18 = // same + $sqlStr18 = 'SELECT "foo".* FROM "foo" GROUP BY "col1", "col2"'; + $internalTests18 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processGroup' => [['"col1"', '"col2"']], + ]; + + $select19 = new Select; + $select19->from('foo')->group(new Expression('DAY(?)', ['col1'], [Expression::TYPE_IDENTIFIER])); + $sqlPrep19 = // same + $sqlStr19 = 'SELECT "foo".* FROM "foo" GROUP BY DAY("col1")'; + $internalTests19 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processGroup' => [['DAY("col1")']], + ]; + + // having (simple string) + $select20 = new Select; + $select20->from('foo')->having('x = 5'); + $sqlPrep20 = // same + $sqlStr20 = 'SELECT "foo".* FROM "foo" HAVING x = 5'; + $internalTests20 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processHaving' => ['x = 5'], + ]; + + // having (returning parameters) + $select21 = new Select; + $select21->from('foo')->having(['x = ?' => 5]); + $sqlPrep21 = 'SELECT "foo".* FROM "foo" HAVING x = ?'; + $sqlStr21 = 'SELECT "foo".* FROM "foo" HAVING x = \'5\''; + $params21 = ['having1' => 5]; + $internalTests21 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processHaving' => ['x = ?'], + ]; + + // order + $select22 = new Select; + $select22->from('foo')->order('c1'); + $sqlPrep22 = // + $sqlStr22 = 'SELECT "foo".* FROM "foo" ORDER BY "c1" ASC'; + $internalTests22 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processOrder' => [[['"c1"', Select::ORDER_ASCENDING]]], + ]; + + $select23 = new Select; + $select23->from('foo')->order(['c1', 'c2']); + $sqlPrep23 = // same + $sqlStr23 = 'SELECT "foo".* FROM "foo" ORDER BY "c1" ASC, "c2" ASC'; + $internalTests23 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processOrder' => [[['"c1"', Select::ORDER_ASCENDING], ['"c2"', Select::ORDER_ASCENDING]]], + ]; + + $select24 = new Select; + $select24->from('foo')->order(['c1' => 'DESC', 'c2' => 'Asc']); // notice partially lower case ASC + $sqlPrep24 = // same + $sqlStr24 = 'SELECT "foo".* FROM "foo" ORDER BY "c1" DESC, "c2" ASC'; + $internalTests24 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processOrder' => [[['"c1"', Select::ORDER_DESCENDING], ['"c2"', Select::ORDER_ASCENDING]]], + ]; + + $select25 = new Select; + $select25->from('foo')->order(['c1' => 'asc'])->order('c2 desc'); // notice partially lower case ASC + $sqlPrep25 = // same + $sqlStr25 = 'SELECT "foo".* FROM "foo" ORDER BY "c1" ASC, "c2" DESC'; + $internalTests25 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processOrder' => [[['"c1"', Select::ORDER_ASCENDING], ['"c2"', Select::ORDER_DESCENDING]]], + ]; + + // limit + $select26 = new Select; + $select26->from('foo')->limit(5); + $sqlPrep26 = 'SELECT "foo".* FROM "foo" LIMIT ?'; + $sqlStr26 = 'SELECT "foo".* FROM "foo" LIMIT \'5\''; + $params26 = ['limit' => 5]; + $internalTests26 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processLimit' => ['?'], + ]; + + // limit with offset + $select27 = new Select; + $select27->from('foo')->limit(5)->offset(10); + $sqlPrep27 = 'SELECT "foo".* FROM "foo" LIMIT ? OFFSET ?'; + $sqlStr27 = 'SELECT "foo".* FROM "foo" LIMIT \'5\' OFFSET \'10\''; + $params27 = ['limit' => 5, 'offset' => 10]; + $internalTests27 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processLimit' => ['?'], + 'processOffset' => ['?'], + ]; + + // joins with a few keywords in the on clause + $select28 = new Select; + // @codingStandardsIgnoreStart + $select28->from('foo')->join('zac', '(m = n AND c.x) BETWEEN x AND y.z OR (c.x < y.z AND c.x <= y.z AND c.x > y.z AND c.x >= y.z)'); + $sqlPrep28 = // same + $sqlStr28 = 'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON ("m" = "n" AND "c"."x") BETWEEN "x" AND "y"."z" OR ("c"."x" < "y"."z" AND "c"."x" <= "y"."z" AND "c"."x" > "y"."z" AND "c"."x" >= "y"."z")'; + // @codingStandardsIgnoreEnd + $internalTests28 = [ + 'processSelect' => [[['"foo".*'], ['"zac".*']], '"foo"'], + // @codingStandardsIgnoreStart + 'processJoins' => [[['INNER', '"zac"', '("m" = "n" AND "c"."x") BETWEEN "x" AND "y"."z" OR ("c"."x" < "y"."z" AND "c"."x" <= "y"."z" AND "c"."x" > "y"."z" AND "c"."x" >= "y"."z")']]], + // @codingStandardsIgnoreEnd + ]; + + // order with compound name + $select29 = new Select; + $select29->from('foo')->order('c1.d2'); + $sqlPrep29 = // + $sqlStr29 = 'SELECT "foo".* FROM "foo" ORDER BY "c1"."d2" ASC'; + $internalTests29 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processOrder' => [[['"c1"."d2"', Select::ORDER_ASCENDING]]], + ]; + + // group with compound name + $select30 = new Select; + $select30->from('foo')->group('c1.d2'); + $sqlPrep30 = // same + $sqlStr30 = 'SELECT "foo".* FROM "foo" GROUP BY "c1"."d2"'; + $internalTests30 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processGroup' => [['"c1"."d2"']], + ]; + + // join with expression in ON part + $select31 = new Select; + $select31->from('foo')->join('zac', new Expression('(m = n AND c.x) BETWEEN x AND y.z')); + $sqlPrep31 = // same + $sqlStr31 = 'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON (m = n AND c.x) BETWEEN x AND y.z'; + $internalTests31 = [ + 'processSelect' => [[['"foo".*'], ['"zac".*']], '"foo"'], + 'processJoins' => [[['INNER', '"zac"', '(m = n AND c.x) BETWEEN x AND y.z']]], + ]; + + $select32subselect = new Select; + $select32subselect->from('bar')->where->like('y', '%Foo%'); + $select32 = new Select; + $select32->from(['x' => $select32subselect]); + $sqlPrep32 = 'SELECT "x".* FROM (SELECT "bar".* FROM "bar" WHERE "y" LIKE ?) AS "x"'; + $sqlStr32 = 'SELECT "x".* FROM (SELECT "bar".* FROM "bar" WHERE "y" LIKE \'%Foo%\') AS "x"'; + $internalTests32 = [ + 'processSelect' => [[['"x".*']], '(SELECT "bar".* FROM "bar" WHERE "y" LIKE ?) AS "x"'], + ]; + + $select33 = new Select; + $select33->from('table')->columns(['*'])->where([ + 'c1' => null, + 'c2' => [1, 2, 3], + new \Zend\Db\Sql\Predicate\IsNotNull('c3'), + ]); + $sqlPrep33 = 'SELECT "table".* FROM "table" WHERE "c1" IS NULL AND "c2" IN (?, ?, ?) AND "c3" IS NOT NULL'; + // @codingStandardsIgnoreStart + $sqlStr33 = 'SELECT "table".* FROM "table" WHERE "c1" IS NULL AND "c2" IN (\'1\', \'2\', \'3\') AND "c3" IS NOT NULL'; + // @codingStandardsIgnoreEnd + $internalTests33 = [ + 'processSelect' => [[['"table".*']], '"table"'], + 'processWhere' => ['"c1" IS NULL AND "c2" IN (?, ?, ?) AND "c3" IS NOT NULL'], + ]; + + // @author Demian Katz + $select34 = new Select; + $select34->from('table')->order([ + new Expression('isnull(?) DESC', ['name'], [Expression::TYPE_IDENTIFIER]), + 'name', + ]); + $sqlPrep34 = 'SELECT "table".* FROM "table" ORDER BY isnull("name") DESC, "name" ASC'; + $sqlStr34 = 'SELECT "table".* FROM "table" ORDER BY isnull("name") DESC, "name" ASC'; + $internalTests34 = [ + 'processOrder' => [[['isnull("name") DESC'], ['"name"', Select::ORDER_ASCENDING]]], + ]; + + // join with Expression object in COLUMNS part (ZF2-514) + // @co-author Koen Pieters (kpieters) + $select35 = new Select; + $select35->from('foo')->columns([])->join('bar', 'm = n', ['thecount' => new Expression("COUNT(*)")]); + $sqlPrep35 = // same + $sqlStr35 = 'SELECT COUNT(*) AS "thecount" FROM "foo" INNER JOIN "bar" ON "m" = "n"'; + $internalTests35 = [ + 'processSelect' => [[['COUNT(*)', '"thecount"']], '"foo"'], + 'processJoins' => [[['INNER', '"bar"', '"m" = "n"']]], + ]; + + // multiple joins with expressions + // reported by @jdolieslager + $select36 = new Select; + $select36->from('foo') + ->join('tableA', new Predicate\Operator('id', '=', 1)) + ->join('tableB', new Predicate\Operator('id', '=', 2)) + ->join('tableC', new Predicate\PredicateSet([ + new Predicate\Operator('id', '=', 3), + new Predicate\Operator('number', '>', 20), + ])); + $sqlPrep36 = 'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo"' + . ' INNER JOIN "tableA" ON "id" = :join1part1 INNER JOIN "tableB" ON "id" = :join2part1 ' + . 'INNER JOIN "tableC" ON "id" = :join3part1 AND "number" > :join3part2'; + $sqlStr36 = 'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo" ' + . 'INNER JOIN "tableA" ON "id" = \'1\' INNER JOIN "tableB" ON "id" = \'2\' ' + . 'INNER JOIN "tableC" ON "id" = \'3\' AND "number" > \'20\''; + $internalTests36 = []; + $useNamedParams36 = true; + + /** + * @author robertbasic + * @link https://github.com/zendframework/zf2/pull/2714 + */ + $select37 = new Select; + $select37->from('foo')->columns(['bar'], false); + $sqlPrep37 = // same + $sqlStr37 = 'SELECT "bar" AS "bar" FROM "foo"'; + $internalTests37 = [ + 'processSelect' => [[['"bar"', '"bar"']], '"foo"'], + ]; + + // @link https://github.com/zendframework/zf2/issues/3294 + // Test TableIdentifier In Joins + $select38 = new Select; + $select38->from('foo')->columns([]) + ->join(new TableIdentifier('bar', 'baz'), 'm = n', ['thecount' => new Expression("COUNT(*)")]); + $sqlPrep38 = // same + $sqlStr38 = 'SELECT COUNT(*) AS "thecount" FROM "foo" INNER JOIN "baz"."bar" ON "m" = "n"'; + $internalTests38 = [ + 'processSelect' => [[['COUNT(*)', '"thecount"']], '"foo"'], + 'processJoins' => [[['INNER', '"baz"."bar"', '"m" = "n"']]], + ]; + + // subselect in join + $select39subselect = new Select; + $select39subselect->from('bar')->where->like('y', '%Foo%'); + $select39 = new Select; + $select39->from('foo')->join(['z' => $select39subselect], 'z.foo = bar.id'); + // @codingStandardsIgnoreStart + $sqlPrep39 = 'SELECT "foo".*, "z".* FROM "foo" INNER JOIN (SELECT "bar".* FROM "bar" WHERE "y" LIKE ?) AS "z" ON "z"."foo" = "bar"."id"'; + $sqlStr39 = 'SELECT "foo".*, "z".* FROM "foo" INNER JOIN (SELECT "bar".* FROM "bar" WHERE "y" LIKE \'%Foo%\') AS "z" ON "z"."foo" = "bar"."id"'; + // @codingStandardsIgnoreEnd + $internalTests39 = [ + 'processJoins' => [ + [['INNER', '(SELECT "bar".* FROM "bar" WHERE "y" LIKE ?) AS "z"', '"z"."foo" = "bar"."id"']], + ], + ]; + + // @link https://github.com/zendframework/zf2/issues/3294 + // Test TableIdentifier In Joins, with multiple joins + $select40 = new Select; + $select40->from('foo') + ->join(['a' => new TableIdentifier('another_foo', 'another_schema')], 'a.x = foo.foo_column') + ->join('bar', 'foo.colx = bar.colx'); + $sqlPrep40 = // same + $sqlStr40 = 'SELECT "foo".*, "a".*, "bar".* FROM "foo"' + . ' INNER JOIN "another_schema"."another_foo" AS "a" ON "a"."x" = "foo"."foo_column"' + . ' INNER JOIN "bar" ON "foo"."colx" = "bar"."colx"'; + $internalTests40 = [ + 'processSelect' => [[['"foo".*'], ['"a".*'], ['"bar".*']], '"foo"'], + 'processJoins' => [[ + ['INNER', '"another_schema"."another_foo" AS "a"', '"a"."x" = "foo"."foo_column"'], + ['INNER', '"bar"', '"foo"."colx" = "bar"."colx"'], + ]], + ]; + + $select41 = new Select; + $select41->from('foo')->quantifier(Select::QUANTIFIER_DISTINCT); + $sqlPrep41 = // same + $sqlStr41 = 'SELECT DISTINCT "foo".* FROM "foo"'; + $internalTests41 = [ + 'processSelect' => [SELECT::QUANTIFIER_DISTINCT, [['"foo".*']], '"foo"'], + ]; + + $select42 = new Select; + $select42->from('foo')->quantifier(new Expression('TOP ?', [10])); + $sqlPrep42 = 'SELECT TOP ? "foo".* FROM "foo"'; + $sqlStr42 = 'SELECT TOP \'10\' "foo".* FROM "foo"'; + $internalTests42 = [ + 'processSelect' => ['TOP ?', [['"foo".*']], '"foo"'], + ]; + + $select43 = new Select(); + $select43->from(['x' => 'foo'])->columns(['bar' => 'foo.bar'], false); + $sqlPrep43 = 'SELECT "foo"."bar" AS "bar" FROM "foo" AS "x"'; + $sqlStr43 = 'SELECT "foo"."bar" AS "bar" FROM "foo" AS "x"'; + $internalTests43 = [ + 'processSelect' => [[['"foo"."bar"', '"bar"']], '"foo" AS "x"'], + ]; + + $select44 = new Select; + $select44->from('foo')->where('a = b'); + $select44b = new Select; + $select44b->from('bar')->where('c = d'); + $select44->combine($select44b, Select::COMBINE_UNION, 'ALL'); + $sqlPrep44 = // same + $sqlStr44 = '( SELECT "foo".* FROM "foo" WHERE a = b ) UNION ALL ( SELECT "bar".* FROM "bar" WHERE c = d )'; + $internalTests44 = [ + 'processCombine' => ['UNION ALL', 'SELECT "bar".* FROM "bar" WHERE c = d'], + ]; + + // limit with offset + $select45 = new Select; + $select45->from('foo')->limit("5")->offset("10"); + $sqlPrep45 = 'SELECT "foo".* FROM "foo" LIMIT ? OFFSET ?'; + $sqlStr45 = 'SELECT "foo".* FROM "foo" LIMIT \'5\' OFFSET \'10\''; + $params45 = ['limit' => 5, 'offset' => 10]; + $internalTests45 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processLimit' => ['?'], + 'processOffset' => ['?'], + ]; + + // functions without table + $select46 = new Select; + $select46->columns([ + new Expression('SOME_DB_FUNCTION_ONE()'), + 'foo' => new Expression('SOME_DB_FUNCTION_TWO()'), + ]); + $sqlPrep46 = 'SELECT SOME_DB_FUNCTION_ONE() AS Expression1, SOME_DB_FUNCTION_TWO() AS "foo"'; + $sqlStr46 = 'SELECT SOME_DB_FUNCTION_ONE() AS Expression1, SOME_DB_FUNCTION_TWO() AS "foo"'; + $params46 = []; + $internalTests46 = []; + + // limit with big offset and limit + $select47 = new Select; + $select47->from('foo')->limit("10000000000000000000")->offset("10000000000000000000"); + $sqlPrep47 = 'SELECT "foo".* FROM "foo" LIMIT ? OFFSET ?'; + $sqlStr47 = 'SELECT "foo".* FROM "foo" LIMIT \'10000000000000000000\' OFFSET \'10000000000000000000\''; + $params47 = ['limit' => 10000000000000000000, 'offset' => 10000000000000000000]; + $internalTests47 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processLimit' => ['?'], + 'processOffset' => ['?'], + ]; + + //combine and union with order at the end + $select48 = new Select; + $select48->from('foo')->where('a = b'); + $select48b = new Select; + $select48b->from('bar')->where('c = d'); + $select48->combine($select48b); + + $select48combined = new Select(); + $select48 = $select48combined->from(['sub' => $select48])->order('id DESC'); + // @codingStandardsIgnoreStart + $sqlPrep48 = // same + $sqlStr48 = 'SELECT "sub".* FROM (( SELECT "foo".* FROM "foo" WHERE a = b ) UNION ( SELECT "bar".* FROM "bar" WHERE c = d )) AS "sub" ORDER BY "id" DESC'; + // @codingStandardsIgnoreEnd + $internalTests48 = [ + 'processCombine' => null, + ]; + + //Expression as joinName + $select49 = new Select; + $select49->from(new TableIdentifier('foo')) + ->join(['bar' => new Expression('psql_function_which_returns_table')], 'foo.id = bar.fooid'); + // @codingStandardsIgnoreStart + $sqlPrep49 = // same + $sqlStr49 = 'SELECT "foo".*, "bar".* FROM "foo" INNER JOIN psql_function_which_returns_table AS "bar" ON "foo"."id" = "bar"."fooid"'; + // @codingStandardsIgnoreEnd + $internalTests49 = [ + 'processSelect' => [[['"foo".*'], ['"bar".*']], '"foo"'], + 'processJoins' => [[['INNER', 'psql_function_which_returns_table AS "bar"', '"foo"."id" = "bar"."fooid"']]], + ]; + + // Test generic predicate is appended with AND + $select50 = new Select; + $select50->from(new TableIdentifier('foo')) + ->where + ->nest + ->isNull('bar') + ->and + ->predicate(new Predicate\Literal('1=1')) + ->unnest; + $sqlPrep50 = // same + $sqlStr50 = 'SELECT "foo".* FROM "foo" WHERE ("bar" IS NULL AND 1=1)'; + $internalTests50 = []; + + // Test generic predicate is appended with OR + $select51 = new Select; + $select51->from(new TableIdentifier('foo')) + ->where + ->nest + ->isNull('bar') + ->or + ->predicate(new Predicate\Literal('1=1')) + ->unnest; + $sqlPrep51 = // same + $sqlStr51 = 'SELECT "foo".* FROM "foo" WHERE ("bar" IS NULL OR 1=1)'; + $internalTests51 = []; + + /** + * @author Andrzej Lewandowski + * @link https://github.com/zendframework/zf2/issues/7222 + */ + $select52 = new Select; + $select52->from('foo')->join('zac', '(catalog_category_website.category_id = catalog_category.category_id)'); + // @codingStandardsIgnoreStart + $sqlPrep52 = // same + $sqlStr52 = 'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON ("catalog_category_website"."category_id" = "catalog_category"."category_id")'; + // @codingStandardsIgnoreEnd + $internalTests52 = [ + 'processSelect' => [[['"foo".*'], ['"zac".*']], '"foo"'], + 'processJoins' => [[ + ['INNER', '"zac"', '("catalog_category_website"."category_id" = "catalog_category"."category_id")'], + ]], + ]; + + $subSelect53 = new Select; + $subSelect53->from('bar')->columns(['id'])->limit(10)->offset(9); + $select53 = new Select; + $select53->from('foo')->where(new In('bar_id', $subSelect53))->limit(11)->offset(12); + $params53 = ['limit' => 11, 'offset' => 12, 'subselect1limit' => 10, 'subselect1offset' => 9]; + // @codingStandardsIgnoreStart + $sqlPrep53 = 'SELECT "foo".* FROM "foo" WHERE "bar_id" IN (SELECT "bar"."id" AS "id" FROM "bar" LIMIT :subselect1limit OFFSET :subselect1offset) LIMIT :limit OFFSET :offset'; + $sqlStr53 = 'SELECT "foo".* FROM "foo" WHERE "bar_id" IN (SELECT "bar"."id" AS "id" FROM "bar" LIMIT \'10\' OFFSET \'9\') LIMIT \'11\' OFFSET \'12\''; + // @codingStandardsIgnoreEnd + $internalTests53 = [ + 'processSelect' => [[['"foo".*']], '"foo"'], + 'processWhere' => ['"bar_id" IN (SELECT "bar"."id" AS "id" FROM "bar" LIMIT ? OFFSET ?)'], + 'processLimit' => ['?'], + 'processOffset' => ['?'], + ]; + + /** + * $select = the select object + * $sqlPrep = the sql as a result of preparation + * $params = the param container contents result of preparation + * $sqlStr = the sql as a result of getting a string back + * $internalTests what the internal functions should return (safe-guarding extension) + */ + + return [ + // $select $sqlPrep $params $sqlStr $internalTests // use named param + [$select0, $sqlPrep0, [], $sqlStr0, $internalTests0], + [$select1, $sqlPrep1, [], $sqlStr1, $internalTests1], + [$select2, $sqlPrep2, [], $sqlStr2, $internalTests2], + [$select3, $sqlPrep3, [], $sqlStr3, $internalTests3], + [$select4, $sqlPrep4, [], $sqlStr4, $internalTests4], + [$select5, $sqlPrep5, [], $sqlStr5, $internalTests5], + [$select6, $sqlPrep6, [], $sqlStr6, $internalTests6], + [$select7, $sqlPrep7, [], $sqlStr7, $internalTests7], + [$select8, $sqlPrep8, [], $sqlStr8, $internalTests8], + [$select9, $sqlPrep9, $params9, $sqlStr9, $internalTests9], + [$select10, $sqlPrep10, [], $sqlStr10, $internalTests10], + [$select11, $sqlPrep11, [], $sqlStr11, $internalTests11], + [$select12, $sqlPrep12, [], $sqlStr12, $internalTests12], + [$select13, $sqlPrep13, [], $sqlStr13, $internalTests13], + [$select14, $sqlPrep14, [], $sqlStr14, $internalTests14], + [$select15, $sqlPrep15, [], $sqlStr15, $internalTests15], + [$select16, $sqlPrep16, $params16, $sqlStr16, $internalTests16], + [$select17, $sqlPrep17, [], $sqlStr17, $internalTests17], + [$select18, $sqlPrep18, [], $sqlStr18, $internalTests18], + [$select19, $sqlPrep19, [], $sqlStr19, $internalTests19], + [$select20, $sqlPrep20, [], $sqlStr20, $internalTests20], + [$select21, $sqlPrep21, $params21, $sqlStr21, $internalTests21], + [$select22, $sqlPrep22, [], $sqlStr22, $internalTests22], + [$select23, $sqlPrep23, [], $sqlStr23, $internalTests23], + [$select24, $sqlPrep24, [], $sqlStr24, $internalTests24], + [$select25, $sqlPrep25, [], $sqlStr25, $internalTests25], + [$select26, $sqlPrep26, $params26, $sqlStr26, $internalTests26], + [$select27, $sqlPrep27, $params27, $sqlStr27, $internalTests27], + [$select28, $sqlPrep28, [], $sqlStr28, $internalTests28], + [$select29, $sqlPrep29, [], $sqlStr29, $internalTests29], + [$select30, $sqlPrep30, [], $sqlStr30, $internalTests30], + [$select31, $sqlPrep31, [], $sqlStr31, $internalTests31], + [$select32, $sqlPrep32, [], $sqlStr32, $internalTests32], + [$select33, $sqlPrep33, [], $sqlStr33, $internalTests33], + [$select34, $sqlPrep34, [], $sqlStr34, $internalTests34], + [$select35, $sqlPrep35, [], $sqlStr35, $internalTests35], + [$select36, $sqlPrep36, [], $sqlStr36, $internalTests36, $useNamedParams36], + [$select37, $sqlPrep37, [], $sqlStr37, $internalTests37], + [$select38, $sqlPrep38, [], $sqlStr38, $internalTests38], + [$select39, $sqlPrep39, [], $sqlStr39, $internalTests39], + [$select40, $sqlPrep40, [], $sqlStr40, $internalTests40], + [$select41, $sqlPrep41, [], $sqlStr41, $internalTests41], + [$select42, $sqlPrep42, [], $sqlStr42, $internalTests42], + [$select43, $sqlPrep43, [], $sqlStr43, $internalTests43], + [$select44, $sqlPrep44, [], $sqlStr44, $internalTests44], + [$select45, $sqlPrep45, $params45, $sqlStr45, $internalTests45], + [$select46, $sqlPrep46, $params46, $sqlStr46, $internalTests46], + [$select47, $sqlPrep47, $params47, $sqlStr47, $internalTests47], + [$select48, $sqlPrep48, [], $sqlStr48, $internalTests48], + [$select49, $sqlPrep49, [], $sqlStr49, $internalTests49], + [$select50, $sqlPrep50, [], $sqlStr50, $internalTests50], + [$select51, $sqlPrep51, [], $sqlStr51, $internalTests51], + [$select52, $sqlPrep52, [], $sqlStr52, $internalTests52], + [$select53, $sqlPrep53, $params53, $sqlStr53, $internalTests53, true], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/SqlFunctionalTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/SqlFunctionalTest.php new file mode 100644 index 00000000..0160eafc --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/SqlFunctionalTest.php @@ -0,0 +1,624 @@ + [ + 'sqlObject' => $this->select('foo')->offset(10), + 'expected' => [ + 'sql92' => [ + 'string' => 'SELECT "foo".* FROM "foo" OFFSET \'10\'', + 'prepare' => 'SELECT "foo".* FROM "foo" OFFSET ?', + 'parameters' => ['offset' => 10], + ], + 'MySql' => [ + 'string' => 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET 10', + 'prepare' => 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET ?', + 'parameters' => ['offset' => 10], + ], + // @codingStandardsIgnoreStart + 'Oracle' => [ + 'string' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (10)', + 'prepare' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (:offset)', + 'parameters' => ['offset' => 10], + ], + 'SqlServer' => [ + 'string' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 0+10', + 'prepare' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?', + 'parameters' => ['offset' => 10, 'limit' => null, 'offsetForSum' => 10], + ], + // @codingStandardsIgnoreEnd + ], + ], + 'Select::processLimit()' => [ + 'sqlObject' => $this->select('foo')->limit(10), + 'expected' => [ + 'sql92' => [ + 'string' => 'SELECT "foo".* FROM "foo" LIMIT \'10\'', + 'prepare' => 'SELECT "foo".* FROM "foo" LIMIT ?', + 'parameters' => ['limit' => 10], + ], + 'MySql' => [ + 'string' => 'SELECT `foo`.* FROM `foo` LIMIT 10', + 'prepare' => 'SELECT `foo`.* FROM `foo` LIMIT ?', + 'parameters' => ['limit' => 10], + ], + // @codingStandardsIgnoreStart + 'Oracle' => [ + 'string' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (0+10)) WHERE b_rownum >= (0 + 1)', + 'prepare' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)', + 'parameters' => ['offset' => 0, 'limit' => 10], + ], + 'SqlServer' => [ + 'string' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 0+1 AND 10+0', + 'prepare' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?', + 'parameters' => ['offset' => null, 'limit' => 10, 'offsetForSum' => null], + ], + // @codingStandardsIgnoreEnd + ], + ], + 'Select::processLimitOffset()' => [ + 'sqlObject' => $this->select('foo')->limit(10)->offset(5), + 'expected' => [ + 'sql92' => [ + 'string' => 'SELECT "foo".* FROM "foo" LIMIT \'10\' OFFSET \'5\'', + 'prepare' => 'SELECT "foo".* FROM "foo" LIMIT ? OFFSET ?', + 'parameters' => ['limit' => 10, 'offset' => 5], + ], + 'MySql' => [ + 'string' => 'SELECT `foo`.* FROM `foo` LIMIT 10 OFFSET 5', + 'prepare' => 'SELECT `foo`.* FROM `foo` LIMIT ? OFFSET ?', + 'parameters' => ['limit' => 10, 'offset' => 5], + ], + // @codingStandardsIgnoreStart + 'Oracle' => [ + 'string' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (5+10)) WHERE b_rownum >= (5 + 1)', + 'prepare' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)', + 'parameters' => ['offset' => 5, 'limit' => 10], + ], + 'SqlServer' => [ + 'string' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 5+1 AND 10+5', + 'prepare' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__ZEND_ROW_NUMBER] FROM [foo] ) AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?', + 'parameters' => ['offset' => 5, 'limit' => 10, 'offsetForSum' => 5], + ], + // @codingStandardsIgnoreEnd + ], + ], + // Github issue https://github.com/zendframework/zend-db/issues/98 + 'Select::processJoinNoJoinedColumns()' => [ + 'sqlObject' => $this->select('my_table') + ->join( + 'joined_table2', + 'my_table.id = joined_table2.id', + $columns = [] + ) + ->join( + 'joined_table3', + 'my_table.id = joined_table3.id', + [\Zend\Db\Sql\Select::SQL_STAR] + ) + ->columns([ + 'my_table_column', + 'aliased_column' => new \Zend\Db\Sql\Expression('NOW()'), + ]), + 'expected' => [ + // @codingStandardsIgnoreStart + 'sql92' => [ + 'string' => 'SELECT "my_table"."my_table_column" AS "my_table_column", NOW() AS "aliased_column", "joined_table3".* FROM "my_table" INNER JOIN "joined_table2" ON "my_table"."id" = "joined_table2"."id" INNER JOIN "joined_table3" ON "my_table"."id" = "joined_table3"."id"', + ], + 'MySql' => [ + 'string' => 'SELECT `my_table`.`my_table_column` AS `my_table_column`, NOW() AS `aliased_column`, `joined_table3`.* FROM `my_table` INNER JOIN `joined_table2` ON `my_table`.`id` = `joined_table2`.`id` INNER JOIN `joined_table3` ON `my_table`.`id` = `joined_table3`.`id`', + ], + 'Oracle' => [ + 'string' => 'SELECT "my_table"."my_table_column" AS "my_table_column", NOW() AS "aliased_column", "joined_table3".* FROM "my_table" INNER JOIN "joined_table2" ON "my_table"."id" = "joined_table2"."id" INNER JOIN "joined_table3" ON "my_table"."id" = "joined_table3"."id"', + ], + 'SqlServer' => [ + 'string' => 'SELECT [my_table].[my_table_column] AS [my_table_column], NOW() AS [aliased_column], [joined_table3].* FROM [my_table] INNER JOIN [joined_table2] ON [my_table].[id] = [joined_table2].[id] INNER JOIN [joined_table3] ON [my_table].[id] = [joined_table3].[id]', + ] + // @codingStandardsIgnoreEnd + ] + ], + 'Select::processJoin()' => [ + 'sqlObject' => $this->select('a') + ->join(['b' => $this->select('c')->where(['cc' => 10])], 'd=e')->where(['x' => 20]), + 'expected' => [ + // @codingStandardsIgnoreStart + 'sql92' => [ + 'string' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = \'10\') AS "b" ON "d"="e" WHERE "x" = \'20\'', + 'prepare' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = ?) AS "b" ON "d"="e" WHERE "x" = ?', + 'parameters' => ['subselect1where1' => 10, 'where1' => 20], + ], + 'MySql' => [ + 'string' => 'SELECT `a`.*, `b`.* FROM `a` INNER JOIN (SELECT `c`.* FROM `c` WHERE `cc` = \'10\') AS `b` ON `d`=`e` WHERE `x` = \'20\'', + 'prepare' => 'SELECT `a`.*, `b`.* FROM `a` INNER JOIN (SELECT `c`.* FROM `c` WHERE `cc` = ?) AS `b` ON `d`=`e` WHERE `x` = ?', + 'parameters' => ['subselect2where1' => 10, 'where2' => 20], + ], + 'Oracle' => [ + 'string' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = \'10\') "b" ON "d"="e" WHERE "x" = \'20\'', + 'prepare' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = ?) "b" ON "d"="e" WHERE "x" = ?', + 'parameters' => ['subselect2where1' => 10, 'where2' => 20], + ], + 'SqlServer' => [ + 'string' => 'SELECT [a].*, [b].* FROM [a] INNER JOIN (SELECT [c].* FROM [c] WHERE [cc] = \'10\') AS [b] ON [d]=[e] WHERE [x] = \'20\'', + 'prepare' => 'SELECT [a].*, [b].* FROM [a] INNER JOIN (SELECT [c].* FROM [c] WHERE [cc] = ?) AS [b] ON [d]=[e] WHERE [x] = ?', + 'parameters' => ['subselect2where1' => 10, 'where2' => 20], + ], + // @codingStandardsIgnoreEnd + ], + ], + 'Ddl::CreateTable::processColumns()' => [ + 'sqlObject' => $this->createTable('foo') + ->addColumn($this->createColumn('col1') + ->setOption('identity', true) + ->setOption('comment', 'Comment1')) + ->addColumn($this->createColumn('col2') + ->setOption('identity', true) + ->setOption('comment', 'Comment2')), + 'expected' => [ + // @codingStandardsIgnoreStart + 'sql92' => "CREATE TABLE \"foo\" ( \n \"col1\" INTEGER NOT NULL,\n \"col2\" INTEGER NOT NULL \n)", + 'MySql' => "CREATE TABLE `foo` ( \n `col1` INTEGER NOT NULL AUTO_INCREMENT COMMENT 'Comment1',\n `col2` INTEGER NOT NULL AUTO_INCREMENT COMMENT 'Comment2' \n)", + 'Oracle' => "CREATE TABLE \"foo\" ( \n \"col1\" INTEGER NOT NULL,\n \"col2\" INTEGER NOT NULL \n)", + 'SqlServer' => "CREATE TABLE [foo] ( \n [col1] INTEGER NOT NULL,\n [col2] INTEGER NOT NULL \n)", + // @codingStandardsIgnoreEnd + ], + ], + 'Ddl::CreateTable::processTable()' => [ + 'sqlObject' => $this->createTable('foo')->setTemporary(true), + 'expected' => [ + 'sql92' => "CREATE TEMPORARY TABLE \"foo\" ( \n)", + 'MySql' => "CREATE TEMPORARY TABLE `foo` ( \n)", + 'Oracle' => "CREATE TEMPORARY TABLE \"foo\" ( \n)", + 'SqlServer' => "CREATE TABLE [#foo] ( \n)", + ], + ], + 'Select::processSubSelect()' => [ + 'sqlObject' => $this->select([ + 'a' => $this->select([ + 'b' => $this->select('c')->where(['cc' => 'CC']), + ])->where(['bb' => 'BB']), + ])->where(['aa' => 'AA']), + 'expected' => [ + // @codingStandardsIgnoreStart + 'sql92' => [ + 'string' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = \'CC\') AS "b" WHERE "bb" = \'BB\') AS "a" WHERE "aa" = \'AA\'', + 'prepare' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = ?) AS "b" WHERE "bb" = ?) AS "a" WHERE "aa" = ?', + 'parameters' => ['subselect2where1' => 'CC', 'subselect1where1' => 'BB', 'where1' => 'AA'], + ], + 'MySql' => [ + 'string' => 'SELECT `a`.* FROM (SELECT `b`.* FROM (SELECT `c`.* FROM `c` WHERE `cc` = \'CC\') AS `b` WHERE `bb` = \'BB\') AS `a` WHERE `aa` = \'AA\'', + 'prepare' => 'SELECT `a`.* FROM (SELECT `b`.* FROM (SELECT `c`.* FROM `c` WHERE `cc` = ?) AS `b` WHERE `bb` = ?) AS `a` WHERE `aa` = ?', + 'parameters' => ['subselect4where1' => 'CC', 'subselect3where1' => 'BB', 'where2' => 'AA'], + ], + 'Oracle' => [ + 'string' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = \'CC\') "b" WHERE "bb" = \'BB\') "a" WHERE "aa" = \'AA\'', + 'prepare' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = ?) "b" WHERE "bb" = ?) "a" WHERE "aa" = ?', + 'parameters' => ['subselect4where1' => 'CC', 'subselect3where1' => 'BB', 'where2' => 'AA'], + ], + 'SqlServer' => [ + 'string' => 'SELECT [a].* FROM (SELECT [b].* FROM (SELECT [c].* FROM [c] WHERE [cc] = \'CC\') AS [b] WHERE [bb] = \'BB\') AS [a] WHERE [aa] = \'AA\'', + 'prepare' => 'SELECT [a].* FROM (SELECT [b].* FROM (SELECT [c].* FROM [c] WHERE [cc] = ?) AS [b] WHERE [bb] = ?) AS [a] WHERE [aa] = ?', + 'parameters' => ['subselect4where1' => 'CC', 'subselect3where1' => 'BB', 'where2' => 'AA'], + ], + // @codingStandardsIgnoreEnd + ], + ], + 'Delete::processSubSelect()' => [ + 'sqlObject' => $this->delete('foo')->where(['x' => $this->select('foo')->where(['x' => 'y'])]), + 'expected' => [ + 'sql92' => [ + 'string' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', + 'prepare' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', + 'parameters' => ['subselect1where1' => 'y'], + ], + 'MySql' => [ + 'string' => 'DELETE FROM `foo` WHERE `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = \'y\')', + 'prepare' => 'DELETE FROM `foo` WHERE `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = ?)', + 'parameters' => ['subselect2where1' => 'y'], + ], + 'Oracle' => [ + 'string' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', + 'prepare' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', + 'parameters' => ['subselect3where1' => 'y'], + ], + 'SqlServer' => [ + 'string' => 'DELETE FROM [foo] WHERE [x] = (SELECT [foo].* FROM [foo] WHERE [x] = \'y\')', + 'prepare' => 'DELETE FROM [foo] WHERE [x] = (SELECT [foo].* FROM [foo] WHERE [x] = ?)', + 'parameters' => ['subselect4where1' => 'y'], + ], + ], + ], + 'Update::processSubSelect()' => [ + 'sqlObject' => $this->update('foo')->set(['x' => $this->select('foo')]), + 'expected' => [ + 'sql92' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo")', + 'MySql' => 'UPDATE `foo` SET `x` = (SELECT `foo`.* FROM `foo`)', + 'Oracle' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo")', + 'SqlServer' => 'UPDATE [foo] SET [x] = (SELECT [foo].* FROM [foo])', + ], + ], + 'Insert::processSubSelect()' => [ + 'sqlObject' => $this->insert('foo')->select($this->select('foo')->where(['x' => 'y'])), + 'expected' => [ + 'sql92' => [ + 'string' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = \'y\'', + 'prepare' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = ?', + 'parameters' => ['subselect1where1' => 'y'], + ], + 'MySql' => [ + 'string' => 'INSERT INTO `foo` SELECT `foo`.* FROM `foo` WHERE `x` = \'y\'', + 'prepare' => 'INSERT INTO `foo` SELECT `foo`.* FROM `foo` WHERE `x` = ?', + 'parameters' => ['subselect2where1' => 'y'], + ], + 'Oracle' => [ + 'string' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = \'y\'', + 'prepare' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = ?', + 'parameters' => ['subselect3where1' => 'y'], + ], + 'SqlServer' => [ + 'string' => 'INSERT INTO [foo] SELECT [foo].* FROM [foo] WHERE [x] = \'y\'', + 'prepare' => 'INSERT INTO [foo] SELECT [foo].* FROM [foo] WHERE [x] = ?', + 'parameters' => ['subselect4where1' => 'y'], + ], + ], + ], + 'Update::processExpression()' => [ + 'sqlObject' => $this->update('foo')->set( + ['x' => new Sql\Expression('?', [$this->select('foo')->where(['x' => 'y'])])] + ), + 'expected' => [ + 'sql92' => [ + 'string' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', + 'prepare' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', + 'parameters' => ['subselect1where1' => 'y'], + ], + 'MySql' => [ + 'string' => 'UPDATE `foo` SET `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = \'y\')', + 'prepare' => 'UPDATE `foo` SET `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = ?)', + 'parameters' => ['subselect2where1' => 'y'], + ], + 'Oracle' => [ + 'string' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', + 'prepare' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', + 'parameters' => ['subselect3where1' => 'y'], + ], + 'SqlServer' => [ + 'string' => 'UPDATE [foo] SET [x] = (SELECT [foo].* FROM [foo] WHERE [x] = \'y\')', + 'prepare' => 'UPDATE [foo] SET [x] = (SELECT [foo].* FROM [foo] WHERE [x] = ?)', + 'parameters' => ['subselect4where1' => 'y'], + ], + ], + ], + 'Update::processJoins()' => [ + 'sqlObject' => $this->update('foo')->set(['x' => 'y'])->where(['xx' => 'yy'])->join( + 'bar', + 'bar.barId = foo.barId' + ), + 'expected' => [ + // @codingStandardsIgnoreStart + 'sql92' => [ + 'string' => 'UPDATE "foo" INNER JOIN "bar" ON "bar"."barId" = "foo"."barId" SET "x" = \'y\' WHERE "xx" = \'yy\'', + ], + 'MySql' => [ + 'string' => 'UPDATE `foo` INNER JOIN `bar` ON `bar`.`barId` = `foo`.`barId` SET `x` = \'y\' WHERE `xx` = \'yy\'', + ], + 'Oracle' => [ + 'string' => 'UPDATE "foo" INNER JOIN "bar" ON "bar"."barId" = "foo"."barId" SET "x" = \'y\' WHERE "xx" = \'yy\'', + ], + 'SqlServer' => [ + 'string' => 'UPDATE [foo] INNER JOIN [bar] ON [bar].[barId] = [foo].[barId] SET [x] = \'y\' WHERE [xx] = \'yy\'', + ], + // @codingStandardsIgnoreEnd + ], + ], + ]; + } + + protected function dataProviderDecorators() + { + return [ + 'RootDecorators::Select' => [ + 'sqlObject' => $this->select('foo')->where(['x' => $this->select('bar')]), + 'expected' => [ + 'sql92' => [ + 'decorators' => [ + 'Zend\Db\Sql\Select' => new TestAsset\SelectDecorator, + ], + 'string' => 'SELECT "foo".* FROM "foo" WHERE "x" = (SELECT "bar".* FROM "bar")', + ], + 'MySql' => [ + 'decorators' => [ + 'Zend\Db\Sql\Select' => new TestAsset\SelectDecorator, + ], + 'string' => 'SELECT `foo`.* FROM `foo` WHERE `x` = (SELECT `bar`.* FROM `bar`)', + ], + 'Oracle' => [ + 'decorators' => [ + 'Zend\Db\Sql\Select' => new TestAsset\SelectDecorator, + ], + 'string' => 'SELECT "foo".* FROM "foo" WHERE "x" = (SELECT "bar".* FROM "bar")', + ], + 'SqlServer' => [ + 'decorators' => [ + 'Zend\Db\Sql\Select' => new TestAsset\SelectDecorator, + ], + 'string' => 'SELECT [foo].* FROM [foo] WHERE [x] = (SELECT [bar].* FROM [bar])', + ], + ], + ], + // @codingStandardsIgnoreStart + /* TODO - should be implemented + 'RootDecorators::Insert' => array( + 'sqlObject' => $this->insert('foo')->select($this->select()), + 'expected' => array( + 'sql92' => array( + 'decorators' => array( + 'Zend\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') + ), + 'string' => 'INSERT INTO "foo" {=SELECT_Sql92=}', + ), + 'MySql' => array( + 'decorators' => array( + 'Zend\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_MySql=}') + ), + 'string' => 'INSERT INTO `foo` {=SELECT_MySql=}', + ), + 'Oracle' => array( + 'decorators' => array( + 'Zend\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Oracle\SelectDecorator', '{=SELECT_Oracle=}') + ), + 'string' => 'INSERT INTO "foo" {=SELECT_Oracle=}', + ), + 'SqlServer' => array( + 'decorators' => array( + 'Zend\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\SqlServer\SelectDecorator', '{=SELECT_SqlServer=}') + ), + 'string' => 'INSERT INTO [foo] {=SELECT_SqlServer=}', + ), + ), + ), + 'RootDecorators::Delete' => array( + 'sqlObject' => $this->delete('foo')->where(array('x'=>$this->select('foo'))), + 'expected' => array( + 'sql92' => array( + 'decorators' => array( + 'Zend\Db\Sql\Delete' => new TestAsset\DeleteDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') + ), + 'string' => 'DELETE FROM "foo" WHERE "x" = ({=SELECT_Sql92=})', + ), + 'MySql' => array( + 'decorators' => array( + 'Zend\Db\Sql\Delete' => new TestAsset\DeleteDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_MySql=}') + ), + 'string' => 'DELETE FROM `foo` WHERE `x` = ({=SELECT_MySql=})', + ), + 'Oracle' => array( + 'decorators' => array( + 'Zend\Db\Sql\Delete' => new TestAsset\DeleteDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Oracle\SelectDecorator', '{=SELECT_Oracle=}') + ), + 'string' => 'DELETE FROM "foo" WHERE "x" = ({=SELECT_Oracle=})', + ), + 'SqlServer' => array( + 'decorators' => array( + 'Zend\Db\Sql\Delete' => new TestAsset\DeleteDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\SqlServer\SelectDecorator', '{=SELECT_SqlServer=}') + ), + 'string' => 'DELETE FROM [foo] WHERE [x] = ({=SELECT_SqlServer=})', + ), + ), + ), + 'RootDecorators::Update' => array( + 'sqlObject' => $this->update('foo')->where(array('x'=>$this->select('foo'))), + 'expected' => array( + 'sql92' => array( + 'decorators' => array( + 'Zend\Db\Sql\Update' => new TestAsset\UpdateDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') + ), + 'string' => 'UPDATE "foo" SET WHERE "x" = ({=SELECT_Sql92=})', + ), + 'MySql' => array( + 'decorators' => array( + 'Zend\Db\Sql\Update' => new TestAsset\UpdateDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_MySql=}') + ), + 'string' => 'UPDATE `foo` SET WHERE `x` = ({=SELECT_MySql=})', + ), + 'Oracle' => array( + 'decorators' => array( + 'Zend\Db\Sql\Update' => new TestAsset\UpdateDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Oracle\SelectDecorator', '{=SELECT_Oracle=}') + ), + 'string' => 'UPDATE "foo" SET WHERE "x" = ({=SELECT_Oracle=})', + ), + 'SqlServer' => array( + 'decorators' => array( + 'Zend\Db\Sql\Update' => new TestAsset\UpdateDecorator, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\SqlServer\SelectDecorator', '{=SELECT_SqlServer=}') + ), + 'string' => 'UPDATE [foo] SET WHERE [x] = ({=SELECT_SqlServer=})', + ), + ), + ), + 'DecorableExpression()' => array( + 'sqlObject' => $this->update('foo')->where(array('x'=>new Sql\Expression('?', array($this->select('foo'))))), + 'expected' => array( + 'sql92' => array( + 'decorators' => array( + 'Zend\Db\Sql\Expression' => new TestAsset\DecorableExpression, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') + ), + 'string' => 'UPDATE "foo" SET WHERE "x" = {decorate-({=SELECT_Sql92=})-decorate}', + ), + 'MySql' => array( + 'decorators' => array( + 'Zend\Db\Sql\Expression' => new TestAsset\DecorableExpression, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_MySql=}') + ), + 'string' => 'UPDATE `foo` SET WHERE `x` = {decorate-({=SELECT_MySql=})-decorate}', + ), + 'Oracle' => array( + 'decorators' => array( + 'Zend\Db\Sql\Expression' => new TestAsset\DecorableExpression, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\Oracle\SelectDecorator', '{=SELECT_Oracle=}') + ), + 'string' => 'UPDATE "foo" SET WHERE "x" = {decorate-({=SELECT_Oracle=})-decorate}', + ), + 'SqlServer' => array( + 'decorators' => array( + 'Zend\Db\Sql\Expression' => new TestAsset\DecorableExpression, + 'Zend\Db\Sql\Select' => array('Zend\Db\Sql\Platform\SqlServer\SelectDecorator', '{=SELECT_SqlServer=}') + ), + 'string' => 'UPDATE [foo] SET WHERE [x] = {decorate-({=SELECT_SqlServer=})-decorate}', + ), + ), + ),*/ + // @codingStandardsIgnoreEnd + ]; + } + + public function dataProvider() + { + $data = array_merge( + $this->dataProviderCommonProcessMethods(), + $this->dataProviderDecorators() + ); + + $res = []; + foreach ($data as $index => $test) { + foreach ($test['expected'] as $platform => $expected) { + $res[$index . '->' . $platform] = [ + 'sqlObject' => $test['sqlObject'], + 'platform' => $platform, + 'expected' => $expected, + ]; + } + } + return $res; + } + + /** + * @param type $sqlObject + * @param type $platform + * @param type $expected + * @dataProvider dataProvider + */ + public function test($sqlObject, $platform, $expected) + { + $sql = new Sql\Sql($this->resolveAdapter($platform)); + + if (is_array($expected) && isset($expected['decorators'])) { + foreach ($expected['decorators'] as $type => $decorator) { + $sql->getSqlPlatform()->setTypeDecorator($type, $this->resolveDecorator($decorator)); + } + } + + $expectedString = is_string($expected) ? $expected : (isset($expected['string']) ? $expected['string'] : null); + if ($expectedString) { + $actual = $sql->getSqlStringForSqlObject($sqlObject); + self::assertEquals($expectedString, $actual, "getSqlString()"); + } + if (is_array($expected) && isset($expected['prepare'])) { + $actual = $sql->prepareStatementForSqlObject($sqlObject); + self::assertEquals($expected['prepare'], $actual->getSql(), "prepareStatement()"); + if (isset($expected['parameters'])) { + $actual = $actual->getParameterContainer()->getNamedArray(); + self::assertSame($expected['parameters'], $actual, "parameterContainer()"); + } + } + } + + protected function resolveDecorator($decorator) + { + if (is_array($decorator)) { + $decoratorMock = $this->getMockBuilder($decorator[0]) + ->setMethods(['buildSqlString']) + ->setConstructorArgs([null]) + ->getMock(); + $decoratorMock->expects($this->any())->method('buildSqlString')->will($this->returnValue($decorator[1])); + return $decoratorMock; + } + if ($decorator instanceof Sql\Platform\PlatformDecoratorInterface) { + return $decorator; + } + return; + } + + protected function resolveAdapter($platform) + { + switch ($platform) { + case 'sql92': + $platform = new TestAsset\TrustingSql92Platform(); + break; + case 'MySql': + $platform = new TestAsset\TrustingMysqlPlatform(); + break; + case 'Oracle': + $platform = new TestAsset\TrustingOraclePlatform(); + break; + case 'SqlServer': + $platform = new TestAsset\TrustingSqlServerPlatform(); + break; + default: + $platform = null; + } + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnCallback(function () { + return new Adapter\StatementContainer; + })); + + return new Adapter\Adapter($mockDriver, $platform); + } + + public function __call($name, $arguments) + { + $arg0 = isset($arguments[0]) ? $arguments[0] : null; + switch ($name) { + case 'select': + return new Sql\Select($arg0); + case 'delete': + return new Sql\Delete($arg0); + case 'update': + return new Sql\Update($arg0); + case 'insert': + return new Sql\Insert($arg0); + case 'createTable': + return new Sql\Ddl\CreateTable($arg0); + case 'createColumn': + return new Sql\Ddl\Column\Column($arg0); + } + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/SqlTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/SqlTest.php new file mode 100644 index 00000000..f38148a9 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/SqlTest.php @@ -0,0 +1,237 @@ +getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); + $mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + + // setup mock adapter + $this->mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver, new TestAsset\TrustingSql92Platform()]) + ->getMock(); + + $this->sql = new Sql($this->mockAdapter, 'foo'); + } + + /** + * @covers \Zend\Db\Sql\Sql::__construct + */ + // @codingStandardsIgnoreStart + public function test__construct() + { + // @codingStandardsIgnoreEnd + $sql = new Sql($this->mockAdapter); + + self::assertFalse($sql->hasTable()); + + $sql->setTable('foo'); + self::assertSame('foo', $sql->getTable()); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Table must be a string, array or instance of TableIdentifier.'); + $sql->setTable(null); + } + + /** + * @covers \Zend\Db\Sql\Sql::select + */ + public function testSelect() + { + $select = $this->sql->select(); + self::assertInstanceOf('Zend\Db\Sql\Select', $select); + self::assertSame('foo', $select->getRawState('table')); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage( + 'This Sql object is intended to work with only the table "foo" provided at construction time.' + ); + $this->sql->select('bar'); + } + + /** + * @covers \Zend\Db\Sql\Sql::insert + */ + public function testInsert() + { + $insert = $this->sql->insert(); + self::assertInstanceOf('Zend\Db\Sql\Insert', $insert); + self::assertSame('foo', $insert->getRawState('table')); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage( + 'This Sql object is intended to work with only the table "foo" provided at construction time.' + ); + $this->sql->insert('bar'); + } + + /** + * @covers \Zend\Db\Sql\Sql::update + */ + public function testUpdate() + { + $update = $this->sql->update(); + self::assertInstanceOf('Zend\Db\Sql\Update', $update); + self::assertSame('foo', $update->getRawState('table')); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage( + 'This Sql object is intended to work with only the table "foo" provided at construction time.' + ); + $this->sql->update('bar'); + } + + /** + * @covers \Zend\Db\Sql\Sql::delete + */ + public function testDelete() + { + $delete = $this->sql->delete(); + + self::assertInstanceOf('Zend\Db\Sql\Delete', $delete); + self::assertSame('foo', $delete->getRawState('table')); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage( + 'This Sql object is intended to work with only the table "foo" provided at construction time.' + ); + $this->sql->delete('bar'); + } + + /** + * @covers \Zend\Db\Sql\Sql::prepareStatementForSqlObject + */ + public function testPrepareStatementForSqlObject() + { + $insert = $this->sql->insert()->columns(['foo'])->values(['foo' => 'bar']); + $stmt = $this->sql->prepareStatementForSqlObject($insert); + self::assertInstanceOf('Zend\Db\Adapter\Driver\StatementInterface', $stmt); + } + + /** + * @group 6890 + */ + public function testForDifferentAdapters() + { + $adapterSql92 = $this->getAdapterForPlatform('sql92'); + $adapterMySql = $this->getAdapterForPlatform('MySql'); + $adapterOracle = $this->getAdapterForPlatform('Oracle'); + $adapterSqlServer = $this->getAdapterForPlatform('SqlServer'); + + $select = $this->sql->select()->offset(10); + + // Default + self::assertEquals( + 'SELECT "foo".* FROM "foo" OFFSET \'10\'', + $this->sql->buildSqlString($select) + ); + $this->mockAdapter->getDriver()->createStatement()->expects($this->any())->method('setSql') + ->with($this->equalTo('SELECT "foo".* FROM "foo" OFFSET ?')); + $this->sql->prepareStatementForSqlObject($select); + + // Sql92 + self::assertEquals( + 'SELECT "foo".* FROM "foo" OFFSET \'10\'', + $this->sql->buildSqlString($select, $adapterSql92) + ); + $adapterSql92->getDriver()->createStatement()->expects($this->any())->method('setSql') + ->with($this->equalTo('SELECT "foo".* FROM "foo" OFFSET ?')); + $this->sql->prepareStatementForSqlObject($select, null, $adapterSql92); + + // MySql + self::assertEquals( + 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET 10', + $this->sql->buildSqlString($select, $adapterMySql) + ); + $adapterMySql->getDriver()->createStatement()->expects($this->any())->method('setSql') + ->with($this->equalTo('SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET ?')); + $this->sql->prepareStatementForSqlObject($select, null, $adapterMySql); + + // Oracle + self::assertEquals( + 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (10)', + $this->sql->buildSqlString($select, $adapterOracle) + ); + // @codingStandardsIgnoreStart + $adapterOracle->getDriver()->createStatement()->expects($this->any())->method('setSql') + ->with($this->equalTo('SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (:offset)')); + // @codingStandardsIgnoreEnd + $this->sql->prepareStatementForSqlObject($select, null, $adapterOracle); + + // SqlServer + self::assertContains( + 'WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN 10+1 AND 0+10', + $this->sql->buildSqlString($select, $adapterSqlServer) + ); + $adapterSqlServer->getDriver()->createStatement()->expects($this->any())->method('setSql') + ->with($this->stringContains( + 'WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ?+1 AND ?+?' + )); + $this->sql->prepareStatementForSqlObject($select, null, $adapterSqlServer); + } + + /** + * Data provider + * + * @param string $platform + * + * @return Adapter + */ + protected function getAdapterForPlatform($platform) + { + switch ($platform) { + case 'sql92': + $platform = new TestAsset\TrustingSql92Platform(); + break; + case 'MySql': + $platform = new TestAsset\TrustingMysqlPlatform(); + break; + case 'Oracle': + $platform = new TestAsset\TrustingOraclePlatform(); + break; + case 'SqlServer': + $platform = new TestAsset\TrustingSqlServerPlatform(); + break; + default: + $platform = null; + } + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + + return new Adapter($mockDriver, $platform); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/TableIdentifierTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/TableIdentifierTest.php new file mode 100644 index 00000000..b1ec4f57 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/TableIdentifierTest.php @@ -0,0 +1,118 @@ +getTable()); + } + + public function testGetDefaultSchema() + { + $tableIdentifier = new TableIdentifier('foo'); + + self::assertNull($tableIdentifier->getSchema()); + } + + public function testGetSchema() + { + $tableIdentifier = new TableIdentifier('foo', 'bar'); + + self::assertSame('bar', $tableIdentifier->getSchema()); + } + + public function testGetTableFromObjectStringCast() + { + $table = $this->getMockBuilder('stdClass')->setMethods(['__toString'])->getMock(); + + $table->expects($this->once())->method('__toString')->will($this->returnValue('castResult')); + + $tableIdentifier = new TableIdentifier($table); + + self::assertSame('castResult', $tableIdentifier->getTable()); + self::assertSame('castResult', $tableIdentifier->getTable()); + } + + public function testGetSchemaFromObjectStringCast() + { + $schema = $this->getMockBuilder('stdClass')->setMethods(['__toString'])->getMock(); + + $schema->expects($this->once())->method('__toString')->will($this->returnValue('castResult')); + + $tableIdentifier = new TableIdentifier('foo', $schema); + + self::assertSame('castResult', $tableIdentifier->getSchema()); + self::assertSame('castResult', $tableIdentifier->getSchema()); + } + + /** + * @dataProvider invalidTableProvider + * + * @param mixed $invalidTable + */ + public function testRejectsInvalidTable($invalidTable) + { + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + + new TableIdentifier($invalidTable); + } + + /** + * @dataProvider invalidSchemaProvider + * + * @param mixed $invalidSchema + */ + public function testRejectsInvalidSchema($invalidSchema) + { + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + + new TableIdentifier('foo', $invalidSchema); + } + + /** + * Data provider + * + * @return mixed[][] + */ + public function invalidTableProvider() + { + return array_merge( + [[null]], + $this->invalidSchemaProvider() + ); + } + + /** + * Data provider + * + * @return mixed[][] + */ + public function invalidSchemaProvider() + { + return [ + [''], + [new stdClass()], + [[]], + ]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/Sql/UpdateTest.php b/bundled-libs/zendframework/zend-db/test/unit/Sql/UpdateTest.php new file mode 100644 index 00000000..4fa6e5bd --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/Sql/UpdateTest.php @@ -0,0 +1,429 @@ +update = new Update; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\Sql\Update::table + */ + public function testTable() + { + $this->update->table('foo', 'bar'); + self::assertEquals('foo', $this->readAttribute($this->update, 'table')); + + $tableIdentifier = new TableIdentifier('foo', 'bar'); + $this->update->table($tableIdentifier); + self::assertEquals($tableIdentifier, $this->readAttribute($this->update, 'table')); + } + + /** + * @covers \Zend\Db\Sql\Update::__construct + */ + public function testConstruct() + { + $update = new Update('foo'); + self::assertEquals('foo', $this->readAttribute($update, 'table')); + } + + /** + * @covers \Zend\Db\Sql\Update::set + */ + public function testSet() + { + $this->update->set(['foo' => 'bar']); + self::assertEquals(['foo' => 'bar'], $this->update->getRawState('set')); + } + + /** + * @covers \Zend\Db\Sql\Update::set + */ + public function testSortableSet() + { + $this->update->set([ + 'two' => 'с_two', + 'three' => 'с_three', + ]); + $this->update->set(['one' => 'с_one'], 10); + + self::assertEquals( + [ + 'one' => 'с_one', + 'two' => 'с_two', + 'three' => 'с_three', + ], + $this->update->getRawState('set') + ); + } + + /** + * @covers \Zend\Db\Sql\Update::where + */ + public function testWhere() + { + $this->update->where('x = y'); + $this->update->where(['foo > ?' => 5]); + $this->update->where(['id' => 2]); + $this->update->where(['a = b'], Where::OP_OR); + $this->update->where(['c1' => null]); + $this->update->where(['c2' => [1, 2, 3]]); + $this->update->where([new \Zend\Db\Sql\Predicate\IsNotNull('c3')]); + $where = $this->update->where; + + $predicates = $this->readAttribute($where, 'predicates'); + self::assertEquals('AND', $predicates[0][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[0][1]); + + self::assertEquals('AND', $predicates[1][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[1][1]); + + self::assertEquals('AND', $predicates[2][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[2][1]); + + self::assertEquals('OR', $predicates[3][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\Literal', $predicates[3][1]); + + self::assertEquals('AND', $predicates[4][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\IsNull', $predicates[4][1]); + + self::assertEquals('AND', $predicates[5][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\In', $predicates[5][1]); + + self::assertEquals('AND', $predicates[6][0]); + self::assertInstanceOf('Zend\Db\Sql\Predicate\IsNotNull', $predicates[6][1]); + + $where = new Where; + $this->update->where($where); + self::assertSame($where, $this->update->where); + + $this->update->where(function ($what) use ($where) { + self::assertSame($where, $what); + }); + + $this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Predicate cannot be null'); + $this->update->where(null); + } + + /** + * @group ZF2-240 + * @covers \Zend\Db\Sql\Update::where + */ + public function testPassingMultipleKeyValueInWhereClause() + { + $update = clone $this->update; + $update->table('table'); + $update->set(['fld1' => 'val1']); + $update->where(['id1' => 'val1', 'id2' => 'val2']); + self::assertEquals( + 'UPDATE "table" SET "fld1" = \'val1\' WHERE "id1" = \'val1\' AND "id2" = \'val2\'', + $update->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @covers \Zend\Db\Sql\Update::getRawState + */ + public function testGetRawState() + { + $this->update->table('foo') + ->set(['bar' => 'baz']) + ->where('x = y'); + + self::assertEquals('foo', $this->update->getRawState('table')); + self::assertEquals(true, $this->update->getRawState('emptyWhereProtection')); + self::assertEquals(['bar' => 'baz'], $this->update->getRawState('set')); + self::assertInstanceOf('Zend\Db\Sql\Where', $this->update->getRawState('where')); + } + + /** + * @covers \Zend\Db\Sql\Update::prepareStatement + */ + public function testPrepareStatement() + { + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $pContainer = new \Zend\Db\Adapter\ParameterContainer([]); + $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); + + $mockStatement->expects($this->at(1)) + ->method('setSql') + ->with($this->equalTo('UPDATE "foo" SET "bar" = ?, "boo" = NOW() WHERE x = y')); + + $this->update->table('foo') + ->set(['bar' => 'baz', 'boo' => new Expression('NOW()')]) + ->where('x = y'); + + $this->update->prepareStatement($mockAdapter, $mockStatement); + + // with TableIdentifier + $this->update = new Update; + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $pContainer = new \Zend\Db\Adapter\ParameterContainer([]); + $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); + + $mockStatement->expects($this->at(1)) + ->method('setSql') + ->with($this->equalTo('UPDATE "sch"."foo" SET "bar" = ?, "boo" = NOW() WHERE x = y')); + + $this->update->table(new TableIdentifier('foo', 'sch')) + ->set(['bar' => 'baz', 'boo' => new Expression('NOW()')]) + ->where('x = y'); + + $this->update->prepareStatement($mockAdapter, $mockStatement); + } + + /** + * @covers \Zend\Db\Sql\Update::getSqlString + */ + public function testGetSqlString() + { + $this->update->table('foo') + ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) + ->where('x = y'); + + self::assertEquals( + 'UPDATE "foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', + $this->update->getSqlString(new TrustingSql92Platform()) + ); + + // with TableIdentifier + $this->update = new Update; + $this->update->table(new TableIdentifier('foo', 'sch')) + ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) + ->where('x = y'); + + self::assertEquals( + 'UPDATE "sch"."foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', + $this->update->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @group 6768 + * @group 6773 + */ + public function testGetSqlStringForFalseUpdateValueParameter() + { + $this->update = new Update; + $this->update->table(new TableIdentifier('foo', 'sch')) + ->set(['bar' => false, 'boo' => 'test', 'bam' => true]) + ->where('x = y'); + self::assertEquals( + 'UPDATE "sch"."foo" SET "bar" = \'\', "boo" = \'test\', "bam" = \'1\' WHERE x = y', + $this->update->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @covers \Zend\Db\Sql\Update::__get + */ + public function testGetUpdate() + { + $getWhere = $this->update->__get('where'); + self::assertInstanceOf('Zend\Db\Sql\Where', $getWhere); + } + + /** + * @covers \Zend\Db\Sql\Update::__get + */ + public function testGetUpdateFails() + { + $getWhat = $this->update->__get('what'); + self::assertNull($getWhat); + } + + /** + * @covers \Zend\Db\Sql\Update::__clone + */ + public function testCloneUpdate() + { + $update1 = clone $this->update; + $update1->table('foo') + ->set(['bar' => 'baz']) + ->where('x = y'); + + $update2 = clone $this->update; + $update2->table('foo') + ->set(['bar' => 'baz']) + ->where([ + 'id = ?' => 1, + ]); + self::assertEquals( + 'UPDATE "foo" SET "bar" = \'baz\' WHERE id = \'1\'', + $update2->getSqlString(new TrustingSql92Platform) + ); + } + + /** + * @coversNothing + */ + public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement() + { + $updateIgnore = new UpdateIgnore(); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); + $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); + $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $pContainer = new \Zend\Db\Adapter\ParameterContainer([]); + $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); + + $mockStatement->expects($this->at(1)) + ->method('setSql') + ->with($this->equalTo('UPDATE IGNORE "foo" SET "bar" = ?, "boo" = NOW() WHERE x = y')); + + $updateIgnore->table('foo') + ->set(['bar' => 'baz', 'boo' => new Expression('NOW()')]) + ->where('x = y'); + + $updateIgnore->prepareStatement($mockAdapter, $mockStatement); + } + + /** + * @coversNothing + */ + public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString() + { + $this->update = new UpdateIgnore(); + + $this->update->table('foo') + ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) + ->where('x = y'); + + self::assertEquals( + 'UPDATE IGNORE "foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', + $this->update->getSqlString(new TrustingSql92Platform()) + ); + + // with TableIdentifier + $this->update = new UpdateIgnore(); + $this->update->table(new TableIdentifier('foo', 'sch')) + ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) + ->where('x = y'); + + self::assertEquals( + 'UPDATE IGNORE "sch"."foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', + $this->update->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @covers \Zend\Db\Sql\Update::where + */ + public function testJoin() + { + $this->update->table('Document'); + $this->update->set(['x' => 'y']) + ->join( + 'User', // table name + 'User.UserId = Document.UserId' // expression to join on + // default JOIN INNER + ) + ->join( + 'Category', + 'Category.CategoryId = Document.CategoryId', + Join::JOIN_LEFT // (optional), one of inner, outer, left, right + ); + + self::assertEquals( + 'UPDATE "Document" INNER JOIN "User" ON "User"."UserId" = "Document"."UserId" ' + . 'LEFT JOIN "Category" ON "Category"."CategoryId" = "Document"."CategoryId" SET "x" = \'y\'', + $this->update->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * Here test if we want update fields from specific table. + * Important when we're updating fields that are existing in several tables in one query. + * The same test as above but here we will specify table in update params + */ + public function testJoinMultiUpdate() + { + $this->update->table('Document'); + $this->update->set(['Documents.x' => 'y']) + ->join( + 'User', + 'User.UserId = Document.UserId' + ) + ->join( + 'Category', + 'Category.CategoryId = Document.CategoryId', + Join::JOIN_LEFT + ); + + self::assertEquals( + 'UPDATE "Document" INNER JOIN "User" ON "User"."UserId" = "Document"."UserId" ' + . 'LEFT JOIN "Category" ON "Category"."CategoryId" = "Document"."CategoryId" SET "Documents"."x" = \'y\'', + $this->update->getSqlString(new TrustingSql92Platform()) + ); + } + + /** + * @testdox unit test: Test join() returns Update object (is chainable) + * @covers \Zend\Db\Sql\Update::join + */ + public function testJoinChainable() + { + $return = $this->update->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); + self::assertSame($this->update, $return); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TableGateway/AbstractTableGatewayTest.php b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/AbstractTableGatewayTest.php new file mode 100644 index 00000000..b0d7a1c7 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/AbstractTableGatewayTest.php @@ -0,0 +1,425 @@ +getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(5)); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); + + $mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $mockConnection->expects($this->any())->method('getLastGeneratedValue')->will($this->returnValue(10)); + + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); + + $this->mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + $this->mockSql = $this->getMockBuilder('Zend\Db\Sql\Sql') + ->setMethods(['select', 'insert', 'update', 'delete']) + ->setConstructorArgs([$this->mockAdapter, 'foo']) + ->getMock(); + $this->mockSql->expects($this->any())->method('select')->will($this->returnValue( + $this->getMockBuilder('Zend\Db\Sql\Select') + ->setMethods(['where', 'getRawState']) + ->setConstructorArgs(['foo']) + ->getMock() + )); + $this->mockSql->expects($this->any())->method('insert')->will($this->returnValue( + $this->getMockBuilder('Zend\Db\Sql\Insert') + ->setMethods(['prepareStatement', 'values']) + ->setConstructorArgs(['foo']) + ->getMock() + )); + $this->mockSql->expects($this->any())->method('update')->will($this->returnValue( + $this->getMockBuilder('Zend\Db\Sql\Update') + ->setMethods(['where', 'join']) + ->setConstructorArgs(['foo']) + ->getMock() + )); + $this->mockSql->expects($this->any())->method('delete')->will($this->returnValue( + $this->getMockBuilder('Zend\Db\Sql\Delete') + ->setMethods(['where']) + ->setConstructorArgs(['foo']) + ->getMock() + )); + + $this->mockFeatureSet = $this->getMockBuilder('Zend\Db\TableGateway\Feature\FeatureSet')->getMock(); + + $this->table = $this->getMockForAbstractClass( + 'Zend\Db\TableGateway\AbstractTableGateway' + //array('getTable') + ); + $tgReflection = new \ReflectionClass('Zend\Db\TableGateway\AbstractTableGateway'); + foreach ($tgReflection->getProperties() as $tgPropReflection) { + $tgPropReflection->setAccessible(true); + switch ($tgPropReflection->getName()) { + case 'table': + $tgPropReflection->setValue($this->table, 'foo'); + break; + case 'adapter': + $tgPropReflection->setValue($this->table, $this->mockAdapter); + break; + case 'resultSetPrototype': + $tgPropReflection->setValue($this->table, new ResultSet); + break; + case 'sql': + $tgPropReflection->setValue($this->table, $this->mockSql); + break; + case 'featureSet': + $tgPropReflection->setValue($this->table, $this->mockFeatureSet); + break; + } + } + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::getTable + */ + public function testGetTable() + { + self::assertEquals('foo', $this->table->getTable()); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::getAdapter + */ + public function testGetAdapter() + { + self::assertSame($this->mockAdapter, $this->table->getAdapter()); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::getSql + */ + public function testGetSql() + { + self::assertInstanceOf('Zend\Db\Sql\Sql', $this->table->getSql()); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::getResultSetPrototype + */ + public function testGetSelectResultPrototype() + { + self::assertInstanceOf('Zend\Db\ResultSet\ResultSet', $this->table->getResultSetPrototype()); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::select + * @covers \Zend\Db\TableGateway\AbstractTableGateway::selectWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeSelect + */ + public function testSelectWithNoWhere() + { + $resultSet = $this->table->select(); + + // check return types + self::assertInstanceOf('Zend\Db\ResultSet\ResultSet', $resultSet); + self::assertNotSame($this->table->getResultSetPrototype(), $resultSet); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::select + * @covers \Zend\Db\TableGateway\AbstractTableGateway::selectWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeSelect + */ + public function testSelectWithWhereString() + { + $mockSelect = $this->mockSql->select(); + + $mockSelect->expects($this->any()) + ->method('getRawState') + ->will($this->returnValue([ + 'table' => $this->table->getTable(), + 'columns' => [], + ])); + + // assert select::from() is called + $mockSelect->expects($this->once()) + ->method('where') + ->with($this->equalTo('foo')); + + $this->table->select('foo'); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::select + * @covers \Zend\Db\TableGateway\AbstractTableGateway::selectWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeSelect + * + * This is a test for the case when a valid $select is built using an aliased table name, then used + * with AbstractTableGateway::selectWith (or AbstractTableGateway::select). + * + * $myTable = new MyTable(...); + * $sql = new \Zend\Db\Sql\Sql(...); + * $select = $sql->select()->from(array('t' => 'mytable')); + * + * // Following fails, with Fatal error: Uncaught exception 'RuntimeException' with message + * 'The table name of the provided select object must match that of the table' unless fix is provided. + * $myTable->selectWith($select); + * + */ + public function testSelectWithArrayTable() + { + // Case 1 + + $select1 = $this->getMockBuilder('Zend\Db\Sql\Select')->setMethods(['getRawState'])->getMock(); + $select1->expects($this->once()) + ->method('getRawState') + ->will($this->returnValue([ + 'table' => 'foo', // Standard table name format, valid according to Select::from() + 'columns' => null, + ])); + $return = $this->table->selectWith($select1); + self::assertNotNull($return); + + // Case 2 + + $select1 = $this->getMockBuilder('Zend\Db\Sql\Select')->setMethods(['getRawState'])->getMock(); + $select1->expects($this->once()) + ->method('getRawState') + ->will($this->returnValue([ + 'table' => ['f' => 'foo'], // Alias table name format, valid according to Select::from() + 'columns' => null, + ])); + $return = $this->table->selectWith($select1); + self::assertNotNull($return); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::insert + * @covers \Zend\Db\TableGateway\AbstractTableGateway::insertWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeInsert + */ + public function testInsert() + { + $mockInsert = $this->mockSql->insert(); + + $mockInsert->expects($this->once()) + ->method('prepareStatement') + ->with($this->mockAdapter); + + + $mockInsert->expects($this->once()) + ->method('values') + ->with($this->equalTo(['foo' => 'bar'])); + + $affectedRows = $this->table->insert(['foo' => 'bar']); + self::assertEquals(5, $affectedRows); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::update + * @covers \Zend\Db\TableGateway\AbstractTableGateway::updateWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeUpdate + */ + public function testUpdate() + { + $mockUpdate = $this->mockSql->update(); + + // assert select::from() is called + $mockUpdate->expects($this->once()) + ->method('where') + ->with($this->equalTo('id = 2')); + + $affectedRows = $this->table->update(['foo' => 'bar'], 'id = 2'); + self::assertEquals(5, $affectedRows); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::update + * @covers \Zend\Db\TableGateway\AbstractTableGateway::updateWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeUpdate + */ + public function testUpdateWithJoin() + { + $mockUpdate = $this->mockSql->update(); + + $joins = [ + [ + 'name' => 'baz', + 'on' => 'foo.fooId = baz.fooId', + 'type' => Sql\Join::JOIN_LEFT, + ], + ]; + + // assert select::from() is called + $mockUpdate->expects($this->once()) + ->method('where') + ->with($this->equalTo('id = 2')); + + $mockUpdate->expects($this->once()) + ->method('join') + ->with($joins[0]['name'], $joins[0]['on'], $joins[0]['type']); + + $affectedRows = $this->table->update(['foo.field' => 'bar'], 'id = 2', $joins); + self::assertEquals(5, $affectedRows); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::update + * @covers \Zend\Db\TableGateway\AbstractTableGateway::updateWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeUpdate + */ + public function testUpdateWithJoinDefaultType() + { + $mockUpdate = $this->mockSql->update(); + + $joins = [ + [ + 'name' => 'baz', + 'on' => 'foo.fooId = baz.fooId', + ], + ]; + + // assert select::from() is called + $mockUpdate->expects($this->once()) + ->method('where') + ->with($this->equalTo('id = 2')); + + $mockUpdate->expects($this->once()) + ->method('join') + ->with($joins[0]['name'], $joins[0]['on'], Sql\Join::JOIN_INNER); + + $affectedRows = $this->table->update(['foo.field' => 'bar'], 'id = 2', $joins); + self::assertEquals(5, $affectedRows); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::update + * @covers \Zend\Db\TableGateway\AbstractTableGateway::updateWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeUpdate + */ + public function testUpdateWithNoCriteria() + { + $mockUpdate = $this->mockSql->update(); + + $affectedRows = $this->table->update(['foo' => 'bar']); + self::assertEquals(5, $affectedRows); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::delete + * @covers \Zend\Db\TableGateway\AbstractTableGateway::deleteWith + * @covers \Zend\Db\TableGateway\AbstractTableGateway::executeDelete + */ + public function testDelete() + { + $mockDelete = $this->mockSql->delete(); + + // assert select::from() is called + $mockDelete->expects($this->once()) + ->method('where') + ->with($this->equalTo('foo')); + + $affectedRows = $this->table->delete('foo'); + self::assertEquals(5, $affectedRows); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::getLastInsertValue + */ + public function testGetLastInsertValue() + { + $this->table->insert(['foo' => 'bar']); + self::assertEquals(10, $this->table->getLastInsertValue()); + } + + public function testInitializeBuildsAResultSet() + { + $stub = $this->getMockForAbstractClass(AbstractTableGateway::class); + + $tgReflection = new \ReflectionClass('Zend\Db\TableGateway\AbstractTableGateway'); + foreach ($tgReflection->getProperties() as $tgPropReflection) { + $tgPropReflection->setAccessible(true); + switch ($tgPropReflection->getName()) { + case 'table': + $tgPropReflection->setValue($stub, 'foo'); + break; + case 'adapter': + $tgPropReflection->setValue($stub, $this->mockAdapter); + break; + case 'featureSet': + $tgPropReflection->setValue($stub, $this->mockFeatureSet); + break; + } + } + + $stub->initialize(); + $this->assertInstanceOf(ResultSet::class, $stub->getResultSetPrototype()); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::__get + */ + // @codingStandardsIgnoreStart + public function test__get() + { + // @codingStandardsIgnoreEnd + $this->table->insert(['foo']); // trigger last insert id update + + self::assertEquals(10, $this->table->lastInsertValue); + self::assertSame($this->mockAdapter, $this->table->adapter); + //self::assertEquals('foo', $this->table->table); + } + + /** + * @covers \Zend\Db\TableGateway\AbstractTableGateway::__clone + */ + // @codingStandardsIgnoreStart + public function test__clone() + { + // @codingStandardsIgnoreEnd + $cTable = clone $this->table; + self::assertSame($this->mockAdapter, $cTable->getAdapter()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/EventFeatureTest.php b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/EventFeatureTest.php new file mode 100644 index 00000000..93c7cda3 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/EventFeatureTest.php @@ -0,0 +1,246 @@ +eventManager = new EventManager; + $this->event = new EventFeature\TableGatewayEvent(); + $this->feature = new EventFeature($this->eventManager, $this->event); + $this->tableGateway = $this->getMockForAbstractClass('Zend\Db\TableGateway\TableGateway', [], '', false); + $this->feature->setTableGateway($this->tableGateway); + + // typically runs before everything else + $this->feature->preInitialize(); + } + + public function testGetEventManager() + { + self::assertSame($this->eventManager, $this->feature->getEventManager()); + } + + public function testGetEvent() + { + self::assertSame($this->event, $this->feature->getEvent()); + } + + public function testPreInitialize() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_PRE_INITIALIZE, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->preInitialize(); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_PRE_INITIALIZE, $event->getName()); + } + + public function testPostInitialize() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_POST_INITIALIZE, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->postInitialize(); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_POST_INITIALIZE, $event->getName()); + } + + public function testPreSelect() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_PRE_SELECT, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->preSelect($select = $this->getMockBuilder('Zend\Db\Sql\Select')->getMock()); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_PRE_SELECT, $event->getName()); + self::assertSame($select, $event->getParam('select')); + } + + public function testPostSelect() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_POST_SELECT, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->postSelect( + ($stmt = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock()), + ($result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock()), + ($resultset = $this->getMockBuilder('Zend\Db\ResultSet\ResultSet')->getMock()) + ); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_POST_SELECT, $event->getName()); + self::assertSame($stmt, $event->getParam('statement')); + self::assertSame($result, $event->getParam('result')); + self::assertSame($resultset, $event->getParam('result_set')); + } + + public function testPreInsert() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_PRE_INSERT, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->preInsert($insert = $this->getMockBuilder('Zend\Db\Sql\Insert')->getMock()); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_PRE_INSERT, $event->getName()); + self::assertSame($insert, $event->getParam('insert')); + } + + public function testPostInsert() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_POST_INSERT, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->postInsert( + ($stmt = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock()), + ($result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock()) + ); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_POST_INSERT, $event->getName()); + self::assertSame($stmt, $event->getParam('statement')); + self::assertSame($result, $event->getParam('result')); + } + + public function testPreUpdate() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_PRE_UPDATE, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->preUpdate($update = $this->getMockBuilder('Zend\Db\Sql\Update')->getMock()); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_PRE_UPDATE, $event->getName()); + self::assertSame($update, $event->getParam('update')); + } + + public function testPostUpdate() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_POST_UPDATE, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->postUpdate( + ($stmt = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock()), + ($result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock()) + ); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_POST_UPDATE, $event->getName()); + self::assertSame($stmt, $event->getParam('statement')); + self::assertSame($result, $event->getParam('result')); + } + + public function testPreDelete() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_PRE_DELETE, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->preDelete($delete = $this->getMockBuilder('Zend\Db\Sql\Delete')->getMock()); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_PRE_DELETE, $event->getName()); + self::assertSame($delete, $event->getParam('delete')); + } + + public function testPostDelete() + { + $closureHasRun = false; + + /** @var $event EventFeature\TableGatewayEvent */ + $event = null; + $this->eventManager->attach(EventFeature::EVENT_POST_DELETE, function ($e) use (&$closureHasRun, &$event) { + $event = $e; + $closureHasRun = true; + }); + + $this->feature->postDelete( + ($stmt = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock()), + ($result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock()) + ); + self::assertTrue($closureHasRun); + self::assertInstanceOf('Zend\Db\TableGateway\TableGateway', $event->getTarget()); + self::assertEquals(EventFeature::EVENT_POST_DELETE, $event->getName()); + self::assertSame($stmt, $event->getParam('statement')); + self::assertSame($result, $event->getParam('result')); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/FeatureSetTest.php b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/FeatureSetTest.php new file mode 100644 index 00000000..ea6da2ef --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/FeatureSetTest.php @@ -0,0 +1,176 @@ +getMockBuilder('Zend\Db\Adapter\AdapterInterface')->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( + $mockStatement + )); + $mockMasterAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); + $mockMasterAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( + new \Zend\Db\Adapter\Platform\Sql92() + )); + + $mockSlaveAdapter = $this->getMockBuilder('Zend\Db\Adapter\AdapterInterface')->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( + $mockStatement + )); + $mockSlaveAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); + $mockSlaveAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( + new \Zend\Db\Adapter\Platform\Sql92() + )); + + $tableGatewayMock = $this->getMockForAbstractClass('Zend\Db\TableGateway\AbstractTableGateway'); + + //feature doesn't have tableGateway, but FeatureSet has + $feature = new MasterSlaveFeature($mockSlaveAdapter); + + $featureSet = new FeatureSet; + $featureSet->setTableGateway($tableGatewayMock); + + self::assertInstanceOf('Zend\Db\TableGateway\Feature\FeatureSet', $featureSet->addFeature($feature)); + } + + /** + * @cover FeatureSet::addFeature + * @group ZF2-4993 + */ + public function testAddFeatureThatFeatureHasTableGatewayButFeatureSetDoesNotHave() + { + $tableGatewayMock = $this->getMockForAbstractClass('Zend\Db\TableGateway\AbstractTableGateway'); + + $metadataMock = $this->getMockBuilder('Zend\Db\Metadata\MetadataInterface')->getMock(); + $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); + + $constraintObject = new ConstraintObject('id_pk', 'table'); + $constraintObject->setColumns(['id']); + $constraintObject->setType('PRIMARY KEY'); + + $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); + + //feature have tableGateway, but FeatureSet doesn't has + $feature = new MetadataFeature($metadataMock); + $feature->setTableGateway($tableGatewayMock); + + $featureSet = new FeatureSet; + self::assertInstanceOf('Zend\Db\TableGateway\Feature\FeatureSet', $featureSet->addFeature($feature)); + } + + /** + * @covers \Zend\Db\TableGateway\Feature\FeatureSet::canCallMagicCall + */ + public function testCanCallMagicCallReturnsTrueForAddedMethodOfAddedFeature() + { + $feature = new SequenceFeature('id', 'table_sequence'); + $featureSet = new FeatureSet; + $featureSet->addFeature($feature); + + self::assertTrue( + $featureSet->canCallMagicCall('lastSequenceId'), + "Should have been able to call lastSequenceId from the Sequence Feature" + ); + } + + /** + * @covers \Zend\Db\TableGateway\Feature\FeatureSet::canCallMagicCall + */ + public function testCanCallMagicCallReturnsFalseForAddedMethodOfAddedFeature() + { + $feature = new SequenceFeature('id', 'table_sequence'); + $featureSet = new FeatureSet; + $featureSet->addFeature($feature); + + self::assertFalse( + $featureSet->canCallMagicCall('postInitialize'), + "Should have been able to call postInitialize from the MetaData Feature" + ); + } + + /** + * @covers \Zend\Db\TableGateway\Feature\FeatureSet::canCallMagicCall + */ + public function testCanCallMagicCallReturnsFalseWhenNoFeaturesHaveBeenAdded() + { + $featureSet = new FeatureSet; + self::assertFalse( + $featureSet->canCallMagicCall('lastSequenceId') + ); + } + + /** + * @covers \Zend\Db\TableGateway\Feature\FeatureSet::callMagicCall + */ + public function testCallMagicCallSucceedsForValidMethodOfAddedFeature() + { + $sequenceName = 'table_sequence'; + + $platformMock = $this->getMockBuilder('Zend\Db\Adapter\Platform\Postgresql')->getMock(); + $platformMock->expects($this->any()) + ->method('getName')->will($this->returnValue('PostgreSQL')); + + $resultMock = $this->getMockBuilder('Zend\Db\Adapter\Driver\Pgsql\Result')->getMock(); + $resultMock->expects($this->any()) + ->method('current') + ->will($this->returnValue(['currval' => 1])); + + $statementMock = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $statementMock->expects($this->any()) + ->method('prepare') + ->with('SELECT CURRVAL(\'' . $sequenceName . '\')'); + $statementMock->expects($this->any()) + ->method('execute') + ->will($this->returnValue($resultMock)); + + $adapterMock = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->disableOriginalConstructor() + ->getMock(); + $adapterMock->expects($this->any()) + ->method('getPlatform')->will($this->returnValue($platformMock)); + $adapterMock->expects($this->any()) + ->method('createStatement')->will($this->returnValue($statementMock)); + + $tableGatewayMock = $this->getMockBuilder('Zend\Db\TableGateway\AbstractTableGateway') + ->disableOriginalConstructor() + ->getMock(); + + $reflectionClass = new ReflectionClass('Zend\Db\TableGateway\AbstractTableGateway'); + $reflectionProperty = $reflectionClass->getProperty('adapter'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($tableGatewayMock, $adapterMock); + + $feature = new SequenceFeature('id', 'table_sequence'); + $feature->setTableGateway($tableGatewayMock); + $featureSet = new FeatureSet; + $featureSet->addFeature($feature); + self::assertEquals(1, $featureSet->callMagicCall('lastSequenceId', null)); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php new file mode 100644 index 00000000..e1cedb8c --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php @@ -0,0 +1,101 @@ +mockMasterAdapter = $this->getMockBuilder('Zend\Db\Adapter\AdapterInterface')->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( + $mockStatement + )); + $this->mockMasterAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); + $this->mockMasterAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( + new \Zend\Db\Adapter\Platform\Sql92() + )); + + $this->mockSlaveAdapter = $this->getMockBuilder('Zend\Db\Adapter\AdapterInterface')->getMock(); + + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( + $mockStatement + )); + $this->mockSlaveAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); + $this->mockSlaveAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( + new \Zend\Db\Adapter\Platform\Sql92() + )); + + $this->feature = new MasterSlaveFeature($this->mockSlaveAdapter); + } + + public function testPostInitialize() + { + /** @var $table \Zend\Db\TableGateway\TableGateway */ + $this->getMockForAbstractClass( + 'Zend\Db\TableGateway\TableGateway', + ['foo', $this->mockMasterAdapter, $this->feature] + ); + // postInitialize is run + self::assertSame($this->mockSlaveAdapter, $this->feature->getSlaveSql()->getAdapter()); + } + + public function testPreSelect() + { + $table = $this->getMockForAbstractClass( + 'Zend\Db\TableGateway\TableGateway', + ['foo', $this->mockMasterAdapter, $this->feature] + ); + + $this->mockSlaveAdapter->getDriver()->createStatement() + ->expects($this->once())->method('execute')->will($this->returnValue( + $this->getMockBuilder('Zend\Db\ResultSet\ResultSet')->getMock() + )); + $table->select('foo = bar'); + } + + public function testPostSelect() + { + $table = $this->getMockForAbstractClass( + 'Zend\Db\TableGateway\TableGateway', + ['foo', $this->mockMasterAdapter, $this->feature] + ); + $this->mockSlaveAdapter->getDriver()->createStatement() + ->expects($this->once())->method('execute')->will($this->returnValue( + $this->getMockBuilder('Zend\Db\ResultSet\ResultSet')->getMock() + )); + + $masterSql = $table->getSql(); + $table->select('foo = bar'); + + // test that the sql object is restored + self::assertSame($masterSql, $table->getSql()); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MetadataFeatureTest.php b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MetadataFeatureTest.php new file mode 100644 index 00000000..8c6c5290 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/MetadataFeatureTest.php @@ -0,0 +1,125 @@ +getMockForAbstractClass('Zend\Db\TableGateway\AbstractTableGateway'); + $metadataMock = $this->getMockBuilder('Zend\Db\Metadata\MetadataInterface')->getMock(); + $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); + + $constraintObject = new ConstraintObject('id_pk', 'table'); + $constraintObject->setColumns(['id']); + $constraintObject->setType('PRIMARY KEY'); + + $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); + + $feature = new MetadataFeature($metadataMock); + $feature->setTableGateway($tableGatewayMock); + $feature->postInitialize(); + + self::assertEquals(['id', 'name'], $tableGatewayMock->getColumns()); + } + + public function testPostInitializeRecordsPrimaryKeyColumnToSharedMetadata() + { + /** @var AbstractTableGateway $tableGatewayMock */ + $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); + $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); + $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); + $metadataMock->expects($this->any()) + ->method('getTable') + ->will($this->returnValue(new TableObject('foo'))); + + + $constraintObject = new ConstraintObject('id_pk', 'table'); + $constraintObject->setColumns(['id']); + $constraintObject->setType('PRIMARY KEY'); + + $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); + + $feature = new MetadataFeature($metadataMock); + $feature->setTableGateway($tableGatewayMock); + $feature->postInitialize(); + + $r = new ReflectionProperty(MetadataFeature::class, 'sharedData'); + $r->setAccessible(true); + $sharedData = $r->getValue($feature); + + self::assertTrue( + isset($sharedData['metadata']['primaryKey']), + 'Shared data must have metadata entry for primary key' + ); + self::assertSame($sharedData['metadata']['primaryKey'], 'id'); + } + + public function testPostInitializeRecordsListOfColumnsInPrimaryKeyToSharedMetadata() + { + /** @var AbstractTableGateway $tableGatewayMock */ + $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); + $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); + $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); + $metadataMock->expects($this->any()) + ->method('getTable') + ->will($this->returnValue(new TableObject('foo'))); + + + $constraintObject = new ConstraintObject('id_pk', 'table'); + $constraintObject->setColumns(['composite', 'id']); + $constraintObject->setType('PRIMARY KEY'); + + $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); + + $feature = new MetadataFeature($metadataMock); + $feature->setTableGateway($tableGatewayMock); + $feature->postInitialize(); + + $r = new ReflectionProperty(MetadataFeature::class, 'sharedData'); + $r->setAccessible(true); + $sharedData = $r->getValue($feature); + + self::assertTrue( + isset($sharedData['metadata']['primaryKey']), + 'Shared data must have metadata entry for primary key' + ); + self::assertEquals($sharedData['metadata']['primaryKey'], ['composite', 'id']); + } + + public function testPostInitializeSkipsPrimaryKeyCheckIfNotTable() + { + /** @var AbstractTableGateway $tableGatewayMock */ + $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); + $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); + $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); + $metadataMock->expects($this->any()) + ->method('getTable') + ->will($this->returnValue(new ViewObject('foo'))); + + $metadataMock->expects($this->never())->method('getConstraints'); + + $feature = new MetadataFeature($metadataMock); + $feature->setTableGateway($tableGatewayMock); + $feature->postInitialize(); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/SequenceFeatureTest.php b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/SequenceFeatureTest.php new file mode 100644 index 00000000..932362e0 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/Feature/SequenceFeatureTest.php @@ -0,0 +1,98 @@ +feature = new SequenceFeature($this->primaryKeyField, $this->sequenceName); + } + + /** + * @dataProvider nextSequenceIdProvider + */ + public function testNextSequenceId($platformName, $statementSql) + { + $platform = $this->getMockForAbstractClass('Zend\Db\Adapter\Platform\PlatformInterface', ['getName']); + $platform->expects($this->any()) + ->method('getName') + ->will($this->returnValue($platformName)); + $platform->expects($this->any()) + ->method('quoteIdentifier') + ->will($this->returnValue($this->sequenceName)); + $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods(['getPlatform', 'createStatement']) + ->disableOriginalConstructor() + ->getMock(); + $adapter->expects($this->any()) + ->method('getPlatform') + ->will($this->returnValue($platform)); + $result = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\ResultInterface', + [], + '', + false, + true, + true, + ['current'] + ); + $result->expects($this->any()) + ->method('current') + ->will($this->returnValue(['nextval' => 2])); + $statement = $this->getMockForAbstractClass( + 'Zend\Db\Adapter\Driver\StatementInterface', + [], + '', + false, + true, + true, + ['prepare', 'execute'] + ); + $statement->expects($this->any()) + ->method('execute') + ->will($this->returnValue($result)); + $statement->expects($this->any()) + ->method('prepare') + ->with($statementSql); + $adapter->expects($this->once()) + ->method('createStatement') + ->will($this->returnValue($statement)); + $this->tableGateway = $this->getMockForAbstractClass( + 'Zend\Db\TableGateway\TableGateway', + ['table', $adapter], + '', + true + ); + $this->feature->setTableGateway($this->tableGateway); + $this->feature->nextSequenceId(); + } + + public function nextSequenceIdProvider() + { + return [['PostgreSQL', 'SELECT NEXTVAL(\'"' . $this->sequenceName . '"\')'], + ['Oracle', 'SELECT ' . $this->sequenceName . '.NEXTVAL as "nextval" FROM dual']]; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TableGateway/TableGatewayTest.php b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/TableGatewayTest.php new file mode 100644 index 00000000..b402cdd6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TableGateway/TableGatewayTest.php @@ -0,0 +1,263 @@ +getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface')->getMock(); + $mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock(); + $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); + $mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock(); + $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); + $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); + $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); + + // setup mock adapter + $this->mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter') + ->setMethods() + ->setConstructorArgs([$mockDriver]) + ->getMock(); + } + + /** + * Beside other tests checks for plain string table identifier + */ + public function testConstructor() + { + // constructor with only required args + $table = new TableGateway( + 'foo', + $this->mockAdapter + ); + + self::assertEquals('foo', $table->getTable()); + self::assertSame($this->mockAdapter, $table->getAdapter()); + self::assertInstanceOf('Zend\Db\TableGateway\Feature\FeatureSet', $table->getFeatureSet()); + self::assertInstanceOf('Zend\Db\ResultSet\ResultSet', $table->getResultSetPrototype()); + self::assertInstanceOf('Zend\Db\Sql\Sql', $table->getSql()); + + // injecting all args + $table = new TableGateway( + 'foo', + $this->mockAdapter, + $featureSet = new Feature\FeatureSet, + $resultSet = new ResultSet, + $sql = new Sql($this->mockAdapter, 'foo') + ); + + self::assertEquals('foo', $table->getTable()); + self::assertSame($this->mockAdapter, $table->getAdapter()); + self::assertSame($featureSet, $table->getFeatureSet()); + self::assertSame($resultSet, $table->getResultSetPrototype()); + self::assertSame($sql, $table->getSql()); + + // constructor expects exception + $this->expectException('Zend\Db\TableGateway\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Table name must be a string or an instance of Zend\Db\Sql\TableIdentifier'); + new TableGateway( + null, + $this->mockAdapter + ); + } + + /** + * @group 6726 + * @group 6740 + */ + public function testTableAsString() + { + $ti = 'fooTable.barSchema'; + // constructor with only required args + $table = new TableGateway( + $ti, + $this->mockAdapter + ); + + self::assertEquals($ti, $table->getTable()); + } + + /** + * @group 6726 + * @group 6740 + */ + public function testTableAsTableIdentifierObject() + { + $ti = new TableIdentifier('fooTable', 'barSchema'); + // constructor with only required args + $table = new TableGateway( + $ti, + $this->mockAdapter + ); + + self::assertEquals($ti, $table->getTable()); + } + + /** + * @group 6726 + * @group 6740 + */ + public function testTableAsAliasedTableIdentifierObject() + { + $aliasedTI = ['foo' => new TableIdentifier('fooTable', 'barSchema')]; + // constructor with only required args + $table = new TableGateway( + $aliasedTI, + $this->mockAdapter + ); + + self::assertEquals($aliasedTI, $table->getTable()); + } + + public function aliasedTables() + { + $identifier = new TableIdentifier('Users'); + return [ + 'simple-alias' => [['U' => 'Users'], 'Users'], + 'identifier-alias' => [['U' => $identifier], $identifier], + ]; + } + + /** + * @group 7311 + * @dataProvider aliasedTables + */ + public function testInsertShouldResetTableToUnaliasedTable($tableValue, $expected) + { + $insert = new Insert(); + $insert->into($tableValue); + + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface') + ->getMock(); + $result->expects($this->once()) + ->method('getAffectedRows') + ->will($this->returnValue(1)); + + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface') + ->getMock(); + $statement->expects($this->once()) + ->method('execute') + ->will($this->returnValue($result)); + + $statementExpectation = function ($insert) use ($expected, $statement) { + $state = $insert->getRawState(); + self::assertSame($expected, $state['table']); + return $statement; + }; + + $sql = $this->getMockBuilder('Zend\Db\Sql\Sql') + ->disableOriginalConstructor() + ->getMock(); + $sql->expects($this->atLeastOnce()) + ->method('getTable') + ->will($this->returnValue($tableValue)); + $sql->expects($this->once()) + ->method('insert') + ->will($this->returnValue($insert)); + $sql->expects($this->once()) + ->method('prepareStatementForSqlObject') + ->with($this->equalTo($insert)) + ->will($this->returnCallback($statementExpectation)); + + $table = new TableGateway( + $tableValue, + $this->mockAdapter, + null, + null, + $sql + ); + + $result = $table->insert([ + 'foo' => 'FOO', + ]); + + $state = $insert->getRawState(); + self::assertInternalType('array', $state['table']); + self::assertEquals( + $tableValue, + $state['table'] + ); + } + + /** + * @dataProvider aliasedTables + */ + public function testUpdateShouldResetTableToUnaliasedTable($tableValue, $expected) + { + $update = new Update(); + $update->table($tableValue); + + $result = $this->getMockBuilder('Zend\Db\Adapter\Driver\ResultInterface') + ->getMock(); + $result->expects($this->once()) + ->method('getAffectedRows') + ->will($this->returnValue(1)); + + $statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface') + ->getMock(); + $statement->expects($this->once()) + ->method('execute') + ->will($this->returnValue($result)); + + $statementExpectation = function ($update) use ($expected, $statement) { + $state = $update->getRawState(); + self::assertSame($expected, $state['table']); + return $statement; + }; + + $sql = $this->getMockBuilder('Zend\Db\Sql\Sql') + ->disableOriginalConstructor() + ->getMock(); + $sql->expects($this->atLeastOnce()) + ->method('getTable') + ->will($this->returnValue($tableValue)); + $sql->expects($this->once()) + ->method('update') + ->will($this->returnValue($update)); + $sql->expects($this->once()) + ->method('prepareStatementForSqlObject') + ->with($this->equalTo($update)) + ->will($this->returnCallback($statementExpectation)); + + $table = new TableGateway( + $tableValue, + $this->mockAdapter, + null, + null, + $sql + ); + + $result = $table->update([ + 'foo' => 'FOO', + ], [ + 'bar' => 'BAR', + ]); + + $state = $update->getRawState(); + self::assertInternalType('array', $state['table']); + self::assertEquals( + $tableValue, + $state['table'] + ); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/ConnectionWrapper.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/ConnectionWrapper.php new file mode 100644 index 00000000..953a6e58 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/ConnectionWrapper.php @@ -0,0 +1,28 @@ +resource = new PdoStubDriver('foo', 'bar', 'baz'); + } + + public function getNestedTransactionsCount() + { + return $this->nestedTransactionsCount; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteDecorator.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteDecorator.php new file mode 100644 index 00000000..5678dcfd --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteDecorator.php @@ -0,0 +1,27 @@ +subject = $subject; + return $this; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteIgnore.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteIgnore.php new file mode 100644 index 00000000..d082e5fa --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/DeleteIgnore.php @@ -0,0 +1,26 @@ + 'DELETE IGNORE FROM %1$s', + self::SPECIFICATION_WHERE => 'WHERE %1$s', + ]; + + protected function processdeleteIgnore( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return parent::processDelete($platform, $driver, $parameterContainer); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/InsertDecorator.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/InsertDecorator.php new file mode 100644 index 00000000..233072ad --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/InsertDecorator.php @@ -0,0 +1,27 @@ +subject = $subject; + return $this; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/PdoStubDriver.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/PdoStubDriver.php new file mode 100644 index 00000000..886324f6 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/PdoStubDriver.php @@ -0,0 +1,24 @@ + 'REPLACE INTO %1$s (%2$s) VALUES (%3$s)', + self::SPECIFICATION_SELECT => 'REPLACE INTO %1$s %2$s %3$s', + ]; + + protected function processreplace( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return parent::processInsert($platform, $driver, $parameterContainer); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/SelectDecorator.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/SelectDecorator.php new file mode 100644 index 00000000..ee47e01b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/SelectDecorator.php @@ -0,0 +1,27 @@ +subject = $subject; + return $this; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TemporaryResultSet.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TemporaryResultSet.php new file mode 100644 index 00000000..2721478f --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TemporaryResultSet.php @@ -0,0 +1,7 @@ +quoteTrustedValue($value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingOraclePlatform.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingOraclePlatform.php new file mode 100644 index 00000000..b003719b --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingOraclePlatform.php @@ -0,0 +1,20 @@ +quoteTrustedValue($value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSql92Platform.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSql92Platform.php new file mode 100644 index 00000000..53725fb8 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSql92Platform.php @@ -0,0 +1,23 @@ +quoteTrustedValue($value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSqlServerPlatform.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSqlServerPlatform.php new file mode 100644 index 00000000..0f4bf957 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/TrustingSqlServerPlatform.php @@ -0,0 +1,20 @@ +quoteTrustedValue($value); + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateDecorator.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateDecorator.php new file mode 100644 index 00000000..5e52a736 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateDecorator.php @@ -0,0 +1,27 @@ +subject = $subject; + return $this; + } +} diff --git a/bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateIgnore.php b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateIgnore.php new file mode 100644 index 00000000..92a743b2 --- /dev/null +++ b/bundled-libs/zendframework/zend-db/test/unit/TestAsset/UpdateIgnore.php @@ -0,0 +1,27 @@ + 'UPDATE IGNORE %1$s', + self::SPECIFICATION_SET => 'SET %1$s', + self::SPECIFICATION_WHERE => 'WHERE %1$s', + ]; + + protected function processupdateIgnore( + PlatformInterface $platform, + DriverInterface $driver = null, + ParameterContainer $parameterContainer = null + ) { + return parent::processUpdate($platform, $driver, $parameterContainer); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/CHANGELOG.md b/bundled-libs/zendframework/zend-stdlib/CHANGELOG.md new file mode 100644 index 00000000..26c5e792 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/CHANGELOG.md @@ -0,0 +1,385 @@ +# Changelog + +All notable changes to this project will be documented in this file, in reverse chronological order by release. + +## 3.2.1 - 2018-08-28 + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#92](https://github.com/zendframework/zend-stdlib/pull/92) fixes serialization of `SplPriorityQueue` by ensuring its `$serial` + property is also serialized. + +- [#91](https://github.com/zendframework/zend-stdlib/pull/91) fixes behavior in the `ArrayObject` implementation that was not + compatible with PHP 7.3. + +## 3.2.0 - 2018-04-30 + +### Added + +- [#87](https://github.com/zendframework/zend-stdlib/pull/87) adds support for PHP 7.2. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- [#87](https://github.com/zendframework/zend-stdlib/pull/87) removes support for HHVM. + +### Fixed + +- Nothing. + +## 3.1.1 - 2018-04-12 + +### Added + +- Nothing. + +### Changed + +- [#67](https://github.com/zendframework/zend-stdlib/pull/67) changes the typehint of the `$content` property + of the `Message` class to indicate it is a string. All known implementations + already assumed this. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#60](https://github.com/zendframework/zend-stdlib/pull/60) fixes an issue whereby calling `remove()` would + incorrectly re-calculate the maximum priority stored in the queue. + +- [#60](https://github.com/zendframework/zend-stdlib/pull/60) fixes an infinite loop condition that can occur when + inserting an item at 0 priority. + +## 3.1.0 - 2016-09-13 + +### Added + +- [#63](https://github.com/zendframework/zend-stdlib/pull/63) adds a new + `Zend\Stdlib\ConsoleHelper` class, providing minimal support for writing + output to `STDOUT` and `STDERR`, with optional colorization, when the console + supports that feature. + +### Deprecated + +- [#38](https://github.com/zendframework/zend-stdlib/pull/38) deprecates + `Zend\Stdlib\JsonSerializable`, as all supported version of PHP now support + it. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + +## 3.0.1 - 2016-04-12 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#59](https://github.com/zendframework/zend-stdlib/pull/59) fixes a notice + when defining the `Zend\Json\Json::GLOB_BRACE` constant on systems using + non-gcc glob implementations. + +## 3.0.0 - 2016-02-03 + +### Added + +- [#51](https://github.com/zendframework/zend-stdlib/pull/51) adds PHP 7 as a + supported PHP version. +- [#51](https://github.com/zendframework/zend-stdlib/pull/51) adds a migration + document from v2 to v3. Hint: if you use hydrators, you need to be using + zend-hydrator instead! +- [#51](https://github.com/zendframework/zend-stdlib/pull/51) adds automated + documentation builds to gh-pages. + +### Deprecated + +- Nothing. + +### Removed + +- [#33](https://github.com/zendframework/zend-stdlib/pull/33) - removed + deprecated classes + - *All Hydrator classes* see #22. + - `Zend\Stdlib\CallbackHandler` see #35 +- [#37](https://github.com/zendframework/zend-stdlib/pull/37) - removed + deprecated classes and polyfills: + - `Zend\Stdlib\DateTime`; this had been deprecated since 2.5, and only + existed as a polyfill for the `createFromISO8601()` support, now standard + in all PHP versions we support. + - `Zend\Stdlib\Exception\InvalidCallbackException`, which was unused since #33. + - `Zend\Stdlib\Guard\GuardUtils`, which duplicated `Zend\Stdlib\Guard\AllGuardsTrait` + to allow usage with pre-PHP 5.4 versions. + - `src/compatibility/autoload.php`, which has been dprecated since 2.5. +- [#37](https://github.com/zendframework/zend-stdlib/pull/37) - removed + unneeded dependencies: + - zend-config (used only in testing ArrayUtils, and the test was redundant) + - zend-serializer (no longer used) +- [#51](https://github.com/zendframework/zend-stdlib/pull/51) removes the + documentation for hydrators, as those are part of the zend-hydrator + component. + +### Fixed + +- Nothing. + +## 2.7.4 - 2015-10-15 + +### Added + +- Nothing. + +### Deprecated + +- [#35](https://github.com/zendframework/zend-stdlib/pull/35) deprecates + `Zend\Stdlib\CallbackHandler`, as the one component that used it, + zend-eventmanager, will no longer depend on it starting in v3. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + +## 2.7.3 - 2015-09-24 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#27](https://github.com/zendframework/zend-stdlib/pull/27) fixes a race + condition in the `FastPriorityQueue::remove()` logic that occurs when removing + items iteratively from the same priority of a queue. + +## 2.7.2 - 2015-09-23 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#26](https://github.com/zendframework/zend-stdlib/pull/26) fixes a subtle + inheritance issue with deprecation in the hydrators, and updates the + `HydratorInterface` to also extend the zend-hydrator `HydratorInterface` to + ensure LSP is preserved. + +## 2.7.1 - 2015-09-22 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#24](https://github.com/zendframework/zend-stdlib/pull/24) fixes an import in + `FastPriorityQueue` to alias `SplPriorityQueue` in order to disambiguate with + the local override present in the component. + +## 2.7.0 - 2015-09-22 + +### Added + +- [#19](https://github.com/zendframework/zend-stdlib/pull/19) adds a new + `FastPriorityQueue` implementation. It follows the same signature as + `SplPriorityQueue`, but uses a performance-optimized algorithm: + + - inserts are 2x faster than `SplPriorityQueue` and 3x faster than the + `Zend\Stdlib\PriorityQueue` implementation. + - extracts are 4x faster than `SplPriorityQueue` and 4-5x faster than the + `Zend\Stdlib\PriorityQueue` implementation. + + The intention is to use this as a drop-in replacement in the + `zend-eventmanager` component to provide performance benefits. + +### Deprecated + +- [#20](https://github.com/zendframework/zend-stdlib/pull/20) deprecates *all + hydrator* classes, in favor of the new [zend-hydrator](https://github.com/zendframework/zend-hydrator) + component. All classes were updated to extend their zend-hydrator equivalents, + and marked as `@deprecated`, indicating the equivalent class from the other + repository. + + Users *should* immediately start changing their code to use the zend-hydrator + equivalents; in most cases, this can be as easy as removing the `Stdlib` + namespace from import statements or hydrator configuration. Hydrators will be + removed entirely from zend-stdlib in v3.0, and all future updates to hydrators + will occur in the zend-hydrator library. + + Changes with backwards compatibility implications: + + - Users implementing `Zend\Stdlib\Hydrator\HydratorAwareInterface` will need to + update their `setHydrator()` implementation to typehint on + `Zend\Hydrator\HydratorInterface`. This can be done by changing the import + statement for that interface as follows: + + ```php + // Replace this: + use Zend\Stdlib\Hydrator\HydratorInterface; + // with this: + use Zend\Hydrator\HydratorInterface; + ``` + + If you are not using imports, change the typehint within the signature itself: + + ```php + // Replace this: + public function setHydrator(\Zend\Stdlib\Hydrator\HydratorInterface $hydrator) + // with this: + public function setHydrator(\Zend\Hydrator\HydratorInterface $hydrator) + ``` + + If you are using `Zend\Stdlib\Hydrator\HydratorAwareTrait`, no changes are + necessary, unless you override that method. + + - If you were catching hydrator-generated exceptions, these were previously in + the `Zend\Stdlib\Exception` namespace. You will need to update your code to + catch exceptions in the `Zend\Hydrator\Exception` namespace. + + - Users who *do* migrate to zend-hydrator may end up in a situation where + their code will not work with existing libraries that are still type-hinting + on the zend-stdlib interfaces. We will be attempting to address that ASAP, + but the deprecation within zend-stdlib is necessary as a first step. + + In the meantime, you can write hydrators targeting zend-stdlib still in + order to guarantee compatibility. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + +## 2.6.0 - 2015-07-21 + +### Added + +- [#13](https://github.com/zendframework/zend-stdlib/pull/13) adds + `Zend\Stdlib\Hydrator\Iterator`, which provides mechanisms for hydrating + objects when iterating a traversable. This allows creating generic collection + resultsets; the original idea was pulled from + [PhlyMongo](https://github.com/phly/PhlyMongo), where it was used to hydrate + collections retrieved from MongoDB. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + +## 2.5.2 - 2015-07-21 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#9](https://github.com/zendframework/zend-stdlib/pull/9) fixes an issue with + count incrementation during insert in PriorityList, ensuring that incrementation only + occurs when the item inserted was not previously present in the list. + +## 2.4.4 - 2015-07-21 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#9](https://github.com/zendframework/zend-stdlib/pull/9) fixes an issue with + count incrementation during insert in PriorityList, ensuring that incrementation only + occurs when the item inserted was not previously present in the list. diff --git a/bundled-libs/zendframework/zend-stdlib/LICENSE.md b/bundled-libs/zendframework/zend-stdlib/LICENSE.md new file mode 100644 index 00000000..d44ab5dc --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/LICENSE.md @@ -0,0 +1,27 @@ +Copyright (c) 2005-2018, Zend Technologies USA, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +- Neither the name of Zend Technologies USA, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bundled-libs/zendframework/zend-stdlib/README.md b/bundled-libs/zendframework/zend-stdlib/README.md new file mode 100644 index 00000000..8d9ff96c --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/README.md @@ -0,0 +1,29 @@ +# zend-stdlib + +[![Build Status](https://secure.travis-ci.org/zendframework/zend-stdlib.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-stdlib) +[![Coverage Status](https://coveralls.io/repos/github/zendframework/zend-stdlib/badge.svg?branch=master)](https://coveralls.io/github/zendframework/zend-stdlib?branch=master) + +`Zend\Stdlib` is a set of components that implements general purpose utility +class for different scopes like: + +- array utilities functions; +- general messaging systems; +- string wrappers; +- etc. + +--- + +- File issues at https://github.com/zendframework/zend-stdlib/issues +- Documentation is at https://docs.zendframework.com/zend-stdlib/ + +## Benchmarks + +We provide scripts for benchmarking zend-stdlib using the +[PHPBench](https://github.com/phpbench/phpbench) framework; these can be +found in the `benchmark/` directory. + +To execute the benchmarks you can run the following command: + +```bash +$ vendor/bin/phpbench run --report=aggregate +``` diff --git a/bundled-libs/zendframework/zend-stdlib/benchmark/ExtractPriorityQueueBench.php b/bundled-libs/zendframework/zend-stdlib/benchmark/ExtractPriorityQueueBench.php new file mode 100644 index 00000000..5311a7bf --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/benchmark/ExtractPriorityQueueBench.php @@ -0,0 +1,54 @@ +splPriorityQueue = new SplPriorityQueue(); + $this->fastPriorityQueue = new FastPriorityQueue(); + $this->priorityQueue = new PriorityQueue(); + + for ($i = 0; $i < 5000; $i += 1) { + $priority = rand(1, 100); + $this->splPriorityQueue->insert('foo', $priority); + $this->fastPriorityQueue->insert('foo', $priority); + $this->priorityQueue->insert('foo', $priority); + } + } + + public function benchExtractSplPriorityQueue() + { + $this->splPriorityQueue->extract(); + } + + public function benchExtractPriorityQueue() + { + $this->priorityQueue->extract(); + } + + public function benchExtractFastPriorityQueue() + { + $this->fastPriorityQueue->extract(); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/benchmark/InsertPriorityQueueBench.php b/bundled-libs/zendframework/zend-stdlib/benchmark/InsertPriorityQueueBench.php new file mode 100644 index 00000000..db2bf5af --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/benchmark/InsertPriorityQueueBench.php @@ -0,0 +1,47 @@ +splPriorityQueue = new SplPriorityQueue(); + $this->fastPriorityQueue = new FastPriorityQueue(); + $this->priorityQueue = new PriorityQueue(); + } + + public function benchInsertSplPriorityQueue() + { + $this->splPriorityQueue->insert('foo', rand(1, 100)); + } + + public function benchInsertPriorityQueue() + { + $this->priorityQueue->insert('foo', rand(1, 100)); + } + + public function benchInsertFastPriorityQueue() + { + $this->fastPriorityQueue->insert('foo', rand(1, 100)); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/benchmark/RemovePriorityQueueBench.php b/bundled-libs/zendframework/zend-stdlib/benchmark/RemovePriorityQueueBench.php new file mode 100644 index 00000000..b7cbbb17 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/benchmark/RemovePriorityQueueBench.php @@ -0,0 +1,46 @@ +fastPriorityQueue = new FastPriorityQueue(); + $this->priorityQueue = new PriorityQueue(); + + for ($i = 0; $i < 1000; $i += 1) { + $priority = rand(1, 100); + $this->fastPriorityQueue->insert('foo', $priority); + $this->priorityQueue->insert('foo', $priority); + } + } + + public function benchRemovePriorityQueue() + { + $this->priorityQueue->remove('foo'); + } + + public function benchRemoveFastPriorityQueue() + { + $this->fastPriorityQueue->remove('foo'); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/composer.json b/bundled-libs/zendframework/zend-stdlib/composer.json new file mode 100644 index 00000000..8c990096 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/composer.json @@ -0,0 +1,56 @@ +{ + "name": "zendframework/zend-stdlib", + "description": "SPL extensions, array utilities, error handlers, and more", + "license": "BSD-3-Clause", + "keywords": [ + "zf", + "zendframework", + "stdlib" + ], + "support": { + "docs": "https://docs.zendframework.com/zend-stdlib/", + "issues": "https://github.com/zendframework/zend-stdlib/issues", + "source": "https://github.com/zendframework/zend-stdlib", + "rss": "https://github.com/zendframework/zend-stdlib/releases.atom", + "slack": "https://zendframework-slack.herokuapp.com", + "forum": "https://discourse.zendframework.com/c/questions/components" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpbench/phpbench": "^0.13", + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "autoload": { + "psr-4": { + "Zend\\Stdlib\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "ZendTest\\Stdlib\\": "test/", + "ZendBench\\Stdlib\\": "benchmark/" + } + }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev", + "dev-develop": "3.3.x-dev" + } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml" + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/docs/CODE_OF_CONDUCT.md b/bundled-libs/zendframework/zend-stdlib/docs/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..02fafcd1 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/CODE_OF_CONDUCT.md @@ -0,0 +1,43 @@ +# Contributor Code of Conduct + +This project adheres to [The Code Manifesto](http://codemanifesto.com) +as its guidelines for contributor interactions. + +## The Code Manifesto + +We want to work in an ecosystem that empowers developers to reach their +potential — one that encourages growth and effective collaboration. A space that +is safe for all. + +A space such as this benefits everyone that participates in it. It encourages +new developers to enter our field. It is through discussion and collaboration +that we grow, and through growth that we improve. + +In the effort to create such a place, we hold to these values: + +1. **Discrimination limits us.** This includes discrimination on the basis of + race, gender, sexual orientation, gender identity, age, nationality, technology + and any other arbitrary exclusion of a group of people. +2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort + levels. Remember that, and if brought to your attention, heed it. +3. **We are our biggest assets.** None of us were born masters of our trade. + Each of us has been helped along the way. Return that favor, when and where + you can. +4. **We are resources for the future.** As an extension of #3, share what you + know. Make yourself a resource to help those that come after you. +5. **Respect defines us.** Treat others as you wish to be treated. Make your + discussions, criticisms and debates from a position of respectfulness. Ask + yourself, is it true? Is it necessary? Is it constructive? Anything less is + unacceptable. +6. **Reactions require grace.** Angry responses are valid, but abusive language + and vindictive actions are toxic. When something happens that offends you, + handle it assertively, but be respectful. Escalate reasonably, and try to + allow the offender an opportunity to explain themselves, and possibly correct + the issue. +7. **Opinions are just that: opinions.** Each and every one of us, due to our + background and upbringing, have varying opinions. The fact of the matter, is + that is perfectly acceptable. Remember this: if you respect your own + opinions, you should respect the opinions of others. +8. **To err is human.** You might not intend it, but mistakes do happen and + contribute to build experience. Tolerate honest mistakes, and don't hesitate + to apologize if you make one yourself. diff --git a/bundled-libs/zendframework/zend-stdlib/docs/CONTRIBUTING.md b/bundled-libs/zendframework/zend-stdlib/docs/CONTRIBUTING.md new file mode 100644 index 00000000..afefd081 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/CONTRIBUTING.md @@ -0,0 +1,189 @@ +# CONTRIBUTING + +## RESOURCES + +If you wish to contribute to this project, please be sure to +read/subscribe to the following resources: + + - [Coding Standards](https://github.com/zendframework/zend-coding-standard) + - [Forums](https://discourse.zendframework.com/c/contributors) + - [Slack](https://zendframework-slack.herokuapp.com) + - [Code of Conduct](CODE_OF_CONDUCT.md) + +If you are working on new features or refactoring +[create a proposal](https://github.com/zendframework/zend-stdlib/issues/new). + +## RUNNING TESTS + +To run tests: + +- Clone the repository: + + ```console + $ git clone git://github.com/zendframework/zend-stdlib.git + $ cd zend-stdlib + ``` + +- Install dependencies via composer: + + ```console + $ composer install + ``` + + If you don't have `composer` installed, please download it from https://getcomposer.org/download/ + +- Run the tests using the "test" command shipped in the `composer.json`: + + ```console + $ composer test + ``` + +You can turn on conditional tests with the `phpunit.xml` file. +To do so: + + - Copy `phpunit.xml.dist` file to `phpunit.xml` + - Edit `phpunit.xml` to enable any specific functionality you + want to test, as well as to provide test values to utilize. + +## Running Coding Standards Checks + +First, ensure you've installed dependencies via composer, per the previous +section on running tests. + +To run CS checks only: + +```console +$ composer cs-check +``` + +To attempt to automatically fix common CS issues: + +```console +$ composer cs-fix +``` + +If the above fixes any CS issues, please re-run the tests to ensure +they pass, and make sure you add and commit the changes after verification. + +## Recommended Workflow for Contributions + +Your first step is to establish a public repository from which we can +pull your work into the master repository. We recommend using +[GitHub](https://github.com), as that is where the component is already hosted. + +1. Setup a [GitHub account](https://github.com/), if you haven't yet +2. Fork the repository (https://github.com/zendframework/zend-stdlib) +3. Clone the canonical repository locally and enter it. + + ```console + $ git clone git://github.com/zendframework/zend-stdlib.git + $ cd zend-stdlib + ``` + +4. Add a remote to your fork; substitute your GitHub username in the command + below. + + ```console + $ git remote add {username} git@github.com:{username}/zend-stdlib.git + $ git fetch {username} + ``` + +### Keeping Up-to-Date + +Periodically, you should update your fork or personal repository to +match the canonical ZF repository. Assuming you have setup your local repository +per the instructions above, you can do the following: + + +```console +$ git checkout master +$ git fetch origin +$ git rebase origin/master +# OPTIONALLY, to keep your remote up-to-date - +$ git push {username} master:master +``` + +If you're tracking other branches -- for example, the "develop" branch, where +new feature development occurs -- you'll want to do the same operations for that +branch; simply substitute "develop" for "master". + +### Working on a patch + +We recommend you do each new feature or bugfix in a new branch. This simplifies +the task of code review as well as the task of merging your changes into the +canonical repository. + +A typical workflow will then consist of the following: + +1. Create a new local branch based off either your master or develop branch. +2. Switch to your new local branch. (This step can be combined with the + previous step with the use of `git checkout -b`.) +3. Do some work, commit, repeat as necessary. +4. Push the local branch to your remote repository. +5. Send a pull request. + +The mechanics of this process are actually quite trivial. Below, we will +create a branch for fixing an issue in the tracker. + +```console +$ git checkout -b hotfix/9295 +Switched to a new branch 'hotfix/9295' +``` + +... do some work ... + + +```console +$ git commit +``` + +... write your log message ... + + +```console +$ git push {username} hotfix/9295:hotfix/9295 +Counting objects: 38, done. +Delta compression using up to 2 threads. +Compression objects: 100% (18/18), done. +Writing objects: 100% (20/20), 8.19KiB, done. +Total 20 (delta 12), reused 0 (delta 0) +To ssh://git@github.com/{username}/zend-stdlib.git + b5583aa..4f51698 HEAD -> master +``` + +To send a pull request, you have two options. + +If using GitHub, you can do the pull request from there. Navigate to +your repository, select the branch you just created, and then select the +"Pull Request" button in the upper right. Select the user/organization +"zendframework" (or whatever the upstream organization is) as the recipient. + +#### What branch to issue the pull request against? + +Which branch should you issue a pull request against? + +- For fixes against the stable release, issue the pull request against the + "master" branch. +- For new features, or fixes that introduce new elements to the public API (such + as new public methods or properties), issue the pull request against the + "develop" branch. + +### Branch Cleanup + +As you might imagine, if you are a frequent contributor, you'll start to +get a ton of branches both locally and on your remote. + +Once you know that your changes have been accepted to the master +repository, we suggest doing some cleanup of these branches. + +- Local branch cleanup + + ```console + $ git branch -d + ``` + +- Remote branch removal + + ```console + $ git push {username} : + ``` diff --git a/bundled-libs/zendframework/zend-stdlib/docs/ISSUE_TEMPLATE.md b/bundled-libs/zendframework/zend-stdlib/docs/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..55d12957 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/ISSUE_TEMPLATE.md @@ -0,0 +1,19 @@ + - [ ] I was not able to find an [open](https://github.com/zendframework/zend-stdlib/issues?q=is%3Aopen) or [closed](https://github.com/zendframework/zend-stdlib/issues?q=is%3Aclosed) issue matching what I'm seeing. + - [ ] This is not a question. (Questions should be asked on [slack](https://zendframework.slack.com/) ([Signup for Slack here](https://zendframework-slack.herokuapp.com/)) or our [forums](https://discourse.zendframework.com/).) + +Provide a narrative description of what you are trying to accomplish. + +### Code to reproduce the issue + + + +```php +``` + +### Expected results + + + +### Actual results + + diff --git a/bundled-libs/zendframework/zend-stdlib/docs/PULL_REQUEST_TEMPLATE.md b/bundled-libs/zendframework/zend-stdlib/docs/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..f00d90c0 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,25 @@ +Provide a narrative description of what you are trying to accomplish: + +- [ ] Are you fixing a bug? + - [ ] Detail how the bug is invoked currently. + - [ ] Detail the original, incorrect behavior. + - [ ] Detail the new, expected behavior. + - [ ] Base your feature on the `master` branch, and submit against that branch. + - [ ] Add a regression test that demonstrates the bug, and proves the fix. + - [ ] Add a `CHANGELOG.md` entry for the fix. + +- [ ] Are you creating a new feature? + - [ ] Why is the new feature needed? What purpose does it serve? + - [ ] How will users use the new feature? + - [ ] Base your feature on the `develop` branch, and submit against that branch. + - [ ] Add only one feature per pull request; split multiple features over multiple pull requests + - [ ] Add tests for the new feature. + - [ ] Add documentation for the new feature. + - [ ] Add a `CHANGELOG.md` entry for the new feature. + +- [ ] Is this related to quality assurance? + + +- [ ] Is this related to documentation? + + diff --git a/bundled-libs/zendframework/zend-stdlib/docs/SUPPORT.md b/bundled-libs/zendframework/zend-stdlib/docs/SUPPORT.md new file mode 100644 index 00000000..82a7461b --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/SUPPORT.md @@ -0,0 +1,25 @@ +# Getting Support + +Zend Framework offers three support channels: + +- For real-time questions, use our + [Slack](https://zendframework-slack.herokuapp.com) +- For detailed questions (e.g., those requiring examples) use our + [forums](https://discourse.zendframework.com/c/questions/components) +- To report issues, use this repository's + [issue tracker](https://github.com/zendframework/zend-stdlib/issues/new) + +**DO NOT** use the issue tracker to ask questions; use Slack or the forums for +that. Questions posed to the issue tracker will be closed. + +When reporting an issue, please include the following details: + +- A narrative description of what you are trying to accomplish. +- The minimum code necessary to reproduce the issue. +- The expected results of exercising that code. +- The actual results received. + +We may ask for additional details: what version of the library you are using, +and what PHP version was used to reproduce the issue. + +You may also submit a failing test case as a pull request. diff --git a/bundled-libs/zendframework/zend-stdlib/docs/book/console-helper.md b/bundled-libs/zendframework/zend-stdlib/docs/book/console-helper.md new file mode 100644 index 00000000..0a275667 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/book/console-helper.md @@ -0,0 +1,126 @@ +# Console Helper + +Writing one-off scripts or vendor binaries for a package is often problematic: + +- You need to parse arguments manually. +- You need to send output to the console in a meaningful fashion: + - Using `STDOUT` for meaningful, expected output + - Using `STDERR` for error messages + - Ensuring any line breaks are converted to `PHP_EOL` + - Optionally, using console colors to provide context, which means: + - Detecting whether or not the console supports colors in the first place + - Providing appropriate escape sequences to produce color + +`Zend\Stdlib\ConsoleHelper` helps to address the second major bullet point and +all beneath it in a minimal fashion. + +## Usage + +Typical usage is to instantiate a `ConsoleHelper`, and call one of its methods: + +```php +use Zend\Stdlib\ConsoleHelper; + +$helper = new ConsoleHelper(); +$helper->writeLine('This is output'); +``` + +You can optionally pass a PHP stream resource to the constructor, which will be +used to determine whether or not color support is available: + +```php +$helper = new ConsoleHelper($stream); +``` + +By default, it assumes `STDOUT`, and tests against that. + +## Available methods + +`ConsoleHelper` provides the following methods. + +### colorize + +- `colorize(string $string) : string` + +`colorize()` accepts a formatted string, and will then apply ANSI color +sequences to them, if color support is detected. + +The following sequences are currently supported: + +- `...` will apply a green color sequence around the provided text. +- `...` will apply a red color sequence around the provided text. + +You may mix multiple sequences within the same stream. + +### write + +- `write(string $string, bool $colorize = true, resource $stream = STDOUT) : void` + +Emits the provided `$string` to the provided `$stream` (which defaults to +`STDOUT` if not provided). Any EOL sequences are convered to `PHP_EOL`. If +`$colorize` is `true`, the string is first passed to `colorize()` as well. + +### writeline + +- `writeLine(string $string, bool $colorize = true, resource $stream = STDOUT) : void` + +Same as `write()`, except it also appends a `PHP_EOL` sequence to the `$string`. + +### writeErrorMessage + +- `writeErrorMessage(string $message)` + +Wraps `$message` in an `` sequence, and passes it to +`writeLine()`, using `STDERR` as the `$stream`. + +## Example + +Below is an example class that accepts an argument list, and determines how and +what to emit. + +```php +namespace Foo; + +use Zend\Stdlib\ConsoleHelper; + +class HelloWorld +{ + private $helper; + + public function __construct(ConsoleHelper $helper = null) + { + $this->helper = $helper ?: new ConsoleHelper(); + } + + public function __invoke(array $args) + { + if (! count($args)) { + $this->helper->writeErrorMessage('Missing arguments!'); + return; + } + + if (count($args) > 1) { + $this->helper->writeErrorMessage('Too many arguments!'); + return; + } + + $target = array_shift($args); + + $this->helper->writeLine(sprintf( + 'Hello %s', + $target + )); + } +} +``` + +## When to upgrade + +`ConsoleHelper` is deliberately simple, and assumes that your primary need for +console tooling is for output considerations. + +If you need to parse complex argument strings, we recommend using +[zend-console](https://docs.zendframework.com/zend-console/)/[zf-console](https://github.com/zfcampus/zf-console) +or [symfony/console](http://symfony.com/doc/current/components/console.html), +as these packages provide those capabilities, as well as far more colorization +and console feature detection facilities. diff --git a/bundled-libs/zendframework/zend-stdlib/docs/book/index.html b/bundled-libs/zendframework/zend-stdlib/docs/book/index.html new file mode 100644 index 00000000..68027545 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/book/index.html @@ -0,0 +1,10 @@ +
+
+

zend-stdlib

+ +

SPL extensions, array utilities, error handlers, and more.

+ +
$ composer require zendframework/zend-stdlib
+
+
+ diff --git a/bundled-libs/zendframework/zend-stdlib/docs/book/migration.md b/bundled-libs/zendframework/zend-stdlib/docs/book/migration.md new file mode 100644 index 00000000..a0c7ff39 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/book/migration.md @@ -0,0 +1,60 @@ +# Migration Guide + +## From v2 to v3 + +The changes made going from v2 to v3 were: + +- Removal of the Hydrator subcomponent. +- Removal of the `CallbackHandler` class. +- Removal of `Zend\Stdlib\Guard\GuardUtils`. + +### Hydrators + +The biggest single change from version 2 to version 3 is that the hydrator +subcomponent, which was deprecated in v2.7.0, is now removed. This means that if +you were using zend-stdlib principally for the hydrators, you need to convert +your code to use [zend-hydrator](https://github.com/zendframework/zend-hydrator). + +This will also mean a multi-step migration. zend-stdlib v3 pre-dates +zend-hydrator v2.1, which will be the first version that supports zend-stdlib v3 +and zend-servicemanager v3. If you are using Composer, the migration should be +seamless: + +- Remove your zend-stdlib dependency: + + ```bash + $ composer remove zendframework/zend-stdlib + ``` + +- Update to use zend-hydrator: + + ```bash + $ composer require zendframework/zend-hydrator + ``` + +When zend-hydrator updates to newer versions of zend-stdlib and +zend-servicemanager, you will either automatically get those versions, or you +can tell composer to use those specific versions: + +```bash +$ composer require "zendframework/zend-stdlib:^3.0" +``` + +### CallbackHandler + +`Zend\Stdlib\CallbackHandler` primarily existed for legacy purposes; it was +created before the `callable` typehint existed, so that we could typehint PHP +callables. It also provided some minimal features around lazy-loading callables +from instantiable classes, but these features were rarely used, and better +approaches already exist for handling such functinality in zend-servicemanager +and zend-expressive. + +As such, the class was marked deprecated in v2.7.0, and removed for v3.0.0. + +### GuardUtils + +Version 3 removes `Zend\Stdlib\Guard\GuardUtils`. This abstract class existed to +provide the functionality of the various traits also present in that +subcomponent, for consumers on versions of PHP earlier than 5.4. Since the +minimum required version is now PHP 5.5, the class is unnecessary. If you were +using it previously, compose the related traits instead. diff --git a/bundled-libs/zendframework/zend-stdlib/docs/bookdown.json b/bundled-libs/zendframework/zend-stdlib/docs/bookdown.json new file mode 100644 index 00000000..ad93f485 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/docs/bookdown.json @@ -0,0 +1,14 @@ +{ + "title": "Zend\\Stdlib", + "target": "html/", + "content": [ + "book/zend.stdlib.hydrator.md", + "book/zend.stdlib.hydrator.filter.md", + "book/zend.stdlib.hydrator.strategy.md", + "book/zend.stdlib.hydrator.aggregate.md", + "book/zend.stdlib.hydrator.namingstrategy.compositenamingstrategy.md", + "book/zend.stdlib.hydrator.namingstrategy.identitynamingstrategy.md", + "book/zend.stdlib.hydrator.namingstrategy.mapnamingstrategy.md", + "book/zend.stdlib.hydrator.namingstrategy.underscorenamingstrategy.md" + ] +} \ No newline at end of file diff --git a/bundled-libs/zendframework/zend-stdlib/src/AbstractOptions.php b/bundled-libs/zendframework/zend-stdlib/src/AbstractOptions.php new file mode 100644 index 00000000..172f5d36 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/AbstractOptions.php @@ -0,0 +1,178 @@ +setFromArray($options); + } + } + + /** + * Set one or more configuration properties + * + * @param array|Traversable|AbstractOptions $options + * @throws Exception\InvalidArgumentException + * @return AbstractOptions Provides fluent interface + */ + public function setFromArray($options) + { + if ($options instanceof self) { + $options = $options->toArray(); + } + + if (! is_array($options) && ! $options instanceof Traversable) { + throw new Exception\InvalidArgumentException( + sprintf( + 'Parameter provided to %s must be an %s, %s or %s', + __METHOD__, + 'array', + 'Traversable', + 'Zend\Stdlib\AbstractOptions' + ) + ); + } + + foreach ($options as $key => $value) { + $this->__set($key, $value); + } + + return $this; + } + + /** + * Cast to array + * + * @return array + */ + public function toArray() + { + $array = []; + $transform = function ($letters) { + $letter = array_shift($letters); + return '_' . strtolower($letter); + }; + foreach ($this as $key => $value) { + if ($key === '__strictMode__') { + continue; + } + $normalizedKey = preg_replace_callback('/([A-Z])/', $transform, $key); + $array[$normalizedKey] = $value; + } + return $array; + } + + /** + * Set a configuration property + * + * @see ParameterObject::__set() + * @param string $key + * @param mixed $value + * @throws Exception\BadMethodCallException + * @return void + */ + public function __set($key, $value) + { + $setter = 'set' . str_replace('_', '', $key); + + if (is_callable([$this, $setter])) { + $this->{$setter}($value); + + return; + } + + if ($this->__strictMode__) { + throw new Exception\BadMethodCallException(sprintf( + 'The option "%s" does not have a callable "%s" ("%s") setter method which must be defined', + $key, + 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))), + $setter + )); + } + } + + /** + * Get a configuration property + * + * @see ParameterObject::__get() + * @param string $key + * @throws Exception\BadMethodCallException + * @return mixed + */ + public function __get($key) + { + $getter = 'get' . str_replace('_', '', $key); + + if (is_callable([$this, $getter])) { + return $this->{$getter}(); + } + + throw new Exception\BadMethodCallException(sprintf( + 'The option "%s" does not have a callable "%s" getter method which must be defined', + $key, + 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))) + )); + } + + /** + * Test if a configuration property is null + * @see ParameterObject::__isset() + * @param string $key + * @return bool + */ + public function __isset($key) + { + $getter = 'get' . str_replace('_', '', $key); + + return method_exists($this, $getter) && null !== $this->__get($key); + } + + /** + * Set a configuration property to NULL + * + * @see ParameterObject::__unset() + * @param string $key + * @throws Exception\InvalidArgumentException + * @return void + */ + public function __unset($key) + { + try { + $this->__set($key, null); + } catch (Exception\BadMethodCallException $e) { + throw new Exception\InvalidArgumentException( + 'The class property $' . $key . ' cannot be unset as' + . ' NULL is an invalid value for it', + 0, + $e + ); + } + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/ArrayObject.php b/bundled-libs/zendframework/zend-stdlib/src/ArrayObject.php new file mode 100644 index 00000000..8c77c620 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/ArrayObject.php @@ -0,0 +1,434 @@ +setFlags($flags); + $this->storage = $input; + $this->setIteratorClass($iteratorClass); + $this->protectedProperties = array_keys(get_object_vars($this)); + } + + /** + * Returns whether the requested key exists + * + * @param mixed $key + * @return bool + */ + public function __isset($key) + { + if ($this->flag == self::ARRAY_AS_PROPS) { + return $this->offsetExists($key); + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + + return isset($this->$key); + } + + /** + * Sets the value at the specified key to value + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function __set($key, $value) + { + if ($this->flag == self::ARRAY_AS_PROPS) { + return $this->offsetSet($key, $value); + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + $this->$key = $value; + } + + /** + * Unsets the value at the specified key + * + * @param mixed $key + * @return void + */ + public function __unset($key) + { + if ($this->flag == self::ARRAY_AS_PROPS) { + return $this->offsetUnset($key); + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + unset($this->$key); + } + + /** + * Returns the value at the specified key by reference + * + * @param mixed $key + * @return mixed + */ + public function &__get($key) + { + $ret = null; + if ($this->flag == self::ARRAY_AS_PROPS) { + $ret =& $this->offsetGet($key); + + return $ret; + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + + return $this->$key; + } + + /** + * Appends the value + * + * @param mixed $value + * @return void + */ + public function append($value) + { + $this->storage[] = $value; + } + + /** + * Sort the entries by value + * + * @return void + */ + public function asort() + { + asort($this->storage); + } + + /** + * Get the number of public properties in the ArrayObject + * + * @return int + */ + public function count() + { + return count($this->storage); + } + + /** + * Exchange the array for another one. + * + * @param array|ArrayObject $data + * @return array + */ + public function exchangeArray($data) + { + if (! is_array($data) && ! is_object($data)) { + throw new Exception\InvalidArgumentException( + 'Passed variable is not an array or object, using empty array instead' + ); + } + + if (is_object($data) && ($data instanceof self || $data instanceof \ArrayObject)) { + $data = $data->getArrayCopy(); + } + if (! is_array($data)) { + $data = (array) $data; + } + + $storage = $this->storage; + + $this->storage = $data; + + return $storage; + } + + /** + * Creates a copy of the ArrayObject. + * + * @return array + */ + public function getArrayCopy() + { + return $this->storage; + } + + /** + * Gets the behavior flags. + * + * @return int + */ + public function getFlags() + { + return $this->flag; + } + + /** + * Create a new iterator from an ArrayObject instance + * + * @return \Iterator + */ + public function getIterator() + { + $class = $this->iteratorClass; + + return new $class($this->storage); + } + + /** + * Gets the iterator classname for the ArrayObject. + * + * @return string + */ + public function getIteratorClass() + { + return $this->iteratorClass; + } + + /** + * Sort the entries by key + * + * @return void + */ + public function ksort() + { + ksort($this->storage); + } + + /** + * Sort an array using a case insensitive "natural order" algorithm + * + * @return void + */ + public function natcasesort() + { + natcasesort($this->storage); + } + + /** + * Sort entries using a "natural order" algorithm + * + * @return void + */ + public function natsort() + { + natsort($this->storage); + } + + /** + * Returns whether the requested key exists + * + * @param mixed $key + * @return bool + */ + public function offsetExists($key) + { + return isset($this->storage[$key]); + } + + /** + * Returns the value at the specified key + * + * @param mixed $key + * @return mixed + */ + public function &offsetGet($key) + { + $ret = null; + if (! $this->offsetExists($key)) { + return $ret; + } + $ret =& $this->storage[$key]; + + return $ret; + } + + /** + * Sets the value at the specified key to value + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function offsetSet($key, $value) + { + $this->storage[$key] = $value; + } + + /** + * Unsets the value at the specified key + * + * @param mixed $key + * @return void + */ + public function offsetUnset($key) + { + if ($this->offsetExists($key)) { + unset($this->storage[$key]); + } + } + + /** + * Serialize an ArrayObject + * + * @return string + */ + public function serialize() + { + return serialize(get_object_vars($this)); + } + + /** + * Sets the behavior flags + * + * @param int $flags + * @return void + */ + public function setFlags($flags) + { + $this->flag = $flags; + } + + /** + * Sets the iterator classname for the ArrayObject + * + * @param string $class + * @return void + */ + public function setIteratorClass($class) + { + if (class_exists($class)) { + $this->iteratorClass = $class; + + return ; + } + + if (strpos($class, '\\') === 0) { + $class = '\\' . $class; + if (class_exists($class)) { + $this->iteratorClass = $class; + + return ; + } + } + + throw new Exception\InvalidArgumentException('The iterator class does not exist'); + } + + /** + * Sort the entries with a user-defined comparison function and maintain key association + * + * @param callable $function + * @return void + */ + public function uasort($function) + { + if (is_callable($function)) { + uasort($this->storage, $function); + } + } + + /** + * Sort the entries by keys using a user-defined comparison function + * + * @param callable $function + * @return void + */ + public function uksort($function) + { + if (is_callable($function)) { + uksort($this->storage, $function); + } + } + + /** + * Unserialize an ArrayObject + * + * @param string $data + * @return void + */ + public function unserialize($data) + { + $ar = unserialize($data); + $this->protectedProperties = array_keys(get_object_vars($this)); + + $this->setFlags($ar['flag']); + $this->exchangeArray($ar['storage']); + $this->setIteratorClass($ar['iteratorClass']); + + foreach ($ar as $k => $v) { + switch ($k) { + case 'flag': + $this->setFlags($v); + break; + case 'storage': + $this->exchangeArray($v); + break; + case 'iteratorClass': + $this->setIteratorClass($v); + break; + case 'protectedProperties': + break; + default: + $this->__set($k, $v); + } + } + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/ArraySerializableInterface.php b/bundled-libs/zendframework/zend-stdlib/src/ArraySerializableInterface.php new file mode 100644 index 00000000..dcf84719 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/ArraySerializableInterface.php @@ -0,0 +1,28 @@ +getArrayCopy(); + return new ArrayIterator(array_reverse($array)); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils.php b/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils.php new file mode 100644 index 00000000..4edcacf1 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils.php @@ -0,0 +1,314 @@ + 0; + } + + /** + * Test whether an array contains one or more integer keys + * + * @param mixed $value + * @param bool $allowEmpty Should an empty array() return true + * @return bool + */ + public static function hasIntegerKeys($value, $allowEmpty = false) + { + if (! is_array($value)) { + return false; + } + + if (! $value) { + return $allowEmpty; + } + + return count(array_filter(array_keys($value), 'is_int')) > 0; + } + + /** + * Test whether an array contains one or more numeric keys. + * + * A numeric key can be one of the following: + * - an integer 1, + * - a string with a number '20' + * - a string with negative number: '-1000' + * - a float: 2.2120, -78.150999 + * - a string with float: '4000.99999', '-10.10' + * + * @param mixed $value + * @param bool $allowEmpty Should an empty array() return true + * @return bool + */ + public static function hasNumericKeys($value, $allowEmpty = false) + { + if (! is_array($value)) { + return false; + } + + if (! $value) { + return $allowEmpty; + } + + return count(array_filter(array_keys($value), 'is_numeric')) > 0; + } + + /** + * Test whether an array is a list + * + * A list is a collection of values assigned to continuous integer keys + * starting at 0 and ending at count() - 1. + * + * For example: + * + * $list = array('a', 'b', 'c', 'd'); + * $list = array( + * 0 => 'foo', + * 1 => 'bar', + * 2 => array('foo' => 'baz'), + * ); + * + * + * @param mixed $value + * @param bool $allowEmpty Is an empty list a valid list? + * @return bool + */ + public static function isList($value, $allowEmpty = false) + { + if (! is_array($value)) { + return false; + } + + if (! $value) { + return $allowEmpty; + } + + return (array_values($value) === $value); + } + + /** + * Test whether an array is a hash table. + * + * An array is a hash table if: + * + * 1. Contains one or more non-integer keys, or + * 2. Integer keys are non-continuous or misaligned (not starting with 0) + * + * For example: + * + * $hash = array( + * 'foo' => 15, + * 'bar' => false, + * ); + * $hash = array( + * 1995 => 'Birth of PHP', + * 2009 => 'PHP 5.3.0', + * 2012 => 'PHP 5.4.0', + * ); + * $hash = array( + * 'formElement, + * 'options' => array( 'debug' => true ), + * ); + * + * + * @param mixed $value + * @param bool $allowEmpty Is an empty array() a valid hash table? + * @return bool + */ + public static function isHashTable($value, $allowEmpty = false) + { + if (! is_array($value)) { + return false; + } + + if (! $value) { + return $allowEmpty; + } + + return (array_values($value) !== $value); + } + + /** + * Checks if a value exists in an array. + * + * Due to "foo" == 0 === TRUE with in_array when strict = false, an option + * has been added to prevent this. When $strict = 0/false, the most secure + * non-strict check is implemented. if $strict = -1, the default in_array + * non-strict behaviour is used. + * + * @param mixed $needle + * @param array $haystack + * @param int|bool $strict + * @return bool + */ + public static function inArray($needle, array $haystack, $strict = false) + { + if (! $strict) { + if (is_int($needle) || is_float($needle)) { + $needle = (string) $needle; + } + if (is_string($needle)) { + foreach ($haystack as &$h) { + if (is_int($h) || is_float($h)) { + $h = (string) $h; + } + } + } + } + return in_array($needle, $haystack, $strict); + } + + /** + * Convert an iterator to an array. + * + * Converts an iterator to an array. The $recursive flag, on by default, + * hints whether or not you want to do so recursively. + * + * @param array|Traversable $iterator The array or Traversable object to convert + * @param bool $recursive Recursively check all nested structures + * @throws Exception\InvalidArgumentException if $iterator is not an array or a Traversable object + * @return array + */ + public static function iteratorToArray($iterator, $recursive = true) + { + if (! is_array($iterator) && ! $iterator instanceof Traversable) { + throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object'); + } + + if (! $recursive) { + if (is_array($iterator)) { + return $iterator; + } + + return iterator_to_array($iterator); + } + + if (method_exists($iterator, 'toArray')) { + return $iterator->toArray(); + } + + $array = []; + foreach ($iterator as $key => $value) { + if (is_scalar($value)) { + $array[$key] = $value; + continue; + } + + if ($value instanceof Traversable) { + $array[$key] = static::iteratorToArray($value, $recursive); + continue; + } + + if (is_array($value)) { + $array[$key] = static::iteratorToArray($value, $recursive); + continue; + } + + $array[$key] = $value; + } + + return $array; + } + + /** + * Merge two arrays together. + * + * If an integer key exists in both arrays and preserveNumericKeys is false, the value + * from the second array will be appended to the first array. If both values are arrays, they + * are merged together, else the value of the second array overwrites the one of the first array. + * + * @param array $a + * @param array $b + * @param bool $preserveNumericKeys + * @return array + */ + public static function merge(array $a, array $b, $preserveNumericKeys = false) + { + foreach ($b as $key => $value) { + if ($value instanceof MergeReplaceKeyInterface) { + $a[$key] = $value->getData(); + } elseif (isset($a[$key]) || array_key_exists($key, $a)) { + if ($value instanceof MergeRemoveKey) { + unset($a[$key]); + } elseif (! $preserveNumericKeys && is_int($key)) { + $a[] = $value; + } elseif (is_array($value) && is_array($a[$key])) { + $a[$key] = static::merge($a[$key], $value, $preserveNumericKeys); + } else { + $a[$key] = $value; + } + } else { + if (! $value instanceof MergeRemoveKey) { + $a[$key] = $value; + } + } + } + + return $a; + } + + /** + * @deprecated Since 3.2.0; use the native array_filter methods + * + * @param array $data + * @param callable $callback + * @param null|int $flag + * @return array + * @throws Exception\InvalidArgumentException + */ + public static function filter(array $data, $callback, $flag = null) + { + if (! is_callable($callback)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Second parameter of %s must be callable', + __METHOD__ + )); + } + + return array_filter($data, $callback, $flag); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeRemoveKey.php b/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeRemoveKey.php new file mode 100644 index 00000000..7c4d097d --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeRemoveKey.php @@ -0,0 +1,14 @@ +data = $data; + } + + /** + * {@inheritDoc} + */ + public function getData() + { + return $this->data; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKeyInterface.php b/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKeyInterface.php new file mode 100644 index 00000000..725cf11b --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/ArrayUtils/MergeReplaceKeyInterface.php @@ -0,0 +1,21 @@ +message`, + * `message`) + * - Write output to a specified stream, optionally with colorization. + * - Write a line of output to a specified stream, optionally with + * colorization, using the system EOL sequence.. + * - Write an error message to STDERR. + * + * Colorization will only occur when expected sequences are discovered, and + * then, only if the console terminal allows it. + * + * Essentially, provides the bare minimum to allow you to provide messages to + * the current console. + */ +class ConsoleHelper +{ + const COLOR_GREEN = "\033[32m"; + const COLOR_RED = "\033[31m"; + const COLOR_RESET = "\033[0m"; + + const HIGHLIGHT_INFO = 'info'; + const HIGHLIGHT_ERROR = 'error'; + + private $highlightMap = [ + self::HIGHLIGHT_INFO => self::COLOR_GREEN, + self::HIGHLIGHT_ERROR => self::COLOR_RED, + ]; + + /** + * @var string Exists only for testing. + */ + private $eol = PHP_EOL; + + /** + * @var resource Exists only for testing. + */ + private $stderr = STDERR; + + /** + * @var bool + */ + private $supportsColor; + + /** + * @param resource $resource + */ + public function __construct($resource = STDOUT) + { + $this->supportsColor = $this->detectColorCapabilities($resource); + } + + /** + * Colorize a string for use with the terminal. + * + * Takes strings formatted as `string` and formats them per the + * $highlightMap; if color support is disabled, simply removes the formatting + * tags. + * + * @param string $string + * @return string + */ + public function colorize($string) + { + $reset = $this->supportsColor ? self::COLOR_RESET : ''; + foreach ($this->highlightMap as $key => $color) { + $pattern = sprintf('#<%s>(.*?)#s', $key, $key); + $color = $this->supportsColor ? $color : ''; + $string = preg_replace($pattern, $color . '$1' . $reset, $string); + } + return $string; + } + + /** + * @param string $string + * @param bool $colorize Whether or not to colorize the string + * @param resource $resource Defaults to STDOUT + * @return void + */ + public function write($string, $colorize = true, $resource = STDOUT) + { + if ($colorize) { + $string = $this->colorize($string); + } + + $string = $this->formatNewlines($string); + + fwrite($resource, $string); + } + + /** + * @param string $string + * @param bool $colorize Whether or not to colorize the line + * @param resource $resource Defaults to STDOUT + * @return void + */ + public function writeLine($string, $colorize = true, $resource = STDOUT) + { + $this->write($string . $this->eol, $colorize, $resource); + } + + /** + * Emit an error message. + * + * Wraps the message in ``, and passes it to `writeLine()`, + * using STDERR as the resource; emits an additional empty line when done, + * also to STDERR. + * + * @param string $message + * @return void + */ + public function writeErrorMessage($message) + { + $this->writeLine(sprintf('%s', $message), true, $this->stderr); + $this->writeLine('', false, $this->stderr); + } + + /** + * @param resource $resource + * @return bool + */ + private function detectColorCapabilities($resource = STDOUT) + { + if ('\\' === DIRECTORY_SEPARATOR) { + // Windows + return false !== getenv('ANSICON') + || 'ON' === getenv('ConEmuANSI') + || 'xterm' === getenv('TERM'); + } + + return function_exists('posix_isatty') && posix_isatty($resource); + } + + /** + * Ensure newlines are appropriate for the current terminal. + * + * @param string + * @return string + */ + private function formatNewlines($string) + { + $string = str_replace($this->eol, "\0PHP_EOL\0", $string); + $string = preg_replace("/(\r\n|\n|\r)/", $this->eol, $string); + return str_replace("\0PHP_EOL\0", $this->eol, $string); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/DispatchableInterface.php b/bundled-libs/zendframework/zend-stdlib/src/DispatchableInterface.php new file mode 100644 index 00000000..4f74d1e8 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/DispatchableInterface.php @@ -0,0 +1,22 @@ +values[$priority][] = $value; + if (! isset($this->priorities[$priority])) { + $this->priorities[$priority] = $priority; + $this->maxPriority = $this->maxPriority === null ? $priority : max($priority, $this->maxPriority); + } + ++$this->count; + } + + /** + * Extract an element in the queue according to the priority and the + * order of insertion + * + * @return mixed + */ + public function extract() + { + if (! $this->valid()) { + return false; + } + $value = $this->current(); + $this->nextAndRemove(); + return $value; + } + + /** + * Remove an item from the queue + * + * This is different than {@link extract()}; its purpose is to dequeue an + * item. + * + * Note: this removes the first item matching the provided item found. If + * the same item has been added multiple times, it will not remove other + * instances. + * + * @param mixed $datum + * @return bool False if the item was not found, true otherwise. + */ + public function remove($datum) + { + $currentIndex = $this->index; + $currentSubIndex = $this->subIndex; + $currentPriority = $this->maxPriority; + + $this->rewind(); + while ($this->valid()) { + if (current($this->values[$this->maxPriority]) === $datum) { + $index = key($this->values[$this->maxPriority]); + unset($this->values[$this->maxPriority][$index]); + + // The `next()` method advances the internal array pointer, so we need to use the `reset()` function, + // otherwise we would lose all elements before the place the pointer points. + reset($this->values[$this->maxPriority]); + + $this->index = $currentIndex; + $this->subIndex = $currentSubIndex; + + // If the array is empty we need to destroy the unnecessary priority, + // otherwise we would end up with an incorrect value of `$this->count` + // {@see \Zend\Stdlib\FastPriorityQueue::nextAndRemove()}. + if (empty($this->values[$this->maxPriority])) { + unset($this->values[$this->maxPriority]); + unset($this->priorities[$this->maxPriority]); + if ($this->maxPriority === $currentPriority) { + $this->subIndex = 0; + } + } + + $this->maxPriority = empty($this->priorities) ? null : max($this->priorities); + --$this->count; + return true; + } + $this->next(); + } + return false; + } + + /** + * Get the total number of elements in the queue + * + * @return integer + */ + public function count() + { + return $this->count; + } + + /** + * Get the current element in the queue + * + * @return mixed + */ + public function current() + { + switch ($this->extractFlag) { + case self::EXTR_DATA: + return current($this->values[$this->maxPriority]); + case self::EXTR_PRIORITY: + return $this->maxPriority; + case self::EXTR_BOTH: + return [ + 'data' => current($this->values[$this->maxPriority]), + 'priority' => $this->maxPriority + ]; + } + } + + /** + * Get the index of the current element in the queue + * + * @return integer + */ + public function key() + { + return $this->index; + } + + /** + * Set the iterator pointer to the next element in the queue + * removing the previous element + */ + protected function nextAndRemove() + { + $key = key($this->values[$this->maxPriority]); + + if (false === next($this->values[$this->maxPriority])) { + unset($this->priorities[$this->maxPriority]); + unset($this->values[$this->maxPriority]); + $this->maxPriority = empty($this->priorities) ? null : max($this->priorities); + $this->subIndex = -1; + } else { + unset($this->values[$this->maxPriority][$key]); + } + ++$this->index; + ++$this->subIndex; + --$this->count; + } + + /** + * Set the iterator pointer to the next element in the queue + * without removing the previous element + */ + public function next() + { + if (false === next($this->values[$this->maxPriority])) { + unset($this->subPriorities[$this->maxPriority]); + reset($this->values[$this->maxPriority]); + $this->maxPriority = empty($this->subPriorities) ? null : max($this->subPriorities); + $this->subIndex = -1; + } + ++$this->index; + ++$this->subIndex; + } + + /** + * Check if the current iterator is valid + * + * @return boolean + */ + public function valid() + { + return isset($this->values[$this->maxPriority]); + } + + /** + * Rewind the current iterator + */ + public function rewind() + { + $this->subPriorities = $this->priorities; + $this->maxPriority = empty($this->priorities) ? 0 : max($this->priorities); + $this->index = 0; + $this->subIndex = 0; + } + + /** + * Serialize to an array + * + * Array will be priority => data pairs + * + * @return array + */ + public function toArray() + { + $array = []; + foreach (clone $this as $item) { + $array[] = $item; + } + return $array; + } + + /** + * Serialize + * + * @return string + */ + public function serialize() + { + $clone = clone $this; + $clone->setExtractFlags(self::EXTR_BOTH); + + $data = []; + foreach ($clone as $item) { + $data[] = $item; + } + + return serialize($data); + } + + /** + * Deserialize + * + * @param string $data + * @return void + */ + public function unserialize($data) + { + foreach (unserialize($data) as $item) { + $this->insert($item['data'], $item['priority']); + } + } + + /** + * Set the extract flag + * + * @param integer $flag + */ + public function setExtractFlags($flag) + { + switch ($flag) { + case self::EXTR_DATA: + case self::EXTR_PRIORITY: + case self::EXTR_BOTH: + $this->extractFlag = $flag; + break; + default: + throw new Exception\InvalidArgumentException("The extract flag specified is not valid"); + } + } + + /** + * Check if the queue is empty + * + * @return boolean + */ + public function isEmpty() + { + return empty($this->values); + } + + /** + * Does the queue contain the given datum? + * + * @param mixed $datum + * @return bool + */ + public function contains($datum) + { + foreach ($this->values as $values) { + if (in_array($datum, $values)) { + return true; + } + } + return false; + } + + /** + * Does the queue have an item with the given priority? + * + * @param int $priority + * @return bool + */ + public function hasPriority($priority) + { + return isset($this->values[$priority]); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/Glob.php b/bundled-libs/zendframework/zend-stdlib/src/Glob.php new file mode 100644 index 00000000..ded3fc53 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/Glob.php @@ -0,0 +1,202 @@ + GLOB_MARK, + self::GLOB_NOSORT => GLOB_NOSORT, + self::GLOB_NOCHECK => GLOB_NOCHECK, + self::GLOB_NOESCAPE => GLOB_NOESCAPE, + self::GLOB_BRACE => defined('GLOB_BRACE') ? GLOB_BRACE : 0, + self::GLOB_ONLYDIR => GLOB_ONLYDIR, + self::GLOB_ERR => GLOB_ERR, + ]; + + $globFlags = 0; + + foreach ($flagMap as $internalFlag => $globFlag) { + if ($flags & $internalFlag) { + $globFlags |= $globFlag; + } + } + } else { + $globFlags = 0; + } + + ErrorHandler::start(); + $res = glob($pattern, $globFlags); + $err = ErrorHandler::stop(); + if ($res === false) { + throw new Exception\RuntimeException("glob('{$pattern}', {$globFlags}) failed", 0, $err); + } + return $res; + } + + /** + * Expand braces manually, then use the system glob. + * + * @param string $pattern + * @param int $flags + * @return array + * @throws Exception\RuntimeException + */ + protected static function fallbackGlob($pattern, $flags) + { + if (! $flags & self::GLOB_BRACE) { + return static::systemGlob($pattern, $flags); + } + + $flags &= ~self::GLOB_BRACE; + $length = strlen($pattern); + $paths = []; + + if ($flags & self::GLOB_NOESCAPE) { + $begin = strpos($pattern, '{'); + } else { + $begin = 0; + + while (true) { + if ($begin === $length) { + $begin = false; + break; + } elseif ($pattern[$begin] === '\\' && ($begin + 1) < $length) { + $begin++; + } elseif ($pattern[$begin] === '{') { + break; + } + + $begin++; + } + } + + if ($begin === false) { + return static::systemGlob($pattern, $flags); + } + + $next = static::nextBraceSub($pattern, $begin + 1, $flags); + + if ($next === null) { + return static::systemGlob($pattern, $flags); + } + + $rest = $next; + + while ($pattern[$rest] !== '}') { + $rest = static::nextBraceSub($pattern, $rest + 1, $flags); + + if ($rest === null) { + return static::systemGlob($pattern, $flags); + } + } + + $p = $begin + 1; + + while (true) { + $subPattern = substr($pattern, 0, $begin) + . substr($pattern, $p, $next - $p) + . substr($pattern, $rest + 1); + + $result = static::fallbackGlob($subPattern, $flags | self::GLOB_BRACE); + + if ($result) { + $paths = array_merge($paths, $result); + } + + if ($pattern[$next] === '}') { + break; + } + + $p = $next + 1; + $next = static::nextBraceSub($pattern, $p, $flags); + } + + return array_unique($paths); + } + + /** + * Find the end of the sub-pattern in a brace expression. + * + * @param string $pattern + * @param int $begin + * @param int $flags + * @return int|null + */ + protected static function nextBraceSub($pattern, $begin, $flags) + { + $length = strlen($pattern); + $depth = 0; + $current = $begin; + + while ($current < $length) { + if (! $flags & self::GLOB_NOESCAPE && $pattern[$current] === '\\') { + if (++$current === $length) { + break; + } + + $current++; + } else { + if (($pattern[$current] === '}' && $depth-- === 0) || ($pattern[$current] === ',' && $depth === 0)) { + break; + } elseif ($pattern[$current++] === '{') { + $depth++; + } + } + } + + return ($current < $length ? $current : null); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/Guard/AllGuardsTrait.php b/bundled-libs/zendframework/zend-stdlib/src/Guard/AllGuardsTrait.php new file mode 100644 index 00000000..95bc5162 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/Guard/AllGuardsTrait.php @@ -0,0 +1,20 @@ +metadata[$spec] = $value; + return $this; + } + if (! is_array($spec) && ! $spec instanceof Traversable) { + throw new Exception\InvalidArgumentException(sprintf( + 'Expected a string, array, or Traversable argument in first position; received "%s"', + (is_object($spec) ? get_class($spec) : gettype($spec)) + )); + } + foreach ($spec as $key => $value) { + $this->metadata[$key] = $value; + } + return $this; + } + + /** + * Retrieve all metadata or a single metadatum as specified by key + * + * @param null|string|int $key + * @param null|mixed $default + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function getMetadata($key = null, $default = null) + { + if (null === $key) { + return $this->metadata; + } + + if (! is_scalar($key)) { + throw new Exception\InvalidArgumentException('Non-scalar argument provided for key'); + } + + if (array_key_exists($key, $this->metadata)) { + return $this->metadata[$key]; + } + + return $default; + } + + /** + * Set message content + * + * @param mixed $value + * @return Message + */ + public function setContent($value) + { + $this->content = $value; + return $this; + } + + /** + * Get message content + * + * @return mixed + */ + public function getContent() + { + return $this->content; + } + + /** + * @return string + */ + public function toString() + { + $request = ''; + foreach ($this->getMetadata() as $key => $value) { + $request .= sprintf( + "%s: %s\r\n", + (string) $key, + (string) $value + ); + } + $request .= "\r\n" . $this->getContent(); + return $request; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/MessageInterface.php b/bundled-libs/zendframework/zend-stdlib/src/MessageInterface.php new file mode 100644 index 00000000..28d8857f --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/MessageInterface.php @@ -0,0 +1,44 @@ +exchangeArray($values); + } + + /** + * Populate from query string + * + * @param string $string + * @return void + */ + public function fromString($string) + { + $array = []; + parse_str($string, $array); + $this->fromArray($array); + } + + /** + * Serialize to native PHP array + * + * @return array + */ + public function toArray() + { + return $this->getArrayCopy(); + } + + /** + * Serialize to query string + * + * @return string + */ + public function toString() + { + return http_build_query($this->toArray()); + } + + /** + * Retrieve by key + * + * Returns null if the key does not exist. + * + * @param string $name + * @return mixed + */ + public function offsetGet($name) + { + if ($this->offsetExists($name)) { + return parent::offsetGet($name); + } + return; + } + + /** + * @param string $name + * @param mixed $default optional default value + * @return mixed + */ + public function get($name, $default = null) + { + if ($this->offsetExists($name)) { + return parent::offsetGet($name); + } + return $default; + } + + /** + * @param string $name + * @param mixed $value + * @return Parameters + */ + public function set($name, $value) + { + $this[$name] = $value; + return $this; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/ParametersInterface.php b/bundled-libs/zendframework/zend-stdlib/src/ParametersInterface.php new file mode 100644 index 00000000..feeda580 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/ParametersInterface.php @@ -0,0 +1,86 @@ +items[$name])) { + $this->count++; + } + + $this->sorted = false; + + $this->items[$name] = [ + 'data' => $value, + 'priority' => (int) $priority, + 'serial' => $this->serial++, + ]; + } + + /** + * @param string $name + * @param int $priority + * + * @return $this + * + * @throws \Exception + */ + public function setPriority($name, $priority) + { + if (! isset($this->items[$name])) { + throw new \Exception("item $name not found"); + } + + $this->items[$name]['priority'] = (int) $priority; + $this->sorted = false; + + return $this; + } + + /** + * Remove a item. + * + * @param string $name + * @return void + */ + public function remove($name) + { + if (isset($this->items[$name])) { + $this->count--; + } + + unset($this->items[$name]); + } + + /** + * Remove all items. + * + * @return void + */ + public function clear() + { + $this->items = []; + $this->serial = 0; + $this->count = 0; + $this->sorted = false; + } + + /** + * Get a item. + * + * @param string $name + * @return mixed + */ + public function get($name) + { + if (! isset($this->items[$name])) { + return; + } + + return $this->items[$name]['data']; + } + + /** + * Sort all items. + * + * @return void + */ + protected function sort() + { + if (! $this->sorted) { + uasort($this->items, [$this, 'compare']); + $this->sorted = true; + } + } + + /** + * Compare the priority of two items. + * + * @param array $item1, + * @param array $item2 + * @return int + */ + protected function compare(array $item1, array $item2) + { + return ($item1['priority'] === $item2['priority']) + ? ($item1['serial'] > $item2['serial'] ? -1 : 1) * $this->isLIFO + : ($item1['priority'] > $item2['priority'] ? -1 : 1); + } + + /** + * Get/Set serial order mode + * + * @param bool|null $flag + * + * @return bool + */ + public function isLIFO($flag = null) + { + if ($flag !== null) { + $isLifo = $flag === true ? 1 : -1; + + if ($isLifo !== $this->isLIFO) { + $this->isLIFO = $isLifo; + $this->sorted = false; + } + } + + return 1 === $this->isLIFO; + } + + /** + * {@inheritDoc} + */ + public function rewind() + { + $this->sort(); + reset($this->items); + } + + /** + * {@inheritDoc} + */ + public function current() + { + $this->sorted || $this->sort(); + $node = current($this->items); + + return $node ? $node['data'] : false; + } + + /** + * {@inheritDoc} + */ + public function key() + { + $this->sorted || $this->sort(); + return key($this->items); + } + + /** + * {@inheritDoc} + */ + public function next() + { + $node = next($this->items); + + return $node ? $node['data'] : false; + } + + /** + * {@inheritDoc} + */ + public function valid() + { + return current($this->items) !== false; + } + + /** + * @return self + */ + public function getIterator() + { + return clone $this; + } + + /** + * {@inheritDoc} + */ + public function count() + { + return $this->count; + } + + /** + * Return list as array + * + * @param int $flag + * + * @return array + */ + public function toArray($flag = self::EXTR_DATA) + { + $this->sort(); + + if ($flag == self::EXTR_BOTH) { + return $this->items; + } + + return array_map( + function ($item) use ($flag) { + return ($flag == PriorityList::EXTR_PRIORITY) ? $item['priority'] : $item['data']; + }, + $this->items + ); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/PriorityQueue.php b/bundled-libs/zendframework/zend-stdlib/src/PriorityQueue.php new file mode 100644 index 00000000..2a162873 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/PriorityQueue.php @@ -0,0 +1,301 @@ +items[] = [ + 'data' => $data, + 'priority' => $priority, + ]; + $this->getQueue()->insert($data, $priority); + return $this; + } + + /** + * Remove an item from the queue + * + * This is different than {@link extract()}; its purpose is to dequeue an + * item. + * + * This operation is potentially expensive, as it requires + * re-initialization and re-population of the inner queue. + * + * Note: this removes the first item matching the provided item found. If + * the same item has been added multiple times, it will not remove other + * instances. + * + * @param mixed $datum + * @return bool False if the item was not found, true otherwise. + */ + public function remove($datum) + { + $found = false; + foreach ($this->items as $key => $item) { + if ($item['data'] === $datum) { + $found = true; + break; + } + } + if ($found) { + unset($this->items[$key]); + $this->queue = null; + + if (! $this->isEmpty()) { + $queue = $this->getQueue(); + foreach ($this->items as $item) { + $queue->insert($item['data'], $item['priority']); + } + } + return true; + } + return false; + } + + /** + * Is the queue empty? + * + * @return bool + */ + public function isEmpty() + { + return (0 === $this->count()); + } + + /** + * How many items are in the queue? + * + * @return int + */ + public function count() + { + return count($this->items); + } + + /** + * Peek at the top node in the queue, based on priority. + * + * @return mixed + */ + public function top() + { + return $this->getIterator()->top(); + } + + /** + * Extract a node from the inner queue and sift up + * + * @return mixed + */ + public function extract() + { + return $this->getQueue()->extract(); + } + + /** + * Retrieve the inner iterator + * + * SplPriorityQueue acts as a heap, which typically implies that as items + * are iterated, they are also removed. This does not work for situations + * where the queue may be iterated multiple times. As such, this class + * aggregates the values, and also injects an SplPriorityQueue. This method + * retrieves the inner queue object, and clones it for purposes of + * iteration. + * + * @return SplPriorityQueue + */ + public function getIterator() + { + $queue = $this->getQueue(); + return clone $queue; + } + + /** + * Serialize the data structure + * + * @return string + */ + public function serialize() + { + return serialize($this->items); + } + + /** + * Unserialize a string into a PriorityQueue object + * + * Serialization format is compatible with {@link Zend\Stdlib\SplPriorityQueue} + * + * @param string $data + * @return void + */ + public function unserialize($data) + { + foreach (unserialize($data) as $item) { + $this->insert($item['data'], $item['priority']); + } + } + + /** + * Serialize to an array + * + * By default, returns only the item data, and in the order registered (not + * sorted). You may provide one of the EXTR_* flags as an argument, allowing + * the ability to return priorities or both data and priority. + * + * @param int $flag + * @return array + */ + public function toArray($flag = self::EXTR_DATA) + { + switch ($flag) { + case self::EXTR_BOTH: + return $this->items; + case self::EXTR_PRIORITY: + return array_map(function ($item) { + return $item['priority']; + }, $this->items); + case self::EXTR_DATA: + default: + return array_map(function ($item) { + return $item['data']; + }, $this->items); + } + } + + /** + * Specify the internal queue class + * + * Please see {@link getIterator()} for details on the necessity of an + * internal queue class. The class provided should extend SplPriorityQueue. + * + * @param string $class + * @return PriorityQueue + */ + public function setInternalQueueClass($class) + { + $this->queueClass = (string) $class; + return $this; + } + + /** + * Does the queue contain the given datum? + * + * @param mixed $datum + * @return bool + */ + public function contains($datum) + { + foreach ($this->items as $item) { + if ($item['data'] === $datum) { + return true; + } + } + return false; + } + + /** + * Does the queue have an item with the given priority? + * + * @param int $priority + * @return bool + */ + public function hasPriority($priority) + { + foreach ($this->items as $item) { + if ($item['priority'] === $priority) { + return true; + } + } + return false; + } + + /** + * Get the inner priority queue instance + * + * @throws Exception\DomainException + * @return SplPriorityQueue + */ + protected function getQueue() + { + if (null === $this->queue) { + $this->queue = new $this->queueClass(); + if (! $this->queue instanceof \SplPriorityQueue) { + throw new Exception\DomainException(sprintf( + 'PriorityQueue expects an internal queue of type SplPriorityQueue; received "%s"', + get_class($this->queue) + )); + } + } + return $this->queue; + } + + /** + * Add support for deep cloning + * + * @return void + */ + public function __clone() + { + if (null !== $this->queue) { + $this->queue = clone $this->queue; + } + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/Request.php b/bundled-libs/zendframework/zend-stdlib/src/Request.php new file mode 100644 index 00000000..7c084039 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/Request.php @@ -0,0 +1,15 @@ +serial--]; + } + parent::insert($datum, $priority); + } + + /** + * Serialize to an array + * + * Array will be priority => data pairs + * + * @return array + */ + public function toArray() + { + $array = []; + foreach (clone $this as $item) { + $array[] = $item; + } + return $array; + } + + /** + * Serialize + * + * @return string + */ + public function serialize() + { + $clone = clone $this; + $clone->setExtractFlags(self::EXTR_BOTH); + + $data = []; + foreach ($clone as $item) { + $data[] = $item; + } + + return serialize($data); + } + + /** + * Deserialize + * + * @param string $data + * @return void + */ + public function unserialize($data) + { + $this->serial = PHP_INT_MAX; + foreach (unserialize($data) as $item) { + $this->serial--; + $this->insert($item['data'], $item['priority']); + } + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/SplQueue.php b/bundled-libs/zendframework/zend-stdlib/src/SplQueue.php new file mode 100644 index 00000000..51d8daf7 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/SplQueue.php @@ -0,0 +1,55 @@ +toArray()); + } + + /** + * Unserialize + * + * @param string $data + * @return void + */ + public function unserialize($data) + { + foreach (unserialize($data) as $item) { + $this->push($item); + } + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/SplStack.php b/bundled-libs/zendframework/zend-stdlib/src/SplStack.php new file mode 100644 index 00000000..6ba27398 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/SplStack.php @@ -0,0 +1,55 @@ +toArray()); + } + + /** + * Unserialize + * + * @param string $data + * @return void + */ + public function unserialize($data) + { + foreach (unserialize($data) as $item) { + $this->unshift($item); + } + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/StringUtils.php b/bundled-libs/zendframework/zend-stdlib/src/StringUtils.php new file mode 100644 index 00000000..79a22a4c --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/StringUtils.php @@ -0,0 +1,187 @@ +setEncoding($encoding, $convertEncoding); + return $wrapper; + } + } + + throw new Exception\RuntimeException( + 'No wrapper found supporting "' . $encoding . '"' + . (($convertEncoding !== null) ? ' and "' . $convertEncoding . '"' : '') + ); + } + + /** + * Get a list of all known single-byte character encodings + * + * @return string[] + */ + public static function getSingleByteEncodings() + { + return static::$singleByteEncodings; + } + + /** + * Check if a given encoding is a known single-byte character encoding + * + * @param string $encoding + * @return bool + */ + public static function isSingleByteEncoding($encoding) + { + return in_array(strtoupper($encoding), static::$singleByteEncodings); + } + + /** + * Check if a given string is valid UTF-8 encoded + * + * @param string $str + * @return bool + */ + public static function isValidUtf8($str) + { + return is_string($str) && ($str === '' || preg_match('/^./su', $str) == 1); + } + + /** + * Is PCRE compiled with Unicode support? + * + * @return bool + */ + public static function hasPcreUnicodeSupport() + { + if (static::$hasPcreUnicodeSupport === null) { + ErrorHandler::start(); + static::$hasPcreUnicodeSupport = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1; + ErrorHandler::stop(); + } + return static::$hasPcreUnicodeSupport; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php new file mode 100644 index 00000000..cf262507 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php @@ -0,0 +1,269 @@ +convertEncoding = $convertEncodingUpper; + } else { + $this->convertEncoding = null; + } + $this->encoding = $encodingUpper; + + return $this; + } + + /** + * Get the defined character encoding to work with + * + * @return string + * @throws Exception\LogicException If no encoding was defined + */ + public function getEncoding() + { + return $this->encoding; + } + + /** + * Get the defined character encoding to convert to + * + * @return string|null + */ + public function getConvertEncoding() + { + return $this->convertEncoding; + } + + /** + * Convert a string from defined character encoding to the defined convert encoding + * + * @param string $str + * @param bool $reverse + * @return string|false + */ + public function convert($str, $reverse = false) + { + $encoding = $this->getEncoding(); + $convertEncoding = $this->getConvertEncoding(); + if ($convertEncoding === null) { + throw new Exception\LogicException( + 'No convert encoding defined' + ); + } + + if ($encoding === $convertEncoding) { + return $str; + } + + $from = $reverse ? $convertEncoding : $encoding; + $to = $reverse ? $encoding : $convertEncoding; + throw new Exception\RuntimeException(sprintf( + 'Converting from "%s" to "%s" isn\'t supported by this string wrapper', + $from, + $to + )); + } + + /** + * Wraps a string to a given number of characters + * + * @param string $string + * @param int $width + * @param string $break + * @param bool $cut + * @return string|false + */ + public function wordWrap($string, $width = 75, $break = "\n", $cut = false) + { + $string = (string) $string; + if ($string === '') { + return ''; + } + + $break = (string) $break; + if ($break === '') { + throw new Exception\InvalidArgumentException('Break string cannot be empty'); + } + + $width = (int) $width; + if ($width === 0 && $cut) { + throw new Exception\InvalidArgumentException('Cannot force cut when width is zero'); + } + + if (StringUtils::isSingleByteEncoding($this->getEncoding())) { + return wordwrap($string, $width, $break, $cut); + } + + $stringWidth = $this->strlen($string); + $breakWidth = $this->strlen($break); + + $result = ''; + $lastStart = $lastSpace = 0; + + for ($current = 0; $current < $stringWidth; $current++) { + $char = $this->substr($string, $current, 1); + + $possibleBreak = $char; + if ($breakWidth !== 1) { + $possibleBreak = $this->substr($string, $current, $breakWidth); + } + + if ($possibleBreak === $break) { + $result .= $this->substr($string, $lastStart, $current - $lastStart + $breakWidth); + $current += $breakWidth - 1; + $lastStart = $lastSpace = $current + 1; + continue; + } + + if ($char === ' ') { + if ($current - $lastStart >= $width) { + $result .= $this->substr($string, $lastStart, $current - $lastStart) . $break; + $lastStart = $current + 1; + } + + $lastSpace = $current; + continue; + } + + if ($current - $lastStart >= $width && $cut && $lastStart >= $lastSpace) { + $result .= $this->substr($string, $lastStart, $current - $lastStart) . $break; + $lastStart = $lastSpace = $current; + continue; + } + + if ($current - $lastStart >= $width && $lastStart < $lastSpace) { + $result .= $this->substr($string, $lastStart, $lastSpace - $lastStart) . $break; + $lastStart = $lastSpace = $lastSpace + 1; + continue; + } + } + + if ($lastStart !== $current) { + $result .= $this->substr($string, $lastStart, $current - $lastStart); + } + + return $result; + } + + /** + * Pad a string to a certain length with another string + * + * @param string $input + * @param int $padLength + * @param string $padString + * @param int $padType + * @return string + */ + public function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT) + { + if (StringUtils::isSingleByteEncoding($this->getEncoding())) { + return str_pad($input, $padLength, $padString, $padType); + } + + $lengthOfPadding = $padLength - $this->strlen($input); + if ($lengthOfPadding <= 0) { + return $input; + } + + $padStringLength = $this->strlen($padString); + if ($padStringLength === 0) { + return $input; + } + + $repeatCount = floor($lengthOfPadding / $padStringLength); + + if ($padType === STR_PAD_BOTH) { + $repeatCountLeft = $repeatCountRight = ($repeatCount - $repeatCount % 2) / 2; + + $lastStringLength = $lengthOfPadding - 2 * $repeatCountLeft * $padStringLength; + $lastStringLeftLength = $lastStringRightLength = floor($lastStringLength / 2); + $lastStringRightLength += $lastStringLength % 2; + + $lastStringLeft = $this->substr($padString, 0, $lastStringLeftLength); + $lastStringRight = $this->substr($padString, 0, $lastStringRightLength); + + return str_repeat($padString, $repeatCountLeft) . $lastStringLeft + . $input + . str_repeat($padString, $repeatCountRight) . $lastStringRight; + } + + $lastString = $this->substr($padString, 0, $lengthOfPadding % $padStringLength); + + if ($padType === STR_PAD_LEFT) { + return str_repeat($padString, $repeatCount) . $lastString . $input; + } + + return $input . str_repeat($padString, $repeatCount) . $lastString; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Iconv.php b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Iconv.php new file mode 100644 index 00000000..bc791b89 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Iconv.php @@ -0,0 +1,289 @@ +getEncoding()); + } + + /** + * Returns the portion of string specified by the start and length parameters + * + * @param string $str + * @param int $offset + * @param int|null $length + * @return string|false + */ + public function substr($str, $offset = 0, $length = null) + { + return iconv_substr($str, $offset, $length, $this->getEncoding()); + } + + /** + * Find the position of the first occurrence of a substring in a string + * + * @param string $haystack + * @param string $needle + * @param int $offset + * @return int|false + */ + public function strpos($haystack, $needle, $offset = 0) + { + return iconv_strpos($haystack, $needle, $offset, $this->getEncoding()); + } + + /** + * Convert a string from defined encoding to the defined convert encoding + * + * @param string $str + * @param bool $reverse + * @return string|false + */ + public function convert($str, $reverse = false) + { + $encoding = $this->getEncoding(); + $convertEncoding = $this->getConvertEncoding(); + if ($convertEncoding === null) { + throw new Exception\LogicException( + 'No convert encoding defined' + ); + } + + if ($encoding === $convertEncoding) { + return $str; + } + + $fromEncoding = $reverse ? $convertEncoding : $encoding; + $toEncoding = $reverse ? $encoding : $convertEncoding; + + // automatically add "//IGNORE" to not stop converting on invalid characters + // invalid characters triggers a notice anyway + return iconv($fromEncoding, $toEncoding . '//IGNORE', $str); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Intl.php b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Intl.php new file mode 100644 index 00000000..4644db36 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Intl.php @@ -0,0 +1,88 @@ +getEncoding()); + } + + /** + * Returns the portion of string specified by the start and length parameters + * + * @param string $str + * @param int $offset + * @param int|null $length + * @return string|false + */ + public function substr($str, $offset = 0, $length = null) + { + return mb_substr($str, $offset, $length, $this->getEncoding()); + } + + /** + * Find the position of the first occurrence of a substring in a string + * + * @param string $haystack + * @param string $needle + * @param int $offset + * @return int|false + */ + public function strpos($haystack, $needle, $offset = 0) + { + return mb_strpos($haystack, $needle, $offset, $this->getEncoding()); + } + + /** + * Convert a string from defined encoding to the defined convert encoding + * + * @param string $str + * @param bool $reverse + * @return string|false + */ + public function convert($str, $reverse = false) + { + $encoding = $this->getEncoding(); + $convertEncoding = $this->getConvertEncoding(); + + if ($convertEncoding === null) { + throw new Exception\LogicException( + 'No convert encoding defined' + ); + } + + if ($encoding === $convertEncoding) { + return $str; + } + + $fromEncoding = $reverse ? $convertEncoding : $encoding; + $toEncoding = $reverse ? $encoding : $convertEncoding; + return mb_convert_encoding($str, $toEncoding, $fromEncoding); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Native.php b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Native.php new file mode 100644 index 00000000..b01bb86c --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/Native.php @@ -0,0 +1,134 @@ +convertEncoding = $encodingUpper; + } + + if ($convertEncoding !== null) { + if ($encodingUpper !== strtoupper($convertEncoding)) { + throw new Exception\InvalidArgumentException( + 'Wrapper doesn\'t support to convert between character encodings' + ); + } + + $this->convertEncoding = $encodingUpper; + } else { + $this->convertEncoding = null; + } + $this->encoding = $encodingUpper; + + return $this; + } + + /** + * Returns the length of the given string + * + * @param string $str + * @return int|false + */ + public function strlen($str) + { + return strlen($str); + } + + /** + * Returns the portion of string specified by the start and length parameters + * + * @param string $str + * @param int $offset + * @param int|null $length + * @return string|false + */ + public function substr($str, $offset = 0, $length = null) + { + return substr($str, $offset, $length); + } + + /** + * Find the position of the first occurrence of a substring in a string + * + * @param string $haystack + * @param string $needle + * @param int $offset + * @return int|false + */ + public function strpos($haystack, $needle, $offset = 0) + { + return strpos($haystack, $needle, $offset); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/StringWrapperInterface.php b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/StringWrapperInterface.php new file mode 100644 index 00000000..f25b3253 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/src/StringWrapper/StringWrapperInterface.php @@ -0,0 +1,111 @@ +assertEquals(ArrayObject::STD_PROP_LIST, $ar->getFlags()); + $this->assertEquals('ArrayIterator', $ar->getIteratorClass()); + $this->assertInstanceOf('ArrayIterator', $ar->getIterator()); + $this->assertSame([], $ar->getArrayCopy()); + $this->assertEquals(0, $ar->count()); + } + + public function testConstructorParameters() + { + $ar = new ArrayObject(['foo' => 'bar'], ArrayObject::ARRAY_AS_PROPS, 'RecursiveArrayIterator'); + $this->assertEquals(ArrayObject::ARRAY_AS_PROPS, $ar->getFlags()); + $this->assertEquals('RecursiveArrayIterator', $ar->getIteratorClass()); + $this->assertInstanceOf('RecursiveArrayIterator', $ar->getIterator()); + $this->assertSame(['foo' => 'bar'], $ar->getArrayCopy()); + $this->assertEquals(1, $ar->count()); + $this->assertSame('bar', $ar->foo); + $this->assertSame('bar', $ar['foo']); + } + + public function testStdPropList() + { + $ar = new ArrayObject(); + $ar->foo = 'bar'; + $ar->bar = 'baz'; + $this->assertSame('bar', $ar->foo); + $this->assertSame('baz', $ar->bar); + $this->assertFalse(isset($ar['foo'])); + $this->assertFalse(isset($ar['bar'])); + $this->assertEquals(0, $ar->count()); + $this->assertSame([], $ar->getArrayCopy()); + } + + public function testStdPropListCannotAccessObjectVars() + { + $this->expectException(InvalidArgumentException::class); + $ar = new ArrayObject(); + $ar->flag; + } + + public function testStdPropListStillHandlesArrays() + { + $ar = new ArrayObject(); + $ar->foo = 'bar'; + $ar['foo'] = 'baz'; + + $this->assertSame('bar', $ar->foo); + $this->assertSame('baz', $ar['foo']); + $this->assertEquals(1, $ar->count()); + } + + public function testArrayAsProps() + { + $ar = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS); + $ar->foo = 'bar'; + $ar['foo'] = 'baz'; + $ar->bar = 'foo'; + $ar['baz'] = 'bar'; + + $this->assertSame('baz', $ar->foo); + $this->assertSame('baz', $ar['foo']); + $this->assertSame($ar->foo, $ar['foo']); + $this->assertEquals(3, $ar->count()); + } + + public function testAppend() + { + $ar = new ArrayObject(['one', 'two']); + $this->assertEquals(2, $ar->count()); + + $ar->append('three'); + + $this->assertSame('three', $ar[2]); + $this->assertEquals(3, $ar->count()); + } + + public function testAsort() + { + $ar = new ArrayObject(['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple']); + $sorted = $ar->getArrayCopy(); + asort($sorted); + $ar->asort(); + $this->assertSame($sorted, $ar->getArrayCopy()); + } + + /** + * PHPUnit 5.7 does not namespace error classes; retrieve appropriate one + * based on what is available. + * + * @return string + */ + protected function getExpectedWarningClass() + { + return class_exists(Warning::class) ? Warning::class : \PHPUnit_Framework_Error_Warning::class; + } + + public function testCount() + { + if (PHP_VERSION_ID >= 70200) { + $this->expectException($this->getExpectedWarningClass()); + $this->expectExceptionMessage('Parameter must be an array or an object that implements Countable'); + } + $ar = new ArrayObject(new TestAsset\ArrayObjectObjectVars()); + $this->assertCount(1, $ar); + } + + public function testCountable() + { + $ar = new ArrayObject(new TestAsset\ArrayObjectObjectCount()); + $this->assertCount(42, $ar); + } + + public function testExchangeArray() + { + $ar = new ArrayObject(['foo' => 'bar']); + $old = $ar->exchangeArray(['bar' => 'baz']); + + $this->assertSame(['foo' => 'bar'], $old); + $this->assertSame(['bar' => 'baz'], $ar->getArrayCopy()); + } + + public function testExchangeArrayPhpArrayObject() + { + $ar = new ArrayObject(['foo' => 'bar']); + $old = $ar->exchangeArray(new \ArrayObject(['bar' => 'baz'])); + + $this->assertSame(['foo' => 'bar'], $old); + $this->assertSame(['bar' => 'baz'], $ar->getArrayCopy()); + } + + public function testExchangeArrayStdlibArrayObject() + { + $ar = new ArrayObject(['foo' => 'bar']); + $old = $ar->exchangeArray(new ArrayObject(['bar' => 'baz'])); + + $this->assertSame(['foo' => 'bar'], $old); + $this->assertSame(['bar' => 'baz'], $ar->getArrayCopy()); + } + + public function testExchangeArrayTestAssetIterator() + { + $ar = new ArrayObject(); + $ar->exchangeArray(new TestAsset\ArrayObjectIterator(['foo' => 'bar'])); + + // make sure it does what php array object does: + $ar2 = new \ArrayObject(); + $ar2->exchangeArray(new TestAsset\ArrayObjectIterator(['foo' => 'bar'])); + + $this->assertEquals($ar2->getArrayCopy(), $ar->getArrayCopy()); + } + + public function testExchangeArrayArrayIterator() + { + $ar = new ArrayObject(); + $ar->exchangeArray(new \ArrayIterator(['foo' => 'bar'])); + + $this->assertEquals(['foo' => 'bar'], $ar->getArrayCopy()); + } + + public function testExchangeArrayStringArgumentFail() + { + $this->expectException(InvalidArgumentException::class); + $ar = new ArrayObject(['foo' => 'bar']); + $old = $ar->exchangeArray('Bacon'); + } + + public function testGetArrayCopy() + { + $ar = new ArrayObject(['foo' => 'bar']); + $this->assertSame(['foo' => 'bar'], $ar->getArrayCopy()); + } + + public function testFlags() + { + $ar = new ArrayObject(); + $this->assertEquals(ArrayObject::STD_PROP_LIST, $ar->getFlags()); + $ar = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS); + $this->assertEquals(ArrayObject::ARRAY_AS_PROPS, $ar->getFlags()); + + $ar->setFlags(ArrayObject::STD_PROP_LIST); + $this->assertEquals(ArrayObject::STD_PROP_LIST, $ar->getFlags()); + $ar->setFlags(ArrayObject::ARRAY_AS_PROPS); + $this->assertEquals(ArrayObject::ARRAY_AS_PROPS, $ar->getFlags()); + } + + public function testIterator() + { + $ar = new ArrayObject(['1' => 'one', '2' => 'two', '3' => 'three']); + $iterator = $ar->getIterator(); + $iterator2 = new \ArrayIterator($ar->getArrayCopy()); + $this->assertEquals($iterator2->getArrayCopy(), $iterator->getArrayCopy()); + } + + public function testIteratorClass() + { + $ar = new ArrayObject([], ArrayObject::STD_PROP_LIST, 'RecursiveArrayIterator'); + $this->assertEquals('RecursiveArrayIterator', $ar->getIteratorClass()); + $ar = new ArrayObject([], ArrayObject::STD_PROP_LIST, 'ArrayIterator'); + $this->assertEquals('ArrayIterator', $ar->getIteratorClass()); + $ar->setIteratorClass('RecursiveArrayIterator'); + $this->assertEquals('RecursiveArrayIterator', $ar->getIteratorClass()); + $ar->setIteratorClass('ArrayIterator'); + $this->assertEquals('ArrayIterator', $ar->getIteratorClass()); + } + + public function testInvalidIteratorClassThrowsInvalidArgumentException() + { + $this->expectException(InvalidArgumentException::class); + $ar = new ArrayObject([], ArrayObject::STD_PROP_LIST, 'InvalidArrayIterator'); + } + + public function testKsort() + { + $ar = new ArrayObject(['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple']); + $sorted = $ar->getArrayCopy(); + ksort($sorted); + $ar->ksort(); + $this->assertSame($sorted, $ar->getArrayCopy()); + } + + public function testNatcasesort() + { + $ar = new ArrayObject(['IMG0.png', 'img12.png', 'img10.png', 'img2.png', 'img1.png', 'IMG3.png']); + $sorted = $ar->getArrayCopy(); + natcasesort($sorted); + $ar->natcasesort(); + $this->assertSame($sorted, $ar->getArrayCopy()); + } + + public function testNatsort() + { + $ar = new ArrayObject(['img12.png', 'img10.png', 'img2.png', 'img1.png']); + $sorted = $ar->getArrayCopy(); + natsort($sorted); + $ar->natsort(); + $this->assertSame($sorted, $ar->getArrayCopy()); + } + + public function testOffsetExists() + { + $ar = new ArrayObject(); + $ar['foo'] = 'bar'; + $ar->bar = 'baz'; + + $this->assertTrue($ar->offsetExists('foo')); + $this->assertFalse($ar->offsetExists('bar')); + $this->assertTrue(isset($ar->bar)); + $this->assertFalse(isset($ar->foo)); + } + + public function testOffsetExistsThrowsExceptionOnProtectedProperty() + { + $this->expectException(InvalidArgumentException::class); + $ar = new ArrayObject(); + isset($ar->protectedProperties); + } + + public function testOffsetGetOffsetSet() + { + $ar = new ArrayObject(); + $ar['foo'] = 'bar'; + $ar->bar = 'baz'; + + $this->assertSame('bar', $ar['foo']); + $this->assertSame('baz', $ar->bar); + $this->assertFalse(isset($ar->unknown)); + $this->assertFalse(isset($ar['unknown'])); + } + + public function testOffsetGetThrowsExceptionOnProtectedProperty() + { + $this->expectException(InvalidArgumentException::class); + $ar = new ArrayObject(); + $ar->protectedProperties; + } + + public function testOffsetSetThrowsExceptionOnProtectedProperty() + { + $this->expectException(InvalidArgumentException::class); + $ar = new ArrayObject(); + $ar->protectedProperties = null; + } + + public function testOffsetUnset() + { + $ar = new ArrayObject(); + $ar['foo'] = 'bar'; + $ar->bar = 'foo'; + unset($ar['foo']); + unset($ar->bar); + $this->assertFalse(isset($ar['foo'])); + $this->assertFalse(isset($ar->bar)); + $this->assertSame([], $ar->getArrayCopy()); + } + + public function testOffsetUnsetMultidimensional() + { + $ar = new ArrayObject(); + $ar['foo'] = ['bar' => ['baz' => 'boo']]; + unset($ar['foo']['bar']['baz']); + + $this->assertArrayNotHasKey('baz', $ar['foo']['bar']); + } + + public function testOffsetUnsetThrowsExceptionOnProtectedProperty() + { + $this->expectException(InvalidArgumentException::class); + $ar = new ArrayObject(); + unset($ar->protectedProperties); + } + + public function testSerializeUnserialize() + { + $ar = new ArrayObject(); + $ar->foo = 'bar'; + $ar['bar'] = 'foo'; + $serialized = $ar->serialize(); + + $ar = new ArrayObject(); + $ar->unserialize($serialized); + + $this->assertSame('bar', $ar->foo); + $this->assertSame('foo', $ar['bar']); + } + + public function testUasort() + { + $function = function ($a, $b) { + if ($a == $b) { + return 0; + } + + return ($a < $b) ? -1 : 1; + }; + $ar = new ArrayObject(['a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4]); + $sorted = $ar->getArrayCopy(); + uasort($sorted, $function); + $ar->uasort($function); + $this->assertSame($sorted, $ar->getArrayCopy()); + } + + public function testUksort() + { + $function = function ($a, $b) { + $a = preg_replace('@^(a|an|the) @', '', $a); + $b = preg_replace('@^(a|an|the) @', '', $b); + + return strcasecmp($a, $b); + }; + + $ar = new ArrayObject(['John' => 1, 'the Earth' => 2, 'an apple' => 3, 'a banana' => 4]); + $sorted = $ar->getArrayCopy(); + uksort($sorted, $function); + $ar->uksort($function); + $this->assertSame($sorted, $ar->getArrayCopy()); + } + + /** + * @group 6089 + */ + public function testSerializationRestoresProperties() + { + $ar = new ArrayObject(); + $ar->foo = 'bar'; + $ar['bar'] = 'foo'; + + $this->assertEquals($ar, unserialize(serialize($ar))); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/ArrayUtilsTest.php b/bundled-libs/zendframework/zend-stdlib/test/ArrayUtilsTest.php new file mode 100644 index 00000000..907503ac --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/ArrayUtilsTest.php @@ -0,0 +1,521 @@ + 'bar' + ]], + [[ + '15', + 'foo' => 'bar', + 'baz' => ['baz'] + ]], + [[ + 0 => false, + 2 => null + ]], + [[ + -100 => 'foo', + 100 => 'bar' + ]], + [[ + 1 => 0 + ]], + ]; + } + + public static function validLists() + { + return [ + [[null]], + [[true]], + [[false]], + [[0]], + [[-0.9999]], + [['string']], + [[new stdClass]], + [[ + 0 => 'foo', + 1 => 'bar', + 2 => false, + 3 => null, + 4 => [], + 5 => new stdClass() + ]] + ]; + } + + public static function validArraysWithStringKeys() + { + return [ + [[ + 'foo' => 'bar', + ]], + [[ + 'bar', + 'foo' => 'bar', + 'baz', + ]], + ]; + } + + public static function validArraysWithNumericKeys() + { + return [ + [[ + 'foo', + 'bar' + ]], + [[ + '0' => 'foo', + '1' => 'bar', + ]], + [[ + 'bar', + '1' => 'bar', + 3 => 'baz' + ]], + [[ + -10000 => null, + '-10000' => null, + ]], + [[ + '-00000.00009' => 'foo' + ]], + [[ + 1 => 0 + ]], + ]; + } + + public static function validArraysWithIntegerKeys() + { + return [ + [[ + 'foo', + 'bar,' + ]], + [[ + 100 => 'foo', + 200 => 'bar' + ]], + [[ + -100 => 'foo', + 0 => 'bar', + 100 => 'baz' + ]], + [[ + 'foo', + 'bar', + 1000 => 'baz' + ]], + ]; + } + + public static function invalidArrays() + { + return [ + [new stdClass()], + [15], + ['foo'], + [new ArrayObject()], + ]; + } + + public static function mergeArrays() + { + return [ + 'merge-integer-and-string-keys' => [ + [ + 'foo', + 3 => 'bar', + 'baz' => 'baz', + 4 => [ + 'a', + 1 => 'b', + 'c', + ], + ], + [ + 'baz', + 4 => [ + 'd' => 'd', + ], + ], + false, + [ + 0 => 'foo', + 3 => 'bar', + 'baz' => 'baz', + 4 => [ + 'a', + 1 => 'b', + 'c', + ], + 5 => 'baz', + 6 => [ + 'd' => 'd', + ], + ] + ], + 'merge-integer-and-string-keys-preserve-numeric' => [ + [ + 'foo', + 3 => 'bar', + 'baz' => 'baz', + 4 => [ + 'a', + 1 => 'b', + 'c', + ], + ], + [ + 'baz', + 4 => [ + 'd' => 'd', + ], + ], + true, + [ + 0 => 'baz', + 3 => 'bar', + 'baz' => 'baz', + 4 => [ + 'a', + 1 => 'b', + 'c', + 'd' => 'd', + ], + ] + ], + 'merge-arrays-recursively' => [ + [ + 'foo' => [ + 'baz' + ] + ], + [ + 'foo' => [ + 'baz' + ] + ], + false, + [ + 'foo' => [ + 0 => 'baz', + 1 => 'baz' + ] + ] + ], + 'replace-string-keys' => [ + [ + 'foo' => 'bar', + 'bar' => [] + ], + [ + 'foo' => 'baz', + 'bar' => 'bat' + ], + false, + [ + 'foo' => 'baz', + 'bar' => 'bat' + ] + ], + 'merge-with-null' => [ + [ + 'foo' => null, + null => 'rod', + 'cat' => 'bar', + 'god' => 'rad' + ], + [ + 'foo' => 'baz', + null => 'zad', + 'god' => null + ], + false, + [ + 'foo' => 'baz', + null => 'zad', + 'cat' => 'bar', + 'god' => null + ] + ], + ]; + } + + /** + * @group 6903 + */ + public function testMergeReplaceKey() + { + $expected = [ + 'car' => [ + 'met' => 'bet', + ], + 'new' => [ + 'foo' => 'get', + ], + ]; + $a = [ + 'car' => [ + 'boo' => 'foo', + 'doo' => 'moo', + ], + ]; + $b = [ + 'car' => new \Zend\Stdlib\ArrayUtils\MergeReplaceKey([ + 'met' => 'bet', + ]), + 'new' => new \Zend\Stdlib\ArrayUtils\MergeReplaceKey([ + 'foo' => 'get', + ]), + ]; + $this->assertInstanceOf('Zend\Stdlib\ArrayUtils\MergeReplaceKeyInterface', $b['car']); + $this->assertEquals($expected, ArrayUtils::merge($a, $b)); + } + + /** + * @group 6899 + */ + public function testAllowsRemovingKeys() + { + $a = [ + 'foo' => 'bar', + 'bar' => 'bat' + ]; + $b = [ + 'foo' => new MergeRemoveKey(), + 'baz' => new MergeRemoveKey(), + ]; + $expected = [ + 'bar' => 'bat' + ]; + $this->assertEquals($expected, ArrayUtils::merge($a, $b)); + } + + public static function validIterators() + { + $array = [ + 'foo' => [ + 'bar' => [ + 'baz' => [ + 'baz' => 'bat', + ], + ], + ], + ]; + $arrayAccess = new ArrayObject($array); + $toArray = new Parameters($array); + + return [ + // Description => [input, expected array] + 'array' => [$array, $array], + 'Traversable' => [$arrayAccess, $array], + 'Traversable and toArray' => [$toArray, $array], + ]; + } + + public static function invalidIterators() + { + return [ + [null], + [true], + [false], + [0], + [1], + [0.0], + [1.0], + ['string'], + [new stdClass], + ]; + } + + /** + * @dataProvider validArraysWithStringKeys + */ + public function testValidArraysWithStringKeys($test) + { + $this->assertTrue(ArrayUtils::hasStringKeys($test)); + } + + /** + * @dataProvider validArraysWithIntegerKeys + */ + public function testValidArraysWithIntegerKeys($test) + { + $this->assertTrue(ArrayUtils::hasIntegerKeys($test)); + } + + /** + * @dataProvider validArraysWithNumericKeys + */ + public function testValidArraysWithNumericKeys($test) + { + $this->assertTrue(ArrayUtils::hasNumericKeys($test)); + } + + /** + * @dataProvider invalidArrays + */ + public function testInvalidArraysAlwaysReturnFalse($test) + { + $this->assertFalse(ArrayUtils::hasStringKeys($test, false)); + $this->assertFalse(ArrayUtils::hasIntegerKeys($test, false)); + $this->assertFalse(ArrayUtils::hasNumericKeys($test, false)); + $this->assertFalse(ArrayUtils::isList($test, false)); + $this->assertFalse(ArrayUtils::isHashTable($test, false)); + + $this->assertFalse(ArrayUtils::hasStringKeys($test, false)); + $this->assertFalse(ArrayUtils::hasIntegerKeys($test, false)); + $this->assertFalse(ArrayUtils::hasNumericKeys($test, false)); + $this->assertFalse(ArrayUtils::isList($test, false)); + $this->assertFalse(ArrayUtils::isHashTable($test, false)); + } + + /** + * @dataProvider validLists + */ + public function testLists($test) + { + $this->assertTrue(ArrayUtils::isList($test)); + $this->assertTrue(ArrayUtils::hasIntegerKeys($test)); + $this->assertTrue(ArrayUtils::hasNumericKeys($test)); + $this->assertFalse(ArrayUtils::hasStringKeys($test)); + $this->assertFalse(ArrayUtils::isHashTable($test)); + } + + /** + * @dataProvider validHashTables + */ + public function testHashTables($test) + { + $this->assertTrue(ArrayUtils::isHashTable($test)); + $this->assertFalse(ArrayUtils::isList($test)); + } + + public function testEmptyArrayReturnsTrue() + { + $test = []; + $this->assertTrue(ArrayUtils::hasStringKeys($test, true)); + $this->assertTrue(ArrayUtils::hasIntegerKeys($test, true)); + $this->assertTrue(ArrayUtils::hasNumericKeys($test, true)); + $this->assertTrue(ArrayUtils::isList($test, true)); + $this->assertTrue(ArrayUtils::isHashTable($test, true)); + } + + public function testEmptyArrayReturnsFalse() + { + $test = []; + $this->assertFalse(ArrayUtils::hasStringKeys($test, false)); + $this->assertFalse(ArrayUtils::hasIntegerKeys($test, false)); + $this->assertFalse(ArrayUtils::hasNumericKeys($test, false)); + $this->assertFalse(ArrayUtils::isList($test, false)); + $this->assertFalse(ArrayUtils::isHashTable($test, false)); + } + + /** + * @dataProvider mergeArrays + */ + public function testMerge($a, $b, $preserveNumericKeys, $expected) + { + $this->assertEquals($expected, ArrayUtils::merge($a, $b, $preserveNumericKeys)); + } + + /** + * @dataProvider validIterators + */ + public function testValidIteratorsReturnArrayRepresentation($test, $expected) + { + $result = ArrayUtils::iteratorToArray($test); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider invalidIterators + */ + public function testInvalidIteratorsRaiseInvalidArgumentException($test) + { + $this->expectException(InvalidArgumentException::class); + $this->assertFalse(ArrayUtils::iteratorToArray($test)); + } + + public function filterArrays() + { + return [ + [ + ['foo' => 'bar', 'fiz' => 'buz'], + function ($value) { + if ($value == 'bar') { + return false; + } + return true; + }, + null, + ['fiz' => 'buz'] + ], + [ + ['foo' => 'bar', 'fiz' => 'buz'], + function ($value, $key) { + if ($value == 'buz') { + return false; + } + + if ($key == 'foo') { + return false; + } + + return true; + }, + ArrayUtils::ARRAY_FILTER_USE_BOTH, + [] + ], + [ + ['foo' => 'bar', 'fiz' => 'buz'], + function ($key) { + if ($key == 'foo') { + return false; + } + return true; + }, + ArrayUtils::ARRAY_FILTER_USE_KEY, + ['fiz' => 'buz'] + ], + ]; + } + + /** + * @dataProvider filterArrays + */ + public function testFiltersArray($data, $callback, $flag, $result) + { + $this->assertEquals($result, ArrayUtils::filter($data, $callback, $flag)); + } + + public function testInvalidCallableRaiseInvalidArgumentException() + { + $this->expectException(InvalidArgumentException::class); + ArrayUtils::filter([], "INVALID"); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/ConsoleHelperTest.php b/bundled-libs/zendframework/zend-stdlib/test/ConsoleHelperTest.php new file mode 100644 index 00000000..276276ef --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/ConsoleHelperTest.php @@ -0,0 +1,148 @@ +helper = new ConsoleHelper(); + } + + public function disableColorSupport() + { + $r = new ReflectionProperty($this->helper, 'supportsColor'); + $r->setAccessible(true); + $r->setValue($this->helper, false); + } + + public function enableColorSupport() + { + $r = new ReflectionProperty($this->helper, 'supportsColor'); + $r->setAccessible(true); + $r->setValue($this->helper, true); + } + + public function overrideEolSequence($newSequence) + { + $r = new ReflectionProperty($this->helper, 'eol'); + $r->setAccessible(true); + $r->setValue($this->helper, $newSequence); + } + + public function overrideStderrResource($stderr) + { + $r = new ReflectionProperty($this->helper, 'stderr'); + $r->setAccessible(true); + $r->setValue($this->helper, $stderr); + } + + public function retrieveStreamContents($stream) + { + rewind($stream); + $contents = ''; + while (! feof($stream)) { + $contents .= fread($stream, 4096); + } + return $contents; + } + + public function testCanColorizeInfoString() + { + $string = ' -h|--help This help message'; + $this->enableColorSupport(); + $colorized = $this->helper->colorize($string); + + $this->assertEquals(" \033[32m-h|--help\033[0m This help message", $colorized); + } + + public function testCanColorizeErrorString() + { + $string = 'NOT OK An error occurred'; + $this->enableColorSupport(); + $colorized = $this->helper->colorize($string); + + $this->assertEquals("\033[31mNOT OK\033[0m An error occurred", $colorized); + } + + public function testCanColorizeMixedStrings() + { + $this->enableColorSupport(); + $string = "NOT OK\n\nUsage: foo"; + $colorized = $this->helper->colorize($string); + + $this->assertContains("\033[31mNOT OK\033[0m", $colorized, 'Colorized error string not found'); + $this->assertContains("\033[32mUsage:\033[0m", $colorized, 'Colorized info string not found'); + } + + public function testColorizationWillReplaceTagsWithEmptyStringsWhenColorSupportIsNotDetected() + { + $this->disableColorSupport(); + $string = "NOT OK\n\nUsage: foo"; + $colorized = $this->helper->colorize($string); + + $this->assertNotContains("\033[31m", $colorized, 'Colorized error string discovered'); + $this->assertNotContains("\033[32m", $colorized, 'Colorized info string discovered'); + $this->assertNotContains("\033[0m", $colorized, 'Color reset sequence discovered'); + $this->assertNotRegexp("/<\/?error>/", $colorized, 'Error template string discovered'); + $this->assertNotRegexp("/<\/?info>/", $colorized, 'Info template string discovered'); + } + + public function testWriteFormatsLinesToPhpEolSequenceAndWritesToProvidedStream() + { + $this->overrideEolSequence("\r\n"); + $string = "foo bar\nbaz bat"; + $stream = fopen('php://temp', 'w+'); + + $this->helper->write($string, false, $stream); + + $contents = $this->retrieveStreamContents($stream); + $this->assertContains("\r\n", $contents); + } + + public function testWriteWillColorizeOutputIfRequested() + { + $this->enableColorSupport(); + $string = 'foo bar'; + $stream = fopen('php://temp', 'w+'); + + $this->helper->write($string, true, $stream); + + $contents = $this->retrieveStreamContents($stream); + $this->assertContains("\033[32mbar\033[0m", $contents); + } + + public function testWriteLineAppendsPhpEolSequenceToString() + { + $this->overrideEolSequence("\r\n"); + $string = 'foo bar'; + $stream = fopen('php://temp', 'w+'); + + $this->helper->writeLine($string, false, $stream); + + $contents = $this->retrieveStreamContents($stream); + $this->assertRegexp("/bar\r\n$/", $contents); + } + + public function testWriteErrorMessageWritesColorizedOutputToStderr() + { + $stderr = fopen('php://temp', 'w+'); + $this->overrideStderrResource($stderr); + $this->enableColorSupport(); + $this->overrideEolSequence("\r\n"); + + $this->helper->writeErrorMessage('an error occurred'); + + $contents = $this->retrieveStreamContents($stderr); + $this->assertEquals("\033[31man error occurred\033[0m\r\n\r\n", $contents); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/ErrorHandlerTest.php b/bundled-libs/zendframework/zend-stdlib/test/ErrorHandlerTest.php new file mode 100644 index 00000000..2a00c64b --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/ErrorHandlerTest.php @@ -0,0 +1,105 @@ +assertSame(0, ErrorHandler::getNestedLevel()); + + ErrorHandler::start(); + $this->assertSame(1, ErrorHandler::getNestedLevel()); + + ErrorHandler::start(); + $this->assertSame(2, ErrorHandler::getNestedLevel()); + + ErrorHandler::stop(); + $this->assertSame(1, ErrorHandler::getNestedLevel()); + + ErrorHandler::stop(); + $this->assertSame(0, ErrorHandler::getNestedLevel()); + } + + public function testClean() + { + ErrorHandler::start(); + $this->assertSame(1, ErrorHandler::getNestedLevel()); + + ErrorHandler::start(); + $this->assertSame(2, ErrorHandler::getNestedLevel()); + + ErrorHandler::clean(); + $this->assertSame(0, ErrorHandler::getNestedLevel()); + } + + public function testStarted() + { + $this->assertFalse(ErrorHandler::started()); + + ErrorHandler::start(); + $this->assertTrue(ErrorHandler::started()); + + ErrorHandler::stop(); + $this->assertFalse(ErrorHandler::started()); + } + + public function testReturnCatchedError() + { + ErrorHandler::start(); + strpos(); // Invalid argument list + $err = ErrorHandler::stop(); + + $this->assertInstanceOf('ErrorException', $err); + } + + public function testThrowCatchedError() + { + ErrorHandler::start(); + strpos(); // Invalid argument list + + $this->expectException(ErrorException::class); + ErrorHandler::stop(true); + } + + public function testAddError() + { + ErrorHandler::start(); + ErrorHandler::addError(1, 'test-msg1', 'test-file1', 100); + ErrorHandler::addError(2, 'test-msg2', 'test-file2', 200); + $err = ErrorHandler::stop(); + + $this->assertInstanceOf('ErrorException', $err); + $this->assertEquals('test-file2', $err->getFile()); + $this->assertEquals('test-msg2', $err->getMessage()); + $this->assertEquals(200, $err->getLine()); + $this->assertEquals(0, $err->getCode()); + $this->assertEquals(2, $err->getSeverity()); + + $previous = $err->getPrevious(); + $this->assertInstanceOf('ErrorException', $previous); + $this->assertEquals('test-file1', $previous->getFile()); + $this->assertEquals('test-msg1', $previous->getMessage()); + $this->assertEquals(100, $previous->getLine()); + $this->assertEquals(0, $previous->getCode()); + $this->assertEquals(1, $previous->getSeverity()); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/FastPriorityQueueTest.php b/bundled-libs/zendframework/zend-stdlib/test/FastPriorityQueueTest.php new file mode 100644 index 00000000..867519bf --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/FastPriorityQueueTest.php @@ -0,0 +1,348 @@ +queue = new FastPriorityQueue(); + $this->insertDataQueue($this->queue); + $this->expected = [ + 'test1', + 'test2', + 'test3', + 'test4', + 'test5', + 'test6' + ]; + } + + protected function getDataPriorityQueue() + { + return [ + 'test3' => -1, + 'test5' => -10, + 'test1' => 5, + 'test2' => 2, + 'test4' => -1, + 'test6' => -10 + ]; + } + + protected function insertDataQueue(FastPriorityQueue $queue) + { + foreach ($this->getDataPriorityQueue() as $value => $priority) { + $queue->insert($value, $priority); + } + } + + /** + * Test the insert and extract operations for the queue + * We test that extract() function remove the elements + */ + public function testInsertExtract() + { + foreach ($this->expected as $value) { + $this->assertEquals($value, $this->queue->extract()); + } + // We check that the elements are removed from the queue + $this->assertTrue($this->queue->isEmpty()); + } + + public function testIteratePreserveElements() + { + $i = 0; + foreach ($this->queue as $value) { + $this->assertEquals($this->expected[$i++], $value); + } + // We check that the elements still exist in the queue + $i = 0; + foreach ($this->queue as $value) { + $this->assertEquals($this->expected[$i++], $value); + } + } + + public function testMaintainsInsertOrderForDataOfEqualPriority() + { + $queue = new FastPriorityQueue(); + $queue->insert('foo', 1000); + $queue->insert('bar', 1000); + $queue->insert('baz', 1000); + $queue->insert('bat', 1000); + + $expected = ['foo', 'bar', 'baz', 'bat']; + $test = []; + foreach ($queue as $datum) { + $test[] = $datum; + } + $this->assertEquals($expected, $test); + } + + public function testSerializationAndDeserializationShouldMaintainState() + { + $s = serialize($this->queue); + $unserialized = unserialize($s); + $count = count($this->queue); + $this->assertSame( + $count, + count($unserialized), + 'Expected count ' . $count . '; received ' . count($unserialized) + ); + + $expected = []; + foreach ($this->queue as $item) { + $expected[] = $item; + } + $test = []; + foreach ($unserialized as $item) { + $test[] = $item; + } + $this->assertSame( + $expected, + $test, + 'Expected: ' . var_export($expected, 1) . "\nReceived:" . var_export($test, 1) + ); + } + + public function testCanRetrieveQueueAsArray() + { + $test = $this->queue->toArray(); + $this->assertSame($this->expected, $test, var_export($test, 1)); + } + + public function testIteratorFunctions() + { + $this->assertEquals($this->expected, iterator_to_array($this->queue)); + } + + public function testRewindOperation() + { + $this->assertEquals(0, $this->queue->key()); + $this->queue->next(); + $this->assertEquals(1, $this->queue->key()); + $this->queue->rewind(); + $this->assertEquals(0, $this->queue->key()); + } + + public function testSetExtractFlag() + { + $priorities = $this->getDataPriorityQueue(); + $this->queue->setExtractFlags(FastPriorityQueue::EXTR_DATA); + $this->assertEquals($this->expected[0], $this->queue->extract()); + $this->queue->setExtractFlags(FastPriorityQueue::EXTR_PRIORITY); + $this->assertEquals($priorities[$this->expected[1]], $this->queue->extract()); + $this->queue->setExtractFlags(FastPriorityQueue::EXTR_BOTH); + $expected = [ + 'data' => $this->expected[2], + 'priority' => $priorities[$this->expected[2]] + ]; + $this->assertEquals($expected, $this->queue->extract()); + } + + public function testSetInvalidExtractFlag() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The extract flag specified is not valid'); + $this->queue->setExtractFlags('foo'); + } + + public function testIsEmpty() + { + $queue = new FastPriorityQueue(); + $this->assertTrue($queue->isEmpty()); + $queue->insert('foo', 1); + $this->assertFalse($queue->isEmpty()); + $value = $queue->extract(); + $this->assertTrue($queue->isEmpty()); + } + + public function testContains() + { + foreach ($this->expected as $value) { + $this->assertTrue($this->queue->contains($value)); + } + $this->assertFalse($this->queue->contains('foo')); + } + + public function testHasPriority() + { + foreach ($this->getDataPriorityQueue() as $value => $priority) { + $this->assertTrue($this->queue->hasPriority($priority)); + } + $this->assertFalse($this->queue->hasPriority(10000)); + } + + public function testCanRemoveItemFromQueue() + { + $this->assertTrue($this->queue->remove('test5')); + $tot = count($this->getDataPriorityQueue()) - 1; + $this->assertEquals($this->queue->count(), $tot); + $this->assertEquals(count($this->queue), $tot); + $expected = ['test1', 'test2', 'test3', 'test4', 'test6']; + $test = []; + foreach ($this->queue as $item) { + $test[] = $item; + } + $this->assertEquals($expected, $test); + } + + public function testRemoveOnlyTheFirstOccurenceFromQueue() + { + $data = $this->getDataPriorityQueue(); + $this->queue->insert('test2', $data['test2']); + $tot = count($this->getDataPriorityQueue()) + 1; + $this->assertEquals($this->queue->count(), $tot); + $this->assertEquals(count($this->queue), $tot); + + $expected = ['test1', 'test2', 'test2', 'test3', 'test4', 'test5', 'test6']; + $test = []; + foreach ($this->queue as $item) { + $test[] = $item; + } + $this->assertEquals($expected, $test); + + $this->assertTrue($this->queue->remove('test2')); + $this->assertEquals($this->queue->count(), $tot - 1); + $this->assertEquals(count($this->queue), $tot - 1); + $test = []; + foreach ($this->queue as $item) { + $test[] = $item; + } + $this->assertEquals($this->expected, $test); + } + + public function testRewindShouldNotRaiseErrorWhenQueueIsEmpty() + { + $queue = new FastPriorityQueue(); + $this->assertTrue($queue->isEmpty()); + + $queue->rewind(); + } + + public function testRemoveShouldFindItemEvenIfMultipleItemsAreInQueue() + { + $prototype = function ($e) { + }; + + $queue = new FastPriorityQueue(); + $this->assertTrue($queue->isEmpty()); + + $listeners = []; + for ($i = 0; $i < 5; $i += 1) { + $listeners[] = $listener = clone $prototype; + $queue->insert($listener, 1); + } + + $remove = array_rand(array_keys($listeners)); + $listener = $listeners[$remove]; + + $this->assertTrue($queue->contains($listener)); + $this->assertTrue($queue->remove($listener)); + $this->assertFalse($queue->contains($listener)); + } + + public function testIterativelyRemovingItemsShouldRemoveAllItems() + { + $prototype = function ($e) { + }; + + $queue = new FastPriorityQueue(); + $this->assertTrue($queue->isEmpty()); + + $listeners = []; + for ($i = 0; $i < 5; $i += 1) { + $listeners[] = $listener = clone $prototype; + $queue->insert($listener, 1); + } + + for ($i = 0; $i < 5; $i += 1) { + $listener = $listeners[$i]; + $queue->remove($listener); + } + + for ($i = 0; $i < 5; $i += 1) { + $listener = $listeners[$i]; + $this->assertFalse($queue->contains($listener), sprintf('Listener %s remained in queue', $i)); + } + } + + public function testRemoveShouldNotAffectExtract() + { + // Removing an element with low priority + $queue = new FastPriorityQueue(); + $queue->insert('a1', 1); + $queue->insert('a2', 1); + $queue->insert('b', 2); + $queue->remove('a1'); + $expected = ['b', 'a2']; + $test = []; + while ($value = $queue->extract()) { + $test[] = $value; + } + $this->assertEquals($expected, $test); + $this->assertTrue($queue->isEmpty()); + + // Removing an element in the middle of a set of elements with the same priority + $queue->insert('a1', 1); + $queue->insert('a2', 1); + $queue->insert('a3', 1); + $queue->remove('a2'); + $expected = ['a1', 'a3']; + $test = []; + while ($value = $queue->extract()) { + $test[] = $value; + } + $this->assertEquals($expected, $test); + $this->assertTrue($queue->isEmpty()); + + // Removing an element with high priority + $queue->insert('a', 1); + $queue->insert('b', 2); + $queue->remove('b'); + $expected = ['a']; + $test = []; + while ($value = $queue->extract()) { + $test[] = $value; + } + $this->assertEquals($expected, $test); + $this->assertTrue($queue->isEmpty()); + } + + public function testZeroPriority() + { + $queue = new FastPriorityQueue(); + $queue->insert('a', 0); + $queue->insert('b', 1); + $expected = ['b', 'a']; + $test = []; + foreach ($queue as $value) { + $test[] = $value; + } + $this->assertEquals($expected, $test); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/GlobTest.php b/bundled-libs/zendframework/zend-stdlib/test/GlobTest.php new file mode 100644 index 00000000..4650ccce --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/GlobTest.php @@ -0,0 +1,73 @@ +markTestSkipped('GLOB_BRACE not available'); + } + + $this->assertEquals( + glob(__DIR__ . '/_files/{alph,bet}a', GLOB_BRACE), + Glob::glob(__DIR__ . '/_files/{alph,bet}a', Glob::GLOB_BRACE, true) + ); + } + + public function testNonMatchingGlobReturnsArray() + { + $result = Glob::glob('/some/path/{,*.}{this,orthis}.php', Glob::GLOB_BRACE); + $this->assertInternalType('array', $result); + } + + public function testThrowExceptionOnError() + { + $this->expectException(RuntimeException::class); + + // run into a max path length error + $path = '/' . str_repeat('a', 10000); + Glob::glob($path); + } + + /** + * @param string $pattern + * + * @dataProvider patternsProvider + */ + public function testPatterns($pattern, $expectedSequence) + { + $result = Glob::glob(__DIR__ . '/_files/' . $pattern, Glob::GLOB_BRACE); + + $this->assertCount(count($expectedSequence), $result); + + foreach ($expectedSequence as $i => $expectedFileName) { + $this->assertStringEndsWith($expectedFileName, $result[$i]); + } + } + + public function patternsProvider() + { + return [ + [ + "{{,*.}alph,{,*.}bet}a", + [ + 'alpha', 'eta.alpha', 'zeta.alpha', 'beta', 'eta.beta', + 'zeta.beta' + ] + ] + ]; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/Guard/ArrayOrTraversableGuardTraitTest.php b/bundled-libs/zendframework/zend-stdlib/test/Guard/ArrayOrTraversableGuardTraitTest.php new file mode 100644 index 00000000..db16ac75 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/Guard/ArrayOrTraversableGuardTraitTest.php @@ -0,0 +1,42 @@ +expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Argument must be an array or Traversable, [string] given'); + $object->setArrayOrTraversable(''); + } + + public function testGuardForArrayOrTraversableAllowsArray() + { + $object = new GuardedObject; + $this->assertNull($object->setArrayOrTraversable([])); + } + + public function testGuardForArrayOrTraversableAllowsTraversable() + { + $object = new GuardedObject; + $traversable = new ArrayObject; + $this->assertNull($object->setArrayOrTraversable($traversable)); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/Guard/EmptyGuardTraitTest.php b/bundled-libs/zendframework/zend-stdlib/test/Guard/EmptyGuardTraitTest.php new file mode 100644 index 00000000..f0889a7c --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/Guard/EmptyGuardTraitTest.php @@ -0,0 +1,34 @@ +expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Argument cannot be empty'); + $object->setNotEmpty(''); + } + + public function testGuardAgainstEmptyAllowsNonEmptyString() + { + $object = new GuardedObject; + $this->assertNull($object->setNotEmpty('foo')); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/Guard/NullGuardTraitTest.php b/bundled-libs/zendframework/zend-stdlib/test/Guard/NullGuardTraitTest.php new file mode 100644 index 00000000..2d6a774d --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/Guard/NullGuardTraitTest.php @@ -0,0 +1,35 @@ +expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Argument cannot be null'); + + $object->setNotNull(null); + } + + public function testGuardAgainstNullAllowsNonNull() + { + $object = new GuardedObject; + $this->assertNull($object->setNotNull('foo')); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/MessageTest.php b/bundled-libs/zendframework/zend-stdlib/test/MessageTest.php new file mode 100644 index 00000000..9148d154 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/MessageTest.php @@ -0,0 +1,73 @@ +setContent('I can set content'); + $this->assertInstanceOf('Zend\Stdlib\Message', $ret); + $this->assertEquals('I can set content', $message->getContent()); + } + + public function testMessageCanSetAndGetMetadataKeyAsString() + { + $message = new Message(); + $ret = $message->setMetadata('foo', 'bar'); + $this->assertInstanceOf('Zend\Stdlib\Message', $ret); + $this->assertEquals('bar', $message->getMetadata('foo')); + $this->assertEquals(['foo' => 'bar'], $message->getMetadata()); + } + + public function testMessageCanSetAndGetMetadataKeyAsArray() + { + $message = new Message(); + $ret = $message->setMetadata(['foo' => 'bar']); + $this->assertInstanceOf('Zend\Stdlib\Message', $ret); + $this->assertEquals('bar', $message->getMetadata('foo')); + } + + public function testMessageGetMetadataWillUseDefaultValueIfNoneExist() + { + $message = new Message(); + $this->assertEquals('bar', $message->getMetadata('foo', 'bar')); + } + + public function testMessageThrowsExceptionOnInvalidKeyForMetadataSet() + { + $message = new Message(); + + $this->expectException(InvalidArgumentException::class); + $message->setMetadata(new \stdClass()); + } + + public function testMessageThrowsExceptionOnInvalidKeyForMetadataGet() + { + $message = new Message(); + + $this->expectException(InvalidArgumentException::class); + $message->getMetadata(new \stdClass()); + } + + public function testMessageToStringWorks() + { + $message = new Message(); + $message->setMetadata(['Foo' => 'bar', 'One' => 'Two']); + $message->setContent('This is my content'); + $expected = "Foo: bar\r\nOne: Two\r\n\r\nThis is my content"; + $this->assertEquals($expected, $message->toString()); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/OptionsTest.php b/bundled-libs/zendframework/zend-stdlib/test/OptionsTest.php new file mode 100644 index 00000000..82f0557f --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/OptionsTest.php @@ -0,0 +1,205 @@ + 1]); + + $this->assertEquals(1, $options->test_field); + } + + public function testConstructionWithTraversable() + { + $config = new ArrayObject(['test_field' => 1]); + $options = new TestOptions($config); + + $this->assertEquals(1, $options->test_field); + } + + public function testConstructionWithOptions() + { + $options = new TestOptions(new TestOptions(['test_field' => 1])); + + $this->assertEquals(1, $options->test_field); + } + + public function testInvalidFieldThrowsException() + { + $this->expectException(BadMethodCallException::class); + + new TestOptions(['foo' => 'bar']); + } + + public function testNonStrictOptionsDoesNotThrowException() + { + $this->assertInstanceOf( + 'ZendTest\Stdlib\TestAsset\TestOptionsNoStrict', + new TestOptionsNoStrict(['foo' => 'bar']) + ); + } + + public function testConstructionWithNull() + { + $this->assertInstanceOf('ZendTest\Stdlib\TestAsset\TestOptions', new TestOptions(null)); + } + + public function testUnsetting() + { + $options = new TestOptions(['test_field' => 1]); + + $this->assertEquals(true, isset($options->test_field)); + unset($options->testField); + $this->assertEquals(false, isset($options->test_field)); + } + + public function testUnsetThrowsInvalidArgumentException() + { + $options = new TestOptions; + + $this->expectException(InvalidArgumentException::class); + + unset($options->foobarField); + } + + public function testGetThrowsBadMethodCallException() + { + $options = new TestOptions(); + + $this->expectException(BadMethodCallException::class); + + $options->fieldFoobar; + } + + public function testSetFromArrayAcceptsArray() + { + $array = ['test_field' => 3]; + $options = new TestOptions(); + + $this->assertSame($options, $options->setFromArray($array)); + $this->assertEquals(3, $options->test_field); + } + + public function testSetFromArrayThrowsInvalidArgumentException() + { + $this->expectException(InvalidArgumentException::class); + $options = new TestOptions; + $options->setFromArray('asd'); + } + + public function testParentPublicProperty() + { + $options = new TestOptionsDerived(['parent_public' => 1]); + + $this->assertEquals(1, $options->parent_public); + } + + public function testParentProtectedProperty() + { + $options = new TestOptionsDerived(['parent_protected' => 1]); + + $this->assertEquals(1, $options->parent_protected); + } + + public function testParentPrivateProperty() + { + $this->expectException(Exception\BadMethodCallException::class); + $this->expectExceptionMessage( + 'The option "parent_private" does not have a callable "setParentPrivate" ("setparentprivate")' + . ' setter method which must be defined' + ); + + new TestOptionsDerived(['parent_private' => 1]); + } + + public function testDerivedPublicProperty() + { + $options = new TestOptionsDerived(['derived_public' => 1]); + + $this->assertEquals(1, $options->derived_public); + } + + public function testDerivedProtectedProperty() + { + $options = new TestOptionsDerived(['derived_protected' => 1]); + + $this->assertEquals(1, $options->derived_protected); + } + + public function testDerivedPrivateProperty() + { + $this->expectException(Exception\BadMethodCallException::class); + $this->expectExceptionMessage( + 'The option "derived_private" does not have a callable "setDerivedPrivate" ("setderivedprivate")' + .' setter method which must be defined' + ); + + new TestOptionsDerived(['derived_private' => 1]); + } + + public function testExceptionMessageContainsActualUsedSetter() + { + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage( + 'The option "foo bar" does not have a callable "setFooBar" ("setfoo bar")' + . ' setter method which must be defined' + ); + + new TestOptions([ + 'foo bar' => 'baz', + ]); + } + + /** + * @group 7287 + */ + public function testIssetReturnsFalseWhenMatchingGetterDoesNotExist() + { + $options = new TestOptionsWithoutGetter([ + 'foo' => 'bar', + ]); + $this->assertFalse(isset($options->foo)); + } + + /** + * @group 7287 + */ + public function testIssetDoesNotThrowExceptionWhenMatchingGetterDoesNotExist() + { + $options = new TestOptionsWithoutGetter(); + + isset($options->foo); + + $this->addToAssertionCount(1); + } + + /** + * @group 7287 + */ + public function testIssetReturnsTrueWithValidDataWhenMatchingGetterDoesNotExist() + { + $options = new TestOptions([ + 'test_field' => 1, + ]); + $this->assertTrue(isset($options->testField)); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/ParametersTest.php b/bundled-libs/zendframework/zend-stdlib/test/ParametersTest.php new file mode 100644 index 00000000..40b1d69e --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/ParametersTest.php @@ -0,0 +1,63 @@ +assertInstanceOf('Zend\Stdlib\ParametersInterface', $parameters); + $this->assertInstanceOf('ArrayObject', $parameters); + $this->assertInstanceOf('ArrayAccess', $parameters); + $this->assertInstanceOf('Countable', $parameters); + $this->assertInstanceOf('Serializable', $parameters); + $this->assertInstanceOf('Traversable', $parameters); + } + + public function testParametersPersistNameAndValues() + { + $parameters = new Parameters(['foo' => 'bar']); + $this->assertEquals('bar', $parameters['foo']); + $this->assertEquals('bar', $parameters->foo); + $parameters->offsetSet('baz', 5); + $this->assertEquals(5, $parameters->baz); + + $parameters->fromArray(['bar' => 'foo']); + $this->assertEquals('foo', $parameters->bar); + + $parameters->fromString('bar=foo&five=5'); + $this->assertEquals('foo', $parameters->bar); + $this->assertEquals('5', $parameters->five); + $this->assertEquals(['bar' => 'foo', 'five' => '5'], $parameters->toArray()); + $this->assertEquals('bar=foo&five=5', $parameters->toString()); + + $parameters->fromArray([]); + $parameters->set('foof', 'barf'); + $this->assertEquals('barf', $parameters->get('foof')); + $this->assertEquals('barf', $parameters->foof); + } + + public function testParametersOffsetgetReturnsNullIfNonexistentKeyIsProvided() + { + $parameters = new Parameters; + $this->assertNull($parameters->foo); + } + + public function testParametersGetReturnsDefaultValueIfNonExistent() + { + $parameters = new Parameters(); + + $this->assertEquals(5, $parameters->get('nonExistentProp', 5)); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/PriorityListTest.php b/bundled-libs/zendframework/zend-stdlib/test/PriorityListTest.php new file mode 100644 index 00000000..d60ace94 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/PriorityListTest.php @@ -0,0 +1,244 @@ +list = new PriorityList(); + } + + public function testInsert() + { + $this->list->insert('foo', new \stdClass(), 0); + + $this->assertEquals(1, count($this->list)); + + foreach ($this->list as $key => $value) { + $this->assertEquals('foo', $key); + } + } + + public function testInsertDuplicates() + { + $this->list->insert('foo', new \stdClass()); + $this->list->insert('bar', new \stdClass()); + + $this->assertEquals(2, count($this->list)); + + $this->list->insert('foo', new \stdClass()); + $this->list->insert('foo', new \stdClass()); + $this->list->insert('bar', new \stdClass()); + + $this->assertEquals(2, count($this->list)); + + $this->list->remove('foo'); + + $this->assertEquals(1, count($this->list)); + } + + public function testRemove() + { + $this->list->insert('foo', new \stdClass(), 0); + $this->list->insert('bar', new \stdClass(), 0); + + $this->assertEquals(2, count($this->list)); + + $this->list->remove('foo'); + + $this->assertEquals(1, count($this->list)); + } + + public function testRemovingNonExistentRouteDoesNotYieldError() + { + $this->list->remove('foo'); + + $this->assertEmpty($this->list); + } + + public function testClear() + { + $this->list->insert('foo', new \stdClass(), 0); + $this->list->insert('bar', new \stdClass(), 0); + + $this->assertEquals(2, count($this->list)); + + $this->list->clear(); + + $this->assertEquals(0, count($this->list)); + $this->assertSame(false, $this->list->current()); + } + + public function testGet() + { + $route = new \stdClass(); + + $this->list->insert('foo', $route, 0); + + $this->assertEquals($route, $this->list->get('foo')); + $this->assertNull($this->list->get('bar')); + } + + public function testLIFOOnly() + { + $this->list->insert('foo', new \stdClass()); + $this->list->insert('bar', new \stdClass()); + $this->list->insert('baz', new \stdClass()); + $this->list->insert('foobar', new \stdClass()); + $this->list->insert('barbaz', new \stdClass()); + + $orders = array_keys(iterator_to_array($this->list)); + + $this->assertEquals(['barbaz', 'foobar', 'baz', 'bar', 'foo'], $orders); + } + + public function testPriorityOnly() + { + $this->list->insert('foo', new \stdClass(), 1); + $this->list->insert('bar', new \stdClass(), 0); + $this->list->insert('baz', new \stdClass(), 2); + + $orders = array_keys(iterator_to_array($this->list)); + + $this->assertEquals(['baz', 'foo', 'bar'], $orders); + } + + public function testLIFOWithPriority() + { + $this->list->insert('foo', new \stdClass(), 0); + $this->list->insert('bar', new \stdClass(), 0); + $this->list->insert('baz', new \stdClass(), 1); + + $orders = array_keys(iterator_to_array($this->list)); + + $this->assertEquals(['baz', 'bar', 'foo'], $orders); + } + + public function testFIFOWithPriority() + { + $this->list->isLIFO(false); + $this->list->insert('foo', new \stdClass(), 0); + $this->list->insert('bar', new \stdClass(), 0); + $this->list->insert('baz', new \stdClass(), 1); + + $orders = array_keys(iterator_to_array($this->list)); + + $this->assertEquals(['baz', 'foo', 'bar'], $orders); + } + + public function testFIFOOnly() + { + $this->list->isLIFO(false); + $this->list->insert('foo', new \stdClass()); + $this->list->insert('bar', new \stdClass()); + $this->list->insert('baz', new \stdClass()); + $this->list->insert('foobar', new \stdClass()); + $this->list->insert('barbaz', new \stdClass()); + + $orders = array_keys(iterator_to_array($this->list)); + + $this->assertEquals(['foo', 'bar', 'baz', 'foobar', 'barbaz'], $orders); + } + + public function testPriorityWithNegativesAndNull() + { + $this->list->insert('foo', new \stdClass(), null); + $this->list->insert('bar', new \stdClass(), 1); + $this->list->insert('baz', new \stdClass(), -1); + + $orders = array_keys(iterator_to_array($this->list)); + + $this->assertEquals(['bar', 'foo', 'baz'], $orders); + } + + public function testCurrent() + { + $this->list->insert('foo', 'foo_value', null); + $this->list->insert('bar', 'bar_value', 1); + $this->list->insert('baz', 'baz_value', -1); + + $this->assertEquals('bar', $this->list->key()); + $this->assertEquals('bar_value', $this->list->current()); + } + + public function testIterator() + { + $this->list->insert('foo', 'foo_value'); + $iterator = $this->list->getIterator(); + $this->assertEquals($iterator, $this->list); + + $this->list->insert('bar', 'bar_value'); + $this->assertNotEquals($iterator, $this->list); + } + + public function testToArray() + { + $this->list->insert('foo', 'foo_value', null); + $this->list->insert('bar', 'bar_value', 1); + $this->list->insert('baz', 'baz_value', -1); + + $this->assertEquals( + [ + 'bar' => 'bar_value', + 'foo' => 'foo_value', + 'baz' => 'baz_value' + ], + $this->list->toArray() + ); + + $this->assertEquals( + [ + 'bar' => ['data' => 'bar_value', 'priority' => 1, 'serial' => 1], + 'foo' => ['data' => 'foo_value', 'priority' => 0, 'serial' => 0], + 'baz' => ['data' => 'baz_value', 'priority' => -1, 'serial' => 2], + ], + $this->list->toArray(PriorityList::EXTR_BOTH) + ); + } + + /** + * @group 6768 + * @group 6773 + */ + public function testBooleanValuesAreValid() + { + $this->list->insert('null', null, null); + $this->list->insert('false', false, null); + $this->list->insert('string', 'test', 1); + $this->list->insert('true', true, -1); + + $orders1 = []; + $orders2 = []; + + foreach ($this->list as $key => $value) { + $orders1[$this->list->key()] = $this->list->current(); + $orders2[$key] = $value; + } + $this->assertEquals($orders1, $orders2); + $this->assertEquals( + [ + 'null' => null, + 'false' => false, + 'string' => 'test', + 'true' => true, + ], + $orders2 + ); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/PriorityQueueTest.php b/bundled-libs/zendframework/zend-stdlib/test/PriorityQueueTest.php new file mode 100644 index 00000000..4a49eb75 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/PriorityQueueTest.php @@ -0,0 +1,164 @@ +queue = new PriorityQueue(); + $this->queue->insert('foo', 3); + $this->queue->insert('bar', 4); + $this->queue->insert('baz', 2); + $this->queue->insert('bat', 1); + } + + public function testSerializationAndDeserializationShouldMaintainState() + { + $s = serialize($this->queue); + $unserialized = unserialize($s); + $count = count($this->queue); + $this->assertSame( + $count, + count($unserialized), + 'Expected count ' . $count . '; received ' . count($unserialized) + ); + + $expected = iterator_to_array($this->queue); + $test = iterator_to_array($unserialized); + $this->assertSame( + $expected, + $test, + 'Expected: ' . var_export($expected, 1) . "\nReceived:" . var_export($test, 1) + ); + } + + public function testRetrievingQueueAsArrayReturnsDataOnlyByDefault() + { + $expected = [ + 'foo', + 'bar', + 'baz', + 'bat', + ]; + $test = $this->queue->toArray(); + $this->assertSame($expected, $test, var_export($test, 1)); + } + + public function testCanCastToArrayOfPrioritiesOnly() + { + $expected = [ + 3, + 4, + 2, + 1, + ]; + $test = $this->queue->toArray(PriorityQueue::EXTR_PRIORITY); + $this->assertSame($expected, $test, var_export($test, 1)); + } + + public function testCanCastToArrayOfDataPriorityPairs() + { + $expected = [ + ['data' => 'foo', 'priority' => 3], + ['data' => 'bar', 'priority' => 4], + ['data' => 'baz', 'priority' => 2], + ['data' => 'bat', 'priority' => 1], + ]; + $test = $this->queue->toArray(PriorityQueue::EXTR_BOTH); + $this->assertSame($expected, $test, var_export($test, 1)); + } + + public function testCanIterateMultipleTimesAndReceiveSameResults() + { + $expected = ['bar', 'foo', 'baz', 'bat']; + + for ($i = 1; $i < 3; $i++) { + $test = []; + foreach ($this->queue as $item) { + $test[] = $item; + } + $this->assertEquals($expected, $test, 'Failed at iteration ' . $i); + } + } + + public function testCanRemoveItemFromQueue() + { + $this->queue->remove('baz'); + $expected = ['bar', 'foo', 'bat']; + $test = array_values(iterator_to_array($this->queue)); + $this->assertEquals($expected, $test); + } + + public function testCanTestForExistenceOfItemInQueue() + { + $this->assertTrue($this->queue->contains('foo')); + $this->assertFalse($this->queue->contains('foobar')); + } + + public function testCanTestForExistenceOfPriorityInQueue() + { + $this->assertTrue($this->queue->hasPriority(3)); + $this->assertFalse($this->queue->hasPriority(1000)); + } + + public function testCloningAlsoClonesQueue() + { + $foo = new \stdClass(); + $foo->name = 'bar'; + + $queue = new PriorityQueue(); + $queue->insert($foo, 1); + $queue->insert($foo, 2); + + $queueClone = clone $queue; + + while (! $queue->isEmpty()) { + $this->assertSame($foo, $queue->top()); + $queue->remove($queue->top()); + } + + $this->assertTrue($queue->isEmpty()); + $this->assertFalse($queueClone->isEmpty()); + $this->assertEquals(2, $queueClone->count()); + + while (! $queueClone->isEmpty()) { + $this->assertSame($foo, $queueClone->top()); + $queueClone->remove($queueClone->top()); + } + + $this->assertTrue($queueClone->isEmpty()); + } + + public function testQueueRevertsToInitialStateWhenEmpty() + { + $queue = new PriorityQueue(); + $testQueue = clone $queue; // store the default state + + $testQueue->insert('foo', 1); + $testQueue->insert('bar', 2); + + $testQueue->remove('foo'); + $testQueue->remove('bar'); + + $this->assertEquals($queue, $testQueue); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/SplPriorityQueueTest.php b/bundled-libs/zendframework/zend-stdlib/test/SplPriorityQueueTest.php new file mode 100644 index 00000000..eb3b83d2 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/SplPriorityQueueTest.php @@ -0,0 +1,73 @@ +queue = new SplPriorityQueue(); + $this->queue->insert('foo', 3); + $this->queue->insert('bar', 4); + $this->queue->insert('baz', 2); + $this->queue->insert('bat', 1); + } + + public function testMaintainsInsertOrderForDataOfEqualPriority() + { + $queue = new SplPriorityQueue(); + $queue->insert('foo', 1000); + $queue->insert('bar', 1000); + $queue->insert('baz', 1000); + $queue->insert('bat', 1000); + + $expected = ['foo', 'bar', 'baz', 'bat']; + $test = array_values(iterator_to_array($queue)); + $this->assertEquals($expected, $test); + } + + public function testSerializationAndDeserializationShouldMaintainState() + { + $s = serialize($this->queue); + $unserialized = unserialize($s); + + // assert same size + $this->assertSameSize($this->queue, $unserialized); + + // assert same values + $this->assertSame(iterator_to_array($this->queue), iterator_to_array($unserialized)); + + // assert equal + $this->assertEquals($this->queue, $unserialized); + } + + public function testCanRetrieveQueueAsArray() + { + $expected = [ + 'bar', + 'foo', + 'baz', + 'bat', + ]; + $test = $this->queue->toArray(); + $this->assertSame($expected, $test, var_export($test, 1)); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/SplQueueTest.php b/bundled-libs/zendframework/zend-stdlib/test/SplQueueTest.php new file mode 100644 index 00000000..b1022b39 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/SplQueueTest.php @@ -0,0 +1,50 @@ +queue = new SplQueue(); + $this->queue->push('foo'); + $this->queue->push('bar'); + $this->queue->push('baz'); + } + + public function testSerializationAndDeserializationShouldMaintainState() + { + $s = serialize($this->queue); + $unserialized = unserialize($s); + $count = count($this->queue); + $this->assertSame($count, count($unserialized)); + + $expected = iterator_to_array($this->queue); + $test = iterator_to_array($unserialized); + $this->assertSame($expected, $test); + } + + public function testCanRetrieveQueueAsArray() + { + $expected = ['foo', 'bar', 'baz']; + $this->assertSame($expected, $this->queue->toArray()); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/SplStackTest.php b/bundled-libs/zendframework/zend-stdlib/test/SplStackTest.php new file mode 100644 index 00000000..c9973096 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/SplStackTest.php @@ -0,0 +1,52 @@ +stack = new SplStack(); + $this->stack->push('foo'); + $this->stack->push('bar'); + $this->stack->push('baz'); + $this->stack->push('bat'); + } + + public function testSerializationAndDeserializationShouldMaintainState() + { + $s = serialize($this->stack); + $unserialized = unserialize($s); + $count = count($this->stack); + $this->assertSame($count, count($unserialized)); + + $expected = iterator_to_array($this->stack); + $test = iterator_to_array($unserialized); + $this->assertSame($expected, $test); + } + + public function testCanRetrieveQueueAsArray() + { + $expected = ['bat', 'baz', 'bar', 'foo']; + $test = $this->stack->toArray(); + $this->assertSame($expected, $test, var_export($test, 1)); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/StringUtilsTest.php b/bundled-libs/zendframework/zend-stdlib/test/StringUtilsTest.php new file mode 100644 index 00000000..c24d90a9 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/StringUtilsTest.php @@ -0,0 +1,160 @@ +assertTrue(StringUtils::isSingleByteEncoding($encoding)); + } + + public function getNonSingleByteEncodings() + { + return [ + ['UTf-8'], + ['UTf-16'], + ['usC-2'], + ['CESU-8'], + ]; + } + + /** + * @dataProvider getNonSingleByteEncodings + * @param string $encoding + */ + public function testIsSingleByteEncodingReturnsFalse($encoding) + { + $this->assertFalse(StringUtils::isSingleByteEncoding($encoding)); + } + + public function testGetWrapper() + { + $wrapper = StringUtils::getWrapper('ISO-8859-1'); + if (extension_loaded('mbstring')) { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\MbString', $wrapper); + } elseif (extension_loaded('iconv')) { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\Iconv', $wrapper); + } else { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\Native', $wrapper); + } + + try { + $wrapper = StringUtils::getWrapper('UTF-8'); + if (extension_loaded('intl')) { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\Intl', $wrapper); + } elseif (extension_loaded('mbstring')) { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\MbString', $wrapper); + } elseif (extension_loaded('iconv')) { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\Iconv', $wrapper); + } + } catch (Exception $e) { + if (extension_loaded('intl') + || extension_loaded('mbstring') + || extension_loaded('iconv') + ) { + $this->fail("Failed to get intl, mbstring or iconv wrapper for UTF-8"); + } + } + + try { + $wrapper = StringUtils::getWrapper('UTF-8', 'ISO-8859-1'); + if (extension_loaded('mbstring')) { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\MbString', $wrapper); + } elseif (extension_loaded('iconv')) { + $this->assertInstanceOf('Zend\Stdlib\StringWrapper\Iconv', $wrapper); + } + } catch (Exception $e) { + if (extension_loaded('mbstring') || extension_loaded('iconv')) { + $this->fail("Failed to get mbstring or iconv wrapper for UTF-8 and ISO-8859-1"); + } + } + } + + public function getUtf8StringValidity() + { + return [ + // valid + ['', true], + ["\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + . "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" + . ' !"#$%&\'()*+,-./0123456789:;<=>?' + . '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_' + . '`abcdefghijklmnopqrstuvwxyz{|}~', + true + ], + + // invalid + [true, false], + [123, false], + [123.45, false], + ["\xFF", false], + ["\x90a", false], + ]; + } + + /** + * @dataProvider getUtf8StringValidity + * @param string $str + * @param bool $valid + */ + public function testIsValidUtf8($str, $valid) + { + $this->assertSame($valid, StringUtils::isValidUtf8($str)); + } + + public function testHasPcreUnicodeSupport() + { + ErrorHandler::start(); + $expected = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1; + ErrorHandler::stop(); + + $this->assertSame($expected, StringUtils::hasPcreUnicodeSupport()); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/CommonStringWrapperTest.php b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/CommonStringWrapperTest.php new file mode 100644 index 00000000..41675267 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/CommonStringWrapperTest.php @@ -0,0 +1,264 @@ +getWrapper($encoding); + if (! $wrapper) { + $this->markTestSkipped("Encoding {$encoding} not supported"); + } + + $result = $wrapper->strlen($str); + $this->assertSame($expected, $result); + } + + public function substrProvider() + { + return [ + ['ascii', 'abcdefghijkl', 1, 5, 'bcdef'], + ['utf-8', 'abcdefghijkl', 1, 5, 'bcdef'], + ['utf-8', 'äöüß', 1, 2, 'öü'], + ]; + } + + /** + * @dataProvider substrProvider + * + * @param string $encoding + * @param string $str + * @param int $offset + * @param int|null $length + * @param mixed $expected + */ + public function testSubstr($encoding, $str, $offset, $length, $expected) + { + $wrapper = $this->getWrapper($encoding); + if (! $wrapper) { + $this->markTestSkipped("Encoding {$encoding} not supported"); + } + + $result = $wrapper->substr($str, $offset, $length); + $this->assertSame($expected, $result); + } + + public function strposProvider() + { + return [ + ['ascii', 'abcdefghijkl', 'g', 3, 6], + ['utf-8', 'abcdefghijkl', 'g', 3, 6], + ['utf-8', 'äöüß', 'ü', 1, 2], + ]; + } + + /** + * @dataProvider strposProvider + * + * @param string $encoding + * @param string $haystack + * @param string $needle + * @param int $offset + * @param mixed $expected + */ + public function testStrpos($encoding, $haystack, $needle, $offset, $expected) + { + $wrapper = $this->getWrapper($encoding); + if (! $wrapper) { + $this->markTestSkipped("Encoding {$encoding} not supported"); + } + + $result = $wrapper->strpos($haystack, $needle, $offset); + $this->assertSame($expected, $result); + } + + public function convertProvider() + { + return [ + ['ascii', 'ascii', 'abc', 'abc'], + ['ascii', 'utf-8', 'abc', 'abc'], + ['utf-8', 'ascii', 'abc', 'abc'], + ['utf-8', 'iso-8859-15', '€', "\xA4"], + ['utf-8', 'iso-8859-16', '€', "\xA4"], // ISO-8859-16 is wrong @ mbstring + ]; + } + + /** + * @dataProvider convertProvider + * + * @param string $str + * @param string $encoding + * @param string $convertEncoding + * @param mixed $expected + */ + public function testConvert($encoding, $convertEncoding, $str, $expected) + { + $wrapper = $this->getWrapper($encoding, $convertEncoding); + if (! $wrapper) { + $this->markTestSkipped("Encoding {$encoding} or {$convertEncoding} not supported"); + } + + $result = $wrapper->convert($str); + $this->assertSame($expected, $result); + + // backword + $result = $wrapper->convert($expected, true); + $this->assertSame($str, $result); + } + + public function wordWrapProvider() + { + // @codingStandardsIgnoreStart + return [ + // Standard cut tests + 'cut-single-line' => ['utf-8', 'äbüöcß', 2, ' ', true, 'äb üö cß'], + 'cut-multi-line' => ['utf-8', 'äbüöc ß äbüöcß', 2, ' ', true, 'äb üö c ß äb üö cß'], + 'cut-multi-line-short-words' => ['utf-8', 'Ä very long wöööööööööööörd.', 8, "\n", true, "Ä very\nlong\nwööööööö\nööööörd."], + 'cut-multi-line-with-previous-new-lines' => ['utf-8', "Ä very\nlong wöööööööööööörd.", 8, "\n", false, "Ä very\nlong\nwöööööööööööörd."], + 'long-break' => ['utf-8', "Ä very
long wöö
öööööööö
öörd.", 8, '
', false, "Ä very
long wöö
öööööööö
öörd."], + + // Alternative cut tests + 'cut-beginning-single-space' => ['utf-8', ' äüöäöü', 3, ' ', true, ' äüö äöü'], + 'cut-ending-single-space' => ['utf-8', 'äüöäöü ', 3, ' ', true, 'äüö äöü '], + 'cut-ending-single-space-with-non-space-divider' => ['utf-8', 'äöüäöü ', 3, '-', true, 'äöü-äöü-'], + 'cut-ending-two-spaces' => ['utf-8', 'äüöäöü ', 3, ' ', true, 'äüö äöü '], + 'no-cut-ending-single-space' => ['utf-8', '12345 ', 5, '-', false, '12345-'], + 'no-cut-ending-two-spaces' => ['utf-8', '12345 ', 5, '-', false, '12345- '], + 'cut-ending-three-spaces' => ['utf-8', 'äüöäöü ', 3, ' ', true, 'äüö äöü '], + 'cut-ending-two-breaks' => ['utf-8', 'äüöäöü--', 3, '-', true, 'äüö-äöü--'], + 'cut-tab' => ['utf-8', "äbü\töcß", 3, ' ', true, "äbü \töc ß"], + 'cut-new-line-with-space' => ['utf-8', "äbü\nößt", 3, ' ', true, "äbü \nöß t"], + 'cut-new-line-with-new-line' => ['utf-8', "äbü\nößte", 3, "\n", true, "äbü\nößt\ne"], + + // Break cut tests + 'cut-break-before' => ['ascii', 'foobar-foofoofoo', 8, '-', true, 'foobar-foofoofo-o'], + 'cut-break-with' => ['ascii', 'foobar-foobar', 6, '-', true, 'foobar-foobar'], + 'cut-break-within' => ['ascii', 'foobar-foobar', 7, '-', true, 'foobar-foobar'], + 'cut-break-within-end' => ['ascii', 'foobar-', 7, '-', true, 'foobar-'], + 'cut-break-after' => ['ascii', 'foobar-foobar', 5, '-', true, 'fooba-r-fooba-r'], + + // Standard no-cut tests + 'no-cut-single-line' => ['utf-8', 'äbüöcß', 2, ' ', false, 'äbüöcß'], + 'no-cut-multi-line' => ['utf-8', 'äbüöc ß äbüöcß', 2, "\n", false, "äbüöc\nß\näbüöcß"], + 'no-cut-multi-word' => ['utf-8', 'äöü äöü äöü', 5, "\n", false, "äöü\näöü\näöü"], + + // Break no-cut tests + 'no-cut-break-before' => ['ascii', 'foobar-foofoofoo', 8, '-', false, 'foobar-foofoofoo'], + 'no-cut-break-with' => ['ascii', 'foobar-foobar', 6, '-', false, 'foobar-foobar'], + 'no-cut-break-within' => ['ascii', 'foobar-foobar', 7, '-', false, 'foobar-foobar'], + 'no-cut-break-within-end' => ['ascii', 'foobar-', 7, '-', false, 'foobar-'], + 'no-cut-break-after' => ['ascii', 'foobar-foobar', 5, '-', false, 'foobar-foobar'], + ]; + // @codingStandardsIgnoreEnd + } + + /** + * @dataProvider wordWrapProvider + * + * @param string $encoding + * @param string $string + * @param int $width + * @param string $break + * @param bool $cut + * @param mixed $expected + */ + public function testWordWrap($encoding, $string, $width, $break, $cut, $expected) + { + $wrapper = $this->getWrapper($encoding); + if (! $wrapper) { + $this->markTestSkipped("Encoding {$encoding} not supported"); + } + + $result = $wrapper->wordWrap($string, $width, $break, $cut); + $this->assertSame($expected, $result); + } + + public function testWordWrapInvalidArgument() + { + $wrapper = $this->getWrapper(); + if (! $wrapper) { + $this->fail("Can't instantiate wrapper"); + } + $this->expectException(Exception\InvalidArgumentException::class); + $this->expectExceptionMessage( + "Cannot force cut when width is zero" + ); + $wrapper->wordWrap('a', 0, "\n", true); + } + + public function strPadProvider() + { + return [ + // single-byte + 'left-padding_single-byte' => ['ascii', 'aaa', 5, 'o', STR_PAD_LEFT, 'ooaaa'], + 'center-padding_single-byte' => ['ascii', 'aaa', 6, 'o', STR_PAD_BOTH, 'oaaaoo'], + 'right-padding_single-byte' => ['ascii', 'aaa', 5, 'o', STR_PAD_RIGHT, 'aaaoo'], + + // multi-byte + 'left-padding_multi-byte' => ['utf-8', 'äää', 5, 'ö', STR_PAD_LEFT, 'ööäää'], + 'center-padding_multi-byte' => ['utf-8', 'äää', 6, 'ö', STR_PAD_BOTH, 'öäääöö'], + 'right-padding_multi-byte' => ['utf-8', 'äää', 5, 'ö', STR_PAD_RIGHT, 'äääöö'], + + // ZF-12186 + 'input-longer-than-pad-length' => ['utf-8', 'äääöö', 2, 'ö', STR_PAD_RIGHT, 'äääöö'], + 'input-same-as-pad-length' => ['utf-8', 'äääöö', 5, 'ö', STR_PAD_RIGHT, 'äääöö'], + 'negative-pad-length' => ['utf-8', 'äääöö', -2, 'ö', STR_PAD_RIGHT, 'äääöö'], + ]; + } + + /** + * @dataProvider strPadProvider + * + * @param string $encoding + * @param string $input + * @param int $padLength + * @param string $padString + * @param int $padType + * @param mixed $expected + * + * @group ZF-12186 + */ + public function testStrPad($encoding, $input, $padLength, $padString, $padType, $expected) + { + $wrapper = $this->getWrapper($encoding); + if (! $wrapper) { + $this->markTestSkipped("Encoding {$encoding} not supported"); + } + + $result = $wrapper->strPad($input, $padLength, $padString, $padType); + $this->assertSame($expected, $result); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IconvTest.php b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IconvTest.php new file mode 100644 index 00000000..8138a02a --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IconvTest.php @@ -0,0 +1,46 @@ +fail('Missing expected Zend\Stdlib\Exception\ExtensionNotLoadedException'); + } catch (Exception\ExtensionNotLoadedException $e) { + $this->markTestSkipped('Missing ext/iconv'); + } + } + + parent::setUp(); + } + + protected function getWrapper($encoding = null, $convertEncoding = null) + { + if ($encoding === null) { + $supportedEncodings = Iconv::getSupportedEncodings(); + $encoding = array_shift($supportedEncodings); + } + + if (! Iconv::isSupported($encoding, $convertEncoding)) { + return false; + } + + $wrapper = new Iconv(); + $wrapper->setEncoding($encoding, $convertEncoding); + return $wrapper; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IntlTest.php b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IntlTest.php new file mode 100644 index 00000000..6bd6b577 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/IntlTest.php @@ -0,0 +1,46 @@ +fail('Missing expected Zend\Stdlib\Exception\ExtensionNotLoadedException'); + } catch (Exception\ExtensionNotLoadedException $e) { + $this->markTestSkipped('Missing ext/intl'); + } + } + + parent::setUp(); + } + + protected function getWrapper($encoding = null, $convertEncoding = null) + { + if ($encoding === null) { + $supportedEncodings = Intl::getSupportedEncodings(); + $encoding = array_shift($supportedEncodings); + } + + if (! Intl::isSupported($encoding, $convertEncoding)) { + return false; + } + + $wrapper = new Intl(); + $wrapper->setEncoding($encoding, $convertEncoding); + return $wrapper; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/MbStringTest.php b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/MbStringTest.php new file mode 100644 index 00000000..4b69b57c --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/MbStringTest.php @@ -0,0 +1,46 @@ +fail('Missing expected Zend\Stdlib\Exception\ExtensionNotLoadedException'); + } catch (Exception\ExtensionNotLoadedException $e) { + $this->markTestSkipped('Missing ext/mbstring'); + } + } + + parent::setUp(); + } + + protected function getWrapper($encoding = null, $convertEncoding = null) + { + if ($encoding === null) { + $supportedEncodings = MbString::getSupportedEncodings(); + $encoding = array_shift($supportedEncodings); + } + + if (! MbString::isSupported($encoding, $convertEncoding)) { + return false; + } + + $wrapper = new MbString(); + $wrapper->setEncoding($encoding, $convertEncoding); + return $wrapper; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/NativeTest.php b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/NativeTest.php new file mode 100644 index 00000000..d74090de --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/StringWrapper/NativeTest.php @@ -0,0 +1,31 @@ +setEncoding($encoding, $convertEncoding); + return $wrapper; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectIterator.php b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectIterator.php new file mode 100644 index 00000000..6c5bf886 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectIterator.php @@ -0,0 +1,51 @@ +var = $array; + } + } + + public function rewind() + { + reset($this->var); + } + + public function current() + { + return current($this->var); + } + + public function key() + { + return key($this->var); + } + + public function next() + { + return next($this->var); + } + + public function valid() + { + $key = key($this->var); + $var = ($key !== null && $key !== false); + + return $var; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectObjectCount.php b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectObjectCount.php new file mode 100644 index 00000000..fef278f6 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/ArrayObjectObjectCount.php @@ -0,0 +1,18 @@ +data = [ + "foo" => "bar", + "bar" => "foo", + "blubb" => "baz", + "quo" => "blubb" + ]; + } + + /** + * Exchange internal values from provided array + * + * @param array $array + * @return void + */ + public function exchangeArray(array $array) + { + $this->data = $array; + } + + /** + * Return an array representation of the object + * + * @return array + */ + public function getArrayCopy() + { + return $this->data; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/TestAsset/GuardedObject.php b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/GuardedObject.php new file mode 100644 index 00000000..f2735835 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/GuardedObject.php @@ -0,0 +1,32 @@ +guardForArrayOrTraversable($value); + } + + public function setNotEmpty($value) + { + $this->guardAgainstEmpty($value); + } + + public function setNotNull($value) + { + $this->guardAgainstNull($value); + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptions.php b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptions.php new file mode 100644 index 00000000..723586fd --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptions.php @@ -0,0 +1,86 @@ +testField = $value; + } + + public function getTestField() + { + return $this->testField; + } + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + private function setParentPrivate($parentPrivate) + { + $this->parentPrivate = $parentPrivate; + } + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + private function getParentPrivate() + { + return $this->parentPrivate; + } + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + protected function setParentProtected($parentProtected) + { + $this->parentProtected = $parentProtected; + } + + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + protected function getParentProtected() + { + return $this->parentProtected; + } + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + public function setParentPublic($parentPublic) + { + $this->parentPublic = $parentPublic; + } + + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + public function getParentPublic() + { + return $this->parentPublic; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsDerived.php b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsDerived.php new file mode 100644 index 00000000..07d3e385 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsDerived.php @@ -0,0 +1,72 @@ +derivedPrivate = $derivedPrivate; + } + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + private function getDerivedPrivate() + { + return $this->derivedPrivate; + } + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + protected function setDerivedProtected($derivedProtected) + { + $this->derivedProtected = $derivedProtected; + } + + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + protected function getDerivedProtected() + { + return $this->derivedProtected; + } + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + public function setDerivedPublic($derivedPublic) + { + $this->derivedPublic = $derivedPublic; + } + + + /** + * Needed to test accessibility of getters / setters within deriving classes + */ + public function getDerivedPublic() + { + return $this->derivedPublic; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsNoStrict.php b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsNoStrict.php new file mode 100644 index 00000000..546fce80 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsNoStrict.php @@ -0,0 +1,34 @@ +testField = $value; + } + + public function getTestField() + { + return $this->testField; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsWithoutGetter.php b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsWithoutGetter.php new file mode 100644 index 00000000..e766e802 --- /dev/null +++ b/bundled-libs/zendframework/zend-stdlib/test/TestAsset/TestOptionsWithoutGetter.php @@ -0,0 +1,25 @@ +foo = $value; + } +} diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/alpha b/bundled-libs/zendframework/zend-stdlib/test/_files/alpha new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/beta b/bundled-libs/zendframework/zend-stdlib/test/_files/beta new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/delta b/bundled-libs/zendframework/zend-stdlib/test/_files/delta new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/eta.alpha b/bundled-libs/zendframework/zend-stdlib/test/_files/eta.alpha new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/eta.beta b/bundled-libs/zendframework/zend-stdlib/test/_files/eta.beta new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/gamma b/bundled-libs/zendframework/zend-stdlib/test/_files/gamma new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/zeta.alpha b/bundled-libs/zendframework/zend-stdlib/test/_files/zeta.alpha new file mode 100644 index 00000000..e69de29b diff --git a/bundled-libs/zendframework/zend-stdlib/test/_files/zeta.beta b/bundled-libs/zendframework/zend-stdlib/test/_files/zeta.beta new file mode 100644 index 00000000..e69de29b diff --git a/composer.json b/composer.json index bf91c7d2..d928362e 100644 --- a/composer.json +++ b/composer.json @@ -6,12 +6,25 @@ } ], "require": { - "php": ">=5.3.3", + "php": "~7.0", "zendframework/zend-db": "2.*", "katzgrau/klogger": "1.0.*", - "voku/simple-cache": "^3.2" + "voku/simple-cache": "4.*" }, + "minimum-stability": "dev", + "prefer-stable": true, "config": { + "apcu-autoloader": true, + "optimize-autoloader": true, + "github-protocols": [ + "git", + "https", + "http" + ], + "platform": { + "php": "7.0.99" + }, + "sort-packages": true, "vendor-dir": "bundled-libs" } }