Constants

$name

$name

CONTENT_EXTENSION

CONTENT_EXTENSION

CORE_LOCALE

CORE_LOCALE

ROLE_ID_ADMINISTRATOR

ROLE_ID_ADMINISTRATOR

ID for "administrator" role, must match the ID stored in DB. You should never change this value on production site.

ROLE_ID_AUTHENTICATED

ROLE_ID_AUTHENTICATED

ID for "authenticated" role, must match the ID stored in DB. You should never change this value on production site.

ROLE_ID_ANONYMOUS

ROLE_ID_ANONYMOUS

ID for "anonymous" role, must match the ID stored in DB. You should never change this value on production site.

USER_TOKEN_EXPIRATION

USER_TOKEN_EXPIRATION

How much time user tokens are valid. Defaults to 24 hours.

Functions

snapshot()

snapshot() : void

Stores some bootstrap-handy information into a persistent file.

Information is stored in TMP/snapshot.php file, it contains useful information such as enabled languages, content types slugs, installed plugins, etc.

You can read this information using Configure::read() as follow:

Configure::read('QuickApps.<option>');

Or using the quickapps() global function:

quickapps('<option>');

normalizePath()

normalizePath(string $path, string $ds) : string

Normalizes the given file system path, makes sure that all DIRECTORY_SEPARATOR are the same, so you won't get a mix of "/" and "\" in your paths.

Example:

normalizePath('/some/path\to/some\\thing\about.zip');
// output: /some/path/to/some/thing/about.zip

You can indicate which "directory separator" symbol to use using the second argument:

