|
cutelyst 3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
The Cutelyst Application. More...
#include <Cutelyst/Application>

Signals | |
| void | afterDispatch (Cutelyst::Context *c) |
| void | beforeDispatch (Cutelyst::Context *c) |
| void | beforePrepareAction (Cutelyst::Context *c, bool *skipMethod) |
| void | postForked (Cutelyst::Application *app) |
| void | preForked (Cutelyst::Application *app) |
| void | shuttingDown (Cutelyst::Application *app) |
Public Member Functions | |
| Application (QObject *parent=nullptr) | |
| void | addTranslator (const QLocale &locale, QTranslator *translator) |
| void | addTranslator (const QString &locale, QTranslator *translator) |
| void | addTranslators (const QLocale &locale, const QVector< QTranslator * > &translators) |
| QVariantMap | config () const noexcept |
| QVariant | config (const QString &key, const QVariant &defaultValue={}) const |
| QVector< Controller * > | controllers () const noexcept |
| Component * | createComponentPlugin (const QString &name, QObject *parent=nullptr) |
| Dispatcher * | dispatcher () const noexcept |
| QVector< DispatchType * > | dispatchers () const noexcept |
| Engine * | engine () const noexcept |
| bool | inited () const noexcept |
| void | loadTranslations (const QString &filename, const QString &directory=QString(), const QString &prefix=QString(), const QString &suffix=QString()) |
| QVector< QLocale > | loadTranslationsFromDir (const QString &filename, const QString &directory=QString(), const QString &prefix=QStringLiteral("."), const QString &suffix=QStringLiteral(".qm")) |
| QVector< QLocale > | loadTranslationsFromDirs (const QString &directory, const QString &filename) |
| QString | pathTo (const QString &path) const |
| QString | pathTo (const QStringList &path) const |
| template<typename T > | |
| T | plugin () |
Returns the registered plugin that casts to the template type T. | |
| QVector< Plugin * > | plugins () const noexcept |
| QString | translate (const QLocale &locale, const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const |
| View * | view (const QString &name) const |
| View * | view (QStringView name={}) const |
Static Public Member Functions | |
| static const char * | cutelystVersion () noexcept |
Protected Member Functions | |
| void | addXCutelystVersionHeader () |
| Headers & | defaultHeaders () noexcept |
| bool | enginePostFork () |
| Called by the Engine once post fork happened. | |
| void | handleRequest (Cutelyst::EngineRequest *request) |
| Called by the Engine to handle a new Request object. | |
| virtual bool | init () |
| virtual bool | postFork () |
| bool | registerController (Controller *controller) |
| bool | registerDispatcher (DispatchType *dispatcher) |
| bool | registerPlugin (Plugin *plugin) |
| bool | registerView (View *view) |
| void | setConfig (const QString &key, const QVariant &value) |
| bool | setup (Engine *engine) |
| Called by the Engine to setup the internal data. | |
Friends | |
| class | Context |
| class | Engine |
This is the main class of a Cutelyst appplication
Definition at line 42 of file application.h.
|
explicit |
The constructor is used to setup the class configuration, subclasses should only use this for objects that do not require configuration to be ready.
A Web Engine will instantiate your application through this class, next it will load the settings file, and in the end it will call init() which is where your application should do it's own setup.
Definition at line 46 of file application.cpp.
References loadTranslations().
|
virtual |
Definition at line 64 of file application.cpp.
| void Application::addTranslator | ( | const QLocale & | locale, |
| QTranslator * | translator | ||
| ) |
Adds a translator for the specified locale.
You can add multiple translators for different application parts for every supported locale. The installed translators will then be used by Context::translate() (what itself will use Application::translate()) to translate strings according to the locale set by Context::setLocale().
Definition at line 438 of file application.cpp.
Referenced by addTranslator(), loadTranslationsFromDir(), and loadTranslationsFromDirs().
| void Application::addTranslator | ( | const QString & | locale, |
| QTranslator * | translator | ||
| ) |
Adds a translator for the specified locale.
The locale string has to be parseable by QLocale.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 450 of file application.cpp.
References addTranslator().
| void Application::addTranslators | ( | const QLocale & | locale, |
| const QVector< QTranslator * > & | translators | ||
| ) |
Adds multiple translators for the specified locale.
Definition at line 455 of file application.cpp.
|
protected |
Adds a X-Cutelyst header with our version on each request
Definition at line 89 of file application.cpp.
|
signal |
This signal is emitted right after the Action found by the dispatcher got executed.
Referenced by handleRequest(), and Cutelyst::Session::setup().
|
signal |
This signal is emitted right after the Dispatcher returns the Action that will be executed.
Referenced by handleRequest(), and Cutelyst::CSRFProtection::setup().
|
signal |
This signal is emitted before the Dispatcher is called to find an action. It's useful if you need to intercept requests before they are dispached. Always check skipMethod and return if it's true. In case you want to stop further processing set skipMethod to true.
Referenced by handleRequest(), Cutelyst::StaticCompressed::setup(), Cutelyst::StaticSimple::setup(), and Cutelyst::LangSelect::setup().
|
noexcept |
User configuration for the application
Definition at line 216 of file application.cpp.
Referenced by pathTo().
| QVariant Application::config | ( | const QString & | key, |
| const QVariant & | defaultValue = {} |
||
| ) | const |
Returns application config specified by key, with a possible default value.
Definition at line 188 of file application.cpp.
|
noexcept |
Returns a list with all registered controllers.
The list might only be complete after application has been setup.
Definition at line 170 of file application.cpp.
Referenced by enginePostFork(), and setup().
| Component * Application::createComponentPlugin | ( | const QString & | name, |
| QObject * | parent = nullptr |
||
| ) |
Tries to load a plugin in Cutelyst default plugin directory with parent as it's parent. A nullptr is returned in case of failure.
Definition at line 139 of file application.cpp.
References Cutelyst::ComponentFactory::createComponent().
|
staticnoexcept |
|
protectednoexcept |
This is the HTTP default response headers that each request gets
Do not change it after the application has started.
Definition at line 83 of file application.cpp.
Referenced by Cutelyst::Context::Context().
|
noexcept |
Returns the dispatcher class.
Definition at line 198 of file application.cpp.
Referenced by registerDispatcher().
|
noexcept |
Returns a list with all registered dispachers.
The list might only be complete after application has been setup.
Definition at line 204 of file application.cpp.
|
noexcept |
Returns current engine that is generating requests.
Definition at line 240 of file application.cpp.
Referenced by Cutelyst::MemcachedSessionStore::MemcachedSessionStore(), handleRequest(), Cutelyst::Session::setup(), Cutelyst::CSRFProtection::setup(), Cutelyst::Memcached::setup(), Cutelyst::StaticCompressed::setup(), and setup().
|
protected |
Definition at line 418 of file application.cpp.
References controllers(), postFork(), and postForked().
|
protected |
Definition at line 374 of file application.cpp.
References afterDispatch(), beforeDispatch(), beforePrepareAction(), Cutelyst::EngineRequest::context, engine(), and Cutelyst::EngineRequest::status.
|
protectedvirtual |
Do your application initialization here, if your application should not proceed log some information that might help on debuggin and return false
For example if your application only works with PostgeSQL and the Qt driver is not available it makes sense to fail here. However you should not initialize resouces that cannot be shared among process.
true if your application was successfuly initted Definition at line 69 of file application.cpp.
Referenced by setup().
|
noexcept |
Returns true if the application has been inited.
Definition at line 234 of file application.cpp.
| void Application::loadTranslations | ( | const QString & | filename, |
| const QString & | directory = QString(), |
||
| const QString & | prefix = QString(), |
||
| const QString & | suffix = QString() |
||
| ) |
Loads translations for a specific filename from a single directory.
This can be used to load translations for a specific component if the translation file names follow a common schema. Let us assume you organised your translation files as follows:
/usr/share/myapp/translations/myapp_de.qm /usr/share/myapp/translations/myapp_pt_BR.qm ...You can then use loadTranslations() in your reimplementation of Application::init() as follows:
If directory is empty, the default directory, set by -DI18NDIR, will be used. prefix is the part between the file name and the locale part. In the example above it is "_", if it is not set the default "." will be used. The suffix is the file name suffix that defaults to ".qm".
Definition at line 529 of file application.cpp.
References loadTranslationsFromDir().
Referenced by Application(), Cutelyst::Validator::loadTranslations(), Cutelyst::CSRFProtection::setup(), and Cutelyst::Memcached::setup().
| QVector< QLocale > Application::loadTranslationsFromDir | ( | const QString & | filename, |
| const QString & | directory = QString(), |
||
| const QString & | prefix = QStringLiteral("."), |
||
| const QString & | suffix = QStringLiteral(".qm") |
||
| ) |
Loads translations for a specific filename from a single directory and returns a list of added locales.
This can be used to load translations for a specific component if the translation file names follow a common schema. Let us assume you organised your translation files as follows:
/usr/share/myapp/translations/myapp_de.qm /usr/share/myapp/translations/myapp_pt_BR.qm ...You can then use loadTranslationsFromDir() in your reimplementation of Application::init() as follows:
If directory is empty, the default directory, set by -DI18NDIR, will be used. prefix is the part between the file name and the locale part. In the example above it is "_", if it is not set the default "." will be used. The suffix is the file name suffix that defaults to ".qm".
Definition at line 537 of file application.cpp.
References addTranslator().
Referenced by loadTranslations().
| QVector< QLocale > Application::loadTranslationsFromDirs | ( | const QString & | directory, |
| const QString & | filename | ||
| ) |
Loads translations for a specific filename from a directory structure under directory and returns a list of added locales.
This can be used to load translations for a specific component or application if the the translation files are organized in subdirectories named after locale codes. Let us assume you organised your translation files as follows:
/usr/share/locale/de/LC_MESSAGES/myapp.qm /usr/share/locale/pt_BR/LC_MESSAGES/myapp.qm ...You can then use loadTranslationsFromDirs() in your reimplementation of Application::init() as follows:
Definition at line 595 of file application.cpp.
References addTranslator().
| QString Application::pathTo | ( | const QString & | path | ) | const |
Merges path with config("HOME") and returns an absolute path.
Definition at line 222 of file application.cpp.
References config().
| QString Cutelyst::Application::pathTo | ( | const QStringList & | path | ) | const |
Merges path with config("HOME") and returns an absolute path.
Definition at line 228 of file application.cpp.
|
inline |
Definition at line 107 of file application.h.
Referenced by registerPlugin(), Cutelyst::CSRFProtection::setup(), and setup().
|
noexcept |
Returns all registered plugins
Definition at line 210 of file application.cpp.
Referenced by setup().
|
protectedvirtual |
This method is called after the engine forks
After the web engine forks itself it will call this function so that you can initialize resources that can't be shared with the parent process, namely sockets and file descriptors.
A good example of usage of this function is when openning a connection to the database which can't be shared with other process and should probably make this function return false if it fails to open.
Default implementation returns true.
Definition at line 76 of file application.cpp.
Referenced by enginePostFork().
|
signal |
This signal is emitted after before
Referenced by enginePostFork(), Cutelyst::Session::setup(), Cutelyst::Authentication::setup(), Cutelyst::CSRFProtection::setup(), Cutelyst::Memcached::setup(), Cutelyst::StatusMessage::setup(), and Cutelyst::LangSelect::setup().
|
signal |
This signal is emitted right after application has been setup and before application forks and
Referenced by setup().
|
protected |
This method registers a Controller class which is responsible for handlying Requests, since they are reused between multiple requests beaware of not storing data there, instead you might want to use a session plugin or the stash.
| controller | the Controller class |
true if succeeded Definition at line 105 of file application.cpp.
|
protected |
Registers a custom DispatchType, if none is registered all the built-in dispatchers types will be registered
Definition at line 129 of file application.cpp.
References dispatcher().
|
protected |
Registers a global plugin ie one that doesn't need to be created explicity for a single request and returns true on plugin->isApplicationPlugin();
true if the plugin could be registered Definition at line 95 of file application.cpp.
References plugin().
|
protected |
This method registers a View class which is responsible for rendering requests.
| view | the View class |
true if succeeded Definition at line 117 of file application.cpp.
References Cutelyst::Component::name(), and view().
|
protected |
Change the value of the configuration key You should never call this from random parts of the code as a way to store shareable data, it should only be called by a subclass
Definition at line 246 of file application.cpp.
|
protected |
Definition at line 252 of file application.cpp.
References Cutelyst::Engine::config(), controllers(), cutelystVersion(), engine(), init(), plugin(), plugins(), preForked(), Cutelyst::Component::reverse(), Cutelyst::Component::setReverse(), view(), and Cutelyst::Engine::workerCore().
|
signal |
This signal is likely to be emitted when the worker process should stop, at this point the application has a limited time to finish it's operations, if a timeout is reached the application will get killed.
| QString Application::translate | ( | const QLocale & | locale, |
| const char * | context, | ||
| const char * | sourceText, | ||
| const char * | disambiguation = nullptr, |
||
| int | n = -1 |
||
| ) | const |
Translates the sourceText into the target locale language.
This uses the installed translators for the specified locale to translate the sourceText for the given context into the target locale. Optionally you can use a disambiguation and/or the n parameter to translate a pluralized version.
Definition at line 493 of file application.cpp.
| View * Application::view | ( | const QString & | name | ) | const |
Returns the view specified by name, if no view is found nullptr is returned.
Definition at line 176 of file application.cpp.
Referenced by Cutelyst::RenderView::init(), registerView(), and setup().
| View * Application::view | ( | QStringView | name = {} | ) | const |
Returns the view specified by name, if no view is found nullptr is returned.
Definition at line 182 of file application.cpp.
|
friend |
Definition at line 452 of file application.h.
|
friend |
Definition at line 451 of file application.h.