Fr3nch13/CakePHP Utilities

Documentation

Table of Contents

Packages

Application

Namespaces

Fr3nch13
Cake
Composer
ComposerLockParser
Laminas
Zend
League
Psr

Classes

InitialMigration
ComposerAutoloaderInit3bb55a41436c988ee8a34cad9609c092

Constants

APP  = \TEST_APP . 'TestApp' . \DS
APP_DIR  = 'TestApp'
CACHE  = \TMP . 'cache' . \DS
CAKE  = \CORE_PATH . 'src' . \DS
CAKE_CORE_INCLUDE_PATH  = \ROOT
CONFIG  = \TEST_APP . 'config' . \DS
CORE_PATH  = \CAKE_CORE_INCLUDE_PATH . \DS
CORE_TEST_CASES  = \CORE_TESTS . 'TestCase'
CORE_TESTS  = \CORE_PATH . 'tests' . \DS
DAY  = 86400
DS  = \DIRECTORY_SEPARATOR
Defines DS as short form of DIRECTORY_SEPARATOR.
DS  = \DIRECTORY_SEPARATOR
E_RECOVERABLE_ERROR  = 4096
HOUR  = 3600
LOGS  = \TMP . 'logs' . \DS
MINUTE  = 60
MONTH  = 2592000
ROOT  = \dirname(__DIR__)
SECOND  = 1
SESSIONS  = \TMP . 'sessions' . \DS
TEST_APP  = \CORE_TESTS . 'test_app' . \DS
TESTS  = __DIR__ . \DS
TIME_START  = \microtime(\true)
TMP  = \sys_get_temp_dir() . \DS
WEEK  = 604800
WWW_ROOT  = \TEST_APP . 'webroot' . \DS
YEAR  = 31536000

Functions

debug()  : mixed
Prints out debug information about given variable and returns the variable that was passed.
stackTrace()  : void
Outputs a stack trace based on the supplied options.
breakpoint()  : string|null
Command to return the eval-able code to startup PsySH in interactive debugger Works the same way as eval(\Psy\sh()); psy/psysh must be loaded in your project
dd()  : void
Prints out debug information about given variable and dies.
collection()  : Collection
Returns a new {@link \Cake\Collection\Collection} object wrapping the passed argument.
h()  : mixed
Convenience method for htmlspecialchars.
pluginSplit()  : array<string|int, mixed>
Splits a dot syntax plugin name into its plugin and class name.
namespaceSplit()  : array<string|int, string>
Split the namespace from the classname.
pr()  : mixed
print_r() convenience function.
pj()  : mixed
JSON pretty print convenience function.
env()  : string|bool|null
Gets an environment variable from available sources, and provides emulation for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on IIS, or SCRIPT_NAME in CGI mode). Also exposes some additional custom environment information.
triggerWarning()  : void
Triggers an E_USER_WARNING.
deprecationWarning()  : void
Helper method for outputting deprecation warnings
getTypeName()  : string
Returns the objects class or var type of it's not an object
__()  : string
Returns a translated string if one is found; Otherwise, the submitted message.
__n()  : string
Returns correct plural form of message identified by $singular and $plural for count $count.
__d()  : string
Allows you to override the current domain for a single message lookup.
__dn()  : string
Allows you to override the current domain for a single plural message lookup.
__x()  : string
Returns a translated string if one is found; Otherwise, the submitted message.
__xn()  : string
Returns correct plural form of message identified by $singular and $plural for count $count.
__dx()  : string
Allows you to override the current domain for a single message lookup.
__dxn()  : string
Returns correct plural form of message identified by $singular and $plural for count $count.
urlArray()  : array<string|int, mixed>
Returns an array URL from a route path string.

Constants

APP

public mixed APP = \TEST_APP . 'TestApp' . \DS

CACHE

public mixed CACHE = \TMP . 'cache' . \DS

CAKE

public mixed CAKE = \CORE_PATH . 'src' . \DS

CAKE_CORE_INCLUDE_PATH

public mixed CAKE_CORE_INCLUDE_PATH = \ROOT

CONFIG

public mixed CONFIG = \TEST_APP . 'config' . \DS

CORE_PATH

public mixed CORE_PATH = \CAKE_CORE_INCLUDE_PATH . \DS

CORE_TEST_CASES

public mixed CORE_TEST_CASES = \CORE_TESTS . 'TestCase'

CORE_TESTS

public mixed CORE_TESTS = \CORE_PATH . 'tests' . \DS

DS

Defines DS as short form of DIRECTORY_SEPARATOR.

public mixed DS = \DIRECTORY_SEPARATOR

E_RECOVERABLE_ERROR

