Exemple #1
0
/**
 * Adds a variable to the debug output
 *
 * @param mixed $var
 * @param string $key
 * @return Phalcon\Debug
 */
PHP_METHOD(Phalcon_Debug, debugVar){

	zval *var, *key = NULL, *ztime, *backtrace, *data;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &var, &key);
	
	if (!key) {
		PHALCON_INIT_VAR(key);
	}
	
	PHALCON_INIT_VAR(ztime);
	ZVAL_LONG(ztime, (long) time(NULL));
	
	PHALCON_INIT_VAR(backtrace);
	phalcon_call_func(backtrace, "debug_backtrace");
	
	PHALCON_INIT_VAR(data);
	array_init_size(data, 3);
	phalcon_array_append(&data, var, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&data, backtrace, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&data, ztime, PH_SEPARATE TSRMLS_CC);
	phalcon_update_property_array_append(this_ptr, SL("_data"), data TSRMLS_CC);
	RETURN_THIS();
}
Exemple #2
0
/**
 * Adds a resource to the annotations handler
 * A resource is a class that contains routing annotations
 *
 * @param string $handler
 * @param string $prefix
 * @return Phalcon\Mvc\Router\Annotations
 */
PHP_METHOD(Phalcon_Mvc_Router_Annotations, addResource){

	zval *handler, *prefix = NULL, *scope;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &handler, &prefix);
	
	if (!prefix) {
		prefix = PHALCON_GLOBAL(z_null);
	}
	
	if (Z_TYPE_P(handler) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The handler must be a class name");
		return;
	}
	
	PHALCON_INIT_VAR(scope);
	array_init_size(scope, 2);
	phalcon_array_append(&scope, prefix, 0);
	phalcon_array_append(&scope, handler, 0);
	phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_processed"), PHALCON_GLOBAL(z_false) TSRMLS_CC);
	
	RETURN_THIS();
}
Exemple #3
0
/**
 * Adds a resource to the ACL list
 *
 * Access names can be a particular action, by example
 * search, update, delete, etc or a list of them
 *
 * Example:
 * <code>
 * //Add a resource to the the list allowing access to an action
 * $acl->addResource(new Phalcon\Acl\Resource('customers'), 'search');
 * $acl->addResource('customers', 'search');
 *
 * //Add a resource  with an access list
 * $acl->addResource(new Phalcon\Acl\Resource('customers'), array('create', 'search'));
 * $acl->addResource('customers', array('create', 'search'));
 * </code>
 *
 * @param   Phalcon\Acl\Resource|string $resource
 * @param   array $accessList
 * @return  boolean
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){

	zval *resource, *access_list = NULL, *resource_name = NULL;
	zval *object = NULL, *resources_names;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &resource, &access_list);
	
	if (!access_list) {
		access_list = PHALCON_GLOBAL(z_null);
	}
	
	if (Z_TYPE_P(resource) == IS_OBJECT) {
		PHALCON_CALL_METHOD(&resource_name, resource, "getname");
		PHALCON_CPY_WRT(object, resource);
	} else {
		PHALCON_CPY_WRT(resource_name, resource);
	
		PHALCON_INIT_NVAR(object);
		object_init_ex(object, phalcon_acl_resource_ce);
		PHALCON_CALL_METHOD(NULL, object, "__construct", resource_name);
	
	}
	
	PHALCON_OBS_VAR(resources_names);
	phalcon_read_property_this(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY TSRMLS_CC);
	if (!phalcon_array_isset(resources_names, resource_name)) {
		phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC);
		phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, PHALCON_GLOBAL(z_true) TSRMLS_CC);
	}
	
	PHALCON_RETURN_CALL_METHOD(this_ptr, "addresourceaccess", resource_name, access_list);
	RETURN_MM();
}
Exemple #4
0
/**
 * Stops the active profile
 *
 * @return Phalcon\Db\Profiler
 */
