diff --git a/.gitignore b/.gitignore index e3c12a73e..129462521 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,41 @@ +.deps +*.lo +*.la +.libs +*/.* +acinclude.m4 +aclocal.m4 +autom4te.cache +build +config.guess +config.h +config.h.in +config.log +config.nice +config.status +config.sub +configure +configure.in +include +install-sh +libtool +ltmain.sh +Makefile +Makefile.fragments +Makefile.global +Makefile.objects +missing +mkinstalldirs +modules +run-tests.php +tests/*/*.diff +tests/*/*.out +tests/*/*.php +tests/*/*.exp +tests/*/*.log +tests/*/*.sh +php.ini +*.patch +*.php *.swp .* diff --git a/config.m4 b/config.m4 new file mode 100644 index 000000000..41a571479 --- /dev/null +++ b/config.m4 @@ -0,0 +1,165 @@ +dnl config.m4 for extension phongo + +PHP_ARG_ENABLE(phongo, whether to enable phongo support, +[ --enable-phongo Enable phongo support]) + +PHP_ARG_WITH(libmongoc-dir, for libmongoc, +[ --with-libmongoc-dir[=DIR] Set the path to libmongoc install prefix.], yes) + + + +if test "$PHONGO" != "no"; then + AC_MSG_CHECKING(for libmongoc support) + + LIBMONGOC_DIR="" + dnl Uses the last one found, so stick the PHP_LIBMONGOC_DIR last + for i in /usr /usr/local $PHP_LIBMONGOC_DIR ; do + if test -r $i/include/libmongoc-1.0/mongoc.h; then + LIBMONGOC_DIR=$i + fi + done + + if test -r "$LIBMONGOC_DIR"; then + LIBMONGOC_INCLUDE="-I$PHP_LIBMONGOC_DIR/include/libmongoc-1.0 -I$PHP_LIBMONGOC_DIR/include/libbson-1.0" + LIBMONGOC_LFLAGS="-L$PHP_LIBMONGOC_DIR/$PHP_LIBDIR" + LIBMONGOC_LIBS="-lmongoc-1.0 -lbson-1.0" + AC_MSG_RESULT(found $LIBMONGOC_DIR) + else + AC_MSG_RESULT([not found]) + AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + + export ORIG_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" + if test -x "$PKG_CONFIG"; then + AC_MSG_CHECKING(for libmongoc using pkg-config) + + export PKG_CONFIG_PATH="$ORIG_PKG_CONFIG_PATH:/usr/local/$PHP_LIBDIR/pkgconfig:/usr/$PHP_LIBDIR/pkgconfig:/opt/$PHP_LIBDIR/pkgconfig:$PHP_LIBMONGOC_DIR" + if ! $PKG_CONFIG --exists libmongoc-1.0; then + export PKG_CONFIG_PATH="$ORIG_PKG_CONFIG_PATH" + AC_MSG_ERROR([Can't find where libmongoc is installed]) + fi + + LIBMONGOC_INCLUDE=`$PKG_CONFIG --cflags-only-I libmongoc-1.0` + LIBMONGOC_LFLAGS=`$PKG_CONFIG --libs-only-L libmongoc-1.0` + LIBMONGOC_LIBS=`$PKG_CONFIG --libs-only-l libmongoc-1.0` + PHP_LIMONGOC_DIR=`$PKG_CONFIG --variable=prefix libmongoc-1.0` + export PKG_CONFIG_PATH="$ORIG_PKG_CONFIG_PATH" + + AC_MSG_RESULT([found using pkg-config]) + else + AC_MSG_ERROR([Can't find where libmongoc is installed]) + fi + fi + + PHP_ADD_INCLUDE($LIBMONGOC_DIR/include/libmongoc-1.0) + PHP_ADD_INCLUDE($LIBMONGOC_DIR/include/libbson-1.0) + + PHP_ADD_LIBRARY_WITH_PATH(mongoc-1.0, $LIBMONGOC_DIR/$PHP_LIBDIR, PHONGO_SHARED_LIBADD) + PHP_SUBST(PHONGO_SHARED_LIBADD) + AC_DEFINE(HAVE_MONGOC, 1, [Kinda useless extension without it..]) + + + + PHP_ARG_ENABLE(developer-flags, whether to enable developer build flags, + [ --enable-developer-flags Enable developer flags],, no) + + if test "$PHP_DEVELOPER_FLAGS" = "yes"; then + dnl Warn about functions which might be candidates for format attributes + PHP_CHECK_GCC_ARG(-Wmissing-format-attribute, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wmissing-format-attribute") + dnl Avoid duplicating values for an enum + PHP_CHECK_GCC_ARG(-Wduplicate-enum, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wduplicate-enum") + dnl Warns on mismatches between #ifndef and #define header guards + PHP_CHECK_GCC_ARG(-Wheader-guard, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wheader-guard") + dnl logical not of a non-boolean expression + PHP_CHECK_GCC_ARG(-Wlogical-not-parentheses, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wlogical-not-parentheses") + dnl Warn about suspicious uses of logical operators in expressions + PHP_CHECK_GCC_ARG(-Wlogical-op, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wlogical-op") + dnl memory error detector. + dnl FIXME: -fsanitize=address,undefined for clang. The PHP_CHECK_GCC_ARG macro isn't happy about that string :( + PHP_CHECK_GCC_ARG(-fsanitize-address, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -fsanitize-address") + dnl Enable frame debugging + PHP_CHECK_GCC_ARG(-fno-omit-frame-pointer, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -fno-omit-frame-pointer") + dnl Make sure we don't optimize calls + PHP_CHECK_GCC_ARG(-fno-optimize-sibling-calls, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -fno-optimize-sibling-calls") + PHP_CHECK_GCC_ARG(-Wlogical-op-parentheses, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wlogical-op-parentheses") + PHP_CHECK_GCC_ARG(-Wno-gnu, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wno-gnu") + PHP_CHECK_GCC_ARG(-Wbool-conversion, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wbool-conversion") + PHP_CHECK_GCC_ARG(-Wloop-analysis, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wloop-analysis") + PHP_CHECK_GCC_ARG(-Wsizeof-array-argument, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wsizeof-array-argument") + PHP_CHECK_GCC_ARG(-Wstring-conversion, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wstring-conversion") + PHP_CHECK_GCC_ARG(-Wno-variadic-macros, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wno-variadic-macros") + PHP_CHECK_GCC_ARG(-Wno-sign-compare, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wno-sign-compare") + PHP_CHECK_GCC_ARG(-fstack-protector, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -fstack-protector") + PHP_CHECK_GCC_ARG(-fno-exceptions, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -fno-exceptions") + PHP_CHECK_GCC_ARG(-Wformat-security, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wformat-security") + PHP_CHECK_GCC_ARG(-Wformat-nonliteral, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wformat-nonliteral") + PHP_CHECK_GCC_ARG(-Winit-self, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Winit-self") + PHP_CHECK_GCC_ARG(-Wwrite-strings, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wwrite-strings") + PHP_CHECK_GCC_ARG(-Wenum-compare, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wenum-compare") + PHP_CHECK_GCC_ARG(-Wempty-body, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wempty-body") + PHP_CHECK_GCC_ARG(-Wparentheses, _EXTRA_CFLAGS="$_EXTRA_CFLAGS -Wparentheses") + + + EXTRA_CFLAGS="-g -O0 -Wall -Wextra -Werror $_EXTRA_CFLAGS " + dnl EXTRA_LDFLAGS="-Wl,--no-undefined" + fi + + + PHP_ARG_ENABLE(coverage, whether to enable code coverage, + [ --enable-coverage Enable developer code coverage information],, no) + + if test "$PHP_COVERAGE" = "yes"; then + PHP_CHECK_GCC_ARG(-fprofile-arcs, _EXTRA_FLAGS="$_EXTRA_FLAGS -fprofile-arcs") + PHP_CHECK_GCC_ARG(-ftest-coverage, _EXTRA_FLAGS="$_EXTRA_FLAGS -ftest-coverage") + EXTRA_CFLAGS="$EXTRA_CFLAGS $_EXTRA_FLAGS " + EXTRA_LDFLAGS="$_EXTRA_FLAGS" + fi + + + PHP_SUBST(EXTRA_LDFLAGS) + + PHONGO_BSON="\ + src/bson.c \ + "; + PHONGO_ROOT="\ + php_phongo.c \ + "; + PHONGO_INTERFACES="\ + src/Cursor.c \ + src/WriteBatch.c \ + src/WriteResult.c \ + "; + PHONGO_CLASSES="\ + src/Command.c \ + src/CommandCursor.c \ + src/CommandResult.c \ + src/CursorId.c \ + src/DeleteBatch.c \ + src/DeleteResult.c \ + src/GeneratedId.c \ + src/InsertBatch.c \ + src/InsertResult.c \ + src/Manager.c \ + src/Query.c \ + src/QueryCursor.c \ + src/ReadPreference.c \ + src/Server.c \ + src/UpdateBatch.c \ + src/UpdateResult.c \ + src/WriteConcernError.c \ + src/WriteError.c \ + "; + + dnl PHP_ADD_SOURCES_X($builddir, $PHONGO_BSON, $EXTRA_CFLAGS, shared_objects_phongo, yes) + PHP_ADD_SOURCES_X($builddir, $PHONGO_INTERFACES, $EXTRA_CFLAGS, shared_objects_phongo, yes) + PHP_ADD_SOURCES_X($builddir, $PHONGO_CLASSES, $EXTRA_CFLAGS, shared_objects_phongo, yes) + PHP_NEW_EXTENSION(phongo, $PHONGO_ROOT, $ext_shared,, $EXTRA_CFLAGS) + + + dnl This must come after PHP_NEW_EXTENSION, otherwise the srcdir won't be set + if test "$PHP_COVERAGE" = "yes"; then + PHP_ADD_MAKEFILE_FRAGMENT + fi + +fi + +dnl: vim: et sw=2 diff --git a/docs/api/MongoDB/Command/CommandCursor.php b/docs/api/MongoDB/Command/CommandCursor.php index 2ef540d15..acdda3e97 100644 --- a/docs/api/MongoDB/Command/CommandCursor.php +++ b/docs/api/MongoDB/Command/CommandCursor.php @@ -48,7 +48,7 @@ public function getId() } /** - * Returns the Server Object that this cursor is attached to + * Returns the Server object that this cursor is attached to * * @return Server Server from which the cursor originated */ @@ -68,7 +68,7 @@ public function isDead() } /** - * Sets a batchsize for the cursor + * Sets a batch size for the cursor * * @param integer $batchSize * @return boolean true on success, false on failure diff --git a/docs/api/MongoDB/Command/CommandResult.php b/docs/api/MongoDB/Command/CommandResult.php index 9c74d3f79..0cde7e8e8 100644 --- a/docs/api/MongoDB/Command/CommandResult.php +++ b/docs/api/MongoDB/Command/CommandResult.php @@ -35,7 +35,7 @@ public function getResponseDocument() } /** - * Returns the Server Object that this cursor is attached to + * Returns the Server object that this cursor is attached to * * @return Server Server from which the result originated */ diff --git a/docs/api/MongoDB/Cursor.php b/docs/api/MongoDB/Cursor.php index 3b5424e8c..b0db7f0f0 100644 --- a/docs/api/MongoDB/Cursor.php +++ b/docs/api/MongoDB/Cursor.php @@ -12,7 +12,7 @@ interface Cursor extends \Iterator function getId(); /** - * Returns the Server Object that this cursor is attached to + * Returns the Server object that this cursor is attached to * * @return Server Server from which the cursor originated */ diff --git a/docs/api/MongoDB/Query/QueryCursor.php b/docs/api/MongoDB/Query/QueryCursor.php index 3b98cd871..4217f2028 100644 --- a/docs/api/MongoDB/Query/QueryCursor.php +++ b/docs/api/MongoDB/Query/QueryCursor.php @@ -44,7 +44,7 @@ public function getId() } /** - * Returns the Server Object that this cursor is attached to + * Returns the Server object that this cursor is attached to * * @return Server Server from which the cursor originated */ @@ -64,7 +64,7 @@ public function isDead() } /** - * Sets a batchsize for the cursor + * Sets a batch size for the cursor * * @param integer $batchSize * @return boolean true on success, false on failure diff --git a/php_compat_53.h b/php_compat_53.h new file mode 100644 index 000000000..ecb076515 --- /dev/null +++ b/php_compat_53.h @@ -0,0 +1,7 @@ +#ifndef PHP_FE_END +# define PHP_FE_END { NULL, NULL, NULL } +#endif + +#ifndef HASH_KEY_NON_EXISTENT +# define HASH_KEY_NON_EXISTENT HASH_KEY_NON_EXISTANT +#endif diff --git a/php_phongo.c b/php_phongo.c new file mode 100644 index 000000000..83d6cf28c --- /dev/null +++ b/php_phongo.c @@ -0,0 +1,232 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include "Zend/zend_interfaces.h" +#include "ext/spl/spl_iterators.h" +#include "ext/spl/spl_exceptions.h" +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +zend_class_entry* phongo_exception_from_phongo_domain(php_phongo_error_domain_t domain) +{ + switch (domain) { + case PHONGO_INVALID_ARGUMENT: + return spl_ce_InvalidArgumentException; + } +} +zend_class_entry* phongo_exception_from_mongoc_domain(mongoc_error_domain_t domain) +{ + switch (domain) { + case MONGOC_ERROR_STREAM: + /* FIXME: We don't have the Exceptions mocked yet.. */ +#if 0 + return phongo_ce_mongo_connection_exception; +#endif + default: + return spl_ce_RuntimeException; + } +} + +/* {{{ M[INIT|SHUTDOWN] R[INIT|SHUTDOWN] G[INIT|SHUTDOWN] MINFO INI */ + +ZEND_DECLARE_MODULE_GLOBALS(phongo) +/* {{{ INI entries */ +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY((char *)"phongo.be_awesome", (char *)"yes", PHP_INI_ALL, OnUpdateString, be_awesome, zend_phongo_globals, phongo_globals) +PHP_INI_END() +/* }}} */ + +/* {{{ PHP_GINIT_FUNCTION */ +PHP_GINIT_FUNCTION(phongo) +{ + phongo_globals->be_awesome = NULL; +} +/* }}} */ + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(phongo) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + + REGISTER_INI_ENTRIES(); + + /* Initialize libmongoc */ + mongoc_init(); + + /* Prep default object handlers to be used when we register the classes */ + /* + memcpy(&phongo_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + phongo_object_handlers.clone_obj = NULL; + phongo_object_handlers.read_property = NULL; + phongo_object_handlers.write_property = NULL; + phongo_object_handlers.get_debug_info = NULL; + */ + + PHP_MINIT(bson)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(CursorId)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(GeneratedId)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(Cursor)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(CommandCursor)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(QueryCursor)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(WriteResult)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(DeleteResult)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(InsertResult)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(UpdateResult)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(CommandResult)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(WriteBatch)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(DeleteBatch)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(InsertBatch)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(UpdateBatch)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(Manager)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(Server)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(Command)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(Query)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(ReadPreference)(INIT_FUNC_ARGS_PASSTHRU); + + PHP_MINIT(WriteConcernError)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(WriteError)(INIT_FUNC_ARGS_PASSTHRU); + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_RINIT_FUNCTION */ +PHP_RINIT_FUNCTION(phongo) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + (void)module_number; /* Really doesn't matter which module number we are */ + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_RSHUTDOWN_FUNCTION */ +PHP_RSHUTDOWN_FUNCTION(phongo) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + (void)module_number; /* Really doesn't matter which module number we are */ + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MSHUTDOWN_FUNCTION */ +PHP_MSHUTDOWN_FUNCTION(phongo) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + + /* Cleanup after libmongoc */ + mongoc_cleanup(); + + UNREGISTER_INI_ENTRIES(); + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_GSHUTDOWN_FUNCTION */ +PHP_GSHUTDOWN_FUNCTION(phongo) +{ + phongo_globals->be_awesome = NULL; +} +/* }}} */ + +/* {{{ PHP_MINFO_FUNCTION */ +PHP_MINFO_FUNCTION(phongo) +{ + php_info_print_table_start(); + php_info_print_table_header(2, "phongo support", "enabled"); + php_info_print_table_row(2, "phongo", PHONGO_VERSION_S); + php_info_print_table_row(2, "libmongoc", MONGOC_VERSION_S); + php_info_print_table_row(2, "libbson", BSON_VERSION_S); + php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); +} +/* }}} */ +/* }}} */ + +/* {{{ phongo_functions[] +*/ +const zend_function_entry phongo_functions[] = { + PHP_FE(bson_encode, NULL) + PHP_FE(bson_decode, NULL) + PHP_FE(bson_to_json, NULL) + PHP_FE_END +}; +/* }}} */ +/* {{{ phongo_module_entry + */ +zend_module_entry phongo_module_entry = { + STANDARD_MODULE_HEADER, + "phongo", + phongo_functions, + PHP_MINIT(phongo), + PHP_MSHUTDOWN(phongo), + PHP_RINIT(phongo), + PHP_RSHUTDOWN(phongo), + PHP_MINFO(phongo), + PHONGO_VERSION, + PHP_MODULE_GLOBALS(phongo), + PHP_GINIT(phongo), + PHP_GSHUTDOWN(phongo), + NULL, + STANDARD_MODULE_PROPERTIES_EX +}; +/* }}} */ + +#ifdef COMPILE_DL_PHONGO +ZEND_GET_MODULE(phongo) +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/php_phongo.h b/php_phongo.h new file mode 100644 index 000000000..87220119d --- /dev/null +++ b/php_phongo.h @@ -0,0 +1,183 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2014 Hannes Magnusson | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Hannes Magnusson | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHONGO_H +#define PHONGO_H + +/* External libs */ +#include +#include + +extern zend_module_entry phongo_module_entry; + +#define PHONGO_VERSION_S "3.0.0" +#define PHONGO_VERSION PHONGO_VERSION_S + +#ifdef PHP_WIN32 +# define PHONGO_API __declspec(dllexport) +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define PHONGO_API __attribute__ ((visibility("default"))) +#else +# define PHONGO_API +#endif + +#ifdef ZTS +# include "TSRM.h" +#endif + +ZEND_BEGIN_MODULE_GLOBALS(phongo) + char *be_awesome; +ZEND_END_MODULE_GLOBALS(phongo) + +#ifdef ZTS +# define PHONGO_G(v) TSRMG(phongo_globals_id, zend_phongo_globals *, v) +#else +# define PHONGO_G(v) (phongo_globals.v) +#endif + +typedef struct { + zend_object std; +} php_phongo_command_t; +typedef struct { + zend_object std; +} php_phongo_commandcursor_t; +typedef struct { + zend_object std; +} php_phongo_commandresult_t; +typedef struct { + zend_object std; +} php_phongo_cursor_t; +typedef struct { + zend_object std; +} php_phongo_cursorid_t; +typedef struct { + zend_object std; +} php_phongo_deletebatch_t; +typedef struct { + zend_object std; +} php_phongo_deleteresult_t; +typedef struct { + zend_object std; +} php_phongo_generatedid_t; +typedef struct { + zend_object std; +} php_phongo_insertbatch_t; +typedef struct { + zend_object std; +} php_phongo_insertresult_t; +typedef struct { + zend_object std; +} php_phongo_manager_t; +typedef struct { + zend_object std; +} php_phongo_query_t; +typedef struct { + zend_object std; +} php_phongo_querycursor_t; +typedef struct { + zend_object std; +} php_phongo_readpreference_t; +typedef struct { + zend_object std; +} php_phongo_server_t; +typedef struct { + zend_object std; +} php_phongo_updatebatch_t; +typedef struct { + zend_object std; +} php_phongo_updateresult_t; +typedef struct { + zend_object std; +} php_phongo_writebatch_t; +typedef struct { + zend_object std; +} php_phongo_writeconcernerror_t; +typedef struct { + zend_object std; +} php_phongo_writeerror_t; +typedef struct { + zend_object std; +} php_phongo_writeresult_t; + +extern PHPAPI zend_class_entry *php_phongo_command_ce; +extern PHPAPI zend_class_entry *php_phongo_commandcursor_ce; +extern PHPAPI zend_class_entry *php_phongo_commandresult_ce; +extern PHPAPI zend_class_entry *php_phongo_cursor_ce; +extern PHPAPI zend_class_entry *php_phongo_cursorid_ce; +extern PHPAPI zend_class_entry *php_phongo_deletebatch_ce; +extern PHPAPI zend_class_entry *php_phongo_deleteresult_ce; +extern PHPAPI zend_class_entry *php_phongo_generatedid_ce; +extern PHPAPI zend_class_entry *php_phongo_insertbatch_ce; +extern PHPAPI zend_class_entry *php_phongo_insertresult_ce; +extern PHPAPI zend_class_entry *php_phongo_manager_ce; +extern PHPAPI zend_class_entry *php_phongo_query_ce; +extern PHPAPI zend_class_entry *php_phongo_querycursor_ce; +extern PHPAPI zend_class_entry *php_phongo_readpreference_ce; +extern PHPAPI zend_class_entry *php_phongo_server_ce; +extern PHPAPI zend_class_entry *php_phongo_updatebatch_ce; +extern PHPAPI zend_class_entry *php_phongo_updateresult_ce; +extern PHPAPI zend_class_entry *php_phongo_writebatch_ce; +extern PHPAPI zend_class_entry *php_phongo_writeconcernerror_ce; +extern PHPAPI zend_class_entry *php_phongo_writeerror_ce; +extern PHPAPI zend_class_entry *php_phongo_writeresult_ce; + +typedef enum { + PHONGO_INVALID_ARGUMENT = 1, +} php_phongo_error_domain_t; + +PHPAPI zend_class_entry* phongo_exception_from_mongoc_domain(mongoc_error_domain_t domain); +PHPAPI zend_class_entry* phongo_exception_from_phongo_domain(php_phongo_error_domain_t domain); + +PHP_MINIT_FUNCTION(bson); +PHP_MINIT_FUNCTION(Command); +PHP_MINIT_FUNCTION(CommandCursor); +PHP_MINIT_FUNCTION(CommandResult); +PHP_MINIT_FUNCTION(Cursor); +PHP_MINIT_FUNCTION(CursorId); +PHP_MINIT_FUNCTION(DeleteBatch); +PHP_MINIT_FUNCTION(DeleteResult); +PHP_MINIT_FUNCTION(GeneratedId); +PHP_MINIT_FUNCTION(InsertBatch); +PHP_MINIT_FUNCTION(InsertResult); +PHP_MINIT_FUNCTION(Manager); +PHP_MINIT_FUNCTION(Query); +PHP_MINIT_FUNCTION(QueryCursor); +PHP_MINIT_FUNCTION(ReadPreference); +PHP_MINIT_FUNCTION(Server); +PHP_MINIT_FUNCTION(UpdateBatch); +PHP_MINIT_FUNCTION(UpdateResult); +PHP_MINIT_FUNCTION(WriteBatch); +PHP_MINIT_FUNCTION(WriteConcernError); +PHP_MINIT_FUNCTION(WriteError); +PHP_MINIT_FUNCTION(WriteResult); +PHP_FUNCTION(bson_encode); +PHP_FUNCTION(bson_decode); +PHP_FUNCTION(bson_to_json); +#endif /* PHONGO_H */ + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/Command.c b/src/Command.c new file mode 100644 index 000000000..b0bfaf07b --- /dev/null +++ b/src/Command.c @@ -0,0 +1,108 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_command_ce; + +/* {{{ proto MongoDB\Command\Command Command::__construct(array|object $document) + Constructs a new MongoDB Command */ +PHP_METHOD(Command, __construct) +{ + php_phongo_command_t *intern; + zend_error_handling error_handling; + zval *document; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_command_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &document) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Value object for a database command document. + */ +/* {{{ MongoDB\Command\Command */ + +ZEND_BEGIN_ARG_INFO_EX(ai_Command___construct, 0, 0, 1) + ZEND_ARG_INFO(0, document) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_command_me[] = { + PHP_ME(Command, __construct, ai_Command___construct, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(Command) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Command", "Command", php_phongo_command_me); + php_phongo_command_ce = zend_register_internal_class(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/CommandCursor.c b/src/CommandCursor.c new file mode 100644 index 000000000..83e8470e0 --- /dev/null +++ b/src/CommandCursor.c @@ -0,0 +1,330 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_commandcursor_ce; + +/* {{{ proto MongoDB\Command\CommandCursor CommandCursor::__construct(MongoDB\Server $server, MongoDB\CursorId $cursorId, array $firstBatch) + Constructs a new CommandCursor object */ +PHP_METHOD(CommandCursor, __construct) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + zval *server; + zval *cursorId; + zval *firstBatch; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OOa", &server, php_phongo_server_ce, &cursorId, php_phongo_cursorid_ce, &firstBatch) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\CursorId CommandCursor::getId() + Returns the CursorId */ +PHP_METHOD(CommandCursor, getId) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Server CommandCursor::getServer() + Returns the Server object that this cursor is attached to */ +PHP_METHOD(CommandCursor, getServer) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto boolean CommandCursor::isDead() + Checks if a cursor is still alive */ +PHP_METHOD(CommandCursor, isDead) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto boolean CommandCursor::setBatchSize(integer $batchSize) + Sets a batch size for the cursor */ +PHP_METHOD(CommandCursor, setBatchSize) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + long batchSize; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &batchSize) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void CommandCursor::current() + */ +PHP_METHOD(CommandCursor, current) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void CommandCursor::next() + */ +PHP_METHOD(CommandCursor, next) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void CommandCursor::key() + */ +PHP_METHOD(CommandCursor, key) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void CommandCursor::valid() + */ +PHP_METHOD(CommandCursor, valid) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void CommandCursor::rewind() + */ +PHP_METHOD(CommandCursor, rewind) +{ + php_phongo_commandcursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandcursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Cursor implementation that may be constructed from values found in a + * CommandResult's response document. + * + * The iteration and internal logic is very similar to QueryCursor, so both + * classes should likely share code. The first batch is comparable to the + * documents found in the OP_REPLY message returned by a QueryCursor's original + * OP_QUERY, in that both may be available at the time the cursor is + * constructed. + */ +/* {{{ MongoDB\Command\CommandCursor */ + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor___construct, 0, 0, 3) + ZEND_ARG_OBJ_INFO(0, server, MongoDB\\Server, 0) + ZEND_ARG_OBJ_INFO(0, cursorId, MongoDB\\CursorId, 0) + ZEND_ARG_ARRAY_INFO(0, firstBatch, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_getId, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_isDead, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_setBatchSize, 0, 0, 1) + ZEND_ARG_INFO(0, batchSize) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_current, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_next, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_key, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_valid, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandCursor_rewind, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_commandcursor_me[] = { + PHP_ME(CommandCursor, __construct, ai_CommandCursor___construct, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, getId, ai_CommandCursor_getId, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, getServer, ai_CommandCursor_getServer, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, isDead, ai_CommandCursor_isDead, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, setBatchSize, ai_CommandCursor_setBatchSize, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, current, ai_CommandCursor_current, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, next, ai_CommandCursor_next, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, key, ai_CommandCursor_key, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, valid, ai_CommandCursor_valid, ZEND_ACC_PUBLIC) + PHP_ME(CommandCursor, rewind, ai_CommandCursor_rewind, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(CommandCursor) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Command", "CommandCursor", php_phongo_commandcursor_me); + php_phongo_commandcursor_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_commandcursor_ce TSRMLS_CC, 1, php_phongo_cursor_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/CommandResult.c b/src/CommandResult.c new file mode 100644 index 000000000..f1138e62b --- /dev/null +++ b/src/CommandResult.c @@ -0,0 +1,156 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_commandresult_ce; + +/* {{{ proto MongoDB\Command\CommandResult CommandResult::__construct(MongoDB\Server $server, array|object $responseDocument) + Constructs a new CommandResult */ +PHP_METHOD(CommandResult, __construct) +{ + php_phongo_commandresult_t *intern; + zend_error_handling error_handling; + zval *server; + zval *responseDocument; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OA", &server, php_phongo_server_ce, &responseDocument) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array CommandResult::getResponseDocument() + Returns the original response document from the server */ +PHP_METHOD(CommandResult, getResponseDocument) +{ + php_phongo_commandresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Server CommandResult::getServer() + Returns the Server object that this cursor is attached to */ +PHP_METHOD(CommandResult, getServer) +{ + php_phongo_commandresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_commandresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Result returned by Server and Manager executeCommand() methods. + */ +/* {{{ MongoDB\Command\CommandResult */ + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandResult___construct, 0, 0, 2) + ZEND_ARG_OBJ_INFO(0, server, MongoDB\\Server, 0) + ZEND_ARG_INFO(0, responseDocument) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandResult_getResponseDocument, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CommandResult_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_commandresult_me[] = { + PHP_ME(CommandResult, __construct, ai_CommandResult___construct, ZEND_ACC_PUBLIC) + PHP_ME(CommandResult, getResponseDocument, ai_CommandResult_getResponseDocument, ZEND_ACC_PUBLIC) + PHP_ME(CommandResult, getServer, ai_CommandResult_getServer, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(CommandResult) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Command", "CommandResult", php_phongo_commandresult_me); + php_phongo_commandresult_ce = zend_register_internal_class(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/Cursor.c b/src/Cursor.c new file mode 100644 index 000000000..7a41186d4 --- /dev/null +++ b/src/Cursor.c @@ -0,0 +1,125 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_cursor_ce; + + + +/* {{{ MongoDB\Cursor */ + +ZEND_BEGIN_ARG_INFO_EX(ai_Cursor_getId, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Cursor_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Cursor_isDead, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Cursor_setBatchSize, 0, 0, 1) + ZEND_ARG_INFO(0, batchSize) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_cursor_me[] = { + /** + * Returns the CursorId + * + * @return CursorId + */ + PHP_ABSTRACT_ME(Cursor, getId, ai_Cursor_getId) + + /** + * Returns the Server object that this cursor is attached to + * + * @return Server Server from which the cursor originated + */ + PHP_ABSTRACT_ME(Cursor, getServer, ai_Cursor_getServer) + + /** + * Checks if a cursor is still alive + * + * @return boolean Whether the cursor is exhausted and has no more results + */ + PHP_ABSTRACT_ME(Cursor, isDead, ai_Cursor_isDead) + + /** + * Sets the BatchSize of the Cursor + * + * @param integer $batchSize + * @return boolean true on success, false on failure + */ + PHP_ABSTRACT_ME(Cursor, setBatchSize, ai_Cursor_setBatchSize) + + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(Cursor) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB", "Cursor", php_phongo_cursor_me); + php_phongo_cursor_ce = zend_register_internal_interface(&ce TSRMLS_CC); + zend_class_implements(php_phongo_cursor_ce TSRMLS_CC, 1, spl_ce_Iterator); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/CursorId.c b/src/CursorId.c new file mode 100644 index 000000000..9f0688dca --- /dev/null +++ b/src/CursorId.c @@ -0,0 +1,135 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_cursorid_ce; + +/* {{{ proto MongoDB\CursorId CursorId::__construct(string $id) + Construct a new CursorId */ +PHP_METHOD(CursorId, __construct) +{ + php_phongo_cursorid_t *intern; + zend_error_handling error_handling; + char *id; + int id_len; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_cursorid_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &id, &id_len) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto string CursorId::__toString() + Returns the string representation of the CursorId */ +PHP_METHOD(CursorId, __toString) +{ + php_phongo_cursorid_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_cursorid_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Value object for the 64-bit cursor identifier. + * + * This is useful for compatibility with 32-bit platforms, and also allows + * Cursor constructors to type-hint against a class. + */ +/* {{{ MongoDB\CursorId */ + +ZEND_BEGIN_ARG_INFO_EX(ai_CursorId___construct, 0, 0, 1) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_CursorId___toString, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_cursorid_me[] = { + PHP_ME(CursorId, __construct, ai_CursorId___construct, ZEND_ACC_PUBLIC) + PHP_ME(CursorId, __toString, ai_CursorId___toString, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(CursorId) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB", "CursorId", php_phongo_cursorid_me); + php_phongo_cursorid_ce = zend_register_internal_class(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/DeleteBatch.c b/src/DeleteBatch.c new file mode 100644 index 000000000..6d7808e43 --- /dev/null +++ b/src/DeleteBatch.c @@ -0,0 +1,133 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_deletebatch_ce; + +/* {{{ proto MongoDB\Write\DeleteBatch DeleteBatch::add(array|object $document) + Adds a new operation to be executed */ +PHP_METHOD(DeleteBatch, add) +{ + php_phongo_deletebatch_t *intern; + zend_error_handling error_handling; + zval *document; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_deletebatch_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &document) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto int DeleteBatch::count() + Returns how many items have been added to this batch */ +PHP_METHOD(DeleteBatch, count) +{ + php_phongo_deletebatch_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_deletebatch_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Aggregates a collection of delete operations, to be executed in batches. + */ +/* {{{ MongoDB\Write\DeleteBatch */ + +ZEND_BEGIN_ARG_INFO_EX(ai_DeleteBatch_add, 0, 0, 1) + ZEND_ARG_INFO(0, document) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_DeleteBatch_count, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_deletebatch_me[] = { + PHP_ME(DeleteBatch, add, ai_DeleteBatch_add, ZEND_ACC_PUBLIC) + PHP_ME(DeleteBatch, count, ai_DeleteBatch_count, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(DeleteBatch) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "DeleteBatch", php_phongo_deletebatch_me); + php_phongo_deletebatch_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_deletebatch_ce TSRMLS_CC, 1, php_phongo_writebatch_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/DeleteResult.c b/src/DeleteResult.c new file mode 100644 index 000000000..b93c32359 --- /dev/null +++ b/src/DeleteResult.c @@ -0,0 +1,204 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_deleteresult_ce; + +/* {{{ proto integer DeleteResult::getNumRemoved() + Returns the Number of documents that got removed */ +PHP_METHOD(DeleteResult, getNumRemoved) +{ + php_phongo_deleteresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_deleteresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array DeleteResult::getInfo() + Returns metadata about the operation, see https://github.com/mongodb/specifications/blob/master/source/server_write_commands.rst#situational-fields */ +PHP_METHOD(DeleteResult, getInfo) +{ + php_phongo_deleteresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_deleteresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Server DeleteResult::getServer() + Returns the Server object that this result originated */ +PHP_METHOD(DeleteResult, getServer) +{ + php_phongo_deleteresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_deleteresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto WriteConcernError[] DeleteResult::getWriteConcernErrors() + Returns all WriteConcern Errors that occurred */ +PHP_METHOD(DeleteResult, getWriteConcernErrors) +{ + php_phongo_deleteresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_deleteresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto WriteError[] DeleteResult::getWriteErrors() + Returns all Write Errors that occurred */ +PHP_METHOD(DeleteResult, getWriteErrors) +{ + php_phongo_deleteresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_deleteresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Result returned by Server and Manager executeWrite() methods processing a + * DeleteBatch. + * + * This class may be constructed internally if it will encapsulate a libmongoc + * data structure. + */ +/* {{{ MongoDB\Write\DeleteResult */ + +ZEND_BEGIN_ARG_INFO_EX(ai_DeleteResult_getNumRemoved, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_DeleteResult_getInfo, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_DeleteResult_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_DeleteResult_getWriteConcernErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_DeleteResult_getWriteErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_deleteresult_me[] = { + PHP_ME(DeleteResult, getNumRemoved, ai_DeleteResult_getNumRemoved, ZEND_ACC_PUBLIC) + PHP_ME(DeleteResult, getInfo, ai_DeleteResult_getInfo, ZEND_ACC_PUBLIC) + PHP_ME(DeleteResult, getServer, ai_DeleteResult_getServer, ZEND_ACC_PUBLIC) + PHP_ME(DeleteResult, getWriteConcernErrors, ai_DeleteResult_getWriteConcernErrors, ZEND_ACC_PUBLIC) + PHP_ME(DeleteResult, getWriteErrors, ai_DeleteResult_getWriteErrors, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(DeleteResult) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "DeleteResult", php_phongo_deleteresult_me); + php_phongo_deleteresult_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_deleteresult_ce TSRMLS_CC, 1, php_phongo_writeresult_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/GeneratedId.c b/src/GeneratedId.c new file mode 100644 index 000000000..ab113f85a --- /dev/null +++ b/src/GeneratedId.c @@ -0,0 +1,157 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_generatedid_ce; + +/* {{{ proto MongoDB\Write\GeneratedId GeneratedId::__construct(mixed $id, integer $index) + Constructs a new GeneratedId */ +PHP_METHOD(GeneratedId, __construct) +{ + php_phongo_generatedid_t *intern; + zend_error_handling error_handling; + zval *id; + long index; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_generatedid_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &id, &index) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto mixed GeneratedId::getId() + Returns the GeneratedId */ +PHP_METHOD(GeneratedId, getId) +{ + php_phongo_generatedid_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_generatedid_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer GeneratedId::getIndex() + Returns the batch index */ +PHP_METHOD(GeneratedId, getIndex) +{ + php_phongo_generatedid_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_generatedid_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Value object for a document identifier that was generated by the driver or + * server during an insert or upsert operation, respectively. + */ +/* {{{ MongoDB\Write\GeneratedId */ + +ZEND_BEGIN_ARG_INFO_EX(ai_GeneratedId___construct, 0, 0, 2) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_GeneratedId_getId, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_GeneratedId_getIndex, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_generatedid_me[] = { + PHP_ME(GeneratedId, __construct, ai_GeneratedId___construct, ZEND_ACC_PUBLIC) + PHP_ME(GeneratedId, getId, ai_GeneratedId_getId, ZEND_ACC_PUBLIC) + PHP_ME(GeneratedId, getIndex, ai_GeneratedId_getIndex, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(GeneratedId) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "GeneratedId", php_phongo_generatedid_me); + php_phongo_generatedid_ce = zend_register_internal_class(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/InsertBatch.c b/src/InsertBatch.c new file mode 100644 index 000000000..7bc5b2657 --- /dev/null +++ b/src/InsertBatch.c @@ -0,0 +1,133 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_insertbatch_ce; + +/* {{{ proto MongoDB\Write\InsertBatch InsertBatch::add(array|object $document) + Adds a new operation to be executed */ +PHP_METHOD(InsertBatch, add) +{ + php_phongo_insertbatch_t *intern; + zend_error_handling error_handling; + zval *document; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertbatch_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &document) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto int InsertBatch::count() + Returns how many items have been added to this batch */ +PHP_METHOD(InsertBatch, count) +{ + php_phongo_insertbatch_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertbatch_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Aggregates a collection of insert operations, to be executed in batches. + */ +/* {{{ MongoDB\Write\InsertBatch */ + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertBatch_add, 0, 0, 1) + ZEND_ARG_INFO(0, document) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertBatch_count, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_insertbatch_me[] = { + PHP_ME(InsertBatch, add, ai_InsertBatch_add, ZEND_ACC_PUBLIC) + PHP_ME(InsertBatch, count, ai_InsertBatch_count, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(InsertBatch) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "InsertBatch", php_phongo_insertbatch_me); + php_phongo_insertbatch_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_insertbatch_ce TSRMLS_CC, 1, php_phongo_writebatch_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/InsertResult.c b/src/InsertResult.c new file mode 100644 index 000000000..047116197 --- /dev/null +++ b/src/InsertResult.c @@ -0,0 +1,227 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_insertresult_ce; + +/* {{{ proto integer InsertResult::getNumInserted() + Returns the Number of documents that where inserted */ +PHP_METHOD(InsertResult, getNumInserted) +{ + php_phongo_insertresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto GeneratedId[] InsertResult::getGeneratedIds() + Returns all generated IDs */ +PHP_METHOD(InsertResult, getGeneratedIds) +{ + php_phongo_insertresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array InsertResult::getInfo() + Returns metadata about the operation, see https://github.com/mongodb/specifications/blob/master/source/server_write_commands.rst#situational-fields */ +PHP_METHOD(InsertResult, getInfo) +{ + php_phongo_insertresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Server InsertResult::getServer() + Returns the Server object that this result originated */ +PHP_METHOD(InsertResult, getServer) +{ + php_phongo_insertresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto WriteConcernError[] InsertResult::getWriteConcernErrors() + Returns all WriteConcern Errors that occurred */ +PHP_METHOD(InsertResult, getWriteConcernErrors) +{ + php_phongo_insertresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto WriteError[] InsertResult::getWriteErrors() + Returns all Write Errors that occurred */ +PHP_METHOD(InsertResult, getWriteErrors) +{ + php_phongo_insertresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_insertresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Result returned by Server and Manager executeWrite() methods processing an + * InsertBatch. + * + * This class may be constructed internally if it will encapsulate a libmongoc + * data structure. + */ +/* {{{ MongoDB\Write\InsertResult */ + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertResult_getNumInserted, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertResult_getGeneratedIds, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertResult_getInfo, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertResult_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertResult_getWriteConcernErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_InsertResult_getWriteErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_insertresult_me[] = { + PHP_ME(InsertResult, getNumInserted, ai_InsertResult_getNumInserted, ZEND_ACC_PUBLIC) + PHP_ME(InsertResult, getGeneratedIds, ai_InsertResult_getGeneratedIds, ZEND_ACC_PUBLIC) + PHP_ME(InsertResult, getInfo, ai_InsertResult_getInfo, ZEND_ACC_PUBLIC) + PHP_ME(InsertResult, getServer, ai_InsertResult_getServer, ZEND_ACC_PUBLIC) + PHP_ME(InsertResult, getWriteConcernErrors, ai_InsertResult_getWriteConcernErrors, ZEND_ACC_PUBLIC) + PHP_ME(InsertResult, getWriteErrors, ai_InsertResult_getWriteErrors, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(InsertResult) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "InsertResult", php_phongo_insertresult_me); + php_phongo_insertresult_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_insertresult_ce TSRMLS_CC, 1, php_phongo_writeresult_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/Manager.c b/src/Manager.c new file mode 100644 index 000000000..8c238724f --- /dev/null +++ b/src/Manager.c @@ -0,0 +1,333 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_manager_ce; + +/* {{{ proto MongoDB\Manager Manager::__construct(string $uri[, array $options = array()[, array $driverOptions = array()]]) + Constructs a new Manager */ +PHP_METHOD(Manager, __construct) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + char *uri; + int uri_len; + zval *options; + zval *driverOptions; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|aa", &uri, &uri_len, &options, &driverOptions) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Manager Manager::createFromServers(array $servers) + Creates new Manager from a list of servers */ +PHP_METHOD(Manager, createFromServers) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + zval *servers; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &servers) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Command\CommandResult Manager::executeCommand(string $db, MongoDB\Command\Command $command[, MongoDB\ReadPreference $readPreference = null]) + Execute a command */ +PHP_METHOD(Manager, executeCommand) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + char *db; + int db_len; + zval *command; + zval *readPreference; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O", &db, &db_len, &command, php_phongo_command_ce, &readPreference, php_phongo_readpreference_ce) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Query\QueryCursor Manager::executeQuery(string $namespace, MongoDB\Query\Query $query[, MongoDB\ReadPreference $readPreference = null]) + Execute a Query */ +PHP_METHOD(Manager, executeQuery) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + char *namespace; + int namespace_len; + zval *query; + zval *readPreference; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|O", &namespace, &namespace_len, &query, php_phongo_query_ce, &readPreference, php_phongo_readpreference_ce) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Write\WriteResult Manager::executeWrite(string $namespace, MongoDB\Write\WriteBatch $batch[, array $writeOptions = array()]) + Executes a write operation batch (e.g. insert, update, delete) */ +PHP_METHOD(Manager, executeWrite) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + char *namespace; + int namespace_len; + zval *batch; + zval *writeOptions; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO|a", &namespace, &namespace_len, &batch, php_phongo_writebatch_ce, &writeOptions) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Write\InsertResult Manager::executeInsert(string $namespace, array|object $document[, array $writeOptions = array()]) + Convenience method for single insert operation. */ +PHP_METHOD(Manager, executeInsert) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + char *namespace; + int namespace_len; + zval *document; + zval *writeOptions; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sA|a", &namespace, &namespace_len, &document, &writeOptions) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Write\UpdateResult Manager::executeUpdate(string $namespace, array|object $query, array|object $newObj[, array $updateOptions = array()[, array $writeOptions = array()]]) + Convenience method for single update operation. */ +PHP_METHOD(Manager, executeUpdate) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + char *namespace; + int namespace_len; + zval *query; + zval *newObj; + zval *updateOptions; + zval *writeOptions; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sAA|aa", &namespace, &namespace_len, &query, &newObj, &updateOptions, &writeOptions) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Write\DeleteResult Manager::executeDelete(string $namespace, array|object $query[, array $deleteOptions = array()[, array $writeOptions = array()]]) + Convenience method for single delete operation. */ +PHP_METHOD(Manager, executeDelete) +{ + php_phongo_manager_t *intern; + zend_error_handling error_handling; + char *namespace; + int namespace_len; + zval *query; + zval *deleteOptions; + zval *writeOptions; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sA|aa", &namespace, &namespace_len, &query, &deleteOptions, &writeOptions) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Manager abstracts a cluster of Server objects (i.e. socket connections). + * + * Typically, users will connect to a cluster using a URI, and the Manager will + * perform tasks such as replica set discovery and create the necessary Server + * objects. That said, it is also possible to create a Manager with an arbitrary + * collection of Server objects using the static factory method (this can be + * useful for testing or administration). + * + * Operation methods do not take socket-level options (e.g. socketTimeoutMS). + * Those options should be specified during construction. + */ +/* {{{ MongoDB\Manager */ + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager___construct, 0, 0, 1) + ZEND_ARG_INFO(0, uri) + ZEND_ARG_ARRAY_INFO(0, options, 0) + ZEND_ARG_ARRAY_INFO(0, driverOptions, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager_createFromServers, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, servers, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeCommand, 0, 0, 2) + ZEND_ARG_INFO(0, db) + ZEND_ARG_OBJ_INFO(0, command, MongoDB\\Command\\Command, 0) + ZEND_ARG_OBJ_INFO(0, readPreference, MongoDB\\ReadPreference, 1) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeQuery, 0, 0, 2) + ZEND_ARG_INFO(0, namespace) + ZEND_ARG_OBJ_INFO(0, query, MongoDB\\Query\\Query, 0) + ZEND_ARG_OBJ_INFO(0, readPreference, MongoDB\\ReadPreference, 1) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeWrite, 0, 0, 2) + ZEND_ARG_INFO(0, namespace) + ZEND_ARG_OBJ_INFO(0, batch, MongoDB\\Write\\WriteBatch, 0) + ZEND_ARG_ARRAY_INFO(0, writeOptions, 1) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeInsert, 0, 0, 2) + ZEND_ARG_INFO(0, namespace) + ZEND_ARG_INFO(0, document) + ZEND_ARG_ARRAY_INFO(0, writeOptions, 1) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeUpdate, 0, 0, 3) + ZEND_ARG_INFO(0, namespace) + ZEND_ARG_INFO(0, query) + ZEND_ARG_INFO(0, newObj) + ZEND_ARG_ARRAY_INFO(0, updateOptions, 1) + ZEND_ARG_ARRAY_INFO(0, writeOptions, 1) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeDelete, 0, 0, 2) + ZEND_ARG_INFO(0, namespace) + ZEND_ARG_INFO(0, query) + ZEND_ARG_ARRAY_INFO(0, deleteOptions, 1) + ZEND_ARG_ARRAY_INFO(0, writeOptions, 1) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_manager_me[] = { + PHP_ME(Manager, __construct, ai_Manager___construct, ZEND_ACC_PUBLIC) + PHP_ME(Manager, createFromServers, ai_Manager_createFromServers, ZEND_ACC_PUBLIC) + PHP_ME(Manager, executeCommand, ai_Manager_executeCommand, ZEND_ACC_PUBLIC) + PHP_ME(Manager, executeQuery, ai_Manager_executeQuery, ZEND_ACC_PUBLIC) + PHP_ME(Manager, executeWrite, ai_Manager_executeWrite, ZEND_ACC_PUBLIC) + PHP_ME(Manager, executeInsert, ai_Manager_executeInsert, ZEND_ACC_PUBLIC) + PHP_ME(Manager, executeUpdate, ai_Manager_executeUpdate, ZEND_ACC_PUBLIC) + PHP_ME(Manager, executeDelete, ai_Manager_executeDelete, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(Manager) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB", "Manager", php_phongo_manager_me); + php_phongo_manager_ce = zend_register_internal_class(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/Query.c b/src/Query.c new file mode 100644 index 000000000..d48e432c9 --- /dev/null +++ b/src/Query.c @@ -0,0 +1,128 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_query_ce; + +/* {{{ proto MongoDB\Query\Query Query::__construct(array|object $query, array|object $selector, integer $flags, integer $skip, integer $limit) + Constructs a new Query */ +PHP_METHOD(Query, __construct) +{ + php_phongo_query_t *intern; + zend_error_handling error_handling; + zval *query; + zval *selector; + long flags; + long skip; + long limit; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_query_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "AAlll", &query, &selector, &flags, &skip, &limit) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Value object corresponding to a wire protocol OP_QUERY message. + * + * If and when queries become commands, we will need to introduce a new Query + * object, such as QueryCommand. At that point, the query will likely be + * constructed from a single document, which includes the arguments below in a + * similar fashion to findAndModify. + */ +/* {{{ MongoDB\Query\Query */ + +ZEND_BEGIN_ARG_INFO_EX(ai_Query___construct, 0, 0, 5) + ZEND_ARG_INFO(0, query) + ZEND_ARG_INFO(0, selector) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, skip) + ZEND_ARG_INFO(0, limit) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_query_me[] = { + PHP_ME(Query, __construct, ai_Query___construct, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(Query) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Query", "Query", php_phongo_query_me); + php_phongo_query_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_query_ce, ZEND_STRL("FLAG_TAILABLE_CURSOR"), 0x01 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_query_ce, ZEND_STRL("FLAG_SLAVE_OK"), 0x02 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_query_ce, ZEND_STRL("FLAG_OPLOG_REPLAY"), 0x04 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_query_ce, ZEND_STRL("FLAG_NO_CURSOR_TIMEOUT"), 0x08 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_query_ce, ZEND_STRL("FLAG_AWAIT_DATA"), 0x10 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_query_ce, ZEND_STRL("FLAG_EXHAUST"), 0x20 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_query_ce, ZEND_STRL("FLAG_PARTIAL"), 0x40 TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/QueryCursor.c b/src/QueryCursor.c new file mode 100644 index 000000000..cc2145d8b --- /dev/null +++ b/src/QueryCursor.c @@ -0,0 +1,327 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_querycursor_ce; + +/* {{{ proto MongoDB\Query\QueryCursor QueryCursor::__construct(MongoDB\Server $server, MongoDB\CursorId $cursorId) + Construct a new QueryCursor */ +PHP_METHOD(QueryCursor, __construct) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + zval *server; + zval *cursorId; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &server, php_phongo_server_ce, &cursorId, php_phongo_cursorid_ce) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\CursorId QueryCursor::getId() + Returns the CursorId */ +PHP_METHOD(QueryCursor, getId) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Server QueryCursor::getServer() + Returns the Server object that this cursor is attached to */ +PHP_METHOD(QueryCursor, getServer) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto boolean QueryCursor::isDead() + Checks if a cursor is still alive */ +PHP_METHOD(QueryCursor, isDead) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto boolean QueryCursor::setBatchSize(integer $batchSize) + Sets a batch size for the cursor */ +PHP_METHOD(QueryCursor, setBatchSize) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + long batchSize; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &batchSize) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void QueryCursor::current() + */ +PHP_METHOD(QueryCursor, current) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void QueryCursor::next() + */ +PHP_METHOD(QueryCursor, next) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void QueryCursor::key() + */ +PHP_METHOD(QueryCursor, key) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void QueryCursor::valid() + */ +PHP_METHOD(QueryCursor, valid) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto void QueryCursor::rewind() + */ +PHP_METHOD(QueryCursor, rewind) +{ + php_phongo_querycursor_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_querycursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Cursor implementation that is returned after executing a Query. + * + * The iteration and internal logic is very similar to CommandCursor, so both + * classes should likely share code. The documents in the OP_REPLY message + * returned by the original OP_QUERY is comparable to the first batch of a + * command cursor, in that both may be available at the time the cursor is + * constructed. + */ +/* {{{ MongoDB\Query\QueryCursor */ + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor___construct, 0, 0, 2) + ZEND_ARG_OBJ_INFO(0, server, MongoDB\\Server, 0) + ZEND_ARG_OBJ_INFO(0, cursorId, MongoDB\\CursorId, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_getId, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_isDead, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_setBatchSize, 0, 0, 1) + ZEND_ARG_INFO(0, batchSize) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_current, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_next, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_key, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_valid, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_QueryCursor_rewind, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_querycursor_me[] = { + PHP_ME(QueryCursor, __construct, ai_QueryCursor___construct, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, getId, ai_QueryCursor_getId, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, getServer, ai_QueryCursor_getServer, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, isDead, ai_QueryCursor_isDead, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, setBatchSize, ai_QueryCursor_setBatchSize, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, current, ai_QueryCursor_current, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, next, ai_QueryCursor_next, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, key, ai_QueryCursor_key, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, valid, ai_QueryCursor_valid, ZEND_ACC_PUBLIC) + PHP_ME(QueryCursor, rewind, ai_QueryCursor_rewind, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(QueryCursor) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Query", "QueryCursor", php_phongo_querycursor_me); + php_phongo_querycursor_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_querycursor_ce TSRMLS_CC, 1, php_phongo_cursor_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/ReadPreference.c b/src/ReadPreference.c new file mode 100644 index 000000000..58a89dd2b --- /dev/null +++ b/src/ReadPreference.c @@ -0,0 +1,116 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_readpreference_ce; + +/* {{{ proto MongoDB\ReadPreference ReadPreference::__construct(string $readPreference[, array $tagSets = array()]) + Constructs a new ReadPreference */ +PHP_METHOD(ReadPreference, __construct) +{ + php_phongo_readpreference_t *intern; + zend_error_handling error_handling; + char *readPreference; + int readPreference_len; + zval *tagSets; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_readpreference_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &readPreference, &readPreference_len, &tagSets) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Value object for read preferences used in issuing commands and queries. + */ +/* {{{ MongoDB\ReadPreference */ + +ZEND_BEGIN_ARG_INFO_EX(ai_ReadPreference___construct, 0, 0, 1) + ZEND_ARG_INFO(0, readPreference) + ZEND_ARG_ARRAY_INFO(0, tagSets, 1) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_readpreference_me[] = { + PHP_ME(ReadPreference, __construct, ai_ReadPreference___construct, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(ReadPreference) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB", "ReadPreference", php_phongo_readpreference_me); + php_phongo_readpreference_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_declare_class_constant_string(php_phongo_readpreference_ce, ZEND_STRL("RP_PRIMARY"), "primary" TSRMLS_DC); + zend_declare_class_constant_string(php_phongo_readpreference_ce, ZEND_STRL("RP_PRIMARY_PREFERRED"), "primaryPreferred" TSRMLS_DC); + zend_declare_class_constant_string(php_phongo_readpreference_ce, ZEND_STRL("RP_SECONDARY"), "secondary" TSRMLS_DC); + zend_declare_class_constant_string(php_phongo_readpreference_ce, ZEND_STRL("RP_SECONDARY_PREFERRED"), "secondaryPreferred" TSRMLS_DC); + zend_declare_class_constant_string(php_phongo_readpreference_ce, ZEND_STRL("RP_NEAREST"), "nearest" TSRMLS_DC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/Server.c b/src/Server.c new file mode 100644 index 000000000..311dba818 --- /dev/null +++ b/src/Server.c @@ -0,0 +1,398 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_server_ce; + +/* {{{ proto MongoDB\Server Server::__construct(string $host, integer $port[, array $options = array()[, array $driverOptions = array()]]) + Constructs a new Server */ +PHP_METHOD(Server, __construct) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + char *host; + int host_len; + long port; + zval *options; + zval *driverOptions; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|aa", &host, &host_len, &port, &options, &driverOptions) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Command\CommandResult Server::executeCommand(string $db, MongoDB\Command\Command $command) + Executes a command on this server */ +PHP_METHOD(Server, executeCommand) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + char *db; + int db_len; + zval *command; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &db, &db_len, &command, php_phongo_command_ce) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Query\QueryCursor Server::executeQuery(string $namespace, MongoDB\Query\Query $query) + Executes a Query */ +PHP_METHOD(Server, executeQuery) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + char *namespace; + int namespace_len; + zval *query; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &namespace, &namespace_len, &query, php_phongo_query_ce) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Write\WriteResult Server::executeWrite(string $namespace, MongoDB\Write\WriteBatch $batch) + Executes a write operation batch (e.g. insert, update, delete) */ +PHP_METHOD(Server, executeWrite) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + char *namespace; + int namespace_len; + zval *batch; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &namespace, &namespace_len, &batch, php_phongo_writebatch_ce) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto string Server::getHost() + Returns the hostname used to connect to this Server */ +PHP_METHOD(Server, getHost) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array Server::getInfo() + Returns the last isMaster() result document */ +PHP_METHOD(Server, getInfo) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer Server::getLatency() + Returns the last messured latency */ +PHP_METHOD(Server, getLatency) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer Server::getPort() + Returns the port used to create this Server */ +PHP_METHOD(Server, getPort) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer Server::getState() + Returns the current state of the node (maintenece/startup/...) */ +PHP_METHOD(Server, getState) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer Server::getType() + Returns the node type of this Server */ +PHP_METHOD(Server, getType) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto bool Server::isDelayed() + Checks if this is a special "delayed" member of a RepilcaSet */ +PHP_METHOD(Server, isDelayed) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto bool Server::isPassive() + Checks if this is a special passive node member of a ReplicaSet */ +PHP_METHOD(Server, isPassive) +{ + php_phongo_server_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_server_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Server abstracts a socket connection to a single MongoDB server. The server + * itself may be a mongod (stand-alone or replica set node) or mongos process. + * + * Users will typically not construct this class directly. The common use case + * will be connection to a cluster of servers via a URI with the Manager class. + * + * This class does not utilize read preferences, since there is only a single + * single socket on which to send a command, query, or write. + * + * Operation methods do not take socket-level options (e.g. socketTimeoutMS). + * Those options should be specified during construction. + */ +/* {{{ MongoDB\Server */ + +ZEND_BEGIN_ARG_INFO_EX(ai_Server___construct, 0, 0, 2) + ZEND_ARG_INFO(0, host) + ZEND_ARG_INFO(0, port) + ZEND_ARG_ARRAY_INFO(0, options, 0) + ZEND_ARG_ARRAY_INFO(0, driverOptions, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_executeCommand, 0, 0, 2) + ZEND_ARG_INFO(0, db) + ZEND_ARG_OBJ_INFO(0, command, MongoDB\\Command\\Command, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_executeQuery, 0, 0, 2) + ZEND_ARG_INFO(0, namespace) + ZEND_ARG_OBJ_INFO(0, query, MongoDB\\Query\\Query, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_executeWrite, 0, 0, 2) + ZEND_ARG_INFO(0, namespace) + ZEND_ARG_OBJ_INFO(0, batch, MongoDB\\Write\\WriteBatch, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_getHost, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_getInfo, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_getLatency, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_getPort, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_getState, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_getType, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_isDelayed, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_Server_isPassive, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_server_me[] = { + PHP_ME(Server, __construct, ai_Server___construct, ZEND_ACC_PUBLIC) + PHP_ME(Server, executeCommand, ai_Server_executeCommand, ZEND_ACC_PUBLIC) + PHP_ME(Server, executeQuery, ai_Server_executeQuery, ZEND_ACC_PUBLIC) + PHP_ME(Server, executeWrite, ai_Server_executeWrite, ZEND_ACC_PUBLIC) + PHP_ME(Server, getHost, ai_Server_getHost, ZEND_ACC_PUBLIC) + PHP_ME(Server, getInfo, ai_Server_getInfo, ZEND_ACC_PUBLIC) + PHP_ME(Server, getLatency, ai_Server_getLatency, ZEND_ACC_PUBLIC) + PHP_ME(Server, getPort, ai_Server_getPort, ZEND_ACC_PUBLIC) + PHP_ME(Server, getState, ai_Server_getState, ZEND_ACC_PUBLIC) + PHP_ME(Server, getType, ai_Server_getType, ZEND_ACC_PUBLIC) + PHP_ME(Server, isDelayed, ai_Server_isDelayed, ZEND_ACC_PUBLIC) + PHP_ME(Server, isPassive, ai_Server_isPassive, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(Server) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB", "Server", php_phongo_server_me); + php_phongo_server_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_MONGOS"), 0x01 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_STANDALONE"), 0x02 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_ARBITER"), 0x03 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_SECONDARY"), 0x04 TSRMLS_CC); + zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_PRIMARY"), 0x05 TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/UpdateBatch.c b/src/UpdateBatch.c new file mode 100644 index 000000000..1ed714d7a --- /dev/null +++ b/src/UpdateBatch.c @@ -0,0 +1,133 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_updatebatch_ce; + +/* {{{ proto MongoDB\Write\UpdateBatch UpdateBatch::add(array|object $document) + Adds a new operation to be executed */ +PHP_METHOD(UpdateBatch, add) +{ + php_phongo_updatebatch_t *intern; + zend_error_handling error_handling; + zval *document; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updatebatch_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &document) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto int UpdateBatch::count() + Returns how many items have been added to this batch */ +PHP_METHOD(UpdateBatch, count) +{ + php_phongo_updatebatch_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updatebatch_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Aggregates a collection of update operations, to be executed in batches. + */ +/* {{{ MongoDB\Write\UpdateBatch */ + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateBatch_add, 0, 0, 1) + ZEND_ARG_INFO(0, document) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateBatch_count, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_updatebatch_me[] = { + PHP_ME(UpdateBatch, add, ai_UpdateBatch_add, ZEND_ACC_PUBLIC) + PHP_ME(UpdateBatch, count, ai_UpdateBatch_count, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(UpdateBatch) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "UpdateBatch", php_phongo_updatebatch_me); + php_phongo_updatebatch_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_updatebatch_ce TSRMLS_CC, 1, php_phongo_writebatch_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/UpdateResult.c b/src/UpdateResult.c new file mode 100644 index 000000000..902e2b539 --- /dev/null +++ b/src/UpdateResult.c @@ -0,0 +1,273 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_updateresult_ce; + +/* {{{ proto integer UpdateResult::getNumMatched() + Returns the number of documents matching the criteria */ +PHP_METHOD(UpdateResult, getNumMatched) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer UpdateResult::getNumModified() + Returns the number of documents that got physically modified */ +PHP_METHOD(UpdateResult, getNumModified) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer UpdateResult::getNumUpserted() + Returns the number of new documentes */ +PHP_METHOD(UpdateResult, getNumUpserted) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto GeneratedId[] UpdateResult::getUpserts() + Returns the GeneratedIds of the upserted documents */ +PHP_METHOD(UpdateResult, getUpserts) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array UpdateResult::getInfo() + Returns metadata about the operation, see https://github.com/mongodb/specifications/blob/master/source/server_write_commands.rst#situational-fields */ +PHP_METHOD(UpdateResult, getInfo) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto MongoDB\Server UpdateResult::getServer() + Returns the Server object that this result originated */ +PHP_METHOD(UpdateResult, getServer) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto WriteConcernError[] UpdateResult::getWriteConcernErrors() + Returns all WriteConcern Errors that occurred */ +PHP_METHOD(UpdateResult, getWriteConcernErrors) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto WriteError[] UpdateResult::getWriteErrors() + Returns all Write Errors that occurred */ +PHP_METHOD(UpdateResult, getWriteErrors) +{ + php_phongo_updateresult_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_updateresult_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Result returned by Server and Manager executeWrite() methods processing an + * UpdateBatch. + * + * This class may be constructed internally if it will encapsulate a libmongoc + * data structure. + */ +/* {{{ MongoDB\Write\UpdateResult */ + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getNumMatched, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getNumModified, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getNumUpserted, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getUpserts, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getInfo, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getWriteConcernErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_UpdateResult_getWriteErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_updateresult_me[] = { + PHP_ME(UpdateResult, getNumMatched, ai_UpdateResult_getNumMatched, ZEND_ACC_PUBLIC) + PHP_ME(UpdateResult, getNumModified, ai_UpdateResult_getNumModified, ZEND_ACC_PUBLIC) + PHP_ME(UpdateResult, getNumUpserted, ai_UpdateResult_getNumUpserted, ZEND_ACC_PUBLIC) + PHP_ME(UpdateResult, getUpserts, ai_UpdateResult_getUpserts, ZEND_ACC_PUBLIC) + PHP_ME(UpdateResult, getInfo, ai_UpdateResult_getInfo, ZEND_ACC_PUBLIC) + PHP_ME(UpdateResult, getServer, ai_UpdateResult_getServer, ZEND_ACC_PUBLIC) + PHP_ME(UpdateResult, getWriteConcernErrors, ai_UpdateResult_getWriteConcernErrors, ZEND_ACC_PUBLIC) + PHP_ME(UpdateResult, getWriteErrors, ai_UpdateResult_getWriteErrors, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(UpdateResult) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "UpdateResult", php_phongo_updateresult_me); + php_phongo_updateresult_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_implements(php_phongo_updateresult_ce TSRMLS_CC, 1, php_phongo_writeresult_ce); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/WriteBatch.c b/src/WriteBatch.c new file mode 100644 index 000000000..ca30e3618 --- /dev/null +++ b/src/WriteBatch.c @@ -0,0 +1,95 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_writebatch_ce; + + + +/* {{{ MongoDB\Write\WriteBatch */ + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteBatch_add, 0, 0, 1) + ZEND_ARG_INFO(0, document) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_writebatch_me[] = { + /** + * Adds a new operation to be executed + * + * @param array|object $document Operation/document to add to the batch + * @return DeleteBatch + */ + PHP_ABSTRACT_ME(WriteBatch, add, ai_WriteBatch_add) + + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(WriteBatch) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "WriteBatch", php_phongo_writebatch_me); + php_phongo_writebatch_ce = zend_register_internal_interface(&ce TSRMLS_CC); + zend_class_implements(php_phongo_writebatch_ce TSRMLS_CC, 1, spl_ce_Countable); + + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/WriteConcernError.c b/src/WriteConcernError.c new file mode 100644 index 000000000..63b97c209 --- /dev/null +++ b/src/WriteConcernError.c @@ -0,0 +1,182 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_writeconcernerror_ce; + +/* {{{ proto MongoDB\Write\WriteConcernError WriteConcernError::__construct(string $message, integer $code, array $info) + Constructs a new WriteConcernError object */ +PHP_METHOD(WriteConcernError, __construct) +{ + php_phongo_writeconcernerror_t *intern; + zend_error_handling error_handling; + char *message; + int message_len; + long code; + zval *info; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeconcernerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sla", &message, &message_len, &code, &info) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer WriteConcernError::getCode() + Returns the MongoDB error code */ +PHP_METHOD(WriteConcernError, getCode) +{ + php_phongo_writeconcernerror_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeconcernerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array WriteConcernError::getInfo() + Returns additional metadata for the error */ +PHP_METHOD(WriteConcernError, getInfo) +{ + php_phongo_writeconcernerror_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeconcernerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto string WriteConcernError::getMessage() + Returns the actual error message from the server */ +PHP_METHOD(WriteConcernError, getMessage) +{ + php_phongo_writeconcernerror_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeconcernerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Value object for a write concern error. + */ +/* {{{ MongoDB\Write\WriteConcernError */ + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcernError___construct, 0, 0, 3) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, code) + ZEND_ARG_ARRAY_INFO(0, info, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcernError_getCode, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcernError_getInfo, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcernError_getMessage, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_writeconcernerror_me[] = { + PHP_ME(WriteConcernError, __construct, ai_WriteConcernError___construct, ZEND_ACC_PUBLIC) + PHP_ME(WriteConcernError, getCode, ai_WriteConcernError_getCode, ZEND_ACC_PUBLIC) + PHP_ME(WriteConcernError, getInfo, ai_WriteConcernError_getInfo, ZEND_ACC_PUBLIC) + PHP_ME(WriteConcernError, getMessage, ai_WriteConcernError_getMessage, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(WriteConcernError) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "WriteConcernError", php_phongo_writeconcernerror_me); + php_phongo_writeconcernerror_ce = zend_register_internal_class(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/WriteError.c b/src/WriteError.c new file mode 100644 index 000000000..8be9fdf48 --- /dev/null +++ b/src/WriteError.c @@ -0,0 +1,207 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_writeerror_ce; + +/* {{{ proto MongoDB\Write\WriteError WriteError::__construct(string $message, integer $code, integer $index, array|object $operation) + Constructs a new WriteError object */ +PHP_METHOD(WriteError, __construct) +{ + php_phongo_writeerror_t *intern; + zend_error_handling error_handling; + char *message; + int message_len; + long code; + long index; + zval *operation; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllA", &message, &message_len, &code, &index, &operation) == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer WriteError::getCode() + Returns the MongoDB error code */ +PHP_METHOD(WriteError, getCode) +{ + php_phongo_writeerror_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto integer WriteError::getIndex() + Returns the Batch index where this WriteError occurred in */ +PHP_METHOD(WriteError, getIndex) +{ + php_phongo_writeerror_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto string WriteError::getMessage() + Returns the actual error message from the server */ +PHP_METHOD(WriteError, getMessage) +{ + php_phongo_writeerror_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ +/* {{{ proto array|object WriteError::getOperation() + Returns the batch operation itself that caused the error */ +PHP_METHOD(WriteError, getOperation) +{ + php_phongo_writeerror_t *intern; + zend_error_handling error_handling; + + (void)return_value; (void)return_value_ptr; (void)return_value_used; /* We don't use these */ + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_INVALID_ARGUMENT), &error_handling TSRMLS_CC); + intern = (php_phongo_writeerror_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC); + return; + } + zend_restore_error_handling(&error_handling TSRMLS_CC); +} +/* }}} */ + +/** + * Value object for a write error (e.g. duplicate key). + */ +/* {{{ MongoDB\Write\WriteError */ + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteError___construct, 0, 0, 4) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, code) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, operation) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteError_getCode, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteError_getIndex, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteError_getMessage, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteError_getOperation, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_writeerror_me[] = { + PHP_ME(WriteError, __construct, ai_WriteError___construct, ZEND_ACC_PUBLIC) + PHP_ME(WriteError, getCode, ai_WriteError_getCode, ZEND_ACC_PUBLIC) + PHP_ME(WriteError, getIndex, ai_WriteError_getIndex, ZEND_ACC_PUBLIC) + PHP_ME(WriteError, getMessage, ai_WriteError_getMessage, ZEND_ACC_PUBLIC) + PHP_ME(WriteError, getOperation, ai_WriteError_getOperation, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(WriteError) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "WriteError", php_phongo_writeerror_me); + php_phongo_writeerror_ce = zend_register_internal_class(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/src/WriteResult.c b/src/WriteResult.c new file mode 100644 index 000000000..812626060 --- /dev/null +++ b/src/WriteResult.c @@ -0,0 +1,121 @@ +/* + +---------------------------------------------------------------------------+ + | PHP Driver for MongoDB | + +---------------------------------------------------------------------------+ + | Copyright 2013-2014 MongoDB, Inc. | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + +---------------------------------------------------------------------------+ + | Copyright (c) 2014, MongoDB, Inc. | + +---------------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* External libs */ +#include +#include + +/* PHP Core stuff */ +#include +#include +#include +#include +#include +/* Our Compatability header */ +#include "php_compat_53.h" + +/* Our stuffz */ +#include "php_phongo.h" +#include "php_bson.h" + + +PHPAPI zend_class_entry *php_phongo_writeresult_ce; + + + +/* {{{ MongoDB\Write\WriteResult */ + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteResult_getInfo, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteResult_getServer, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteResult_getWriteConcernErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(ai_WriteResult_getWriteErrors, 0, 0, 0) +ZEND_END_ARG_INFO(); + + +static zend_function_entry php_phongo_writeresult_me[] = { + /** + * Returns metadata about the operation, see https://github.com/mongodb/specifications/blob/master/source/server_write_commands.rst#situational-fields + * + * @return array Additional metadata for the operation(s) (e.g. lastOp) + */ + PHP_ABSTRACT_ME(WriteResult, getInfo, ai_WriteResult_getInfo) + + /** + * Returns the Server object that this result originated + * + * @return Server Server from which the result originated + */ + PHP_ABSTRACT_ME(WriteResult, getServer, ai_WriteResult_getServer) + + /** + * Returns all WriteConcern Errors that occurred + * + * @return WriteConcernError[] + */ + PHP_ABSTRACT_ME(WriteResult, getWriteConcernErrors, ai_WriteResult_getWriteConcernErrors) + + /** + * Returns all Write Errors that occurred + * + * @return WriteError[] + */ + PHP_ABSTRACT_ME(WriteResult, getWriteErrors, ai_WriteResult_getWriteErrors) + + PHP_FE_END +}; + +/* }}} */ + + +/* {{{ PHP_MINIT_FUNCTION */ +PHP_MINIT_FUNCTION(WriteResult) +{ + (void)type; /* We don't care if we are loaded via dl() or extension= */ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Write", "WriteResult", php_phongo_writeresult_me); + php_phongo_writeresult_ce = zend_register_internal_interface(&ce TSRMLS_CC); + + return SUCCESS; +} +/* }}} */ + + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */