Leaf PHP

PrettyPageHandler extends Handler
in package

Abstract implementation of a Handler.

Table of Contents

Constants

DONE  = 0x10
EDITOR_ATOM  = "atom"
EDITOR_EMACS  = "emacs"
EDITOR_ESPRESSO  = "espresso"
EDITOR_IDEA  = "idea"
EDITOR_MACVIM  = "macvim"
EDITOR_NETBEANS  = "netbeans"
EDITOR_PHPSTORM  = "phpstorm"
EDITOR_SUBLIME  = "sublime"
EDITOR_TEXTMATE  = "textmate"
EDITOR_VSCODE  = "vscode"
EDITOR_XDEBUG  = "xdebug"
LAST_HANDLER  = 0x20
The Handler has handled the Throwable in some way, and wishes to skip any other Handler.
QUIT  = 0x30
The Handler has handled the Throwable in some way, and wishes to quit/stop execution

Properties

$editor  : callable|string
An identifier for a known IDE/text editor.
$editors  : array<string|int, mixed>
A list of known editor strings.
$templateHelper  : TemplateHelper
$applicationPaths  : array<string|int, array<string|int, mixed>>
$blacklist  : array<string|int, array<string|int, mixed>>
$customCss  : string|null
The name of the custom css file.
$customJs  : string|null
The name of the custom js file.
$exception  : Throwable
$extraTables  : array<string|int, array<string|int, mixed>>
$handleUnconditionally  : bool
$inspector  : Inspector
$pageTitle  : string
$resourceCache  : array<string|int, mixed>
Fast lookup cache for known resource locations.
$run  : RunInterface
$searchPaths  : array<string|int, mixed>
Search paths to be scanned for resources.

Methods

__construct()  : void
Constructor.
addCustomCss()  : static
Adds a custom css file to be loaded.
addCustomJs()  : static
Adds a custom js file to be loaded.
addDataTable()  : static
Adds an entry to the list of tables displayed in the template.
addDataTableCallback()  : static
Lazily adds an entry to the list of tables displayed in the table.
addEditor()  : static
Adds an editor resolver.
addResourcePath()  : static
Adds a path to the list of paths to be searched for resources.
blacklist()  : static
blacklist a sensitive value within one of the superglobal arrays.
contentType()  : string
getApplicationPaths()  : array<string|int, mixed>
Return the application paths.
getDataTables()  : array<string|int, array<string|int, mixed>>|callable
Returns all the extra data tables registered with this handler.
getEditorAjax()  : bool
Determine if the editor link should act as an Ajax request.
getEditorHref()  : string|bool
Get the editor href for a given file and line, if available.
getPageTitle()  : string
Get the page title.
getResourcePaths()  : array<string|int, mixed>
getResourcesPath()  : string
handle()  : int|null
handleUnconditionally()  : bool|static
Set whether to handle unconditionally.
hideSuperglobalKey()  : static
Hide a sensitive value within one of the superglobal arrays.
isLocal()  : bool
is Local Environment Check if the application is running in a local environment.
setApplicationPaths()  : void
Set the application paths.
setApplicationRootPath()  : void
Set the application root path.
setEditor()  : static
Set the editor to use to open referenced files.
setException()  : void
setInspector()  : void
setPageTitle()  : static
Set the page title.
setResourcesPath()  : static
setRun()  : void
getEditor()  : array<string|int, mixed>
Determines both the editor and if ajax should be used.
getException()  : Throwable
getExceptionCode()  : string
Get the code of the exception currently being handled.
getExceptionFrames()  : FrameCollection
Get the stack trace frames of the exception currently being handled.
getInspector()  : Inspector
getResource()  : string
Finds a resource, by its relative path, in all available search paths.
getRun()  : RunInterface
masked()  : array<string|int, mixed>
Checks all values within the given superGlobal array.

Constants

LAST_HANDLER

The Handler has handled the Throwable in some way, and wishes to skip any other Handler.

public mixed LAST_HANDLER = 0x20

Execution will continue.

QUIT

The Handler has handled the Throwable in some way, and wishes to quit/stop execution

public mixed QUIT = 0x30

Properties

