Constants

CI_VERSION

CI_VERSION = '4.0.0-rc.3'

The current version of CodeIgniter Framework

Properties

$startTime

$startTime : mixed

App startup time.

Type

mixed

$totalTime

$totalTime : float

Total app execution time

Type

float

$config

$config : \Config\App

Main application configuration

Type

\Config\App

$router

$router : \CodeIgniter\Router\Router

Router to use.

Type

\CodeIgniter\Router\Router

$controller

$controller : string|\Closure

Controller to use.

Type

string|\Closure

$method

$method : string

Controller method to invoke.

Type

string

$output

$output : string

Output handler to use.

Type

string

$cacheTTL

$cacheTTL : integer

Cache expiration time

Type

integer

$path

$path : string

Request path to use.

Type

string

$useSafeOutput

$useSafeOutput : boolean

Should the Response instance "pretend" to keep from setting headers/cookies/etc

Type

boolean

Methods

__construct()

__construct(\CodeIgniter\type  $config) 

Constructor.

Parameters

\CodeIgniter\type $config

initialize()

initialize() 

Handles some basic app and environment setup.

run()

run(\CodeIgniter\Router\RouteCollectionInterface  $routes = null, boolean  $returnResponse = false) : boolean|\CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed

Launch the application!

This is "the loop" if you will. The main entry point into the script that gets the required class instances, fires off the filters, tries to route the response, loads the controller and generally makes all of the pieces work together.

Parameters

\CodeIgniter\Router\RouteCollectionInterface $routes
boolean $returnResponse

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

boolean|\CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed

useSafeOutput()

useSafeOutput(boolean  $safe = true) : $this

Set our Response instance to "pretend" mode so that things like cookies and headers are not actually sent, allowing PHP 7.2+ to not complain when ini_set() function is used.

Parameters

boolean $safe

Returns

$this

setRequest()

setRequest(\CodeIgniter\HTTP\Request  $request) : \CodeIgniter\CodeIgniter

Sets a Request object to be used for this request.

Used when running certain tests.

Parameters

\CodeIgniter\HTTP\Request $request

Returns

\CodeIgniter\CodeIgniter

displayCache()

displayCache(\Config\Cache  $config) : boolean|\CodeIgniter\HTTP\ResponseInterface

Determines if a response has been cached for the given URI.

Parameters

\Config\Cache $config

Throws

\Exception

Returns

boolean|\CodeIgniter\HTTP\ResponseInterface

cache()

cache(integer  $time) : void

Tells the app that the final output should be cached.

Parameters

integer $time

cachePage()

cachePage(\Config\Cache  $config) : mixed

Caches the full response from the current request. Used for full-page caching for very high performance.

Parameters

\Config\Cache $config

Returns

mixed

getPerformanceStats()

getPerformanceStats() : array

Returns an array with our basic performance stats collected.

Returns

array

displayPerformanceMetrics()

displayPerformanceMetrics(string  $output) : string

Replaces the memory_usage and elapsed_time tags.

Parameters

string $output

Returns

string

setPath()

setPath(string  $path) : $this

Allows the request path to be set from outside the class, instead of relying on CLIRequest or IncomingRequest for the path.

This is primarily used by the Console.

Parameters

string $path

Returns

$this

storePreviousURL()

storePreviousURL(\CodeIgniter\HTTP\URI  $uri) 

If we have a session object to use, store the current URI as the previous URI. This is called just prior to sending the response to the client, and will make it available next request.

This helps provider safer, more reliable previous_url() detection.

Parameters

\CodeIgniter\HTTP\URI $uri

spoofRequestMethod()

spoofRequestMethod() 

Modifies the Request Object to use a different method if a POST variable called _method is found.

handleRequest()

handleRequest(\CodeIgniter\Router\RouteCollectionInterface  $routes = null,   $cacheConfig, boolean  $returnResponse = false) : \CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed

Handles the main request logic and fires the controller.

Parameters

\CodeIgniter\Router\RouteCollectionInterface $routes
$cacheConfig
boolean $returnResponse

Throws

\CodeIgniter\Router\Exceptions\RedirectException

Returns

\CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed

detectEnvironment()

detectEnvironment() 

You can load different configurations depending on your current environment. Setting the environment also influences things like logging and error reporting.

This can be set to anything, but default usage is:

development
testing
production

bootstrapEnvironment()

bootstrapEnvironment() 

Load any custom boot files based upon the current environment.

If no boot file exists, we shouldn't continue because something is wrong. At the very least, they should have error reporting setup.

startBenchmark()

startBenchmark() 

Start the Benchmark

The timer is used to display total script execution both in the debug toolbar, and potentially on the displayed page.

getRequestObject()

getRequestObject() 

Get our Request object, (either IncomingRequest or CLIRequest) and set the server protocol based on the information provided by the server.

getResponseObject()

getResponseObject() 

Get our Response object, and set some default values, including the HTTP protocol version and a default successful response.

forceSecureAccess()

forceSecureAccess(integer  $duration = 31536000) 

Force Secure Site Access? If the config value 'forceGlobalSecureRequests' is true, will enforce that all requests to this site are made through HTTPS. Will redirect the user to the current page with HTTPS, as well as set the HTTP Strict Transport Security header for those browsers that support it.

Parameters

integer $duration

How long the Strict Transport Security should be enforced for this URL.

generateCacheName()

generateCacheName(  $config) : string

Generates the cache name to use for our full-page caching.

Parameters

$config

Returns

string

tryToRouteIt()

tryToRouteIt(\CodeIgniter\Router\RouteCollectionInterface  $routes = null) : string

Try to Route It - As it sounds like, works with the router to match a route against the current URI. If the route is a "redirect route", will also handle the redirect.

Parameters

\CodeIgniter\Router\RouteCollectionInterface $routes

An collection interface to use in place of the config file.

Throws

\CodeIgniter\Router\Exceptions\RedirectException

Returns

string

determinePath()

determinePath() 

Determines the path to use for us to try to route to, based on user input (setPath), or the CLI/IncomingRequest path.

startController()

startController() 

Now that everything has been setup, this method attempts to run the controller method and make the script go. If it's not able to, will show the appropriate Page Not Found error.

createController()

createController() : mixed

Instantiates the controller class.

Returns

mixed

runController()

runController(mixed  $class) : mixed

Runs the controller, allowing for _remap methods to function.

Parameters

mixed $class

Returns

mixed

display404errors()

display404errors(\CodeIgniter\Exceptions\PageNotFoundException  $e) 

Displays a 404 Page Not Found error. If set, will try to call the 404Override controller/method that was set in routing config.

Parameters

\CodeIgniter\Exceptions\PageNotFoundException $e

gatherOutput()

gatherOutput(null  $cacheConfig = null, null  $returned = null) 

Gathers the script output from the buffer, replaces some execution time tag in the output and displays the debug toolbar, if required.

Parameters

null $cacheConfig
null $returned

sendResponse()

sendResponse() 

Sends the output of this request back to the client.

This is what they've been waiting for!

callExit()

callExit(  $code) 

Exits the application, setting the exit code for CLI-based applications that might be watching.

Made into a separate method so that it can be mocked during testing without actually stopping script execution.

Parameters

$code