/** * Checks whether a model has a hasOne relation with another model * * @param string $modelName * @param string $modelRelation * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasOne){ zval *model_name = NULL, *model_relation = NULL, *initialized = NULL; zval *model = NULL, *has_one = NULL; zval *r0 = NULL; int eval_int; zend_class_entry *ce0, *ce1; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &model_name, &model_relation) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(initialized); phalcon_read_property(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); eval_int = phalcon_array_isset(initialized, model_name); if (!eval_int) { ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); } eval_int = phalcon_array_isset(initialized, model_relation); if (!eval_int) { ce1 = phalcon_fetch_class(model_relation TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce1); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); } PHALCON_INIT_VAR(has_one); phalcon_read_property(&has_one, this_ptr, SL("_hasOne"), PH_NOISY_CC); eval_int = phalcon_array_isset(has_one, model_name); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch(&r0, has_one, model_name, PH_NOISY_CC); eval_int = phalcon_array_isset(r0, model_relation); if (eval_int) { PHALCON_MM_RESTORE(); RETURN_TRUE; } } PHALCON_MM_RESTORE(); RETURN_FALSE; }
/** * Executes a find using the parameters built with the criteria * * @return Phalcon\Mvc\Model\ResultsetInterface */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, execute){ zval *model, *params = NULL; zend_class_entry *ce; PHALCON_MM_GROW(); model = phalcon_fetch_nproperty_this(this_ptr, SL("_model"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(model) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model name must be string"); return; } PHALCON_CALL_METHOD(¶ms, this_ptr, "getparams"); ce = phalcon_fetch_class(model TSRMLS_CC); if (!ce) { zend_throw_exception_ex(phalcon_mvc_model_exception_ce, 0 TSRMLS_CC, "Class '%s' does not exist", Z_STRVAL_P(model)); RETURN_MM(); } PHALCON_RETURN_CALL_CE_STATIC(ce, "find", params); PHALCON_MM_RESTORE(); }
/** * Load a configuration * * @param string $filePath * @param string $absolutePath */ PHP_METHOD(Phalcon_Config_Adapter, load){ zval *file_path = NULL, *absolute_path = NULL, *class_name; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &file_path, &absolute_path); PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name ); ce0 = phalcon_fetch_class(class_name); object_init_ex(return_value, ce0); if (file_path) { if (absolute_path == NULL) { absolute_path = &PHALCON_GLOBAL(z_false); } PHALCON_RETURN_CALL_STATICW("factory", file_path, absolute_path); } else { PHALCON_RETURN_CALL_STATICW("factory"); } PHALCON_MM_RESTORE(); }
/** * Initializes the internal handler, calling functions on it * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){ zval *method, *arguments, handler = {}, definition = {}, call_handler = {}; zend_class_entry *ce0; phalcon_fetch_params(0, 2, 0, &method, &arguments); phalcon_return_property(&handler, getThis(), SL("_handler")); if (Z_TYPE(handler) != IS_OBJECT) { phalcon_read_property(&definition, getThis(), SL("_definition"), PH_NOISY); ce0 = phalcon_fetch_class(&definition, ZEND_FETCH_CLASS_DEFAULT); PHALCON_OBJECT_INIT(&handler, ce0); if (phalcon_has_constructor(&handler)) { PHALCON_CALL_METHODW(NULL, &handler, "__construct"); } phalcon_update_property_zval(getThis(), SL("_handler"), &handler); } array_init_size(&call_handler, 2); phalcon_array_append(&call_handler, &handler, PH_COPY); phalcon_array_append(&call_handler, method, PH_COPY); /** * Call the handler */ PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &call_handler, arguments); }
/** * Initializes the internal handler, calling functions on it * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){ zval *method, *arguments, *handler = NULL, *definition; zval *call_handler; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &method, &arguments); handler = phalcon_read_property(getThis(), SL("_handler"), PH_NOISY); if (Z_TYPE_P(handler) != IS_OBJECT) { definition = phalcon_read_property(getThis(), SL("_definition"), PH_NOISY); ce0 = phalcon_fetch_class(definition); PHALCON_INIT_NVAR(handler); object_init_ex(handler, ce0); if (phalcon_has_constructor(handler)) { PHALCON_CALL_METHOD(NULL, handler, "__construct"); } phalcon_update_property_this(getThis(), SL("_handler"), handler); } PHALCON_INIT_VAR(call_handler); array_init_size(call_handler, 2); phalcon_array_append(call_handler, handler, PH_COPY); phalcon_array_append(call_handler, method, PH_COPY); /** * Call the handler */ PHALCON_CALL_USER_FUNC_ARRAY(&return_value, call_handler, arguments); RETURN_MM(); }
/** * Phalcon\Config\Adapter factory * * @param string $filePath * @param string $absolutePath */ PHP_METHOD(Phalcon_Config_Adapter, factory){ zval *file_path = NULL, *absolute_path = NULL, *instances, *instance = NULL, *class_name; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &file_path, &absolute_path); instances = phalcon_read_static_property_ce(phalcon_config_adapter_ce, SL("_instances")); if (!phalcon_array_isset_fetch(&instance, instances, file_path)) { PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name ); ce0 = phalcon_fetch_class(class_name); object_init_ex(return_value, ce0); if (file_path) { if (absolute_path == NULL) { absolute_path = &PHALCON_GLOBAL(z_false); } PHALCON_CALL_METHOD(NULL, return_value, "__construct", file_path, absolute_path); } else { PHALCON_CALL_METHOD(NULL, return_value, "__construct"); } phalcon_update_static_property_array_multi_ce(phalcon_config_adapter_ce, SL("_instances"), return_value, SL("z"), 1, file_path); RETURN_MM(); } RETURN_CTOR(instance); }
/** * Loads a model throwing an exception if it doesn't exist * * @return Phalcon\Mvc\Model */ PHP_METHOD(Phalcon_Mvc_Model_Manager, load){ zval *model_name, *model, *exception_message; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &model_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (phalcon_class_exists(model_name TSRMLS_CC)) { ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); RETURN_CTOR(model); } PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "The model '", model_name, "' could not be loaded"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; }
/** * Loads a model throwing an exception if it doesn't exist * * @return Phalcon\Mvc\Model */ PHP_METHOD(Phalcon_Mvc_Model_Manager, load){ zval *model_name = NULL, *model_exists = NULL, *model = NULL, *exception_message = NULL; zval *exception = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &model_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(model_exists); PHALCON_CALL_FUNC_PARAMS_1(model_exists, "class_exists", model_name); if (zend_is_true(model_exists)) { ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); RETURN_CTOR(model); } PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "The model '", model_name, "' could not be loaded"); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_model_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; }
/** * Phalcon_Logger constructor * * @param string $adapter * @param string $name * @param array $options */ PHP_METHOD(Phalcon_Logger, __construct){ zval *adapter = NULL, *name = NULL, *options = NULL, *class_name = NULL; zval *a0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *i0 = NULL, *i1 = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zzz", &adapter, &name, &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!adapter) { PHALCON_INIT_VAR(adapter); ZVAL_STRING(adapter, "File", 1); } if (!name) { PHALCON_INIT_VAR(name); ZVAL_NULL(name); } if (!options) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(options, a0); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_LEFT(r0, "Phalcon_Logger_Adapter_", adapter); PHALCON_CPY_WRT(class_name, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "class_exists", class_name, 0x012); if (!zend_is_true(r1)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_logger_exception_ce); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_BOTH(r2, "Logger adapter '", class_name, "' cannot be found"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r2, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } ce0 = phalcon_fetch_class(class_name TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, ce0); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i1, "__construct", name, options, PHALCON_CHECK); phalcon_update_property_zval(this_ptr, "_adapter", strlen("_adapter"), i1 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon_Acl Constructor * * @param string $adapterName * @param array $options */ PHP_METHOD(Phalcon_Acl, __construct){ zval *adapter_name = NULL, *options = NULL, *adapter_class = NULL; zval *a0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *i0 = NULL, *i1 = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &adapter_name, &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!adapter_name) { PHALCON_INIT_VAR(adapter_name); ZVAL_STRING(adapter_name, "Memory", 1); } if (!options) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(options, a0); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_SV(r0, "Phalcon_Acl_Adapter_", adapter_name); PHALCON_CPY_WRT(adapter_class, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "class_exists", adapter_class); if (!zend_is_true(r1)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_acl_exception_ce); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVS(r2, "Adapter '", adapter_name, "' does not exist"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r2, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } ce0 = phalcon_fetch_class(adapter_class TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, ce0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i1, "__construct", options, PHALCON_CHECK); phalcon_update_property_zval(this_ptr, SL("_adapter"), i1 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon_Model_MetaData constructor * * @param string $adapter * @param array $options */ PHP_METHOD(Phalcon_Model_MetaData, __construct){ zval *adapter = NULL, *options = NULL, *adapter_class = NULL, *adapter_object = NULL; zval *a0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL; zval *i0 = NULL, *i1 = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &adapter, &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!options) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(options, a0); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_SV(r0, "Phalcon_Model_MetaData_", adapter); PHALCON_CPY_WRT(adapter_class, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "class_exists", adapter_class); if (zend_is_true(r1)) { ce0 = phalcon_fetch_class(adapter_class TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, ce0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", options, PHALCON_CHECK); PHALCON_CPY_WRT(adapter_object, i0); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD(r2, adapter_object, "read", PHALCON_NO_CHECK); phalcon_update_property_zval(this_ptr, SL("_metaData"), r2 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_adapter"), adapter_object TSRMLS_CC); } else { PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_model_exception_ce); PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_SVS(r3, "Meta-data adapter '", adapter, "' could not found"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i1, "__construct", r3, PHALCON_CHECK); phalcon_throw_exception(i1 TSRMLS_CC); return; } PHALCON_MM_RESTORE(); }
/** * Phalcon\Db constructor * * @param stdClass $descriptor */ PHP_METHOD(Phalcon_Db, __construct){ zval *descriptor = NULL, *connection_consecutive = NULL; zval *next_consecutive = NULL, *dialect_type = NULL, *dialect_class = NULL; zval *dialect_object = NULL; zval *t0 = NULL; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_OBSERVE_VAR(connection_consecutive); phalcon_read_static_property(&connection_consecutive, SL("phalcon\\db"), SL("_connectionConsecutive") TSRMLS_CC); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_INIT_VAR(next_consecutive); phalcon_add_function(next_consecutive, connection_consecutive, t0 TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\db"), SL("_connectionConsecutive"), next_consecutive TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_connectionId"), connection_consecutive TSRMLS_CC); eval_int = phalcon_array_isset_string(descriptor, SL("dialectClass")+1); if (!eval_int) { PHALCON_INIT_VAR(dialect_type); phalcon_read_property(&dialect_type, this_ptr, SL("_dialectType"), PH_NOISY_CC); PHALCON_INIT_VAR(dialect_class); PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); } else { PHALCON_INIT_VAR(dialect_class); phalcon_array_fetch_string(&dialect_class, descriptor, SL("dialectClass"), PH_NOISY_CC); } ce0 = phalcon_fetch_class(dialect_class TSRMLS_CC); PHALCON_INIT_VAR(dialect_object); object_init_ex(dialect_object, ce0); PHALCON_CALL_METHOD_NORETURN(dialect_object, "__construct", PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_dialect"), dialect_object TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_descriptor"), descriptor TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Constructor for Phalcon\Db\Adapter\Pdo * * @param array $descriptor */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, __construct){ zval *descriptor = NULL, *dialect_type = NULL, *dialect_class = NULL; zval *dialect_object = NULL; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(descriptor) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "$descriptor must be an array"); return; } eval_int = phalcon_array_isset_string(descriptor, SL("dialectClass")+1); if (!eval_int) { PHALCON_INIT_VAR(dialect_type); phalcon_read_property(&dialect_type, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(dialect_class); PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); } else { PHALCON_INIT_VAR(dialect_class); phalcon_array_fetch_string(&dialect_class, descriptor, SL("dialectClass"), PH_NOISY_CC); } ce0 = phalcon_fetch_class(dialect_class TSRMLS_CC); PHALCON_INIT_VAR(dialect_object); object_init_ex(dialect_object, ce0); PHALCON_CALL_METHOD_NORETURN(dialect_object, "__construct", PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_dialect"), dialect_object TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "connect", descriptor, PH_NO_CHECK); PHALCON_MM_RESTORE(); }
/** * Phalcon_Translate constructor * * @param string $adapter * @param array $options */ PHP_METHOD(Phalcon_Translate, __construct){ zval *adapter = NULL, *options = NULL, *adapter_class = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *i0 = NULL, *i1 = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &adapter, &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_SV(r0, "Phalcon_Translate_Adapter_", adapter); PHALCON_CPY_WRT(adapter_class, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "class_exists", adapter_class); if (!zend_is_true(r1)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_translate_exception_ce); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVS(r2, "No existe el adaptador \"", adapter, "\""); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r2, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } ce0 = phalcon_fetch_class(adapter_class TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, ce0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i1, "__construct", options, PHALCON_CHECK); phalcon_update_property_zval(this_ptr, SL("_adapter"), i1 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Initializes the internal handler, calling functions on it * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call) { zval *method, *arguments, *handler = NULL, *definition; zval *call_handler, *result; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &method, &arguments); PHALCON_OBS_VAR(handler); phalcon_read_property_this(&handler, this_ptr, SL("_handler"), PH_NOISY_CC); if (Z_TYPE_P(handler) != IS_OBJECT) { PHALCON_OBS_VAR(definition); phalcon_read_property_this(&definition, this_ptr, SL("_definition"), PH_NOISY_CC); ce0 = phalcon_fetch_class(definition TSRMLS_CC); PHALCON_INIT_NVAR(handler); object_init_ex(handler, ce0); if (phalcon_has_constructor(handler TSRMLS_CC)) { phalcon_call_method_noret(handler, "__construct"); } phalcon_update_property_this(this_ptr, SL("_handler"), handler TSRMLS_CC); } PHALCON_INIT_VAR(call_handler); array_init_size(call_handler, 2); phalcon_array_append(&call_handler, handler, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&call_handler, method, PH_SEPARATE TSRMLS_CC); /** * Call the handler */ PHALCON_INIT_VAR(result); PHALCON_CALL_USER_FUNC_ARRAY(result, call_handler, arguments); RETURN_CCTOR(result); }
/** * Factories different caches backends from its adapters * * @param string $frontendAdapter * @param string $backendAdapter * @param array $frontendOptions * @param array $backendOptions * @return Phalcon_Cache_Backend_File * @static */ PHP_METHOD(Phalcon_Cache, factory){ zval *frontend_adapter = NULL, *backend_adapter = NULL; zval *frontend_options = NULL, *backend_options = NULL; zval *frontend_class = NULL, *backend_class = NULL, *front_object = NULL; zval *a0 = NULL, *a1 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL; zval *i0 = NULL, *i1 = NULL, *i2 = NULL, *i3 = NULL; zend_class_entry *ce0, *ce1; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|zz", &frontend_adapter, &backend_adapter, &frontend_options, &backend_options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!frontend_options) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(frontend_options, a0); } if (!backend_options) { PHALCON_INIT_VAR(a1); array_init(a1); PHALCON_CPY_WRT(backend_options, a1); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_SV(r0, "Phalcon_Cache_Frontend_", frontend_adapter); PHALCON_CPY_WRT(frontend_class, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "class_exists", frontend_class, 0x012); if (!zend_is_true(r1)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_cache_exception_ce); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVS(r2, "Frontend adapter \"", backend_adapter, "' doesn't exist"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r2, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_SV(r3, "Phalcon_Cache_Backend_", backend_adapter); PHALCON_CPY_WRT(backend_class, r3); PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_FUNC_PARAMS_1(r4, "class_exists", backend_class, 0x012); if (!zend_is_true(r4)) { PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_cache_exception_ce); PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CONCAT_SVS(r5, "Backend adapter \"", backend_adapter, "' doesn't exist"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i1, "__construct", r5, PHALCON_CHECK); phalcon_throw_exception(i1 TSRMLS_CC); return; } ce0 = phalcon_fetch_class(frontend_class TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i2); object_init_ex(i2, ce0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i2, "__construct", frontend_options, PHALCON_CHECK); PHALCON_CPY_WRT(front_object, i2); ce1 = phalcon_fetch_class(backend_class TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i3); object_init_ex(i3, ce1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i3, "__construct", front_object, backend_options, PHALCON_CHECK); PHALCON_RETURN_CTOR(i3); }
/** * Builds a Phalcon\Mvc\Model\Criteria based on an input array like $_POST * * @param Phalcon\DI $dependencyInjector * @param string $modelName * @param array $data */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ zval *dependency_injector = NULL, *model_name = NULL, *data = NULL; zval *conditions = NULL, *number_data = NULL, *service = NULL, *meta_data = NULL; zval *model = NULL, *data_types = NULL, *bind = NULL, *value = NULL, *field = NULL, *type = NULL; zval *condition = NULL, *value_pattern = NULL, *criteria = NULL, *number_conditions = NULL; zval *join_conditions = NULL; zval *c0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &dependency_injector, &model_name, &data) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array"); return; } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); return; } PHALCON_INIT_VAR(conditions); array_init(conditions); PHALCON_INIT_VAR(number_data); phalcon_fast_count(number_data, data TSRMLS_CC); if (!phalcon_compare_strict_long(number_data, 0 TSRMLS_CC)) { PHALCON_INIT_VAR(service); ZVAL_STRING(service, "modelsMetadata", 1); PHALCON_INIT_VAR(meta_data); PHALCON_CALL_METHOD_PARAMS_1(meta_data, dependency_injector, "getshared", service, PH_NO_CHECK); ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); PHALCON_CALL_METHOD_NORETURN(model, "__construct", PH_CHECK); PHALCON_INIT_VAR(data_types); PHALCON_CALL_METHOD_PARAMS_1(data_types, meta_data, "getdatatypes", model, PH_NO_CHECK); PHALCON_INIT_VAR(bind); array_init(bind); if (!phalcon_valid_foreach(data TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(data); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_1d26_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_1d26_0; } PHALCON_INIT_VAR(field); PHALCON_GET_FOREACH_KEY(field, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); eval_int = phalcon_array_isset(data_types, field); if (eval_int) { if (Z_TYPE_P(value) != IS_NULL) { if (!PHALCON_COMPARE_STRING(value, "")) { PHALCON_INIT_VAR(type); phalcon_array_fetch(&type, data_types, field, PH_NOISY_CC); if (phalcon_compare_strict_long(type, 2 TSRMLS_CC)) { PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":"); PHALCON_INIT_VAR(value_pattern); PHALCON_CONCAT_SVS(value_pattern, "%", value, "%"); phalcon_array_update_zval(&bind, field, &value_pattern, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VSVS(condition, field, "=:", field, ":"); phalcon_array_update_zval(&bind, field, &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); } } } zend_hash_move_forward_ex(ah0, &hp0); goto fes_1d26_0; fee_1d26_0: if(0){} } PHALCON_INIT_VAR(criteria); object_init_ex(criteria, phalcon_mvc_model_criteria_ce); PHALCON_CALL_METHOD_NORETURN(criteria, "__construct", PH_CHECK); PHALCON_INIT_VAR(number_conditions); phalcon_fast_count(number_conditions, conditions TSRMLS_CC); if (!phalcon_compare_strict_long(number_conditions, 0 TSRMLS_CC)) { PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, " AND ", 1); PHALCON_INIT_VAR(join_conditions); phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(criteria, "where", join_conditions, PH_NO_CHECK); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(criteria, "bind", bind, PH_NO_CHECK); } RETURN_CTOR(criteria); }
/** * Helper method to query records based on a relation definition * * @param array $relation * @param string $method * @param Phalcon\Mvc\Model $record */ PHP_METHOD(Phalcon_Mvc_Model_Manager, _getRelationRecords){ zval *relation = NULL, *method = NULL, *record = NULL, *conditions = NULL, *placeholders = NULL; zval *field = NULL, *value = NULL, *referenced_field = NULL, *condition = NULL; zval *i = NULL, *fields = NULL, *number_args = NULL, *function_arguments = NULL; zval *key = NULL, *join_conditions = NULL, *find_params = NULL, *arguments = NULL; zval *reference_table = NULL, *referenced_entity = NULL; zval *call_object = NULL, *records = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *c0 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &relation, &method, &record) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(conditions); array_init(conditions); PHALCON_INIT_VAR(placeholders); array_init(placeholders); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, relation, SL("fi"), PH_NOISY_CC); if (Z_TYPE_P(r0) != IS_ARRAY) { PHALCON_INIT_VAR(field); phalcon_array_fetch_string(&field, relation, SL("fi"), PH_NOISY_CC); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch_string(&referenced_field, relation, SL("rf"), PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VS(condition, referenced_field, " = ?0"); phalcon_array_update_long(&conditions, 0, &condition, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(i); ZVAL_LONG(i, 0); PHALCON_INIT_VAR(fields); phalcon_array_fetch_string(&fields, relation, SL("fi"), PH_NOISY_CC); if (!phalcon_valid_foreach(fields TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(fields); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_74b5_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_74b5_0; } PHALCON_INIT_VAR(field); ZVAL_ZVAL(field, *hd, 1, 0); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(r1); phalcon_array_fetch_string(&r1, relation, SL("rf"), PH_NOISY_CC); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch(&referenced_field, r1, i, PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VSV(condition, referenced_field, " = ?", i); phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); PHALCON_SEPARATE(i); increment_function(i); zend_hash_move_forward_ex(ah0, &hp0); goto fes_74b5_0; fee_74b5_0: if(0){} } PHALCON_INIT_VAR(number_args); PHALCON_CALL_FUNC(number_args, "func_num_args"); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 4); PHALCON_ALLOC_ZVAL_MM(r2); is_smaller_function(r2, t0, number_args TSRMLS_CC); if (zend_is_true(r2)) { PHALCON_INIT_VAR(function_arguments); PHALCON_CALL_FUNC(function_arguments, "func_get_args"); if (!phalcon_valid_foreach(function_arguments TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(function_arguments); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_74b5_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_74b5_1; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah1, hp1); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 0); PHALCON_INIT_VAR(r3); is_equal_function(r3, key, t1 TSRMLS_CC); PHALCON_INIT_VAR(t2); ZVAL_STRING(t2, "conditions", 1); PHALCON_INIT_VAR(r4); is_equal_function(r4, key, t2 TSRMLS_CC); PHALCON_INIT_VAR(r5); ZVAL_BOOL(r5, zend_is_true(r3) || zend_is_true(r4)); if (zend_is_true(r5)) { phalcon_array_append(&conditions, value, PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); goto fes_74b5_1; fee_74b5_1: if(0){} } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, " AND ", 1); PHALCON_INIT_VAR(join_conditions); phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC); PHALCON_INIT_VAR(find_params); array_init(find_params); phalcon_array_append(&find_params, join_conditions, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&find_params, SL("bind"), &placeholders, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, find_params, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(reference_table); phalcon_array_fetch_string(&reference_table, relation, SL("rt"), PH_NOISY_CC); ce0 = phalcon_fetch_class(reference_table TSRMLS_CC); PHALCON_INIT_VAR(referenced_entity); object_init_ex(referenced_entity, ce0); PHALCON_CALL_METHOD_NORETURN(referenced_entity, "__construct", PH_CHECK); PHALCON_ALLOC_ZVAL_MM(r6); PHALCON_CALL_METHOD(r6, record, "getconnectionservice", PH_NO_CHECK); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(referenced_entity, "setconnectionservice", r6, PH_NO_CHECK); PHALCON_INIT_VAR(call_object); array_init(call_object); phalcon_array_append(&call_object, referenced_entity, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&call_object, method, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(records); PHALCON_CALL_FUNC_PARAMS_2(records, "call_user_func_array", call_object, arguments); RETURN_CCTOR(records); }
/** * Helper method to query records based on a relation definition * * @param array $relation * @param string $method * @param Phalcon\Mvc\Model $record * @param array $parameters * @return Phalcon\Mvc\Model\Resultset\Simple */ PHP_METHOD(Phalcon_Mvc_Model_Manager, _getRelationRecords){ zval *relation = NULL, *method = NULL, *record = NULL, *parameters = NULL, *placeholders = NULL; zval *pre_conditions = NULL, *conditions = NULL, *fields = NULL, *field = NULL; zval *value = NULL, *referenced_field = NULL, *condition = NULL, *i = NULL; zval *referenced_fields = NULL, *join_conditions = NULL; zval *find_params = NULL, *find_arguments = NULL, *arguments = NULL; zval *reference_table = NULL, *referenced_entity = NULL; zval *connection_service = NULL, *call_object = NULL, *records = NULL; zval *c0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|z", &relation, &method, &record, ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_ALLOC_ZVAL_MM(parameters); ZVAL_NULL(parameters); } else { PHALCON_SEPARATE_PARAM(parameters); } if (Z_TYPE_P(parameters) == IS_ARRAY) { eval_int = phalcon_array_isset_string(parameters, SL("bind")+1); if (eval_int) { PHALCON_INIT_VAR(placeholders); phalcon_array_fetch_string(&placeholders, parameters, SL("bind"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(parameters); phalcon_array_unset_string(parameters, SL("bind")+1); } else { PHALCON_INIT_VAR(placeholders); array_init(placeholders); } } else { PHALCON_INIT_VAR(placeholders); array_init(placeholders); } PHALCON_INIT_VAR(pre_conditions); ZVAL_NULL(pre_conditions); if (Z_TYPE_P(parameters) == IS_ARRAY) { eval_int = phalcon_array_isset_long(parameters, 0); if (eval_int) { PHALCON_INIT_VAR(pre_conditions); phalcon_array_fetch_long(&pre_conditions, parameters, 0, PH_NOISY_CC); PHALCON_SEPARATE_PARAM(parameters); phalcon_array_unset_long(parameters, 0); } else { eval_int = phalcon_array_isset_string(parameters, SL("conditions")+1); if (eval_int) { PHALCON_INIT_VAR(pre_conditions); phalcon_array_fetch_string(&pre_conditions, parameters, SL("conditions"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(parameters); phalcon_array_unset_string(parameters, SL("conditions")+1); } } } else { if (Z_TYPE_P(parameters) == IS_STRING) { PHALCON_CPY_WRT(pre_conditions, parameters); } } if (Z_TYPE_P(pre_conditions) != IS_NULL) { PHALCON_INIT_VAR(conditions); array_init(conditions); phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(conditions); array_init(conditions); } PHALCON_INIT_VAR(fields); phalcon_array_fetch_string(&fields, relation, SL("fi"), PH_NOISY_CC); if (Z_TYPE_P(fields) != IS_ARRAY) { PHALCON_CPY_WRT(field, fields); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch_string(&referenced_field, relation, SL("rf"), PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VS(condition, referenced_field, " = ?0"); phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(i); ZVAL_LONG(i, 0); PHALCON_INIT_VAR(referenced_fields); phalcon_array_fetch_string(&referenced_fields, relation, SL("rf"), PH_NOISY_CC); if (!phalcon_valid_foreach(fields TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(fields); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_74b5_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_74b5_0; } PHALCON_INIT_VAR(field); ZVAL_ZVAL(field, *hd, 1, 0); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch(&referenced_field, referenced_fields, i, PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VSV(condition, referenced_field, " = ?", i); phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); PHALCON_SEPARATE(i); increment_function(i); zend_hash_move_forward_ex(ah0, &hp0); goto fes_74b5_0; fee_74b5_0: if(0){} } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, " AND ", 1); PHALCON_INIT_VAR(join_conditions); phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC); PHALCON_INIT_VAR(find_params); array_init(find_params); phalcon_array_append(&find_params, join_conditions, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&find_params, SL("bind"), &placeholders, PH_COPY | PH_SEPARATE TSRMLS_CC); if (Z_TYPE_P(parameters) == IS_ARRAY) { PHALCON_INIT_VAR(find_arguments); PHALCON_CALL_FUNC_PARAMS_2(find_arguments, "array_merge", find_params, parameters); } else { PHALCON_CPY_WRT(find_arguments, find_params); } PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, find_arguments, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(reference_table); phalcon_array_fetch_string(&reference_table, relation, SL("rt"), PH_NOISY_CC); ce0 = phalcon_fetch_class(reference_table TSRMLS_CC); PHALCON_INIT_VAR(referenced_entity); object_init_ex(referenced_entity, ce0); PHALCON_CALL_METHOD_NORETURN(referenced_entity, "__construct", PH_CHECK); PHALCON_INIT_VAR(connection_service); PHALCON_CALL_METHOD(connection_service, record, "getconnectionservice", PH_NO_CHECK); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(referenced_entity, "setconnectionservice", connection_service, PH_NO_CHECK); PHALCON_INIT_VAR(call_object); array_init(call_object); phalcon_array_append(&call_object, referenced_entity, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&call_object, method, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(records); PHALCON_CALL_FUNC_PARAMS_2(records, "call_user_func_array", call_object, arguments); RETURN_CCTOR(records); }
/** * Loads registered template engines, if none is registered use Phalcon_View_Engine_Php * * @return array */ PHP_METHOD(Phalcon_View, _loadTemplateEngines){ zval *engines = NULL, *registered_engines = NULL, *engine = NULL; zval *extension = NULL, *options = NULL, *name = NULL, *class_name = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *a0 = NULL, *a1 = NULL, *a2 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL; zval *i0 = NULL, *i1 = NULL, *i2 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_engines", sizeof("_engines")-1, PHALCON_NOISY TSRMLS_CC); if (!zend_is_true(t0)) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(engines, a0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_registeredEngines", sizeof("_registeredEngines")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(registered_engines, t1); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_count(r0, registered_engines TSRMLS_CC); if (!zend_is_true(r0)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_view_engine_php_ce); PHALCON_INIT_VAR(a1); array_init(a1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i0, "__construct", this_ptr, a1, PHALCON_CHECK); phalcon_array_update_string(&engines, ".phtml", strlen(".phtml"), &i0, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { if (phalcon_valid_foreach(registered_engines TSRMLS_CC)) { ah0 = Z_ARRVAL_P(registered_engines); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_b0d8_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_b0d8_0; } else { PHALCON_INIT_VAR(extension); PHALCON_GET_FOREACH_KEY(extension, ah0, hp0); } PHALCON_INIT_VAR(engine); ZVAL_ZVAL(engine, *hd, 1, 0); PHALCON_INIT_VAR(a2); array_init(a2); PHALCON_CPY_WRT(options, a2); if (Z_TYPE_P(engine) == IS_ARRAY) { eval_int = phalcon_array_isset_long(engine, 0); if (eval_int) { PHALCON_INIT_VAR(r1); phalcon_array_fetch_long(&r1, engine, 0, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(name, r1); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_view_exception_ce, "The template engine name is required"); return; } eval_int = phalcon_array_isset_long(engine, 1); if (eval_int) { PHALCON_INIT_VAR(r2); phalcon_array_fetch_long(&r2, engine, 1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(options, r2); } } else { if (Z_TYPE_P(engine) == IS_STRING) { PHALCON_CPY_WRT(name, engine); } else { if (Z_TYPE_P(engine) == IS_OBJECT) { PHALCON_CALL_METHOD_PARAMS_2_NORETURN(engine, "initialize", this_ptr, options, PHALCON_NO_CHECK); phalcon_array_update(&engines, extension, &engine, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); goto fes_b0d8_0; } else { PHALCON_THROW_EXCEPTION_STR(phalcon_view_exception_ce, "The template engine is invalid"); return; } } } PHALCON_INIT_VAR(r3); PHALCON_CONCAT_SV(r3, "Phalcon_View_Engine_", name); PHALCON_CPY_WRT(class_name, r3); PHALCON_INIT_VAR(r4); PHALCON_CALL_FUNC_PARAMS_1(r4, "class_exists", class_name, 0x012); if (zend_is_true(r4)) { ce0 = phalcon_fetch_class(class_name TSRMLS_CC); PHALCON_INIT_VAR(i1); object_init_ex(i1, ce0); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i1, "__construct", this_ptr, options, PHALCON_CHECK); phalcon_array_update(&engines, extension, &i1, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(i2); object_init_ex(i2, phalcon_view_exception_ce); PHALCON_INIT_VAR(r5); PHALCON_CONCAT_SVS(r5, "Template engine '", class_name, "' cannot be loaded"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i2, "__construct", r5, PHALCON_CHECK); phalcon_throw_exception(i2 TSRMLS_CC); return; } zend_hash_move_forward_ex(ah0, &hp0); goto fes_b0d8_0; fee_b0d8_0: if(0){} } else { return; } } phalcon_update_property_zval(this_ptr, "_engines", strlen("_engines"), engines TSRMLS_CC); } else { PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_engines", sizeof("_engines")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(engines, t2); } PHALCON_RETURN_CHECK_CTOR(engines); }
/** * Returns a PHQL statement built based on the builder parameters * * @return string */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getPhql){ zval *dependency_injector = NULL, *models, *conditions = NULL; zval *one, *number_models, *invalid_condition; zval *model = NULL, *service_name, *meta_data, *model_instance; zval *no_primary = NULL, *primary_keys, *first_primary_key; zval *column_map = NULL, *attribute_field = NULL, *exception_message; zval *primary_key_condition, *phql, *columns; zval *selected_columns = NULL, *column = NULL, *alias = NULL, *aliased_column = NULL; zval *joined_columns = NULL, *selected_column = NULL, *selected_models; zval *selected_model = NULL, *joined_models, *joins; zval *join = NULL, *join_model = NULL, *join_conditions = NULL, *join_alias = NULL; zval *join_type = NULL, *group, *group_items, *group_item = NULL; zval *escaped_item = NULL, *joined_items = NULL, *having, *order; zval *order_items, *order_item = NULL, *limit, *number; zval *offset = NULL; HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; HashPosition hp0, hp1, hp2, hp3, hp4, hp5; zval **hd; zend_class_entry *ce0; PHALCON_MM_GROW(); PHALCON_OBS_VAR(dependency_injector); phalcon_read_property(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_INIT_NVAR(dependency_injector); PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); phalcon_update_property_zval(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); } PHALCON_OBS_VAR(models); phalcon_read_property(&models, this_ptr, SL("_models"), PH_NOISY_CC); if (Z_TYPE_P(models) == IS_ARRAY) { if (!phalcon_fast_count_ev(models TSRMLS_CC)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "At least one model is required to build the query"); return; } } else { if (!zend_is_true(models)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "At least one model is required to build the query"); return; } } PHALCON_OBS_VAR(conditions); phalcon_read_property(&conditions, this_ptr, SL("_conditions"), PH_NOISY_CC); if (phalcon_is_numeric(conditions)) { /** * If the conditions is a single numeric field. We internally create a condition * using the related primary key */ if (Z_TYPE_P(models) == IS_ARRAY) { PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(number_models); phalcon_fast_count(number_models, models TSRMLS_CC); PHALCON_INIT_VAR(invalid_condition); is_smaller_function(invalid_condition, one, number_models TSRMLS_CC); if (PHALCON_IS_TRUE(invalid_condition)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Cannot build the query. Invalid condition"); return; } PHALCON_OBS_VAR(model); phalcon_array_fetch_long(&model, models, 0, PH_NOISY_CC); } else { PHALCON_CPY_WRT(model, models); } PHALCON_INIT_VAR(service_name); ZVAL_STRING(service_name, "modelsMetadata", 1); /** * Get the models metadata service to obtain the column names, column map and * primary key */ PHALCON_INIT_VAR(meta_data); PHALCON_CALL_METHOD_PARAMS_1(meta_data, dependency_injector, "getshared", service_name); ce0 = phalcon_fetch_class(model TSRMLS_CC); PHALCON_INIT_VAR(model_instance); object_init_ex(model_instance, ce0); if (phalcon_has_constructor(model_instance TSRMLS_CC)) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(model_instance, "__construct", dependency_injector); } PHALCON_INIT_VAR(no_primary); ZVAL_BOOL(no_primary, 1); PHALCON_INIT_VAR(primary_keys); PHALCON_CALL_METHOD_PARAMS_1(primary_keys, meta_data, "getprimarykeyattributes", model_instance); if (phalcon_fast_count_ev(primary_keys TSRMLS_CC)) { if (phalcon_array_isset_long(primary_keys, 0)) { PHALCON_OBS_VAR(first_primary_key); phalcon_array_fetch_long(&first_primary_key, primary_keys, 0, PH_NOISY_CC); /** * The PHQL contains the renamed columns if available */ if (PHALCON_GLOBAL(orm).column_renaming) { PHALCON_INIT_VAR(column_map); PHALCON_CALL_METHOD_PARAMS_1(column_map, meta_data, "getcolumnmap", model_instance); } else { PHALCON_INIT_NVAR(column_map); } if (Z_TYPE_P(column_map) == IS_ARRAY) { if (phalcon_array_isset(column_map, first_primary_key)) { PHALCON_OBS_VAR(attribute_field); phalcon_array_fetch(&attribute_field, column_map, first_primary_key, PH_NOISY_CC); } else { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Column '", first_primary_key, "\" isn't part of the column map"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } } else { PHALCON_CPY_WRT(attribute_field, first_primary_key); } PHALCON_INIT_VAR(primary_key_condition); PHALCON_CONCAT_SVSVSV(primary_key_condition, "[", model, "].[", attribute_field, "] = ", conditions); PHALCON_CPY_WRT(conditions, primary_key_condition); ZVAL_BOOL(no_primary, 0); } } /** * A primary key is mandatory in these cases */ if (PHALCON_IS_TRUE(no_primary)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Source related to this model does not have a primary key defined"); return; } } PHALCON_INIT_VAR(phql); ZVAL_STRING(phql, "SELECT ", 1); PHALCON_OBS_VAR(columns); phalcon_read_property(&columns, this_ptr, SL("_columns"), PH_NOISY_CC); if (Z_TYPE_P(columns) != IS_NULL) { if (Z_TYPE_P(columns) == IS_ARRAY) { PHALCON_INIT_VAR(selected_columns); array_init(selected_columns); if (!phalcon_is_iterable(columns, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(alias, ah0, hp0); PHALCON_GET_FOREACH_VALUE(column); if (Z_TYPE_P(alias) == IS_LONG) { phalcon_array_append(&selected_columns, column, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_NVAR(aliased_column); PHALCON_CONCAT_VSV(aliased_column, column, " AS ", alias); phalcon_array_append(&selected_columns, aliased_column, PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(joined_columns); phalcon_fast_join_str(joined_columns, SL(", "), selected_columns TSRMLS_CC); phalcon_concat_self(&phql, joined_columns TSRMLS_CC); } else { phalcon_concat_self(&phql, columns TSRMLS_CC); } } else { if (Z_TYPE_P(models) == IS_ARRAY) { PHALCON_INIT_NVAR(selected_columns); array_init(selected_columns); if (!phalcon_is_iterable(models, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_KEY(alias, ah1, hp1); PHALCON_GET_FOREACH_VALUE(model); if (Z_TYPE_P(alias) == IS_LONG) { PHALCON_INIT_NVAR(selected_column); PHALCON_CONCAT_SVS(selected_column, "[", model, "].*"); } else { PHALCON_INIT_NVAR(selected_column); PHALCON_CONCAT_SVS(selected_column, "[", alias, "].*"); } phalcon_array_append(&selected_columns, selected_column, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); } PHALCON_INIT_NVAR(joined_columns); phalcon_fast_join_str(joined_columns, SL(", "), selected_columns TSRMLS_CC); phalcon_concat_self(&phql, joined_columns TSRMLS_CC); } else { PHALCON_SCONCAT_SVS(phql, "[", models, "].*"); } } /** * Join multiple models or use a single one if it is a string */ if (Z_TYPE_P(models) == IS_ARRAY) { PHALCON_INIT_VAR(selected_models); array_init(selected_models); if (!phalcon_is_iterable(models, &ah2, &hp2, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_FOREACH_KEY(alias, ah2, hp2); PHALCON_GET_FOREACH_VALUE(model); if (Z_TYPE_P(alias) == IS_STRING) { PHALCON_INIT_NVAR(selected_model); PHALCON_CONCAT_SVSVS(selected_model, "[", model, "] AS [", alias, "]"); } else { PHALCON_INIT_NVAR(selected_model); PHALCON_CONCAT_SVS(selected_model, "[", model, "]"); } phalcon_array_append(&selected_models, selected_model, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah2, &hp2); } PHALCON_INIT_VAR(joined_models); phalcon_fast_join_str(joined_models, SL(", "), selected_models TSRMLS_CC); PHALCON_SCONCAT_SV(phql, " FROM ", joined_models); } else { PHALCON_SCONCAT_SVS(phql, " FROM [", models, "]"); } /** * Check if joins were passed to the builders */ PHALCON_OBS_VAR(joins); phalcon_read_property(&joins, this_ptr, SL("_joins"), PH_NOISY_CC); if (Z_TYPE_P(joins) == IS_ARRAY) { if (!phalcon_is_iterable(joins, &ah3, &hp3, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(join); /** * The joined table is in the first place of the array */ PHALCON_OBS_NVAR(join_model); phalcon_array_fetch_long(&join_model, join, 0, PH_NOISY_CC); /** * The join conditions are in the second place of the array */ PHALCON_OBS_NVAR(join_conditions); phalcon_array_fetch_long(&join_conditions, join, 1, PH_NOISY_CC); /** * The join alias is in the second place of the array */ PHALCON_OBS_NVAR(join_alias); phalcon_array_fetch_long(&join_alias, join, 2, PH_NOISY_CC); /** * Join type */ PHALCON_OBS_NVAR(join_type); phalcon_array_fetch_long(&join_type, join, 3, PH_NOISY_CC); /** * Create the join according to the type */ if (zend_is_true(join_type)) { PHALCON_SCONCAT_VSVS(phql, join_type, " JOIN [", join_model, "]"); } else { PHALCON_SCONCAT_SVS(phql, " JOIN [", join_model, "]"); } /** * Alias comes first */ if (zend_is_true(join_alias)) { PHALCON_SCONCAT_SVS(phql, " AS [", join_alias, "]"); } /** * Conditions then */ if (zend_is_true(join_conditions)) { PHALCON_SCONCAT_SV(phql, " ON ", join_conditions); } zend_hash_move_forward_ex(ah3, &hp3); } } if (Z_TYPE_P(conditions) == IS_STRING) { PHALCON_SCONCAT_SV(phql, " WHERE ", conditions); } /** * Process group parameters */ PHALCON_OBS_VAR(group); phalcon_read_property(&group, this_ptr, SL("_group"), PH_NOISY_CC); if (Z_TYPE_P(group) != IS_NULL) { if (Z_TYPE_P(group) == IS_ARRAY) { PHALCON_INIT_VAR(group_items); array_init(group_items); if (!phalcon_is_iterable(group, &ah4, &hp4, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(group_item); if (phalcon_is_numeric(group_item)) { phalcon_array_append(&group_items, group_item, PH_SEPARATE TSRMLS_CC); } else { if (phalcon_memnstr_str(group_item, SL(".") TSRMLS_CC)) { phalcon_array_append(&group_items, group_item, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_NVAR(escaped_item); PHALCON_CONCAT_SVS(escaped_item, "[", group_item, "]"); phalcon_array_append(&group_items, escaped_item, PH_SEPARATE TSRMLS_CC); } } zend_hash_move_forward_ex(ah4, &hp4); } PHALCON_INIT_VAR(joined_items); phalcon_fast_join_str(joined_items, SL(", "), group_items TSRMLS_CC); PHALCON_SCONCAT_SV(phql, " GROUP BY ", joined_items); } else { if (phalcon_is_numeric(group)) { PHALCON_SCONCAT_SV(phql, " GROUP BY ", group); } else { if (phalcon_memnstr_str(group, SL(".") TSRMLS_CC)) { PHALCON_SCONCAT_SV(phql, " GROUP BY ", group); } else { PHALCON_SCONCAT_SVS(phql, " GROUP BY [", group, "]"); } } } PHALCON_OBS_VAR(having); phalcon_read_property(&having, this_ptr, SL("_having"), PH_NOISY_CC); if (Z_TYPE_P(having) != IS_NULL) { PHALCON_SCONCAT_SV(phql, " HAVING ", having); } } /** * Process order clause */ PHALCON_OBS_VAR(order); phalcon_read_property(&order, this_ptr, SL("_order"), PH_NOISY_CC); if (Z_TYPE_P(order) != IS_NULL) { if (Z_TYPE_P(order) == IS_ARRAY) { PHALCON_INIT_VAR(order_items); array_init(order_items); if (!phalcon_is_iterable(order, &ah5, &hp5, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(order_item); if (phalcon_is_numeric(order_item)) { phalcon_array_append(&order_items, order_item, PH_SEPARATE TSRMLS_CC); } else { if (phalcon_memnstr_str(order_item, SL(".") TSRMLS_CC)) { phalcon_array_append(&order_items, order_item, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_NVAR(escaped_item); PHALCON_CONCAT_SVS(escaped_item, "[", order_item, "]"); phalcon_array_append(&order_items, escaped_item, PH_SEPARATE TSRMLS_CC); } } zend_hash_move_forward_ex(ah5, &hp5); } PHALCON_INIT_NVAR(joined_items); phalcon_fast_join_str(joined_items, SL(", "), order_items TSRMLS_CC); PHALCON_SCONCAT_SV(phql, " ORDER BY ", joined_items); } else { PHALCON_SCONCAT_SV(phql, " ORDER BY ", order); } } /** * Process limit parameters */ PHALCON_OBS_VAR(limit); phalcon_read_property(&limit, this_ptr, SL("_limit"), PH_NOISY_CC); if (Z_TYPE_P(limit) != IS_NULL) { if (Z_TYPE_P(limit) == IS_ARRAY) { PHALCON_OBS_VAR(number); phalcon_array_fetch_string(&number, limit, SL("number"), PH_NOISY_CC); if (phalcon_array_isset_string(limit, SS("offset"))) { PHALCON_OBS_VAR(offset); phalcon_array_fetch_string(&offset, limit, SL("offset"), PH_NOISY_CC); if (phalcon_is_numeric(offset)) { PHALCON_SCONCAT_SVSV(phql, " LIMIT ", number, " OFFSET ", offset); } else { PHALCON_SCONCAT_SVS(phql, " LIMIT ", number, " OFFSET 0"); } } else { PHALCON_SCONCAT_SV(phql, " LIMIT ", number); } } else { if (phalcon_is_numeric(limit)) { PHALCON_SCONCAT_SV(phql, " LIMIT ", limit); PHALCON_OBS_NVAR(offset); phalcon_read_property(&offset, this_ptr, SL("_offset"), PH_NOISY_CC); if (Z_TYPE_P(offset) != IS_NULL) { if (phalcon_is_numeric(offset)) { PHALCON_SCONCAT_SV(phql, " OFFSET ", offset); } else { phalcon_concat_self_str(&phql, SL(" OFFSET 0") TSRMLS_CC); } } } } } RETURN_CTOR(phql); }
/** * Builds a Phalcon\Mvc\Model\Criteria based on an input array like $_POST * * @param Phalcon\DiInterface $dependencyInjector * @param string $modelName * @param array $data * @return Phalcon\Mvc\Model\Criteria */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ zval *dependency_injector, *model_name, *data; zval *conditions, *service, *meta_data = NULL, *model; zval *data_types = NULL, *bind, *value = NULL, *field = NULL, *type, *condition = NULL; zval *value_pattern = NULL, *join_conditions; zval *column_map = NULL; HashTable *ah0; HashPosition hp0; zval **hd; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &dependency_injector, &model_name, &data); if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array"); return; } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); return; } object_init_ex(return_value, phalcon_mvc_model_criteria_ce); if (zend_hash_num_elements(Z_ARRVAL_P(data))) { PHALCON_INIT_VAR(service); PHALCON_ZVAL_MAYBE_INTERNED_STRING(service, phalcon_interned_modelsMetadata); PHALCON_CALL_METHOD(&meta_data, dependency_injector, "getshared", service); PHALCON_VERIFY_INTERFACE(meta_data, phalcon_mvc_model_metadatainterface_ce); ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); if (phalcon_has_constructor(model TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, model, "__construct"); } PHALCON_VERIFY_INTERFACE_EX(model, phalcon_mvc_modelinterface_ce, phalcon_mvc_model_exception_ce, 1); if (PHALCON_GLOBAL(orm).column_renaming) { PHALCON_CALL_METHOD(&column_map, meta_data, "getreversecolumnmap", model); if (Z_TYPE_P(column_map) != IS_ARRAY) { PHALCON_INIT_NVAR(column_map); } } else { column_map = PHALCON_GLOBAL(z_null); } PHALCON_CALL_METHOD(&data_types, meta_data, "getdatatypes", model); PHALCON_INIT_VAR(bind); array_init(bind); PHALCON_INIT_VAR(conditions); array_init(conditions); /** * We look for attributes in the array passed as data */ phalcon_is_iterable(data, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { zval *real_field; PHALCON_GET_HKEY(field, ah0, hp0); PHALCON_GET_HVALUE(value); if (Z_TYPE_P(column_map) != IS_ARRAY || !phalcon_array_isset_fetch(&real_field, column_map, field)) { real_field = field; } if (phalcon_array_isset_fetch(&type, data_types, real_field)) { if (Z_TYPE_P(value) != IS_NULL && !PHALCON_IS_STRING(value, "")) { if (PHALCON_IS_LONG(type, 2)) { /** * For varchar types we use LIKE operator */ PHALCON_INIT_NVAR(condition); PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":"); PHALCON_INIT_NVAR(value_pattern); PHALCON_CONCAT_SVS(value_pattern, "%", value, "%"); phalcon_array_update_zval(&bind, field, value_pattern, PH_COPY); } else { /** * For the rest of data types we use a plain = operator */ PHALCON_INIT_NVAR(condition); PHALCON_CONCAT_VSVS(condition, field, "=:", field, ":"); phalcon_array_update_zval(&bind, field, value, PH_COPY); } phalcon_array_append(&conditions, condition, 0); } } zend_hash_move_forward_ex(ah0, &hp0); } if (zend_hash_num_elements(Z_ARRVAL_P(conditions))) { PHALCON_INIT_VAR(join_conditions); phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); PHALCON_CALL_METHOD(NULL, return_value, "where", join_conditions, bind); } } PHALCON_CALL_METHOD(NULL, return_value, "setmodelname", model_name); RETURN_MM(); }
/** * Dispatches a controller action taking into account the routing parameters * * @param Phalcon_Request $request * @param Phalcon_Response $response * @param Phalcon_View $view * @param Phalcon_Model_Manager $model * @return Phalcon_Controller */ PHP_METHOD(Phalcon_Dispatcher, dispatch){ zval *request = NULL, *response = NULL, *view = NULL, *model = NULL, *controllers_dir = NULL; zval *value = NULL, *controller = NULL, *number_dispatches = NULL; zval *controller_name = NULL, *controllers = NULL, *controller_class = NULL; zval *controller_path = NULL, *params = NULL, *action_name = NULL; zval *action_method = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL, *t10 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL; zval *i0 = NULL; zval *a0 = NULL, *a1 = NULL; zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|zz", &request, &response, &view, &model) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!view) { PHALCON_INIT_VAR(view); ZVAL_NULL(view); } if (!model) { PHALCON_INIT_VAR(model); ZVAL_NULL(model); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_basePath"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_controllersDir"), PHALCON_NOISY TSRMLS_CC); PHALCON_CONCAT_VV(r0, t0, t1); PHALCON_CPY_WRT(controllers_dir, r0); PHALCON_INIT_VAR(value); ZVAL_NULL(value); PHALCON_INIT_VAR(controller); ZVAL_NULL(controller); PHALCON_INIT_VAR(number_dispatches); ZVAL_LONG(number_dispatches, 0); phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); ws_e10f_0: PHALCON_INIT_VAR(t2); phalcon_read_property(&t2, this_ptr, SL("_finished"), PHALCON_NOISY TSRMLS_CC); if (zend_is_true(t2)) { goto we_e10f_0; } phalcon_update_property_bool(this_ptr, SL("_finished"), 1 TSRMLS_CC); PHALCON_INIT_VAR(t3); phalcon_read_property(&t3, this_ptr, SL("_controllerName"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller_name, t3); if (!zend_is_true(controller_name)) { PHALCON_INIT_VAR(t4); phalcon_read_property(&t4, this_ptr, SL("_defaultController"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller_name, t4); phalcon_update_property_zval(this_ptr, SL("_controllerName"), controller_name TSRMLS_CC); } PHALCON_INIT_VAR(t5); phalcon_read_property(&t5, this_ptr, SL("_controllers"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controllers, t5); PHALCON_INIT_VAR(r1); PHALCON_INIT_VAR(r2); PHALCON_CALL_STATIC_PARAMS_1(r2, "phalcon_text", "camelize", controller_name); PHALCON_CONCAT_VS(r1, r2, "Controller"); PHALCON_CPY_WRT(controller_class, r1); eval_int = phalcon_array_isset(controllers, controller_class); if (!eval_int) { PHALCON_INIT_VAR(c0); ZVAL_BOOL(c0, 0); PHALCON_INIT_VAR(r3); PHALCON_CALL_FUNC_PARAMS_2(r3, "class_exists", controller_class, c0); if (!zend_is_true(r3)) { PHALCON_INIT_VAR(r4); PHALCON_CONCAT_VVS(r4, controllers_dir, controller_class, ".php"); PHALCON_CPY_WRT(controller_path, r4); if (phalcon_file_exists(controller_path TSRMLS_CC) == SUCCESS) { if (phalcon_require(controller_path TSRMLS_CC) == FAILURE) { return; } } else { PHALCON_INIT_VAR(r5); PHALCON_CONCAT_SVS(r5, "File for controller class ", controller_class, " doesn't exist"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r5, PHALCON_NO_CHECK); } PHALCON_INIT_VAR(c1); ZVAL_BOOL(c1, 0); PHALCON_INIT_VAR(r6); PHALCON_CALL_FUNC_PARAMS_2(r6, "class_exists", controller_class, c1); if (!zend_is_true(r6)) { PHALCON_INIT_VAR(r7); PHALCON_CONCAT_SVS(r7, "Class ", controller_class, " was not found on controller file"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r7, PHALCON_NO_CHECK); } } ce0 = phalcon_fetch_class(controller_class TSRMLS_CC); PHALCON_INIT_VAR(i0); object_init_ex(i0, ce0); p0[0] = this_ptr; p0[1] = request; p0[2] = response; p0[3] = view; p0[4] = model; PHALCON_CALL_METHOD_PARAMS_NORETURN(i0, "__construct", 5, p0, PHALCON_CHECK); PHALCON_CPY_WRT(controller, i0); if (phalcon_method_exists_ex(controller, SL("initialize") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_NORETURN(controller, "initialize", PHALCON_NO_CHECK); } PHALCON_INIT_VAR(t6); phalcon_read_property(&t6, this_ptr, SL("_controllers"), PHALCON_NOISY TSRMLS_CC); phalcon_array_update(&t6, controller_class, &controller, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_controllers"), t6 TSRMLS_CC); } else { PHALCON_INIT_VAR(r8); phalcon_array_fetch(&r8, controllers, controller_class, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller, r8); } PHALCON_INIT_VAR(t7); phalcon_read_property(&t7, this_ptr, SL("_params"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(params, t7); PHALCON_INIT_VAR(t8); phalcon_read_property(&t8, this_ptr, SL("_actionName"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(action_name, t8); if (!zend_is_true(action_name)) { PHALCON_INIT_VAR(t9); phalcon_read_property(&t9, this_ptr, SL("_defaultAction"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(action_name, t9); phalcon_update_property_zval(this_ptr, SL("_actionName"), action_name TSRMLS_CC); } if (phalcon_method_exists_ex(controller, SL("beforedispatch") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(r9); PHALCON_CALL_METHOD_PARAMS_3(r9, controller, "beforedispatch", controller_name, action_name, params, PHALCON_NO_CHECK); if (Z_TYPE_P(r9) == IS_BOOL && !Z_BVAL_P(r9)) { PHALCON_INIT_VAR(value); ZVAL_BOOL(value, 0); goto we_e10f_0; } } PHALCON_INIT_VAR(r10); PHALCON_CONCAT_VS(r10, action_name, "Action"); PHALCON_CPY_WRT(action_method, r10); if (phalcon_method_exists(controller, action_method TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(a0); array_init(a0); phalcon_array_append(&a0, controller, PHALCON_SEPARATE_PLZ TSRMLS_CC); phalcon_array_append(&a0, action_method, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_INIT_VAR(value); PHALCON_CALL_FUNC_PARAMS_2(value, "call_user_func_array", a0, params); } else { if (phalcon_method_exists_ex(controller, SL("notfoundaction") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(a1); array_init(a1); phalcon_array_append(&a1, controller, PHALCON_SEPARATE_PLZ TSRMLS_CC); add_next_index_stringl(a1, SL("notFoundAction"), 1); PHALCON_INIT_VAR(value); PHALCON_CALL_FUNC_PARAMS_2(value, "call_user_func_array", a1, params); } else { PHALCON_INIT_VAR(r11); PHALCON_CONCAT_SVSVS(r11, "Action '", action_name, "' was not found on controller '", controller_name, "'"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r11, PHALCON_NO_CHECK); } } if (phalcon_method_exists_ex(controller, SL("afterdispatch") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_PARAMS_3_NORETURN(controller, "afterdispatch", controller_name, action_name, params, PHALCON_NO_CHECK); } PHALCON_SEPARATE(number_dispatches); increment_function(number_dispatches); PHALCON_INIT_VAR(t10); ZVAL_LONG(t10, 256); PHALCON_INIT_VAR(r12); is_smaller_function(r12, t10, number_dispatches TSRMLS_CC); if (zend_is_true(r12)) { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "Dispatcher has detected a cyclic routing causing stability problems", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, c2, PHALCON_NO_CHECK); } goto ws_e10f_0; we_e10f_0: phalcon_update_property_zval(this_ptr, SL("_returnedValue"), value TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_lastController"), controller TSRMLS_CC); RETURN_CHECK_CTOR(controller); }
/** * Builds a Phalcon\Mvc\Model\Criteria based on an input array like $_POST * * @param Phalcon\DiInterface $dependencyInjector * @param string $modelName * @param array $data * @return static */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ zval *dependency_injector, *model_name, *data; zval *conditions, *service, *meta_data, *model; zval *data_types, *bind, *value = NULL, *field = NULL, *type = NULL, *condition = NULL; zval *value_pattern = NULL, *criteria, *join_conditions; HashTable *ah0; HashPosition hp0; zval **hd; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &dependency_injector, &model_name, &data); if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array"); return; } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); return; } PHALCON_INIT_VAR(conditions); array_init(conditions); if (phalcon_fast_count_ev(data TSRMLS_CC)) { PHALCON_INIT_VAR(service); ZVAL_STRING(service, "modelsMetadata", 1); PHALCON_INIT_VAR(meta_data); phalcon_call_method_p1(meta_data, dependency_injector, "getshared", service); ce0 = phalcon_fetch_class(model_name TSRMLS_CC); PHALCON_INIT_VAR(model); object_init_ex(model, ce0); if (phalcon_has_constructor(model TSRMLS_CC)) { phalcon_call_method_noret(model, "__construct"); } PHALCON_INIT_VAR(data_types); phalcon_call_method_p1(data_types, meta_data, "getdatatypes", model); PHALCON_INIT_VAR(bind); array_init(bind); /** * We look for attributes in the array passed as data */ phalcon_is_iterable(data, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(field, ah0, hp0); PHALCON_GET_HVALUE(value); if (phalcon_array_isset(data_types, field)) { if (Z_TYPE_P(value) != IS_NULL) { if (!PHALCON_IS_STRING(value, "")) { PHALCON_OBS_NVAR(type); phalcon_array_fetch(&type, data_types, field, PH_NOISY_CC); if (PHALCON_IS_LONG(type, 2)) { /** * For varchar types we use LIKE operator */ PHALCON_INIT_NVAR(condition); PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":"); PHALCON_INIT_NVAR(value_pattern); PHALCON_CONCAT_SVS(value_pattern, "%", value, "%"); phalcon_array_update_zval(&bind, field, &value_pattern, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { /** * For the rest of data types we use a plain = operator */ PHALCON_INIT_NVAR(condition); PHALCON_CONCAT_VSVS(condition, field, "=:", field, ":"); phalcon_array_update_zval(&bind, field, &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); } } } zend_hash_move_forward_ex(ah0, &hp0); } } /** * Create an object instance and pass the paramaters to it */ PHALCON_INIT_VAR(criteria); object_init_ex(criteria, phalcon_mvc_model_criteria_ce); if (phalcon_fast_count_ev(conditions TSRMLS_CC)) { PHALCON_INIT_VAR(join_conditions); phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); phalcon_call_method_p1_noret(criteria, "where", join_conditions); phalcon_call_method_p1_noret(criteria, "bind", bind); } RETURN_CTOR(criteria); }