Beispiel #1
0
PHP_METHOD(Phalcon_Mvc_Collection_GridFS, create){

	zval *filename = NULL, *data = NULL, *white_list = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 3, &filename, &data, &white_list);

	if (!filename) {
		filename = &PHALCON_GLOBAL(z_null);
	}

	if (!data) {
		data = &PHALCON_GLOBAL(z_null);
	}

	if (!white_list) {
		white_list = &PHALCON_GLOBAL(z_null);
	}

	PHALCON_RETURN_CALL_METHOD(getThis(), "save", filename, data, white_list, &PHALCON_GLOBAL(z_true));
	RETURN_MM();
}
Beispiel #2
0
/**
 *
 * @param string $session_id optional, session id
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Session_Adapter_Memcache, destroy){

	zval *sid = NULL;
	zval *memcache;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &sid);

	if (!sid) {
		PHALCON_INIT_VAR(sid);
		PHALCON_CALL_SELF(&sid, "getid");
	}

	memcache = phalcon_fetch_nproperty_this(this_ptr, SL("_memcache"), PH_NOISY TSRMLS_CC);

	if (Z_TYPE_P(memcache) == IS_OBJECT) {
		PHALCON_RETURN_CALL_METHOD(memcache, "delete", sid);

		RETURN_MM();
	} else {
		RETURN_MM_FALSE;
	}
}
Beispiel #3
0
/**
 * Returns the cookie's value
 *
 * @param string|array $filters
 * @param string $defaultValue
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Cookie, getValue){

	zval *filters = NULL, *default_value = NULL, *restored, *dependency_injector = NULL;
	zval *readed, *name, *_COOKIE, *value = NULL, *encryption;
	zval *service = NULL, *crypt = NULL, *decrypted_value = NULL, *filter = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(0, 0, 2, &filters, &default_value);

	if (!filters) {
		filters = &PHALCON_GLOBAL(z_null);
	}

	if (!default_value) {
		default_value = &PHALCON_GLOBAL(z_null);
	}

	restored = phalcon_read_property(getThis(), SL("_restored"), PH_NOISY);
	if (!zend_is_true(restored)) {
		PHALCON_CALL_METHOD(NULL, getThis(), "restore");
	}

	PHALCON_INIT_VAR(dependency_injector);

	readed = phalcon_read_property(getThis(), SL("_readed"), PH_NOISY);
	if (PHALCON_IS_FALSE(readed)) {
		name = phalcon_read_property(getThis(), SL("_name"), PH_NOISY);

		_COOKIE = phalcon_get_global(SL("_COOKIE"));
		if (phalcon_array_isset_fetch(&value, _COOKIE, name)) {
			encryption = phalcon_read_property(getThis(), SL("_useEncryption"), PH_NOISY);
			if (zend_is_true(encryption)) {
				dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY);
				if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
					PHALCON_THROW_EXCEPTION_STR(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'filter' service");
					return;
				}

				PHALCON_INIT_VAR(service);
				ZVAL_STRING(service, "crypt");

				PHALCON_CALL_METHOD(&crypt, dependency_injector, "getshared", service);
				PHALCON_VERIFY_INTERFACE(crypt, phalcon_cryptinterface_ce);

				/** 
				 * Decrypt the value also decoding it with base64
				 */
				PHALCON_CALL_METHOD(&decrypted_value, crypt, "decryptbase64", value);
			} else {
				PHALCON_CPY_WRT(decrypted_value, value);
			}

			/** 
			 * Update the decrypted value
			 */
			phalcon_update_property_this(getThis(), SL("_value"), decrypted_value);
			if (Z_TYPE_P(filters) != IS_NULL) {
				filter = phalcon_read_property(getThis(), SL("_filter"), PH_NOISY);
				if (Z_TYPE_P(filter) != IS_OBJECT) {
					if (Z_TYPE_P(dependency_injector) == IS_NULL) {
						dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY);
						PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_http_cookie_exception_ce, 1);
					}

					PHALCON_INIT_NVAR(service);
					ZVAL_STR(service, IS(filter));

					PHALCON_CALL_METHOD(&filter, dependency_injector, "getshared", service);
					PHALCON_VERIFY_INTERFACE(filter, phalcon_filterinterface_ce);
					phalcon_update_property_this(getThis(), SL("_filter"), filter);
				}

				PHALCON_RETURN_CALL_METHOD(filter, "sanitize", decrypted_value, filters);
				RETURN_MM();
			}

			/** 
			 * Return the value without filtering
			 */

			RETURN_CTOR(decrypted_value);
		}

		RETURN_CTOR(default_value);
	}

	value = phalcon_read_property(getThis(), SL("_value"), PH_NOISY);

	RETURN_CTOR(value);
}
Beispiel #4
0
/**
 * Returns a cached content
 *
 * @param int|string $keyName
 * @param   long $lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_File, get){

	zval *key_name, *lifetime = NULL;
	zval *options, *prefix, *prefixed_key, *cache_dir;
	zval *cache_file, *tmp = NULL;
	zval *modified_time;
	zval *cached_content, *exception_message;
	long int now, ttl, mtime, diff;
	int expired;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &key_name, &lifetime);

	options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC);
	prefix  = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC);

	PHALCON_INIT_VAR(prefixed_key);
	PHALCON_CONCAT_VV(prefixed_key, prefix, key_name);
	phalcon_update_property_this(this_ptr, SL("_lastKey"), prefixed_key TSRMLS_CC);

	if (unlikely(!phalcon_array_isset_string_fetch(&cache_dir, options, SS("cacheDir")))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options");
		return;
	}

	PHALCON_INIT_VAR(cache_file);
	PHALCON_CONCAT_VV(cache_file, cache_dir, prefixed_key);

	if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) {

		zval *frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC);

		/**
		 * Check if the file has expired
		 */
		now = (long int)time(NULL);

		/**
		 * Take the lifetime from the frontend or read it from the set in start()
		 */
		if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) {
			zval *last_lifetime = phalcon_fetch_nproperty_this(this_ptr, SL("_lastLifetime"), PH_NOISY TSRMLS_CC);

			if (Z_TYPE_P(last_lifetime) == IS_NULL) {
				PHALCON_CALL_METHOD(&tmp, frontend, "getlifetime");
				ttl = phalcon_get_intval(tmp);
			} else {
				ttl = phalcon_get_intval(last_lifetime);
			}
		} else {
			ttl = phalcon_get_intval(lifetime);
		}

		PHALCON_INIT_VAR(modified_time);
		phalcon_filemtime(modified_time, cache_file TSRMLS_CC);
		if (unlikely(Z_TYPE_P(modified_time) != IS_LONG)) {
			convert_to_long(modified_time);
		}

		mtime   = Z_LVAL_P(modified_time);
		diff    = now - ttl;
		expired = diff > mtime;

		/**
		 * The content is only retrieved if the content has not expired
		 */
		if (!expired) {

			/**
			 * Use file-get-contents to control that the openbase_dir can't be skipped
			 */
			PHALCON_INIT_VAR(cached_content);
			phalcon_file_get_contents(cached_content, cache_file TSRMLS_CC);
			if (PHALCON_IS_FALSE(cached_content)) {
				PHALCON_INIT_VAR(exception_message);
				PHALCON_CONCAT_SVS(exception_message, "Cache file ", cache_file, " could not be opened");
				PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cache_exception_ce, exception_message);
				return;
			}

			if (phalcon_is_numeric(cached_content)) {
				RETURN_CCTOR(cached_content);
			} else {
				/**
				 * Use the frontend to process the content of the cache
				 */
				PHALCON_RETURN_CALL_METHOD(frontend, "afterretrieve", cached_content);
			}

			RETURN_MM();
		}
	}

	RETURN_MM_NULL();
}
Beispiel #5
0
/**
 * Rollbacks the active transaction in the connection
 *
 * @param boolean $nesting
 * @return boolean
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){

	zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL;
	zval *event_name = NULL, *ntw_savepoint = NULL, *savepoint_name = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &nesting);

	if (!nesting) {
		nesting = PHALCON_GLOBAL(z_true);
	}

	pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY TSRMLS_CC);
	if (Z_TYPE_P(pdo) != IS_OBJECT) {
		RETURN_MM_FALSE;
	}

	/** 
	 * Check the transaction nesting level
	 */
	transaction_level = phalcon_fetch_nproperty_this(this_ptr, SL("_transactionLevel"), PH_NOISY TSRMLS_CC);
	if (!zend_is_true(transaction_level)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction");
		return;
	}

	if (PHALCON_IS_LONG(transaction_level, 1)) {
		events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY TSRMLS_CC);

		/** 
		 * Notify the events manager about the rollbacked transaction
		 */
		if (Z_TYPE_P(events_manager) == IS_OBJECT) {
			PHALCON_INIT_VAR(event_name);
			ZVAL_STRING(event_name, "db:rollbackTransaction", 1);
			PHALCON_CALL_METHOD(NULL, events_manager, "fire", event_name, this_ptr);
		}

		/** 
		 * Reduce the transaction nesting level
		 */
		phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC);
		PHALCON_RETURN_CALL_METHOD(pdo, "rollback");
		RETURN_MM();
	}

	if (zend_is_true(transaction_level)) {
		if (zend_is_true(nesting)) {
			PHALCON_CALL_METHOD(&ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints");
			if (zend_is_true(ntw_savepoint)) {

				events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY TSRMLS_CC);

				PHALCON_CALL_METHOD(&savepoint_name, this_ptr, "getnestedtransactionsavepointname");

				/**
				 * Notify the events manager about the rollbacked savepoint
				 */
				if (Z_TYPE_P(events_manager) == IS_OBJECT) {
					PHALCON_INIT_NVAR(event_name);
					ZVAL_STRING(event_name, "db:rollbackSavepoint", 1);
					PHALCON_CALL_METHOD(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name);
				}

				/**
				 * Reduce the transaction nesting level
				 */
				phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC);
				PHALCON_RETURN_CALL_METHOD(this_ptr, "rollbacksavepoint", savepoint_name);
				RETURN_MM();
			}
		}
	}

	/** 
	 * Reduce the transaction nesting level
	 */
	if (PHALCON_GT_LONG(transaction_level, 0)) {
		phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC);
	}

	RETURN_MM_FALSE;
}
Beispiel #6
0
/**
 * Starts a transaction in the connection
 *
 * @param boolean $nesting
 * @return boolean
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){

	zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL;
	zval *event_name = NULL, *ntw_savepoint = NULL, *savepoint_name = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &nesting);

	if (!nesting) {
		nesting = PHALCON_GLOBAL(z_true);
	}

	pdo = phalcon_fetch_nproperty_this(this_ptr, SL("_pdo"), PH_NOISY TSRMLS_CC);
	if (Z_TYPE_P(pdo) != IS_OBJECT) {
		RETURN_MM_FALSE;
	}

	/** 
	 * Increase the transaction nesting level
	 */
	phalcon_property_incr(this_ptr, SL("_transactionLevel") TSRMLS_CC);

	/** 
	 * Check the transaction nesting level
	 */
	transaction_level = phalcon_fetch_nproperty_this(this_ptr, SL("_transactionLevel"), PH_NOISY TSRMLS_CC);
	if (PHALCON_IS_LONG(transaction_level, 1)) {

		events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY TSRMLS_CC);

		/** 
		 * Notify the events manager about the started transaction
		 */
		if (Z_TYPE_P(events_manager) == IS_OBJECT) {
			PHALCON_INIT_VAR(event_name);
			ZVAL_STRING(event_name, "db:beginTransaction", 1);
			PHALCON_CALL_METHOD(NULL, events_manager, "fire", event_name, this_ptr);
		}

		PHALCON_RETURN_CALL_METHOD(pdo, "begintransaction");
		RETURN_MM();
	}

	if (zend_is_true(transaction_level)) {
		if (zend_is_true(nesting)) {
			PHALCON_CALL_METHOD(&ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints");
			if (zend_is_true(ntw_savepoint)) {
				events_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY TSRMLS_CC);

				PHALCON_CALL_METHOD(&savepoint_name, this_ptr, "getnestedtransactionsavepointname");

				/**
				 * Notify the events manager about the created savepoint
				 */
				if (Z_TYPE_P(events_manager) == IS_OBJECT) {
					PHALCON_INIT_NVAR(event_name);
					ZVAL_STRING(event_name, "db:createSavepoint", 1);
					PHALCON_CALL_METHOD(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name);
				}

				PHALCON_RETURN_CALL_METHOD(this_ptr, "createsavepoint", savepoint_name);
				RETURN_MM();
			}
		}
	}

	RETURN_MM_FALSE;
}
Beispiel #7
0
/**
 * Returns a MongoDb collection based on the backend parameters
 *
 * @return MongoCollection
 */