public mixed E_RECOVERABLE_ERROR = 4096

LOGS

public mixed LOGS = \TMP . 'logs' . \DS

MONTH

public mixed MONTH = 2592000

SESSIONS

public mixed SESSIONS = \TMP . 'sessions' . \DS

TEST_APP

public mixed TEST_APP = \CORE_TESTS . 'test_app' . \DS

TIME_START

public float TIME_START = \microtime(\true)

TMP

public mixed TMP = \sys_get_temp_dir() . \DS

WWW_ROOT

public mixed WWW_ROOT = \TEST_APP . 'webroot' . \DS

YEAR

public mixed YEAR = 31536000

Functions

debug()

Prints out debug information about given variable and returns the variable that was passed.

debug(mixed $var[, bool|null $showHtml = null ][, bool $showFrom = true ]) : mixed

Only runs if debug mode is enabled.

Parameters
$var : mixed

Variable to show debug information for.

$showHtml : bool|null = null

If set to true, the method prints the debug data in a browser-friendly way.

$showFrom : bool = true

If set to true, the method prints from where the function was called.

Tags
link
https://book.cakephp.org/4/en/development/debugging.html#basic-debugging
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#debug
Return values
mixed

The same $var that was passed

stackTrace()

Outputs a stack trace based on the supplied options.

stackTrace([array<string, mixed> $options = [] ]) : void

Options

  • depth - The number of stack frames to return. Defaults to 999
  • args - Should arguments for functions be shown? If true, the arguments for each method call will be displayed.
  • start - The stack frame to start generating a trace from. Defaults to 1
Parameters
$options : array<string, mixed> = []

Format for outputting stack trace

breakpoint()

Command to return the eval-able code to startup PsySH in interactive debugger Works the same way as eval(\Psy\sh()); psy/psysh must be loaded in your project

breakpoint() : string|null
eval(breakpoint());
Tags
link
https://psysh.org/
Return values
string|null

dd()

Prints out debug information about given variable and dies.

dd(mixed $var[, bool|null $showHtml = null ]) : void

Only runs if debug mode is enabled. It will otherwise just continue code execution and ignore this function.

Parameters
$var : mixed

Variable to show debug information for.

$showHtml : bool|null = null

If set to true, the method prints the debug data in a browser-friendly way.

Tags
link
https://book.cakephp.org/4/en/development/debugging.html#basic-debugging

collection()

Returns a new {@link \Cake\Collection\Collection} object wrapping the passed argument.

collection(iterable<string|int, mixed> $items) : Collection
Parameters
$items : iterable<string|int, mixed>

The items from which the collection will be built.

Return values
Collection

h()

Convenience method for htmlspecialchars.

h(mixed $text[, bool $double = true ][, string|null $charset = null ]) : mixed
Parameters
$text : mixed

Text to wrap through htmlspecialchars. Also works with arrays, and objects. Arrays will be mapped and have all their elements escaped. Objects will be string cast if they implement a __toString method. Otherwise, the class name will be used. Other scalar types will be returned unchanged.

$double : bool = true

Encode existing html entities.

$charset : string|null = null

Character set to use when escaping. Defaults to config value in mb_internal_encoding() or 'UTF-8'.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#h
Return values
mixed

Wrapped text.

pluginSplit()

Splits a dot syntax plugin name into its plugin and class name.

pluginSplit(string $name[, bool $dotAppend = false ][, string|null $plugin = null ]) : array<string|int, mixed>

If $name does not have a dot, then index 0 will be null.

Commonly used like

list($plugin, $name) = pluginSplit($name);
Parameters
$name : string

The name you want to plugin split.

$dotAppend : bool = false

Set to true if you want the plugin to have a '.' appended to it.

$plugin : string|null = null

Optional default plugin to use if no plugin is found. Defaults to null.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#pluginSplit
psalm-return

array{string|null, string}

Return values
array<string|int, mixed>

Array with 2 indexes. 0 => plugin name, 1 => class name.

namespaceSplit()

Split the namespace from the classname.

namespaceSplit(string $class) : array<string|int, string>

Commonly used like list($namespace, $className) = namespaceSplit($class);.

Parameters
$class : string

The full class name, ie Cake\Core\App.

Return values
array<string|int, string>

Array with 2 indexes. 0 => namespace, 1 => classname.

pr()

print_r() convenience function.

pr(mixed $var) : mixed

In terminals this will act similar to using print_r() directly, when not run on CLI print_r() will also wrap <pre> tags around the output of given variable. Similar to debug().

This function returns the same variable that was passed.

Parameters
$var : mixed

Variable to print out.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#pr
see
debug()
Return values
mixed

the same $var that was passed to this function