$editor

An identifier for a known IDE/text editor.

protected callable|string $editor

Either a string, or a calalble that resolves a string, that can be used to open a given file in an editor. If the string contains the special substrings %file or %line, they will be replaced with the correct data.

Tags
example

"txmt://open?url=%file&line=%line"

$editors

A list of known editor strings.

protected array<string|int, mixed> $editors = ["sublime" => "subl://open?url=file://%file&line=%line", "textmate" => "txmt://open?url=file://%file&line=%line", "emacs" => "emacs://open?url=file://%file&line=%line", "macvim" => "mvim://open/?url=file://%file&line=%line", "phpstorm" => "phpstorm://open?file=%file&line=%line", "idea" => "idea://open?file=%file&line=%line", "vscode" => "vscode://file/%file:%line", "atom" => "atom://core/open/file?filename=%file&line=%line", "espresso" => "x-espresso://open?filepath=%file&lines=%line", "netbeans" => "netbeans://open/?f=%file:%line"]

$applicationPaths

private array<string|int, array<string|int, mixed>> $applicationPaths

$blacklist

private array<string|int, array<string|int, mixed>> $blacklist = ['_GET' => [], '_POST' => [], '_FILES' => [], '_COOKIE' => [], '_SESSION' => [], '' => [], '_ENV' => []]

$customCss

The name of the custom css file.

private string|null $customCss = null

$customJs

The name of the custom js file.

private string|null $customJs = null

$exception

private Throwable $exception

$extraTables

private array<string|int, array<string|int, mixed>> $extraTables = []

$resourceCache

Fast lookup cache for known resource locations.

private array<string|int, mixed> $resourceCache = []

$searchPaths

Search paths to be scanned for resources.

private array<string|int, mixed> $searchPaths = []

Stored in the reverse order they're declared.

Methods

addCustomCss()

Adds a custom css file to be loaded.

public addCustomCss(string|null $name) : static
Parameters
$name : string|null
Return values
static

addCustomJs()

Adds a custom js file to be loaded.

public addCustomJs(string|null $name) : static
Parameters
$name : string|null
Return values
static

addDataTable()

Adds an entry to the list of tables displayed in the template.

public addDataTable(string $label, array<string|int, mixed> $data) : static

The expected data is a simple associative array. Any nested arrays will be flattened with print_r.

Parameters
$label : string
$data : array<string|int, mixed>
Return values
static

addDataTableCallback()

Lazily adds an entry to the list of tables displayed in the table.

public addDataTableCallback(string $label, callable $callback) : static

The supplied callback argument will be called when the error is rendered, it should produce a simple associative array. Any nested arrays will be flattened with print_r.

Parameters
$label : string
$callback : callable

Callable returning an associative array

Tags
throws
InvalidArgumentException

If $callback is not callable

Return values
static

addEditor()

Adds an editor resolver.

public addEditor(string $identifier, string|callable $resolver) : static

Either a string, or a closure that resolves a string, that can be used to open a given file in an editor. If the string contains the special substrings %file or %line, they will be replaced with the correct data.

Parameters
$identifier : string
$resolver : string|callable
Tags
example

$run->addEditor('macvim', "mvim://open?url=file://%file&line=%line")

example

$run->addEditor('remove-it', function($file, $line) { unlink($file); return "http://stackoverflow.com"; });

Return values
static

addResourcePath()

Adds a path to the list of paths to be searched for resources.

public addResourcePath(string $path) : static
Parameters
$path : string
Tags
throws
InvalidArgumentException

If $path is not a valid directory

Return values
static

blacklist()

blacklist a sensitive value within one of the superglobal arrays.

public blacklist(string $superGlobalName, string $key) : static

Alias for the hideSuperglobalKey method.

Parameters
$superGlobalName : string

The name of the superglobal array, e.g. '_GET'

$key : string

The key within the superglobal

Tags
see
hideSuperglobalKey
Return values
static

getApplicationPaths()

Return the application paths.

public getApplicationPaths() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDataTables()

Returns all the extra data tables registered with this handler.

public getDataTables([string|null $label = null ]) : array<string|int, array<string|int, mixed>>|callable

