コード例 #1
0
ファイル: builder.c プロジェクト: dreamsxin/cphalcon7
/**
 * Create a new Query Builder for Delete
 *
 *
 * @return Phalcon\Mvc\Model\Query\Builder\Delete
 */
PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, createDeleteBuilder){

	zval *params = NULL, *_di = NULL, di = {}, service_name = {};

	phalcon_fetch_params(0, 0, 2, &params, &_di);

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

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

	if (Z_TYPE_P(_di) == IS_OBJECT) {
		PHALCON_VERIFY_INTERFACEW(_di, phalcon_diinterface_ce);
		PHALCON_CPY_WRT(&di, _di);
	} else {
		PHALCON_CALL_CE_STATICW(&di, phalcon_di_ce, "getdefault", _di);
	}

	PHALCON_STR(&service_name, ISV(modelsQueryBuilderForDelete));
	PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, &PHALCON_GLOBAL(z_null), &PHALCON_GLOBAL(z_true));
	if (Z_TYPE_P(return_value) != IS_OBJECT) {
		object_init_ex(return_value, phalcon_mvc_model_query_builder_delete_ce);
		PHALCON_CALL_METHODW(NULL, return_value, "__construct", params);
	}

	PHALCON_VERIFY_INTERFACEW(return_value, phalcon_mvc_model_query_builderinterface_ce);
}
コード例 #2
0
ファイル: date.c プロジェクト: dreamsxin/cphalcon7
/**
 * Executes the validation
 *
 * @param string $value
 * @return boolean
 */
PHP_METHOD(Phalcon_Validation_Validator_Date, valid){

	zval *value, *format = NULL, valid = {};

	phalcon_fetch_params(0, 1, 1, &value, &format);

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

	PHALCON_CALL_CE_STATICW(&valid, phalcon_date_ce, "valid", value, format);
	if (!zend_is_true(&valid)) {
		RETURN_FALSE;
	}

	RETURN_TRUE;
}
コード例 #3
0
ファイル: engine.c プロジェクト: googlle/cphalcon7
/**
 * Adds a user-defined method
 *
 * @param string $name
 * @param closure $methodCallable
 * @return Phalcon\Mvc\View\Engine
 */
PHP_METHOD(Phalcon_Mvc_View_Engine, addMethod){

	zval *name, *method_callable, class_name = {}, method = {};

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

	if (Z_TYPE_P(method_callable) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(method_callable), zend_ce_closure)) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Method must be an closure object");
		return;
	}

	phalcon_get_class(&class_name, getThis(), 0);

	PHALCON_CALL_CE_STATICW(&method, zend_ce_closure, "bind", method_callable, getThis(), &class_name);

	phalcon_update_property_array(getThis(), SL("_methods"), name, &method);
	RETURN_THISW();
}
コード例 #4
0
ファイル: builder.c プロジェクト: dreamsxin/cphalcon7
/**
 * Create a new Query Builder of the given type.
 *
 *<code>
 *	Phalcon\Mvc\Model\Query\Builder::create(Phalcon\Mvc\Model\Query::TYPE_SELECT);
 *</code>
 *
 * @return Phalcon\Mvc\Model\Query\Builder
 */
PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, create){

	zval *type, *params = NULL, *_di = NULL, di = {}, service_name = {}, has = {}, exception_message = {};

	phalcon_fetch_params(0, 1, 2, &type, &params, &_di);

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

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

	if (Z_TYPE_P(_di) == IS_OBJECT) {
		PHALCON_VERIFY_INTERFACEW(_di, phalcon_diinterface_ce);
		PHALCON_CPY_WRT(&di, _di);
	} else {
		PHALCON_CALL_CE_STATICW(&di, phalcon_di_ce, "getdefault", _di);
	}

	switch (phalcon_get_intval(type)) {
		case PHQL_T_SELECT:
			PHALCON_STR(&service_name, ISV(modelsQueryBuilderForSelect));
			PHALCON_CALL_METHODW(&has, &di, "has", &service_name);
			if (zend_is_true(&has)) {
				PHALCON_CALL_METHODW(return_value, &di, "get", &service_name);
			} else {
				object_init_ex(return_value, phalcon_mvc_model_query_builder_select_ce);
			}
			PHALCON_CALL_METHODW(NULL, return_value, "__construct", params);
			break;

		case PHQL_T_INSERT:
			PHALCON_STR(&service_name, ISV(modelsQueryBuilderForInsert));
			PHALCON_CALL_METHODW(&has, &di, "has", &service_name);
			if (zend_is_true(&has)) {
				PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, params);
			} else {
				object_init_ex(return_value, phalcon_mvc_model_query_builder_insert_ce);
			}
			PHALCON_CALL_METHODW(NULL, return_value, "__construct", params);
			break;

		case PHQL_T_UPDATE:
			PHALCON_STR(&service_name, ISV(modelsQueryBuilderForUpdate));
			PHALCON_CALL_METHODW(&has, &di, "has", &service_name);
			if (zend_is_true(&has)) {
				PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, params);
			} else {
				object_init_ex(return_value, phalcon_mvc_model_query_builder_delete_ce);
			}
			PHALCON_CALL_METHODW(NULL, return_value, "__construct", params);
			break;

		case PHQL_T_DELETE:
			PHALCON_STR(&service_name, ISV(modelsQueryBuilderForDelete));
			PHALCON_CALL_METHODW(&has, &di, "has", &service_name);
			if (zend_is_true(&has)) {
				PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, params);
			} else {
				object_init_ex(return_value, phalcon_mvc_model_query_builder_delete_ce);
			}
			PHALCON_CALL_METHODW(NULL, return_value, "__construct", params);
			break;

		default:
			PHALCON_CONCAT_SV(&exception_message, "Not found builder: ", type);
			PHALCON_THROW_EXCEPTION_ZVALW(phalcon_mvc_model_query_exception_ce, &exception_message);
			return;
	}

	PHALCON_VERIFY_INTERFACEW(return_value, phalcon_mvc_model_query_builderinterface_ce);
}
コード例 #5
0
ファイル: gd.c プロジェクト: dreamsxin/cphalcon7
/**
 * Phalcon\Image\GD constructor
 *
 * @param string $file
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, __construct){

	zval *file, *width = NULL, *height = NULL, exception_message = {}, checked = {}, realpath = {}, img_width = {}, img_height = {}, type = {}, mime = {}, format = {}, image = {}, imageinfo = {}, saveflag = {}, blendmode = {};

	phalcon_fetch_params(0, 1, 2, &file, &width, &height);

	if (Z_TYPE_P(file) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_image_exception_ce, "file parameter should be a string");
		return;
	}

	phalcon_return_static_property_ce(&checked, phalcon_image_adapter_gd_ce, SL("_checked"));

	if (!zend_is_true(&checked)) {
		PHALCON_CALL_CE_STATICW(NULL, phalcon_image_adapter_gd_ce, "check");
	}

	phalcon_update_property_zval(getThis(), SL("_file"), file);

	if (phalcon_file_exists(file) != FAILURE) {
		phalcon_file_realpath(&realpath, file);
		if (unlikely(Z_TYPE(realpath) != IS_STRING)) {
			convert_to_string(&realpath);
		}

		phalcon_update_property_zval(getThis(), SL("_realpath"), &realpath);

		PHALCON_CALL_FUNCTIONW(&imageinfo, "getimagesize", &realpath);

		if (phalcon_array_isset_fetch_long(&img_width, &imageinfo, 0)) {
			phalcon_update_property_zval(getThis(), SL("_width"), &img_width);
		}

		if (phalcon_array_isset_fetch_long(&img_height, &imageinfo, 1)) {
			phalcon_update_property_zval(getThis(), SL("_height"), &img_height);
		}

		if (phalcon_array_isset_fetch_long(&type, &imageinfo, 2)) {
			convert_to_long(&type);
			phalcon_update_property_zval(getThis(), SL("_type"), &type);
		} else {
			ZVAL_LONG(&type, -1);
		}

		if (phalcon_array_isset_fetch_str(&mime, &imageinfo, SL("mime"))) {
			convert_to_string(&mime);
			phalcon_update_property_zval(getThis(), SL("_mime"), &mime);
		}

		assert(Z_TYPE(type) == IS_LONG);

		switch (Z_LVAL(type)) {
			case 1: // GIF
				ZVAL_STRING(&format, "gif");
				PHALCON_CALL_FUNCTIONW(&image, "imagecreatefromgif", &realpath);
				break;

			case 2: // JPEG
				ZVAL_STRING(&format, "jpg");
				PHALCON_CALL_FUNCTIONW(&image, "imagecreatefromjpeg", &realpath);
				break;

			case 3: // PNG
				ZVAL_STRING(&format, "png");
				PHALCON_CALL_FUNCTIONW(&image, "imagecreatefrompng", &realpath);
				break;

			default:
				if (PHALCON_IS_NOT_EMPTY(&mime)) {
					zend_throw_exception_ex(phalcon_image_exception_ce, 0, "Installed GD does not support '%s' images", Z_STRVAL(mime));
				} else {
					zend_throw_exception_ex(phalcon_image_exception_ce, 0, "Installed GD does not support such images");
				}
				return;
		}

		if (Z_TYPE(image) != IS_RESOURCE) {
			assert(Z_TYPE(realpath) == IS_STRING);
			zend_throw_exception_ex(phalcon_image_exception_ce, 0, "Failed to create image from file '%s'", Z_STRVAL(realpath));
			return;
		}

		phalcon_update_property_zval(getThis(), SL("_format"), &format);

		ZVAL_TRUE(&saveflag);

		PHALCON_CALL_FUNCTIONW(NULL, "imagesavealpha", &image, &saveflag);
	} else if (width && height) {
		PHALCON_CALL_FUNCTIONW(&image, "imagecreatetruecolor", width, height);

		if (Z_TYPE(image) != IS_RESOURCE) {
			PHALCON_THROW_EXCEPTION_STRW(phalcon_image_exception_ce, "imagecreatetruecolor() failed");
			return;
		}

		ZVAL_TRUE(&blendmode);
		ZVAL_TRUE(&saveflag);

		PHALCON_CALL_FUNCTIONW(NULL, "imagealphablending", &image, &blendmode);
		PHALCON_CALL_FUNCTIONW(NULL, "imagesavealpha", &image, &saveflag);

		phalcon_update_property_zval(getThis(), SL("_realpath"), file);
		phalcon_update_property_zval(getThis(), SL("_width"), width);
		phalcon_update_property_zval(getThis(), SL("_height"), height);

		ZVAL_LONG(&type, 3);

		phalcon_update_property_zval(getThis(), SL("_type"), &type);

		ZVAL_STRING(&format, "png");

		phalcon_update_property_zval(getThis(), SL("_format"), &format);

		ZVAL_STRING(&mime, "image/png");

		phalcon_update_property_zval(getThis(), SL("_mime"), &mime);
	} else {
		PHALCON_CONCAT_SVS(&exception_message, "Failed to create image from file '", file, "'");
		PHALCON_THROW_EXCEPTION_ZVALW(phalcon_image_exception_ce, &exception_message);
		return;
	}

	phalcon_update_property_zval(getThis(), SL("_image"), &image);
}
コード例 #6
0
ファイル: service.c プロジェクト: dreamsxin/cphalcon7
/**
 * Resolves the service
 *
 * @param array $parameters
 * @param Phalcon\DIInterface $dependencyInjector
 * @return object
 */
