Skip to content

Commit

Permalink
Validation improvements, adding support for complex expressions in PH…
Browse files Browse the repository at this point in the history
…QL ORDER BY/GROUP BY, fixing wrong method name in Phalcon\Mvc\Criteria
phalcon committed Feb 25, 2013
1 parent 6a8ad8c commit d3c1f21
Showing 20 changed files with 1,034 additions and 691 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -21,6 +21,9 @@
- Improved \Phalcon\Mvc\Router\Annotations to work better with controllers in namespaces and modules
- A model can be marked to keep record snapshots allowing to check what fields have been changed
- The _source and _schema properties have been moved from Phalcon\Mvc\Model to Phalcon\Mvc\Model\Manager. This allow set source/schema in the model initializer
- Added Phalcon\Session\Bag::remove to remove an specific variable from a session bag
- Added support for complex expressions in PHQL ORDER BY clause
- Added support for complex expressions in PHQL GROUP BY clause

0.9.0b2
- Support for reusable records. A relation can be marked to cache queried records in memory to speedup getting related records
2 changes: 1 addition & 1 deletion ext/config.m4
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@ PHP_ARG_ENABLE(phalcon, whether to enable phalcon framework, [ --enable-phalcon

if test "$PHP_PHALCON" = "yes"; then
AC_DEFINE(HAVE_PHALCON, 1, [Whether you have Phalcon Framework])
PHP_NEW_EXTENSION(phalcon, phalcon.c kernel/main.c kernel/fcall.c kernel/require.c kernel/debug.c kernel/assert.c kernel/object.c kernel/array.c kernel/string.c kernel/filter.c kernel/operators.c kernel/concat.c kernel/exception.c kernel/file.c kernel/memory.c kernel/experimental/fcall.c session/adapterinterface.c session/baginterface.c session/exception.c session/adapter/files.c session/adapter.c session/bag.c loader.c di.c forms/element.c forms/exception.c forms/form.c forms/element/text.c forms/manager.c text.c mvc/viewinterface.c mvc/router/exception.c mvc/router/route.c mvc/router/group.c mvc/router/routeinterface.c mvc/router/annotations.c mvc/dispatcherinterface.c mvc/router.c mvc/micro.c mvc/urlinterface.c mvc/dispatcher/exception.c mvc/collection/exception.c mvc/collection/managerinterface.c mvc/collection/manager.c mvc/view.c mvc/collection.c mvc/view/engine.c mvc/view/exception.c mvc/view/engineinterface.c mvc/view/engine/php.c mvc/view/engine/volt.c mvc/view/engine/volt/compiler.c mvc/url.c mvc/controller.c mvc/application/exception.c mvc/url/exception.c mvc/dispatcher.c mvc/model.c mvc/micro/exception.c mvc/micro/collection.c mvc/model/validator/uniqueness.c mvc/model/validator/presenceof.c mvc/model/validator/exclusionin.c mvc/model/validator/regex.c mvc/model/validator/url.c mvc/model/validator/inclusionin.c mvc/model/validator/stringlength.c mvc/model/validator/numericality.c mvc/model/validator/email.c mvc/model/query.c mvc/model/resultset/complex.c mvc/model/resultset/simple.c mvc/model/query/builder.c mvc/model/query/statusinterface.c mvc/model/query/status.c mvc/model/query/builderinterface.c mvc/model/query/lang.c mvc/model/resultsetinterface.c mvc/model/exception.c mvc/model/queryinterface.c mvc/model/transactioninterface.c mvc/model/behaviorinterface.c mvc/model/metadatainterface.c mvc/model/messageinterface.c mvc/model/relationinterface.c mvc/model/managerinterface.c mvc/model/criteria.c mvc/model/validatorinterface.c mvc/model/relation.c mvc/model/criteriainterface.c mvc/model/validator.c mvc/model/row.c mvc/model/transaction/exception.c mvc/model/transaction/managerinterface.c mvc/model/transaction/failed.c mvc/model/transaction/manager.c mvc/model/behavior.c mvc/model/resultinterface.c mvc/model/metadata.c mvc/model/message.c mvc/model/manager.c mvc/model/behavior/softdelete.c mvc/model/behavior/timestampable.c mvc/model/metadata/strategy/introspection.c mvc/model/metadata/strategy/annotations.c mvc/model/metadata/memory.c mvc/model/metadata/files.c mvc/model/metadata/apc.c mvc/model/metadata/session.c mvc/model/resultset.c mvc/model/transaction.c mvc/modelinterface.c mvc/routerinterface.c mvc/collectioninterface.c mvc/user/plugin.c mvc/user/module.c mvc/user/component.c mvc/application.c mvc/controllerinterface.c mvc/moduledefinitioninterface.c config/exception.c config/adapter/ini.c exception.c db.c dispatcherinterface.c logger.c cache/frontendinterface.c cache/exception.c cache/frontend/base64.c cache/frontend/output.c cache/frontend/none.c cache/frontend/data.c cache/backendinterface.c cache/backend.c cache/backend/mongo.c cache/backend/memcache.c cache/backend/memory.c cache/backend/apc.c cache/backend/file.c cache/multiple.c acl/adapterinterface.c acl/exception.c acl/resourceinterface.c acl/adapter/memory.c acl/adapter.c acl/role.c acl/roleinterface.c acl/resource.c escaperinterface.c diinterface.c validation.c paginator/adapterinterface.c paginator/exception.c paginator/adapter/model.c paginator/adapter/nativearray.c tag/exception.c tag/select.c filterinterface.c flashinterface.c filter/exception.c security/exception.c flash/direct.c flash/exception.c flash/session.c escaper/exception.c dispatcher.c translate.c db/dialectinterface.c db/profiler.c db/adapterinterface.c db/referenceinterface.c db/columninterface.c db/exception.c db/reference.c db/dialect.c db/adapter/pdo/mysql.c db/adapter/pdo/postgresql.c db/adapter/pdo/sqlite.c db/adapter/pdo.c db/adapter.c db/indexinterface.c db/profiler/item.c db/rawvalue.c db/resultinterface.c db/column.c db/index.c db/result/pdo.c db/dialect/mysql.c db/dialect/postgresql.c db/dialect/sqlite.c tag.c validation/validator/presenceof.c validation/validator/identical.c validation/exception.c validation/validator.c validation/message.c kernel.c http/cookie.c http/cookie/exception.c http/requestinterface.c http/request/exception.c http/request/fileinterface.c http/request/file.c http/response/exception.c http/response/headers.c http/response/cookies.c http/response/headersinterface.c http/response.c http/request.c http/responseinterface.c security.c session.c annotations/reader.c annotations/adapterinterface.c annotations/readerinterface.c annotations/exception.c annotations/collection.c annotations/adapter/memory.c annotations/adapter/files.c annotations/adapter/apc.c annotations/adapter.c annotations/annotation.c annotations/reflection.c version.c flash.c config.c filter.c di/factorydefault/cli.c di/serviceinterface.c di/exception.c di/injectable.c di/service.c di/service/builder.c di/injectionawareinterface.c di/factorydefault.c events/event.c events/exception.c events/managerinterface.c events/eventsawareinterface.c events/manager.c acl.c translate/adapterinterface.c translate/exception.c translate/adapter/nativearray.c translate/adapter.c escaper.c cli/task.c cli/router/exception.c cli/router.c cli/dispatcher/exception.c cli/console.c cli/dispatcher.c cli/console/exception.c logger/adapterinterface.c logger/exception.c logger/adapter/syslog.c logger/adapter/stream.c logger/adapter/file.c logger/adapter.c logger/formatter.c logger/formatter/syslog.c logger/formatter/line.c logger/formatter/json.c logger/item.c logger/formatterinterface.c logger/multiple.c loader/exception.c mvc/model/query/parser.c mvc/model/query/scanner.c mvc/view/engine/volt/parser.c mvc/view/engine/volt/scanner.c annotations/parser.c annotations/scanner.c, $ext_shared)
PHP_NEW_EXTENSION(phalcon, phalcon.c kernel/main.c kernel/fcall.c kernel/require.c kernel/debug.c kernel/assert.c kernel/object.c kernel/array.c kernel/string.c kernel/filter.c kernel/operators.c kernel/concat.c kernel/exception.c kernel/file.c kernel/memory.c kernel/experimental/fcall.c session/adapterinterface.c session/baginterface.c session/exception.c session/adapter/files.c session/adapter.c session/bag.c loader.c di.c forms/element.c forms/exception.c forms/form.c forms/element/text.c forms/manager.c text.c mvc/viewinterface.c mvc/router/exception.c mvc/router/route.c mvc/router/group.c mvc/router/routeinterface.c mvc/router/annotations.c mvc/dispatcherinterface.c mvc/router.c mvc/micro.c mvc/urlinterface.c mvc/dispatcher/exception.c mvc/collection/exception.c mvc/collection/managerinterface.c mvc/collection/manager.c mvc/view.c mvc/collection.c mvc/view/engine.c mvc/view/exception.c mvc/view/engineinterface.c mvc/view/engine/php.c mvc/view/engine/volt.c mvc/view/engine/volt/compiler.c mvc/url.c mvc/controller.c mvc/application/exception.c mvc/url/exception.c mvc/dispatcher.c mvc/model.c mvc/micro/exception.c mvc/micro/collection.c mvc/model/validator/uniqueness.c mvc/model/validator/presenceof.c mvc/model/validator/exclusionin.c mvc/model/validator/regex.c mvc/model/validator/url.c mvc/model/validator/inclusionin.c mvc/model/validator/stringlength.c mvc/model/validator/numericality.c mvc/model/validator/email.c mvc/model/query.c mvc/model/resultset/complex.c mvc/model/resultset/simple.c mvc/model/query/builder.c mvc/model/query/statusinterface.c mvc/model/query/status.c mvc/model/query/builderinterface.c mvc/model/query/lang.c mvc/model/resultsetinterface.c mvc/model/exception.c mvc/model/queryinterface.c mvc/model/transactioninterface.c mvc/model/behaviorinterface.c mvc/model/metadatainterface.c mvc/model/messageinterface.c mvc/model/relationinterface.c mvc/model/managerinterface.c mvc/model/criteria.c mvc/model/validatorinterface.c mvc/model/relation.c mvc/model/criteriainterface.c mvc/model/validator.c mvc/model/row.c mvc/model/transaction/exception.c mvc/model/transaction/managerinterface.c mvc/model/transaction/failed.c mvc/model/transaction/manager.c mvc/model/behavior.c mvc/model/resultinterface.c mvc/model/metadata.c mvc/model/message.c mvc/model/manager.c mvc/model/behavior/softdelete.c mvc/model/behavior/timestampable.c mvc/model/metadata/strategy/introspection.c mvc/model/metadata/strategy/annotations.c mvc/model/metadata/memory.c mvc/model/metadata/files.c mvc/model/metadata/apc.c mvc/model/metadata/session.c mvc/model/resultset.c mvc/model/transaction.c mvc/modelinterface.c mvc/routerinterface.c mvc/collectioninterface.c mvc/user/plugin.c mvc/user/module.c mvc/user/component.c mvc/application.c mvc/controllerinterface.c mvc/moduledefinitioninterface.c config/exception.c config/adapter/ini.c exception.c db.c dispatcherinterface.c logger.c cache/frontendinterface.c cache/exception.c cache/frontend/base64.c cache/frontend/output.c cache/frontend/none.c cache/frontend/data.c cache/backendinterface.c cache/backend.c cache/backend/mongo.c cache/backend/memcache.c cache/backend/memory.c cache/backend/apc.c cache/backend/file.c cache/multiple.c acl/adapterinterface.c acl/exception.c acl/resourceinterface.c acl/adapter/memory.c acl/adapter.c acl/role.c acl/roleinterface.c acl/resource.c escaperinterface.c diinterface.c validation.c paginator/adapterinterface.c paginator/exception.c paginator/adapter/model.c paginator/adapter/nativearray.c tag/exception.c tag/select.c filterinterface.c flashinterface.c filter/exception.c security/exception.c flash/direct.c flash/exception.c flash/session.c escaper/exception.c dispatcher.c translate.c db/dialectinterface.c db/profiler.c db/adapterinterface.c db/referenceinterface.c db/columninterface.c db/exception.c db/reference.c db/dialect.c db/adapter/pdo/mysql.c db/adapter/pdo/postgresql.c db/adapter/pdo/sqlite.c db/adapter/pdo.c db/adapter.c db/indexinterface.c db/profiler/item.c db/rawvalue.c db/resultinterface.c db/column.c db/index.c db/result/pdo.c db/dialect/mysql.c db/dialect/postgresql.c db/dialect/sqlite.c tag.c validation/validator/presenceof.c validation/validator/identical.c validation/validator/stringlength.c validation/exception.c validation/validator.c validation/message.c kernel.c http/cookie.c http/cookie/exception.c http/requestinterface.c http/request/exception.c http/request/fileinterface.c http/request/file.c http/response/exception.c http/response/headers.c http/response/cookies.c http/response/headersinterface.c http/response.c http/request.c http/responseinterface.c security.c session.c annotations/reader.c annotations/adapterinterface.c annotations/readerinterface.c annotations/exception.c annotations/collection.c annotations/adapter/memory.c annotations/adapter/files.c annotations/adapter/apc.c annotations/adapter.c annotations/annotation.c annotations/reflection.c version.c flash.c config.c filter.c di/factorydefault/cli.c di/serviceinterface.c di/exception.c di/injectable.c di/service.c di/service/builder.c di/injectionawareinterface.c di/factorydefault.c events/event.c events/exception.c events/managerinterface.c events/eventsawareinterface.c events/manager.c acl.c translate/adapterinterface.c translate/exception.c translate/adapter/nativearray.c translate/adapter.c escaper.c cli/task.c cli/router/exception.c cli/router.c cli/dispatcher/exception.c cli/console.c cli/dispatcher.c cli/console/exception.c logger/adapterinterface.c logger/exception.c logger/adapter/syslog.c logger/adapter/stream.c logger/adapter/file.c logger/adapter.c logger/formatter.c logger/formatter/syslog.c logger/formatter/line.c logger/formatter/json.c logger/item.c logger/formatterinterface.c logger/multiple.c loader/exception.c mvc/model/query/parser.c mvc/model/query/scanner.c mvc/view/engine/volt/parser.c mvc/view/engine/volt/scanner.c annotations/parser.c annotations/scanner.c, $ext_shared)
fi
2 changes: 1 addition & 1 deletion ext/config.w32
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ if (PHP_PHALCON != "no") {
ADD_SOURCES("ext/phalcon/db/profiler", "item.c", "phalcon")
ADD_SOURCES("ext/phalcon/db/result", "pdo.c", "phalcon")
ADD_SOURCES("ext/phalcon/db/dialect", "mysql.c postgresql.c sqlite.c", "phalcon")
ADD_SOURCES("ext/phalcon/validation/validator", "presenceof.c identical.c", "phalcon")
ADD_SOURCES("ext/phalcon/validation/validator", "presenceof.c identical.c stringlength.c", "phalcon")
ADD_SOURCES("ext/phalcon/validation", "exception.c validator.c message.c", "phalcon")
ADD_SOURCES("ext/phalcon/http", "cookie.c requestinterface.c response.c request.c responseinterface.c", "phalcon")
ADD_SOURCES("ext/phalcon/http/cookie", "exception.c", "phalcon")
10 changes: 10 additions & 0 deletions ext/mvc/micro.c
Original file line number Diff line number Diff line change
@@ -811,6 +811,11 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){
PHALCON_INIT_VAR(returned_value);
PHALCON_CALL_USER_FUNC_ARRAY(returned_value, handler, params);

/**
* Update the returned value
*/
phalcon_update_property_zval(this_ptr, SL("_returnedValue"), returned_value TSRMLS_CC);

/**
* Calling afterExecuteRoute event
*/
@@ -882,6 +887,11 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){
PHALCON_INIT_NVAR(returned_value);
PHALCON_CALL_USER_FUNC(returned_value, not_found_handler);

/**
* Update the returned value
*/
phalcon_update_property_zval(this_ptr, SL("_returnedValue"), returned_value TSRMLS_CC);

RETURN_CCTOR(returned_value);
}

13 changes: 13 additions & 0 deletions ext/mvc/model.c
Original file line number Diff line number Diff line change
@@ -5593,6 +5593,19 @@ PHP_METHOD(Phalcon_Mvc_Model, __callStatic){
}
}

/**
* Check if the method starts with 'count'
*/
if (Z_TYPE_P(extra_method) == IS_NULL) {
if (phalcon_start_with_str(method, SL("countBy"))) {
PHALCON_INIT_NVAR(type);
ZVAL_STRING(type, "count", 1);

PHALCON_INIT_NVAR(extra_method);
phalcon_substr(extra_method, method, 7, 0 TSRMLS_CC);
}
}

/**
* The called class is the model
*/
24 changes: 22 additions & 2 deletions ext/mvc/model/criteria.c
Original file line number Diff line number Diff line change
@@ -35,10 +35,10 @@
#include "kernel/exception.h"
#include "kernel/object.h"
#include "kernel/array.h"
#include "kernel/fcall.h"
#include "kernel/concat.h"
#include "kernel/operators.h"
#include "kernel/file.h"
#include "kernel/fcall.h"
#include "kernel/string.h"

/**
@@ -202,13 +202,33 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, where){
}

/**
* Appends a condition to the current conditions using an AND operator
* Appends a condition to the current conditions using an AND operator (deprecated)
*
* @param string $conditions
* @return Phalcon\Mvc\Model\Criteria
*/
PHP_METHOD(Phalcon_Mvc_Model_Criteria, addWhere){

zval *conditions;

PHALCON_MM_GROW();

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

PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "andwhere", conditions);
RETURN_THIS();
}

