Class Phalcon\Config\Adapter\Grouped
Source sur GitHub
Namespace |
Phalcon\Config\Adapter |
|
Uses |
Phalcon\Config\Config, Phalcon\Config\ConfigFactory, Phalcon\Config\ConfigInterface, Phalcon\Config\Exception, Phalcon\Factory\Exception |
|
Extends |
Config |
Reads multiple files (or arrays) and merges them all together.
See Phalcon\Config\ConfigFactory::load
To load Config Adapter class using ‘adapter’ option.
use Phalcon\Config\Adapter\Grouped;
$config = new Grouped(
[
"path/to/config.php",
"path/to/config.dist.php",
]
);
use Phalcon\Config\Adapter\Grouped;
$config = new Grouped(
[
"path/to/config.json",
"path/to/config.dist.json",
],
"json"
);
use Phalcon\Config\Adapter\Grouped;
$config = new Grouped(
[
[
"filePath" => "path/to/config.php",
"adapter" => "php",
],
[
"filePath" => "path/to/config.json",
"adapter" => "json",
],
[
"adapter" => "array",
"config" => [
"property" => "value",
],
],
],
);
Méthodes
public function __construct( array $arrayConfig, string $defaultAdapter = string );
Phalcon\Config\Adapter\Grouped constructor
Class Phalcon\Config\Adapter\Ini
Source sur GitHub
Namespace |
Phalcon\Config\Adapter |
|
Uses |
Phalcon\Config\Config, Phalcon\Config\Exception, Phalcon\Support\Traits\PhpFileTrait |
|
Extends |
Config |
Reads ini files and converts them to Phalcon\Config\Config objects.
Given the next configuration file:
[database]
adapter = Mysql
host = localhost
username = scott
password = cheetah
dbname = test_db
[phalcon]
controllersDir = "../app/controllers/"
modelsDir = "../app/models/"
viewsDir = "../app/views/"
You can read it as follows:
use Phalcon\Config\Adapter\Ini;
$config = new Ini("path/config.ini");
echo $config->phalcon->controllersDir;
echo $config->database->username;
PHP constants may also be parsed in the ini file, so if you define a constant as an ini value before calling the constructor, the constant’s value will be integrated into the results. To use it this way you must specify the optional second parameter as INI_SCANNER_NORMAL
when calling the constructor:
$config = new \Phalcon\Config\Adapter\Ini(
"path/config-with-constants.ini",
INI_SCANNER_NORMAL
);
Méthodes
public function __construct( string $filePath, int $mode = int );
Ini constructor.
protected function cast( mixed $ini ): bool | null | double | int | string;
We have to cast values manually because parse_ini_file() has a poor implementation.
protected function castArray( array $ini ): array;
protected function parseIniString( string $path, mixed $value ): array;
Build multidimensional array from string
protected function phpParseIniFile( string $filename, bool $processSections = bool, int $scannerMode = int );
@todo to be removed when we get traits
Class Phalcon\Config\Adapter\Json
Source sur GitHub
Namespace |
Phalcon\Config\Adapter |
|
Uses |
InvalidArgumentException, Phalcon\Config\Config |
|
Extends |
Config |
Reads JSON files and converts them to Phalcon\Config\Config objects.
Given the following configuration file:
{"phalcon":{"baseuri":"\/phalcon\/"},"models":{"metadata":"memory"}}
You can read it as follows:
use Phalcon\Config\Adapter\Json;
$config = new Json("path/config.json");
echo $config->phalcon->baseuri;
echo $config->models->metadata;
Méthodes
public function __construct( string $filePath );
Phalcon\Config\Adapter\Json constructor
Class Phalcon\Config\Adapter\Php
Source sur GitHub
Namespace |
Phalcon\Config\Adapter |
|
Uses |
Phalcon\Config\Config |
|
Extends |
Config |
Reads php files and converts them to Phalcon\Config\Config objects.
Given the next configuration file:
<?php
return [
"database" => [
"adapter" => "Mysql",
"host" => "localhost",
"username" => "scott",
"password" => "cheetah",
"dbname" => "test_db",
],
"phalcon" => [
"controllersDir" => "../app/controllers/",
"modelsDir" => "../app/models/",
"viewsDir" => "../app/views/",
],
];
You can read it as follows:
use Phalcon\Config\Adapter\Php;
$config = new Php("path/config.php");
echo $config->phalcon->controllersDir;
echo $config->database->username;
Méthodes
public function __construct( string $filePath );
Phalcon\Config\Adapter\Php constructor
Class Phalcon\Config\Adapter\Yaml
Source sur GitHub
Namespace |
Phalcon\Config\Adapter |
|
Uses |
Phalcon\Config\Config, Phalcon\Config\Exception |
|
Extends |
Config |
Reads YAML files and converts them to Phalcon\Config\Config objects.
Given the following configuration file:
phalcon:
baseuri: /phalcon/
controllersDir: !approot /app/controllers/
models:
metadata: memory
You can read it as follows:
define(
"APPROOT",
dirname(__DIR__)
);
use Phalcon\Config\Adapter\Yaml;
$config = new Yaml(
"path/config.yaml",
[
"!approot" => function($value) {
return APPROOT . $value;
},
]
);
echo $config->phalcon->controllersDir;
echo $config->phalcon->baseuri;
echo $config->models->metadata;
Méthodes
public function __construct( string $filePath, array $callbacks = null );
Phalcon\Config\Adapter\Yaml constructor
protected function phpExtensionLoaded( string $name ): bool;
protected function phpYamlParseFile( mixed $filename, mixed $pos = int, mixed $ndocs = null, mixed $callbacks = [] );
@todo to be removed when we get traits
Class Phalcon\Config\Config
Source sur GitHub
Namespace |
Phalcon\Config |
|
Uses |
Phalcon\Support\Collection |
|
Extends |
Collection |
|
Implements |
ConfigInterface |
Phalcon\Config
is designed to simplify the access to, and the use of, configuration data within applications. It provides a nested object property based user interface for accessing this configuration data within application code.
$config = new \Phalcon\Config\Config(
[
"database" => [
"adapter" => "Mysql",
"host" => "localhost",
"username" => "scott",
"password" => "cheetah",
"dbname" => "test_db",
],
"phalcon" => [
"controllersDir" => "../app/controllers/",
"modelsDir" => "../app/models/",
"viewsDir" => "../app/views/",
],
]
);
Constants
const DEFAULT_PATH_DELIMITER = .;
Properties
/**
* @var string
*/
protected pathDelimiter;
Méthodes
public function getPathDelimiter(): string;
Gets the default path delimiter
public function merge( mixed $toMerge ): ConfigInterface;
Merges a configuration into the current one
$appConfig = new \Phalcon\Config\Config(
[
"database" => [
"host" => "localhost",
],
]
);
$globalConfig->merge($appConfig);
public function path( string $path, mixed $defaultValue = null, string $delimiter = null ): mixed;
Returns a value from current config using a dot separated path.
echo $config->path("unknown.path", "default", ".");
public function setPathDelimiter( string $delimiter = null ): ConfigInterface;
Sets the default path delimiter
public function toArray(): array;
Converts recursively the object to an array
print_r(
$config->toArray()
);
final protected function internalMerge( array $source, array $target ): array;
Performs a merge recursively
protected function setData( mixed $element, mixed $value ): void;
Sets the collection data
Class Phalcon\Config\ConfigFactory
Source sur GitHub
Namespace |
Phalcon\Config |
|
Uses |
Phalcon\Config\Config, Phalcon\Config\ConfigInterface, Phalcon\Factory\AbstractFactory |
|
Extends |
AbstractFactory |
Loads Config Adapter class using ‘adapter’ option, if no extension is provided it will be added to filePath
use Phalcon\Config\ConfigFactory;
$options = [
"filePath" => "path/config",
"adapter" => "php",
];
$config = (new ConfigFactory())->load($options);
Méthodes
public function __construct( array $services = [] );
ConfigFactory constructor.
public function load( mixed $config ): ConfigInterface;
Load a config to create a new instance
public function newInstance( string $name, string $fileName, mixed $params = null ): ConfigInterface;
Returns a new Config instance
protected function getExceptionClass(): string;
protected function getServices(): array;
Returns the available adapters
protected function parseConfig( mixed $config ): array;
Interface Phalcon\Config\ConfigInterface
Source sur GitHub
Namespace |
Phalcon\Config |
|
Uses |
Phalcon\Support\Collection\CollectionInterface |
|
Extends |
CollectionInterface |
Phalcon\Config\ConfigInterface
Interface for Phalcon\Config\Config class
Méthodes
public function getPathDelimiter(): string;
public function merge( mixed $toMerge ): ConfigInterface;
public function path( string $path, mixed $defaultValue = null, string $delimiter = null ): mixed;
public function setPathDelimiter( string $delimiter = null ): ConfigInterface;
Class Phalcon\Config\Exception
Source sur GitHub
Namespace |
Phalcon\Config |
|
Extends |
\Exception |
Exceptions thrown in Phalcon\Config will use this class