コード例 #1
0
ファイル: adapter.c プロジェクト: Myleft/cphalcon7
/**
 * Sets base path
 *
 * @param string $basePath
 * @return Phalcon\Config\Adapter
 */
PHP_METHOD(Phalcon_Config_Adapter, setBasePath){

	zval *base_path;

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

	phalcon_add_trailing_slash(base_path);
	phalcon_update_static_property_ce(phalcon_config_adapter_ce, SL("_basePath"), base_path);
}
コード例 #2
0
ファイル: di.c プロジェクト: googlle/cphalcon7
/**
 * Phalcon\DI constructor
 *
 */
PHP_METHOD(Phalcon_DI, __construct){

	zval *default_di;

	default_di = phalcon_read_static_property_ce(phalcon_di_ce, SL("_default"));
	if (Z_TYPE_P(default_di) == IS_NULL) {
		phalcon_update_static_property_ce(phalcon_di_ce, SL("_default"), getThis());
	}
}
コード例 #3
0
ファイル: di.c プロジェクト: googlle/cphalcon7
/**
 * Set a default dependency injection container to be obtained into static methods
 *
 * @param Phalcon\DiInterface $dependencyInjector
 */
PHP_METHOD(Phalcon_DI, setDefault){

	zval *dependency_injector;

	phalcon_fetch_params(0, 1, 0, &dependency_injector);
	PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_di_exception_ce, 0);

	phalcon_update_static_property_ce(phalcon_di_ce, SL("_default"), dependency_injector);
}
コード例 #4
0
ファイル: debug.c プロジェクト: Myleft/cphalcon
/**
 * Sets the character set used to display the HTML
 *
 * @brief \Phalcon\Debug \Phalcon\Debug::setCharset(string $charset)
 * @param string $charset
 * @return \Phalcon\Debug
 */
PHP_METHOD(Phalcon_Debug, setCharset) {

	zval **charset;

	phalcon_fetch_params_ex(1, 0, &charset);
	PHALCON_ENSURE_IS_STRING(charset);

	phalcon_update_static_property_ce(phalcon_debug_ce, SL("_charset"), *charset TSRMLS_CC);
	RETURN_THISW();
}
コード例 #5
0
ファイル: route.c プロジェクト: 100851766/cphalcon
/**
 * Phalcon\Mvc\Router\Route constructor
 *
 * @param string $pattern
 * @param array $paths
 * @param array|string $httpMethods
 */
PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){

	zval *pattern, *paths = NULL, *http_methods = NULL, *unique_id = NULL;
	zval *route_id = NULL;
	int separate = 0;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods);
	
	if (!paths) {
		paths = PHALCON_GLOBAL(z_null);
	}
	
	if (!http_methods) {
		http_methods = PHALCON_GLOBAL(z_null);
	}
	
	/** 
	 * Configure the route (extract parameters, paths, etc)
	 */
	PHALCON_CALL_METHOD(NULL, this_ptr, "reconfigure", pattern, paths);
	
	/** 
	 * Update the HTTP method constraints
	 */
	phalcon_update_property_this(this_ptr, SL("_methods"), http_methods TSRMLS_CC);
	
	/** 
	 * Get the unique Id from the static member _uniqueId
	 */
	unique_id = phalcon_fetch_static_property_ce(phalcon_mvc_router_route_ce, SL("_uniqueId") TSRMLS_CC);
	if (Z_REFCOUNT_P(unique_id) > 1) {
		PHALCON_INIT_VAR(unique_id);
		separate = 1;
	}

	if (Z_TYPE_P(unique_id) == IS_NULL) {
		ZVAL_LONG(unique_id, 0);
	}
	
	PHALCON_CPY_WRT_CTOR(route_id, unique_id); /* route_id is now separated from unique_id */
	phalcon_update_property_this(this_ptr, SL("_id"), route_id TSRMLS_CC);
	
	/* increment_function() will increment the value of the static property as well */
	increment_function(unique_id);
	if (separate) {
		phalcon_update_static_property_ce(phalcon_mvc_router_route_ce, SL("_uniqueId"), unique_id TSRMLS_CC);
	}
	
	PHALCON_MM_RESTORE();
}
コード例 #6
0
ファイル: gd.c プロジェクト: dreamsxin/cphalcon7
/**
 * Checks if GD is enabled
 *
 * @return  boolean
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, check){

	zval gd_version = {}, ret = {}, gd_info = {}, version = {}, exception_message = {}, pattern = {}, matches = {};

	if (phalcon_function_exists_ex(SL("gd_info")) == FAILURE) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_image_exception_ce, "GD is either not installed or not enabled, check your configuration");
		return;
	}

	if (!phalcon_get_constant(&gd_version, SL("GD_VERSION"))) {
		PHALCON_CALL_FUNCTIONW(&gd_info, "gd_info");

		if (phalcon_array_isset_fetch_str(&gd_version, &gd_info, SL("GD Version"))) {
			ZVAL_STRING(&pattern, "#\\d+\\.\\d+(?:\\.\\d+)?#");
			ZVAL_NULL(&matches);
			ZVAL_MAKE_REF(&matches);
			RETURN_ON_FAILURE(phalcon_preg_match(&ret, &pattern, &gd_version, &matches));
			ZVAL_UNREF(&matches);

			if (zend_is_true(&ret)) {
				if (!phalcon_array_isset_fetch_long(&version, &matches, 0)) {
					ZVAL_EMPTY_STRING(&version);
				}
			} else {
				ZVAL_EMPTY_STRING(&version);
			}
		} else {
			PHALCON_CPY_WRT_CTOR(&version, &gd_version);
		}
	}

	if (-1 == php_version_compare(Z_STRVAL_P(&gd_version), "2.0.1")) {
		PHALCON_CONCAT_SV(&exception_message, "Phalcon\\Image\\Adapter\\GD requires GD version '2.0.1' or greater, you have '", &gd_version);
		PHALCON_THROW_EXCEPTION_ZVALW(phalcon_image_exception_ce, &exception_message);
		return;
	}

	phalcon_update_static_property_ce(phalcon_image_adapter_gd_ce, SL("_checked"), &PHALCON_GLOBAL(z_true));

	RETURN_TRUE;
}
コード例 #7
0
ファイル: firephp.c プロジェクト: Myleft/cphalcon7
/**
 * Writes the log to the stream itself
 *
 * @param string $message
 * @param int $type
 * @param int $time
 * @param array $context
 * @see http://www.firephp.org/Wiki/Reference/Protocol
 */
PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){

	zval *message, *type, *time, *context, *formatter = NULL, *applied_format = NULL;
	zval *initialized, *index;
	sapi_header_line h = { NULL, 0, 0 };
	smart_str str      = { 0 };
	int size, offset;
	int separate_index = 0;
	size_t num_bytes;
	const int chunk = 4500;

	/* If headers has already been sent, we can do nothing. Exit early. */
	if (SG(headers_sent)) {
		RETURN_FALSE;
	}

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 4, 0, &message, &type, &time, &context);

	PHALCON_CALL_METHOD(&formatter, getThis(), "getformatter");

	initialized = phalcon_read_static_property_ce(phalcon_logger_adapter_firephp_ce, SL("_initialized"));
	if (!zend_is_true(initialized)) {
		/**
		 * Send the required initialization headers.
		 * Use Zend API here so that the user can see the progress and because
		 * if we delegate this to Phalcon and there will be a fatal errors,
		 * chances are that the headers will never ne sent.
		 */
		h.line     = "X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2";
		h.line_len = sizeof("X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2")-1;
		sapi_header_op(SAPI_HEADER_REPLACE, &h);

		h.line     = "X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3";
		h.line_len = sizeof("X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")-1;
		sapi_header_op(SAPI_HEADER_REPLACE, &h);

		h.line     = "X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1";
		h.line_len = sizeof("X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")-1;
		sapi_header_op(SAPI_HEADER_REPLACE, &h);

		ZVAL_TRUE(initialized); /* This will also update the property because "initialized" was not separated */
	}

	PHALCON_CALL_METHOD(&applied_format, formatter, "format", message, type, time, context);
	convert_to_string(applied_format);

	index = phalcon_read_static_property_ce(phalcon_logger_adapter_firephp_ce, SL("_index"));
	assert(Z_TYPE_P(index) == IS_LONG);

	size   = Z_STRLEN_P(applied_format);
	offset = 0;

	/**
	 * We need to send the data in chunks not exceeding 5,000 bytes.
	 * Allocate the smart string once to avoid performance penalties.
	 */
	num_bytes = smart_str_alloc(&str, (uint)(size > chunk ? chunk : size), 0);

	while (size > 0) {
		smart_str_appends(&str, "X-Wf-1-1-1-");
		smart_str_append_long(&str, Z_LVAL_P(index));
		smart_str_appends(&str, ": ");
		num_bytes = size > chunk ? chunk : size;

		if (offset) {
			/* This is not the first chunk, prepend the payload with "|" */
			smart_str_appendc(&str, '|');
		}

		/* Grab the chunk from the encoded string */
		smart_str_appendl(&str, Z_STRVAL_P(applied_format) + offset, num_bytes);

		size   -= num_bytes;
		offset += num_bytes;

		if (size) {
			/* If we have more data to send, append "|/" */
			smart_str_appendl(&str, "|\\", 2);
		}

		smart_str_0(&str); /* Not strictly necessary but just to be safe */

		/* Send the result */
		h.line     = str.s->val;
		h.line_len = str.s->len;
		sapi_header_op(SAPI_HEADER_REPLACE, &h);

		ZVAL_LONG(index, Z_LVAL_P(index)+1);

		/**
		 * Do not free and then reallocate memory. Just pretend the string
		 * is empty. We will take care of deallocation later.
		 */
		str.s->len = 0;
	}

	if (separate_index) {
		phalcon_update_static_property_ce(phalcon_logger_adapter_firephp_ce, SL("_index"), index);
	}

	/* Deallocate the smnart string if it is not empty */
	smart_str_free(&str);

	PHALCON_MM_RESTORE();
}
コード例 #8
0
ファイル: header.c プロジェクト: Myleft/cphalcon
/**
 * Phalcon\Http\Client\Header constructor
 */