PHP_METHOD(Phalcon_Db_Profiler, stopProfile){

	zval active_profile = {}, final_time = {}, initial_time = {}, difference = {}, total_seconds = {}, new_total_seconds = {};

	phalcon_read_property(&active_profile, getThis(), SL("_activeProfile"), PH_NOISY);

	PHALCON_CALL_FUNCTIONW(&final_time, "microtime", &PHALCON_GLOBAL(z_true));
	PHALCON_CALL_METHODW(NULL, &active_profile, "setfinaltime", &final_time);

	PHALCON_CALL_METHODW(&initial_time, &active_profile, "getinitialtime");

	phalcon_sub_function(&difference, &final_time, &initial_time);

	phalcon_read_property(&total_seconds, getThis(), SL("_totalSeconds"), PH_NOISY);

	phalcon_add_function(&new_total_seconds, &total_seconds, &difference);

	phalcon_update_property_zval(getThis(), SL("_totalSeconds"), &new_total_seconds);
	phalcon_update_property_array_append(getThis(), SL("_allProfiles"), &active_profile);

	if (phalcon_method_exists_ex(getThis(), SL("afterendprofile")) == SUCCESS) {
		PHALCON_CALL_METHODW(NULL, getThis(), "afterendprofile", &active_profile);
	}

	RETURN_THISW();
}
Exemple #5
0
/**
 * Adds a resource to the annotations handler
 * A resource is a class that contains routing annotations
 * The class is located in a module
 *
 * @param string $module
 * @param string $handler
 * @param string $prefix
 * @return Phalcon\Mvc\Router\Annotations
 */
PHP_METHOD(Phalcon_Mvc_Router_Annotations, addModuleResource){

	zval *module, *handler, *prefix = NULL, *scope;

	phalcon_fetch_params(0, 2, 1, &module, &handler, &prefix);
	
	if (!prefix) {
		prefix = PHALCON_GLOBAL(z_null);
	}
	
	if (Z_TYPE_P(module) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_router_exception_ce, "The module is not a valid string");
		return;
	}
	if (Z_TYPE_P(handler) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_router_exception_ce, "The handler must be a class name");
		return;
	}
	
	MAKE_STD_ZVAL(scope);
	array_init_size(scope, 3);
	phalcon_array_append(&scope, prefix, 0);
	phalcon_array_append(&scope, handler, 0);
	phalcon_array_append(&scope, module, 0);
	phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC);
	zval_ptr_dtor(&scope);

	phalcon_update_property_this(this_ptr, SL("_processed"), PHALCON_GLOBAL(z_false) TSRMLS_CC);
	
	RETURN_THISW();
}
/**
 * Adds a LEFT join to the query
 *
 *<code>
 *	$builder->leftJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
 *</code>
 *
 * @param string $model
 * @param string $conditions
 * @param string $alias
 * @return Phalcon\Mvc\Model\Query\Builder
 */
PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, leftJoin){

	zval *model, *conditions = NULL, *alias = NULL, *type, *join;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias);
	
	if (!conditions) {
		PHALCON_INIT_VAR(conditions);
	}
	
	if (!alias) {
		PHALCON_INIT_VAR(alias);
	}
	
	PHALCON_INIT_VAR(type);
	ZVAL_STRING(type, "LEFT", 1);
	
	PHALCON_INIT_VAR(join);
	array_init_size(join, 4);
	phalcon_array_append(&join, model, PH_SEPARATE);
	phalcon_array_append(&join, conditions, PH_SEPARATE);
	phalcon_array_append(&join, alias, PH_SEPARATE);
	phalcon_array_append(&join, type, PH_SEPARATE);
	phalcon_update_property_array_append(this_ptr, SL("_joins"), join TSRMLS_CC);
	RETURN_THIS();
}
Exemple #7
0
/**
 * Adds a variable to the debug output
 *
 * @param mixed $var
 * @param string $key
 * @return Phalcon\Debug
 */
PHP_METHOD(Phalcon_Debug, debugVar){

	zval *var, *key = NULL, *ztime, *backtrace, *data;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &var, &key);
	
	if (!key) {
		PHALCON_INIT_VAR(key);
	}
	
	PHALCON_INIT_VAR(ztime);
	ZVAL_LONG(ztime, (long) time(NULL));
	
	PHALCON_INIT_VAR(backtrace);
#if PHP_VERSION_ID < 50400
#ifdef DEBUG_BACKTRACE_PROVIDE_OBJECT
	zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT TSRMLS_CC);
#else
	zend_fetch_debug_backtrace(backtrace, 0, 1 TSRMLS_CC);
#endif
#else
	zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT, 0 TSRMLS_CC);