normalizePath('/some/path\to//some\thing\about.zip', '\');
// output: \some\path\to\some\thing\about.zip

By defaults uses DIRECTORY_SEPARATOR as symbol.

Parameters

string $path

The path to normalize

string $ds

Directory separator character, defaults to DIRECTORY_SEPARATOR

Returns

string —

Normalized $path

quickapps()

quickapps(string $key) : mixed

Shortcut for reading QuickApps's snapshot configuration.

For example, quickapps('variables'); maps to Configure::read('QuickApps.variables');. If this function is used with no arguments, quickapps(), the entire snapshot will be returned.

Parameters

string $key

The key to read from snapshot, or null to read the whole snapshot's info

Returns

mixed

option()

option(string $name, mixed $default) : mixed

Shortcut for getting an option value from "options" DB table.

The second arguments, $default, is used as default value to return if no value is found. If not value is found and not default values was given this function will return false.

Example:

option('site_slogan');

Parameters

string $name

Name of the option to retrieve. e.g. front_theme, default_language, site_slogan, etc

mixed $default

The default value to return if no value is found

Returns

mixed —

Current value for the specified option. If the specified option does not exist, returns boolean FALSE

plugin()

plugin(string $plugin) : \QuickApps\Core\Package\PluginPackage|\Cake\Collection\Collection

Shortcut for "Plugin::get()".

Example:

$specialSetting = plugin('MyPlugin')->settings['special_setting'];

Parameters

string $plugin

Plugin name to get, or null to get a collection of all plugin objects

Throws

\Cake\Error\FatalErrorException

When requested plugin was not found

Returns

\QuickApps\Core\Package\PluginPackage|\Cake\Collection\Collection

theme()

theme(string|null $name) : \QuickApps\Core\Package\PluginPackage

Gets the given (or in use) theme as a package object.

Example:

// current theme
$bgColor = theme()->settings['background_color'];

// specific theme
$bgColor = theme('BlueTheme')->settings['background_color'];

Parameters

string|null $name

Name of the theme to get, or null to get the theme being used in current request

Throws

\Cake\Error\FatalErrorException

When theme could not be found

Returns

\QuickApps\Core\Package\PluginPackage

listeners()

listeners(\Cake\Event\EventManager\null $manager) : array

Returns a list of all registered event listeners within the provided event manager, or within the global manager if not provided.

Parameters

\Cake\Event\EventManager\null $manager

Event manager instance, or null to use global manager instance.

Returns

array

packageSplit()

packageSplit(string $name, boolean $camelize) : array

Splits a composer package syntax into its vendor and package name.

Commonly used like list($vendor, $package) = packageSplit($name);

Example:

list($vendor, $package) = packageSplit('some-vendor/this-package', true);
echo "{$vendor} : {$package}";
// prints: SomeVendor : ThisPackage

Parameters

string $name

Package name. e.g. author-name/package-name

boolean $camelize

Set to true to Camelize each part

Returns

array —

Array with 2 indexes. 0 => vendor name, 1 => package name.

normalizeLocale()

normalizeLocale(string $locale) : string

Normalizes the given locale code.

Parameters

string $locale

The locale code to normalize. e.g. en-US

Returns

string —

Normalized code. e.g. en_US

aspects()

aspects() : array

Gets a list of all active aspect classes.

Returns

array

localeSplit()

localeSplit(string $localeId) : array

Parses and splits the given locale code and returns its parts: language and regional codes.

Example:

list($language, $region) = localeSplit('en_NZ');

IMPORTANT: Note that region code may be an empty string.

Parameters

string $localeId

Locale code. e.g. "en_NZ" (or "en-NZ") for "English New Zealand"

Returns

array —

Array with 2 indexes. 0 => language code, 1 => country code.

array_move()

array_move(array $list, integer $index, string $direction) : array

Moves up or down the given element by index from a list array of elements.

If item could not be moved, the original list will be returned. Valid values for $direction are up or down.

Example:

array_move(['a', 'b', 'c'], 1, 'up');
// returns: ['a', 'c', 'b']

Parameters

array $list

Numeric indexed array list of elements

integer $index

The index position of the element you want to move

string $direction

Direction, 'up' or 'down'

Returns

array —

Reordered original list.

php_eval()

php_eval(string $code, array $args) : string

Evaluate a string of PHP code.

This is a wrapper around PHP's eval(). It uses output buffering to capture both returned and printed text. Unlike eval(), we require code to be surrounded by <?php ?> tags; in other words, we evaluate the code as if it were a stand-alone PHP file.

Using this wrapper also ensures that the PHP code which is evaluated can not overwrite any variables in the calling code, unlike a regular eval() call.

Usage:

echo php_eval('<?php return "Hello {$world}!"; ?>', ['world' => 'WORLD']);
// output: Hello WORLD

Parameters

string $code

The code to evaluate

array $args

Array of arguments as key => value pairs, evaluated code can access this variables

Returns

string

get_this_class_methods()

get_this_class_methods(string $class) : array

Return only the methods for the given object. It will strip out inherited methods.

Parameters

string $class

Class name

Returns

array —

List of methods

str_replace_once()

str_replace_once(string|array $search, string $replace, string $subject) : string

Replace the first occurrence only.

Example:

echo str_replace_once('A', 'a', 'AAABBBCCC');
// out: aAABBBCCC

Parameters

string|array $search

The value being searched for

string $replace

The replacement value that replaces found search value

string $subject

The string being searched and replaced on

Returns

string —

A string with the replaced value

str_replace_last()

str_replace_last(string|array $search, string $replace, string $subject) : string

Replace the last occurrence only.

Example:

echo str_replace_once('A', 'a', 'AAABBBCCC');
// out: AAaBBBCCC

Parameters

string|array $search

The value being searched for

string $replace

The replacement value that replaces found search value

string $subject

The string being searched and replaced on

Returns

string —

A string with the replaced value

str_starts_with()

str_starts_with(string $haystack, string $needle) : boolean

Check if $haystack string starts with $needle string.

Example:

str_starts_with('lorem ipsum', 'lo'); // true
str_starts_with('lorem ipsum', 'ipsum'); // false

Parameters

string $haystack
string $needle

Returns

boolean

str_ends_with()

str_ends_with(string $haystack, string $needle) : boolean

Check if $haystack string ends with $needle string.

Example:

str_ends_with('lorem ipsum', 'm'); // true
str_ends_with('dolorem sit amet', 'at'); // false

Parameters

string $haystack
string $needle

Returns

boolean

tryDefine()

tryDefine(string $name, string $value) : void

Tries to define the given constant if not defined already.

Parameters

string $name

Constant name

string $value

Constant value

fieldsInfo()

fieldsInfo(string|null $field) : \Cake\Collection\Collection|array

Gets a collection of information of every registered field in the system, or information for a particular field.

Some fields may register themselves as hidden when they are intended to be used exclusively by plugins. So users can not attach them to entities using Field UI.

Usage:

$visibleOnly = fieldsInfo()->filter(function ($info) {
    return !$info['hidden'];
});

Parameters

string|null $field

Field for which get its information as an array, or null (default) to get all of them as a collection.

Returns

\Cake\Collection\Collection|array —

A collection of fields information

language()

language(string|null $key) : mixed

Retrieves information for current language.

Useful when you need to read current language's code, language's direction, etc. It will returns all the information if no $key is given.

Usage:

language('code');
// may return: en

language();
// may return:
[
    'name' => 'English (US)',
    'locale' => 'en_US',
    'code' => 'en',
    'country' => 'US',
    'direction' => 'ltr',
    'icon' => 'us.gif',
]

Accepted keys are:

  • name: Language's name, e.g. English, Spanish, etc.
  • locale: Full localized language's code, e.g. en-US, es, etc.
  • code: Language's ISO 639-1 code, e.g. en, es, fr, etc. (lowercase)
  • country: Language's country code, e.g. US, ES, FR, etc. (uppercase)
  • direction: Language writing direction, possible values are "ltr" or "rtl".
  • icon: Flag icon (it may be empty) e.g. es.gif, es.gif, icons files are located in Locale plugin's /webroot/img/flags/ directory, to render an icon using HtmlHelper you should do as follow:
<?php echo $this->Html->image('Locale.flags/' . language('icon')); ?>

Parameters

string|null $key

The key to read, or null to read the whole info

Returns

mixed

stripLanguagePrefix()

stripLanguagePrefix(string $url) : string

Strips language prefix from the given URL.

For instance, /en_US/article/my-first-article.html becomes /article/my-first-article.html.

Parameters

string $url

The URL

Returns

string —

New URL

user()

user() : \User\Model\Entity\UserSession

Retrieves current user's information (logged in or not) as an entity object.

Usage:

$user = user();
echo user()->name;
// prints "Anonymous" if not logged in

Returns

\User\Model\Entity\UserSession