예제 #1
0
파일: debug.c 프로젝트: Myleft/cphalcon
PHP_METHOD(Phalcon_Debug, getFileLink) {

	zval **file, **line, **format;

	phalcon_fetch_params_ex(3, 0, &file, &line, &format);

	PHALCON_ENSURE_IS_STRING(file);
	PHALCON_ENSURE_IS_STRING(line);

	if (Z_TYPE_PP(format) == IS_STRING) {
		char *tmp, *link;
		int tmp_len, link_len;
		zval z_link = zval_used_for_init;

		tmp  = php_str_to_str_ex(Z_STRVAL_PP(format), Z_STRLEN_PP(format), SL("%f"), Z_STRVAL_PP(file), Z_STRLEN_PP(file), &tmp_len, 1, NULL);
		link = php_str_to_str_ex(tmp, tmp_len, SL("%l"), Z_STRVAL_PP(line), Z_STRLEN_PP(line), &link_len, 1, NULL);

		ZVAL_STRINGL(&z_link, link, link_len, 0);

		efree(tmp);
		PHALCON_CONCAT_SVSVS(return_value, "<a href=\"", &z_link, "\">", *file, "</a>");
		efree(link);
	}
	else {
		RETVAL_ZVAL(*file, 1, 0);
	}
}
예제 #2
0
파일: reader.c 프로젝트: 100851766/cphalcon
/**
 * Parses a raw doc block returning the annotations found
 *
 * @param string $docBlock
 * @param string $file
 * @param int $line
 * @return array
 */
PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock)
{
	zval **doc_block, **file = NULL, **line = NULL;

	phalcon_fetch_params_ex(3, 0, &doc_block, &file, &line);

	PHALCON_ENSURE_IS_STRING(doc_block);
	PHALCON_ENSURE_IS_STRING(file);
	PHALCON_ENSURE_IS_LONG(line);

	RETURN_ON_FAILURE(phannot_parse_annotations(return_value, Z_STRVAL_PP(doc_block), Z_STRLEN_PP(doc_block), Z_STRVAL_PP(file), Z_LVAL_PP(line) TSRMLS_CC));
}
예제 #3
0
/**
 * @brief Phalcon\Registry Phalcon\Registry::unserialize(string $str)
 */
PHP_METHOD(Phalcon_Registry, unserialize){
	zval data = {}, *str, zv = {};
	php_unserialize_data_t var_hash;
	const unsigned char *buf, *max;

	phalcon_fetch_params(0, 1, 0, &str);
	PHALCON_ENSURE_IS_STRING(str);

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);

	if (zend_hash_num_elements(Z_ARRVAL(data))) {
		zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot call unserialize() on an already constructed object");
		return;
	}

	buf = (unsigned char*)(Z_STRVAL_P(str));
	max = buf + Z_STRLEN_P(str);

	PHP_VAR_UNSERIALIZE_INIT(var_hash);
	if (php_var_unserialize(&zv, &buf, max, &var_hash) && Z_TYPE(zv) == IS_ARRAY) {
		if (zend_hash_num_elements(Z_ARRVAL(zv)) != 0) {
			zend_hash_copy(Z_ARRVAL(data), Z_ARRVAL(zv), (copy_ctor_func_t) zval_add_ref);
		}
	} else {
		zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Bad parameters passed to Phalcon\\Registry::unserialize()");
	}

	zval_dtor(&zv);
	PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
}
예제 #4
0
파일: stream.c 프로젝트: googlle/cphalcon7
/**
 * Phalcon\Logger\Adapter\Stream constructor
 *
 * @param string $name
 * @param array $options
 */
PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct){

	zval *name, *options = NULL, mode = {}, stream = {};

	phalcon_fetch_params(0, 1, 1, &name, &options);
	PHALCON_ENSURE_IS_STRING(name);

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

	if (phalcon_array_isset_fetch_str(&mode, options, SL("mode"))) {
		if (phalcon_memnstr_str(&mode, SL("r"))) {
			PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "Stream must be opened in append or write mode");
			return;
		}
	} else {
		ZVAL_STRING(&mode, "ab");
	}

	/** 
	 * We use 'fopen' to respect to open-basedir directive
	 */
	PHALCON_CALL_FUNCTIONW(&stream, "fopen", name, &mode);
	if (Z_TYPE(stream) != IS_RESOURCE) {
		zend_throw_exception_ex(phalcon_logger_exception_ce, 0, "Cannot open stream '%s'", Z_STRVAL_P(name));
	} else {
		phalcon_update_property_this(getThis(), SL("_stream"), &stream);
	}
}
예제 #5
0
파일: di.c 프로젝트: googlle/cphalcon7
/**
 * Resolves a service, the resolved service is stored in the DI, subsequent requests for this service will return the same instance
 *
 * @param string $name
 * @param array $parameters
 * @return mixed
 */
PHP_METHOD(Phalcon_DI, getShared){

	zval *name, *parameters = NULL, *noerror = NULL, instance = {};

	phalcon_fetch_params(0, 1, 2, &name, &parameters, &noerror);
	PHALCON_ENSURE_IS_STRING(name);

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

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

	if (phalcon_isset_property_array(getThis(), SL("_sharedInstances"), name)) {
		phalcon_return_property_array(&instance, getThis(), SL("_sharedInstances"), name);
		phalcon_update_property_bool(getThis(), SL("_freshInstance"), 0);
	} else {
		PHALCON_CALL_SELFW(&instance, "get", name, parameters, noerror);
		if (zend_is_true(&instance)) {
			phalcon_update_property_bool(getThis(), SL("_freshInstance"), 1);
			phalcon_update_property_array(getThis(), SL("_sharedInstances"), name, &instance);
		}
	}

	RETURN_CTORW(&instance);
}
예제 #6
0
/**
 * Checks whether put has certain index
 *
 * @param string $name
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, hasPut)
{
	zval *name, is_put = {}, put = {}, raw = {}, new_put = {};
	char *tmp;

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

	PHALCON_CALL_METHODW(&is_put, getThis(), "isput");

	if (!zend_is_true(&is_put)) {
		phalcon_read_global_str(&new_put, SL("_PUT"));
	} else {
		phalcon_read_property(&put, getThis(), SL("_put"), PH_NOISY);
		if (Z_TYPE(put) != IS_ARRAY) {
			PHALCON_CALL_METHODW(&raw, getThis(), "getrawbody");

			array_init(&new_put);

			PHALCON_ENSURE_IS_STRING(&raw);
			tmp = estrndup(Z_STRVAL(raw), Z_STRLEN(raw));
			sapi_module.treat_data(PARSE_STRING, tmp, &new_put);

			phalcon_update_property_zval(getThis(), SL("_put"), &new_put);
		} else {
			PHALCON_CPY_WRT(&new_put, &put);
		}
	}

	RETVAL_BOOL(phalcon_array_isset(&new_put, name));
}
예제 #7
0
파일: crypt.c 프로젝트: dreamsxin/cphalcon7
/**
 * Decrypt a text that is coded as a base64 string
 *
 * @param string $text
 * @param string $key
 * @return string
 */
PHP_METHOD(Phalcon_Crypt, decryptBase64){

	zval *text, *key = NULL, *safe = NULL, decrypt_text = {}, decrypt_value = {};

	phalcon_fetch_params(0, 1, 2, &text, &key, &safe);
	PHALCON_ENSURE_IS_STRING(text);

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

	if (!safe) {
		safe = &PHALCON_GLOBAL(z_false);
	}

	if (zend_is_true(safe)) {
		ZVAL_NEW_STR(&decrypt_text, zend_string_dup(Z_STR_P(text), 0));
		php_strtr(Z_STRVAL(decrypt_text), Z_STRLEN(decrypt_text), "-_", "+/", 2);
	} else {
		PHALCON_CPY_WRT_CTOR(&decrypt_text, text);
	}

	phalcon_base64_decode(&decrypt_value, &decrypt_text);

	PHALCON_RETURN_CALL_METHODW(getThis(), "decrypt", &decrypt_value, key);
}
예제 #8
0
파일: files.c 프로젝트: dreamsxin/cphalcon7
/**
 * Writes parsed annotations to files
 *
 * @param string $key
 * @param Phalcon\Annotations\Reflection $data
 */
PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){

	zval *key, *data, annotations_dir = {}, virtual_key = {}, path = {}, php_export = {}, status = {};
	smart_str exp = { 0 };

	phalcon_fetch_params(0, 2, 0, &key, &data);
	PHALCON_ENSURE_IS_STRING(key);

	phalcon_return_property(&annotations_dir, getThis(), SL("_annotationsDir"));
	
	/** 
	 * Paths must be normalized before be used as keys
	 */
	phalcon_prepare_virtual_path_ex(&virtual_key, Z_STRVAL_P(key), Z_STRLEN_P(key), '_');

	PHALCON_CONCAT_VVS(&path, &annotations_dir, &virtual_key, ".php");
	
	smart_str_appends(&exp, "<?php return ");
	php_var_export_ex(data, 0, &exp);
	smart_str_appendc(&exp, ';');
	smart_str_0(&exp);

	ZVAL_STR(&php_export, exp.s);

	phalcon_file_put_contents(&status, &path, &php_export);
	if (PHALCON_IS_FALSE(&status)) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Annotations directory cannot be written");
		return;
	}
}
예제 #9
0
파일: php.c 프로젝트: googlle/cphalcon7
/**
 * Load config file
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Php, read){

	zval *file_path, *absolute_path = NULL, config_dir_path = {}, *base_path, config = {};

	phalcon_fetch_params(0, 1, 1, &file_path, &absolute_path);
	PHALCON_ENSURE_IS_STRING(file_path);

	if (absolute_path == NULL) {
		absolute_path = &PHALCON_GLOBAL(z_false);
	}

	if (zend_is_true(absolute_path)) {
		PHALCON_CPY_WRT(&config_dir_path, file_path);
	} else {
		base_path = phalcon_read_static_property_ce(phalcon_config_adapter_ce, SL("_basePath"));

		PHALCON_CONCAT_VV(&config_dir_path, base_path, file_path);
	}

	if (phalcon_require_ret(&config, Z_STRVAL(config_dir_path)) == FAILURE) {
		zend_throw_exception_ex(phalcon_config_exception_ce, 0, "Configuration file '%s' cannot be read", Z_STRVAL(config_dir_path));
		PHALCON_PTR_DTOR(&config_dir_path);
		return;
	}
	PHALCON_PTR_DTOR(&config_dir_path);

	if (Z_TYPE(config) == IS_ARRAY) {
		PHALCON_CALL_METHODW(NULL, getThis(), "val", &config);
	}
	PHALCON_PTR_DTOR(&config);
	RETURN_THISW();
}
예제 #10
0
파일: files.c 프로젝트: 100851766/cphalcon
/**
 * Reads meta-data from files
 *
 * @param string $key
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){

	zval **key, *meta_data_dir, *virtual_key;
	zval *path, *data = NULL;

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

	PHALCON_MM_GROW();

	meta_data_dir = phalcon_fetch_nproperty_this(this_ptr, SL("_metaDataDir"), PH_NOISY TSRMLS_CC);
	
	PHALCON_INIT_VAR(virtual_key);
	phalcon_prepare_virtual_path_ex(virtual_key, Z_STRVAL_PP(key), Z_STRLEN_PP(key), '_' TSRMLS_CC);
	
	PHALCON_INIT_VAR(path);
	PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php");
	
	if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) {
		RETURN_MM_ON_FAILURE(phalcon_require_ret(&data, Z_STRVAL_P(path) TSRMLS_CC));
		RETVAL_ZVAL(data, 1, 1);
	}
	
	PHALCON_MM_RESTORE();
}
예제 #11
0
파일: yaml.c 프로젝트: dreamsxin/cphalcon7
/**
 * Load config file
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Yaml, read){

	zval *file_path, *absolute_path = NULL, config_dir_path = {}, *base_path = NULL, config = {};

	phalcon_fetch_params(0, 1, 1, &file_path, &absolute_path);
	PHALCON_ENSURE_IS_STRING(file_path);

	if (absolute_path == NULL) {
		absolute_path = &PHALCON_GLOBAL(z_false);
	}

	if (zend_is_true(absolute_path)) {
		PHALCON_CPY_WRT_CTOR(&config_dir_path, file_path);
	} else {
		base_path = phalcon_read_static_property_ce(phalcon_config_adapter_ce, SL("_basePath"));

		PHALCON_CONCAT_VV(&config_dir_path, base_path, file_path);
	}

	PHALCON_CALL_FUNCTIONW(&config, "yaml_parse_file", &config_dir_path);

	if (Z_TYPE(config) == IS_ARRAY) {
		PHALCON_CALL_METHODW(NULL, getThis(), "val", &config);
	}

	RETURN_THISW();
}
예제 #12
0
파일: crypt.c 프로젝트: tianhendi/cphalcon
/**
 * Decrypt a text that is coded as a base64 string
 *
 * @param string $text
 * @param string $key
 * @return string
 */
