Exemplo n.º 1
0
/**
 * Return the lastest DI created
 *
 * @return Phalcon\DiInterface
 */
PHP_METHOD(Phalcon_DI, getDefault){

	zval default_di = {}, dependency_injector = {};

	phalcon_return_static_property_ce(&default_di, phalcon_di_ce, SL("_default"));
	if (Z_TYPE(default_di) != IS_OBJECT) {
		object_init_ex(&dependency_injector, phalcon_di_factorydefault_ce);
		PHALCON_CALL_METHODW(NULL, &dependency_injector, "__construct");
		RETURN_CTORW(&dependency_injector);
	}

	RETURN_CTORW(&default_di);
}
Exemplo n.º 2
0
/**
 * Creates a form registering it in the forms manager
 *
 * @param string $name
 * @param object $entity
 * @return Phalcon\Forms\Form
 */
PHP_METHOD(Phalcon_Forms_Manager, create){

	zval *name = NULL, *entity = NULL, form = {};

	phalcon_fetch_params(0, 0, 2, &name, &entity);

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

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

	if (Z_TYPE_P(name) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The form name must be string");
		return;
	}

	object_init_ex(&form, phalcon_forms_form_ce);
	PHALCON_CALL_METHODW(NULL, &form, "__construct", entity);

	phalcon_update_property_array(getThis(), SL("_forms"), name, &form);

	RETURN_CTORW(&form);
}
Exemplo n.º 3
0
/**
 * Returns a cached content
 *
 * @param int|string $keyName
 * @param   long $lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){

	zval *key_name, *lifetime = NULL, memcache = {}, frontend = {}, prefix = {}, prefixed_key = {}, cached_content = {};

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

	phalcon_return_property(&memcache, getThis(), SL("_memcache"));
	if (Z_TYPE(memcache) != IS_OBJECT) {
		PHALCON_CALL_METHODW(&memcache, getThis(), "_connect");
	}

	phalcon_return_property(&frontend, getThis(), SL("_frontend"));
	phalcon_return_property(&prefix, getThis(), SL("_prefix"));

	PHALCON_CONCAT_VV(&prefixed_key, &prefix, key_name);
	phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key);

	PHALCON_CALL_METHODW(&cached_content, &memcache, "get", &prefixed_key);
	if (PHALCON_IS_FALSE(&cached_content)) {
		RETURN_NULL();
	}

	if (phalcon_is_numeric(&cached_content)) {
		RETURN_CTORW(&cached_content);
	}

	PHALCON_RETURN_CALL_METHOD(&frontend, "afterretrieve", &cached_content);
}
Exemplo n.º 4
0
/**
 * Get label for field
 *
 * @param string field
 * @return string
 */
PHP_METHOD(Phalcon_Validation, getLabel) {

	zend_bool _0;
	zval *field, *labels = NULL, *value = NULL;

	zephir_fetch_params(0, 1, 0, &field);



	labels = zephir_fetch_nproperty_this(this_ptr, SL("_labels"), PH_NOISY_CC);
	_0 = Z_TYPE_P(labels) == IS_ARRAY;
	if (_0) {
		_0 = Z_TYPE_P(field) != IS_ARRAY;
	}
	if (_0) {
		if (zephir_array_isset_fetch(&value, labels, field, 1 TSRMLS_CC)) {
			RETURN_CTORW(value);
		}
	} else if (Z_TYPE_P(field) == IS_ARRAY) {
		zephir_fast_join_str(return_value, SL(", "), field TSRMLS_CC);
		return;
	}
	RETVAL_ZVAL(field, 1, 0);
	return;

}
Exemplo n.º 5
0
/**
 * Returns the complete location where the joined/filtered collection must be written
 *
 * @param string $basePath
 * @return string
 */
PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){

	zval *base_path = NULL, *target_path, complete_path = {};

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

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

	target_path = phalcon_read_property(getThis(), SL("_targetPath"), PH_NOISY);

	/** 
	 * A base path for resources can be set in the assets manager
	 */
	PHALCON_CONCAT_VV(&complete_path, base_path, target_path);

	/** 
	 * Get the real template path, the target path can optionally don't exist
	 */
	if (phalcon_file_exists(&complete_path) == SUCCESS) {
		phalcon_file_realpath(return_value, &complete_path);
		return;
	}

	RETURN_CTORW(&complete_path);
}
Exemplo n.º 6
0
/**
 * Gets HTTP raw request body
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getRawBody)
{
	zval raw = {}, *zcontext = NULL;
	zend_string *content;
	php_stream_context *context;
	php_stream *stream;
	long int maxlen;

	phalcon_read_property(&raw, getThis(), SL("_rawBody"), PH_NOISY);
	if (Z_TYPE(raw) == IS_STRING) {
		RETURN_CTORW(&raw);
	}

	context = php_stream_context_from_zval(zcontext, 0);
	stream = php_stream_open_wrapper_ex("php://input", "rb", REPORT_ERRORS, NULL, context);
	maxlen    = PHP_STREAM_COPY_ALL;

	if (!stream) {
		RETURN_FALSE;
	}

	content = php_stream_copy_to_mem(stream, maxlen, 0);
	if (content != NULL) {
		RETVAL_STR(content);
		phalcon_update_property_zval(getThis(), SL("_rawBody"), return_value);
	} else {
		RETVAL_FALSE;
	}

	php_stream_close(stream);
}
Exemplo n.º 7
0
/**
 * 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);
}
Exemplo n.º 8
0
/**
 * Internal get wrapper to filter
 *
 * @param string $name
 * @param string|array $filters
 * @param mixed $defaultValue
 * @param boolean $notAllowEmpty
 * @param boolean $noRecursive
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, _get)
{
	zval *data, *name, *filters, *default_value, *not_allow_empty, *norecursive;
	zval value = {}, dependency_injector = {}, service = {}, filter = {}, filter_value = {};

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

	if (Z_TYPE_P(name) != IS_NULL) {
		if (!phalcon_array_isset_fetch(&value, data, name, 0)) {
			RETURN_CTORW(default_value);
		}
	} else {
		PHALCON_CPY_WRT_CTOR(&value, data);
	}

	if (Z_TYPE_P(filters) != IS_NULL) {
		phalcon_return_property(&filter, getThis(), SL("_filter"));
		if (Z_TYPE(filter) != IS_OBJECT) {
			PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi");
			if (Z_TYPE(dependency_injector) != IS_OBJECT) {
				PHALCON_THROW_EXCEPTION_STRW(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service");
				return;
			}

			PHALCON_STR(&service, ISV(filter));

			PHALCON_CALL_METHODW(&filter, &dependency_injector, "getshared", &service);
			PHALCON_VERIFY_INTERFACEW(&filter, phalcon_filterinterface_ce);

			phalcon_update_property_zval(getThis(), SL("_filter"), &filter);
		}

		PHALCON_CALL_METHODW(&filter_value, &filter, "sanitize", &value, filters, norecursive);

		if ((PHALCON_IS_EMPTY(&filter_value) && zend_is_true(not_allow_empty)) || PHALCON_IS_FALSE(&filter_value)) {
			RETURN_CTORW(default_value);
		}

		RETURN_CTORW(&filter_value);
	}

	if (PHALCON_IS_EMPTY(&value) && zend_is_true(not_allow_empty)) {
		RETURN_CTORW(default_value);
	}

	RETURN_CTORW(&value);
}
PHP_METHOD(Test_Properties_StaticProtectedProperties, getSomeNullInitial) {

	zval *_0;


	_0 = zephir_fetch_static_property_ce(test_properties_staticprotectedproperties_ce, SL("someNullInitial") TSRMLS_CC);
	RETURN_CTORW(_0);

}
Exemplo n.º 10
0
PHP_METHOD(Test_Concat, getTestProperty) {

    zval *_0;


    _0 = zephir_fetch_static_property_ce(test_concat_ce, SL("testProperty") TSRMLS_CC);
    RETURN_CTORW(_0);

}
Exemplo n.º 11
0
/**
 * Return the latest DI created
 */
PHP_METHOD(Phalcon_Di, getDefault) {

	zval *_0;


	_0 = zephir_fetch_static_property_ce(phalcon_di_ce, SL("_default") TSRMLS_CC);
	RETURN_CTORW(_0);

}
Exemplo n.º 12
0
/**
 * Returns the default Di container instance, or if one was not created
 * then created a new instance and set the default
 *
 * @return DiInterface
 */