PHP_METHOD(Phalcon_Http_Client_Header, __construct){

	zval *messages;

	PHALCON_MM_GROW();

	PHALCON_INIT_VAR(messages);
	array_init(messages);

	phalcon_array_update_long_string(&messages, 100, SL("Continue"), PH_COPY);
	phalcon_array_update_long_string(&messages, 101, SL("Switching Protocols"), PH_COPY);

	phalcon_array_update_long_string(&messages, 200, SL("OK"), PH_COPY);
	phalcon_array_update_long_string(&messages, 201, SL("Created"), PH_COPY);
	phalcon_array_update_long_string(&messages, 202, SL("Accepted"), PH_COPY);
	phalcon_array_update_long_string(&messages, 203, SL("Non-Authoritative Information"), PH_COPY);
	phalcon_array_update_long_string(&messages, 204, SL("No Content"), PH_COPY);
	phalcon_array_update_long_string(&messages, 205, SL("Reset Content"), PH_COPY);
	phalcon_array_update_long_string(&messages, 206, SL("Partial Content"), PH_COPY);

	phalcon_array_update_long_string(&messages, 300, SL("Multiple Choices"), PH_COPY);
	phalcon_array_update_long_string(&messages, 301, SL("Moved Permanently"), PH_COPY);
	phalcon_array_update_long_string(&messages, 302, SL("Found"), PH_COPY);
	phalcon_array_update_long_string(&messages, 303, SL("See Other"), PH_COPY);
	phalcon_array_update_long_string(&messages, 304, SL("Not Modified"), PH_COPY);
	phalcon_array_update_long_string(&messages, 305, SL("Use Proxy"), PH_COPY);
	phalcon_array_update_long_string(&messages, 306, SL("(Unused)"), PH_COPY);
	phalcon_array_update_long_string(&messages, 307, SL("Temporary Redirect"), PH_COPY);

	phalcon_array_update_long_string(&messages, 400, SL("Bad Request"), PH_COPY);
	phalcon_array_update_long_string(&messages, 401, SL("Unauthorized"), PH_COPY);
	phalcon_array_update_long_string(&messages, 402, SL("Payment Required"), PH_COPY);
	phalcon_array_update_long_string(&messages, 403, SL("Forbidden"), PH_COPY);
	phalcon_array_update_long_string(&messages, 404, SL("Not Found"), PH_COPY);
	phalcon_array_update_long_string(&messages, 405, SL("Method Not Allowed"), PH_COPY);
	phalcon_array_update_long_string(&messages, 406, SL("Not Acceptable"), PH_COPY);
	phalcon_array_update_long_string(&messages, 407, SL("Proxy Authentication Required"), PH_COPY);
	phalcon_array_update_long_string(&messages, 408, SL("Request Timeout"), PH_COPY);
	phalcon_array_update_long_string(&messages, 409, SL("Conflict"), PH_COPY);
	phalcon_array_update_long_string(&messages, 410, SL("Gone"), PH_COPY);
	phalcon_array_update_long_string(&messages, 411, SL("Length Required"), PH_COPY);
	phalcon_array_update_long_string(&messages, 412, SL("Precondition Failed"), PH_COPY);
	phalcon_array_update_long_string(&messages, 413, SL("Request Entity Too Large"), PH_COPY);
	phalcon_array_update_long_string(&messages, 414, SL("Request-URI Too Long"), PH_COPY);
	phalcon_array_update_long_string(&messages, 415, SL("Unsupported Media Type"), PH_COPY);
	phalcon_array_update_long_string(&messages, 416, SL("Requested Range Not Satisfiable"), PH_COPY);
	phalcon_array_update_long_string(&messages, 417, SL("Expectation Failed"), PH_COPY);
	
	phalcon_array_update_long_string(&messages, 500, SL("Internal Server Error"), PH_COPY);
	phalcon_array_update_long_string(&messages, 501, SL("Not Implemented"), PH_COPY);
	phalcon_array_update_long_string(&messages, 502, SL("Bad Gateway"), PH_COPY);
	phalcon_array_update_long_string(&messages, 503, SL("Service Unavailable"), PH_COPY);
	phalcon_array_update_long_string(&messages, 504, SL("Gateway Timeout"), PH_COPY);
	phalcon_array_update_long_string(&messages, 505, SL("HTTP Version Not Supported"), PH_COPY);
	phalcon_array_update_long_string(&messages, 506, SL("Bandwidth Limit Exceeded"), PH_COPY);

	phalcon_update_static_property_ce(phalcon_http_client_header_ce, SL("_messages"), messages TSRMLS_CC);
	phalcon_update_property_empty_array(this_ptr, SL("_fields") TSRMLS_CC);

	PHALCON_MM_RESTORE();
}