PHP_METHOD(Phalcon_Crypt, decryptBase64){

	zval **text, **key = NULL, **safe = NULL, *decrypt_text;
	char *decoded;
	int decoded_len;

	phalcon_fetch_params_ex(1, 2, &text, &key, &safe);

	PHALCON_ENSURE_IS_STRING(text);
	if (!key) {
		key = &PHALCON_GLOBAL(z_null);
	}

	if (safe && zend_is_true(*safe)) {
		char *tmp = estrndup(Z_STRVAL_PP(text), Z_STRLEN_PP(text));
		php_strtr(tmp, Z_STRLEN_PP(text), "-_", "+/", 2);
		decoded = (char*)php_base64_decode((unsigned char*)tmp, Z_STRLEN_PP(text), &decoded_len);
		efree(tmp);
	}
	else {
		decoded = (char*)php_base64_decode((unsigned char*)(Z_STRVAL_PP(text)), Z_STRLEN_PP(text), &decoded_len);
	}

	if (!decoded) {
		RETURN_FALSE;
	}

	PHALCON_MM_GROW();
	PHALCON_ALLOC_GHOST_ZVAL(decrypt_text);
	ZVAL_STRINGL(decrypt_text, decoded, decoded_len, 0);
	PHALCON_RETURN_CALL_METHOD(this_ptr, "decrypt", decrypt_text, *key);
	RETURN_MM();
}
예제 #13
0
파일: escaper.c 프로젝트: googlle/cphalcon7
/**
 * Sets the encoding to be used by the escaper
 *
 *<code>
 * $escaper->setEncoding('utf-8');
 *</code>
 *
 * @param string $encoding
 */
PHP_METHOD(Phalcon_Escaper, setEncoding){

	zval *encoding;

	phalcon_fetch_params(0, 1, 0, &encoding);
	PHALCON_ENSURE_IS_STRING(encoding);
	phalcon_update_property_this(getThis(), SL("_encoding"), encoding);
}
예제 #14
0
/**
 * Sets the encoding to be used by the escaper
 *
 *<code>
 * $escaper->setEncoding('utf-8');
 *</code>
 *
 * @param string $encoding
 */