#endif
	
	PHALCON_INIT_VAR(data);
	array_init_size(data, 3);
	phalcon_array_append(&data, var, PH_SEPARATE);
	phalcon_array_append(&data, backtrace, PH_SEPARATE);
	phalcon_array_append(&data, ztime, PH_SEPARATE);
	phalcon_update_property_array_append(this_ptr, SL("_data"), data TSRMLS_CC);
	RETURN_THIS();
}
Exemple #8
0
/**
 * Adds a resource to the annotations handler
 * A resource is a class that contains routing annotations
 *
 * @param string $handler
 * @param string $prefix
 * @return Phalcon\Mvc\Router\Annotations
 */
PHP_METHOD(Phalcon_Mvc_Router_Annotations, addResource){

	zval *handler, *prefix = NULL, *scope;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &handler, &prefix) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (!prefix) {
		PHALCON_INIT_VAR(prefix);
	}
	
	if (Z_TYPE_P(handler) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The handler must be a class name");
		return;
	}
	
	PHALCON_INIT_VAR(scope);
	array_init_size(scope, 2);
	phalcon_array_append(&scope, prefix, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&scope, handler, PH_SEPARATE TSRMLS_CC);
	phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC);
	phalcon_update_property_bool(this_ptr, SL("_processed"), 0 TSRMLS_CC);
	
	RETURN_THIS();
}
Exemple #9
0
/**
 * Adds a variable to the debug output
 *
 * @param mixed $var
 * @param string $key
 * @return Phalcon\Debug
 */
PHP_METHOD(Phalcon_Debug, debugVar) {

    zval *var, *key = NULL, *ztime, *backtrace, *data;

    PHALCON_MM_GROW();

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

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

    PHALCON_INIT_VAR(ztime);
    ZVAL_LONG(ztime, (long) time(NULL));

    PHALCON_INIT_VAR(backtrace);
    zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT, 0);

    PHALCON_INIT_VAR(data);
    array_init_size(data, 3);
    phalcon_array_append(data, var, PH_COPY);
    phalcon_array_append(data, backtrace, PH_COPY);
    phalcon_array_append(data, ztime, PH_COPY);
    phalcon_update_property_array_append(getThis(), SL("_data"), data);
    RETURN_THIS();
}
/**
 * Adds a resource to the annotations handler
 * A resource is a class that contains routing annotations
 * The class is located in a module
 *
 * @param string $module
 * @param string $handler
 * @param string $prefix
 * @return Phalcon\Mvc\Router\Annotations
 */
PHP_METHOD(Phalcon_Mvc_Router_Annotations, addModuleResource){

	zval *module, *handler, *prefix = NULL, *scope;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 1, &module, &handler, &prefix);
	
	if (!prefix) {
		PHALCON_INIT_VAR(prefix);
	}
	
	if (Z_TYPE_P(module) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The module is not a valid string");
		return;
	}
	if (Z_TYPE_P(handler) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The handler must be a class name");
		return;
	}
	
	PHALCON_INIT_VAR(scope);
	array_init_size(scope, 3);
	phalcon_array_append(&scope, prefix, PH_SEPARATE);
	phalcon_array_append(&scope, handler, PH_SEPARATE);
	phalcon_array_append(&scope, module, PH_SEPARATE);
	phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC);
	phalcon_update_property_bool(this_ptr, SL("_processed"), 0 TSRMLS_CC);
	
	RETURN_THIS();
}
Exemple #11
0
/**
 * Stops the active profile
 *
 * @return Phalcon\Db\Profiler
 */
PHP_METHOD(Phalcon_Db_Profiler, stopProfile){

	zval *final_time = NULL, *active_profile, *initial_time = NULL;
	zval *difference, *total_seconds, *new_total_seconds;

	PHALCON_MM_GROW();

	PHALCON_CALL_FUNCTION(&final_time, "microtime", PHALCON_GLOBAL(z_true));
	
	active_profile = phalcon_fetch_nproperty_this(this_ptr, SL("_activeProfile"), PH_NOISY TSRMLS_CC);
	PHALCON_CALL_METHOD(NULL, active_profile, "setfinaltime", final_time);
	
	PHALCON_CALL_METHOD(&initial_time, active_profile, "getinitialtime");
	
	PHALCON_INIT_VAR(difference);
	sub_function(difference, final_time, initial_time TSRMLS_CC);
	
	total_seconds = phalcon_fetch_nproperty_this(this_ptr, SL("_totalSeconds"), PH_NOISY TSRMLS_CC);
	
	PHALCON_INIT_VAR(new_total_seconds);
	phalcon_add_function(new_total_seconds, total_seconds, difference TSRMLS_CC);
	phalcon_update_property_this(this_ptr, SL("_totalSeconds"), new_total_seconds TSRMLS_CC);
	phalcon_update_property_array_append(this_ptr, SL("_allProfiles"), active_profile TSRMLS_CC);
	if (phalcon_method_exists_ex(this_ptr, SS("afterendprofile") TSRMLS_CC) == SUCCESS) {
		PHALCON_CALL_METHOD(NULL, this_ptr, "afterendprofile", active_profile);
	}
	
	RETURN_THIS();
}
Exemple #12
0
/**
 * Adds a validator to a field
 *
 * @param string $attribute
 * @param Phalcon\Validation\ValidatorInterface
 * @return Phalcon\Validation
 */
