Phalcon config
NOTE
All classes are prefixed with Phalcon
Config\Adapter\Grouped¶
Class Source on GitHub
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",
],
],
],
);
Phalcon\Support\CollectionPhalcon\Config\ConfigPhalcon\Config\Adapter\Grouped
Uses Phalcon\Config\Config · Phalcon\Config\ConfigFactory · Phalcon\Config\ConfigInterface · Phalcon\Config\Exception · Phalcon\Config\Exceptions\GroupedAdapterRequiresArray · Phalcon\Factory\Exception
Method Summary¶
Methods¶
__construct()¶
public function __construct(
array $arrayConfig,
string $defaultAdapter = "php",
ConfigFactory $factory = null
);
Phalcon\Config\Adapter\Grouped constructor
Config\Adapter\Ini¶
Class Source on GitHub
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:
Phalcon\Support\CollectionPhalcon\Config\ConfigPhalcon\Config\Adapter\Ini
Uses Phalcon\Config\Config · Phalcon\Config\Exception · Phalcon\Config\Exceptions\CannotLoadConfigFile
Method Summary¶
public
__construct(string $filePath,int $mode = 1)
Ini constructor.
protected
mixed
cast( mixed $ini )
We have to cast values manually because parse_ini_file() has a poor
protected
array
castArray( array $ini )
protected
array
parseIniString(string $path,mixed $value)
Build multidimensional array from string
protected
phpParseIniFile(string $filename,bool $processSections = false,int $scannerMode = 1)
@todo to be removed when we get traits
Methods¶
__construct()¶
Ini constructor.
cast()¶
We have to cast values manually because parse_ini_file() has a poor implementation.
Note: this casting is an ini-format compensation and is deliberately
specific to this adapter. Ini files carry untyped strings, so
on/yes/true, off/no/false, null and numeric strings are decoded
here. The json, yaml and php adapters receive natively typed values
from their parsers and perform no casting.
castArray()¶
parseIniString()¶
Build multidimensional array from string
phpParseIniFile()¶
protected function phpParseIniFile(
string $filename,
bool $processSections = false,
int $scannerMode = 1
);
@todo to be removed when we get traits
Config\Adapter\Json¶
Class Source on GitHub
Reads JSON files and converts them to Phalcon\Config\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;
Phalcon\Support\CollectionPhalcon\Config\ConfigPhalcon\Config\Adapter\Json
Uses Phalcon\Config\Config · Phalcon\Config\Exceptions\CannotLoadConfigFile · Phalcon\Support\Helper\Json\Decode
Method Summary¶
Methods¶
__construct()¶
Phalcon\Config\Adapter\Json constructor
Config\Adapter\Php¶
Class Source on GitHub
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;
Phalcon\Support\CollectionPhalcon\Config\ConfigPhalcon\Config\Adapter\Php
Uses Phalcon\Config\Config · Phalcon\Config\Exceptions\CannotLoadConfigFile
Method Summary¶
Methods¶
__construct()¶
Phalcon\Config\Adapter\Php constructor
Config\Adapter\Yaml¶
Class Source on GitHub
Reads YAML files and converts them to Phalcon\Config\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;
Phalcon\Support\CollectionPhalcon\Config\ConfigPhalcon\Config\Adapter\Yaml
Uses Phalcon\Config\Config · Phalcon\Config\Exception · Phalcon\Config\Exceptions\CannotLoadConfigFile · Phalcon\Config\Exceptions\MissingYamlExtension
Method Summary¶
public
__construct(string $filePath,array $callbacks = null)
Phalcon\Config\Adapter\Yaml constructor
protected
bool
phpExtensionLoaded( string $name )
protected
phpYamlParseFile(mixed $filename,mixed $pos = 0,mixed $ndocs = null,mixed $callbacks = [])
@todo to be removed when we get traits
Methods¶
__construct()¶
Phalcon\Config\Adapter\Yaml constructor
phpExtensionLoaded()¶
phpYamlParseFile()¶
protected function phpYamlParseFile(
mixed $filename,
mixed $pos = 0,
mixed $ndocs = null,
mixed $callbacks = []
);
@todo to be removed when we get traits
Config\Config¶
Class Source on GitHub
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/",
],
]
);
Uses Phalcon\Config\Exceptions\InvalidMergeData · Phalcon\Support\Collection
Method Summary¶
public
string
getPathDelimiter()
Gets the default path delimiter
public
ConfigInterface
merge( mixed $toMerge )
Merges a configuration into the current one
public
mixed
path(string $path,mixed $defaultValue = null,string $delimiter = null)
Returns a value from current config using a dot separated path.
public
ConfigInterface
setPathDelimiter( string $delimiter = null )
Sets the default path delimiter
public
array
toArray()
Converts recursively the object to an array
protected
static
cloneEmpty( array $data = [] )
Builds a new collection with the given data, carrying over the
protected
array
internalMerge(array $source,array $target)
Performs a merge recursively
protected
void
setData(mixed $element,mixed $value)
Sets the collection data
Constants¶
string
DEFAULT_PATH_DELIMITER = "."
Properties¶
protected
string
$pathDelimiter = self::DEFAULT_PATH_DELIMITER
Methods¶
getPathDelimiter()¶
Gets the default path delimiter
merge()¶
Merges a configuration into the current one
$appConfig = new \Phalcon\Config\Config(
[
"database" => [
"host" => "localhost",
],
]
);
$globalConfig->merge($appConfig);
path()¶
Returns a value from current config using a dot separated path.
setPathDelimiter()¶
Sets the default path delimiter
toArray()¶
Converts recursively the object to an array
cloneEmpty()¶
Builds a new collection with the given data, carrying over the
configuration of the current one. Clone-based instead of
constructor-based: adapter subclasses (Ini, Json, Php, Yaml, Grouped)
define file-loading constructors that are incompatible with the
parent's (array data, ...) signature, so filter(), map(),
sort() and where() would otherwise fail on any adapter instance.
internalMerge()¶
Performs a merge recursively
setData()¶
Sets the collection data
Array values become nested Config objects carrying the insensitive,
strictNull and type flags of this instance. The type guard is
applied to leaf values only - arrays are not validated themselves;
the nested Config validates its own leaves.
Config\ConfigFactory¶
Class Source on GitHub
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);
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Config\ConfigFactory
Uses Phalcon\Config\Config · Phalcon\Config\ConfigInterface · Phalcon\Config\Exceptions\ConfigNotArrayOrObject · Phalcon\Config\Exceptions\MissingConfigOption · Phalcon\Config\Exceptions\MissingFileExtension · Phalcon\Factory\AbstractFactory
Method Summary¶
public
__construct( array $services = [] )
ConfigFactory constructor.
public
ConfigInterface
load( mixed $config )
Load a config to create a new instance
public
ConfigInterface
newInstance(string $name,string $fileName,mixed $params = null)
Returns a new Config instance
protected
array
getAdapterAliases()
Adapter name aliases resolved by load() (file extensions that map
protected
string
getExceptionClass()
protected
array
getExtraArguments()
Adapters accepting an extra constructor argument, with the config
protected
array
getServices()
Returns the available adapters
protected
array
parseConfig( mixed $config )
Methods¶
__construct()¶
ConfigFactory constructor.
load()¶
Load a config to create a new instance
newInstance()¶
public function newInstance(
string $name,
string $fileName,
mixed $params = null
): ConfigInterface;
Returns a new Config instance
getAdapterAliases()¶
Adapter name aliases resolved by load() (file extensions that map
to a registered adapter)
getExceptionClass()¶
getExtraArguments()¶
Adapters accepting an extra constructor argument, with the config
option carrying it and its default value. Single source for the
parameter-forwarding knowledge used by load() and newInstance().
getServices()¶
Returns the available adapters
parseConfig()¶
Config\ConfigInterface¶
Interface Source on GitHub
Phalcon\Config\ConfigInterface
Interface for Phalcon\Config\Config class
ArrayAccessPhalcon\Contracts\Support\CollectionPhalcon\Support\Collection\CollectionInterfacePhalcon\Config\ConfigInterface
Uses Phalcon\Support\Collection\CollectionInterface
Method Summary¶
public
string
getPathDelimiter()
public
ConfigInterface
merge( mixed $toMerge )
public
mixed
path(string $path,mixed $defaultValue = null,string $delimiter = null)
public
ConfigInterface
setPathDelimiter( string $delimiter = null )
Methods¶
getPathDelimiter()¶
merge()¶
path()¶
setPathDelimiter()¶
Config\Exception¶
Class Source on GitHub
Exceptions thrown in Phalcon\Config will use this class
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\CannotLoadConfigFilePhalcon\Config\Exceptions\ConfigNotArrayOrObjectPhalcon\Config\Exceptions\GroupedAdapterRequiresArrayPhalcon\Config\Exceptions\InvalidMergeDataPhalcon\Config\Exceptions\MissingConfigOptionPhalcon\Config\Exceptions\MissingFileExtensionPhalcon\Config\Exceptions\MissingYamlExtension
Config\Exceptions\CannotLoadConfigFile¶
Class Source on GitHub
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\CannotLoadConfigFile
Uses Phalcon\Config\Exception
Method Summary¶
Methods¶
__construct()¶
getFileName()¶
Config\Exceptions\ConfigNotArrayOrObject¶
Class Source on GitHub
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\ConfigNotArrayOrObject
Uses Phalcon\Config\Exception
Method Summary¶
Methods¶
__construct()¶
Config\Exceptions\GroupedAdapterRequiresArray¶
Class Source on GitHub
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\GroupedAdapterRequiresArray
Uses Phalcon\Config\Exception
Method Summary¶
Methods¶
__construct()¶
Config\Exceptions\InvalidMergeData¶
Class Source on GitHub
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\InvalidMergeData
Uses Phalcon\Config\Exception
Method Summary¶
Methods¶
__construct()¶
Config\Exceptions\MissingConfigOption¶
Class Source on GitHub
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingConfigOption
Uses Phalcon\Config\Exception
Method Summary¶
Methods¶
__construct()¶
getOption()¶
Config\Exceptions\MissingFileExtension¶
Class Source on GitHub
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingFileExtension
Uses Phalcon\Config\Exception
Method Summary¶
Methods¶
__construct()¶
Config\Exceptions\MissingYamlExtension¶
Class Source on GitHub
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingYamlExtension
Uses Phalcon\Config\Exception