/** * Phalcon_Backend_Adapter_File constructor * * @param mixed $frontendObject * @param array $backendOptions */ PHP_METHOD(Phalcon_Cache_Backend_File, __construct){ zval *frontend_object = NULL, *backend_options = NULL; zval *a0 = NULL; zval *r0 = NULL, *r1 = NULL; zval *i0 = NULL, *i1 = NULL; zval *c0 = NULL, *c1 = NULL; int eval_int; PHALCON_MM_GROW(); PHALCON_INIT_VAR(a0); array_init(a0); zend_update_property(phalcon_cache_backend_file_ce, this_ptr, "_backendOptions", strlen("_backendOptions"), a0 TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &frontend_object, &backend_options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_zval(this_ptr, "_frontendObject", strlen("_frontendObject"), frontend_object TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_backendOptions", strlen("_backendOptions"), backend_options TSRMLS_CC); eval_int = phalcon_array_isset_string(backend_options, "cacheDir", strlen("cacheDir")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, backend_options, "cacheDir", strlen("cacheDir"), PHALCON_NOISY TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_1(r0, "is_writable", r1, 0x017); if (!zend_is_true(r0)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_cache_exception_ce); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "The cache directory does not exist or is not writable", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", c0, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } } else { PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_cache_exception_ce); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "You must specify the cache directory with the option cachesDir", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i1, "__construct", c1, PHALCON_CHECK); phalcon_throw_exception(i1 TSRMLS_CC); return; } PHALCON_MM_RESTORE(); }
/** * Throws an internal exception * * @param string $message * @param int $exceptionCode */ PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException) { zval *message, *exception_code = NULL, *exception, *events_manager; zval *event_name, *status; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &message, &exception_code); if (!exception_code) { PHALCON_INIT_VAR(exception_code); ZVAL_LONG(exception_code, 0); } PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_cli_dispatcher_exception_ce); phalcon_call_method_p2_noret(exception, "__construct", message, exception_code); PHALCON_OBS_VAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "dispatch:beforeException", 1); PHALCON_INIT_VAR(status); phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, exception); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } phalcon_throw_exception(exception TSRMLS_CC); 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; }
/** * Throws an internal exception * * @param Phalcon_Response $response * @param string $message */ PHP_METHOD(Phalcon_Dispatcher, _throwDispatchException){ zval *response = NULL, *message = NULL; zval *c0 = NULL, *c1 = NULL; zval *i0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &response, &message) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(c0); ZVAL_LONG(c0, 404); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "Not Found", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(response, "setstatuscode", c0, c1, PHALCON_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_dispatcher_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", message, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; }
/** * Sets transaction manager related to the transaction * * @param Phalcon\Mvc\Model\Transaction\Manager $manager */ PHP_METHOD(Phalcon_Mvc_Model_Transaction, setTransactionManager){ zval *manager = NULL; zval *i0 = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &manager) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(manager) != IS_OBJECT) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_mvc_model_transaction_exception_ce); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_VS(r0, manager, " must be an Object"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r0, PH_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } phalcon_update_property_zval(this_ptr, SL("_manager"), manager TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * 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_Translate_Adapter_Array constructor * * @param array $data */ PHP_METHOD(Phalcon_Translate_Adapter_Array, __construct){ zval *options = NULL, *data = NULL; zval *r0 = NULL; zval *i0 = NULL, *i1 = NULL; zval *c0 = NULL, *c1 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } eval_int = phalcon_array_isset_string(options, "content", strlen("content")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, options, "content", strlen("content"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(data, r0); if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_translate_exception_ce); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "Translation data must be an array", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", c0, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } } else { PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_translate_exception_ce); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "Translation content was not provided", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i1, "__construct", c1, PHALCON_CHECK); phalcon_throw_exception(i1 TSRMLS_CC); return; } phalcon_update_property_zval(this_ptr, "_traslate", strlen("_traslate"), data TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Sends SQL statements to the MySQL database server returning success state. * When the SQL sent have returned any row, the result is a PHP resource. * * * $resultset = $connection->query("SELECT * FROM robots WHERE type=?", array("mechanical")); * * @param string $sqlStatement * @return Phalcon_Db_Result_Mysql|boolean */ PHP_METHOD(Phalcon_Db_Adapter_Mysql, query){ zval *sql_statement = NULL, *id_connection = NULL, *result = NULL; zval *number_error = NULL, *error_message = NULL; zval *t0 = NULL; zval *i0 = NULL, *i1 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &sql_statement) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "_beforequery", sql_statement, PHALCON_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_idConnection"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(id_connection, t0); PHALCON_INIT_VAR(result); PHALCON_CALL_FUNC_PARAMS_2(result, "mysqli_query", id_connection, sql_statement); if (zend_is_true(result)) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "_afterquery", sql_statement, PHALCON_NO_CHECK); if (Z_TYPE_P(result) == IS_OBJECT) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_db_result_mysql_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", result, PHALCON_CHECK); RETURN_CTOR(i0); } RETURN_CHECK_CTOR(result); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, this_ptr, "noerror", PHALCON_NO_CHECK); PHALCON_CPY_WRT(number_error, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVS(r2, " when executing \"", sql_statement, "\""); PHALCON_CALL_METHOD_PARAMS_1(r1, this_ptr, "error", r2, PHALCON_NO_CHECK); PHALCON_CPY_WRT(error_message, r1); PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_db_exception_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i1, "__construct", error_message, number_error, PHALCON_CHECK); phalcon_throw_exception(i1 TSRMLS_CC); return; }
/** * Phalcon_Logger_Adapter_File constructor * * @param string $name * @param array $options */ PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ zval *name = NULL, *options = NULL, *mode = NULL; zval *a0 = NULL, *a1 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *t0 = NULL; zval *i0 = NULL; int eval_int; PHALCON_MM_GROW(); PHALCON_INIT_VAR(a0); array_init(a0); zend_update_property(phalcon_logger_adapter_file_ce, this_ptr, "_quenue", strlen("_quenue"), a0 TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &name, &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!options) { PHALCON_INIT_VAR(a1); array_init(a1); PHALCON_CPY_WRT(options, a1); } eval_int = phalcon_array_isset_string(options, "mode", strlen("mode")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, options, "mode", strlen("mode"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(mode, r0); } else { PHALCON_INIT_VAR(mode); ZVAL_STRING(mode, "ab", 1); } PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_2(r1, "fopen", name, mode, 0x025); phalcon_update_property_zval(this_ptr, "_fileHandler", strlen("_fileHandler"), r1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_fileHandler", sizeof("_fileHandler")-1, PHALCON_NOISY TSRMLS_CC); if (!zend_is_true(t0)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_logger_exception_ce); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVS(r2, "Can't open log file at '", name, "'"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r2, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_MM_RESTORE(); }
/** * Creates a table using MySQL SQL * * @param string $tableName * @param string $schemaName * @param array $definition * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, createTable){ zval *table_name = NULL, *schema_name = NULL, *definition = NULL; zval *sql = NULL, *success = NULL; zval *i0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *t0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &table_name, &schema_name, &definition) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(definition) != IS_ARRAY) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_db_exception_ce); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_SVS(r0, "Invalid definition to create the table '", table_name, "'"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r0, PH_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } eval_int = phalcon_array_isset_string(definition, SL("columns")+1); if (!eval_int) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); return; } PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, definition, SL("columns"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r2); phalcon_fast_count(r2, r1 TSRMLS_CC); if (!zend_is_true(r2)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); return; } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_3(sql, t0, "createtable", table_name, schema_name, definition, PH_NO_CHECK); PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD_PARAMS_1(success, this_ptr, "execute", sql, PH_NO_CHECK); RETURN_CCTOR(success); }
/** * 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\Logger\Adapter\File constructor * * @param string $name * @param array $options */ PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ zval *name = NULL, *options = NULL, *mode = NULL, *handler = NULL, *exception_message = NULL; zval *exception = NULL; zval *a0 = NULL; int eval_int; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(a0); array_init(a0); zend_update_property(phalcon_logger_adapter_file_ce, this_ptr, SL("_quenue"), a0 TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &name, &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!options) { PHALCON_INIT_VAR(options); array_init(options); } eval_int = phalcon_array_isset_string(options, SL("mode")+1); if (eval_int) { PHALCON_INIT_VAR(mode); phalcon_array_fetch_string(&mode, options, SL("mode"), PH_NOISY_CC); } else { PHALCON_INIT_VAR(mode); ZVAL_STRING(mode, "ab", 1); } PHALCON_INIT_VAR(handler); PHALCON_CALL_FUNC_PARAMS_2(handler, "fopen", name, mode); if (!zend_is_true(handler)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Can't open log file at '", name, "'"); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_logger_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } phalcon_update_property_zval(this_ptr, SL("_path"), name TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_options"), options TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_fileHandler"), handler 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(); }
/** * Gets row in a specific position of the resultset * * @param int $index * @return Phalcon_Model_Base */ PHP_METHOD(Phalcon_Model_Resultset, offsetGet){ zval *index = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL; zval *i0 = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, this_ptr, "count", PHALCON_NO_CHECK); PHALCON_INIT_VAR(r1); is_smaller_function(r1, index, r0 TSRMLS_CC); if (zend_is_true(r1)) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "seek", index, PHALCON_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD(r2, this_ptr, "valid", PHALCON_NO_CHECK); if (Z_TYPE_P(r2) != IS_BOOL || (Z_TYPE_P(r2) == IS_BOOL && Z_BVAL_P(r2))) { PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CALL_METHOD(r3, this_ptr, "current", PHALCON_NO_CHECK); PHALCON_RETURN_DZVAL(r3); } else { PHALCON_MM_RESTORE(); RETURN_FALSE; } } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_model_exception_ce); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "The index does not exist in the cursor", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", c0, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; }
/** * Resulsets cannot be changed. It has only been implemented to meet the definition of the ArrayAccess interface * * @param int $index */ PHP_METHOD(Phalcon_Model_Resultset, offsetUnset){ zval *offset = NULL; zval *i0 = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &offset) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_model_exception_ce); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "Cursor is an immutable ArrayAccess object", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", c0, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; }
/** * Throws an internal exception * * @param string $message */ PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){ zval *message = NULL, *dependency_injector = NULL, *service = NULL; zval *response = NULL, *status_code = NULL, *status_message = NULL; zval *exception = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &message) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(dependency_injector); phalcon_read_property(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_dispatcher_exception_ce, "A dependency injection container is required to access the 'response' service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "response", 1); PHALCON_INIT_VAR(response); PHALCON_CALL_METHOD_PARAMS_1(response, dependency_injector, "getshared", service, PH_NO_CHECK); PHALCON_INIT_VAR(status_code); ZVAL_LONG(status_code, 404); PHALCON_INIT_VAR(status_message); ZVAL_STRING(status_message, "Not Found", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(response, "setstatuscode", status_code, status_message, PH_NO_CHECK); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_dispatcher_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; }
/** * 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(); }
/** * Rolls back the transaction * * @param string $rollbackMessage * @param Phalcon\Mvc\ModelInterface $rollbackRecord * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){ zval *message = NULL, *_rollback_record = NULL, *rollback_code = NULL, rollback_record = {}, rollback_message = {}, manager = {}, connection = {}, success = {}, i0 = {}; phalcon_fetch_params(0, 0, 4, &message, &rollback_record, &rollback_code); if (!message || !zend_is_true(message)) { ZVAL_STRING(&rollback_message, "Transaction aborted"); } else { PHALCON_CPY_WRT(&rollback_message, message); } if (_rollback_record && Z_TYPE_P(_rollback_record) != IS_OBJECT) { phalcon_update_property_zval(getThis(), SL("_rollbackRecord"), _rollback_record); } phalcon_read_property(&rollback_record, getThis(), SL("_rollbackRecord"), PH_NOISY); if (!rollback_code) { rollback_code = &PHALCON_GLOBAL(z_zero); } phalcon_read_property(&manager, getThis(), SL("_manager"), PH_NOISY); if (Z_TYPE(manager) == IS_OBJECT) { PHALCON_CALL_METHODW(NULL, &manager, "notifyrollback", getThis()); } phalcon_read_property(&connection, getThis(), SL("_connection"), PH_NOISY); PHALCON_CALL_METHODW(&success, &connection, "rollback"); if (zend_is_true(&success)) { object_init_ex(&i0, phalcon_mvc_model_transaction_failed_ce); PHALCON_CALL_METHODW(NULL, &i0, "__construct", &rollback_message, &rollback_record, rollback_code); phalcon_throw_exception(&i0); } RETURN_CTOR(&success); }
/** * Throws an internal exception * * @param string $message * @param int $exceptionCode */ PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException){ zval *message, *exception_code = NULL, *exception, *events_manager; zval *event_name, *status; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &message, &exception_code) == FAILURE) { RETURN_MM_NULL(); } if (!exception_code) { PHALCON_INIT_VAR(exception_code); ZVAL_LONG(exception_code, 0); } PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_cli_dispatcher_exception_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(exception, "__construct", message, exception_code); PHALCON_OBS_VAR(events_manager); phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "dispatch:beforeException", 1); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_3(status, events_manager, "fire", event_name, this_ptr, exception); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } phalcon_throw_exception(exception TSRMLS_CC); return; }
/** * Fires a event in the events manager causing that the acive listeners will be notified about it * * @param string $eventType * @param object $source * @return mixed */ PHP_METHOD(Phalcon_Events_Manager, fire){ zval *event_type = NULL, *source = NULL, *colon = NULL, *event_parts = NULL; zval *exception_message = NULL, *exception = NULL, *type = NULL, *event_name = NULL; zval *status = NULL, *events = NULL, *fire_events = NULL, *handler = NULL, *event = NULL; zval *class_name = NULL, *arguments = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &event_type, &source) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(colon); ZVAL_STRING(colon, ":", 1); PHALCON_INIT_VAR(event_parts); phalcon_fast_explode(event_parts, colon, event_type TSRMLS_CC); eval_int = phalcon_array_isset_long(event_parts, 1); if (!eval_int) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "Invalid event type ", event_type); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_events_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_INIT_VAR(type); phalcon_array_fetch_long(&type, event_parts, 0, PH_NOISY_CC); PHALCON_INIT_VAR(event_name); phalcon_array_fetch_long(&event_name, event_parts, 1, PH_NOISY_CC); PHALCON_INIT_VAR(status); ZVAL_NULL(status); PHALCON_INIT_VAR(events); phalcon_read_property(&events, this_ptr, SL("_events"), PH_NOISY_CC); eval_int = phalcon_array_isset(events, type); if (eval_int) { PHALCON_INIT_VAR(fire_events); phalcon_array_fetch(&fire_events, events, type, PH_NOISY_CC); if (!phalcon_valid_foreach(fire_events TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(fire_events); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(handler); if (Z_TYPE_P(handler) == IS_OBJECT) { PHALCON_INIT_VAR(event); object_init_ex(event, phalcon_events_event_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(event, "__construct", event_name, source, PH_CHECK); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, handler TSRMLS_CC); if (PHALCON_COMPARE_STRING(class_name, "Closure")) { PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, event, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&arguments, source, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(status); PHALCON_CALL_FUNC_PARAMS_2(status, "call_user_func_array", handler, arguments); } else { if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, handler, Z_STRVAL_P(event_name), event, source, PH_NO_CHECK); } } } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: if(0){} } RETURN_CCTOR(status); }
/** * Generates a URL * * @param string|array $uri * @return string */ PHP_METHOD(Phalcon_Mvc_Url, get){ zval *uri = NULL, *base_uri = NULL, *dependency_injector = NULL, *service = NULL; zval *router = NULL, *route_name = NULL, *route = NULL, *exception_message = NULL; zval *exception = NULL, *pattern = NULL, *replaced_pattern = NULL; zval *controller_name = NULL, *wildcard = NULL, *action_name = NULL; zval *have_bracket = NULL, *matches = NULL, *match_position = NULL; zval *set_order = NULL, *names_pattern = NULL, *have_variables = NULL; zval *match = NULL, *match_zero = NULL, *match_one = NULL, *value = NULL, *new_pcre_pattern = NULL; zval *final_uri = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *t0 = NULL; zval *p0[] = { NULL, NULL, NULL, NULL }; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &uri) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!uri) { PHALCON_ALLOC_ZVAL_MM(uri); ZVAL_NULL(uri); } PHALCON_INIT_VAR(base_uri); PHALCON_CALL_METHOD(base_uri, this_ptr, "getbaseuri", PH_NO_CHECK); if (Z_TYPE_P(uri) == IS_ARRAY) { eval_int = phalcon_array_isset_string(uri, SL("for")+1); if (!eval_int) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "It's necessary to define the route name with the parameter \"for\""); return; } PHALCON_INIT_VAR(dependency_injector); phalcon_read_property(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (!zend_is_true(dependency_injector)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "router", 1); PHALCON_INIT_VAR(router); PHALCON_CALL_METHOD_PARAMS_1(router, dependency_injector, "getshared", service, PH_NO_CHECK); PHALCON_INIT_VAR(route_name); phalcon_array_fetch_string(&route_name, uri, SL("for"), PH_NOISY_CC); PHALCON_INIT_VAR(route); PHALCON_CALL_METHOD_PARAMS_1(route, router, "getroutebyname", route_name, PH_NO_CHECK); if (Z_TYPE_P(route) != IS_OBJECT) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Cannot obtain a route using the name \"", route_name, "\""); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_url_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_INIT_VAR(pattern); PHALCON_CALL_METHOD(pattern, route, "getpattern", PH_NO_CHECK); PHALCON_CPY_WRT(replaced_pattern, pattern); eval_int = phalcon_array_isset_string(uri, SL("controller")+1); if (eval_int) { PHALCON_INIT_VAR(controller_name); phalcon_array_fetch_string(&controller_name, uri, SL("controller"), PH_NOISY_CC); PHALCON_INIT_VAR(wildcard); ZVAL_STRING(wildcard, ":controller", 1); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_str_replace(r0, wildcard, controller_name, replaced_pattern TSRMLS_CC); PHALCON_CPY_WRT(replaced_pattern, r0); } eval_int = phalcon_array_isset_string(uri, SL("action")+1); if (eval_int) { PHALCON_INIT_VAR(action_name); phalcon_array_fetch_string(&action_name, uri, SL("action"), PH_NOISY_CC); PHALCON_INIT_VAR(wildcard); ZVAL_STRING(wildcard, ":action", 1); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_str_replace(r1, wildcard, action_name, replaced_pattern TSRMLS_CC); PHALCON_CPY_WRT(replaced_pattern, r1); } PHALCON_INIT_VAR(have_bracket); phalcon_fast_strpos_str(have_bracket, replaced_pattern, SL("{") TSRMLS_CC); if (Z_TYPE_P(have_bracket) != IS_BOOL || (Z_TYPE_P(have_bracket) == IS_BOOL && Z_BVAL_P(have_bracket))) { PHALCON_INIT_VAR(matches); ZVAL_NULL(matches); PHALCON_INIT_VAR(match_position); ZVAL_LONG(match_position, 1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 2); PHALCON_CPY_WRT(set_order, t0); PHALCON_INIT_VAR(names_pattern); ZVAL_STRING(names_pattern, "#{([a-zA-Z][a-zA-Z0-9\\_\\-]+)(:([^}]+))*}#", 1); p0[0] = names_pattern; p0[1] = replaced_pattern; Z_SET_ISREF_P(matches); p0[2] = matches; p0[3] = set_order; PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_FUNC_PARAMS(r2, "preg_match_all", 4, p0); Z_UNSET_ISREF_P(p0[2]); PHALCON_CPY_WRT(have_variables, r2); if (zend_is_true(have_variables)) { if (!phalcon_valid_foreach(matches TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(matches); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_0306_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_0306_0; } PHALCON_INIT_VAR(match); ZVAL_ZVAL(match, *hd, 1, 0); PHALCON_INIT_VAR(match_zero); phalcon_array_fetch_long(&match_zero, match, 0, PH_NOISY_CC); PHALCON_INIT_VAR(match_one); phalcon_array_fetch_long(&match_one, match, 1, PH_NOISY_CC); eval_int = phalcon_array_isset(uri, match_one); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch(&value, uri, match_one, PH_NOISY_CC); PHALCON_INIT_VAR(new_pcre_pattern); phalcon_fast_str_replace(new_pcre_pattern, match_zero, value, replaced_pattern TSRMLS_CC); PHALCON_CPY_WRT(replaced_pattern, new_pcre_pattern); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_0306_0; fee_0306_0: if(0){} } } RETURN_CCTOR(replaced_pattern); } else { PHALCON_INIT_VAR(final_uri); PHALCON_CONCAT_VV(final_uri, base_uri, uri); RETURN_CTOR(final_uri); } PHALCON_MM_RESTORE(); }
/** * Inserts data into a table using custom RBDM SQL syntax * * @param string $table * @param array $values * @param array $fields * @return boolean */ PHP_METHOD(Phalcon_Db, insert){ zval *table = NULL, *values = NULL, *fields = NULL, *number_values = NULL, *exception_message = NULL; zval *exception = NULL, *placeholders = NULL, *value = NULL, *position = NULL; zval *str_value = NULL, *comma = NULL, *joined_values = NULL, *joined_fields = NULL; zval *insert_sql = NULL, *success = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &table, &values, &fields) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(values); if (!fields) { PHALCON_ALLOC_ZVAL_MM(fields); ZVAL_NULL(fields); } if (Z_TYPE_P(values) == IS_ARRAY) { PHALCON_INIT_VAR(number_values); phalcon_fast_count(number_values, values TSRMLS_CC); if (phalcon_compare_strict_long(number_values, 0 TSRMLS_CC)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Unable to insert into ", table, " without data"); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_db_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_INIT_VAR(placeholders); array_init(placeholders); if (!phalcon_valid_foreach(values TSRMLS_CC)) { return; } ALLOC_HASHTABLE(ah0); zend_hash_init(ah0, 0, NULL, NULL, 0); zend_hash_copy(ah0, Z_ARRVAL_P(values), NULL, NULL, sizeof(zval*)); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto ph_cycle_end_0; } PHALCON_INIT_VAR(position); PHALCON_GET_FOREACH_KEY(position, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(value) == IS_OBJECT) { PHALCON_INIT_VAR(str_value); PHALCON_CALL_FUNC_PARAMS_1(str_value, "strval", value); phalcon_array_append(&placeholders, str_value, PH_SEPARATE TSRMLS_CC); PHALCON_SEPARATE_PARAM(values); phalcon_array_unset(values, position); } else { if (Z_TYPE_P(value) == IS_NULL) { phalcon_array_append_string(&placeholders, SL("null"), PH_SEPARATE TSRMLS_CC); PHALCON_SEPARATE_PARAM(values); phalcon_array_unset(values, position); } else { phalcon_array_append_string(&placeholders, SL("?"), PH_SEPARATE TSRMLS_CC); } } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: zend_hash_destroy(ah0); efree(ah0); PHALCON_INIT_VAR(comma); ZVAL_STRING(comma, ", ", 1); PHALCON_INIT_VAR(joined_values); phalcon_fast_join(joined_values, comma, placeholders TSRMLS_CC); if (Z_TYPE_P(fields) == IS_ARRAY) { PHALCON_INIT_VAR(joined_fields); phalcon_fast_join(joined_fields, comma, fields TSRMLS_CC); PHALCON_INIT_VAR(insert_sql); PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", table, " (", joined_fields, ") VALUES (", joined_values, ")"); } else { PHALCON_INIT_VAR(insert_sql); PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", table, " VALUES (", joined_values, ")"); } PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD_PARAMS_2(success, this_ptr, "execute", insert_sql, values, PH_NO_CHECK); RETURN_CCTOR(success); } PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array"); return; }
/** * Rollbacks the transaction * * @param string $rollbackMessage * @param Phalcon\Mvc\Model $rollbackRecord * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){ zval *rollback_message = NULL, *rollback_record = NULL; zval *manager = NULL, *call_object = NULL, *arguments = NULL, *connection = NULL; zval *success = NULL, *exception = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &rollback_message, &rollback_record) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!rollback_message) { PHALCON_ALLOC_ZVAL_MM(rollback_message); ZVAL_NULL(rollback_message); } else { PHALCON_SEPARATE_PARAM(rollback_message); } if (!rollback_record) { PHALCON_ALLOC_ZVAL_MM(rollback_record); ZVAL_NULL(rollback_record); } else { PHALCON_SEPARATE_PARAM(rollback_record); } PHALCON_INIT_VAR(manager); phalcon_read_property(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); if (zend_is_true(manager)) { PHALCON_INIT_VAR(call_object); array_init(call_object); phalcon_array_append(&call_object, manager, PH_SEPARATE TSRMLS_CC); add_next_index_stringl(call_object, SL("notifyRollback"), 1); PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, this_ptr, PH_SEPARATE TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("call_user_func_array", call_object, arguments); } PHALCON_INIT_VAR(connection); phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC); PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD(success, connection, "rollback", PH_NO_CHECK); if (zend_is_true(success)) { if (!zend_is_true(rollback_message)) { PHALCON_INIT_VAR(rollback_message); ZVAL_STRING(rollback_message, "Transaction aborted", 1); } if (zend_is_true(rollback_record)) { phalcon_update_property_zval(this_ptr, SL("_rollbackRecord"), rollback_record TSRMLS_CC); } PHALCON_INIT_VAR(rollback_record); phalcon_read_property(&rollback_record, this_ptr, SL("_rollbackRecord"), PH_NOISY_CC); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_model_transaction_failed_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(exception, "__construct", rollback_message, rollback_record, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_MM_RESTORE(); }
PHP_METHOD(Phalcon_Model_MetaData, _initializeMetaData){ zval *model = NULL, *table = NULL, *schema = NULL, *key = NULL, *connection = NULL, *is_view = NULL; zval *exists = NULL, *meta_datas = NULL, *attributes = NULL, *primary_keys = NULL; zval *non_primary_keys = NULL, *numeric_typed = NULL, *not_null = NULL; zval *field_types = NULL, *identity_field = NULL, *meta_data = NULL; zval *field_name = NULL, *type = NULL, *table_metadata = 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, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL; zval *i0 = NULL; zval *a0 = NULL, *a1 = NULL, *a2 = NULL, *a3 = NULL, *a4 = NULL, *a5 = NULL, *a6 = NULL; zval *a7 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &model, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_VV(r0, schema, table); PHALCON_CPY_WRT(key, r0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PHALCON_NOISY TSRMLS_CC); eval_int = phalcon_array_isset(t0, key); if (!eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, model, "getconnection", PHALCON_NO_CHECK); PHALCON_CPY_WRT(connection, r1); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD(r2, model, "isview", PHALCON_NO_CHECK); PHALCON_CPY_WRT(is_view, r2); if (!zend_is_true(is_view)) { PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CALL_METHOD_PARAMS_2(r3, connection, "tableexists", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(exists, r3); } else { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD_PARAMS_2(r4, connection, "viewexists", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(exists, r4); } if (!zend_is_true(exists)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_model_exception_ce); PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_ALLOC_ZVAL_MM(r6); phalcon_get_class(r6, model TSRMLS_CC); PHALCON_CONCAT_SVSVSV(r5, "Table \"", schema, "\".\"", table, "\" doesn't exist on database when dumping information for ", r6); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r5, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } else { if (zend_is_true(is_view)) { PHALCON_ALLOC_ZVAL_MM(r7); PHALCON_CALL_METHOD_PARAMS_2(r7, connection, "describeview", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(meta_datas, r7); } else { PHALCON_ALLOC_ZVAL_MM(r8); PHALCON_CALL_METHOD_PARAMS_2(r8, connection, "describetable", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(meta_datas, r8); } PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(attributes, a0); PHALCON_INIT_VAR(a1); array_init(a1); PHALCON_CPY_WRT(primary_keys, a1); PHALCON_INIT_VAR(a2); array_init(a2); PHALCON_CPY_WRT(non_primary_keys, a2); PHALCON_INIT_VAR(a3); array_init(a3); PHALCON_CPY_WRT(numeric_typed, a3); PHALCON_INIT_VAR(a4); array_init(a4); PHALCON_CPY_WRT(not_null, a4); PHALCON_INIT_VAR(a5); array_init(a5); PHALCON_CPY_WRT(field_types, a5); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); if (phalcon_valid_foreach(meta_datas TSRMLS_CC)) { ah0 = Z_ARRVAL_P(meta_datas); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_f5c6_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_f5c6_0; } PHALCON_INIT_VAR(meta_data); ZVAL_ZVAL(meta_data, *hd, 1, 0); PHALCON_INIT_VAR(r9); phalcon_array_fetch_string(&r9, meta_data, SL("Field"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(field_name, r9); phalcon_array_append(&attributes, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_INIT_VAR(r10); phalcon_array_fetch_string(&r10, meta_data, SL("Key"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r10, "PRI")) { phalcon_array_append(&primary_keys, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } PHALCON_INIT_VAR(r11); phalcon_array_fetch_string(&r11, meta_data, SL("Type"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(type, r11); phalcon_array_update(&field_types, field_name, &type, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "char", 1); PHALCON_INIT_VAR(r12); phalcon_fast_strpos(r12, type, c0 TSRMLS_CC); if (Z_TYPE_P(r12) == IS_BOOL && !Z_BVAL_P(r12)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "int", 1); PHALCON_INIT_VAR(r13); phalcon_fast_strpos(r13, type, c1 TSRMLS_CC); if (Z_TYPE_P(r13) != IS_BOOL || (Z_TYPE_P(r13) == IS_BOOL && Z_BVAL_P(r13))) { PHALCON_INIT_VAR(t1); ZVAL_BOOL(t1, 1); phalcon_array_update(&numeric_typed, field_name, &t1, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "decimal", 1); PHALCON_INIT_VAR(r14); phalcon_fast_strpos(r14, type, c2 TSRMLS_CC); if (Z_TYPE_P(r14) != IS_BOOL || (Z_TYPE_P(r14) == IS_BOOL && Z_BVAL_P(r14))) { PHALCON_INIT_VAR(t2); ZVAL_BOOL(t2, 1); phalcon_array_update(&numeric_typed, field_name, &t2, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(c3); ZVAL_STRING(c3, "numeric", 1); PHALCON_INIT_VAR(r15); phalcon_fast_strpos(r15, type, c3 TSRMLS_CC); if (Z_TYPE_P(r15) != IS_BOOL || (Z_TYPE_P(r15) == IS_BOOL && Z_BVAL_P(r15))) { PHALCON_INIT_VAR(t3); ZVAL_BOOL(t3, 1); phalcon_array_update(&numeric_typed, field_name, &t3, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } } } } PHALCON_INIT_VAR(r16); phalcon_array_fetch_string(&r16, meta_data, SL("Null"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r16, "NO")) { phalcon_array_append(¬_null, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } PHALCON_INIT_VAR(r17); phalcon_array_fetch_string(&r17, meta_data, SL("Extra"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r17, "auto_increment")) { PHALCON_CPY_WRT(identity_field, field_name); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_f5c6_0; fee_f5c6_0: if(0){} } else { return; } PHALCON_INIT_VAR(a6); array_init(a6); PHALCON_CPY_WRT(table_metadata, a6); phalcon_array_update_long(&table_metadata, 0, &attributes, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t4); phalcon_read_property(&t4, this_ptr, SL("_metaData"), PHALCON_NOISY TSRMLS_CC); phalcon_array_update(&t4, key, &table_metadata, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t4 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t5); phalcon_read_property(&t5, this_ptr, SL("_changed"), PHALCON_NOISY TSRMLS_CC); if (!zend_is_true(t5)) { PHALCON_INIT_VAR(a7); array_init(a7); phalcon_array_append(&a7, this_ptr, PHALCON_SEPARATE_PLZ TSRMLS_CC); add_next_index_stringl(a7, SL("storeMetaData"), 1); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("register_shutdown_function", a7); phalcon_update_property_bool(this_ptr, SL("_changed"), 1 TSRMLS_CC); } } } PHALCON_MM_RESTORE(); }
/** * Get the conditions of query * * @return string $query */ PHP_METHOD(Phalcon_Model_Query, getConditions){ zval *controller_front = NULL, *model_manager = NULL, *model_name = NULL; zval *entity = NULL, *meta_data = NULL, *attributes = NULL, *numeric_types = NULL; zval *i = NULL, *parameters = NULL, *conditions = NULL, *value = NULL, *param = NULL; zval *condition = NULL, *index = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = 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, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL; zval *i0 = NULL; zval *a0 = NULL, *a1 = NULL; zval *c0 = NULL; HashTable *ah0, *ah1, *ah2; HashPosition hp0, hp1, hp2; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY TSRMLS_CC); if (!zend_is_true(t0)) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_STATIC(r0, "phalcon_controller_front", "getinstance"); PHALCON_CPY_WRT(controller_front, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, controller_front, "getmodelcomponent", PHALCON_NO_CHECK); PHALCON_CPY_WRT(model_manager, r1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "setmanager", model_manager, PHALCON_NO_CHECK); } else { PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(model_manager, t1); } PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_models", sizeof("_models")-1, PHALCON_NOISY TSRMLS_CC); if (phalcon_valid_foreach(t2 TSRMLS_CC)) { ah0 = Z_ARRVAL_P(t2); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_a355_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_a355_0; } PHALCON_INIT_VAR(model_name); ZVAL_ZVAL(model_name, *hd, 1, 0); PHALCON_INIT_VAR(r2); PHALCON_CALL_METHOD_PARAMS_1(r2, model_manager, "getmodel", model_name, PHALCON_NO_CHECK); PHALCON_CPY_WRT(entity, r2); if (!zend_is_true(entity)) { PHALCON_INIT_VAR(i0); object_init_ex(i0, phalcon_model_exception_ce); PHALCON_INIT_VAR(r3); PHALCON_CONCAT_BOTH(r3, "The model ", model_name, " does not exist"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r3, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_INIT_VAR(r4); PHALCON_CALL_METHOD(r4, model_manager, "getmetadata", PHALCON_NO_CHECK); PHALCON_CPY_WRT(meta_data, r4); PHALCON_INIT_VAR(r5); PHALCON_CALL_METHOD_PARAMS_1(r5, meta_data, "getattributes", entity, PHALCON_NO_CHECK); PHALCON_CPY_WRT(attributes, r5); PHALCON_INIT_VAR(r6); PHALCON_CALL_METHOD_PARAMS_1(r6, meta_data, "getdatatypesnumeric", entity, PHALCON_NO_CHECK); PHALCON_CPY_WRT(numeric_types, r6); PHALCON_INIT_VAR(t3); phalcon_read_property(&t3, this_ptr, "_data", sizeof("_data")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_INIT_VAR(r7); phalcon_fast_count(r7, t3 TSRMLS_CC); if (zend_is_true(r7)) { PHALCON_INIT_VAR(i); ZVAL_LONG(i, 0); PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(parameters, a0); PHALCON_INIT_VAR(a1); array_init(a1); PHALCON_CPY_WRT(conditions, a1); PHALCON_INIT_VAR(t4); phalcon_read_property(&t4, this_ptr, "_data", sizeof("_data")-1, PHALCON_NOISY TSRMLS_CC); if (phalcon_valid_foreach(t4 TSRMLS_CC)) { ah1 = Z_ARRVAL_P(t4); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_a355_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_a355_1; } else { PHALCON_INIT_VAR(param); PHALCON_GET_FOREACH_KEY(param, ah1, hp1); } PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_INIT_VAR(r8); PHALCON_CALL_FUNC_PARAMS_2(r8, "in_array", param, attributes, 0x03E); if (zend_is_true(r8)) { PHALCON_INIT_VAR(t5); ZVAL_STRING(t5, "", 1); PHALCON_INIT_VAR(r9); is_not_identical_function(r9, t5, value TSRMLS_CC); PHALCON_INIT_VAR(r11); PHALCON_CALL_FUNC_PARAMS_1(r11, "is_null", value, 0x041); PHALCON_INIT_VAR(r10); boolean_not_function(r10, r11 TSRMLS_CC); PHALCON_INIT_VAR(r12); phalcon_and_function(r12, r9, r10); if (zend_is_true(r12)) { if (!PHALCON_COMPARE_STRING(value, "@")) { eval_int = phalcon_array_isset(numeric_types, param); if (eval_int) { PHALCON_INIT_VAR(r13); PHALCON_CONCAT_VBOTH(r13, param, " = ?", i); PHALCON_CPY_WRT(condition, r13); phalcon_array_update(¶meters, i, &value, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(r14); PHALCON_CONCAT_VBOTH(r14, param, " LIKE ?", i); PHALCON_CPY_WRT(condition, r14); PHALCON_INIT_VAR(r15); PHALCON_CONCAT_BOTH(r15, "%", value, "%"); phalcon_array_update(¶meters, i, &r15, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } phalcon_array_append(&conditions, condition, PHALCON_SEPARATE_PLZ TSRMLS_CC); } } } PHALCON_SEPARATE(i); increment_function(i); zend_hash_move_forward_ex(ah1, &hp1); goto fes_a355_1; fee_a355_1: if(0){} } else { return; } } else { PHALCON_INIT_VAR(t6); phalcon_read_property(&t6, this_ptr, "_parameters", sizeof("_parameters")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(parameters, t6); PHALCON_INIT_VAR(t7); phalcon_read_property(&t7, this_ptr, "_conditions", sizeof("_conditions")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(conditions, t7); } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, " AND ", 1); PHALCON_INIT_VAR(r16); phalcon_fast_join(r16, c0, conditions TSRMLS_CC); PHALCON_CPY_WRT(conditions, r16); if (phalcon_valid_foreach(parameters TSRMLS_CC)) { ah2 = Z_ARRVAL_P(parameters); zend_hash_internal_pointer_reset_ex(ah2, &hp2); fes_a355_2: if(zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) != SUCCESS){ goto fee_a355_2; } else { PHALCON_INIT_VAR(index); PHALCON_GET_FOREACH_KEY(index, ah2, hp2); } PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_INIT_VAR(r17); PHALCON_INIT_VAR(r18); PHALCON_CONCAT_LEFT(r18, "?", index); PHALCON_CALL_FUNC_PARAMS_3(r17, "str_replace", r18, value, conditions, 0x003); PHALCON_CPY_WRT(conditions, r17); zend_hash_move_forward_ex(ah2, &hp2); goto fes_a355_2; fee_a355_2: if(0){} } else { return; } if (PHALCON_COMPARE_STRING(conditions, "")) { PHALCON_INIT_VAR(conditions); ZVAL_STRING(conditions, "1=1", 1); } PHALCON_RETURN_CHECK_CTOR(conditions); zend_hash_move_forward_ex(ah0, &hp0); goto fes_a355_0; fee_a355_0: if(0){} } else { return; } PHALCON_MM_RESTORE(); }
/** * Inserts data into a table using custom RBDM SQL syntax * * @param string $table * @param array $values * @param array $fields * @return boolean */ PHP_METHOD(Phalcon_Db, insert){ zval *table = NULL, *values = NULL, *fields = NULL, *placeholders = NULL, *value = NULL; zval *n = NULL, *comma = NULL, *joined_values = NULL, *insert_sql = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; zval *i0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &table, &values, &fields) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(values); if (!fields) { PHALCON_ALLOC_ZVAL_MM(fields); ZVAL_NULL(fields); } if (Z_TYPE_P(values) == IS_ARRAY) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_count(r0, values TSRMLS_CC); if (!zend_is_true(r0)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_db_exception_ce); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CONCAT_SVS(r1, "Unable to insert into ", table, " without data"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r1, PH_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_INIT_VAR(placeholders); array_init(placeholders); if (!phalcon_valid_foreach(values TSRMLS_CC)) { return; } ALLOC_HASHTABLE(ah0); zend_hash_init(ah0, 0, NULL, NULL, 0); zend_hash_copy(ah0, Z_ARRVAL_P(values), NULL, NULL, sizeof(zval*)); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_e7f0_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_e7f0_1; } PHALCON_INIT_VAR(n); PHALCON_GET_FOREACH_KEY(n, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); if (Z_TYPE_P(value) == IS_OBJECT) { PHALCON_INIT_VAR(r2); PHALCON_CALL_FUNC_PARAMS_1(r2, "strval", value); phalcon_array_append(&placeholders, r2, PH_SEPARATE TSRMLS_CC); PHALCON_SEPARATE_PARAM(values); phalcon_array_unset(values, n); } else { phalcon_array_append_string(&placeholders, SL("?"), PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_e7f0_1; fee_e7f0_1: zend_hash_destroy(ah0); efree(ah0); PHALCON_INIT_VAR(comma); ZVAL_STRING(comma, ", ", 1); PHALCON_INIT_VAR(joined_values); phalcon_fast_join(joined_values, comma, placeholders TSRMLS_CC); if (Z_TYPE_P(fields) == IS_ARRAY) { PHALCON_ALLOC_ZVAL_MM(r3); phalcon_fast_join(r3, comma, fields TSRMLS_CC); PHALCON_INIT_VAR(insert_sql); PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", table, " (", r3, ") VALUES (", joined_values, ")"); } else { PHALCON_INIT_VAR(insert_sql); PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", table, " VALUES (", joined_values, ")"); } PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD_PARAMS_2(r4, this_ptr, "execute", insert_sql, values, PH_NO_CHECK); RETURN_CTOR(r4); } PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array"); return; }
/** * Checks whether view exists on registered extensions and render it */ PHP_METHOD(Phalcon_View, _engineRender){ zval *engines = NULL, *view_path = NULL, *silence = NULL, *not_exists = NULL; zval *view_params = NULL, *views_dir_path = NULL, *engine = NULL; zval *extension = NULL, *view_engine_path = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *i0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &engines, &view_path, &silence) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 1); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_viewParams", sizeof("_viewParams")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(view_params, t0); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_basePath", sizeof("_basePath")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_viewsDir", sizeof("_viewsDir")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CONCAT_VVV(r0, t1, t2, view_path); PHALCON_CPY_WRT(views_dir_path, r0); if (phalcon_valid_foreach(engines TSRMLS_CC)) { ah0 = Z_ARRVAL_P(engines); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_b0d8_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_b0d8_1; } 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(r1); PHALCON_CONCAT_VV(r1, views_dir_path, extension); PHALCON_CPY_WRT(view_engine_path, r1); if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_PARAMS_2_NORETURN(engine, "render", view_engine_path, view_params, PHALCON_NO_CHECK); PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 0); goto fee_b0d8_1; } zend_hash_move_forward_ex(ah0, &hp0); goto fes_b0d8_1; fee_b0d8_1: if(0){} } else { return; } if (zend_is_true(not_exists)) { if (!zend_is_true(silence)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_view_exception_ce); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVS(r2, "View '", views_dir_path, "' was not found in the views directory"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r2, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } } PHALCON_MM_RESTORE(); }
/** * 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); }
/** * 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); }
/** * Throws an internal exception * * @param string $message * @param int $exceptionCode */ PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){ zval *message, *exception_code = NULL, *dependency_injector; zval *exception_message, *exception = NULL, *service; zval *response, *status_code, *status_message; zval *events_manager, *event_name, *status; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &message, &exception_code); if (!exception_code) { PHALCON_INIT_VAR(exception_code); ZVAL_LONG(exception_code, 0); } else { PHALCON_SEPARATE_PARAM(exception_code); } PHALCON_OBS_VAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_INIT_NVAR(exception_code); ZVAL_LONG(exception_code, 0); PHALCON_INIT_VAR(exception_message); ZVAL_STRING(exception_message, "A dependency injection container is required to access the 'response' service", 1); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_dispatcher_exception_ce); phalcon_call_method_p2_noret(exception, "__construct", exception_message, exception_code); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "response", 1); PHALCON_INIT_VAR(response); phalcon_call_method_p1(response, dependency_injector, "getshared", service); /** * Dispatcher exceptions automatically sends 404 status */ PHALCON_INIT_VAR(status_code); ZVAL_LONG(status_code, 404); PHALCON_INIT_VAR(status_message); ZVAL_STRING(status_message, "Not Found", 1); phalcon_call_method_p2_noret(response, "setstatuscode", status_code, status_message); /** * Create the real exception */ PHALCON_INIT_NVAR(exception); object_init_ex(exception, phalcon_mvc_dispatcher_exception_ce); phalcon_call_method_p2_noret(exception, "__construct", message, exception_code); PHALCON_OBS_VAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "dispatch:beforeException", 1); PHALCON_INIT_VAR(status); phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, exception); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } /** * Throw the exception if it wasn't handled */ phalcon_throw_exception(exception TSRMLS_CC); return; }