|
NameOpenXPKI::Server::Context (Singleton) DescriptionThis package provices a globally accessible Context singleton that holds object references for the OpenXPKI base infrastructure. Typically the package is included in every module that needs to access basic functions such as logging or database operations.During startup of the system this Context package must be initialized once by passing in the configuration file (see create()). After initialization has completed the package holds a global context that can be accessed from anywhere within the OpenXPKI code structure. Callers typically use the CTX() function to access this context. See below for usage hints. Basic objects (always available)The following Context objects are always created and can be retrieved by calling CTX('...') once create() has been called:
Auxiliary objects (only available after explicit addition)In addition to the above objects that are guaranteed to exist after initialization has happened, the following can be retrieved if they have been explicitly added to the Context after initialization via setcontext().
These objects are usually created and attached by the OpenXPKI Server initialization procedure in order to make the objects available globally. FunctionsCTX($)Allows to retrieve an object reference for the specified name. If called before initialization has happened (see create() function) calling CTX() yields an exception. CTX() returns the associated object in the global context.Usage: use OpenXPKI::Server::Context; my $config = OpenXPKI::Server::Context::CTX('xml_config'); or simpler: use OpenXPKI::Server::Context qw( CTX ); my $config = CTX('xml_config'); CTX(@)It is also possible to call CTX() in list context to obtain multiple context entries at once:my ($config, $log, $dbi) = CTX('xml_config', 'log', 'dbi'); setcontext(%)Allows to set additional globally available Context information after the Context has been initialized via create().To prevent abuse (storing arbitrary stuff globally) the Context module only allows to set Context entries that are allowed explicitly. Only the keys mentioned above are accepted, trying to set an unsupported Context object yields an exception. Please note that it is NOT possible to overwrite a Context object once it has been set once. setcontext() will throw an exception if somebody tries to set an object that has already been attached. Usage: # attach this server object and the API to the global context OpenXPKI::Server::Context::setcontext({ server => $self, api2 => OpenXPKI::Server::API2->new(), }); hascontextCheck if the requested entry is available from the context.killsessionDelete the recorded session from the context. Used during server startup where we start with a mock session and need a real one later.resetResets the context, i.e. deletes all context objects by resetting the file scope ("static") variables to their initial state.Used to re-initialize the server in tests.
Visit the GSP FreeBSD Man Page Interface. |