PHP_METHOD(Phalcon_Escaper, setEncoding){

	zval **encoding;

	phalcon_fetch_params_ex(1, 0, &encoding);
	PHALCON_ENSURE_IS_STRING(encoding);
	phalcon_update_property_this(this_ptr, SL("_encoding"), *encoding TSRMLS_CC);
}
예제 #15
0
/**
 * Phalcon\Session\Bag constructor
 *
 * @param string $name
 */
PHP_METHOD(Phalcon_Session_Bag, __construct){

	zval **name;

	phalcon_fetch_params_ex(1, 0, &name);
	PHALCON_ENSURE_IS_STRING(name);
	phalcon_update_property_this(this_ptr, SL("_name"), *name TSRMLS_CC);
}
예제 #16
0
/**
 * Phalcon\Mvc\Micro\LazyLoader constructor
 *
 * @param string $definition
 */
PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __construct){

	zval *definition;

	phalcon_fetch_params(0, 1, 0, &definition);
	PHALCON_ENSURE_IS_STRING(definition);

	phalcon_update_property_zval(getThis(), SL("_definition"), definition);
}
예제 #17
0
파일: di.c 프로젝트: googlle/cphalcon7
/**
 * Removes a service in the services container
 *
 * @param string $name
 */
PHP_METHOD(Phalcon_DI, remove){

	zval *name;

	phalcon_fetch_params(0, 1, 0, &name);
	PHALCON_ENSURE_IS_STRING(name);

	phalcon_unset_property_array(getThis(), SL("_services"), name);
}
예제 #18
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();
}
예제 #19
0
파일: crypt.c 프로젝트: dreamsxin/cphalcon7
/**
 * Sets the encryption key
 *
 * @param string $key
 * @return Phalcon\Encrypt
 */
PHP_METHOD(Phalcon_Crypt, setKey){

	zval *key;

	phalcon_fetch_params(0, 1, 0, &key);
	PHALCON_ENSURE_IS_STRING(key);

	phalcon_update_property_zval(getThis(), SL("_key"), key);
	RETURN_THISW();
}
예제 #20
0
파일: crypt.c 프로젝트: tianhendi/cphalcon
/**
 * Sets the encrypt/decrypt mode
 *
 * @param string $cipher
 * @return Phalcon\Encrypt
 */
PHP_METHOD(Phalcon_Crypt, setMode){

	zval **mode;

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

	phalcon_update_property_this(this_ptr, SL("_mode"), *mode TSRMLS_CC);
	RETURN_THISW();
}
예제 #21
0
파일: crypt.c 프로젝트: tianhendi/cphalcon
/**
 * Sets the encryption key
 *
 * @param string $key
 * @return Phalcon\Encrypt
 */
PHP_METHOD(Phalcon_Crypt, setKey){

	zval **key;

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

	phalcon_update_property_this(this_ptr, SL("_key"), *key TSRMLS_CC);
	RETURN_THISW();
}
예제 #22
0
/**
 * Registers a form in the Forms Manager
 *
 * @param string $name
 * @param Phalcon\Forms\Form $form
 * @return Phalcon\Forms\Manager
 */
PHP_METHOD(Phalcon_Forms_Manager, set){

	zval **name, **form;

	phalcon_fetch_params_ex(2, 0, &name, &form);
	PHALCON_ENSURE_IS_STRING(name);
	PHALCON_VERIFY_CLASS_EX(*form, phalcon_forms_form_ce, phalcon_forms_exception_ce, 0);
	
	phalcon_update_property_array(this_ptr, SL("_forms"), *name, *form TSRMLS_CC);
	RETURN_THISW();
}
예제 #23
0
파일: manager.c 프로젝트: googlle/cphalcon7
/**
 * Registers a form in the Forms Manager
 *
 * @param string $name
 * @param Phalcon\Forms\Form $form
 * @return Phalcon\Forms\Manager
 */
