From ae30d570745427b7ad7ac03f04002160dd891030 Mon Sep 17 00:00:00 2001 From: Stephen Cuppett Date: Wed, 2 Apr 2014 18:42:43 -0700 Subject: [PATCH] Implement CallbackFilterIterator This implements CallbackFilterIterator. It also makes the basic tests pass. Moved the test from zend/bad to zend/good. The 002 tests in the folder diff because of the output messages from the compiler versus PHP's. However, they appear to be giving the right failures. Wasn't sure whether the group ignores those, patches up the expect file, corrects the messages from the compiler, etc. Closes #2244 Closes #1715 Reviewed By: @fredemmott Differential Revision: D1249528 Pulled By: @ptarjan --- hphp/runtime/ext/ext_pdo.cpp | 5 +++ hphp/runtime/ext/ext_pdo.h | 1 + hphp/system/idl/pdo.idl.json | 12 +++++++ hphp/system/php.txt | 1 + .../php/spl/iterators/CallbackFilterIterator.php | 38 ++++++++++++++++++++++ .../ext/spl/tests/CallbackFilterIteratorTest.php | 0 .../tests/CallbackFilterIteratorTest.php.expectf | 0 7 files changed, 57 insertions(+) create mode 100644 hphp/system/php/spl/iterators/CallbackFilterIterator.php rename hphp/test/zend/{bad => good}/ext/spl/tests/CallbackFilterIteratorTest.php (100%) rename hphp/test/zend/{bad => good}/ext/spl/tests/CallbackFilterIteratorTest.php.expectf (100%) diff --git a/hphp/runtime/ext/ext_pdo.cpp b/hphp/runtime/ext/ext_pdo.cpp index 337703ba3a8..7c260d6fb4c 100644 --- a/hphp/runtime/ext/ext_pdo.cpp +++ b/hphp/runtime/ext/ext_pdo.cpp @@ -1137,6 +1137,11 @@ bool c_PDO::t_commit() { return false; } +bool c_PDO::t_intransaction() { + assert(m_dbh->driver); + return m_dbh->in_txn; +} + bool c_PDO::t_rollback() { assert(m_dbh->driver); if (!m_dbh->in_txn) { diff --git a/hphp/runtime/ext/ext_pdo.h b/hphp/runtime/ext/ext_pdo.h index e70819c1097..170e1a1f7ad 100644 --- a/hphp/runtime/ext/ext_pdo.h +++ b/hphp/runtime/ext/ext_pdo.h @@ -127,6 +127,7 @@ class c_PDO : public ExtObjectData { const Array& options = null_array); public: bool t_begintransaction(); public: bool t_commit(); + public: bool t_intransaction(); public: bool t_rollback(); public: bool t_setattribute(int64_t attribute, const Variant& value); public: Variant t_getattribute(int64_t attribute); diff --git a/hphp/system/idl/pdo.idl.json b/hphp/system/idl/pdo.idl.json index 9af6cf84baf..b125565bd42 100644 --- a/hphp/system/idl/pdo.idl.json +++ b/hphp/system/idl/pdo.idl.json @@ -103,6 +103,18 @@ ] }, { + "name": "inTransaction", + "desc": "Checks if a transaction is currently active within the driver. This method only works for database drivers that support transactions.", + "flags": [ + ], + "return": { + "type": "Boolean", + "desc": "Returns TRUE if a transaction is currently active, and FALSE if not." + }, + "args": [ + ] + }, + { "name": "rollBack", "desc": "Rolls back the current transaction, as initiated by PDO::beginTransaction(). It is an error to call this method if no transaction is active.\n\nIf the database was set to autocommit mode, this function will restore autocommit mode after it has rolled back the transaction.\n\nSome databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary.", "flags": [ diff --git a/hphp/system/php.txt b/hphp/system/php.txt index 935aeda0302..24c9db6e62c 100644 --- a/hphp/system/php.txt +++ b/hphp/system/php.txt @@ -37,6 +37,7 @@ hphp/system/php/spl/interfaces/OuterIterator.php hphp/system/php/spl/iterators/IteratorIterator.php hphp/system/php/spl/iterators/AppendIterator.php hphp/system/php/spl/iterators/FilterIterator.php +hphp/system/php/spl/iterators/CallbackFilterIterator.php hphp/system/php/spl/iterators/RecursiveFilterIterator.php hphp/system/php/spl/iterators/RegexIterator.php hphp/system/php/spl/iterators/RecursiveRegexIterator.php diff --git a/hphp/system/php/spl/iterators/CallbackFilterIterator.php b/hphp/system/php/spl/iterators/CallbackFilterIterator.php new file mode 100644 index 00000000000..2a794a6933b --- /dev/null +++ b/hphp/system/php/spl/iterators/CallbackFilterIterator.php @@ -0,0 +1,38 @@ +callback = $callback; + } + + /** + * Calls the callback with the current value, the current key and the inner + * iterator as arguments + * + * @return bool The callback is expected to return TRUE if the current item + * is to be accepted, or FALSE otherwise. + */ + public function accept() { + return call_user_func( + $this->callback, + $this->current(), + $this->key(), + $this->getInnerIterator() + ); + } + +} diff --git a/hphp/test/zend/bad/ext/spl/tests/CallbackFilterIteratorTest.php b/hphp/test/zend/good/ext/spl/tests/CallbackFilterIteratorTest.php similarity index 100% rename from hphp/test/zend/bad/ext/spl/tests/CallbackFilterIteratorTest.php rename to hphp/test/zend/good/ext/spl/tests/CallbackFilterIteratorTest.php diff --git a/hphp/test/zend/bad/ext/spl/tests/CallbackFilterIteratorTest.php.expectf b/hphp/test/zend/good/ext/spl/tests/CallbackFilterIteratorTest.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext/spl/tests/CallbackFilterIteratorTest.php.expectf rename to hphp/test/zend/good/ext/spl/tests/CallbackFilterIteratorTest.php.expectf -- 2.11.4.GIT