Optionally accepts a 'label' parameter, to only return the data table under that label.

Parameters
$label : string|null = null
Return values
array<string|int, array<string|int, mixed>>|callable

getEditorAjax()

Determine if the editor link should act as an Ajax request.

public getEditorAjax(string $filePath, int $line) : bool
Parameters
$filePath : string
$line : int
Tags
throws
UnexpectedValueException

If editor resolver does not return a boolean

Return values
bool

getEditorHref()

Get the editor href for a given file and line, if available.

public getEditorHref(string $filePath, int $line) : string|bool
Parameters
$filePath : string
$line : int
Tags
throws
InvalidArgumentException

If editor resolver does not return a string

Return values
string|bool

getPageTitle()

Get the page title.

public getPageTitle() : string
Return values
string

getResourcePaths()

public getResourcePaths() : array<string|int, mixed>
Return values
array<string|int, mixed>

handle()

public handle() : int|null
Tags
throws
Exception
Return values
int|null

handleUnconditionally()

Set whether to handle unconditionally.

public handleUnconditionally([bool|null $value = null ]) : bool|static

Allows to disable all attempts to dynamically decide whether to handle or return prematurely. Set this to ensure that the handler will perform, no matter what.

Parameters
$value : bool|null = null
Return values
bool|static

hideSuperglobalKey()

Hide a sensitive value within one of the superglobal arrays.

public hideSuperglobalKey(string $superGlobalName, string $key) : static
Parameters
$superGlobalName : string

The name of the superglobal array, e.g. '_GET'

$key : string

The key within the superglobal

Return values
static

isLocal()

is Local Environment Check if the application is running in a local environment.

public isLocal() : bool
Return values
bool

True if running locally, otherwise false.

setApplicationPaths()

Set the application paths.

public setApplicationPaths(array<string|int, mixed> $applicationPaths) : void
Parameters
$applicationPaths : array<string|int, mixed>

setApplicationRootPath()

Set the application root path.

public setApplicationRootPath(string $applicationRootPath) : void
Parameters
$applicationRootPath : string

setEditor()

Set the editor to use to open referenced files.

public setEditor(string|callable $editor) : static

Pass either the name of a configured editor, or a closure that directly resolves an editor string.

Parameters
$editor : string|callable
Tags
example

$run->setEditor(function($file, $line) { return "file:///{$file}"; });

example

$run->setEditor('sublime');

throws
InvalidArgumentException

If invalid argument identifier provided

Return values
static

setException()

public setException(Throwable $exception) : void
Parameters
$exception : Throwable

setPageTitle()

Set the page title.

public setPageTitle(string $title) : static
Parameters
$title : string
Return values
static

setResourcesPath()

public setResourcesPath(string $resourcesPath) : static
Parameters
$resourcesPath : string
Return values
static

getEditor()

Determines both the editor and if ajax should be used.

protected getEditor(string $filePath, int $line) : array<string|int, mixed>
Parameters
$filePath : string
$line : int
Return values
array<string|int, mixed>

getException()

protected getException() : Throwable
Return values
Throwable

getExceptionCode()

Get the code of the exception currently being handled.

protected getExceptionCode() : string
Return values
string

getResource()

Finds a resource, by its relative path, in all available search paths.

protected getResource(string $resource) : string

The search is performed starting at the last search path, and all the way back to the first, enabling a cascading-type system of overrides for all resources.

Parameters
$resource : string
Tags
throws
RuntimeException

If resource cannot be found in any of the available paths

Return values
string

masked()

Checks all values within the given superGlobal array.

private masked(array<string|int, mixed> $superGlobal, string $superGlobalName) : array<string|int, mixed>

Blacklisted values will be replaced by a equal length string containing only '*' characters for string values. Non-string values will be replaced with a fixed asterisk count. We intentionally dont rely on $GLOBALS as it depends on the 'auto_globals_jit' php.ini setting.

Parameters
$superGlobal : array<string|int, mixed>

One of the superglobal arrays

$superGlobalName : string

The name of the superglobal array, e.g. '_GET'

Return values
array<string|int, mixed>

$values without sensitive data


        
On this page

Search results