PHP_METHOD(Phalcon_DI_Service, resolve){

	zval *parameters = NULL, *dependency_injector = NULL, name = {}, shared = {}, shared_instance = {}, definition = {}, builder = {};
	int found = 0, ishared = 0;

	phalcon_fetch_params(0, 0, 2, &parameters, &dependency_injector);

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

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

	phalcon_return_property(&shared, getThis(), SL("_shared"));
	phalcon_return_property(&shared_instance, getThis(), SL("_sharedInstance"));

	ishared = zend_is_true(&shared);

	/* Check if the service is shared */
	if (ishared && Z_TYPE(shared_instance) != IS_NULL) {
		RETURN_CTORW(&shared_instance);
	}

	phalcon_return_property(&definition, getThis(), SL("_definition"));

	if (Z_TYPE(definition) == IS_STRING) {
		/* String definitions can be class names without implicit parameters */
		if (phalcon_class_exists(&definition, 1) != NULL) {
			found = 1;
			if (Z_TYPE_P(parameters) == IS_ARRAY) {
				RETURN_ON_FAILURE(phalcon_create_instance_params(return_value, &definition, parameters));
			} else {
				RETURN_ON_FAILURE(phalcon_create_instance(return_value, &definition));
			}
		}
	} else if (likely(Z_TYPE(definition) == IS_OBJECT)) {
		/* Object definitions can be a Closure or an already resolved instance */
		found = 1;
		if (instanceof_function_ex(Z_OBJCE(definition), zend_ce_closure, 0)) {
			if (likely(Z_TYPE_P(dependency_injector) == IS_OBJECT)) {
				PHALCON_CALL_CE_STATICW(&definition, zend_ce_closure, "bind", &definition, dependency_injector);
			}
			if (Z_TYPE_P(parameters) == IS_ARRAY) {
				PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &definition, parameters);
			} else {
				PHALCON_CALL_USER_FUNCW(return_value, &definition);
			}
		} else {
			PHALCON_CPY_WRT(return_value, &definition);
		}
	} else if (Z_TYPE(definition) == IS_ARRAY) {
		found = 1;
		/* Array definitions require a 'className' parameter */
		object_init_ex(&builder, phalcon_di_service_builder_ce);

		PHALCON_CALL_METHODW(return_value, &builder, "build", dependency_injector, &definition, parameters);
	}

	if (!EG(exception)) {
		if (found) {
			if (ishared) {
				phalcon_update_property_zval(getThis(), SL("_sharedInstance"), return_value);
			}
			/* Update the shared instance if the service is shared */
			phalcon_update_property_bool(getThis(), SL("_resolved"), 1);
		} else {
			phalcon_return_property(&name, getThis(), SL("_name"));
			PHALCON_THROW_EXCEPTION_FORMATW(phalcon_di_exception_ce, "Service '%s' cannot be resolved", Z_STRVAL(name));
		}
	}
}