PHP_METHOD(Phalcon_Validation, add){

	zval *attribute, *validator, *scope;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &attribute, &validator);
	
	if (Z_TYPE_P(attribute) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string");
		return;
	}
	if (Z_TYPE_P(validator) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator must be an object");
		return;
	}
	
	PHALCON_INIT_VAR(scope);
	array_init_size(scope, 2);
	phalcon_array_append(&scope, attribute, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&scope, validator, PH_SEPARATE TSRMLS_CC);
	phalcon_update_property_array_append(this_ptr, SL("_validators"), scope TSRMLS_CC);
	
	RETURN_THIS();
}
Exemple #13
0
/**
 * Adds a route applying the common attributes
 *
 * @param string $patten
 * @param array $paths
 * @param array $httpMethods
 * @return Phalcon\Mvc\Router\Route
 */
PHP_METHOD(Phalcon_Mvc_Router_Group, _addRoute){

	zval *pattern, *paths = NULL, *http_methods = NULL, *prefix, *prefix_pattern;
	zval *default_paths, *merged_paths = NULL, *route;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &pattern, &paths, &http_methods) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (!paths) {
		PHALCON_INIT_VAR(paths);
	}
	
	if (!http_methods) {
		PHALCON_INIT_VAR(http_methods);
	}
	
	PHALCON_OBS_VAR(prefix);
	phalcon_read_property(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
	
	/** 
	 * Add the prefix to the pattern
	 */
	PHALCON_INIT_VAR(prefix_pattern);
	PHALCON_CONCAT_VV(prefix_pattern, prefix, pattern);
	
	PHALCON_OBS_VAR(default_paths);
	phalcon_read_property(&default_paths, this_ptr, SL("_paths"), PH_NOISY_CC);
	
	/** 
	 * Check if the paths need to be merged with current paths
	 */
	if (Z_TYPE_P(default_paths) == IS_ARRAY) { 
		if (Z_TYPE_P(paths) == IS_ARRAY) { 
			/** 
			 * Merge the paths with the default paths
			 */
			PHALCON_INIT_VAR(merged_paths);
			PHALCON_CALL_FUNC_PARAMS_2(merged_paths, "array_merge", default_paths, paths);
		} else {
			PHALCON_CPY_WRT(merged_paths, default_paths);
		}
	} else {
		PHALCON_CPY_WRT(merged_paths, paths);
	}
	
	/** 
	 * Every route is internally stored as a Phalcon\Mvc\Router\Route
	 */
	PHALCON_INIT_VAR(route);
	object_init_ex(route, phalcon_mvc_router_route_ce);
	PHALCON_CALL_METHOD_PARAMS_3_NORETURN(route, "__construct", prefix_pattern, merged_paths, http_methods);
	
	phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC);
	
	RETURN_CTOR(route);
}
Exemple #14
0
/**
 * Adds a filter to the collection
 *
 * @param Phalcon\Assets\FilterInterface $filter
 * @return Phalcon\Assets\Collection
 */