/**
* Appends a condition to the current conditions using an AND operator
*
* @param string $conditions
* @return Phalcon\Mvc\Model\Criteria
*/
PHP_METHOD(Phalcon_Mvc_Model_Criteria, andWhere){

zval *conditions, *params, *current_conditions;
zval *new_conditions = NULL;

6 changes: 6 additions & 0 deletions ext/mvc/model/criteria.h
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, getModelName);
PHP_METHOD(Phalcon_Mvc_Model_Criteria, bind);
PHP_METHOD(Phalcon_Mvc_Model_Criteria, where);
PHP_METHOD(Phalcon_Mvc_Model_Criteria, addWhere);
PHP_METHOD(Phalcon_Mvc_Model_Criteria, andWhere);
PHP_METHOD(Phalcon_Mvc_Model_Criteria, orWhere);
PHP_METHOD(Phalcon_Mvc_Model_Criteria, conditions);
PHP_METHOD(Phalcon_Mvc_Model_Criteria, order);
@@ -62,6 +63,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_criteria_addwhere, 0, 0, 1)
ZEND_ARG_INFO(0, conditions)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_criteria_andwhere, 0, 0, 1)
ZEND_ARG_INFO(0, conditions)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_criteria_orwhere, 0, 0, 1)
ZEND_ARG_INFO(0, conditions)
ZEND_END_ARG_INFO()
@@ -101,6 +106,7 @@ PHALCON_INIT_FUNCS(phalcon_mvc_model_criteria_method_entry){
PHP_ME(Phalcon_Mvc_Model_Criteria, bind, arginfo_phalcon_mvc_model_criteria_bind, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Criteria, where, arginfo_phalcon_mvc_model_criteria_where, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Criteria, addWhere, arginfo_phalcon_mvc_model_criteria_addwhere, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Criteria, andWhere, arginfo_phalcon_mvc_model_criteria_andwhere, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Criteria, orWhere, arginfo_phalcon_mvc_model_criteria_orwhere, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Criteria, conditions, arginfo_phalcon_mvc_model_criteria_conditions, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Model_Criteria, order, arginfo_phalcon_mvc_model_criteria_order, ZEND_ACC_PUBLIC)
9 changes: 9 additions & 0 deletions ext/mvc/model/query.c
Original file line number Diff line number Diff line change
@@ -944,6 +944,15 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){
phalcon_array_update_string(&expr_return, SL("right"), &right, PH_COPY | PH_SEPARATE TSRMLS_CC);
break;

case 276:
PHALCON_INIT_NVAR(expr_return);
array_init_size(expr_return, 4);
add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1);
add_assoc_stringl_ex(expr_return, SS("op"), SL("AGAINST"), 1);
phalcon_array_update_string(&expr_return, SL("left"), &left, PH_COPY | PH_SEPARATE TSRMLS_CC);
phalcon_array_update_string(&expr_return, SL("right"), &right, PH_COPY | PH_SEPARATE TSRMLS_CC);
break;

