/** * Gets creation options from a table * * @param string $tableName * @param string $schemaName * @return array */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, tableOptions){ zval *table_name = NULL, *schema_name = NULL, *dialect = NULL, *sql = NULL; zval *describe = NULL, *first = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table_name, &schema_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema_name) { PHALCON_ALLOC_ZVAL_MM(schema_name); ZVAL_NULL(schema_name); } PHALCON_INIT_VAR(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "tableoptions", table_name, schema_name, PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_get_class_constant(t0, phalcon_db_ce, SL("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, t0, PH_NO_CHECK); PHALCON_INIT_VAR(first); phalcon_array_fetch_long(&first, describe, 0, PH_NOISY_CC); RETURN_CCTOR(first); }
/** * Generates SQL checking for the existence of a schema.table * * @param string $tableName * @param string $schemaName * @return string */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, tableExists){ zval *table_name = NULL, *schema_name = NULL, *sql = NULL, *num = NULL; zval *t0 = NULL, *t1 = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table_name, &schema_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema_name) { PHALCON_ALLOC_ZVAL_MM(schema_name); ZVAL_NULL(schema_name); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, t0, "tableexists", table_name, schema_name, PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_get_class_constant(t1, phalcon_db_ce, SL("FETCH_NUM") TSRMLS_CC); PHALCON_INIT_VAR(num); PHALCON_CALL_METHOD_PARAMS_2(num, this_ptr, "fetchone", sql, t1, PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_long(&r0, num, 0, PH_NOISY_CC); RETURN_CCTOR(r0); }
/** * Sanizites a value with a specified single or set of filters * * @param mixed $value * @param mixed $filters * @return mixed */ PHP_METHOD(Phalcon_Filter, sanitize){ zval *value, *filters, *new_value = NULL, *filter = NULL, *filter_value = NULL; zval *sanizited_value; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &value, &filters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(filters) == IS_ARRAY) { PHALCON_CPY_WRT(new_value, value); if (Z_TYPE_P(value) != IS_NULL) { if (!phalcon_valid_foreach(filters TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(filters); 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(filter); PHALCON_INIT_NVAR(filter_value); PHALCON_CALL_METHOD_PARAMS_2(filter_value, this_ptr, "_sanitize", new_value, filter, PH_NO_CHECK); PHALCON_CPY_WRT(new_value, filter_value); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: if(0){} } RETURN_CCTOR(new_value); } PHALCON_INIT_VAR(sanizited_value); PHALCON_CALL_METHOD_PARAMS_2(sanizited_value, this_ptr, "_sanitize", value, filters, PH_NO_CHECK); RETURN_CCTOR(sanizited_value); }
/** * Receives events generated in the models and dispatches them to a events-manager if available * Notify the behaviors that are listening in the model * * @param string $eventName * @param Phalcon\Mvc\CollectionInterface $model */ PHP_METHOD(Phalcon_Mvc_Collection_Manager, notifyEvent){ zval *event_name, *model, *status = NULL, *events_manager; zval *fire_event_name = NULL, *custom_events_manager; zval *entity_name; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &event_name, &model); PHALCON_INIT_VAR(status); /** * Dispatch events to the global events manager */ 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(fire_event_name); PHALCON_CONCAT_SV(fire_event_name, "collection:", event_name); PHALCON_CALL_METHOD_PARAMS_2(status, events_manager, "fire", fire_event_name, model); if (PHALCON_IS_FALSE(status)) { RETURN_CCTOR(status); } } /** * A model can has a specific events manager for it */ PHALCON_OBS_VAR(custom_events_manager); phalcon_read_property_this(&custom_events_manager, this_ptr, SL("_customEventsManager"), PH_NOISY_CC); if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { PHALCON_INIT_VAR(entity_name); phalcon_get_class(entity_name, model, 1 TSRMLS_CC); if (phalcon_array_isset(custom_events_manager, entity_name)) { PHALCON_INIT_NVAR(fire_event_name); PHALCON_CONCAT_SV(fire_event_name, "collection:", event_name); PHALCON_INIT_NVAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, custom_events_manager, "fire", fire_event_name, model); if (PHALCON_IS_FALSE(status)) { RETURN_CCTOR(status); } } } RETURN_CCTOR(status); }
/** * Generates SQL checking for the existence of a schema.table * * * * @param string $tableName * @param string $schemaName * @return string */ PHP_METHOD(Phalcon_Db_Adapter_Mysql, tableExists){ zval *table_name = NULL, *schema_name = NULL, *sql = NULL, *num = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table_name, &schema_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema_name) { PHALCON_INIT_VAR(schema_name); ZVAL_NULL(schema_name); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_STATIC_PARAMS_2(r0, "phalcon_db_dialect_mysql", "tableexists", table_name, schema_name); PHALCON_CPY_WRT(sql, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 2); PHALCON_CALL_METHOD_PARAMS_2(r1, this_ptr, "fetchone", sql, t0, PHALCON_NO_CHECK); PHALCON_CPY_WRT(num, r1); PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_long(&r2, num, 0, PHALCON_NOISY TSRMLS_CC); RETURN_CHECK_CTOR(r2); }
/** * Returns the translation string of the given key * * @param string $translateKey * @param array $placeholders * @return string */ PHP_METHOD(Phalcon_Translate, _){ zval *translate_key = NULL, *placeholders = NULL; zval *a0 = NULL; zval *r0 = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &translate_key, &placeholders) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!placeholders) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(placeholders, a0); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_adapter"), PHALCON_NOISY TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_2(r0, t0, "query", translate_key, placeholders, PHALCON_NO_CHECK); RETURN_DZVAL(r0); }
/** * Returns the reverse column map if any * *<code> * print_r($metaData->getReverseColumnMap(new Robots())); *</code> * * @param Phalcon\Mvc\ModelInterface $model * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, getReverseColumnMap){ zval *model, *index, *data; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &model) == FAILURE) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(index); ZVAL_LONG(index, 1); PHALCON_INIT_VAR(data); PHALCON_CALL_METHOD_PARAMS_2(data, this_ptr, "readcolumnmapindex", model, index); if (Z_TYPE_P(data) != IS_NULL) { if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupted"); return; } } RETURN_CCTOR(data); }
/** * Generates SQL describing a table * * * * @param string $table * @param string $schema * @return string */ PHP_METHOD(Phalcon_Db_Adapter_Mysql, describeTable){ zval *table = NULL, *schema = NULL, *sql = NULL, *describe = NULL; zval *r0 = NULL, *r1 = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema) { PHALCON_INIT_VAR(schema); ZVAL_NULL(schema); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_STATIC_PARAMS_2(r0, "phalcon_db_dialect_mysql", "describetable", table, schema); PHALCON_CPY_WRT(sql, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_CALL_METHOD_PARAMS_2(r1, this_ptr, "fetchall", sql, t0, PHALCON_NO_CHECK); PHALCON_CPY_WRT(describe, r1); RETURN_CHECK_CTOR(describe); }
/** * Renders a view using the template engine * * @param string $path * @param array $params */ PHP_METHOD(Phalcon_View_Engine_Mustache, render){ zval *path = NULL, *params = NULL; zval *t0 = NULL, *t1 = NULL; zval *r0 = NULL, *r1 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &path, ¶ms) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_zval(this_ptr, SL("_params"), params TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_view"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_mustache"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "file_get_contents", path); PHALCON_CALL_METHOD_PARAMS_2(r0, t1, "render", r1, this_ptr, PHALCON_NO_CHECK); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(t0, "setcontent", r0, PHALCON_NO_CHECK); PHALCON_MM_RESTORE(); }
/** * Starts a cache. The $keyname allows to identify the created fragment * * @param int|string $keyName * @param long $lifetime * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend, start){ zval *key_name, *lifetime = NULL, *existing_cache, *fresh = NULL; zval *frontend; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); if (!lifetime) { PHALCON_INIT_VAR(lifetime); } /** * Get the cache content verifying if it was expired */ PHALCON_INIT_VAR(existing_cache); PHALCON_CALL_METHOD_PARAMS_2(existing_cache, this_ptr, "get", key_name, lifetime); if (Z_TYPE_P(existing_cache) == IS_NULL) { PHALCON_INIT_VAR(fresh); ZVAL_BOOL(fresh, 1); PHALCON_OBS_VAR(frontend); phalcon_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); PHALCON_CALL_METHOD_NORETURN(frontend, "start"); } else { PHALCON_INIT_NVAR(fresh); ZVAL_BOOL(fresh, 0); } phalcon_update_property_this(this_ptr, SL("_fresh"), fresh TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); RETURN_CCTOR(existing_cache); }
/** * List all tables on a database * * * * @param string $schemaName * @return array */ PHP_METHOD(Phalcon_Db_Adapter_Mysql, listTables){ zval *schema_name = NULL, *sql = NULL, *tables = NULL, *all_tables = NULL, *table = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *t0 = NULL; zval *a0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &schema_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema_name) { PHALCON_INIT_VAR(schema_name); ZVAL_NULL(schema_name); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_STATIC_PARAMS_1(r0, "phalcon_db_dialect_mysql", "listtables", schema_name); PHALCON_CPY_WRT(sql, r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 2); PHALCON_CALL_METHOD_PARAMS_2(r1, this_ptr, "fetchall", sql, t0, PHALCON_NO_CHECK); PHALCON_CPY_WRT(tables, r1); PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(all_tables, a0); if (phalcon_valid_foreach(tables TSRMLS_CC)) { ah0 = Z_ARRVAL_P(tables); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_321f_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_321f_1; } PHALCON_INIT_VAR(table); ZVAL_ZVAL(table, *hd, 1, 0); PHALCON_INIT_VAR(r2); phalcon_array_fetch_long(&r2, table, 0, PHALCON_NOISY TSRMLS_CC); phalcon_array_append(&all_tables, r2, PHALCON_SEPARATE_PLZ TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_321f_1; fee_321f_1: if(0){} } else { return; } RETURN_CTOR(all_tables); }
/** * Sends/Writes messages to the file log * * @param string $message * @param int $type */ PHP_METHOD(Phalcon_Logger_Adapter_File, log){ zval *message = NULL, *type = NULL, *msg = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; zval *c0 = NULL; zval *i0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &message, &type) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } 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_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid"); return; } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_FUNC_PARAMS_1(r0, "is_scalar", message, 0x045); if (zend_is_true(r0)) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_INIT_VAR(c0); ZVAL_BOOL(c0, 1); PHALCON_CALL_FUNC_PARAMS_2(r1, "print_r", message, c0, 0x008); PHALCON_CPY_WRT(msg, r1); } PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_transaction", sizeof("_transaction")-1, PHALCON_NOISY TSRMLS_CC); if (zend_is_true(t1)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_logger_item_ce); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_FUNC(r2, "time", 0x018); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(i0, "__construct", message, type, r2, PHALCON_CHECK); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_quenue", sizeof("_quenue")-1, PHALCON_NOISY TSRMLS_CC); phalcon_array_append(&t2, i0, PHALCON_NO_SEPARATE_THX TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_quenue", strlen("_quenue"), t2 TSRMLS_CC); } else { PHALCON_ALLOC_ZVAL_MM(t3); phalcon_read_property(&t3, this_ptr, "_fileHandler", sizeof("_fileHandler")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD_PARAMS_2(r4, this_ptr, "_applyformat", message, type, PHALCON_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(t4); zend_get_constant("PHP_EOL", strlen("PHP_EOL"), t4 TSRMLS_CC); PHALCON_CONCAT_VV(r3, r4, t4); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("fputs", t3, r3, 0x04F); } PHALCON_MM_RESTORE(); }
/** * List all tables on a database * * @param string $schemaName * @return array */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, listTables){ zval *schema_name = NULL, *sql = NULL, *tables = NULL, *all_tables = NULL, *table = NULL; zval *t0 = NULL, *t1 = NULL; zval *r0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &schema_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema_name) { PHALCON_ALLOC_ZVAL_MM(schema_name); ZVAL_NULL(schema_name); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_1(sql, t0, "listtables", schema_name, PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_get_class_constant(t1, phalcon_db_ce, SL("FETCH_NUM") TSRMLS_CC); PHALCON_INIT_VAR(tables); PHALCON_CALL_METHOD_PARAMS_2(tables, this_ptr, "fetchall", sql, t1, PH_NO_CHECK); PHALCON_INIT_VAR(all_tables); array_init(all_tables); if (!phalcon_valid_foreach(tables TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(tables); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_7f5d_3: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_7f5d_3; } PHALCON_INIT_VAR(table); ZVAL_ZVAL(table, *hd, 1, 0); PHALCON_INIT_VAR(r0); phalcon_array_fetch_long(&r0, table, 0, PH_NOISY_CC); phalcon_array_append(&all_tables, r0, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_7f5d_3; fee_7f5d_3: if(0){} RETURN_CTOR(all_tables); }
/** * Gets variable from $_GET superglobal applying filters if needed * *<code> * //Returns value from $_GET["id"] without sanitizing * $id = $request->getQuery("id"); * * //Returns value from $_GET["id"] with sanitizing * $id = $request->getQuery("id", "int"); * * //Returns value from $_GET["id"] with a default value * $id = $request->getQuery("id", null, 150); *</code> * * @param string $name * @param string|array $filters * @param mixed $defaultValue * @return mixed */ PHP_METHOD(Phalcon_Http_Request, getQuery) { zval *name, *filters = NULL, *default_value = NULL, *value, *filter = NULL; zval *dependency_injector, *service, *sanitized_value; zval *g0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &name, &filters, &default_value) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!filters) { PHALCON_INIT_NVAR(filters); } if (!default_value) { PHALCON_INIT_NVAR(default_value); } phalcon_get_global(&g0, SL("_GET")+1 TSRMLS_CC); eval_int = phalcon_array_isset(g0, name); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch(&value, g0, name, PH_NOISY_CC); if (Z_TYPE_P(filters) != IS_NULL) { PHALCON_INIT_VAR(filter); phalcon_read_property(&filter, this_ptr, SL("_filter"), PH_NOISY_CC); if (Z_TYPE_P(filter) != IS_OBJECT) { 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_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "filter", 1); PHALCON_INIT_NVAR(filter); PHALCON_CALL_METHOD_PARAMS_1(filter, dependency_injector, "getshared", service, PH_NO_CHECK); phalcon_update_property_zval(this_ptr, SL("_filter"), filter TSRMLS_CC); } PHALCON_INIT_VAR(sanitized_value); PHALCON_CALL_METHOD_PARAMS_2(sanitized_value, filter, "sanitize", value, filters, PH_NO_CHECK); RETURN_CCTOR(sanitized_value); } else { RETURN_CCTOR(value); } } RETURN_CCTOR(default_value); }
/** * Adds a role to the ACL list. Second parameter allows inheriting access data from other existing role * * Example: * <code> * $acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultant'); * $acl->addRole('administrator', 'consultant'); * </code> * * @param Phalcon\Acl\RoleInterface $role * @param array|string $accessInherits * @return boolean */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){ zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL; zval *roles_names, *default_access, *_access; zval *success; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &role, &access_inherits) == FAILURE) { RETURN_MM_NULL(); } if (!access_inherits) { PHALCON_INIT_VAR(access_inherits); } if (Z_TYPE_P(role) == IS_OBJECT) { PHALCON_INIT_VAR(role_name); PHALCON_CALL_METHOD(role_name, role, "getname"); PHALCON_CPY_WRT(object, role); } else { PHALCON_CPY_WRT(role_name, role); PHALCON_INIT_VAR(object); object_init_ex(object, phalcon_acl_role_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(object, "__construct", role); } PHALCON_OBS_VAR(roles_names); phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC); if (phalcon_array_isset(roles_names, role_name)) { RETURN_MM_FALSE; } phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC); PHALCON_INIT_VAR(t0); ZVAL_BOOL(t0, 1); phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, t0 TSRMLS_CC); PHALCON_OBS_VAR(default_access); phalcon_read_property(&default_access, this_ptr, SL("_defaultAccess"), PH_NOISY_CC); PHALCON_OBS_VAR(_access); phalcon_read_property(&_access, this_ptr, SL("_access"), PH_NOISY_CC); phalcon_array_update_zval_string_string_multi_3(&_access, role_name, SL("*"), SL("*"), &default_access, 0 TSRMLS_CC); if (Z_TYPE_P(access_inherits) != IS_NULL) { PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD_PARAMS_2(success, this_ptr, "addinherit", role_name, access_inherits); RETURN_CCTOR(success); } RETURN_MM_TRUE; }
/** * Create internal connection to memcached */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, _connect){ zval *options, *memcache, *host, *port, *persistent; zval *success = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); PHALCON_OBS_VAR(options); phalcon_read_property(&options, this_ptr, SL("_options"), PH_NOISY_CC); ce0 = zend_fetch_class(SL("Memcache"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(memcache); object_init_ex(memcache, ce0); if (phalcon_has_constructor(memcache TSRMLS_CC)) { PHALCON_CALL_METHOD_NORETURN(memcache, "__construct"); } PHALCON_OBS_VAR(host); phalcon_array_fetch_string(&host, options, SL("host"), PH_NOISY_CC); PHALCON_OBS_VAR(port); phalcon_array_fetch_string(&port, options, SL("port"), PH_NOISY_CC); PHALCON_OBS_VAR(persistent); phalcon_array_fetch_string(&persistent, options, SL("persistent"), PH_NOISY_CC); if (zend_is_true(persistent)) { PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD_PARAMS_2(success, memcache, "pconnect", host, port); } else { PHALCON_INIT_NVAR(success); PHALCON_CALL_METHOD_PARAMS_2(success, memcache, "connect", host, port); } if (!zend_is_true(success)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cannot connect to Memcached server"); return; } phalcon_update_property_zval(this_ptr, SL("_memcache"), memcache TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Sends/Writes messages to the file log * * @param string $message * @param int $type */ PHP_METHOD(Phalcon_Logger_Adapter_File, log){ zval *message, *type = NULL, *file_handler, *transaction; zval *time, *quenue_item, *applied_format, *eol; zval *applied_eol; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &message, &type) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!type) { PHALCON_INIT_NVAR(type); ZVAL_LONG(type, 7); } PHALCON_INIT_VAR(file_handler); phalcon_read_property(&file_handler, this_ptr, SL("_fileHandler"), PH_NOISY_CC); if (!zend_is_true(file_handler)) { PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid"); return; } PHALCON_INIT_VAR(transaction); phalcon_read_property(&transaction, this_ptr, SL("_transaction"), PH_NOISY_CC); if (zend_is_true(transaction)) { PHALCON_INIT_VAR(time); PHALCON_CALL_FUNC(time, "time"); PHALCON_INIT_VAR(quenue_item); object_init_ex(quenue_item, phalcon_logger_item_ce); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(quenue_item, "__construct", message, type, time, PH_CHECK); PHALCON_INIT_VAR(t0); phalcon_read_property(&t0, this_ptr, SL("_quenue"), PH_NOISY_CC); phalcon_array_append(&t0, quenue_item, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_quenue"), t0 TSRMLS_CC); } else { PHALCON_INIT_VAR(applied_format); PHALCON_CALL_METHOD_PARAMS_2(applied_format, this_ptr, "_applyformat", message, type, PH_NO_CHECK); PHALCON_INIT_VAR(eol); zend_get_constant(SL("PHP_EOL"), eol TSRMLS_CC); PHALCON_INIT_VAR(applied_eol); PHALCON_CONCAT_VV(applied_eol, applied_format, eol); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("fwrite", file_handler, applied_eol); } PHALCON_MM_RESTORE(); }
/** * Gets variable from $_POST superglobal applying filters if needed * * @param string $name * @param string|array $filters * @return mixed */ PHP_METHOD(Phalcon_Http_Request, getPost){ zval *name = NULL, *filters = NULL, *value = NULL, *dependency_injector = NULL; zval *filter = NULL, *sanitized_value = NULL; zval *g0 = NULL; zval *c0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &name, &filters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!filters) { PHALCON_ALLOC_ZVAL_MM(filters); ZVAL_NULL(filters); } phalcon_get_global(&g0, SL("_POST")+1 TSRMLS_CC); eval_int = phalcon_array_isset(g0, name); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch(&value, g0, name, PH_NOISY_CC); if (zend_is_true(filters)) { 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_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "filter", 1); PHALCON_INIT_VAR(filter); PHALCON_CALL_METHOD_PARAMS_1(filter, dependency_injector, "getshared", c0, PH_NO_CHECK); PHALCON_INIT_VAR(sanitized_value); PHALCON_CALL_METHOD_PARAMS_2(sanitized_value, filter, "sanitize", value, filters, PH_NO_CHECK); RETURN_CCTOR(sanitized_value); } else { RETURN_CCTOR(value); } } PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Gets best language accepted by the browser/client from $_SERVER['HTTP_ACCEPT_LANGUAGE'] * * @return string */ PHP_METHOD(Phalcon_Request, getBestLanguage){ zval *r0 = NULL, *r1 = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, this_ptr, "getlanguages", PHALCON_NO_CHECK); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "language", 1); PHALCON_CALL_METHOD_PARAMS_2(r0, this_ptr, "_getbestquality", r1, c0, PHALCON_NO_CHECK); PHALCON_RETURN_DZVAL(r0); }
/** * Gets languages array and their quality accepted by the browser/client from $_SERVER['HTTP_ACCEPT_LANGUAGE'] * * @return array */ PHP_METHOD(Phalcon_Http_Request, getLanguages){ zval *c0 = NULL, *c1 = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "HTTP_ACCEPT_LANGUAGE", 1); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "language", 1); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD_PARAMS_2(r0, this_ptr, "_getqualityheader", c0, c1, PH_NO_CHECK); RETURN_CTOR(r0); }
/** * Gets charsets array and their quality accepted by the browser/client from $_SERVER['HTTP_ACCEPT_CHARSET'] * * @return array */ PHP_METHOD(Phalcon_Request, getClientCharsets){ zval *r0 = NULL; zval *c0 = NULL, *c1 = NULL; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "HTTP_ACCEPT_CHARSET", 1); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "charset", 1); PHALCON_CALL_METHOD_PARAMS_2(r0, this_ptr, "_getqualityheader", c0, c1, PHALCON_NO_CHECK); PHALCON_RETURN_DZVAL(r0); }
/** * Gets creation options from a table * *<code> * print_r($connection->tableOptions('robots')); *</code> * * @param string $tableName * @param string $schemaName * @return array */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, tableOptions){ zval *table_name, *schema_name = NULL, *dialect, *sql; zval *fetch_assoc, *describe, *first, *empty_arr; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table_name, &schema_name) == FAILURE) { RETURN_MM_NULL(); } if (!schema_name) { PHALCON_INIT_VAR(schema_name); } PHALCON_OBS_VAR(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "tableoptions", table_name, schema_name); if (zend_is_true(sql)) { PHALCON_INIT_VAR(fetch_assoc); phalcon_get_class_constant(fetch_assoc, phalcon_db_ce, SS("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_assoc); PHALCON_OBS_VAR(first); phalcon_array_fetch_long(&first, describe, 0, PH_NOISY_CC); RETURN_CCTOR(first); } PHALCON_INIT_VAR(empty_arr); array_init(empty_arr); RETURN_CTOR(empty_arr); }
/** * Gets charsets array and their quality accepted by the browser/client from $_SERVER['HTTP_ACCEPT_CHARSET'] * * @return array */ PHP_METHOD(Phalcon_Http_Request, getClientCharsets){ zval *quality_charset = NULL; zval *c0 = NULL, *c1 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "HTTP_ACCEPT_CHARSET", 1); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "charset", 1); PHALCON_INIT_VAR(quality_charset); PHALCON_CALL_METHOD_PARAMS_2(quality_charset, this_ptr, "_getqualityheader", c0, c1, PH_NO_CHECK); RETURN_CCTOR(quality_charset); }
/** * Gets array with mime/types and their quality accepted by the browser/client from $_SERVER['HTTP_ACCEPT'] * * @return array */ PHP_METHOD(Phalcon_Http_Request, getAcceptableContent){ zval *quality_header = NULL; zval *c0 = NULL, *c1 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "HTTP_ACCEPT", 1); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "accept", 1); PHALCON_INIT_VAR(quality_header); PHALCON_CALL_METHOD_PARAMS_2(quality_header, this_ptr, "_getqualityheader", c0, c1, PH_NO_CHECK); RETURN_CCTOR(quality_header); }
/** * Adds a resource to the ACL list * * Access names can be a particular action, by example * search, update, delete, etc or a list of them * * Example: * <code> * //Add a resource to the the list allowing access to an action * $acl->addResource(new Phalcon\Acl\Resource('customers'), 'search'); * $acl->addResource('customers', 'search'); * * //Add a resource with an access list * $acl->addResource(new Phalcon\Acl\Resource('customers'), array('create', 'search')); * $acl->addResource('customers', array('create', 'search')); * </code> * * @param Phalcon\Acl\Resource $resource * @param array $accessList * @return boolean */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){ zval *resource, *access_list = NULL, *resource_name = NULL; zval *object = NULL, *resources_names, *empty_arr, *status; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &resource, &access_list) == FAILURE) { RETURN_MM_NULL(); } if (!access_list) { PHALCON_INIT_VAR(access_list); } if (Z_TYPE_P(resource) == IS_OBJECT) { PHALCON_INIT_VAR(resource_name); PHALCON_CALL_METHOD(resource_name, resource, "getname"); PHALCON_CPY_WRT(object, resource); } else { PHALCON_CPY_WRT(resource_name, resource); PHALCON_INIT_VAR(object); object_init_ex(object, phalcon_acl_resource_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(object, "__construct", resource_name); } PHALCON_OBS_VAR(resources_names); phalcon_read_property(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY_CC); if (!phalcon_array_isset(resources_names, resource_name)) { phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC); PHALCON_INIT_VAR(empty_arr); array_init(empty_arr); phalcon_update_property_array(this_ptr, SL("_accessList"), resource_name, empty_arr TSRMLS_CC); PHALCON_INIT_VAR(t0); ZVAL_BOOL(t0, 1); phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, t0 TSRMLS_CC); } PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, this_ptr, "addresourceaccess", resource_name, access_list); RETURN_CCTOR(status); }
PHP_METHOD(Phalcon_Flash_Direct, message){ zval *type = NULL, *message = NULL, *flash_message = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &type, &message) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(flash_message); PHALCON_CALL_METHOD_PARAMS_2(flash_message, this_ptr, "outputmessage", type, message, PH_NO_CHECK); RETURN_CCTOR(flash_message); }
/** * Shows a HTML warning message * *<code> * $flash->warning('Hey, this is important'); *</code> * * @param string $message * @return string */ PHP_METHOD(Phalcon_Flash, warning){ zval *message, *type, *flash_message; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &message) == FAILURE) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(type); ZVAL_STRING(type, "warning", 1); PHALCON_INIT_VAR(flash_message); PHALCON_CALL_METHOD_PARAMS_2(flash_message, this_ptr, "message", type, message); RETURN_CCTOR(flash_message); }
/** * Gets best mime/type accepted by the browser/client from $_SERVER['HTTP_ACCEPT'] * * @return array */ PHP_METHOD(Phalcon_Http_Request, getBestAccept){ zval *acceptable_content = NULL, *best_quality = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(acceptable_content); PHALCON_CALL_METHOD(acceptable_content, this_ptr, "getacceptablecontent", PH_NO_CHECK); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "accept", 1); PHALCON_INIT_VAR(best_quality); PHALCON_CALL_METHOD_PARAMS_2(best_quality, this_ptr, "_getbestquality", acceptable_content, c0, PH_NO_CHECK); RETURN_CCTOR(best_quality); }
/** * Gets best charset accepted by the browser/client from $_SERVER['HTTP_ACCEPT_CHARSET'] * * @return string */ PHP_METHOD(Phalcon_Http_Request, getBestCharset){ zval *client_charsets = NULL, *best_charset = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(client_charsets); PHALCON_CALL_METHOD(client_charsets, this_ptr, "getclientcharsets", PH_NO_CHECK); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "charset", 1); PHALCON_INIT_VAR(best_charset); PHALCON_CALL_METHOD_PARAMS_2(best_charset, this_ptr, "_getbestquality", client_charsets, c0, PH_NO_CHECK); RETURN_CCTOR(best_charset); }
/** * Gets best language accepted by the browser/client from $_SERVER['HTTP_ACCEPT_LANGUAGE'] * * @return string */ PHP_METHOD(Phalcon_Http_Request, getBestLanguage){ zval *languages = NULL, *best_language = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(languages); PHALCON_CALL_METHOD(languages, this_ptr, "getlanguages", PH_NO_CHECK); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "language", 1); PHALCON_INIT_VAR(best_language); PHALCON_CALL_METHOD_PARAMS_2(best_language, this_ptr, "_getbestquality", languages, c0, PH_NO_CHECK); RETURN_CCTOR(best_language); }