Fr3nch13/CakePHP Utilities

PhpConfig
in package
implements ConfigEngineInterface uses FileConfigTrait

PHP engine allows Configure to load configuration values from files containing simple PHP arrays.

Files compatible with PhpConfig should return an array that contains all the configuration data contained in the file.

An example configuration file would look like::

<?php
return [
    'debug' => false,
    'Security' => [
        'salt' => 'its-secret'
    ],
    'App' => [
        'namespace' => 'App'
    ]
];
Tags
see
Configure::load()

for how to load custom configuration files.

Table of Contents

Interfaces

ConfigEngineInterface
An interface for creating objects compatible with Configure::load()

Properties

$_extension  : string
File extension.
$_path  : string
The path this engine finds files on.

Methods

__construct()  : mixed
Constructor for PHP Config file reading.
dump()  : bool
Converts the provided $data into a string of PHP code that can be used saved into a file and loaded later.
read()  : array<string|int, mixed>
Read a config file and return its contents.
_getFilePath()  : string
Get file path

Properties

$_extension

File extension.

protected string $_extension = '.php'

$_path

The path this engine finds files on.

protected string $_path = ''

Methods

__construct()

Constructor for PHP Config file reading.

public __construct([string|null $path = null ]) : mixed
Parameters
$path : string|null = null

The path to read config files from. Defaults to CONFIG.

dump()

Converts the provided $data into a string of PHP code that can be used saved into a file and loaded later.

public dump(string $key, array<string|int, mixed> $data) : bool
Parameters
$key : string

The identifier to write to. If the key has a . it will be treated as a plugin prefix.

$data : array<string|int, mixed>

Data to dump.

Return values
bool

Success

read()

Read a config file and return its contents.

public read(string $key) : array<string|int, mixed>

Files with . in the name will be treated as values in plugins. Instead of reading from the initialized path, plugin keys will be located using Plugin::path().

Parameters
$key : string

The identifier to read from. If the key has a . it will be treated as a plugin prefix.

Tags
throws
CakeException

when files don't exist or they don't contain $config. Or when files contain '..' as this could lead to abusive reads.

Return values
array<string|int, mixed>

Parsed configuration values.

_getFilePath()

Get file path

protected _getFilePath(string $key[, bool $checkExists = false ]) : string
Parameters
$key : string

The identifier to write to. If the key has a . it will be treated as a plugin prefix.

$checkExists : bool = false

Whether to check if file exists. Defaults to false.

Tags
throws
CakeException

When files don't exist or when files contain '..' as this could lead to abusive reads.

Return values
string

Full file path


        
On this page

Search results