PHP_METHOD(Pdm_Di_Container, getDefault) {

	zval *_0;


	_0 = zephir_fetch_static_property_ce(pdm_di_container_ce, SL("defaultInstance") TSRMLS_CC);
	RETURN_CTORW(_0);

}
/**
 * @return boolean  TRUE if the grant type requires a redirect_uri, FALSE if not
 */
PHP_METHOD(OAuth2_ResponseType_AuthorizationCode, enforceRedirect) {

	zval *_0, *_1;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("config"), PH_NOISY_CC);
	zephir_array_fetch_string(&_1, _0, SL("enforce_redirect"), PH_NOISY | PH_READONLY, "oauth2/responsetype/authorizationcode.zep", 74 TSRMLS_CC);
	RETURN_CTORW(_1);

}
Exemplo n.º 14
0
PHP_METHOD(OAuth2_GrantType_JwtBearer, getUserId) {

	zval *_0, *_1;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("jwt"), PH_NOISY_CC);
	zephir_array_fetch_string(&_1, _0, SL("sub"), PH_NOISY | PH_READONLY, "oauth2/granttype/jwtbearer.zep", 185 TSRMLS_CC);
	RETURN_CTORW(_1);

}
Exemplo n.º 15
0
/**
 * Sets a service using a raw Phalcon\DI\Service definition
 *
 * @param string|Phalcon\DI\ServiceInterface $raw_definition_or_name
 * @param Phalcon\DI\ServiceInterface $rawDefinition
 * @return Phalcon\DI\ServiceInterface
 */
PHP_METHOD(Phalcon_DI, setService)
{
	zval *name, *raw_definition;

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

	phalcon_update_property_array(getThis(), SL("_services"), name, raw_definition);

	RETURN_CTORW(raw_definition);
}
Exemplo n.º 16
0
/**
 * Gets active server name
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getServerName){

	zval *server, server_name = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_fetch_str(&server_name, server, SL("SERVER_NAME"))) {
		RETURN_CTORW(&server_name);
	}

	RETURN_STRING("localhost");
}
Exemplo n.º 17
0
/**
 * Returns the current resource in the iterator
 */
