/** * Sends the cookie to the HTTP client * Stores the cookie definition in session * * @return Phalcon\Http\Cookie */ PHP_METHOD(Phalcon_Http_Cookie, send){ zval *name, *value, *expire, *domain, *path, *secure; zval *http_only, *dependency_injector, *definition; zval *service = NULL, *session, *key, *encryption, *crypt; zval *encrypt_value = NULL, *has_session; PHALCON_MM_GROW(); PHALCON_OBS_VAR(name); phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); PHALCON_OBS_VAR(value); phalcon_read_property_this(&value, this_ptr, SL("_value"), PH_NOISY_CC); PHALCON_OBS_VAR(expire); phalcon_read_property_this(&expire, this_ptr, SL("_expire"), PH_NOISY_CC); PHALCON_OBS_VAR(domain); phalcon_read_property_this(&domain, this_ptr, SL("_domain"), PH_NOISY_CC); PHALCON_OBS_VAR(path); phalcon_read_property_this(&path, this_ptr, SL("_path"), PH_NOISY_CC); PHALCON_OBS_VAR(secure); phalcon_read_property_this(&secure, this_ptr, SL("_secure"), PH_NOISY_CC); PHALCON_OBS_VAR(http_only); phalcon_read_property_this(&http_only, this_ptr, SL("_httpOnly"), PH_NOISY_CC); 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_VAR(service); PHALCON_INIT_VAR(has_session); ZVAL_STRING(service, "session", 1); phalcon_call_method_p1(has_session, dependency_injector, "has", service); if (zend_is_true(has_session)) { PHALCON_INIT_VAR(definition); array_init(definition); if (!PHALCON_IS_LONG(expire, 0)) { phalcon_array_update_string(&definition, SL("expire"), &expire, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(path)) { phalcon_array_update_string(&definition, SL("path"), &path, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(domain)) { phalcon_array_update_string(&definition, SL("domain"), &domain, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(secure)) { phalcon_array_update_string(&definition, SL("secure"), &secure, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(http_only)) { phalcon_array_update_string(&definition, SL("httpOnly"), &http_only, PH_COPY); } /** * The definition is stored in session */ if (phalcon_fast_count_ev(definition TSRMLS_CC)) { PHALCON_INIT_VAR(session); phalcon_call_method_p1(session, dependency_injector, "getshared", service); if (Z_TYPE_P(session) != IS_NULL) { PHALCON_INIT_VAR(key); PHALCON_CONCAT_SV(key, "_PHCOOKIE_", name); phalcon_call_method_p2_noret(session, "set", key, definition); } } } } PHALCON_OBS_VAR(encryption); phalcon_read_property_this(&encryption, this_ptr, SL("_useEncryption"), PH_NOISY_CC); if (zend_is_true(encryption) && PHALCON_IS_NOT_EMPTY(value)) { if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } PHALCON_INIT_NVAR(service); ZVAL_STRING(service, "crypt", 1); PHALCON_INIT_VAR(crypt); phalcon_call_method_p1(crypt, dependency_injector, "getshared", service); /** * Encrypt the value also coding it with base64 */ PHALCON_INIT_VAR(encrypt_value); phalcon_call_method_p1(encrypt_value, crypt, "encryptbase64", value); } else { PHALCON_CPY_WRT(encrypt_value, value); } /** * Sets the cookie using the standard 'setcookie' function */ convert_to_string_ex(&name); convert_to_string_ex(&encrypt_value); convert_to_long_ex(&expire); convert_to_string_ex(&path); convert_to_string_ex(&domain); convert_to_long_ex(&secure); convert_to_long_ex(&http_only); php_setcookie( Z_STRVAL_P(name), Z_STRLEN_P(name), Z_STRVAL_P(encrypt_value), Z_STRLEN_P(encrypt_value), Z_LVAL_P(expire), Z_STRVAL_P(path), Z_STRLEN_P(path), Z_STRVAL_P(domain), Z_STRLEN_P(domain), Z_LVAL_P(secure), 1, Z_LVAL_P(http_only) TSRMLS_CC ); RETURN_THIS(); }
/** * Phalcon\DI\FactoryDefault constructor */ PHP_METHOD(Phalcon_DI_FactoryDefault, __construct){ zval *shared, *name = NULL, *definition = NULL, *router, *dispatcher; zval *url, *models_manager, *models_metadata; zval *response, *cookies, *request, *filter, *escaper; zval *annotations, *security, *crypt, *flash, *flash_session; zval *tag, *session, *session_bag, *events_manager; zval *transaction_manager, *assets, *services; PHALCON_MM_GROW(); PHALCON_CALL_PARENT_NORETURN(this_ptr, "Phalcon\\DI\\FactoryDefault", "__construct"); PHALCON_INIT_VAR(shared); ZVAL_BOOL(shared, 1); PHALCON_INIT_VAR(name); ZVAL_STRING(name, "router", 1); PHALCON_INIT_VAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Router", 1); PHALCON_INIT_VAR(router); object_init_ex(router, phalcon_di_service_ce); phalcon_call_method_p3_noret(router, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "dispatcher", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Dispatcher", 1); PHALCON_INIT_VAR(dispatcher); object_init_ex(dispatcher, phalcon_di_service_ce); phalcon_call_method_p3_noret(dispatcher, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "url", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Url", 1); PHALCON_INIT_VAR(url); object_init_ex(url, phalcon_di_service_ce); phalcon_call_method_p3_noret(url, "__construct", name, definition, shared); /** * Models manager for ORM */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "modelsManager", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Manager", 1); PHALCON_INIT_VAR(models_manager); object_init_ex(models_manager, phalcon_di_service_ce); phalcon_call_method_p3_noret(models_manager, "__construct", name, definition, shared); /** * Models meta-data using the Memory adapter */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "modelsMetadata", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\MetaData\\Memory", 1); PHALCON_INIT_VAR(models_metadata); object_init_ex(models_metadata, phalcon_di_service_ce); phalcon_call_method_p3_noret(models_metadata, "__construct", name, definition, shared); /** * Request/Response are always shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "response", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Http\\Response", 1); PHALCON_INIT_VAR(response); object_init_ex(response, phalcon_di_service_ce); phalcon_call_method_p3_noret(response, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "cookies", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Http\\Response\\Cookies", 1); PHALCON_INIT_VAR(cookies); object_init_ex(cookies, phalcon_di_service_ce); phalcon_call_method_p3_noret(cookies, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "request", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Http\\Request", 1); PHALCON_INIT_VAR(request); object_init_ex(request, phalcon_di_service_ce); phalcon_call_method_p3_noret(request, "__construct", name, definition, shared); /** * Filter/Escaper services are always shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "filter", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Filter", 1); PHALCON_INIT_VAR(filter); object_init_ex(filter, phalcon_di_service_ce); phalcon_call_method_p3_noret(filter, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "escaper", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Escaper", 1); PHALCON_INIT_VAR(escaper); object_init_ex(escaper, phalcon_di_service_ce); phalcon_call_method_p3_noret(escaper, "__construct", name, definition, shared); /** * Default annotations service */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "annotations", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Annotations\\Adapter\\Memory", 1); PHALCON_INIT_VAR(annotations); object_init_ex(annotations, phalcon_di_service_ce); phalcon_call_method_p3_noret(annotations, "__construct", name, definition, shared); /** * Security doesn't need to be shared, but anyways we register it as shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "security", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Security", 1); PHALCON_INIT_VAR(security); object_init_ex(security, phalcon_di_service_ce); phalcon_call_method_p3_noret(security, "__construct", name, definition, shared); /** * Crypt Service */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "crypt", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Crypt", 1); PHALCON_INIT_VAR(crypt); object_init_ex(crypt, phalcon_di_service_ce); phalcon_call_method_p3_noret(crypt, "__construct", name, definition, shared); /** * Flash services are always shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "flash", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Flash\\Direct", 1); PHALCON_INIT_VAR(flash); object_init_ex(flash, phalcon_di_service_ce); phalcon_call_method_p3_noret(flash, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "flashSession", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Flash\\Session", 1); PHALCON_INIT_VAR(flash_session); object_init_ex(flash_session, phalcon_di_service_ce); phalcon_call_method_p3_noret(flash_session, "__construct", name, definition, shared); /** * Tag/Helpers */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "tag", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Tag", 1); PHALCON_INIT_VAR(tag); object_init_ex(tag, phalcon_di_service_ce); phalcon_call_method_p3_noret(tag, "__construct", name, definition, shared); /** * Session is always shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "session", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Session\\Adapter\\Files", 1); PHALCON_INIT_VAR(session); object_init_ex(session, phalcon_di_service_ce); phalcon_call_method_p3_noret(session, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "sessionBag", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Session\\Bag", 1); PHALCON_INIT_VAR(session_bag); object_init_ex(session_bag, phalcon_di_service_ce); phalcon_call_method_p2_noret(session_bag, "__construct", name, definition); /** * Events Manager is always shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "eventsManager", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Events\\Manager", 1); PHALCON_INIT_VAR(events_manager); object_init_ex(events_manager, phalcon_di_service_ce); phalcon_call_method_p3_noret(events_manager, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "transactions", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Transaction\\Manager", 1); PHALCON_INIT_VAR(transaction_manager); object_init_ex(transaction_manager, phalcon_di_service_ce); phalcon_call_method_p3_noret(transaction_manager, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "assets", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Assets\\Manager", 1); PHALCON_INIT_VAR(assets); object_init_ex(assets, phalcon_di_service_ce); phalcon_call_method_p3_noret(assets, "__construct", name, definition, shared); /** * Register services */ PHALCON_INIT_VAR(services); array_init_size(services, 21); phalcon_array_update_string(&services, SL("router"), &router, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("dispatcher"), &dispatcher, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("url"), &url, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("modelsManager"), &models_manager, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("modelsMetadata"), &models_metadata, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("response"), &response, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("cookies"), &cookies, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("request"), &request, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("filter"), &filter, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("escaper"), &escaper, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("security"), &security, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("crypt"), &crypt, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("annotations"), &annotations, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("flash"), &flash, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("flashSession"), &flash_session, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("tag"), &tag, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("session"), &session, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("sessionBag"), &session_bag, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("eventsManager"), &events_manager, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("transactionManager"), &transaction_manager, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("assets"), &assets, PH_COPY | PH_SEPARATE TSRMLS_CC); /** * Update the internal services properties */ phalcon_update_property_this(this_ptr, SL("_services"), services TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Listens for notifications from the models manager * * @param string $type * @param Phalcon\Mvc\ModelInterface $model */ PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){ zval *type, *model, *options, *skip, *value, *field, *actual_value; zval *update_model, *status, *messages, *message = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &type, &model); if (PHALCON_IS_STRING(type, "beforeDelete")) { PHALCON_INIT_VAR(options); phalcon_call_method(options, this_ptr, "getoptions"); if (!phalcon_array_isset_string(options, SS("value"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'value' is required"); return; } if (!phalcon_array_isset_string(options, SS("field"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required"); return; } PHALCON_INIT_VAR(skip); ZVAL_BOOL(skip, 1); /** * Skip the current operation */ phalcon_call_method_p1_noret(model, "skipoperation", skip); /** * 'value' is the value to be updated instead of delete the record */ PHALCON_OBS_VAR(value); phalcon_array_fetch_string(&value, options, SL("value"), PH_NOISY_CC); /** * 'field' is the attribute to be updated instead of delete the record */ PHALCON_OBS_VAR(field); phalcon_array_fetch_string(&field, options, SL("field"), PH_NOISY_CC); PHALCON_INIT_VAR(actual_value); phalcon_call_method_p1(actual_value, model, "readattribute", field); /** * If the record is already flagged as 'deleted' we don't delete it again */ if (!PHALCON_IS_EQUAL(actual_value, value)) { /** * Clone the current model to make a clean new operation */ PHALCON_INIT_VAR(update_model); if (phalcon_clone(update_model, model TSRMLS_CC) == FAILURE) { return; } phalcon_call_method_p2_noret(update_model, "writeattribute", field, value); /** * Update the cloned model */ PHALCON_INIT_VAR(status); phalcon_call_method(status, update_model, "save"); if (!zend_is_true(status)) { /** * Transfer the messages from the cloned model to the original model */ PHALCON_INIT_VAR(messages); phalcon_call_method(messages, update_model, "getmessages"); phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(message); phalcon_call_method_p1_noret(model, "appendmessage", message); zend_hash_move_forward_ex(ah0, &hp0); } RETURN_MM_FALSE; } /** * Update the original model too */ phalcon_call_method_p2_noret(model, "writeattribute", field, value); } } PHALCON_MM_RESTORE(); }
/** * Commits the active transaction in the connection * * @param boolean $nesting * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; zval *event_name = NULL, *ntw_savepoint, *savepoint_name; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &nesting); if (!nesting) { PHALCON_INIT_VAR(nesting); ZVAL_BOOL(nesting, 1); } PHALCON_OBS_VAR(pdo); phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(pdo) != IS_OBJECT) { RETURN_MM_FALSE; } /** * Check the transaction nesting level */ PHALCON_OBS_VAR(transaction_level); phalcon_read_property_this(&transaction_level, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (!zend_is_true(transaction_level)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction"); return; } if (PHALCON_IS_LONG(transaction_level, 1)) { PHALCON_OBS_VAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); /** * Notify the events manager about the commited transaction */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "db:commitTransaction", 1); phalcon_call_method_p2_noret(events_manager, "fire", event_name, this_ptr); } /** * Reduce the transaction nesting level */ phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); phalcon_call_method(return_value, pdo, "commit"); RETURN_MM(); } else { if (zend_is_true(transaction_level)) { if (zend_is_true(nesting)) { /** * Check if the current database system supports nested transactions */ PHALCON_INIT_VAR(ntw_savepoint); phalcon_call_method(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints"); if (zend_is_true(ntw_savepoint)) { PHALCON_OBS_NVAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); PHALCON_INIT_VAR(savepoint_name); phalcon_call_method(savepoint_name, this_ptr, "getnestedtransactionsavepointname"); /** * Notify the events manager about the commited savepoint */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "db:releaseSavepoint", 1); phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, savepoint_name); } /** * Reduce the transaction nesting level */ phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); phalcon_call_method_p1(return_value, this_ptr, "releasesavepoint", savepoint_name); RETURN_MM(); } } } } /** * Reduce the transaction nesting level */ if (PHALCON_GT_LONG(transaction_level, 0)) { phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); } RETURN_MM_FALSE; }
/** * Phalcon\DI\FactoryDefault\CLI constructor */ PHP_METHOD(Phalcon_DI_FactoryDefault_CLI, __construct){ zval *shared, *name = NULL, *definition = NULL, *router, *dispatcher; zval *models_manager, *models_metadata, *filter; zval *escaper, *annotations, *security, *events_manager; zval *transaction_manager, *services; PHALCON_MM_GROW(); PHALCON_CALL_PARENT_NORETURN(this_ptr, "Phalcon\\DI\\FactoryDefault\\CLI", "__construct"); PHALCON_INIT_VAR(shared); ZVAL_BOOL(shared, 1); PHALCON_INIT_VAR(name); ZVAL_STRING(name, "router", 1); PHALCON_INIT_VAR(definition); ZVAL_STRING(definition, "Phalcon\\CLI\\Router", 1); PHALCON_INIT_VAR(router); object_init_ex(router, phalcon_di_service_ce); phalcon_call_method_p2_noret(router, "__construct", name, definition); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "dispatcher", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\CLI\\Dispatcher", 1); PHALCON_INIT_VAR(dispatcher); object_init_ex(dispatcher, phalcon_di_service_ce); phalcon_call_method_p2_noret(dispatcher, "__construct", name, definition); /** * Models manager for ORM */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "modelsManager", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Manager", 1); PHALCON_INIT_VAR(models_manager); object_init_ex(models_manager, phalcon_di_service_ce); phalcon_call_method_p2_noret(models_manager, "__construct", name, definition); /** * Models meta-data using the Memory adapter */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "modelsMetadata", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Metadata\\Memory", 1); PHALCON_INIT_VAR(models_metadata); object_init_ex(models_metadata, phalcon_di_service_ce); phalcon_call_method_p2_noret(models_metadata, "__construct", name, definition); /** * Filter/Escaper services are always shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "filter", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Filter", 1); PHALCON_INIT_VAR(filter); object_init_ex(filter, phalcon_di_service_ce); phalcon_call_method_p3_noret(filter, "__construct", name, definition, shared); PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "escaper", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Escaper", 1); PHALCON_INIT_VAR(escaper); object_init_ex(escaper, phalcon_di_service_ce); phalcon_call_method_p3_noret(escaper, "__construct", name, definition, shared); /** * Default annotations service */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "annotations", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Annotations\\Adapter\\Memory", 1); PHALCON_INIT_VAR(annotations); object_init_ex(annotations, phalcon_di_service_ce); phalcon_call_method_p3_noret(annotations, "__construct", name, definition, shared); /** * Security doesn't need to be shared, but anyways we register it as shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "security", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Security", 1); PHALCON_INIT_VAR(security); object_init_ex(security, phalcon_di_service_ce); phalcon_call_method_p3_noret(security, "__construct", name, definition, shared); /** * Events Manager is always shared */ PHALCON_INIT_NVAR(name); ZVAL_STRING(name, "eventsManager", 1); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Events\\Manager", 1); PHALCON_INIT_VAR(events_manager); object_init_ex(events_manager, phalcon_di_service_ce); phalcon_call_method_p3_noret(events_manager, "__construct", name, definition, shared); PHALCON_INIT_NVAR(definition); ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Transaction\\Manager", 1); PHALCON_INIT_VAR(transaction_manager); object_init_ex(transaction_manager, phalcon_di_service_ce); phalcon_call_method_p2_noret(transaction_manager, "__construct", name, definition); PHALCON_INIT_VAR(services); array_init_size(services, 10); phalcon_array_update_string(&services, SL("router"), &router, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("dispatcher"), &dispatcher, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("modelsManager"), &models_manager, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("modelsMetadata"), &models_metadata, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("filter"), &filter, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("escaper"), &escaper, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("annotations"), &annotations, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("security"), &security, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("eventsManager"), &events_manager, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&services, SL("transactionManager"), &transaction_manager, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_services"), services TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Renders a view * * @param string $path * @param array $params * @return string */ PHP_METHOD(Phalcon_Mvc_View_Simple, render){ zval *path, *params = NULL, *cache, *is_started = NULL, *key = NULL, *lifetime = NULL; zval *cache_options, *content = NULL, *view_params; zval *merged_params = NULL, *is_fresh; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &path, ¶ms); if (!params) { PHALCON_INIT_VAR(params); } /** * Create/Get a cache */ PHALCON_INIT_VAR(cache); phalcon_call_method(cache, this_ptr, "getcache"); if (Z_TYPE_P(cache) == IS_OBJECT) { /** * Check if the cache is started, the first time a cache is started we start the * cache */ PHALCON_INIT_VAR(is_started); phalcon_call_method(is_started, cache, "isstarted"); if (PHALCON_IS_FALSE(is_started)) { PHALCON_INIT_VAR(key); PHALCON_INIT_VAR(lifetime); PHALCON_OBS_VAR(cache_options); phalcon_read_property_this(&cache_options, this_ptr, SL("_cacheOptions"), PH_NOISY_CC); /** * Check if the user has defined a different options to the default */ if (Z_TYPE_P(cache_options) == IS_ARRAY) { if (phalcon_array_isset_string(cache_options, SS("key"))) { PHALCON_OBS_NVAR(key); phalcon_array_fetch_string(&key, cache_options, SL("key"), PH_NOISY); } if (phalcon_array_isset_string(cache_options, SS("lifetime"))) { PHALCON_OBS_NVAR(lifetime); phalcon_array_fetch_string(&lifetime, cache_options, SL("lifetime"), PH_NOISY); } } /** * If a cache key is not set we create one using a md5 */ if (Z_TYPE_P(key) == IS_NULL) { PHALCON_INIT_NVAR(key); phalcon_md5(key, path); } /** * We start the cache using the key set */ PHALCON_INIT_VAR(content); phalcon_call_method_p2(content, cache, "start", key, lifetime); if (Z_TYPE_P(content) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_content"), content TSRMLS_CC); RETURN_CCTOR(content); } } } /** * Create a virtual symbol table */ phalcon_create_symbol_table(TSRMLS_C); phalcon_ob_start(TSRMLS_C); PHALCON_OBS_VAR(view_params); phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); /** * Merge parameters */ if (Z_TYPE_P(params) == IS_ARRAY) { if (Z_TYPE_P(view_params) == IS_ARRAY) { PHALCON_INIT_VAR(merged_params); phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params, params); } } else { PHALCON_CPY_WRT(merged_params, view_params); } /** * internalRender is also reused by partials */ phalcon_call_method_p2_noret(this_ptr, "_internalrender", path, merged_params); /** * Store the data in output into the cache */ if (Z_TYPE_P(cache) == IS_OBJECT) { PHALCON_INIT_NVAR(is_started); phalcon_call_method(is_started, cache, "isstarted"); if (PHALCON_IS_TRUE(is_started)) { PHALCON_INIT_VAR(is_fresh); phalcon_call_method(is_fresh, cache, "isfresh"); if (PHALCON_IS_TRUE(is_fresh)) { phalcon_call_method_noret(cache, "save"); } else { phalcon_call_method_noret(cache, "stop"); } } else { phalcon_call_method_noret(cache, "stop"); } } phalcon_ob_end_clean(TSRMLS_C); PHALCON_OBS_NVAR(content); phalcon_read_property_this(&content, this_ptr, SL("_content"), PH_NOISY_CC); RETURN_CCTOR(content); }
/** * Restores the internal state of a Phalcon\Db\Column object * * @param array $data * @return \Phalcon\Db\Column */ PHP_METHOD(Phalcon_Db_Column, __set_state){ zval *data, *definition, *column_name, *column_type; zval *not_null, *primary, *size, *dunsigned, *after; zval *is_numeric, *first, *bind_type; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &data); if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column state must be an array"); return; } PHALCON_INIT_VAR(definition); array_init(definition); if (!phalcon_array_isset_string(data, SS("_columnName"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column name is required"); return; } PHALCON_OBS_VAR(column_name); phalcon_array_fetch_string(&column_name, data, SL("_columnName"), PH_NOISY); if (phalcon_array_isset_string(data, SS("_type"))) { PHALCON_OBS_VAR(column_type); phalcon_array_fetch_string(&column_type, data, SL("_type"), PH_NOISY); phalcon_array_update_string(&definition, SL("type"), &column_type, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_notNull"))) { PHALCON_OBS_VAR(not_null); phalcon_array_fetch_string(¬_null, data, SL("_notNull"), PH_NOISY); phalcon_array_update_string(&definition, SL("notNull"), ¬_null, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_primary"))) { PHALCON_OBS_VAR(primary); phalcon_array_fetch_string(&primary, data, SL("_primary"), PH_NOISY); phalcon_array_update_string(&definition, SL("primary"), &primary, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_size"))) { PHALCON_OBS_VAR(size); phalcon_array_fetch_string(&size, data, SL("_size"), PH_NOISY); phalcon_array_update_string(&definition, SL("size"), &size, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_unsigned"))) { PHALCON_OBS_VAR(dunsigned); phalcon_array_fetch_string(&dunsigned, data, SL("_unsigned"), PH_NOISY); phalcon_array_update_string(&definition, SL("unsigned"), &dunsigned, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_after"))) { PHALCON_OBS_VAR(after); phalcon_array_fetch_string(&after, data, SL("_after"), PH_NOISY); phalcon_array_update_string(&definition, SL("after"), &after, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_isNumeric"))) { PHALCON_OBS_VAR(is_numeric); phalcon_array_fetch_string(&is_numeric, data, SL("_isNumeric"), PH_NOISY); phalcon_array_update_string(&definition, SL("isNumeric"), &is_numeric, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_first"))) { PHALCON_OBS_VAR(first); phalcon_array_fetch_string(&first, data, SL("_first"), PH_NOISY); phalcon_array_update_string(&definition, SL("first"), &first, PH_COPY | PH_SEPARATE); } if (phalcon_array_isset_string(data, SS("_bindType"))) { PHALCON_OBS_VAR(bind_type); phalcon_array_fetch_string(&bind_type, data, SL("_bindType"), PH_NOISY); phalcon_array_update_string(&definition, SL("bindType"), &bind_type, PH_COPY | PH_SEPARATE); } object_init_ex(return_value, phalcon_db_column_ce); phalcon_call_method_p2_noret(return_value, "__construct", column_name, definition); RETURN_MM(); }
/** * Attach a listener to the events manager * * @param string $eventType * @param object|callable $handler * @param int $priority */ PHP_METHOD(Phalcon_Events_Manager, attach){ zval *event_type, *handler, *priority = NULL, *events = NULL; zval *enable_priorities, *priority_queue = NULL; zval *mode; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &event_type, &handler, &priority); if (!priority) { PHALCON_INIT_VAR(priority); ZVAL_LONG(priority, 100); } if (unlikely(Z_TYPE_P(event_type) != IS_STRING)) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event type must be a string"); return; } if (unlikely(Z_TYPE_P(handler) != IS_OBJECT)) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event handler must be an Object"); return; } PHALCON_OBS_VAR(events); phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); if (Z_TYPE_P(events) != IS_ARRAY) { PHALCON_INIT_NVAR(events); array_init(events); } if (!phalcon_array_isset(events, event_type)) { PHALCON_OBS_VAR(enable_priorities); phalcon_read_property_this(&enable_priorities, this_ptr, SL("_enablePriorities"), PH_NOISY_CC); if (zend_is_true(enable_priorities)) { /** * Create a SplPriorityQueue to store the events with priorities */ PHALCON_INIT_VAR(priority_queue); object_init_ex(priority_queue, spl_ce_SplPriorityQueue); if (phalcon_has_constructor(priority_queue TSRMLS_CC)) { phalcon_call_method_noret(priority_queue, "__construct"); } /** * Extract only the Data */ PHALCON_INIT_VAR(mode); ZVAL_LONG(mode, 1); /** * Set extraction flags */ phalcon_call_method_p1_noret(priority_queue, "setextractflags", mode); /** * Append the events to the queue */ phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); phalcon_update_property_this(this_ptr, SL("_events"), events TSRMLS_CC); } else { PHALCON_INIT_NVAR(priority_queue); array_init(priority_queue); } } else { /** * Get the current SplPriorityQueue */ PHALCON_OBS_NVAR(priority_queue); phalcon_array_fetch(&priority_queue, events, event_type, PH_NOISY); } /** * Insert the handler in the queue */ if (unlikely(Z_TYPE_P(priority_queue) == IS_OBJECT)) { phalcon_call_method_p2_noret(priority_queue, "insert", handler, priority); } else { phalcon_array_append(&priority_queue, handler, PH_SEPARATE); /** * Append the events to the queue */ phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); phalcon_update_property_this(this_ptr, SL("_events"), events TSRMLS_CC); } PHALCON_MM_RESTORE(); }
/** * 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; }
/** * Listens for notifications from the models manager * * @param string $type * @param Phalcon\Mvc\ModelInterface $model */ PHP_METHOD(Phalcon_Mvc_Model_Behavior_Timestampable, notify){ zval *type, *model, *take_action, *options, *timestamp = NULL; zval *format, *generator, *field, *single_field = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &type, &model); /** * Check if the developer decided to take action here */ PHALCON_INIT_VAR(take_action); phalcon_call_method_p1(take_action, this_ptr, "musttakeaction", type); if (PHALCON_IS_NOT_TRUE(take_action)) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(options); phalcon_call_method_p1(options, this_ptr, "getoptions", type); if (Z_TYPE_P(options) == IS_ARRAY) { /** * The field name is required in this behavior */ if (!phalcon_array_isset_string(options, SS("field"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required"); return; } PHALCON_INIT_VAR(timestamp); if (phalcon_array_isset_string(options, SS("format"))) { /** * Format is a format for date() */ PHALCON_OBS_VAR(format); phalcon_array_fetch_string(&format, options, SL("format"), PH_NOISY_CC); phalcon_call_func_p1(timestamp, "date", format); } else { if (phalcon_array_isset_string(options, SS("generator"))) { /** * A generator is a closure that produce the correct timestamp value */ PHALCON_OBS_VAR(generator); phalcon_array_fetch_string(&generator, options, SL("generator"), PH_NOISY_CC); if (Z_TYPE_P(generator) == IS_OBJECT) { if (phalcon_is_instance_of(generator, SL("Closure") TSRMLS_CC)) { PHALCON_INIT_NVAR(timestamp); PHALCON_CALL_USER_FUNC(timestamp, generator); } } } } /** * Last resort call time() */ if (Z_TYPE_P(timestamp) == IS_NULL) { PHALCON_INIT_NVAR(timestamp); ZVAL_LONG(timestamp, (long) time(NULL)); } PHALCON_OBS_VAR(field); phalcon_array_fetch_string(&field, options, SL("field"), PH_NOISY_CC); /** * Assign the value to the field, use writeattribute if the property is protected */ if (unlikely(Z_TYPE_P(field) == IS_ARRAY)) { phalcon_is_iterable(field, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(single_field); phalcon_call_method_p2_noret(model, "writeattribute", single_field, timestamp); zend_hash_move_forward_ex(ah0, &hp0); } } else { phalcon_call_method_p2_noret(model, "writeattribute", field, timestamp); } } PHALCON_MM_RESTORE(); }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * <code>print_r($connection->describeColumns("posts")); ?></code> * * @param string $table * @param string $schema * @return Phalcon\Db\Column[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){ zval *table, *schema = NULL, *columns, *dialect, *sql, *fetch_num; zval *describe, *old_column = NULL, *field = NULL, *definition = NULL; zval *column_size = NULL, *column_precision = NULL, *column_scale = NULL; zval *column_type = NULL, *attribute = NULL, *column_name = NULL; zval *column = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { PHALCON_INIT_VAR(schema); } PHALCON_INIT_VAR(columns); array_init(columns); PHALCON_OBS_VAR(dialect); phalcon_read_property_this(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); phalcon_call_method_p2(sql, dialect, "describecolumns", table, schema); /** * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); ZVAL_LONG(fetch_num, 3); PHALCON_INIT_VAR(describe); phalcon_call_method_p2(describe, this_ptr, "fetchall", sql, fetch_num); /** * 0:column_name, 1:data_type, 2:data_length, 3:data_precision, 4:data_scale, * 5:nullable, 6:constraint_type, 7:default, 8:position; */ PHALCON_INIT_VAR(old_column); phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(field); PHALCON_INIT_NVAR(definition); array_init_size(definition, 1); add_assoc_long_ex(definition, SS("bindType"), 2); PHALCON_OBS_NVAR(column_size); phalcon_array_fetch_long(&column_size, field, 2, PH_NOISY); PHALCON_OBS_NVAR(column_precision); phalcon_array_fetch_long(&column_precision, field, 3, PH_NOISY); PHALCON_OBS_NVAR(column_scale); phalcon_array_fetch_long(&column_scale, field, 4, PH_NOISY); PHALCON_OBS_NVAR(column_type); phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); /** * Check the column type to get the correct Phalcon type */ while (1) { /** * Integer */ if (phalcon_memnstr_str(column_type, SL("NUMBER"))) { phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); phalcon_array_update_string(&definition, SL("size"), &column_precision, PH_COPY | PH_SEPARATE); phalcon_array_update_string(&definition, SL("scale"), &column_scale, PH_COPY | PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); break; } /** * Tinyint(1) is boolean */ if (phalcon_memnstr_str(column_type, SL("TINYINT(1)"))) { phalcon_array_update_string_long(&definition, SL("type"), 8, PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_SEPARATE); break; } /** * Smallint/Bigint/Integers/Int are int */ if (phalcon_memnstr_str(column_type, SL("INTEGER"))) { phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); phalcon_array_update_string(&definition, SL("size"), &column_precision, PH_COPY | PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); break; } /** * Float/Smallfloats/Decimals are float */ if (phalcon_memnstr_str(column_type, SL("FLOAT"))) { phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE); phalcon_array_update_string(&definition, SL("scale"), &column_scale, PH_COPY | PH_SEPARATE); phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); break; } /** * Date */ if (phalcon_memnstr_str(column_type, SL("TIMESTAMP"))) { phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); break; } /** * Text */ if (phalcon_memnstr_str(column_type, SL("RAW"))) { phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); break; } /** * Text */ if (phalcon_memnstr_str(column_type, SL("BLOB"))) { phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); break; } /** * Text */ if (phalcon_memnstr_str(column_type, SL("CLOB"))) { phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); break; } /** * Chars2 are string */ if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) { phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE); break; } /** * Chars are chars */ if (phalcon_memnstr_str(column_type, SL("CHAR"))) { phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE); break; } /** * Text are varchars */ if (phalcon_memnstr_str(column_type, SL("text"))) { phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); break; } /** * By default is string */ phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); break; } if (Z_TYPE_P(old_column) == IS_NULL) { phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE); } else { phalcon_array_update_string(&definition, SL("after"), &old_column, PH_COPY | PH_SEPARATE); } /** * Check if the field is primary key */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); if (PHALCON_IS_STRING(attribute, "P")) { phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); } /** * Check if the column allows null values */ PHALCON_OBS_NVAR(attribute); phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); if (PHALCON_IS_STRING(attribute, "N")) { phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE); } PHALCON_OBS_NVAR(column_name); phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); /** * Create a Phalcon\Db\Column to abstract the column */ PHALCON_INIT_NVAR(column); object_init_ex(column, phalcon_db_column_ce); phalcon_call_method_p2_noret(column, "__construct", column_name, definition); phalcon_array_append(&columns, column, PH_SEPARATE); PHALCON_CPY_WRT(old_column, column_name); zend_hash_move_forward_ex(ah0, &hp0); } RETURN_CTOR(columns); }
/** * Appends a NOT IN condition to the current conditions * *<code> * $builder->notInWhere('id', [1, 2, 3]); *</code> * * @param string $expr * @param array $values * @return Phalcon\Mvc\Model\Query\Builder */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, notInWhere){ zval *expr, *values, *hidden_param, *bind_params; zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; zval *conditions; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &expr, &values); if (Z_TYPE_P(values) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Values must be an array"); return; } PHALCON_OBS_VAR(hidden_param); phalcon_read_property_this(&hidden_param, this_ptr, SL("_hiddenParamNumber"), PH_NOISY_CC); PHALCON_INIT_VAR(bind_params); array_init(bind_params); PHALCON_INIT_VAR(bind_keys); array_init(bind_keys); phalcon_is_iterable(values, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(value); /** * Key with auto bind-params */ PHALCON_INIT_NVAR(key); PHALCON_CONCAT_SV(key, "phi", hidden_param); PHALCON_INIT_NVAR(query_key); PHALCON_CONCAT_SVS(query_key, ":", key, ":"); phalcon_array_append(&bind_keys, query_key, PH_SEPARATE); phalcon_array_update_zval(&bind_params, key, &value, PH_COPY | PH_SEPARATE); PHALCON_SEPARATE(hidden_param); phalcon_increment(hidden_param); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(joined_keys); phalcon_fast_join_str(joined_keys, SL(", "), bind_keys TSRMLS_CC); /** * Create a standard IN condition with bind params */ PHALCON_INIT_VAR(conditions); PHALCON_CONCAT_VSVS(conditions, expr, " NOT IN (", joined_keys, ")"); /** * Append the IN to the current conditions using and 'and' */ phalcon_call_method_p2_noret(this_ptr, "andwhere", conditions, bind_params); phalcon_update_property_this(this_ptr, SL("_hiddenParamNumber"), hidden_param TSRMLS_CC); RETURN_THIS(); }
/** * Initialize the metadata for certain table * * @param Phalcon\Mvc\ModelInterface $model * @param string $key * @param string $table * @param string $schema */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initialize) { zval *model, *key, *table, *schema, *strategy = NULL, *class_name; zval *meta_data = NULL, *prefix_key = NULL, *data = NULL, *model_metadata = NULL; zval *exception_message, *dependency_injector = NULL; zval *key_name, *column_map = NULL, *model_column_map; PHALCON_MM_GROW(); phalcon_fetch_params(1, 4, 0, &model, &key, &table, &schema); PHALCON_INIT_VAR(strategy); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, model, 0 TSRMLS_CC); if (Z_TYPE_P(key) != IS_NULL) { PHALCON_OBS_VAR(meta_data); phalcon_read_property_this(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC); if (!phalcon_array_isset(meta_data, key)) { PHALCON_INIT_VAR(prefix_key); PHALCON_CONCAT_SV(prefix_key, "meta-", key); /** * The meta-data is read from the adapter always */ PHALCON_INIT_VAR(data); phalcon_call_method_p1(data, this_ptr, "read", prefix_key); if (Z_TYPE_P(data) != IS_NULL) { if (Z_TYPE_P(meta_data) != IS_ARRAY) { PHALCON_INIT_NVAR(meta_data); array_init(meta_data); } phalcon_array_update_zval(&meta_data, key, &data, PH_COPY | PH_SEPARATE); phalcon_update_property_this(this_ptr, SL("_metaData"), meta_data TSRMLS_CC); } else { /** * Check if there is a method 'metaData' in the model to retrieve meta-data from it */ if (phalcon_method_exists_ex(model, SS("metadata") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(model_metadata); phalcon_call_method(model_metadata, model, "metadata"); if (Z_TYPE_P(model_metadata) != IS_ARRAY) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "Invalid meta-data for model ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } } else { PHALCON_OBS_VAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); /** * Get the meta-data extraction strategy */ phalcon_call_method(strategy, this_ptr, "getstrategy"); /** * Get the meta-data */ PHALCON_INIT_NVAR(model_metadata); phalcon_call_method_p2(model_metadata, strategy, "getmetadata", model, dependency_injector); } /** * Store the meta-data locally */ phalcon_update_property_array(this_ptr, SL("_metaData"), key, model_metadata TSRMLS_CC); /** * Store the meta-data in the adapter */ phalcon_call_method_p2_noret(this_ptr, "write", prefix_key, model_metadata); } } } /** * Check for a column map, store in _columnMap in order and reversed order */ if (!PHALCON_GLOBAL(orm).column_renaming) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(key_name); phalcon_fast_strtolower(key_name, class_name); PHALCON_OBS_VAR(column_map); phalcon_read_property_this(&column_map, this_ptr, SL("_columnMap"), PH_NOISY_CC); if (phalcon_array_isset(column_map, key_name)) { RETURN_MM_NULL(); } if (Z_TYPE_P(column_map) != IS_ARRAY) { PHALCON_INIT_NVAR(column_map); array_init(column_map); } /** * Create the map key name */ PHALCON_INIT_NVAR(prefix_key); PHALCON_CONCAT_SV(prefix_key, "map-", key_name); /** * Check if the meta-data is already in the adapter */ PHALCON_INIT_NVAR(data); phalcon_call_method_p1(data, this_ptr, "read", prefix_key); if (Z_TYPE_P(data) != IS_NULL) { phalcon_array_update_zval(&column_map, key_name, &data, PH_COPY | PH_SEPARATE); phalcon_update_property_this(this_ptr, SL("_columnMap"), column_map TSRMLS_CC); RETURN_MM_NULL(); } /** * Get the meta-data extraction strategy */ if (Z_TYPE_P(strategy) != IS_OBJECT) { PHALCON_OBS_NVAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); PHALCON_INIT_NVAR(strategy); phalcon_call_method(strategy, this_ptr, "getstrategy"); } /** * Get the meta-data */ PHALCON_INIT_VAR(model_column_map); phalcon_call_method_p2(model_column_map, strategy, "getcolumnmaps", model, dependency_injector); /** * Update the column map locally */ phalcon_update_property_array(this_ptr, SL("_columnMap"), key_name, model_column_map TSRMLS_CC); /** * Write the data to the adapter */ phalcon_call_method_p2_noret(this_ptr, "write", prefix_key, model_column_map); PHALCON_MM_RESTORE(); }
/** * Stores cached content into the Memcached backend and stops the frontend * * @param int|string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *last_key = NULL, *prefix, *frontend, *memcache = NULL, *cached_content = NULL; zval *prepared_content, *ttl = NULL, *flags, *success; zval *options, *special_key, *keys = NULL, *is_buffering; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name) { PHALCON_INIT_VAR(key_name); } if (!content) { PHALCON_INIT_VAR(content); } if (!lifetime) { PHALCON_INIT_VAR(lifetime); } if (!stop_buffer) { PHALCON_INIT_VAR(stop_buffer); ZVAL_BOOL(stop_buffer, 1); } if (Z_TYPE_P(key_name) == IS_NULL) { PHALCON_OBS_VAR(last_key); phalcon_read_property_this(&last_key, this_ptr, SL("_lastKey"), PH_NOISY_CC); } else { PHALCON_OBS_VAR(prefix); phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC); PHALCON_INIT_NVAR(last_key); PHALCON_CONCAT_VV(last_key, prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } PHALCON_OBS_VAR(frontend); phalcon_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); /** * Check if a connection is created or make a new one */ PHALCON_OBS_VAR(memcache); phalcon_read_property_this(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC); if (Z_TYPE_P(memcache) != IS_OBJECT) { phalcon_call_method_noret(this_ptr, "_connect"); PHALCON_OBS_NVAR(memcache); phalcon_read_property_this(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC); } if (Z_TYPE_P(content) == IS_NULL) { PHALCON_INIT_VAR(cached_content); phalcon_call_method(cached_content, frontend, "getcontent"); } else { PHALCON_CPY_WRT(cached_content, content); } /** * Prepare the content in the frontend */ PHALCON_INIT_VAR(prepared_content); phalcon_call_method_p1(prepared_content, frontend, "beforestore", cached_content); if (Z_TYPE_P(lifetime) == IS_NULL) { PHALCON_INIT_VAR(ttl); phalcon_call_method(ttl, frontend, "getlifetime"); } else { PHALCON_CPY_WRT(ttl, lifetime); } PHALCON_INIT_VAR(flags); ZVAL_LONG(flags, 0); /** * We store without flags */ PHALCON_INIT_VAR(success); phalcon_call_method_p4(success, memcache, "set", last_key, prepared_content, flags, ttl); if (!zend_is_true(success)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Failed storing data in memcached"); return; } PHALCON_OBS_VAR(options); phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); PHALCON_OBS_VAR(special_key); phalcon_array_fetch_string(&special_key, options, SL("statsKey"), PH_NOISY); /** * Update the stats key */ PHALCON_INIT_VAR(keys); phalcon_call_method_p1(keys, memcache, "get", special_key); if (Z_TYPE_P(keys) != IS_ARRAY) { PHALCON_INIT_NVAR(keys); array_init(keys); } if (!phalcon_array_isset(keys, last_key)) { phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); phalcon_call_method_p2_noret(memcache, "set", special_key, keys); } PHALCON_INIT_VAR(is_buffering); phalcon_call_method(is_buffering, frontend, "isbuffering"); if (PHALCON_IS_TRUE(stop_buffer)) { phalcon_call_method_noret(frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Loads registered template engines, if none is registered it will use Phalcon\Mvc\View\Engine\Php * * @return array */ PHP_METHOD(Phalcon_Mvc_View_Simple, _loadTemplateEngines){ zval *engines = NULL, *dependency_injector, *registered_engines; zval *php_engine, *arguments, *engine_service = NULL; zval *extension = NULL, *engine_object = NULL, *exception_message = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); PHALCON_OBS_VAR(engines); phalcon_read_property_this(&engines, this_ptr, SL("_engines"), PH_NOISY_CC); /** * If the engines aren't initialized 'engines' is false */ if (PHALCON_IS_FALSE(engines)) { PHALCON_OBS_VAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); PHALCON_INIT_NVAR(engines); array_init(engines); PHALCON_OBS_VAR(registered_engines); phalcon_read_property_this(®istered_engines, this_ptr, SL("_registeredEngines"), PH_NOISY_CC); if (Z_TYPE_P(registered_engines) != IS_ARRAY) { /** * We use Phalcon\Mvc\View\Engine\Php as default */ PHALCON_INIT_VAR(php_engine); object_init_ex(php_engine, phalcon_mvc_view_engine_php_ce); phalcon_call_method_p2_noret(php_engine, "__construct", this_ptr, dependency_injector); /** * Use .phtml as extension for the PHP engine */ phalcon_array_update_string(&engines, SL(".phtml"), &php_engine, PH_COPY | PH_SEPARATE); } else { if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the application services"); return; } /** * Arguments for instantiated engines */ PHALCON_INIT_VAR(arguments); array_init_size(arguments, 2); phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); phalcon_array_append(&arguments, dependency_injector, PH_SEPARATE); phalcon_is_iterable(registered_engines, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(extension, ah0, hp0); PHALCON_GET_HVALUE(engine_service); if (Z_TYPE_P(engine_service) == IS_OBJECT) { /** * Engine can be a closure */ if (phalcon_is_instance_of(engine_service, SL("Closure") TSRMLS_CC)) { PHALCON_INIT_NVAR(engine_object); PHALCON_CALL_USER_FUNC_ARRAY(engine_object, engine_service, arguments); } else { PHALCON_CPY_WRT(engine_object, engine_service); } } else { /** * Engine can be a string representing a service in the DI */ if (Z_TYPE_P(engine_service) == IS_STRING) { PHALCON_INIT_NVAR(engine_object); phalcon_call_method_p2(engine_object, dependency_injector, "getshared", engine_service, arguments); } else { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SV(exception_message, "Invalid template engine registration for extension: ", extension); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); return; } } phalcon_array_update_zval(&engines, extension, &engine_object, PH_COPY | PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } } phalcon_update_property_this(this_ptr, SL("_engines"), engines TSRMLS_CC); } else { PHALCON_OBS_NVAR(engines); phalcon_read_property_this(&engines, this_ptr, SL("_engines"), PH_NOISY_CC); } RETURN_CCTOR(engines); }
/** * Executes a prepared statement binding. This function uses integer indexes starting from zero * *<code> * $statement = $db->prepare('SELECT * FROM robots WHERE name = :name'); * $result = $connection->executePrepared($statement, array('name' => 'Voltron')); *</code> * * @param \PDOStatement $statement * @param array $placeholders * @param array $dataTypes * @return \PDOStatement */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared){ zval *statement = NULL, *placeholders = NULL, *data_types = NULL; zval *one, *value = NULL, *wildcard = NULL, *parameter = NULL, *type = NULL, *cast_value = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &statement, &placeholders, &data_types) == FAILURE) { RETURN_MM_NULL(); } PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); if (!phalcon_is_iterable_ex(placeholders, &ah0, &hp0, 0, 0)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(wildcard, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(wildcard) == IS_LONG) { PHALCON_INIT_NVAR(parameter); phalcon_add_function(parameter, wildcard, one TSRMLS_CC); } else { if (Z_TYPE_P(wildcard) == IS_STRING) { PHALCON_CPY_WRT(parameter, wildcard); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind parameter"); return; } } if (Z_TYPE_P(data_types) == IS_ARRAY) { if (likely(phalcon_array_isset(data_types, wildcard))) { /** * The bind type is double so we try to get the double value */ PHALCON_OBS_NVAR(type); phalcon_array_fetch(&type, data_types, wildcard, PH_NOISY); if (phalcon_compare_strict_long(type, 32 TSRMLS_CC)) { PHALCON_INIT_NVAR(cast_value); phalcon_cast(cast_value, value, IS_DOUBLE); PHALCON_INIT_NVAR(type); ZVAL_LONG(type, 1024); } else { PHALCON_CPY_WRT(cast_value, value); } /** * 1024 is ignore the bind type */ Z_SET_ISREF_P(cast_value); if (phalcon_compare_strict_long(type, 1024 TSRMLS_CC)) { phalcon_call_method_p2_noret(statement, "bindparam", parameter, cast_value); } else { phalcon_call_method_p3_noret(statement, "bindparam", parameter, cast_value, type); } Z_UNSET_ISREF_P(cast_value); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind type parameter"); return; } } else { Z_SET_ISREF_P(value); phalcon_call_method_p2_noret(statement, "bindparam", parameter, value); Z_UNSET_ISREF_P(value); } zend_hash_move_forward_ex(ah0, &hp0); } phalcon_call_method_noret(statement, "execute"); RETURN_CCTOR(statement); }
/** * Tries to render the view with every engine registered in the component * * @param string $path * @param array $params */ PHP_METHOD(Phalcon_Mvc_View_Simple, _internalRender){ zval *path, *params, *events_manager, *event_name = NULL; zval *status = NULL, *not_exists = NULL, *must_clean, *views_dir; zval *views_dir_path, *engines, *engine = NULL, *extension = NULL; zval *view_engine_path = NULL, *exception_message; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &path, ¶ms); 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_update_property_this(this_ptr, SL("_activeRenderPath"), path TSRMLS_CC); } /** * Call beforeRender if there is an events manager */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:beforeRender", 1); PHALCON_INIT_VAR(status); phalcon_call_method_p2(status, events_manager, "fire", event_name, this_ptr); if (PHALCON_IS_FALSE(status)) { RETURN_MM_NULL(); } } PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 1); PHALCON_INIT_VAR(must_clean); ZVAL_BOOL(must_clean, 1); PHALCON_OBS_VAR(views_dir); phalcon_read_property_this(&views_dir, this_ptr, SL("_viewsDir"), PH_NOISY_CC); PHALCON_INIT_VAR(views_dir_path); PHALCON_CONCAT_VV(views_dir_path, views_dir, path); /** * Load the template engines */ PHALCON_INIT_VAR(engines); phalcon_call_method(engines, this_ptr, "_loadtemplateengines"); /** * Views are rendered in each engine */ phalcon_is_iterable(engines, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(extension, ah0, hp0); PHALCON_GET_HVALUE(engine); PHALCON_INIT_NVAR(view_engine_path); PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { /** * Call beforeRenderView if there is a events manager available */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "view:beforeRenderView", 1); PHALCON_INIT_NVAR(status); phalcon_call_method_p3(status, events_manager, "fire", event_name, this_ptr, view_engine_path); if (PHALCON_IS_FALSE(status)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } } phalcon_call_method_p3_noret(engine, "render", view_engine_path, params, must_clean); /** * Call afterRenderView if there is a events manager available */ PHALCON_INIT_NVAR(not_exists); ZVAL_BOOL(not_exists, 0); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "view:afterRenderView", 1); phalcon_call_method_p2_noret(events_manager, "fire", event_name, this_ptr); } break; } zend_hash_move_forward_ex(ah0, &hp0); } /** * Always throw an exception if the view does not exist */ if (PHALCON_IS_TRUE(not_exists)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); return; } /** * Call afterRender event */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "view:afterRender", 1); phalcon_call_method_p2_noret(events_manager, "fire", event_name, this_ptr); } PHALCON_MM_RESTORE(); }
/** * Starts a transaction in the connection * * @param boolean $nesting * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; zval *event_name = NULL, *ntw_savepoint, *savepoint_name; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &nesting); if (!nesting) { PHALCON_INIT_VAR(nesting); ZVAL_BOOL(nesting, 1); } PHALCON_OBS_VAR(pdo); phalcon_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(pdo) != IS_OBJECT) { RETURN_MM_FALSE; } /** * Increase the transaction nesting level */ phalcon_property_incr(this_ptr, SL("_transactionLevel") TSRMLS_CC); /** * Check the transaction nesting level */ PHALCON_OBS_VAR(transaction_level); phalcon_read_property_this(&transaction_level, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (PHALCON_IS_LONG(transaction_level, 1)) { PHALCON_OBS_VAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); /** * Notify the events manager about the started transaction */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "db:beginTransaction", 1); phalcon_call_method_p2_noret(events_manager, "fire", event_name, this_ptr); } phalcon_call_method(return_value, pdo, "begintransaction"); RETURN_MM(); } else { if (zend_is_true(transaction_level)) { if (zend_is_true(nesting)) { PHALCON_INIT_VAR(ntw_savepoint); phalcon_call_method(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints"); if (zend_is_true(ntw_savepoint)) { PHALCON_OBS_NVAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); PHALCON_INIT_VAR(savepoint_name); phalcon_call_method(savepoint_name, this_ptr, "getnestedtransactionsavepointname"); /** * Notify the events manager about the created savepoint */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "db:createSavepoint", 1); phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, savepoint_name); } phalcon_call_method_p1(return_value, this_ptr, "createsavepoint", savepoint_name); RETURN_MM(); } } } } RETURN_MM_FALSE; }
/** * Renders a partial view * * <code> * //Show a partial inside another view * $this->partial('shared/footer'); * </code> * * <code> * //Show a partial inside another view with parameters * $this->partial('shared/footer', array('content' => $html)); * </code> * * @param string $partialPath * @param array $params */ PHP_METHOD(Phalcon_Mvc_View_Simple, partial){ zval *partial_path, *params = NULL, *view_params = NULL, *merged_params = NULL; zval *content; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); if (!params) { PHALCON_INIT_VAR(params); } /** * Start ouput buffering */ phalcon_ob_start(TSRMLS_C); /** * If the developer pass an array of variables we create a new virtual symbol table */ if (Z_TYPE_P(params) == IS_ARRAY) { PHALCON_OBS_VAR(view_params); phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); /** * Merge or assign the new params as parameters */ if (Z_TYPE_P(view_params) == IS_ARRAY) { PHALCON_INIT_VAR(merged_params); phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params, params); } /** * Create a virtual symbol table */ phalcon_create_symbol_table(TSRMLS_C); } else { PHALCON_CPY_WRT(merged_params, params); } /** * Call engine render, this checks in every registered engine for the partial */ phalcon_call_method_p2_noret(this_ptr, "_internalrender", partial_path, merged_params); /** * Now we need to restore the original view parameters */ if (view_params != NULL) { /** * Restore the original view params */ phalcon_update_property_this(this_ptr, SL("_viewParams"), view_params TSRMLS_CC); } phalcon_ob_end_clean(TSRMLS_C); PHALCON_OBS_VAR(content); phalcon_read_property_this(&content, this_ptr, SL("_content"), PH_NOISY_CC); /** * Content is output to the parent view */ zend_print_zval(content, 0); PHALCON_MM_RESTORE(); }
/** * Produce the routing parameters from the rewrite information * * @param string $uri */ PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ zval *uri = NULL, *real_uri = NULL, *processed, *annotations_service = NULL; zval *handlers, *controller_suffix, *scope = NULL, *prefix = NULL; zval *dependency_injector = NULL, *service = NULL, *handler = NULL; zval *controller_name = NULL; zval *namespace_name = NULL, *module_name = NULL, *suffixed = NULL; zval *handler_annotations = NULL, *class_annotations = NULL; zval *annotations = NULL, *annotation = NULL, *method_annotations = NULL; zval *collection = NULL, *method = NULL; HashTable *ah0, *ah1, *ah2, *ah3; HashPosition hp0, hp1, hp2, hp3; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &uri); if (!uri) { PHALCON_INIT_VAR(uri); } if (!zend_is_true(uri)) { /** * If 'uri' isn't passed as parameter it reads $_GET['_url'] */ PHALCON_INIT_VAR(real_uri); phalcon_call_method(real_uri, this_ptr, "getrewriteuri"); } else { PHALCON_CPY_WRT(real_uri, uri); } PHALCON_OBS_VAR(processed); phalcon_read_property_this(&processed, this_ptr, SL("_processed"), PH_NOISY_CC); if (!zend_is_true(processed)) { PHALCON_INIT_VAR(annotations_service); PHALCON_OBS_VAR(handlers); phalcon_read_property_this(&handlers, this_ptr, SL("_handlers"), PH_NOISY_CC); if (Z_TYPE_P(handlers) == IS_ARRAY) { PHALCON_OBS_VAR(controller_suffix); phalcon_read_property_this(&controller_suffix, this_ptr, SL("_controllerSuffix"), PH_NOISY_CC); phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(scope); if (Z_TYPE_P(scope) == IS_ARRAY) { /** * A prefix (if any) must be in position 0 */ PHALCON_OBS_NVAR(prefix); phalcon_array_fetch_long(&prefix, scope, 0, PH_NOISY); if (Z_TYPE_P(prefix) == IS_STRING) { if (!phalcon_start_with(real_uri, prefix, NULL)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } } if (Z_TYPE_P(annotations_service) != IS_OBJECT) { PHALCON_OBS_NVAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "A dependency injection container is required to access the 'annotations' service"); return; } PHALCON_INIT_NVAR(service); ZVAL_STRING(service, "annotations", 1); PHALCON_INIT_NVAR(annotations_service); phalcon_call_method_p1(annotations_service, dependency_injector, "getshared", service); } /** * The controller must be in position 1 */ PHALCON_OBS_NVAR(handler); phalcon_array_fetch_long(&handler, scope, 1, PH_NOISY); if (phalcon_memnstr_str(handler, SL("\\"))) { /** * Extract the real class name from the namespaced class */ PHALCON_INIT_NVAR(controller_name); phalcon_get_class_ns(controller_name, handler, 0 TSRMLS_CC); /** * Extract the namespace from the namespaced class */ PHALCON_INIT_NVAR(namespace_name); phalcon_get_ns_class(namespace_name, handler, 0 TSRMLS_CC); } else { PHALCON_CPY_WRT(controller_name, handler); PHALCON_INIT_NVAR(namespace_name); } phalcon_update_property_null(this_ptr, SL("_routePrefix") TSRMLS_CC); /** * Check if the scope has a module associated */ if (phalcon_array_isset_long(scope, 2)) { PHALCON_OBS_NVAR(module_name); phalcon_array_fetch_long(&module_name, scope, 2, PH_NOISY); } else { PHALCON_INIT_NVAR(module_name); } PHALCON_INIT_NVAR(suffixed); PHALCON_CONCAT_VV(suffixed, handler, controller_suffix); /** * Get the annotations from the class */ PHALCON_INIT_NVAR(handler_annotations); phalcon_call_method_p1(handler_annotations, annotations_service, "get", suffixed); /** * Process class annotations */ PHALCON_INIT_NVAR(class_annotations); phalcon_call_method(class_annotations, handler_annotations, "getclassannotations"); if (Z_TYPE_P(class_annotations) == IS_OBJECT) { /** * Process class annotations */ PHALCON_INIT_NVAR(annotations); phalcon_call_method(annotations, class_annotations, "getannotations"); if (Z_TYPE_P(annotations) == IS_ARRAY) { phalcon_is_iterable(annotations, &ah1, &hp1, 0, 0); while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_HVALUE(annotation); phalcon_call_method_p2_noret(this_ptr, "processcontrollerannotation", controller_name, annotation); zend_hash_move_forward_ex(ah1, &hp1); } } } /** * Process method annotations */ PHALCON_INIT_NVAR(method_annotations); phalcon_call_method(method_annotations, handler_annotations, "getmethodsannotations"); if (Z_TYPE_P(method_annotations) == IS_ARRAY) { phalcon_is_iterable(method_annotations, &ah2, &hp2, 0, 0); while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_HKEY(method, ah2, hp2); PHALCON_GET_HVALUE(collection); if (Z_TYPE_P(collection) == IS_OBJECT) { PHALCON_INIT_NVAR(annotations); phalcon_call_method(annotations, collection, "getannotations"); phalcon_is_iterable(annotations, &ah3, &hp3, 0, 0); while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { PHALCON_GET_HVALUE(annotation); phalcon_call_method_p5_noret(this_ptr, "processactionannotation", module_name, namespace_name, controller_name, method, annotation); zend_hash_move_forward_ex(ah3, &hp3); } } zend_hash_move_forward_ex(ah2, &hp2); } } } zend_hash_move_forward_ex(ah0, &hp0); } } phalcon_update_property_bool(this_ptr, SL("_processed"), 1 TSRMLS_CC); } /** * Call the parent handle method() */ PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Router\\Annotations", "handle", real_uri); PHALCON_MM_RESTORE(); }