/** * Create internal connection to memcached */ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, _connect){ zval *options, *memcache, *servers, *client = NULL, *res = NULL; zend_string *str_key; ulong idx; zend_class_entry *ce0; PHALCON_MM_GROW(); options = phalcon_read_property(getThis(), SL("_options"), PH_NOISY); ce0 = zend_fetch_class(SSL("Memcached"), ZEND_FETCH_CLASS_AUTO); PHALCON_INIT_VAR(memcache); object_init_ex(memcache, ce0); if (phalcon_has_constructor(memcache)) { PHALCON_CALL_METHOD(NULL, memcache, "__construct"); } if (!phalcon_array_isset_str_fetch(&servers, options, SL("servers")) || Z_TYPE_P(servers) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Servers must be an array"); return; } phalcon_array_isset_str_fetch(&client, options, SL("client")); PHALCON_RETURN_CALL_METHOD(memcache, "addservers", servers); if (!zend_is_true(return_value)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cannot connect to Memcached server"); return; } if (client && Z_TYPE_P(client) == IS_ARRAY) { zval *value; ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(client), idx, str_key, value) { zval option; if (str_key) { if ((res = zend_get_constant(str_key)) != NULL) { PHALCON_CALL_METHOD(NULL, memcache, "setoption", res, value); } } else { ZVAL_LONG(&option, idx); PHALCON_CALL_METHOD(NULL, memcache, "setoption", &option, value); } } ZEND_HASH_FOREACH_END();
/** * Create internal connection to memcached */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, _connect) { zval options = {}, memcache = {}, host = {}, port = {}, persistent = {}, success = {}; zend_class_entry *ce0; phalcon_return_property(&options, getThis(), SL("_options")); ce0 = zend_fetch_class(SSL("Memcache"), ZEND_FETCH_CLASS_AUTO); object_init_ex(&memcache, ce0); if (phalcon_has_constructor(&memcache)) { PHALCON_CALL_METHODW(NULL, &memcache, "__construct"); } if ( !phalcon_array_isset_fetch_str(&host, &options, SL("host")) || !phalcon_array_isset_fetch_str(&port, &options, SL("port")) || !phalcon_array_isset_fetch_str(&persistent, &options, SL("persistent")) ) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "Unexpected inconsistency in options"); return; } if (zend_is_true(&persistent)) { PHALCON_CALL_METHODW(&success, &memcache, "pconnect", &host, &port); } else { PHALCON_CALL_METHODW(&success, &memcache, "connect", &host, &port); } if (!zend_is_true(&success)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cannot connect to Memcached server"); return; } phalcon_update_property_this(getThis(), SL("_memcache"), &memcache); RETURN_CTORW(&memcache); }
SSL* SSL_new(SSL_CTX* ctx) { return NEW_YS SSL(ctx); }
/** * Returns a MongoDb collection based on the backend parameters * * @return MongoCollection */ PHP_METHOD(Phalcon_Cache_Backend_Mongo, _getCollection){ zval *mongo_collection; zend_class_entry *ce0; PHALCON_MM_GROW(); mongo_collection = phalcon_read_property(getThis(), SL("_collection"), PH_NOISY); if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { zval *options, *mongo; zval *server = NULL, *database = NULL, *collection = NULL; options = phalcon_read_property(getThis(), SL("_options"), PH_NOISY); /** * If mongo is defined a valid Mongo object must be passed */ if (phalcon_array_isset_str_fetch(&mongo, options, SL("mongo"))) { if (Z_TYPE_P(mongo) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The 'mongo' parameter must be a valid Mongo instance"); return; } } else { /** * Server must be defined otherwise */ phalcon_array_isset_str_fetch(&server, options, SL("server")); if (!server || Z_TYPE_P(server) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB connection string"); return; } ce0 = zend_fetch_class(SSL("MongoClient"), ZEND_FETCH_CLASS_AUTO); PHALCON_INIT_VAR(mongo); object_init_ex(mongo, ce0); assert(phalcon_has_constructor(mongo)); PHALCON_CALL_METHOD(NULL, mongo, "__construct", server); } /** * Check if the database name is a string */ phalcon_array_isset_str_fetch(&database, options, SL("db")); if (!database || Z_TYPE_P(database) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB db"); return; } /** * Retrieve the connection name */ phalcon_array_isset_str_fetch(&collection, options, SL("collection")); if (!collection || Z_TYPE_P(collection) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB collection"); return; } /** * Make the connection and get the collection */ PHALCON_RETURN_CALL_METHOD(mongo, "selectcollection", database, collection); } else { RETVAL_ZVAL(mongo_collection, 1, 0); } PHALCON_MM_RESTORE(); }