From 053788de1099a10c89b018da03bf9f7666e3ae19 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Mon, 18 Nov 2013 08:49:05 +0200 Subject: [PATCH 1/3] Fix #1529 --- ext/cli/console.c | 7 +-- ext/cli/router.c | 3 +- ext/db/adapter.c | 3 +- ext/di/injectable.c | 13 ++--- ext/dispatcher.c | 3 +- ext/flash/session.c | 3 +- ext/http/cookie.c | 3 +- ext/http/request.c | 3 +- ext/http/response.c | 3 +- ext/http/response/cookies.c | 3 +- ext/mvc/collection.c | 3 +- ext/mvc/collection/manager.c | 7 +-- ext/mvc/micro.c | 6 +-- ext/mvc/model.c | 3 +- ext/mvc/model/criteria.c | 7 +-- ext/mvc/model/manager.c | 7 +-- ext/mvc/model/metadata.c | 7 +-- ext/mvc/model/query.c | 74 +++++++++++++++++++---------- ext/mvc/model/query/builder.c | 7 +-- ext/mvc/model/transaction/manager.c | 3 +- ext/mvc/router.c | 3 +- ext/mvc/url.c | 7 +-- ext/mvc/view/engine/volt/compiler.c | 7 +-- ext/security.c | 3 +- ext/session/bag.c | 7 +-- ext/tag.c | 7 +-- 26 files changed, 78 insertions(+), 124 deletions(-) diff --git a/ext/cli/console.c b/ext/cli/console.c index faa1f902ad1..7310cbf37bd 100644 --- a/ext/cli/console.c +++ b/ext/cli/console.c @@ -89,13 +89,8 @@ PHP_METHOD(Phalcon_CLI_Console, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Dependency Injector is invalid"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_cli_console_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/cli/router.c b/ext/cli/router.c index d240d06915c..26198dd76b4 100644 --- a/ext/cli/router.c +++ b/ext/cli/router.c @@ -103,9 +103,8 @@ PHP_METHOD(Phalcon_CLI_Router, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_cli_router_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/db/adapter.c b/ext/db/adapter.c index 39a10e43cfc..db0d4256961 100644 --- a/ext/db/adapter.c +++ b/ext/db/adapter.c @@ -164,9 +164,8 @@ PHP_METHOD(Phalcon_Db_Adapter, setDialect){ zval *dialect; phalcon_fetch_params(0, 1, 0, &dialect); - + PHALCON_VERIFY_INTERFACE_EX(dialect, phalcon_db_dialectinterface_ce, phalcon_db_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dialect"), dialect TSRMLS_CC); - } /** diff --git a/ext/di/injectable.c b/ext/di/injectable.c index 19f7b62fb1f..1197fe97f46 100644 --- a/ext/di/injectable.c +++ b/ext/di/injectable.c @@ -66,19 +66,16 @@ PHALCON_INIT_CLASS(Phalcon_DI_Injectable){ * Sets the dependency injector * * @param Phalcon\DiInterface $dependencyInjector + * @throw Phalcon\Di\Exception if !($dependencyInjector instanceof Phalcon\DiInterface) */ PHP_METHOD(Phalcon_DI_Injectable, setDI){ - zval *dependency_injector; + zval **dependency_injector; - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "Dependency Injector is invalid"); - return; - } - phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); + phalcon_fetch_params_ex(1, 0, &dependency_injector); + PHALCON_VERIFY_INTERFACE_EX(*dependency_injector, phalcon_diinterface_ce, phalcon_di_exception_ce, 0); + phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), *dependency_injector TSRMLS_CC); } /** diff --git a/ext/dispatcher.c b/ext/dispatcher.c index 070563c8951..401df20ec88 100644 --- a/ext/dispatcher.c +++ b/ext/dispatcher.c @@ -108,9 +108,8 @@ PHP_METHOD(Phalcon_Dispatcher, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/flash/session.c b/ext/flash/session.c index a1a980e0d69..183d9b9e8f1 100644 --- a/ext/flash/session.c +++ b/ext/flash/session.c @@ -70,9 +70,8 @@ PHP_METHOD(Phalcon_Flash_Session, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_session_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/http/cookie.c b/ext/http/cookie.c index 6ce29a4b3ae..eb8349842d4 100644 --- a/ext/http/cookie.c +++ b/ext/http/cookie.c @@ -146,9 +146,8 @@ PHP_METHOD(Phalcon_Http_Cookie, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_http_cookie_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/http/request.c b/ext/http/request.c index 2a9a14cf4d3..5fa2f65d12b 100644 --- a/ext/http/request.c +++ b/ext/http/request.c @@ -96,9 +96,8 @@ PHP_METHOD(Phalcon_Http_Request, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_http_request_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/http/response.c b/ext/http/response.c index 98817dbc902..db3557eebdc 100644 --- a/ext/http/response.c +++ b/ext/http/response.c @@ -116,9 +116,8 @@ PHP_METHOD(Phalcon_Http_Response, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_http_response_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/http/response/cookies.c b/ext/http/response/cookies.c index b2b8f91d9ad..b1e062b7e5f 100644 --- a/ext/http/response/cookies.c +++ b/ext/http/response/cookies.c @@ -75,9 +75,8 @@ PHP_METHOD(Phalcon_Http_Response_Cookies, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_http_response_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/collection.c b/ext/mvc/collection.c index 053ca1dd3fe..ad5716fe41f 100644 --- a/ext/mvc/collection.c +++ b/ext/mvc/collection.c @@ -213,9 +213,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_collection_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/collection/manager.c b/ext/mvc/collection/manager.c index 09fb4ca0cb1..6d340312604 100644 --- a/ext/mvc/collection/manager.c +++ b/ext/mvc/collection/manager.c @@ -91,13 +91,8 @@ PHP_METHOD(Phalcon_Mvc_Collection_Manager, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/micro.c b/ext/mvc/micro.c index 68bb63659f5..41637928c89 100644 --- a/ext/mvc/micro.c +++ b/ext/mvc/micro.c @@ -118,11 +118,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, setDI){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "The dependency injector must be an object"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_micro_exception_ce, 1); /** * We automatically set ourselves as application service diff --git a/ext/mvc/model.c b/ext/mvc/model.c index f620ca0d0c1..12dbe407b8f 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -245,9 +245,8 @@ PHP_METHOD(Phalcon_Mvc_Model, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/model/criteria.c b/ext/mvc/model/criteria.c index 8be689015e1..83a5b53f284 100644 --- a/ext/mvc/model/criteria.c +++ b/ext/mvc/model/criteria.c @@ -87,13 +87,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Dependency Injector is invalid"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_exception_ce, 0); phalcon_update_property_array_string(this_ptr, SL("_params"), SS("di"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/model/manager.c b/ext/mvc/model/manager.c index 4b3a1c7a67c..6d531269a03 100644 --- a/ext/mvc/model/manager.c +++ b/ext/mvc/model/manager.c @@ -110,13 +110,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Manager, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/model/metadata.c b/ext/mvc/model/metadata.c index 513cb15367a..352f6b53cfa 100644 --- a/ext/mvc/model/metadata.c +++ b/ext/mvc/model/metadata.c @@ -255,13 +255,8 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/model/query.c b/ext/mvc/model/query.c index 1b0d5dc44bd..a9fb9cbaf61 100644 --- a/ext/mvc/model/query.c +++ b/ext/mvc/model/query.c @@ -122,17 +122,17 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, __construct){ PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &phql, &dependency_injector); + phalcon_fetch_params(0, 0, 2, &phql, &dependency_injector); if (phql && Z_TYPE_P(phql) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_phql"), phql TSRMLS_CC); } if (dependency_injector && Z_TYPE_P(dependency_injector) == IS_OBJECT) { + PHALCON_MM_GROW(); phalcon_call_method_p1_noret(this_ptr, "setdi", dependency_injector); + PHALCON_MM_RESTORE(); } - - PHALCON_MM_RESTORE(); } /** @@ -148,8 +148,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, setDI){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &dependency_injector); - - PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce); + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_exception_ce, 1); PHALCON_INIT_VAR(service); PHALCON_ZVAL_MAYBE_INTERNED_STRING(service, phalcon_interned_modelsManager); @@ -1567,6 +1566,9 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _getMultiJoin){ phalcon_call_method_p0_ex(intermediate_model_name, &intermediate_model_name, relation, "getintermediatemodel"); manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } /** * Get the intermediate model instance @@ -1843,7 +1845,10 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoins){ array_init(join_prepared); manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); - + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + PHALCON_OBS_VAR(joins); phalcon_array_fetch_string(&joins, select, SL("joins"), PH_NOISY); if (!phalcon_array_isset_long(joins, 0)) { @@ -2445,13 +2450,16 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareSelect){ if (!phalcon_array_isset_long(tables, 0)) { PHALCON_INIT_VAR(selected_models); array_init_size(selected_models, 1); - phalcon_array_append(&selected_models, tables, PH_SEPARATE); + phalcon_array_append(&selected_models, tables, 0); } else { PHALCON_CPY_WRT(selected_models, tables); } manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); - + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + /** * Processing selected columns */ @@ -2781,9 +2789,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareInsert){ return; } - PHALCON_OBS_VAR(manager); - phalcon_read_property_this(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); - + manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + PHALCON_OBS_VAR(model_name); phalcon_array_fetch_string(&model_name, qualified_name, ISL(name), PH_NOISY); @@ -2799,7 +2809,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareInsert){ PHALCON_INIT_NVAR(source); array_init_size(source, 2); phalcon_array_append(&source, schema, PH_SEPARATE); - phalcon_array_append(&source, source, PH_SEPARATE); + phalcon_array_append(&source, source, 0); } PHALCON_INIT_VAR(sql_aliases); @@ -2967,6 +2977,9 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareUpdate){ } manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } phalcon_is_iterable(update_tables, &ah0, &hp0, 0, 0); @@ -3202,7 +3215,10 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareDelete){ } manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); - + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + phalcon_is_iterable(delete_tables, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { @@ -3516,9 +3532,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeSelect){ PHALCON_SEPARATE_PARAM(intermediate); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); - + manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + /** * Models instances is an array if the SELECT was prepared with parse */ @@ -4022,9 +4040,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeInsert){ PHALCON_OBS_VAR(model_name); phalcon_array_fetch_string(&model_name, intermediate, SL("model"), PH_NOISY); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); - + manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + PHALCON_OBS_VAR(models_instances); phalcon_read_property_this(&models_instances, this_ptr, SL("_modelsInstances"), PH_NOISY_CC); if (phalcon_array_isset(models_instances, model_name)) { @@ -4382,9 +4402,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeUpdate){ PHALCON_OBS_VAR(model); phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); } else { - PHALCON_OBS_VAR(manager); - phalcon_read_property_this(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); - + manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + PHALCON_INIT_NVAR(model); phalcon_call_method_p1(model, manager, "load", model_name); } @@ -4621,9 +4643,11 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeDelete){ PHALCON_OBS_VAR(model); phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); } else { - PHALCON_OBS_VAR(manager); - phalcon_read_property_this(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); - + manager = phalcon_fetch_nproperty_this(this_ptr, SL("_manager"), PH_NOISY_CC); + if (Z_TYPE_P(manager) != IS_OBJECT) { + zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "dependency Injector is required to get '%s' service", "modelsManager"); + } + PHALCON_INIT_NVAR(model); phalcon_call_method_p1(model, manager, "load", model_name); } diff --git a/ext/mvc/model/query/builder.c b/ext/mvc/model/query/builder.c index bf5bd297030..729f88e0c98 100644 --- a/ext/mvc/model/query/builder.c +++ b/ext/mvc/model/query/builder.c @@ -336,13 +336,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector must be an Object"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - RETURN_THISW(); } diff --git a/ext/mvc/model/transaction/manager.c b/ext/mvc/model/transaction/manager.c index 5d0733a50cc..5249d73af77 100644 --- a/ext/mvc/model/transaction/manager.c +++ b/ext/mvc/model/transaction/manager.c @@ -148,9 +148,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_model_transaction_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/router.c b/ext/mvc/router.c index 7f05e324f97..5b8c1bdf024 100644 --- a/ext/mvc/router.c +++ b/ext/mvc/router.c @@ -179,9 +179,8 @@ PHP_METHOD(Phalcon_Mvc_Router, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_router_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/url.c b/ext/mvc/url.c index 6bb43765cc7..1b060d88f36 100644 --- a/ext/mvc/url.c +++ b/ext/mvc/url.c @@ -86,13 +86,8 @@ PHP_METHOD(Phalcon_Mvc_Url, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_url_exception_ce, "The dependency injector must be an Object"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_url_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/mvc/view/engine/volt/compiler.c b/ext/mvc/view/engine/volt/compiler.c index b862c816159..689c527dc66 100644 --- a/ext/mvc/view/engine/volt/compiler.c +++ b/ext/mvc/view/engine/volt/compiler.c @@ -120,13 +120,8 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Dependency Injector is invalid"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_mvc_view_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/security.c b/ext/security.c index 4979ab68e98..144c924ce60 100644 --- a/ext/security.c +++ b/ext/security.c @@ -90,8 +90,7 @@ PHP_METHOD(Phalcon_Security, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - PHALCON_VERIFY_INTERFACE_OR_NULL_EX(dependency_injector, phalcon_diinterface_ce, phalcon_security_exception_ce, 0); - + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_security_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); } diff --git a/ext/session/bag.c b/ext/session/bag.c index 5f5b71ae4cd..82a9b1eb2d9 100644 --- a/ext/session/bag.c +++ b/ext/session/bag.c @@ -99,13 +99,8 @@ PHP_METHOD(Phalcon_Session_Bag, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_session_exception_ce, "The dependency injector must be an Object"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_session_exception_ce, 0); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** diff --git a/ext/tag.c b/ext/tag.c index 3ca4ade73d5..f132afd250d 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -200,13 +200,8 @@ PHP_METHOD(Phalcon_Tag, setDI){ zval *dependency_injector; phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "Parameter dependencyInjector must be an Object"); - return; - } + PHALCON_VERIFY_INTERFACE_EX(dependency_injector, phalcon_diinterface_ce, phalcon_tag_exception_ce, 0); phalcon_update_static_property_ce(phalcon_tag_ce, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - } /** From b466d75fa8a1e30757977c72d71646aec061dbd7 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Mon, 18 Nov 2013 08:54:31 +0200 Subject: [PATCH 2/3] Bug fix --- ext/mvc/model/query.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/mvc/model/query.c b/ext/mvc/model/query.c index a9fb9cbaf61..cd0806545f3 100644 --- a/ext/mvc/model/query.c +++ b/ext/mvc/model/query.c @@ -120,8 +120,6 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, __construct){ zval *phql = NULL, *dependency_injector = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(0, 0, 2, &phql, &dependency_injector); if (phql && Z_TYPE_P(phql) != IS_NULL) { From 5bc05585da7c146e0f646acfb4e751fa510c4a58 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Mon, 18 Nov 2013 09:05:54 +0200 Subject: [PATCH 3/3] Updated tests --- ext/tests/issue-744.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/tests/issue-744.phpt b/ext/tests/issue-744.phpt index 840785cc2a2..667f68d9854 100644 --- a/ext/tests/issue-744.phpt +++ b/ext/tests/issue-744.phpt @@ -41,7 +41,7 @@ catch (Exception $e) { } ?> --EXPECT-- -Parameter dependencyInjector must be an Object +Unexpected value type: expected object implementing Phalcon\DiInterface, integer given OK OK An array is required as default values