case 350:
PHALCON_INIT_NVAR(expr_return);
PHALCON_CALL_METHOD_PARAMS_1(expr_return, this_ptr, "_getfunctioncall", expr);
1,185 changes: 597 additions & 588 deletions ext/mvc/model/query/parser.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ext/mvc/model/query/parser.h
Original file line number Diff line number Diff line change
@@ -48,8 +48,8 @@
#define PHQL_BY 48
#define PHQL_ASC 49
#define PHQL_DESC 50
#define PHQL_INTEGER 51
#define PHQL_GROUP 52
#define PHQL_GROUP 51
#define PHQL_INTEGER 52
#define PHQL_HAVING 53
#define PHQL_LIMIT 54
#define PHQL_OFFSET 55
24 changes: 10 additions & 14 deletions ext/mvc/model/query/parser.lemon
Original file line number Diff line number Diff line change
@@ -908,24 +908,16 @@ order_list(R) ::= order_item(I) . {

%destructor order_item { zval_ptr_dtor(&$$); }

order_item(R) ::= order_qualified_or_int(Q) . {
R = phql_ret_order_item(Q, 0);
order_item(R) ::= expr(O) . {
R = phql_ret_order_item(O, 0);
}

order_item(R) ::= order_qualified_or_int(Q) ASC . {
R = phql_ret_order_item(Q, PHQL_T_ASC);
order_item(R) ::= expr(O) ASC . {
R = phql_ret_order_item(O, PHQL_T_ASC);
}

order_item(R) ::= order_qualified_or_int(Q) DESC . {
R = phql_ret_order_item(Q, PHQL_T_DESC);
}

order_qualified_or_int(R) ::= qualified_name(Q) . {
R = Q;
}

order_qualified_or_int(R) ::= INTEGER(I) . {
R = phql_ret_literal_zval(PHQL_T_INTEGER, I);
order_item(R) ::= expr(O) DESC . {
R = phql_ret_order_item(O, PHQL_T_DESC);
}

%destructor group_clause { zval_ptr_dtor(&$$); }
@@ -1070,6 +1062,10 @@ expr(R) ::= expr(E) NOT IN BRACKET_OPEN argument_list(L) BRACKET_CLOSE . {
R = phql_ret_expr(PHQL_T_NOTIN, E, L);
}

expr(R) ::= expr(O1) AGAINST expr(O2) . {
R = phql_ret_expr(PHQL_T_AGAINST, O1, O2);
}

%destructor function_call { zval_ptr_dtor(&$$); }

expr(R) ::= function_call(F) . {
2 changes: 1 addition & 1 deletion ext/mvc/model/query/scanner.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Generated by re2c 0.13.5 on Wed Feb 20 02:54:37 2013 */
/* Generated by re2c 0.13.5 on Sun Feb 24 21:26:18 2013 */
// 1 "scanner.re"

/*
92 changes: 47 additions & 45 deletions ext/phalcon.c
Original file line number Diff line number Diff line change
@@ -33,25 +33,25 @@
#include "kernel/memory.h"


zend_class_entry *phalcon_tag_ce;
zend_class_entry *phalcon_di_ce;
zend_class_entry *phalcon_acl_ce;
zend_class_entry *phalcon_text_ce;
zend_class_entry *phalcon_db_ce;
zend_class_entry *phalcon_di_ce;
zend_class_entry *phalcon_tag_ce;
zend_class_entry *phalcon_text_ce;
zend_class_entry *phalcon_cache_backend_ce;
zend_class_entry *phalcon_cache_multiple_ce;
zend_class_entry *phalcon_cache_exception_ce;
zend_class_entry *phalcon_cache_multiple_ce;
zend_class_entry *phalcon_cache_backend_memory_ce;
zend_class_entry *phalcon_cache_backend_mongo_ce;
zend_class_entry *phalcon_cache_backend_file_ce;
zend_class_entry *phalcon_cache_frontend_none_ce;
zend_class_entry *phalcon_cache_backend_apc_ce;
zend_class_entry *phalcon_cache_frontend_data_ce;
zend_class_entry *phalcon_cache_frontend_output_ce;
zend_class_entry *phalcon_cache_backendinterface_ce;
zend_class_entry *phalcon_cache_backend_memcache_ce;
zend_class_entry *phalcon_cache_frontendinterface_ce;
zend_class_entry *phalcon_cache_frontend_output_ce;
zend_class_entry *phalcon_cache_frontend_base64_ce;
zend_class_entry *phalcon_cache_frontendinterface_ce;
zend_class_entry *phalcon_tag_select_ce;
zend_class_entry *phalcon_tag_exception_ce;
zend_class_entry *phalcon_paginator_exception_ce;
@@ -62,19 +62,20 @@ zend_class_entry *phalcon_validation_ce;
zend_class_entry *phalcon_validation_validator_ce;
zend_class_entry *phalcon_validation_message_ce;
zend_class_entry *phalcon_validation_exception_ce;
zend_class_entry *phalcon_validation_validator_presenceof_ce;
zend_class_entry *phalcon_validation_validator_identical_ce;
zend_class_entry *phalcon_validation_validator_presenceof_ce;
zend_class_entry *phalcon_validation_validator_stringlength_ce;
zend_class_entry *phalcon_db_index_ce;
zend_class_entry *phalcon_db_profiler_ce;
zend_class_entry *phalcon_db_adapter_ce;
zend_class_entry *phalcon_db_reference_ce;
zend_class_entry *phalcon_db_exception_ce;
zend_class_entry *phalcon_db_dialect_ce;
zend_class_entry *phalcon_db_column_ce;
zend_class_entry *phalcon_db_reference_ce;
zend_class_entry *phalcon_db_rawvalue_ce;
zend_class_entry *phalcon_db_adapter_pdo_ce;
zend_class_entry *phalcon_db_adapter_pdo_mysql_ce;
zend_class_entry *phalcon_db_adapterinterface_ce;
zend_class_entry *phalcon_db_adapter_pdo_mysql_ce;
zend_class_entry *phalcon_db_adapter_pdo_sqlite_ce;
zend_class_entry *phalcon_db_adapter_pdo_postgresql_ce;
zend_class_entry *phalcon_db_columninterface_ce;
@@ -104,8 +105,8 @@ zend_class_entry *phalcon_session_bag_ce;
zend_class_entry *phalcon_session_adapter_ce;
zend_class_entry *phalcon_session_baginterface_ce;
zend_class_entry *phalcon_session_exception_ce;
zend_class_entry *phalcon_session_adapterinterface_ce;
zend_class_entry *phalcon_session_adapter_files_ce;
zend_class_entry *phalcon_session_adapterinterface_ce;
zend_class_entry *phalcon_filter_ce;
zend_class_entry *phalcon_di_exception_ce;
zend_class_entry *phalcon_di_service_ce;
@@ -124,8 +125,8 @@ zend_class_entry *phalcon_flash_ce;
zend_class_entry *phalcon_cli_task_ce;
zend_class_entry *phalcon_flash_direct_ce;
zend_class_entry *phalcon_flashinterface_ce;
zend_class_entry *phalcon_flash_session_ce;
zend_class_entry *phalcon_flash_exception_ce;
zend_class_entry *phalcon_flash_session_ce;
zend_class_entry *phalcon_cli_router_ce;
zend_class_entry *phalcon_cli_console_ce;
zend_class_entry *phalcon_cli_dispatcher_ce;
@@ -134,38 +135,38 @@ zend_class_entry *phalcon_cli_dispatcher_exception_ce;
zend_class_entry *phalcon_cli_router_exception_ce;
zend_class_entry *phalcon_annotations_adapter_ce;
zend_class_entry *phalcon_annotations_reader_ce;
zend_class_entry *phalcon_annotations_collection_ce;
zend_class_entry *phalcon_annotations_reflection_ce;
zend_class_entry *phalcon_annotations_annotation_ce;
zend_class_entry *phalcon_annotations_adapter_apc_ce;
zend_class_entry *phalcon_annotations_reflection_ce;
zend_class_entry *phalcon_annotations_collection_ce;
zend_class_entry *phalcon_annotations_exception_ce;
zend_class_entry *phalcon_annotations_adapter_memory_ce;
zend_class_entry *phalcon_annotations_adapter_files_ce;
zend_class_entry *phalcon_annotations_adapterinterface_ce;
zend_class_entry *phalcon_annotations_readerinterface_ce;
zend_class_entry *phalcon_loader_ce;
zend_class_entry *phalcon_config_ce;
zend_class_entry *phalcon_logger_ce;
zend_class_entry *phalcon_loader_ce;
zend_class_entry *phalcon_loader_exception_ce;
zend_class_entry *phalcon_logger_item_ce;
zend_class_entry *phalcon_logger_multiple_ce;
zend_class_entry *phalcon_logger_formatter_ce;
zend_class_entry *phalcon_logger_adapter_ce;
zend_class_entry *phalcon_logger_exception_ce;
zend_class_entry *phalcon_logger_formatter_ce;
zend_class_entry *phalcon_logger_multiple_ce;
zend_class_entry *phalcon_logger_adapter_file_ce;
zend_class_entry *phalcon_logger_adapterinterface_ce;
zend_class_entry *phalcon_logger_formatter_syslog_ce;
zend_class_entry *phalcon_logger_adapter_stream_ce;
zend_class_entry *phalcon_logger_adapter_syslog_ce;
zend_class_entry *phalcon_logger_formatter_json_ce;
zend_class_entry *phalcon_logger_formatter_line_ce;
zend_class_entry *phalcon_logger_formatter_json_ce;
zend_class_entry *phalcon_logger_adapter_stream_ce;
zend_class_entry *phalcon_logger_formatterinterface_ce;
zend_class_entry *phalcon_config_exception_ce;
zend_class_entry *phalcon_config_adapter_ini_ce;
zend_class_entry *phalcon_forms_form_ce;
zend_class_entry *phalcon_forms_element_ce;
zend_class_entry *phalcon_forms_exception_ce;
zend_class_entry *phalcon_forms_manager_ce;
zend_class_entry *phalcon_forms_exception_ce;
zend_class_entry *phalcon_forms_element_text_ce;
zend_class_entry *phalcon_translate_ce;
zend_class_entry *phalcon_translate_adapter_ce;
@@ -181,38 +182,38 @@ zend_class_entry *phalcon_http_response_ce;
zend_class_entry *phalcon_http_request_file_ce;
zend_class_entry *phalcon_http_cookie_exception_ce;
zend_class_entry *phalcon_http_requestinterface_ce;
zend_class_entry *phalcon_http_response_cookies_ce;
zend_class_entry *phalcon_http_responseinterface_ce;
zend_class_entry *phalcon_http_response_headers_ce;
zend_class_entry *phalcon_http_responseinterface_ce;
zend_class_entry *phalcon_http_response_cookies_ce;
zend_class_entry *phalcon_http_response_exception_ce;
zend_class_entry *phalcon_http_request_exception_ce;
zend_class_entry *phalcon_http_request_fileinterface_ce;
zend_class_entry *phalcon_http_response_headersinterface_ce;
zend_class_entry *phalcon_mvc_view_ce;
zend_class_entry *phalcon_mvc_url_ce;
zend_class_entry *phalcon_mvc_micro_ce;
zend_class_entry *phalcon_mvc_model_ce;
zend_class_entry *phalcon_mvc_micro_ce;
zend_class_entry *phalcon_mvc_router_ce;
zend_class_entry *phalcon_mvc_user_plugin_ce;
zend_class_entry *phalcon_mvc_view_engine_ce;
zend_class_entry *phalcon_mvc_router_route_ce;
zend_class_entry *phalcon_mvc_controller_ce;
zend_class_entry *phalcon_mvc_collection_ce;
zend_class_entry *phalcon_mvc_application_ce;
zend_class_entry *phalcon_mvc_router_group_ce;
zend_class_entry *phalcon_mvc_user_module_ce;
zend_class_entry *phalcon_mvc_urlinterface_ce;
zend_class_entry *phalcon_mvc_dispatcher_ce;
zend_class_entry *phalcon_mvc_model_row_ce;
zend_class_entry *phalcon_mvc_collection_ce;
zend_class_entry *phalcon_mvc_controller_ce;
zend_class_entry *phalcon_mvc_model_query_ce;
zend_class_entry *phalcon_mvc_application_exception_ce;
zend_class_entry *phalcon_mvc_collectioninterface_ce;
zend_class_entry *phalcon_mvc_collection_manager_ce;
zend_class_entry *phalcon_mvc_controllerinterface_ce;
zend_class_entry *phalcon_mvc_collection_exception_ce;
zend_class_entry *phalcon_mvc_collection_manager_ce;
zend_class_entry *phalcon_mvc_collection_managerinterface_ce;
zend_class_entry *phalcon_mvc_dispatcherinterface_ce;
zend_class_entry *phalcon_mvc_dispatcher_exception_ce;
zend_class_entry *phalcon_mvc_dispatcherinterface_ce;
zend_class_entry *phalcon_mvc_model_behavior_ce;
zend_class_entry *phalcon_mvc_model_message_ce;
zend_class_entry *phalcon_mvc_model_query_lang_ce;
@@ -376,9 +377,9 @@ PHP_MINIT_FUNCTION(phalcon){
PHALCON_INIT(Phalcon_Db_Adapter_Pdo);
PHALCON_INIT(Phalcon_Logger_Adapter);
PHALCON_INIT(Phalcon_Annotations_Adapter);
PHALCON_INIT(Phalcon_Validation_Validator);
PHALCON_INIT(Phalcon_Db_Dialect);
PHALCON_INIT(Phalcon_Flash);
PHALCON_INIT(Phalcon_Validation_Validator);
PHALCON_INIT(Phalcon_DI);
PHALCON_INIT(Phalcon_Dispatcher);
PHALCON_INIT(Phalcon_Mvc_Model_Behavior);
@@ -392,19 +393,19 @@ PHP_MINIT_FUNCTION(phalcon){
PHALCON_INIT(Phalcon_DI_FactoryDefault);
PHALCON_INIT(Phalcon_Mvc_Router);
PHALCON_INIT(Phalcon_Mvc_Model_Exception);
PHALCON_INIT(Phalcon_Tag);
PHALCON_INIT(Phalcon_Db);
PHALCON_INIT(Phalcon_Acl);
PHALCON_INIT(Phalcon_Cache_Exception);
PHALCON_INIT(Phalcon_Tag);
PHALCON_INIT(Phalcon_Cache_Multiple);
PHALCON_INIT(Phalcon_Cache_Exception);
PHALCON_INIT(Phalcon_Cache_Backend_File);
PHALCON_INIT(Phalcon_Cache_Backend_Apc);
PHALCON_INIT(Phalcon_Cache_Backend_Mongo);
PHALCON_INIT(Phalcon_Cache_Backend_Memory);
PHALCON_INIT(Phalcon_Cache_Backend_Memcache);
PHALCON_INIT(Phalcon_Cache_Frontend_Output);
PHALCON_INIT(Phalcon_Cache_Frontend_Data);
PHALCON_INIT(Phalcon_Cache_Frontend_None);
PHALCON_INIT(Phalcon_Cache_Frontend_Data);
PHALCON_INIT(Phalcon_Cache_Frontend_Output);
PHALCON_INIT(Phalcon_Cache_Frontend_Base64);
PHALCON_INIT(Phalcon_Tag_Select);
PHALCON_INIT(Phalcon_Tag_Exception);
@@ -416,8 +417,9 @@ PHP_MINIT_FUNCTION(phalcon){
PHALCON_INIT(Phalcon_Validation_Exception);
PHALCON_INIT(Phalcon_Validation_Validator_Identical);
PHALCON_INIT(Phalcon_Validation_Validator_PresenceOf);
PHALCON_INIT(Phalcon_Db_Column);
PHALCON_INIT(Phalcon_Validation_Validator_StringLength);
PHALCON_INIT(Phalcon_Db_Index);
PHALCON_INIT(Phalcon_Db_Column);
PHALCON_INIT(Phalcon_Db_Adapter_Pdo_Mysql);
PHALCON_INIT(Phalcon_Db_Adapter_Pdo_Sqlite);
PHALCON_INIT(Phalcon_Db_Adapter_Pdo_Postgresql);
@@ -427,16 +429,16 @@ PHP_MINIT_FUNCTION(phalcon){
PHALCON_INIT(Phalcon_Db_Exception);
PHALCON_INIT(Phalcon_Db_Profiler);
PHALCON_INIT(Phalcon_Db_Profiler_Item);
PHALCON_INIT(Phalcon_Db_Reference);
PHALCON_INIT(Phalcon_Db_RawValue);
PHALCON_INIT(Phalcon_Db_Reference);
PHALCON_INIT(Phalcon_Db_Result_Pdo);
PHALCON_INIT(Phalcon_Db_ResultInterface);
PHALCON_INIT(Phalcon_Acl_Role);
PHALCON_INIT(Phalcon_Acl_Resource);
PHALCON_INIT(Phalcon_Acl_Adapter_Memory);
PHALCON_INIT(Phalcon_Acl_Exception);
PHALCON_INIT(Phalcon_Text);
PHALCON_INIT(Phalcon_Kernel);
PHALCON_INIT(Phalcon_Text);
PHALCON_INIT(Phalcon_Security);
PHALCON_INIT(Phalcon_Security_Exception);
PHALCON_INIT(Phalcon_Version);
@@ -451,8 +453,8 @@ PHP_MINIT_FUNCTION(phalcon){
PHALCON_INIT(Phalcon_DI_Service_Builder);
PHALCON_INIT(Phalcon_Filter_Exception);
PHALCON_INIT(Phalcon_Flash_Direct);
PHALCON_INIT(Phalcon_Flash_Exception);
PHALCON_INIT(Phalcon_Flash_Session);
PHALCON_INIT(Phalcon_Flash_Exception);
PHALCON_INIT(Phalcon_CLI_Task);
PHALCON_INIT(Phalcon_CLI_Console);
PHALCON_INIT(Phalcon_CLI_Router);
@@ -462,29 +464,29 @@ PHP_MINIT_FUNCTION(phalcon){
PHALCON_INIT(Phalcon_CLI_Router_Exception);
PHALCON_INIT(Phalcon_Annotations_Reader);
PHALCON_INIT(Phalcon_Annotations_Exception);
PHALCON_INIT(Phalcon_Annotations_Collection);
PHALCON_INIT(Phalcon_Annotations_Adapter_Apc);
PHALCON_INIT(Phalcon_Annotations_Reflection);
PHALCON_INIT(Phalcon_Annotations_Adapter_Apc);
PHALCON_INIT(Phalcon_Annotations_Collection);
PHALCON_INIT(Phalcon_Annotations_Annotation);
PHALCON_INIT(Phalcon_Annotations_Adapter_Files);
PHALCON_INIT(Phalcon_Annotations_Adapter_Memory);
PHALCON_INIT(Phalcon_Loader);
PHALCON_INIT(Phalcon_Logger);
PHALCON_INIT(Phalcon_Loader);
PHALCON_INIT(Phalcon_Loader_Exception);
PHALCON_INIT(Phalcon_Logger_Item);
PHALCON_INIT(Phalcon_Logger_Multiple);
PHALCON_INIT(Phalcon_Logger_Exception);
PHALCON_INIT(Phalcon_Logger_Adapter_Syslog);
PHALCON_INIT(Phalcon_Logger_Adapter_Stream);
PHALCON_INIT(Phalcon_Logger_Adapter_File);
PHALCON_INIT(Phalcon_Logger_Formatter_Line);
PHALCON_INIT(Phalcon_Logger_Formatter_Json);
PHALCON_INIT(Phalcon_Logger_Adapter_Syslog);
PHALCON_INIT(Phalcon_Logger_Formatter_Line);
PHALCON_INIT(Phalcon_Logger_Formatter_Syslog);
PHALCON_INIT(Phalcon_Config_Exception);
PHALCON_INIT(Phalcon_Config_Adapter_Ini);
PHALCON_INIT(Phalcon_Forms_Form);
PHALCON_INIT(Phalcon_Forms_Exception);
PHALCON_INIT(Phalcon_Forms_Manager);
PHALCON_INIT(Phalcon_Forms_Exception);
PHALCON_INIT(Phalcon_Forms_Element_Text);
PHALCON_INIT(Phalcon_Translate);
PHALCON_INIT(Phalcon_Translate_Exception);
@@ -496,18 +498,18 @@ PHP_MINIT_FUNCTION(phalcon){
PHALCON_INIT(Phalcon_Http_Response);
PHALCON_INIT(Phalcon_Http_Cookie_Exception);
PHALCON_INIT(Phalcon_Http_Request_File);
PHALCON_INIT(Phalcon_Http_Response_Cookies);
PHALCON_INIT(Phalcon_Http_Response_Headers);
PHALCON_INIT(Phalcon_Http_Response_Cookies);
PHALCON_INIT(Phalcon_Http_Request_Exception);
PHALCON_INIT(Phalcon_Http_Response_Exception);
PHALCON_INIT(Phalcon_Mvc_Url);
PHALCON_INIT(Phalcon_Mvc_Micro);
PHALCON_INIT(Phalcon_Mvc_View);
PHALCON_INIT(Phalcon_Mvc_Model);
PHALCON_INIT(Phalcon_Mvc_View);
PHALCON_INIT(Phalcon_Mvc_Micro);
PHALCON_INIT(Phalcon_Mvc_Application);
PHALCON_INIT(Phalcon_Mvc_Application_Exception);
PHALCON_INIT(Phalcon_Mvc_Controller);
PHALCON_INIT(Phalcon_Mvc_Collection);
PHALCON_INIT(Phalcon_Mvc_Controller);
PHALCON_INIT(Phalcon_Mvc_Collection_Manager);
PHALCON_INIT(Phalcon_Mvc_Collection_Exception);
PHALCON_INIT(Phalcon_Mvc_Collection_ManagerInterface);
39 changes: 20 additions & 19 deletions ext/phalcon.h
Original file line number Diff line number Diff line change
@@ -80,9 +80,9 @@
#include "db/adapter/pdo.h"
#include "logger/adapter.h"
#include "annotations/adapter.h"
#include "validation/validator.h"
#include "db/dialect.h"
#include "flash.h"
#include "validation/validator.h"
#include "di.h"
#include "dispatcher.h"
#include "mvc/model/behavior.h"
@@ -96,19 +96,19 @@
#include "di/factorydefault.h"
#include "mvc/router.h"
#include "mvc/model/exception.h"
#include "tag.h"
#include "db.h"
#include "acl.h"
#include "cache/exception.h"
#include "tag.h"
#include "cache/multiple.h"
#include "cache/exception.h"
#include "cache/backend/file.h"
#include "cache/backend/apc.h"
#include "cache/backend/mongo.h"
#include "cache/backend/memory.h"
#include "cache/backend/memcache.h"
#include "cache/frontend/output.h"
#include "cache/frontend/data.h"
#include "cache/frontend/none.h"
#include "cache/frontend/data.h"
#include "cache/frontend/output.h"
#include "cache/frontend/base64.h"
#include "tag/select.h"
#include "tag/exception.h"
@@ -120,8 +120,9 @@
#include "validation/exception.h"
#include "validation/validator/identical.h"
#include "validation/validator/presenceof.h"
#include "db/column.h"
#include "validation/validator/stringlength.h"
#include "db/index.h"
#include "db/column.h"
#include "db/adapter/pdo/mysql.h"
#include "db/adapter/pdo/sqlite.h"
#include "db/adapter/pdo/postgresql.h"
@@ -131,16 +132,16 @@
#include "db/exception.h"
#include "db/profiler.h"
#include "db/profiler/item.h"
#include "db/reference.h"
#include "db/rawvalue.h"
#include "db/reference.h"
#include "db/result/pdo.h"
#include "db/resultinterface.h"
#include "acl/role.h"
#include "acl/resource.h"
#include "acl/adapter/memory.h"
#include "acl/exception.h"
#include "text.h"
#include "kernel.h"
#include "text.h"
#include "security.h"
#include "security/exception.h"
#include "version.h"
@@ -155,8 +156,8 @@
#include "di/service/builder.h"
#include "filter/exception.h"
#include "flash/direct.h"
#include "flash/exception.h"
#include "flash/session.h"
#include "flash/exception.h"
#include "cli/task.h"
#include "cli/console.h"
#include "cli/router.h"
@@ -166,29 +167,29 @@
#include "cli/router/exception.h"
#include "annotations/reader.h"
#include "annotations/exception.h"
#include "annotations/collection.h"
#include "annotations/adapter/apc.h"
#include "annotations/reflection.h"
#include "annotations/adapter/apc.h"
#include "annotations/collection.h"
#include "annotations/annotation.h"
#include "annotations/adapter/files.h"
#include "annotations/adapter/memory.h"
#include "loader.h"
#include "logger.h"
#include "loader.h"
#include "loader/exception.h"
#include "logger/item.h"
#include "logger/multiple.h"
#include "logger/exception.h"
#include "logger/adapter/syslog.h"
#include "logger/adapter/stream.h"
#include "logger/adapter/file.h"
#include "logger/formatter/line.h"
#include "logger/formatter/json.h"
#include "logger/adapter/syslog.h"
#include "logger/formatter/line.h"
#include "logger/formatter/syslog.h"
#include "config/exception.h"
#include "config/adapter/ini.h"
#include "forms/form.h"
#include "forms/exception.h"
#include "forms/manager.h"
#include "forms/exception.h"
#include "forms/element/text.h"
#include "translate.h"
#include "translate/exception.h"
@@ -200,18 +201,18 @@
#include "http/response.h"
#include "http/cookie/exception.h"
#include "http/request/file.h"
#include "http/response/cookies.h"
#include "http/response/headers.h"
#include "http/response/cookies.h"
#include "http/request/exception.h"
#include "http/response/exception.h"
#include "mvc/url.h"
#include "mvc/micro.h"
#include "mvc/view.h"
#include "mvc/model.h"
#include "mvc/view.h"
#include "mvc/micro.h"
#include "mvc/application.h"
#include "mvc/application/exception.h"
#include "mvc/controller.h"
#include "mvc/collection.h"
#include "mvc/controller.h"
#include "mvc/collection/manager.h"
#include "mvc/collection/exception.h"
#include "mvc/collection/managerinterface.h"
143 changes: 128 additions & 15 deletions ext/validation.c
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
#include "kernel/exception.h"
#include "kernel/array.h"
#include "kernel/fcall.h"
#include "kernel/concat.h"

/**
* Phalcon\Validation
@@ -50,30 +51,41 @@ PHALCON_INIT_CLASS(Phalcon_Validation){
PHALCON_REGISTER_CLASS(Phalcon, Validation, validation, phalcon_validation_method_entry, 0);

zend_declare_property_null(phalcon_validation_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_entity"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_validators"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_validation_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC);

return SUCCESS;
}

/**
* Validate a set of data according to a set of rules
*
* @param array|object $data
* @param object $entity
*/
PHP_METHOD(Phalcon_Validation, validate){

zval *data = NULL, *validators, *scope = NULL, *attribute = NULL, *validator = NULL;
zval *messages;
zval *data = NULL, *entity = NULL, *validators, *scope = NULL, *attribute = NULL;
zval *validator = NULL, *messages;
HashTable *ah0;
HashPosition hp0;
zval **hd;

PHALCON_MM_GROW();

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &data) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &data, &entity) == FAILURE) {
RETURN_MM_NULL();
}

if (!data) {
PHALCON_INIT_VAR(data);
}

if (!entity) {
PHALCON_INIT_VAR(entity);
}

phalcon_update_property_null(this_ptr, SL("_messages") TSRMLS_CC);
if (Z_TYPE_P(data) == IS_ARRAY) {
phalcon_update_property_zval(this_ptr, SL("_data"), data TSRMLS_CC);
@@ -114,12 +126,22 @@ PHP_METHOD(Phalcon_Validation, validate){
zend_hash_move_forward_ex(ah0, &hp0);
}

/**
* Get the messages generated by the validators
*/
PHALCON_OBS_VAR(messages);
phalcon_read_property(&messages, this_ptr, SL("_messages"), PH_NOISY_CC);

RETURN_CCTOR(messages);
}

/**
* Adds a validator to a field
*
* @param string $attribute
* @param Phalcon\Validation\ValidatorInterface
* @return Phalcon\Validator
*/
PHP_METHOD(Phalcon_Validation, add){

zval *attribute, *validator, *scope;
@@ -145,64 +167,155 @@ PHP_METHOD(Phalcon_Validation, add){
phalcon_array_append(&scope, validator, PH_SEPARATE TSRMLS_CC);
phalcon_update_property_array_append(this_ptr, SL("_validators"), scope TSRMLS_CC);

PHALCON_MM_RESTORE();
RETURN_THIS();
}

/**
* Returns the data that is currently validated
*
* @return array
*/
PHP_METHOD(Phalcon_Validation, getData){


RETURN_MEMBER(this_ptr, "_data");
}

/**
* Returns the bound entity
*
* @return object
*/
PHP_METHOD(Phalcon_Validation, getEntity){


RETURN_MEMBER(this_ptr, "_entity");
}

/**
* Returns the registered validators
*
* @return array
*/
PHP_METHOD(Phalcon_Validation, getValidators){


RETURN_MEMBER(this_ptr, "_validators");
}

/**
* Returns the validation messages produced by the validation process
*
* @return array
*/
PHP_METHOD(Phalcon_Validation, getMessages){


RETURN_MEMBER(this_ptr, "_messages");
}

/**
* Appends a message to the messages list
*
* @param Phalcon\Validation\MessageInterface $message
*/
PHP_METHOD(Phalcon_Validation, appendMessage){

zval *message;

PHALCON_MM_GROW();

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &message) == FAILURE) {
RETURN_NULL();
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();
}

/**
* Assigns the data to an entity
* The entity is used to obtain the validation values
*
* @param object $entity
* @param array $data
* @return Phalcon\Validator
*/
PHP_METHOD(Phalcon_Validation, bind){

zval *data;
zval *entity, *data;

PHALCON_MM_GROW();

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

if (Z_TYPE_P(entity) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The entity must be an object");
return;
}
if (Z_TYPE_P(data) != IS_ARRAY) {
if (Z_TYPE_P(data) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The data to validate must be an array or object");
return;
}
}

phalcon_update_property_zval(this_ptr, SL("_data"), data TSRMLS_CC);

PHALCON_MM_RESTORE();
RETURN_THIS();
}

/**
* Obtain an value from the data passed to the validator
* If an entity is
*
* @param string $attribute
* @return mixed
*/
PHP_METHOD(Phalcon_Validation, getValue){

zval *key, *data, *value = NULL;
zval *attribute, *entity, *method, *value = NULL, *data;

PHALCON_MM_GROW();

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

PHALCON_OBS_VAR(entity);
phalcon_read_property(&entity, this_ptr, SL("_entity"), PH_NOISY_CC);

/**
* If the entity is an object use it to retrieve the values
*/
if (Z_TYPE_P(entity) == IS_OBJECT) {

PHALCON_INIT_VAR(method);
PHALCON_CONCAT_SV(method, "get", attribute);
if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_VAR(value);
PHALCON_CALL_METHOD(value, entity, Z_STRVAL_P(method));
} else {
if (phalcon_method_exists_ex(entity, SS("readattribute") TSRMLS_CC) == SUCCESS) {
PHALCON_INIT_NVAR(value);
PHALCON_CALL_METHOD_PARAMS_1(value, entity, "readattribute", attribute);
} else {
PHALCON_OBS_NVAR(value);
phalcon_read_property_zval(&value, entity, attribute, PH_NOISY_CC);
}
}


RETURN_CCTOR(value);
}

PHALCON_OBS_VAR(data);
phalcon_read_property(&data, this_ptr, SL("_data"), PH_NOISY_CC);
if (Z_TYPE_P(data) != IS_ARRAY) {
@@ -213,17 +326,17 @@ PHP_METHOD(Phalcon_Validation, getValue){
}

if (Z_TYPE_P(data) == IS_ARRAY) {
if (phalcon_array_isset(data, key)) {
PHALCON_OBS_VAR(value);
phalcon_array_fetch(&value, data, key, PH_NOISY_CC);
if (phalcon_array_isset(data, attribute)) {
PHALCON_OBS_NVAR(value);
phalcon_array_fetch(&value, data, attribute, PH_NOISY_CC);
RETURN_CCTOR(value);
}
}

if (Z_TYPE_P(data) == IS_OBJECT) {
if (phalcon_isset_property_zval(data, key TSRMLS_CC)) {
if (phalcon_isset_property_zval(data, attribute TSRMLS_CC)) {
PHALCON_OBS_NVAR(value);
phalcon_read_property_zval(&value, data, key, PH_NOISY_CC);
phalcon_read_property_zval(&value, data, attribute, PH_NOISY_CC);
RETURN_CCTOR(value);
}
}
10 changes: 8 additions & 2 deletions ext/validation.h
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ PHALCON_INIT_CLASS(Phalcon_Validation);

PHP_METHOD(Phalcon_Validation, validate);
PHP_METHOD(Phalcon_Validation, add);
PHP_METHOD(Phalcon_Validation, getData);
PHP_METHOD(Phalcon_Validation, getEntity);
PHP_METHOD(Phalcon_Validation, getValidators);
PHP_METHOD(Phalcon_Validation, getMessages);
PHP_METHOD(Phalcon_Validation, appendMessage);
@@ -31,6 +33,7 @@ PHP_METHOD(Phalcon_Validation, getValue);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_validate, 0, 0, 0)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, entity)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_add, 0, 0, 2)
@@ -42,17 +45,20 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_appendmessage, 0, 0, 1)
ZEND_ARG_INFO(0, message)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_bind, 0, 0, 1)
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_bind, 0, 0, 2)
ZEND_ARG_INFO(0, entity)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_getvalue, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, attribute)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_validation_method_entry){
PHP_ME(Phalcon_Validation, validate, arginfo_phalcon_validation_validate, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, add, arginfo_phalcon_validation_add, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getData, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getEntity, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getValidators, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, getMessages, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Validation, appendMessage, arginfo_phalcon_validation_appendmessage, ZEND_ACC_PUBLIC)
2 changes: 1 addition & 1 deletion ext/validation/validator/identical.c
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ PHP_METHOD(Phalcon_Validation_Validator_Identical, validate){
PHALCON_CALL_METHOD_PARAMS_1(message_str, this_ptr, "getoption", option);
if (!zend_is_true(message_str)) {
PHALCON_INIT_NVAR(message_str);
PHALCON_CONCAT_VS(message_str, attribute, " doest not have the expected value");
PHALCON_CONCAT_VS(message_str, attribute, " does not have the expected value");
}

PHALCON_INIT_VAR(type);
14 changes: 14 additions & 0 deletions ext/validation/validator/presenceof.c
Original file line number Diff line number Diff line change
@@ -36,6 +36,13 @@
#include "kernel/operators.h"
#include "kernel/concat.h"

/**
* Phalcon\Validation\Validator\PresenceOf
*
* Validates that a value is not null or empty string
*/


/**
* Phalcon\Validation\Validator\PresenceOf initializer
*/
@@ -46,6 +53,13 @@ PHALCON_INIT_CLASS(Phalcon_Validation_Validator_PresenceOf){
return SUCCESS;
}

/**
* Executes the validation
*
* @param Phalcon\Validator $validator
* @param string $attribute
* @return boolean
*/
PHP_METHOD(Phalcon_Validation_Validator_PresenceOf, validate){

zval *validator, *attribute, *value, *type, *option;
106 changes: 106 additions & 0 deletions ext/validation/validator/stringlength.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_phalcon.h"
#include "phalcon.h"

#include "Zend/zend_operators.h"
#include "Zend/zend_exceptions.h"
#include "Zend/zend_interfaces.h"

#include "kernel/main.h"
#include "kernel/memory.h"

#include "kernel/fcall.h"
#include "kernel/operators.h"
#include "kernel/concat.h"

/**
* Phalcon\Validation\Validator\StringLength
*
* Validates that a value is not null or empty string
*/


/**
* Phalcon\Validation\Validator\StringLength initializer
*/
PHALCON_INIT_CLASS(Phalcon_Validation_Validator_StringLength){

PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, StringLength, validation_validator_stringlength, "phalcon\\validation\\validator", phalcon_validation_validator_stringlength_method_entry, 0);

return SUCCESS;
}

/**
* Executes the validation
*
* @param Phalcon\Validator $validator
* @param string $attribute
* @return boolean
*/
PHP_METHOD(Phalcon_Validation_Validator_StringLength, validate){

zval *validator, *attribute, *value, *option = NULL, *identical_value;
zval *message_str = NULL, *type, *message;

PHALCON_MM_GROW();

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &validator, &attribute) == FAILURE) {
RETURN_MM_NULL();
}

PHALCON_INIT_VAR(value);
PHALCON_CALL_METHOD_PARAMS_1(value, validator, "getvalue", attribute);

PHALCON_INIT_VAR(option);
ZVAL_STRING(option, "value", 1);

PHALCON_INIT_VAR(identical_value);
PHALCON_CALL_METHOD_PARAMS_1(identical_value, this_ptr, "getoption", option);
if (!PHALCON_IS_EQUAL(value, identical_value)) {

PHALCON_INIT_NVAR(option);
ZVAL_STRING(option, "message", 1);

PHALCON_INIT_VAR(message_str);
PHALCON_CALL_METHOD_PARAMS_1(message_str, this_ptr, "getoption", option);
if (!zend_is_true(message_str)) {
PHALCON_INIT_NVAR(message_str);
PHALCON_CONCAT_VS(message_str, attribute, " does not have the expected value");
}

PHALCON_INIT_VAR(type);
ZVAL_STRING(type, "Identical", 1);

PHALCON_INIT_VAR(message);
object_init_ex(message, phalcon_validation_message_ce);
PHALCON_CALL_METHOD_PARAMS_3_NORETURN(message, "__construct", message_str, attribute, type);

PHALCON_CALL_METHOD_PARAMS_1_NORETURN(validator, "appendmessage", message);
}

PHALCON_MM_RESTORE();
}

35 changes: 35 additions & 0 deletions ext/validation/validator/stringlength.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/

extern zend_class_entry *phalcon_validation_validator_stringlength_ce;

PHALCON_INIT_CLASS(Phalcon_Validation_Validator_StringLength);

PHP_METHOD(Phalcon_Validation_Validator_StringLength, validate);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_validation_validator_stringlength_validate, 0, 0, 2)
ZEND_ARG_INFO(0, validator)
ZEND_ARG_INFO(0, attribute)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_validation_validator_stringlength_method_entry){
PHP_ME(Phalcon_Validation_Validator_StringLength, validate, arginfo_phalcon_validation_validator_stringlength_validate, ZEND_ACC_PUBLIC)
PHP_FE_END
};

0 comments on commit d3c1f21

Please sign in to comment.