PHP_METHOD(Phalcon_Cache_Backend_Mongo, _getCollection){

	zval *mongo_collection, *mongo_database = NULL;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();

	mongo_collection = phalcon_fetch_nproperty_this(this_ptr, SL("_collection"), PH_NOISY TSRMLS_CC);
	if (Z_TYPE_P(mongo_collection) != IS_OBJECT) {
		zval *options, *mongo;
		zval *server = NULL, *database = NULL, *collection = NULL;

		options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC);
	
		/** 
		 * If mongo is defined a valid Mongo object must be passed
		 */
		if (phalcon_array_isset_string_fetch(&mongo, options, SS("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_string_fetch(&server, options, SS("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(SL("MongoClient"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
	
			PHALCON_INIT_VAR(mongo);
			object_init_ex(mongo, ce0);
			assert(phalcon_has_constructor(mongo TSRMLS_CC));
			PHALCON_CALL_METHOD(NULL, mongo, "__construct", server);
		}
	
		/** 
		 * Check if the database name is a string
		 */
		phalcon_array_isset_string_fetch(&database, options, SS("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_string_fetch(&collection, options, SS("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_CALL_METHOD(&mongo_database, mongo, "selectdb", database);
		PHALCON_RETURN_CALL_METHOD(mongo_database, "selectcollection", collection);
	}
	else {
		RETVAL_ZVAL(mongo_collection, 1, 0);
	}
	
	PHALCON_MM_RESTORE();
}
Beispiel #8
0
/**
 * Save the image. If the filename is omitted, the original image will
 * be overwritten.
 *
 * @param string $file new image path
 * @param int $quality quality of image: 1-100
 * @return boolean
 */
PHP_METHOD(Phalcon_Image_Adapter, save) {

    zval **fname = NULL, **q = NULL;
    zval *file, *quality;
    zval *ret = NULL, *dir, *constant;

    phalcon_fetch_params_ex(0, 2, &fname, &q);

    PHALCON_MM_GROW();

    if (!fname) {
        PHALCON_OBS_VAR(file);
        phalcon_read_property_this(&file, this_ptr, SL("_realpath"), PH_NOISY TSRMLS_CC);
        convert_to_string_ex(&file);
    }
    else {
        PHALCON_ENSURE_IS_STRING(fname);
        file = *fname;
    }

    PHALCON_INIT_VAR(quality);
    if (!q || Z_TYPE_PP(q) != IS_LONG) {
        ZVAL_LONG(quality, 100);
    } else if (Z_LVAL_PP(q) > 100) {
        ZVAL_LONG(quality, 100);
    } else if (Z_LVAL_PP(q) < 1) {
        ZVAL_LONG(quality, 1);
    } else {
        ZVAL_LONG(quality, Z_LVAL_PP(q));
    }

    PHALCON_CALL_FUNCTION(&ret, "is_file", file);

    if (zend_is_true(ret)) {
        PHALCON_CALL_FUNCTION(&ret, "is_writable", file);
        if (!zend_is_true(ret)) {
            zend_throw_exception_ex(phalcon_image_exception_ce, 0 TSRMLS_CC, "File must be writable: '%s'", Z_STRVAL_P(file));
            RETURN_MM();
        }
    } else {
        PHALCON_INIT_VAR(constant);
        if (!zend_get_constant(SL("PATHINFO_DIRNAME"), constant TSRMLS_CC)) {
            RETURN_MM();
        }

        PHALCON_CALL_FUNCTION(&ret, "pathinfo", file, constant);

        PHALCON_INIT_VAR(dir);
        phalcon_realpath(dir, ret TSRMLS_CC);
        convert_to_string(dir);

        PHALCON_INIT_NVAR(ret);
        phalcon_is_dir(ret, dir TSRMLS_CC);

        if (!zend_is_true(ret)) {
            zend_throw_exception_ex(phalcon_image_exception_ce, 0 TSRMLS_CC, "Directory must be writable: '%s'", Z_STRVAL_P(dir));
            RETURN_MM();
        }

        PHALCON_CALL_FUNCTION(&ret, "is_writable", dir);
        if (!zend_is_true(ret)) {
            zend_throw_exception_ex(phalcon_image_exception_ce, 0 TSRMLS_CC, "Directory must be writable: '%s'", Z_STRVAL_P(dir));
            RETURN_MM();
        }
    }

    PHALCON_RETURN_CALL_METHOD(this_ptr, "_save", file, quality);
    RETURN_MM();
}
Beispiel #9
0
PHP_METHOD(Phalcon_Mvc_Collection_GridFS, remove){

	zval *sha1 = NULL, *md5 = NULL, *source = NULL, *files_source;
	zval *connection = NULL, *mongo_collection = NULL;
	zval *criteria, *operation, *field, *value, *new_object;
	zval *status = NULL, *ok, *exist, *options, *grid_fs = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 2, &sha1, &md5);

	if (!sha1) {
		sha1 = phalcon_read_property(getThis(), SL("sha1"), PH_NOISY);
	}

	if (!md5) {
		md5 = phalcon_read_property(getThis(), SL("md5"), PH_NOISY);
	}

	PHALCON_CALL_METHOD(&source, getThis(), "getsource");

	PHALCON_INIT_VAR(files_source);
	PHALCON_CONCAT_VS(files_source, source, ".files");

	PHALCON_CALL_METHOD(&connection, getThis(), "getconnection");

	PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", files_source);
	if (Z_TYPE_P(mongo_collection) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo collection");
		return;
	}

	PHALCON_INIT_VAR(criteria);
	array_init_size(criteria, 2);

	phalcon_array_update_str(criteria, SL("md5"), md5, PH_COPY);
	phalcon_array_update_str(criteria, SL("sha1"), sha1, PH_COPY);

	PHALCON_INIT_VAR(operation);
	ZVAL_STRING(operation, "$inc");

	PHALCON_INIT_VAR(field);
	ZVAL_STRING(field, "use");

	PHALCON_INIT_VAR(value);
	ZVAL_LONG(value, -1)

	PHALCON_INIT_VAR(new_object);
	array_init_size(new_object, 1);

	phalcon_array_update_multi_2(new_object, operation, field, value, PH_COPY);
	
	PHALCON_CALL_METHOD(&status, mongo_collection, "update", criteria, new_object);

	if (phalcon_array_isset_str_fetch(&ok, status, SL("ok"))) {
		if (zend_is_true(ok)) {
			if (phalcon_array_isset_str_fetch(&exist, status, SL("updatedExisting"))) {
				if (!zend_is_true(exist)) {
					RETURN_MM_FALSE;
				}
			}
		} else {
			RETURN_MM_FALSE;
		}
	}

	PHALCON_CALL_METHOD(&grid_fs, connection, "getgridfs", source);
	if (Z_TYPE_P(grid_fs) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo GridFS");
		return;
	}

	PHALCON_INIT_NVAR(criteria);
	array_init_size(criteria, 3);

	phalcon_array_update_str(criteria, SL("sha1"), sha1, PH_COPY);
	phalcon_array_update_str(criteria, SL("md5"), md5, PH_COPY);

	PHALCON_INIT_NVAR(operation);
	ZVAL_STRING(operation, "$lte");

	PHALCON_INIT_NVAR(value);
	ZVAL_LONG(value, 0)

	phalcon_array_update_multi_2(criteria, field, operation, value, PH_COPY);

	PHALCON_INIT_VAR(options);
	array_init_size(options, 1);

	phalcon_array_update_str_long(options, SL("w"), 0, PH_COPY);

	PHALCON_RETURN_CALL_METHOD(grid_fs, "remove", criteria, options);
	RETURN_MM();
}
Beispiel #10
0
/**
 * Produces an string representation of a variable
 *
 * @param mixed $variable
 * @return string
 */
PHP_METHOD(Phalcon_Debug, _getVarDump){

	zval *variable, *class_name, *dumped_object = NULL;
	zval *array_dump = NULL, *dump = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &variable);

	if (PHALCON_IS_SCALAR(variable)) {

		/** 
		 * Boolean variables are represented as 'true'/'false'
		 */
		if (Z_TYPE_P(variable) == IS_BOOL) {
			if (zend_is_true(variable)) {
				RETURN_MM_STRING("true", 1);
			} else {
				RETURN_MM_STRING("false", 1);
			}
		}

		/** 
		 * String variables are escaped to avoid XSS injections
		 */
		if (Z_TYPE_P(variable) == IS_STRING) {
			PHALCON_RETURN_CALL_METHOD(this_ptr, "_escapestring", variable);
			RETURN_MM();
		}

		/** 
		 * Other scalar variables are just converted to strings
		 */

		RETURN_CTOR(variable);
	}

	/** 
	 * If the variable is an object print its class name
	 */
	if (Z_TYPE_P(variable) == IS_OBJECT) {
		const zend_class_entry *ce = Z_OBJCE_P(variable);

		PHALCON_INIT_VAR(class_name);
		ZVAL_STRINGL(class_name, ce->name, ce->name_length, !IS_INTERNED(ce->name));

		/** 
		 * Try to check for a 'dump' method, this surely produces a better printable
		 * representation
		 */
		if (phalcon_method_exists_ex(variable, SS("dump") TSRMLS_CC) == SUCCESS) {
			PHALCON_CALL_METHOD(&dumped_object, variable, "dump");

			/** 
			 * dump() must return an array, generate a recursive representation using
			 * getArrayDump
			 */
			PHALCON_CALL_METHOD(&array_dump, this_ptr, "_getarraydump", dumped_object);

			PHALCON_INIT_VAR(dump);
			PHALCON_CONCAT_SVSVS(dump, "Object(", class_name, ": ", array_dump, ")");
		} else {
			/** 
			 * If dump() is not available just print the class name
			 */
			PHALCON_INIT_NVAR(dump);
			PHALCON_CONCAT_SVS(dump, "Object(", class_name, ")</span>");
		}

		RETURN_CTOR(dump);
	}

	/** 
	 * Recursively process the array and enclose it in Array()
	 */
	if (Z_TYPE_P(variable) == IS_ARRAY) { 
		PHALCON_CALL_METHOD(&array_dump, this_ptr, "_getarraydump", variable);
		PHALCON_CONCAT_SVS(return_value, "Array(", array_dump, ")");
		RETURN_MM();
	}

	/** 
	 * Null variables are represented as 'null'
	 * Other types are represented by its type
	 */
	RETURN_MM_STRING(zend_zval_type_name(variable), 1);
}