Config\Adapter\Grouped
ClassSource on GitHubReads 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
ClassSource on GitHubReads 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
);Phalcon\Support\CollectionPhalcon\Config\ConfigPhalcon\Config\Adapter\Ini
Uses Phalcon\Config\Config · Phalcon\Config\Exception · Phalcon\Config\Exceptions\CannotLoadConfigFile · Phalcon\Traits\Php\IniTrait
Method Summary
public__construct(string$filePath,int$mode = 1)Ini constructor.protectedmixedcast( mixed$ini )We have to cast values manually because parse_ini_file() has a poorprotectedarraycastArray( array$ini )protectedarrayparseIniString(string$path,mixed$value)Build multidimensional array from stringMethods
__construct()
public function __construct(
string $filePath,
int $mode = 1
);Ini constructor.
cast()
protected function cast( mixed $ini ): mixed;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()
protected function castArray( array $ini ): array;parseIniString()
protected function parseIniString(
string $path,
mixed $value
): array;Build multidimensional array from string
Config\Adapter\Json
ClassSource on GitHubReads 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;Phalcon\Support\CollectionPhalcon\Config\ConfigPhalcon\Config\Adapter\Json
Uses Phalcon\Config\Config · Phalcon\Config\Exceptions\CannotLoadConfigFile · Phalcon\Support\Helper\Json\Decode · Phalcon\Traits\Php\FileTrait
Method Summary
Methods
__construct()
public function __construct( string $filePath );Phalcon\Config\Adapter\Json constructor
Config\Adapter\Php
ClassSource on GitHubReads 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()
public function __construct( string $filePath );Phalcon\Config\Adapter\Php constructor
Config\Adapter\Yaml
ClassSource on GitHubReads YAML files and converts them to Phalcon\Config\Config objects.
Given the following configuration file:
phalcon:
baseuri: /phalcon/
controllersDir: !approot /app/controllers/
models:
metadata: memoryYou 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 · Phalcon\Traits\Php\InfoTrait · Phalcon\Traits\Php\YamlTrait
Method Summary
Methods
__construct()
public function __construct(
string $filePath,
array $callbacks = null
);Phalcon\Config\Adapter\Yaml constructor
Config\Config
ClassSource on GitHubPhalcon\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
publicstringgetPathDelimiter()Gets the default path delimiterpublicConfigInterfacemerge( mixed$toMerge )Merges a configuration into the current onepublicmixedpath(string$path,mixed$defaultValue = null,string$delimiter = null)Returns a value from current config using a dot separated path.publicConfigInterfacesetPathDelimiter( string$delimiter = null )Sets the default path delimiterpublicarraytoArray()Converts recursively the object to an arrayprotectedstaticcloneEmpty( array$data = [] )Builds a new collection with the given data, carrying over theprotectedarrayinternalMerge(array$source,array$target)Performs a merge recursivelyprotectedvoidsetData(mixed$element,mixed$value)Sets the collection dataConstants
stringDEFAULT_PATH_DELIMITER = "."Properties
protectedstring$pathDelimiter = self::DEFAULT_PATH_DELIMITERMethods
getPathDelimiter()
public function getPathDelimiter(): string;Gets the default path delimiter
merge()
public function merge( mixed $toMerge ): ConfigInterface;Merges a configuration into the current one
$appConfig = new \Phalcon\Config\Config(
[
"database" => [
"host" => "localhost",
],
]
);
$globalConfig->merge($appConfig);path()
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", ".");setPathDelimiter()
public function setPathDelimiter( string $delimiter = null ): ConfigInterface;Sets the default path delimiter
toArray()
public function toArray(): array;Converts recursively the object to an array
print_r(
$config->toArray()
);cloneEmpty()
protected function cloneEmpty( array $data = [] ): static;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()
final protected function internalMerge(
array $source,
array $target
): array;Performs a merge recursively
setData()
protected function setData(
mixed $element,
mixed $value
): void;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
ClassSource on GitHubLoads 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.publicConfigInterfaceload( mixed$config )Load a config to create a new instancepublicConfigInterfacenewInstance(string$name,string$fileName,mixed$params = null)Returns a new Config instanceprotectedarraygetAdapterAliases()Adapter name aliases resolved by load() (file extensions that mapprotectedstringgetExceptionClass()protectedarraygetExtraArguments()Adapters accepting an extra constructor argument, with the configprotectedarraygetServices()Returns the available adaptersprotectedarrayparseConfig( mixed$config )Methods
__construct()
public function __construct( array $services = [] );ConfigFactory constructor.
load()
public function load( mixed $config ): ConfigInterface;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()
protected function getAdapterAliases(): array;Adapter name aliases resolved by load() (file extensions that map
to a registered adapter)
getExceptionClass()
protected function getExceptionClass(): string;getExtraArguments()
protected function getExtraArguments(): array;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()
protected function getServices(): array;Returns the available adapters
parseConfig()
protected function parseConfig( mixed $config ): array;Config\ConfigInterface
InterfaceSource on GitHubPhalcon\Config\ConfigInterface
Interface for Phalcon\Config\Config class
ArrayAccessPhalcon\Contracts\Support\CollectionPhalcon\Support\Collection\CollectionInterfacePhalcon\Config\ConfigInterface
Uses Phalcon\Support\Collection\CollectionInterface
Method Summary
publicstringgetPathDelimiter()publicConfigInterfacemerge( mixed$toMerge )publicmixedpath(string$path,mixed$defaultValue = null,string$delimiter = null)publicConfigInterfacesetPathDelimiter( string$delimiter = null )Methods
getPathDelimiter()
public function getPathDelimiter(): string;merge()
public function merge( mixed $toMerge ): ConfigInterface;path()
public function path(
string $path,
mixed $defaultValue = null,
string $delimiter = null
): mixed;setPathDelimiter()
public function setPathDelimiter( string $delimiter = null ): ConfigInterface;Config\Exception
ClassSource on GitHubExceptions 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
ClassSource on GitHub\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\CannotLoadConfigFile
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct( string $fileName );getFileName()
public function getFileName(): string;Config\Exceptions\ConfigNotArrayOrObject
ClassSource on GitHub\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\ConfigNotArrayOrObject
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\GroupedAdapterRequiresArray
ClassSource on GitHub\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\GroupedAdapterRequiresArray
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\InvalidMergeData
ClassSource on GitHub\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\InvalidMergeData
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\MissingConfigOption
ClassSource on GitHub\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingConfigOption
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct( string $option );getOption()
public function getOption(): string;Config\Exceptions\MissingFileExtension
ClassSource on GitHub\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingFileExtension
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\MissingYamlExtension
ClassSource on GitHub\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingYamlExtension
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();