- Phalcon\Config
- Phalcon\Config\Adapter\Grouped
- Phalcon\Config\Adapter\Ini
- Phalcon\Config\Adapter\Json
- Phalcon\Config\Adapter\Php
- Phalcon\Config\Adapter\Yaml
- Phalcon\Config\ConfigFactory
- Phalcon\Config\ConfigInterface
- Phalcon\Config\Exception
Class Phalcon\Config
| Namespace | Phalcon | | Uses | Phalcon\Collection, Phalcon\Config\ConfigInterface, Phalcon\Config\Exception | | 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(
[
"database" => [
"adapter" => "Mysql",
"host" => "localhost",
"username" => "scott",
"password" => "cheetah",
"dbname" => "test_db",
],
"phalcon" => [
"controllersDir" => "../app/controllers/",
"modelsDir" => "../app/models/",
"viewsDir" => "../app/views/",
],
]
);
Constants¶
Properties¶
Methods¶
Gets the default path delimiter Merges a configuration into the current one$appConfig = new \Phalcon\Config(
[
"database" => [
"host" => "localhost",
],
]
);
$globalConfig->merge($appConfig);
public function path( string $path, mixed $defaultValue = null, mixed $delimiter = null ): mixed | null;
Class Phalcon\Config\Adapter\Grouped
| Namespace | Phalcon\Config\Adapter | | Uses | Phalcon\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\Factory::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",
],
],
],
);
Methods¶
Phalcon\Config\Adapter\Grouped constructorClass Phalcon\Config\Adapter\Ini
| Namespace | Phalcon\Config\Adapter | | Uses | Phalcon\Config, Phalcon\Config\Exception | | Extends | Config |
Reads ini files and converts them to Phalcon\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:
Methods¶
Ini constructor. We have to cast values manually because parse_ini_file() has a poor implementation. Build multidimensional array from stringClass Phalcon\Config\Adapter\Json
| Namespace | Phalcon\Config\Adapter | | Uses | Phalcon\Config, Phalcon\Helper\Json | | Extends | Config |
Reads JSON files and converts them to Phalcon\Config objects.
Given the following configuration file:
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;
Methods¶
Phalcon\Config\Adapter\Json constructorClass Phalcon\Config\Adapter\Php
| Namespace | Phalcon\Config\Adapter | | Uses | Phalcon\Config | | Extends | Config |
Reads php files and converts them to Phalcon\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;
Methods¶
Phalcon\Config\Adapter\Php constructorClass Phalcon\Config\Adapter\Yaml
| Namespace | Phalcon\Config\Adapter | | Uses | Phalcon\Config, Phalcon\Config\Exception | | Extends | Config |
Reads YAML files and converts them to Phalcon\Config objects.
Given the following configuration file:
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;
Methods¶
Phalcon\Config\Adapter\Yaml constructorClass Phalcon\Config\ConfigFactory
| Namespace | Phalcon\Config | | Uses | Phalcon\Config, Phalcon\Config\ConfigInterface, Phalcon\Factory\AbstractFactory, Phalcon\Helper\Arr | | 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);
Methods¶
ConfigFactory constructor. Load a config to create a new instancepublic function newInstance( string $name, string $fileName, mixed $params = null ): ConfigInterface;
Interface Phalcon\Config\ConfigInterface
| Namespace | Phalcon\Config | | Uses | Phalcon\Collection\CollectionInterface | | Extends | CollectionInterface |
Phalcon\Config\ConfigInterface
Interface for Phalcon\Config class
Methods¶
public function path( string $path, mixed $defaultValue = null, mixed $delimiter = null ): mixed | null;
Class Phalcon\Config\Exception
| Namespace | Phalcon\Config | | Extends | \Phalcon\Exception |
Exceptions thrown in Phalcon\Config will use this class