PHP_METHOD(Phalcon_Assets_Collection, addFilter){

	zval *filter;

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

	phalcon_update_property_array_append(getThis(), SL("_filters"), filter);
	RETURN_THISW();
}
Exemple #15
0
/**
 * Adds a role to the ACL list. Second parameter allows inheriting access data from other existing role
 *
 * Example:
 * <code>
 * 	$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultant');
 * 	$acl->addRole('administrator', 'consultant');
 * </code>
 *
 * @param  Phalcon\Acl\RoleInterface $role
 * @param  array|string $accessInherits
 * @return boolean
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){

	zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL;
	zval *roles_names, *default_access, *_access;
	zval *success;
	zval *t0 = NULL;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &role, &access_inherits) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (!access_inherits) {
		PHALCON_INIT_VAR(access_inherits);
	}
	
	if (Z_TYPE_P(role) == IS_OBJECT) {
		PHALCON_INIT_VAR(role_name);
		PHALCON_CALL_METHOD(role_name, role, "getname");
		PHALCON_CPY_WRT(object, role);
	} else {
		PHALCON_CPY_WRT(role_name, role);
	
		PHALCON_INIT_VAR(object);
		object_init_ex(object, phalcon_acl_role_ce);
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(object, "__construct", role);
	
	}
	
	PHALCON_OBS_VAR(roles_names);
	phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC);
	if (phalcon_array_isset(roles_names, role_name)) {
		RETURN_MM_FALSE;
	}
	
	phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC);
	
	PHALCON_INIT_VAR(t0);
	ZVAL_BOOL(t0, 1);
	phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, t0 TSRMLS_CC);
	
	PHALCON_OBS_VAR(default_access);
	phalcon_read_property(&default_access, this_ptr, SL("_defaultAccess"), PH_NOISY_CC);
	
	PHALCON_OBS_VAR(_access);
	phalcon_read_property(&_access, this_ptr, SL("_access"), PH_NOISY_CC);
	phalcon_array_update_zval_string_string_multi_3(&_access, role_name, SL("*"), SL("*"), &default_access, 0 TSRMLS_CC);
	if (Z_TYPE_P(access_inherits) != IS_NULL) {
		PHALCON_INIT_VAR(success);
		PHALCON_CALL_METHOD_PARAMS_2(success, this_ptr, "addinherit", role_name, access_inherits);
		RETURN_CCTOR(success);
	}
	
	RETURN_MM_TRUE;
}
Exemple #16
0
/**
 * Adds an option to the current options
 *
 * @param array $option
 * @return $this;
 */
PHP_METHOD(Phalcon_Forms_Element_Select, addOption){

	zval *option;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &option) == FAILURE) {
		RETURN_NULL();
	}

	phalcon_update_property_array_append(this_ptr, SL("_options"), option TSRMLS_CC);
	RETURN_THISW();
}
Exemple #17
0
/**
 * Adds a role to the ACL list. Second parameter allows inheriting access data from other existing role
 *
 * Example:
 * <code>
 * 	$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultant');
 * 	$acl->addRole('administrator', 'consultant');
 * </code>
 *
 * @param  Phalcon\Acl\RoleInterface $role
 * @param  array|string $accessInherits
 * @return boolean
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){

	zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL;
	zval *roles_names, *exists, *default_access;
	zval *key, *success;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &role, &access_inherits);
	
	if (!access_inherits) {
		PHALCON_INIT_VAR(access_inherits);
	}
	
	if (Z_TYPE_P(role) == IS_OBJECT) {
		PHALCON_INIT_VAR(role_name);
		phalcon_call_method(role_name, role, "getname");
		PHALCON_CPY_WRT(object, role);
	} else {
		PHALCON_CPY_WRT(role_name, role);
	
		PHALCON_INIT_NVAR(object);
		object_init_ex(object, phalcon_acl_role_ce);
		phalcon_call_method_p1_noret(object, "__construct", role);
	
	}
	
	PHALCON_OBS_VAR(roles_names);
	phalcon_read_property_this(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC);
	if (phalcon_array_isset(roles_names, role_name)) {
		RETURN_MM_FALSE;
	}
	
	PHALCON_INIT_VAR(exists);
	ZVAL_BOOL(exists, 1);
	phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC);
	phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, exists TSRMLS_CC);
	
	PHALCON_OBS_VAR(default_access);
	phalcon_read_property_this(&default_access, this_ptr, SL("_defaultAccess"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(key);
	PHALCON_CONCAT_VS(key, role_name, "!*!*");
	phalcon_update_property_array(this_ptr, SL("_access"), key, default_access TSRMLS_CC);
	if (Z_TYPE_P(access_inherits) != IS_NULL) {
		PHALCON_INIT_VAR(success);
		phalcon_call_method_p2(success, this_ptr, "addinherit", role_name, access_inherits);
		RETURN_CCTOR(success);
	}
	
	RETURN_MM_TRUE;
}
Exemple #18
0
/**
 * Pushes a logger to the logger tail
 *
 * @param Phalcon\Logger\AdapterInterface $logger
 */
