Fr3nch13/CakePHP Utilities

functions.php

CakePHP(tm) : Rapid Development Framework (https://cakephp.org) Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)

Licensed under The MIT License For full copyright and license information, please see the LICENSE.txt Redistributions of files must retain the above copyright notice.

Tags
copyright

Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)

link

CakePHP(tm) Project

since
3.0.0
license

https://opensource.org/licenses/mit-license.php MIT License

Table of Contents

Constants

DS  = \DIRECTORY_SEPARATOR
Defines DS as short form of DIRECTORY_SEPARATOR.

Functions

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

Constants

DS

Defines DS as short form of DIRECTORY_SEPARATOR.

public mixed DS = \DIRECTORY_SEPARATOR

Functions

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


        
On this page

Search results