PHP_METHOD(Phalcon_Forms_Manager, set){

	zval *name, *form;

	phalcon_fetch_params(0, 2, 0, &name, &form);
	PHALCON_ENSURE_IS_STRING(name);
	PHALCON_VERIFY_CLASS_EX(form, phalcon_forms_form_ce, phalcon_forms_exception_ce, 0);

	phalcon_update_property_array(getThis(), SL("_forms"), name, form);
	RETURN_THISW();
}
예제 #24
0
파일: job.c 프로젝트: Myleft/cphalcon
/**
 * Phalcon\Queue\Beanstalk\Job
 *
 * @param Phalcon\Queue\Beanstalk $queue
 * @param string $id
 * @param mixed $body
 */
PHP_METHOD(Phalcon_Queue_Beanstalk_Job, __construct){

	zval **queue, **id, **body;

	phalcon_fetch_params_ex(3, 0, &queue, &id, &body);
	PHALCON_VERIFY_CLASS_EX(*queue, phalcon_queue_beanstalk_ce, phalcon_exception_ce, 0);
	PHALCON_ENSURE_IS_STRING(id);

	phalcon_update_property_this(this_ptr, SL("_queue"), *queue TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_id"),    *id    TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_body"),  *body  TSRMLS_CC);
}
예제 #25
0
파일: job.c 프로젝트: Myleft/cphalcon7
/**
 * Phalcon\Queue\Beanstalk\Job
 *
 * @param Phalcon\Queue\Beanstalk $queue
 * @param string $id
 * @param mixed $body
 */
PHP_METHOD(Phalcon_Queue_Beanstalk_Job, __construct){

	zval *queue, *id, *body;

	phalcon_fetch_params(0, 3, 0, &queue, &id, &body);
	PHALCON_VERIFY_CLASS_EX(queue, phalcon_queue_beanstalk_ce, phalcon_exception_ce, 0);
	PHALCON_ENSURE_IS_STRING(id);

	phalcon_update_property_this(getThis(), SL("_queue"), queue);
	phalcon_update_property_this(getThis(), SL("_id"),    id   );
	phalcon_update_property_this(getThis(), SL("_body"),  body );
}
예제 #26
0
파일: di.c 프로젝트: googlle/cphalcon7
/**
 * Registers an "always shared" service in the services container
 *
 * @param string $name
 * @param mixed $definition
 * @return Phalcon\DI\ServiceInterface
 */
PHP_METHOD(Phalcon_DI, setShared){

	zval *name, *definition;

	phalcon_fetch_params(0, 2, 0, &name, &definition);
	PHALCON_ENSURE_IS_STRING(name);

	object_init_ex(return_value, phalcon_di_service_ce);
	PHALCON_CALL_METHODW(NULL, return_value, "__construct", name, definition, &PHALCON_GLOBAL(z_true));

	phalcon_update_property_array(getThis(), SL("_services"), name, return_value);
}
예제 #27
0
파일: di.c 프로젝트: googlle/cphalcon7
/**
 * Check whether the DI contains a service by a name
 *
 * @param string $name
 * @return boolean
 */
PHP_METHOD(Phalcon_DI, has){

	zval *name;

	phalcon_fetch_params(0, 1, 0, &name);
	PHALCON_ENSURE_IS_STRING(name);
	
	if (phalcon_isset_property_array(getThis(), SL("_services"), name)) {
		RETURN_TRUE;
	}

	RETURN_FALSE;
}
예제 #28
0
파일: registry.c 프로젝트: Myleft/cphalcon7
/**
 * @brief void Phalcon\Registry::__call(string $name, array $arguments)
 */
PHP_METHOD(Phalcon_Registry, __call){
	zval *name, *arguments, *callback;

	phalcon_fetch_params(0, 2, 0, &name, &arguments);
	PHALCON_ENSURE_IS_STRING(name);

	if (phalcon_isset_property_array(getThis(), SL("_data"), name)) {
		callback = phalcon_read_property_array(getThis(), SL("_data"), name);
		PHALCON_RETURN_CALL_ZVAL_FUNCTIONW(callback, arguments);
	} else {
		zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Call to undefined method Phalcon\\Registry::%s", Z_STRVAL_P(name));
	}
}
예제 #29
0
/**
 * Checks a plain text password and its hash version to check if the password matches
 *
 * @param string $password
 * @param string $passwordHash
 * @param int $maxPasswordLength
 * @return boolean
 */