PHP_METHOD(Phalcon_Logger_Multiple, push){

	zval *logger;

	phalcon_fetch_params(0, 1, 0, &logger);
	
	if (Z_TYPE_P(logger) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The logger is invalid");
		return;
	}
	phalcon_update_property_array_append(this_ptr, SL("_loggers"), logger TSRMLS_CC);
	
}
Exemple #19
0
/**
 * Adds a validator to the element
 *
 * @param Phalcon\Validation\ValidatorInterface
 * @return Phalcon\Forms\ElementInterface
 */
PHP_METHOD(Phalcon_Forms_Element, addValidator){

	zval *validator;

	phalcon_fetch_params(0, 1, 0, &validator);
	
	if (Z_TYPE_P(validator) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The validators parameter must be an object");
		return;
	}
	phalcon_update_property_array_append(this_ptr, SL("_validators"), validator TSRMLS_CC);
	
	RETURN_THISW();
}
Exemple #20
0
/**
 * Adds a resource to the collection
 *
 * @param Phalcon\Assets\Resource $resource
 * @return Phalcon\Assets\Collection
 */
PHP_METHOD(Phalcon_Assets_Collection, add){

	zval *resource;

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

	if (Z_TYPE_P(resource) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Resource must be an object");
		return;
	}
	phalcon_update_property_array_append(getThis(), SL("_resources"), resource);

	RETURN_THISW();
}
Exemple #21
0
/**
 * Adds a resource to the ACL list
 *
 * Access names can be a particular action, by example
 * search, update, delete, etc or a list of them
 *
 * Example:
 * <code>
 * //Add a resource to the the list allowing access to an action
 * $acl->addResource(new Phalcon\Acl\Resource('customers'), 'search');
 * $acl->addResource('customers', 'search');
 *
 * //Add a resource  with an access list
 * $acl->addResource(new Phalcon\Acl\Resource('customers'), array('create', 'search'));
 * $acl->addResource('customers', array('create', 'search'));
 * </code>
 *
 * @param   Phalcon\Acl\Resource $resource
 * @param   array $accessList
 * @return  boolean
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){

	zval *resource, *access_list = NULL, *resource_name = NULL;
	zval *object = NULL, *resources_names, *empty_arr, *status;
	zval *t0 = NULL;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &resource, &access_list) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (!access_list) {
		PHALCON_INIT_VAR(access_list);
	}
	
	if (Z_TYPE_P(resource) == IS_OBJECT) {
		PHALCON_INIT_VAR(resource_name);
		PHALCON_CALL_METHOD(resource_name, resource, "getname");
		PHALCON_CPY_WRT(object, resource);
	} else {
		PHALCON_CPY_WRT(resource_name, resource);
	
		PHALCON_INIT_VAR(object);
		object_init_ex(object, phalcon_acl_resource_ce);
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(object, "__construct", resource_name);
	
	}
	
	PHALCON_OBS_VAR(resources_names);
	phalcon_read_property(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY_CC);
	if (!phalcon_array_isset(resources_names, resource_name)) {
		phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC);
	
		PHALCON_INIT_VAR(empty_arr);
		array_init(empty_arr);
		phalcon_update_property_array(this_ptr, SL("_accessList"), resource_name, empty_arr TSRMLS_CC);
	
		PHALCON_INIT_VAR(t0);
		ZVAL_BOOL(t0, 1);
		phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, t0 TSRMLS_CC);
	}
	
	PHALCON_INIT_VAR(status);
	PHALCON_CALL_METHOD_PARAMS_2(status, this_ptr, "addresourceaccess", resource_name, access_list);
	
	RETURN_CCTOR(status);
}
Exemple #22
0
/**
 * Set send file
 *
 * @param string $file
 * @return Phalcon\Http\Client\Adapter
 */