pj()

JSON pretty print convenience function.

pj(mixed $var) : mixed

In terminals this will act similar to using json_encode() with JSON_PRETTY_PRINT directly, when not run on CLI will also wrap <pre> tags around the output of given variable. Similar to pr().

This function returns the same variable that was passed.

Parameters
$var : mixed

Variable to print out.

Tags
see
pr()
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#pj
Return values
mixed

the same $var that was passed to this function

env()

Gets an environment variable from available sources, and provides emulation for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on IIS, or SCRIPT_NAME in CGI mode). Also exposes some additional custom environment information.

env(string $key[, string|bool|null $default = null ]) : string|bool|null
Parameters
$key : string

Environment variable name.

$default : string|bool|null = null

Specify a default value in case the environment variable is not defined.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#env
Return values
string|bool|null

Environment variable setting.

triggerWarning()

Triggers an E_USER_WARNING.

triggerWarning(string $message) : void
Parameters
$message : string

The warning message.

deprecationWarning()

Helper method for outputting deprecation warnings

deprecationWarning(string $message[, int $stackFrame = 1 ]) : void
Parameters
$message : string

The message to output as a deprecation warning.

$stackFrame : int = 1

The stack frame to include in the error. Defaults to 1 as that should point to application/plugin code.

getTypeName()

Returns the objects class or var type of it's not an object

getTypeName(mixed $var) : string
Parameters
$var : mixed

Variable to check

Return values
string

Returns the class name or variable type

__n()

Returns correct plural form of message identified by $singular and $plural for count $count.

__n(string $singular, string $plural, int $count, mixed ...$args) : string

Some languages have more than one form for plural messages dependent on the count.

Parameters
$singular : string

Singular text to translate.

$plural : string

Plural text.

$count : int

Count.

$args : mixed

Array with arguments or multiple arguments in function.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#__n
Return values
string

Plural form of translated string.

__dn()

Allows you to override the current domain for a single plural message lookup.

__dn(string $domain, string $singular, string $plural, int $count, mixed ...$args) : string

Returns correct plural form of message identified by $singular and $plural for count $count from domain $domain.

Parameters
$domain : string

Domain.

$singular : string

Singular string to translate.

$plural : string

Plural.

$count : int

Count.

$args : mixed

Array with arguments or multiple arguments in function.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#__dn
Return values
string

Plural form of translated string.

__x()

Returns a translated string if one is found; Otherwise, the submitted message.

__x(string $context, string $singular, mixed ...$args) : string

The context is a unique identifier for the translations string that makes it unique within the same domain.

Parameters
$context : string

Context of the text.

$singular : string

Text to translate.

$args : mixed

Array with arguments or multiple arguments in function.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#__x
Return values
string

Translated string.

__xn()

Returns correct plural form of message identified by $singular and $plural for count $count.

__xn(string $context, string $singular, string $plural, int $count, mixed ...$args) : string

Some languages have more than one form for plural messages dependent on the count. The context is a unique identifier for the translations string that makes it unique within the same domain.

Parameters
$context : string

Context of the text.

$singular : string

Singular text to translate.

$plural : string

Plural text.

$count : int

Count.

$args : mixed

Array with arguments or multiple arguments in function.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#__xn
Return values
string

Plural form of translated string.

__dx()

Allows you to override the current domain for a single message lookup.

__dx(string $domain, string $context, string $msg, mixed ...$args) : string

The context is a unique identifier for the translations string that makes it unique within the same domain.

Parameters
$domain : string

Domain.

$context : string

Context of the text.

$msg : string

String to translate.

$args : mixed

Array with arguments or multiple arguments in function.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#__dx
Return values
string

Translated string.

__dxn()

Returns correct plural form of message identified by $singular and $plural for count $count.

__dxn(string $domain, string $context, string $singular, string $plural, int $count, mixed ...$args) : string

Allows you to override the current domain for a single message lookup. The context is a unique identifier for the translations string that makes it unique within the same domain.

Parameters
$domain : string

Domain.

$context : string

Context of the text.

$singular : string

Singular text to translate.

$plural : string

Plural text.

$count : int

Count.

$args : mixed

Array with arguments or multiple arguments in function.

Tags
link
https://book.cakephp.org/4/en/core-libraries/global-constants-and-functions.html#__dxn
Return values
string

Plural form of translated string.

urlArray()

Returns an array URL from a route path string.

urlArray(string $path[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>
Parameters
$path : string

Route path.

$params : array<string|int, mixed> = []

An array specifying any additional parameters. Can be also any special parameters supported by Router::url().

Tags
see
Router::pathUrl()
Return values
array<string|int, mixed>

URL

Search results