PHP_METHOD(Phalcon_Security, checkHash){

	zval **password, **password_hash, **max_pass_length = NULL, *hash;
	zval* params[2];
	int check = 0;

	phalcon_fetch_params_ex(2, 1, &password, &password_hash, &max_pass_length);
	
	PHALCON_ENSURE_IS_STRING(password);

	if (max_pass_length) {
		PHALCON_ENSURE_IS_LONG(max_pass_length);

		if (Z_LVAL_PP(max_pass_length) > 0 && Z_STRLEN_PP(password) > Z_LVAL_PP(max_pass_length)) {
			RETURN_FALSE;
		}
	}

	params[0] = *password;
	params[1] = *password_hash;

	ALLOC_INIT_ZVAL(hash);
	phalcon_call_func_params_w(hash, SL("crypt"), 2, params TSRMLS_CC);
	if (UNEXPECTED(EG(exception) != NULL)) {
		zval_ptr_dtor(&hash);
		RETURN_NULL();
	}

	if (UNEXPECTED(Z_TYPE_P(hash) != IS_STRING)) {
		convert_to_string(hash);
	}

	if (Z_STRLEN_P(hash) == Z_STRLEN_PP(password_hash)) {
		int n    = Z_STRLEN_P(hash);
		char *h1 = Z_STRVAL_P(hash);
		char *h2 = Z_STRVAL_PP(password_hash);

		while (n) {
			check |= ((unsigned int)*h1) ^ ((unsigned int)*h2);
			++h1;
			++h2;
			--n;
		}

		zval_ptr_dtor(&hash);
		RETURN_BOOL(check == 0);
	}

	zval_ptr_dtor(&hash);
	RETURN_FALSE;
}
예제 #30
0
/**
 * Gets a variable from put request
 *
 *<code>
 *	$userEmail = $request->getPut("user_email");
 *
 *	$userEmail = $request->getPut("user_email", "email");
 *</code>
 *
 * @param string $name
 * @param string|array $filters
 * @param mixed $defaultValue
 * @param boolean $notAllowEmpty
 * @param boolean $noRecursive
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, getPut)
{
	zval *name = NULL, *filters = NULL, *default_value = NULL, *not_allow_empty = NULL, *norecursive = NULL, is_put = {}, put = {}, raw = {}, new_put = {};
	char *tmp;

	phalcon_fetch_params(0, 0, 5, &name, &filters, &default_value, &not_allow_empty, &norecursive);

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

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

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

	if (!not_allow_empty) {
		not_allow_empty = &PHALCON_GLOBAL(z_false);
	}

	if (!norecursive) {
		norecursive = &PHALCON_GLOBAL(z_false);
	}

	PHALCON_CALL_METHODW(&is_put, getThis(), "isput");

	if (!zend_is_true(&is_put)) {
		RETURN_EMPTY_ARRAY();
	} else {
		phalcon_read_property(&put, getThis(), SL("_put"), PH_NOISY);
		if (Z_TYPE(put) != IS_ARRAY) {
			PHALCON_CALL_METHODW(&raw, getThis(), "getrawbody");

			array_init(&new_put);

			PHALCON_ENSURE_IS_STRING(&raw);
			tmp = estrndup(Z_STRVAL(raw), Z_STRLEN(raw));

			sapi_module.treat_data(PARSE_STRING, tmp, &new_put);

			phalcon_update_property_zval(getThis(), SL("_put"), &new_put);
		} else {
			PHALCON_CPY_WRT(&new_put, &put);
		}
	}

	PHALCON_RETURN_CALL_SELFW("_get", &new_put, name, filters, default_value, not_allow_empty, norecursive);
}