PHP_METHOD(Phalcon_Http_Client_Adapter, setFile){

	zval *file;

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

	if (Z_TYPE_P(file) != IS_ARRAY) {
		phalcon_update_property_array_append(getThis(), SL("_files"), file);
	} else {
		phalcon_update_property_zval(getThis(), SL("_files"), file);
	}

	// zend_error_noreturn(E_DEPRECATED, "Method Phalcon\\Http\\Client\\Adapter::setFile is deprecated, please use Phalcon\\Http\\Client\\Adapter::setFiles instead");

	RETURN_THISW();
}
Exemple #23
0
/**
 * Adds a role to the ACL list. Second parameter allows inheriting access data from other existing role
 *
 * Example:
 * <code>
 * 	$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultant');
 * 	$acl->addRole('administrator', 'consultant');
 * </code>
 *
 * @param  Phalcon\Acl\RoleInterface|string $role
 * @param  array|string $accessInherits
 * @return boolean
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){

	zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL;
	zval *roles_names, *default_access;
	zval *key;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &role, &access_inherits);
	
	if (!access_inherits) {
		access_inherits = PHALCON_GLOBAL(z_null);
	}
	
	if (Z_TYPE_P(role) == IS_OBJECT) {
		PHALCON_CALL_METHOD(&role_name, role, "getname");
		PHALCON_CPY_WRT(object, role);
	} else {
		PHALCON_CPY_WRT(role_name, role);
	
		PHALCON_INIT_NVAR(object);
		object_init_ex(object, phalcon_acl_role_ce);
		PHALCON_CALL_METHOD(NULL, object, "__construct", role);
	
	}
	
	roles_names = phalcon_fetch_nproperty_this(this_ptr, SL("_rolesNames"), PH_NOISY TSRMLS_CC);
	if (phalcon_array_isset(roles_names, role_name)) {
		RETURN_MM_FALSE;
	}
	
	phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC);
	phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, PHALCON_GLOBAL(z_true) TSRMLS_CC);
	
	default_access = phalcon_fetch_nproperty_this(this_ptr, SL("_defaultAccess"), PH_NOISY TSRMLS_CC);
	
	PHALCON_INIT_VAR(key);
	PHALCON_CONCAT_VS(key, role_name, "!*!*");
	phalcon_update_property_array(this_ptr, SL("_access"), key, default_access TSRMLS_CC);
	if (Z_TYPE_P(access_inherits) != IS_NULL) {
		PHALCON_RETURN_CALL_METHOD(this_ptr, "addinherit", role_name, access_inherits);
		RETURN_MM();
	}
	
	RETURN_MM_TRUE;
}
/**
 * Internal function to add a handler to the group
 *
 * @param string|array $method
 * @param string $routePattern
 * @param mixed $handler
 */