PHP_METHOD(Phalcon_Assets_Collection, current) {

	zval *resource, *_0, *_1;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_resources"), PH_NOISY_CC);
	_1 = zephir_fetch_nproperty_this(this_ptr, SL("_position"), PH_NOISY_CC);
	zephir_array_isset_fetch(&resource, _0, _1, 1 TSRMLS_CC);
	RETURN_CTORW(resource);

}
Exemplo n.º 18
0
/**
 * Gets HTTP user agent used to made the request
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getUserAgent){

	zval *server, user_agent = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_fetch_str(&user_agent, server, SL("HTTP_USER_AGENT"))) {
		RETURN_CTORW(&user_agent);
	}

	RETURN_EMPTY_STRING();
}
Exemplo n.º 19
0
/**
 * Gets active server address IP
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getServerAddress){

	zval *server, server_addr = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_fetch_str(&server_addr, server, SL("SERVER_ADDR"))) {
		RETURN_CTORW(&server_addr);
	}

	RETURN_STRING("127.0.0.1");
}
Exemplo n.º 20
0
/**
 * Gets most possible client IPv4 Address. This method search in $_SERVER['REMOTE_ADDR'] and optionally in $_SERVER['HTTP_X_FORWARDED_FOR']
 *
 * @param boolean $trustForwardedHeader
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getClientAddress){

	zval *trust_forwarded_header = NULL, *_SERVER, address = {}, addresses = {}, first = {};

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

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

	_SERVER = phalcon_get_global_str(SL("_SERVER"));

	/**
	 * Proxies use this IP
	 */
	if (zend_is_true(trust_forwarded_header)) {
		if (!phalcon_array_isset_fetch_str(&address, _SERVER, SL("HTTP_X_FORWARDED_FOR"))) {
			if (!phalcon_array_isset_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"))) {
				phalcon_array_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"), PH_NOISY);
			}
		}
	} else if (!phalcon_array_isset_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"))) {
		phalcon_array_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"), PH_NOISY);
	}

	if (Z_TYPE(address) == IS_STRING) {
		if (phalcon_memnstr_str(&address, SL(","))) {
			/**
			 * The client address has multiples parts, only return the first part
			 */
			phalcon_fast_explode_str(&addresses, SL(","), &address);

			phalcon_array_fetch_long(&first, &addresses, 0, PH_NOISY);
			RETURN_CTORW(&first);
		}

		RETURN_CTORW(&address);
	}

	RETURN_FALSE;
}
Exemplo n.º 21
0
/**
 * Retrieve the URI path
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Uri, getPath)
{
	zval parts = {}, value = {};

	phalcon_read_property(&parts, getThis(), SL("_parts"), PH_NOISY);

	if (!phalcon_array_isset_fetch_str(&value, &parts, SL("path"))) {
		 RETURN_NULL();
	}

	RETURN_CTORW(&value);
}
Exemplo n.º 22
0
PHP_METHOD(Phalcon_Http_Uri, resolve)
{
	zval *uri, self = {};

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

	object_init_ex(&self, phalcon_http_uri_ce);
	PHALCON_CALL_METHODW(NULL, &self, "__construct", getThis());
	PHALCON_CALL_METHODW(NULL, &self, "extend", uri);

	RETURN_CTORW(&self);
}
Exemplo n.º 23
0
/**
 * Returns the order clause in the criteria
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, getOrder) {

	zval *order = NULL, *_0;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC);
	if (zephir_array_isset_string_fetch(&order, _0, SS("order"), 1 TSRMLS_CC)) {
		RETURN_CTORW(order);
	}
	RETURN_NULL();

}
Exemplo n.º 24
0
/**
 * Returns the conditions parameter in the criteria
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, getConditions) {

	zval *conditions = NULL, *_0;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC);
	if (zephir_array_isset_string_fetch(&conditions, _0, SS("conditions"), 1 TSRMLS_CC)) {
		RETURN_CTORW(conditions);
	}
	RETURN_NULL();

}
Exemplo n.º 25
0
PHP_METHOD(Test_Concat, getTestProperty) {

    zval _0;
    ZEPHIR_INIT_THIS();

    ZVAL_UNDEF(&_0);


    zephir_read_static_property_ce(&_0, test_concat_ce, SL("testProperty"), PH_NOISY_CC | PH_READONLY);
    RETURN_CTORW(_0);

}
Exemplo n.º 26
0
/**
 * Returns the DependencyInjector container
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, getDI) {

	zval *dependencyInjector = NULL, *_0;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC);
	if (zephir_array_isset_string_fetch(&dependencyInjector, _0, SS("di"), 1 TSRMLS_CC)) {
		RETURN_CTORW(dependencyInjector);
	}
	RETURN_NULL();

}
Exemplo n.º 27
0
/**
 * Returns the having clause in the criteria
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, getHaving) {

	zval *having = NULL, *_0;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC);
	if (zephir_array_isset_string_fetch(&having, _0, SS("having"), 1 TSRMLS_CC)) {
		RETURN_CTORW(having);
	}
	RETURN_NULL();

}
PHP_METHOD(Test_Properties_StaticProtectedProperties, getSomeNull) {

	zval _0;
	ZEPHIR_INIT_THIS();

	ZVAL_UNDEF(&_0);


	zephir_read_static_property_ce(&_0, test_properties_staticprotectedproperties_ce, SL("someNull"), PH_NOISY_CC | PH_READONLY);
	RETURN_CTORW(_0);

}
Exemplo n.º 29
0
/**
 * Returns the group clause in the criteria
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, getGroupBy) {

	zval *group = NULL, *_0;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC);
	if (zephir_array_isset_string_fetch(&group, _0, SS("group"), 1 TSRMLS_CC)) {
		RETURN_CTORW(group);
	}
	RETURN_NULL();

}
Exemplo n.º 30
0
/**
 * Returns the limit parameter in the criteria, which will be
 * an integer if limit was set without an offset,
 * an array with 'number' and 'offset' keys if an offset was set with the limit,
 * or null if limit has not been set.
 *
 * @return int|array|null
 */
PHP_METHOD(Phalcon_Mvc_Model_Criteria, getLimit) {

	zval *limit = NULL, *_0;


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_params"), PH_NOISY_CC);
	if (zephir_array_isset_string_fetch(&limit, _0, SS("limit"), 1 TSRMLS_CC)) {
		RETURN_CTORW(limit);
	}
	RETURN_NULL();

}