/** * Blur image * * @param int $radius Blur radius * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, blur) { zval *radius = NULL; long r; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &radius); if (!radius) { PHALCON_INIT_VAR(radius); ZVAL_LONG(radius, 1); } else if (Z_TYPE_P(radius) != IS_LONG) { PHALCON_SEPARATE_PARAM(radius); PHALCON_INIT_NVAR(radius); ZVAL_LONG(radius, 1); } else { r = phalcon_get_intval(radius); if (r < 1) { PHALCON_SEPARATE_PARAM(radius); PHALCON_INIT_NVAR(radius); ZVAL_LONG(radius, 1); } else if (r > 100) { PHALCON_SEPARATE_PARAM(radius); PHALCON_INIT_NVAR(radius); ZVAL_LONG(radius, 100); } } PHALCON_CALL_METHOD(NULL, this_ptr, "_blur", radius); RETURN_THIS(); }
/** * Phalcon_Model_MetaData_Session constructor * * @param Phalcon_Config|stdClass $options */ PHP_METHOD(Phalcon_Model_MetaData_Session, __construct){ zval *options = NULL, *adapter_options = NULL; zval *t0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(options); if (Z_TYPE_P(options) == IS_ARRAY) { PHALCON_SEPARATE_PARAM(options); convert_to_array(options); PHALCON_CPY_WRT(adapter_options, options); } else { PHALCON_CPY_WRT(adapter_options, options); } eval_int = phalcon_isset_property(adapter_options, "suffix", strlen("suffix") TSRMLS_CC); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, adapter_options, "suffix", sizeof("suffix")-1, PHALCON_NOISY TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_suffix", strlen("_suffix"), t0 TSRMLS_CC); } PHALCON_MM_RESTORE(); }
/** * Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch() * *<code> * //Return array with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_NUM); * * //Return associative array without integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_ASSOC); * * //Return associative array together with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_BOTH); * * //Return an object * $result->setFetchMode(Phalcon\Db::FETCH_OBJ); *</code> * * @param int $fetchMode */ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ zval *fetch_mode, *fetch_arg1 = NULL, *fetch_arg2 = NULL; zval *pdo_statement; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &fetch_mode, &fetch_arg1, &fetch_arg2); PHALCON_SEPARATE_PARAM(fetch_mode); if (Z_TYPE_P(fetch_mode) != IS_LONG) { convert_to_long(fetch_mode); } pdo_statement = phalcon_read_property(getThis(), SL("_pdoStatement"), PH_NOISY); if (Z_LVAL_P(fetch_mode) != 0) { if (fetch_arg1 && fetch_arg2) { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode, fetch_arg1, fetch_arg2); } else if (fetch_arg1) { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode, fetch_arg1); } else if (fetch_arg2) { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode, fetch_arg2); } else { PHALCON_CALL_METHOD(NULL, pdo_statement, "setfetchmode", fetch_mode); } phalcon_update_property_long(getThis(), SL("_fetchMode"), Z_LVAL_P(fetch_mode)); } RETURN_MM_NULL(); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, connect){ zval *descriptor = NULL, *dbname; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { RETURN_MM_NULL(); } if (!descriptor) { PHALCON_INIT_VAR(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_OBS_NVAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } if (!phalcon_array_isset_string(descriptor, SS("dbname"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "dbname must be specified"); return; } else { PHALCON_OBS_VAR(dbname); phalcon_array_fetch_string(&dbname, descriptor, SL("dbname"), PH_NOISY_CC); phalcon_array_update_string(&descriptor, SL("dsn"), &dbname, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Sqlite", "connect", descriptor); PHALCON_MM_RESTORE(); }
/** * Creates a password hash using bcrypt with a pseudo random salt * * @param string $password * @param int $workFactor * @return string */ PHP_METHOD(Phalcon_Security, hash){ zval *password, *work_factor = NULL, *format, *factor; zval *salt_bytes, *salt; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &password, &work_factor); if (!work_factor) { PHALCON_INIT_VAR(work_factor); } else { PHALCON_SEPARATE_PARAM(work_factor); } if (Z_TYPE_P(work_factor) == IS_NULL) { PHALCON_OBS_NVAR(work_factor); phalcon_read_property_this(&work_factor, this_ptr, SL("_workFactor"), PH_NOISY_CC); } PHALCON_INIT_VAR(format); ZVAL_STRING(format, "%02s", 1); PHALCON_INIT_VAR(factor); phalcon_call_func_p2(factor, "sprintf", format, work_factor); PHALCON_INIT_VAR(salt_bytes); phalcon_call_method(salt_bytes, this_ptr, "getsaltbytes"); PHALCON_INIT_VAR(salt); PHALCON_CONCAT_SVSV(salt, "$2a$", factor, "$", salt_bytes); phalcon_call_func_p2(return_value, "crypt", password, salt); RETURN_MM(); }
/** * Phalcon\Cache\Backend\Xcache constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, __construct){ zval *frontend, *options = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &frontend, &options); if (!options) { PHALCON_INIT_VAR(options); } else { PHALCON_SEPARATE_PARAM(options); } if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_INIT_NVAR(options); array_init(options); } if (!phalcon_array_isset_str(options, SL("statsKey"))) { phalcon_array_update_str_str(options, SL("statsKey"), SL("_PHCX"), PH_COPY); } PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_xcache_ce, getThis(), "__construct", frontend, options); PHALCON_MM_RESTORE(); }
/** * Phalcon\Cache\Backend\Xcache constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, __construct){ zval *frontend, *options = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &frontend, &options); if (!options) { PHALCON_INIT_VAR(options); } else { PHALCON_SEPARATE_PARAM(options); } if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_INIT_NVAR(options); array_init(options); } if (!phalcon_array_isset_string(options, SS("statsKey"))) { phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCX"), PH_SEPARATE TSRMLS_CC); } PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Xcache", "__construct", frontend, options); PHALCON_MM_RESTORE(); }
/** * Constructor for Phalcon_Db_Adapter_Mysql. This method does not should to be called directly. Use Phalcon_Db::factory instead * * @param stdClass $descriptor */ PHP_METHOD(Phalcon_Db_Adapter_Mysql, __construct){ zval *descriptor = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!descriptor) { PHALCON_INIT_VAR(descriptor); ZVAL_NULL(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_descriptor"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(descriptor, t0); } PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "connect", descriptor, PHALCON_NO_CHECK); PHALCON_MM_RESTORE(); }
/** * Phalcon\Flash constructor * * @param array $cssClasses */ PHP_METHOD(Phalcon_Flash, __construct){ zval *css_classes = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &css_classes); if (!css_classes) { PHALCON_INIT_VAR(css_classes); } else { PHALCON_SEPARATE_PARAM(css_classes); } if (Z_TYPE_P(css_classes) != IS_ARRAY) { PHALCON_INIT_NVAR(css_classes); array_init_size(css_classes, 4); add_assoc_stringl_ex(css_classes, SS("error"), SL("errorMessage"), 1); add_assoc_stringl_ex(css_classes, SS("notice"), SL("noticeMessage"), 1); add_assoc_stringl_ex(css_classes, SS("success"), SL("successMessage"), 1); add_assoc_stringl_ex(css_classes, SS("warning"), SL("warningMessage"), 1); } phalcon_update_property_this(this_ptr, SL("_cssClasses"), css_classes TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon\Flash constructor * * @param array $cssClasses */ PHP_METHOD(Phalcon_Flash, __construct){ zval *css_classes = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &css_classes) == FAILURE) { RETURN_MM_NULL(); } if (!css_classes) { PHALCON_INIT_VAR(css_classes); } else { PHALCON_SEPARATE_PARAM(css_classes); } if (Z_TYPE_P(css_classes) != IS_ARRAY) { PHALCON_INIT_NVAR(css_classes); array_init_size(css_classes, 4); add_assoc_stringl_ex(css_classes, SS("error"), SL("errorMessage"), 1); add_assoc_stringl_ex(css_classes, SS("notice"), SL("noticeMessage"), 1); add_assoc_stringl_ex(css_classes, SS("success"), SL("successMessage"), 1); add_assoc_stringl_ex(css_classes, SS("warning"), SL("warningMessage"), 1); } phalcon_update_property_zval(this_ptr, SL("_cssClasses"), css_classes TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Parses a raw doc block returning the annotations found * * @param string $docBlock * @param string $file * @param int $line * @return array */ PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock){ zval *doc_block, *file = NULL, *line = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &doc_block, &file, &line); if (!file) { PHALCON_INIT_VAR(file); } else { PHALCON_SEPARATE_PARAM(file); } if (!line) { PHALCON_INIT_VAR(line); } if (Z_TYPE_P(file) != IS_STRING) { PHALCON_INIT_NVAR(file); ZVAL_STRING(file, "eval code", 1); } if (phannot_parse_annotations(return_value, doc_block, file, line TSRMLS_CC) == FAILURE) { return; } RETURN_MM(); }
/** * Handles routing information received from command-line arguments * * @param array $arguments */ PHP_METHOD(Phalcon_CLI_Router, handle){ zval *arguments = NULL, *module_name = NULL, *task_name = NULL, *action_name = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &arguments); if (!arguments) { PHALCON_INIT_VAR(arguments); array_init(arguments); } else { PHALCON_SEPARATE_PARAM(arguments); } if (Z_TYPE_P(arguments) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_cli_router_exception_ce, "Arguments must be an Array"); return; } PHALCON_INIT_VAR(module_name); PHALCON_INIT_VAR(task_name); PHALCON_INIT_VAR(action_name); /** * Check for a module */ if (phalcon_array_isset_string(arguments, SS("module"))) { PHALCON_OBS_NVAR(module_name); phalcon_array_fetch_string(&module_name, arguments, SL("module"), PH_NOISY); phalcon_array_unset_string(&arguments, SS("module"), PH_SEPARATE); } /** * Check for a task */ if (phalcon_array_isset_string(arguments, SS("task"))) { PHALCON_OBS_NVAR(task_name); phalcon_array_fetch_string(&task_name, arguments, SL("task"), PH_NOISY); phalcon_array_unset_string(&arguments, SS("task"), PH_SEPARATE); } /** * Check for an action */ if (phalcon_array_isset_string(arguments, SS("action"))) { PHALCON_OBS_NVAR(action_name); phalcon_array_fetch_string(&action_name, arguments, SL("action"), PH_NOISY); phalcon_array_unset_string(&arguments, SS("action"), PH_SEPARATE); } phalcon_update_property_this(this_ptr, SL("_module"), module_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_task"), task_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_action"), action_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_params"), arguments TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon\Mvc\Model\Transaction\Manager constructor * * @param Phalcon\DiInterface $dependencyInjector */ PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, __construct){ zval *dependency_injector = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &dependency_injector); if (!dependency_injector) { PHALCON_INIT_VAR(dependency_injector); } else { PHALCON_SEPARATE_PARAM(dependency_injector); } if (zend_is_true(dependency_injector)) { phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); } else { PHALCON_INIT_NVAR(dependency_injector); PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); return; } PHALCON_MM_RESTORE(); }
void test_phalcon_separate_param(void) { startup_php(__func__); zend_first_try { zval* x; zval* orig; PHALCON_MM_GROW(); MAKE_STD_ZVAL(x); ZVAL_LONG(x, 0xB61964F6l); Z_ADDREF_P(x); Z_ADDREF_P(x); Z_ADDREF_P(x); orig = x; CU_ASSERT_EQUAL(Z_REFCOUNT_P(x), 4); CU_ASSERT_EQUAL(Z_ISREF_P(x), 0); PHALCON_SEPARATE_PARAM(x); CU_ASSERT_EQUAL(Z_REFCOUNT_P(x), 1); CU_ASSERT_EQUAL(Z_ISREF_P(x), 0); CU_ASSERT_PTR_NOT_EQUAL(x, orig); CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 4); CU_ASSERT_EQUAL(Z_ISREF_P(orig), 0); CU_ASSERT_EQUAL(Z_TYPE_P(x), IS_LONG); CU_ASSERT_EQUAL(Z_LVAL_P(x), 0xB61964F6l); CU_ASSERT_EQUAL(Z_TYPE_P(x), Z_TYPE_P(orig)); CU_ASSERT_EQUAL(Z_LVAL_P(x), Z_LVAL_P(orig)); zval_ptr_dtor(&orig); CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1); CU_ASSERT_EQUAL(_mem_block_check(orig, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1); CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 3); zval_ptr_dtor(&orig); CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1); CU_ASSERT_EQUAL(_mem_block_check(orig, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1); CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 2); zval_ptr_dtor(&orig); CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1); CU_ASSERT_EQUAL(_mem_block_check(orig, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1); CU_ASSERT_EQUAL(Z_REFCOUNT_P(orig), 1); zval_ptr_dtor(&orig); CU_ASSERT_EQUAL(_mem_block_check(x, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC), 1); PHALCON_MM_RESTORE(); } zend_catch { CU_ASSERT(0); } zend_end_try(); shutdown_php(); CU_ASSERT_EQUAL(leaks, 0); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * Support set search_path after connectted if schema is specified in config. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ zval *descriptor = NULL, *schema = NULL, *sql, *password; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &descriptor); if (!descriptor) { PHALCON_INIT_VAR(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_OBS_NVAR(descriptor); phalcon_read_property_this(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY TSRMLS_CC); } if (phalcon_array_isset_string(descriptor, SS("schema"))) { PHALCON_OBS_VAR(schema); phalcon_array_fetch_string(&schema, descriptor, SL("schema"), PH_NOISY); phalcon_array_unset_string(&descriptor, SS("schema"), PH_COPY); phalcon_update_property_this(this_ptr, SL("_schema"), schema TSRMLS_CC); } else { PHALCON_INIT_VAR(schema); } if (phalcon_array_isset_string_fetch(&password, descriptor, SS("password"))) { /* There is a bug in pdo_pgsql driver when the password is empty, * the driver tries to access invalid memory: * * if (dbh->password[0] != '\'' && dbh->password[strlen(dbh->password) - 1] != '\'') * * To avoid this we set the password to null */ if (Z_TYPE_P(password) == IS_STRING && Z_STRLEN_P(password) == 0) { phalcon_array_update_string(&descriptor, SL("password"), PHALCON_GLOBAL(z_null), PH_COPY); } } PHALCON_CALL_PARENT(NULL, phalcon_db_adapter_pdo_postgresql_ce, this_ptr, "connect", descriptor); /** * Execute the search path in the after connect */ if (Z_TYPE_P(schema) == IS_STRING) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); PHALCON_CALL_METHOD(NULL, this_ptr, "execute", sql); } PHALCON_MM_RESTORE(); }
/** * Applies the internal format to the message * * @param string $message * @param int $type * @param int $time * @return string */ PHP_METHOD(Phalcon_Logger_Adapter_File, _applyFormat){ zval *message = NULL, *type = NULL, *time = NULL, *format = NULL, *date_format = NULL; zval *date = NULL, *new_format = NULL, *type_string = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &message, &type, &time) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!time) { PHALCON_ALLOC_ZVAL_MM(time); ZVAL_LONG(time, 0); } else { PHALCON_SEPARATE_PARAM(time); } if (!zend_is_true(time)) { PHALCON_INIT_VAR(time); PHALCON_CALL_FUNC(time, "time"); } PHALCON_INIT_VAR(format); phalcon_read_property(&format, this_ptr, SL("_format"), PH_NOISY_CC); PHALCON_INIT_VAR(date_format); phalcon_read_property(&date_format, this_ptr, SL("_dateFormat"), PH_NOISY_CC); PHALCON_INIT_VAR(date); PHALCON_CALL_FUNC_PARAMS_2(date, "date", date_format, time); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "%date%", 1); PHALCON_INIT_VAR(new_format); phalcon_fast_str_replace(new_format, c0, date, format TSRMLS_CC); PHALCON_INIT_VAR(type_string); PHALCON_CALL_METHOD_PARAMS_1(type_string, this_ptr, "gettypestring", type, PH_NO_CHECK); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "%type%", 1); PHALCON_INIT_VAR(format); phalcon_fast_str_replace(format, c1, type_string, new_format TSRMLS_CC); PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "%message%", 1); PHALCON_INIT_VAR(new_format); phalcon_fast_str_replace(new_format, c2, message, format TSRMLS_CC); RETURN_CTOR(new_format); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * Support set search_path after connectted if schema is specified in config. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect) { zval *descriptor = NULL, *schema = NULL, *sql = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!descriptor) { PHALCON_ALLOC_ZVAL_MM(descriptor); ZVAL_NULL(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_INIT_VAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } PHALCON_INIT_VAR(schema); ZVAL_NULL(schema); eval_int = phalcon_array_isset_string(descriptor, SS("schema")); if (eval_int) { PHALCON_INIT_VAR(schema); phalcon_array_fetch_string(&schema, descriptor, SL("schema"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SS("schema")); } PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); if (Z_TYPE_P(schema) == IS_STRING) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "execute", sql, PH_NO_CHECK); } PHALCON_MM_RESTORE(); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, connect) { zval *descriptor = NULL, *startup, *value = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &descriptor); if (!descriptor) { PHALCON_INIT_VAR(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_OBS_NVAR(descriptor); phalcon_read_property_this(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY TSRMLS_CC); } /** * Connect */ PHALCON_CALL_PARENT(NULL, phalcon_db_adapter_pdo_oracle_ce, this_ptr, "connect", descriptor); /** * Database session settings initiated with each HTTP request. Oracle behaviour * depends on particular NLS* parameter. Check if the developer has defined custom * startup or create one from scratch */ if (phalcon_array_isset_string(descriptor, SS("startup"))) { PHALCON_OBS_VAR(startup); phalcon_array_fetch_string(&startup, descriptor, SL("startup"), PH_NOISY); if (Z_TYPE_P(startup) == IS_ARRAY) { phalcon_is_iterable(startup, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(value); PHALCON_CALL_METHOD(NULL, this_ptr, "execute", value); zend_hash_move_forward_ex(ah0, &hp0); } } } PHALCON_MM_RESTORE(); }
/** * Appends a message to the validator * * @param string $message * @param string $field * @param string $type */ PHP_METHOD(Phalcon_Mvc_Model_Validator, appendMessage){ zval *message = NULL, *field = NULL, *type = NULL, *class_name = NULL, *suffix = NULL; zval *empty_string = NULL, *model_message = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &message, &field, &type) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!field) { PHALCON_ALLOC_ZVAL_MM(field); ZVAL_NULL(field); } if (!type) { PHALCON_ALLOC_ZVAL_MM(type); ZVAL_NULL(type); } else { PHALCON_SEPARATE_PARAM(type); } if (!zend_is_true(type)) { PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, this_ptr TSRMLS_CC); PHALCON_INIT_VAR(suffix); ZVAL_STRING(suffix, "Validator", 1); PHALCON_INIT_VAR(empty_string); ZVAL_STRING(empty_string, "", 1); PHALCON_INIT_VAR(type); phalcon_fast_str_replace(type, suffix, empty_string, class_name TSRMLS_CC); } PHALCON_INIT_VAR(model_message); object_init_ex(model_message, phalcon_mvc_model_message_ce); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(model_message, "__construct", message, field, type, PH_CHECK); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_messages"), PH_NOISY_CC); phalcon_array_append(&t0, model_message, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_messages"), t0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Moves internal resulset cursor to another position letting us to fetch a certain row * * @param int $number */ PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek) { zval *number = NULL, *n = NULL, *pdo_statement = NULL, *result = NULL; zval *r0 = NULL, *r1 = NULL; zval *t0 = NULL, *t1 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &number) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(number); PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, -1); PHALCON_ALLOC_ZVAL_MM(r0); mul_function(r0, t0, t1 TSRMLS_CC); PHALCON_CPY_WRT(n, r0); decrement_function(number); PHALCON_INIT_VAR(pdo_statement); phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); PHALCON_CALL_METHOD_NORETURN(pdo_statement, "execute", PH_NO_CHECK); ws_a5eb_0: PHALCON_INIT_VAR(r1); is_not_equal_function(r1, n, number TSRMLS_CC); if (!zend_is_true(r1)) { goto we_a5eb_0; } PHALCON_INIT_VAR(result); PHALCON_CALL_METHOD(result, pdo_statement, "fetch", PH_NO_CHECK); if (Z_TYPE_P(result) != IS_ARRAY) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE(n); increment_function(n); goto ws_a5eb_0; we_a5eb_0: if(0) {} PHALCON_MM_RESTORE(); }
/** * Handles routing information received from command-line arguments * * @param array $arguments */ PHP_METHOD(Phalcon_CLI_Router, handle){ zval *arguments = NULL, module_name = {}, namespace_name = {}, task_name = {}, action_name = {}; phalcon_fetch_params(0, 0, 1, &arguments); if (!arguments || Z_TYPE_P(arguments) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_router_exception_ce, "Arguments must be an Array"); return; } PHALCON_SEPARATE_PARAM(arguments); /** * Check for a module */ if (phalcon_array_isset_fetch_str(&module_name, arguments, SL("module"))) { phalcon_array_unset_str(arguments, SL("module"), PH_COPY); phalcon_update_property_this(getThis(), SL("_module"), &module_name); } /** * Check for a namespace */ if (phalcon_array_isset_fetch_str(&namespace_name, arguments, SL("namespace"))) { phalcon_array_unset_str(arguments, SL("namespace"), PH_COPY); phalcon_update_property_this(getThis(), SL("_namespace"), &namespace_name); } /** * Check for a task */ if (phalcon_array_isset_fetch_str(&task_name, arguments, SL("task"))) { phalcon_array_unset_str(arguments, SL("task"), PH_COPY); phalcon_update_property_this(getThis(), SL("_task"), &task_name); } /** * Check for an action */ if (phalcon_array_isset_fetch_str(&action_name, arguments, SL("action"))) { phalcon_array_unset_str(arguments, SL("action"), PH_COPY); phalcon_update_property_this(getThis(), SL("_action"), &action_name); } phalcon_update_property_this(getThis(), SL("_params"), arguments); }
/** * Phalcon\Cache\Backend\Libmemcached constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, __construct){ zval *frontend, *options = NULL, *server, *servers; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &frontend, &options); if (!options) { PHALCON_INIT_VAR(options); } else { PHALCON_SEPARATE_PARAM(options); } if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_INIT_NVAR(options); array_init(options); } if (!phalcon_array_isset_str(options, SL("servers"))) { PHALCON_INIT_VAR(servers); array_init_size(servers, 1); PHALCON_INIT_VAR(server); array_init_size(server, 3); phalcon_array_update_str_str(server, SL("host"), SL("127.0.0.1"), PH_COPY); phalcon_array_update_str_long(server, SL("port"), 11211, PH_COPY); phalcon_array_update_str_long(server, SL("weight"), 1, PH_COPY); phalcon_array_append(servers, server, PH_COPY); phalcon_array_update_str(options, SL("servers"), servers, PH_COPY); } if (!phalcon_array_isset_str(options, SL("statsKey"))) { phalcon_array_update_str_str(options, SL("statsKey"), SL("_PHCM"), PH_COPY); } PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_libmemcached_ce, getThis(), "__construct", frontend, options); PHALCON_MM_RESTORE(); }
/** * Appends a message to the validator * * @param string $message * @param string $field * @param string $type */ PHP_METHOD(Phalcon_Mvc_Model_Validator, appendMessage){ zval *message, *field = NULL, *type = NULL, *class_name, *suffix; zval *empty_string, *model_message; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &message, &field, &type); if (!field) { PHALCON_INIT_VAR(field); } if (!type) { PHALCON_INIT_VAR(type); } else { PHALCON_SEPARATE_PARAM(type); } if (!zend_is_true(type)) { PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); PHALCON_INIT_VAR(suffix); ZVAL_STRING(suffix, "Validator", 1); PHALCON_INIT_VAR(empty_string); ZVAL_STRING(empty_string, "", 1); PHALCON_INIT_NVAR(type); phalcon_fast_str_replace(type, suffix, empty_string, class_name TSRMLS_CC); } PHALCON_INIT_VAR(model_message); object_init_ex(model_message, phalcon_mvc_model_message_ce); phalcon_call_method_p3_noret(model_message, "__construct", message, field, type); phalcon_update_property_array_append(this_ptr, SL("_messages"), model_message TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon\Cache\Backend\Memcache constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, __construct){ zval *frontend, *options = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &frontend, &options) == FAILURE) { RETURN_MM_NULL(); } if (!options) { PHALCON_INIT_VAR(options); } else { PHALCON_SEPARATE_PARAM(options); } if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_INIT_NVAR(options); array_init(options); } if (!phalcon_array_isset_string(options, SS("host"))) { phalcon_array_update_string_string(&options, SL("host"), SL("127.0.0.1"), PH_SEPARATE TSRMLS_CC); } if (!phalcon_array_isset_string(options, SS("port"))) { phalcon_array_update_string_string(&options, SL("port"), SL("11211"), PH_SEPARATE TSRMLS_CC); } if (!phalcon_array_isset_string(options, SS("persistent"))) { phalcon_array_update_string_bool(&options, SL("persistent"), 0, PH_SEPARATE TSRMLS_CC); } if (!phalcon_array_isset_string(options, SS("statsKey"))) { phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCM"), PH_SEPARATE TSRMLS_CC); } PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Memcache", "__construct", frontend, options); PHALCON_MM_RESTORE(); }
/** * Phalcon\Cache\Backend\Memcache constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, __construct){ zval *frontend, *options = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &frontend, &options); if (!options) { PHALCON_INIT_VAR(options); } else { PHALCON_SEPARATE_PARAM(options); } if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_INIT_NVAR(options); array_init_size(options, 4); } if (!phalcon_array_isset_string(options, SS("host"))) { phalcon_array_update_string_string(&options, SL("host"), SL("127.0.0.1"), PH_COPY); } if (!phalcon_array_isset_string(options, SS("port"))) { phalcon_array_update_string_long(&options, SL("port"), 11211, PH_COPY); } if (!phalcon_array_isset_string(options, SS("persistent"))) { phalcon_array_update_string_bool(&options, SL("persistent"), 0, PH_COPY); } if (!phalcon_array_isset_string(options, SS("statsKey"))) { phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCM"), PH_COPY); } PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_memcache_ce, this_ptr, "__construct", frontend, options); PHALCON_MM_RESTORE(); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * Support set search_path after connectted if schema is specified in config. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ zval *descriptor = NULL, *schema = NULL, *sql; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &descriptor); if (!descriptor) { PHALCON_INIT_VAR(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_OBS_NVAR(descriptor); phalcon_read_property_this(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } PHALCON_INIT_VAR(schema); if (phalcon_array_isset_string(descriptor, SS("schema"))) { PHALCON_OBS_NVAR(schema); phalcon_array_fetch_string(&schema, descriptor, SL("schema"), PH_NOISY); phalcon_array_unset_string(&descriptor, SS("schema"), PH_SEPARATE); } PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); /** * Execute the search path in the after connect */ if (Z_TYPE_P(schema) == IS_STRING) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); phalcon_call_method_p1_noret(this_ptr, "execute", sql); } PHALCON_MM_RESTORE(); }
/** * Render the image and return the binary string. * * @param string $ext image type to return: png, jpg, gif, etc * @param int $quality quality of image: 1-100 * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, render) { zval *ext = NULL, *quality = NULL, *constant, *file; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &ext, &quality); if (!ext) { file = phalcon_fetch_nproperty_this(this_ptr, SL("_file"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(constant); if (!zend_get_constant(SL("PATHINFO_EXTENSION"), constant TSRMLS_CC)) { RETURN_MM(); } ext = NULL; PHALCON_CALL_FUNCTION(&ext, "pathinfo", file, constant); if (!PHALCON_IS_NOT_EMPTY(ext)) { ZVAL_STRING(ext, "png", 1); } } if (!quality) { PHALCON_INIT_VAR(quality); ZVAL_LONG(quality, 100); } else { if (Z_TYPE_P(quality) != IS_LONG) { PHALCON_SEPARATE_PARAM(quality); convert_to_long(quality); } } PHALCON_RETURN_CALL_METHOD(this_ptr, "_render", ext, quality); RETURN_MM(); }
/** * Adds a number to a string or increment that number if it already is defined * *<code> * echo Phalcon\Text::increment("a"); // "a_1" * echo Phalcon\Text::increment("a_1"); // "a_2" *</code> * * @param string $str * @param string $separator * @return string */ PHP_METHOD(Phalcon_Text, increment) { zval *str, *separator = NULL, *parts, *number = NULL, *first_part; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &str, &separator); if (!separator) { PHALCON_INIT_VAR(separator); } else { PHALCON_SEPARATE_PARAM(separator); } if (Z_TYPE_P(separator) == IS_NULL) { PHALCON_INIT_NVAR(separator); ZVAL_STRING(separator, "_", 1); } PHALCON_INIT_VAR(parts); phalcon_fast_explode(parts, separator, str); if (phalcon_array_isset_long(parts, 1)) { PHALCON_OBS_VAR(number); phalcon_array_fetch_long(&number, parts, 1, PH_NOISY); SEPARATE_ZVAL(&number); phalcon_increment(number); } else { PHALCON_INIT_VAR(number); ZVAL_LONG(number, 1); } PHALCON_OBS_VAR(first_part); phalcon_array_fetch_long(&first_part, parts, 0, PH_NOISY); PHALCON_CONCAT_VVV(return_value, first_part, separator, number); RETURN_MM(); }
/** * Stores the messages in session * * @param array $messages */ PHP_METHOD(Phalcon_Flash_Session, _setSessionMessages){ zval *messages = NULL, *dependency_injector, *service; zval *session, *index_name; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &messages) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(messages); 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_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "session", 1); PHALCON_INIT_VAR(session); PHALCON_CALL_METHOD_PARAMS_1(session, dependency_injector, "getshared", service, PH_NO_CHECK); PHALCON_INIT_VAR(index_name); ZVAL_STRING(index_name, "_flashMessages", 1); PHALCON_INIT_VAR(r0); PHALCON_CALL_METHOD_PARAMS_2(r0, session, "set", index_name, messages, PH_NO_CHECK); PHALCON_CPY_WRT(messages, r0); RETURN_CCTOR(messages); }
/** * Transform an intermediate representation for a schema/table into a database system valid expression * * @param array $table * @param string $escapeChar * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, getSqlTable){ zval *table, *escape_char = NULL, *table_name, *sql_table = NULL; zval *schema_name, *sql_schema = NULL, *alias_name; zval *sql_table_alias = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &table, &escape_char); if (!escape_char) { PHALCON_INIT_VAR(escape_char); } else { PHALCON_SEPARATE_PARAM(escape_char); } if (Z_TYPE_P(escape_char) == IS_NULL) { PHALCON_OBS_NVAR(escape_char); phalcon_read_property_this(&escape_char, this_ptr, SL("_escapeChar"), PH_NOISY TSRMLS_CC); } if (Z_TYPE_P(table) == IS_ARRAY) { /** * The index '0' is the table name */ PHALCON_OBS_VAR(table_name); phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); if (PHALCON_GLOBAL(db).escape_identifiers) { PHALCON_INIT_VAR(sql_table); PHALCON_CONCAT_VVV(sql_table, escape_char, table_name, escape_char); } else { PHALCON_CPY_WRT(sql_table, table_name); } /** * The index '1' is the schema name */ PHALCON_OBS_VAR(schema_name); phalcon_array_fetch_long(&schema_name, table, 1, PH_NOISY); if (Z_TYPE_P(schema_name) != IS_NULL) { if (PHALCON_GLOBAL(db).escape_identifiers) { PHALCON_INIT_VAR(sql_schema); PHALCON_CONCAT_VVVSV(sql_schema, escape_char, schema_name, escape_char, ".", sql_table); } else { PHALCON_INIT_NVAR(sql_schema); PHALCON_CONCAT_VSV(sql_schema, schema_name, ".", sql_table); } } else { PHALCON_CPY_WRT(sql_schema, sql_table); } /** * The index '2' is the table alias */ if (phalcon_array_isset_long(table, 2)) { PHALCON_OBS_VAR(alias_name); phalcon_array_fetch_long(&alias_name, table, 2, PH_NOISY); if (PHALCON_GLOBAL(db).escape_identifiers) { PHALCON_INIT_VAR(sql_table_alias); PHALCON_CONCAT_VSVVV(sql_table_alias, sql_schema, " ", escape_char, alias_name, escape_char); } else { PHALCON_INIT_NVAR(sql_table_alias); PHALCON_CONCAT_VSV(sql_table_alias, sql_schema, " ", alias_name); } } else { PHALCON_CPY_WRT(sql_table_alias, sql_schema); } RETURN_CTOR(sql_table_alias); } if (PHALCON_GLOBAL(db).escape_identifiers) { PHALCON_INIT_NVAR(sql_table); PHALCON_CONCAT_VVV(sql_table, escape_char, table, escape_char); RETURN_CTOR(sql_table); } RETURN_CTOR(table); }