PHP_METHOD(Phalcon_Mvc_Micro_Collection, _addMap){

	zval *method, *route_pattern, *handler, *handler_definition;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 3, 0, &method, &route_pattern, &handler);
	
	PHALCON_INIT_VAR(handler_definition);
	array_init_size(handler_definition, 3);
	phalcon_array_append(&handler_definition, method, PH_SEPARATE);
	phalcon_array_append(&handler_definition, route_pattern, PH_SEPARATE);
	phalcon_array_append(&handler_definition, handler, PH_SEPARATE);
	phalcon_update_property_array_append(this_ptr, SL("_handlers"), handler_definition TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #25
0
/**
 * Appends a message to the group
 *
 *<code>
 * $messages->appendMessage(new Phalcon\Validation\Message('This is a message'));
 *</code>
 *
 * @param Phalcon\Validation\MessageInterface $message
 */
PHP_METHOD(Phalcon_Validation_Message_Group, appendMessage){

	zval *message;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &message) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (Z_TYPE_P(message) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The message must be an object");
		return;
	}
	phalcon_update_property_array_append(this_ptr, SL("_messages"), message TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #26
0
/**
 * Adds a backend
 *
 * @param Phalcon\Cache\BackendInterface $backend
 * @return Phalcon\Cache\Multiple
 */
PHP_METHOD(Phalcon_Cache_Multiple, push){

	zval *backend;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &backend) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (Z_TYPE_P(backend) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend is not valid");
		return;
	}
	phalcon_update_property_array_append(this_ptr, SL("_backends"), backend TSRMLS_CC);
	
	RETURN_THIS();
}
Exemple #27
0
/**
 * Pushes a logger to the logger tail
 *
 * @param Phalcon\Logger\AdapterInterface $logger
 */
PHP_METHOD(Phalcon_Logger_Multiple, push){

	zval *logger;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &logger) == FAILURE) {
		RETURN_MM_NULL();
	}

	if (Z_TYPE_P(logger) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "The logger is invalid");
		return;
	}
	phalcon_update_property_array_append(this_ptr, SL("_loggers"), logger TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #28
0
/**
 * Internal function to add a handler to the group
 *
 * @param string|array $method
 * @param string $routePattern
 * @param mixed $handler
 */
PHP_METHOD(Phalcon_Mvc_Micro_Collection, _addMap){

	zval *method, *route_pattern, *handler, *handler_definition;

	PHALCON_MM_GROW();

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &method, &route_pattern, &handler) == FAILURE) {
		RETURN_MM_NULL();
	}

	PHALCON_INIT_VAR(handler_definition);
	array_init_size(handler_definition, 3);
	phalcon_array_append(&handler_definition, method, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&handler_definition, route_pattern, PH_SEPARATE TSRMLS_CC);
	phalcon_array_append(&handler_definition, handler, PH_SEPARATE TSRMLS_CC);
	phalcon_update_property_array_append(this_ptr, SL("_handlers"), handler_definition TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #29
0
/**
 * Appends a message to the validator
 *
 * @param string $message
 * @param string $field
 * @param string $type
 */
PHP_METHOD(Phalcon_Mvc_Model_Validator, appendMessage){

	zval *message, *field = NULL, *type = NULL, *class_name, *suffix;
	zval *empty_string, *model_message;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 2, &message, &field, &type);
	
	if (!field) {
		PHALCON_INIT_VAR(field);
	}
	
	if (!type) {
		PHALCON_INIT_VAR(type);
	} else {
		PHALCON_SEPARATE_PARAM(type);
	}
	
	if (!zend_is_true(type)) {
		PHALCON_INIT_VAR(class_name);
		phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC);
	
		PHALCON_INIT_VAR(suffix);
		ZVAL_STRING(suffix, "Validator", 1);
	
		PHALCON_INIT_VAR(empty_string);
		ZVAL_STRING(empty_string, "", 1);
	
		PHALCON_INIT_NVAR(type);
		phalcon_fast_str_replace(type, suffix, empty_string, class_name TSRMLS_CC);
	}
	
	PHALCON_INIT_VAR(model_message);
	object_init_ex(model_message, phalcon_mvc_model_message_ce);
	phalcon_call_method_p3_noret(model_message, "__construct", message, field, type);
	
	phalcon_update_property_array_append(this_ptr, SL("_messages"), model_message TSRMLS_CC);
	
	PHALCON_MM_RESTORE();
}
Exemple #30
0
/**
 * Adds a resource to the ACL list
 *
 * Access names can be a particular action, by example
 * search, update, delete, etc or a list of them
 *
 * Example:
 * <code>
 * //Add a resource to the the list allowing access to an action
 * $acl->addResource(new Phalcon\Acl\Resource('customers'), 'search');
 * $acl->addResource('customers', 'search');
 *
 * //Add a resource  with an access list
 * $acl->addResource(new Phalcon\Acl\Resource('customers'), array('create', 'search'));
 * $acl->addResource('customers', array('create', 'search'));
 * </code>
 *
 * @param   Phalcon\Acl\Resource $resource
 * @param   array $accessList
 * @return  boolean
 */
PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){

	zval *resource, *access_list = NULL, *resource_name = NULL;
	zval *object = NULL, *resources_names, *exists, *status;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &resource, &access_list);
	
	if (!access_list) {
		PHALCON_INIT_VAR(access_list);
	}
	
	if (Z_TYPE_P(resource) == IS_OBJECT) {
		PHALCON_INIT_VAR(resource_name);
		phalcon_call_method(resource_name, resource, "getname");
		PHALCON_CPY_WRT(object, resource);
	} else {
		PHALCON_CPY_WRT(resource_name, resource);
	
		PHALCON_INIT_NVAR(object);
		object_init_ex(object, phalcon_acl_resource_ce);
		phalcon_call_method_p1_noret(object, "__construct", resource_name);
	
	}
	
	PHALCON_OBS_VAR(resources_names);
	phalcon_read_property_this(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY_CC);
	if (!phalcon_array_isset(resources_names, resource_name)) {
		PHALCON_INIT_VAR(exists);
		ZVAL_BOOL(exists, 1);
		phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC);
		phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, exists TSRMLS_CC);
	}
	
	PHALCON_INIT_VAR(status);
	phalcon_call_method_p2(status, this_ptr, "addresourceaccess", resource_name, access_list);
	
	RETURN_CCTOR(status);
}