Pickles Framework Documentation

Kernel
in package

Class Kernel

The Kernel class is the core of the Pickles framework. It is responsible for bootstrapping the application, handling HTTP requests, resolving routes, executing actions, and sending HTTP responses.

Table of Contents

Properties

$database  : DatabaseDriver
$request  : Request
The request instance representing the current HTTP request.
$root  : string
$router  : Router
The router instance responsible for handling route definitions and dispatching.
$server  : Server
The server instance providing server-related utilities and information.
$session  : Session
The session instance used to manage user sessions.
$viewEngine  : Engine
The view engine instance used for rendering views.

Methods

abort()  : void
Aborts the current process by terminating it with the given response.
bootstrap()  : self
Bootstraps the application by initializing the root directory, loading configuration, running service providers, setting up HTTP handlers, establishing a database connection, and running runtime service providers.
getRequest()  : Request
Get the value of request
getRouter()  : Router
Get the server instance providing server-related utilities and information.
getServer()  : Server
Get the value of server
getSession()  : Session
Get the value of session
getViewEngine()  : mixed
Get the value of viewEngine
prepareNextRequest()  : void
Prepares the application for the next request.
run()  : void
Executes the main application logic by resolving the route, invoking the corresponding action, and sending the response.
terminate()  : void
Terminates the current request lifecycle.
loadConfig()  : self
Loads the application configuration.
runServiceProviders()  : self
Executes the service providers of the specified type.
setHttpHandlers()  : self
Sets up the HTTP handlers for the application.
setUpDatabaseConnection()  : self
Sets up the database connection for the application.

Properties

$request

The request instance representing the current HTTP request.

public Request $request

$root

public static string $root

$router

The router instance responsible for handling route definitions and dispatching.

public Router $router

$server

The server instance providing server-related utilities and information.

public Server $server

$session

The session instance used to manage user sessions.

public Session $session

$viewEngine

The view engine instance used for rendering views.

public Engine $viewEngine

Methods

abort()

Aborts the current process by terminating it with the given response.

public abort(Response $response) : void
Parameters
$response : Response

The response object used to terminate the process.

bootstrap()

Bootstraps the application by initializing the root directory, loading configuration, running service providers, setting up HTTP handlers, establishing a database connection, and running runtime service providers.

public static bootstrap(string $root) : self
Parameters
$root : string

The root directory of the application.

Return values
self

Returns the instance of the Kernel after bootstrapping.

getRouter()

Get the server instance providing server-related utilities and information.

public getRouter() : Router
Return values
Router

getViewEngine()

Get the value of viewEngine

public getViewEngine() : mixed

prepareNextRequest()

Prepares the application for the next request.

public prepareNextRequest() : void

If the current request method is GET, this method stores the URI of the current request in the session under a predefined key. This allows the application to keep track of the previous request's URI for future use.

run()

Executes the main application logic by resolving the route, invoking the corresponding action, and sending the response.

public run() : void

terminate()

Terminates the current request lifecycle.

public terminate(Response $response) : void

This method performs cleanup tasks after the response has been sent. It prepares the system for the next request, sends the response to the client, closes the database connection, and terminates the script execution.

Parameters
$response : Response

The response object to be sent to the client.

loadConfig()

Loads the application configuration.

protected loadConfig() : self

This method initializes the environment variables using the Dotenv library and loads the application configuration files from the specified directory.

Return values
self

Returns the current instance for method chaining.

runServiceProviders()

Executes the service providers of the specified type.

protected runServiceProviders(string $type) : self

This method iterates through the list of service providers defined in the configuration for the given type, instantiates each provider, and ensures it implements the ServiceProvider interface. If a provider does not implement the required interface, an InvalidServiceProviderException is thrown. Each valid provider's registerServices method is then called.

Parameters
$type : string

The type of service providers to execute ("boot" or "runtime").

Tags
throws
InvalidServiceProviderException

If a provider does not implement the ServiceProvider interface.

Return values
self

Returns the current instance for method chaining.

setHttpHandlers()

Sets up the HTTP handlers for the application.

protected setHttpHandlers() : self

This method initializes and assigns the following components:

  • Router: A singleton instance of the Router class.
  • Server: An application instance of the Server class.
  • Request: The current HTTP request obtained from the server.
  • Session: A singleton instance of the Session class, initialized with a SessionStorage instance.
Return values
self

Returns the current instance for method chaining.

setUpDatabaseConnection()

Sets up the database connection for the application.

protected setUpDatabaseConnection() : self

This method initializes the database driver and establishes a connection using configuration values such as protocol, host, port, username, password, and database name. It also sets the database driver for the application's models to ensure consistent database interactions.

Return values
self

Returns the current instance for method chaining.


        
On this page

Search results