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"
);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
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 stringprotectedphpParseIniFile(string$filename,bool$processSections = false,int$scannerMode = 1)@todo to be removed when we get traitsMethods
__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.
castArray()
protected function castArray( array $ini ): array;parseIniString()
protected function parseIniString(
string $path,
mixed $value
): array;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
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\Support\Helper\Json\Decode
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
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
Method Summary
public__construct(string$filePath,array$callbacks = null)Phalcon\Config\Adapter\Yaml constructorprotectedboolphpExtensionLoaded( string$name )protectedphpYamlParseFile(mixed$filename,mixed$pos = 0,mixed$ndocs = null,mixed$callbacks = [])@todo to be removed when we get traitsMethods
__construct()
public function __construct(
string $filePath,
array $callbacks = null
);Phalcon\Config\Adapter\Yaml constructor
phpExtensionLoaded()
protected function phpExtensionLoaded( string $name ): bool;phpYamlParseFile()
protected function phpYamlParseFile(
mixed $filename,
mixed $pos = 0,
mixed $ndocs = null,
mixed $callbacks = []
);@todo to be removed when we get traits
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 arrayprotectedarrayinternalMerge(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()
);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
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 instanceprotectedstringgetExceptionClass()protectedarraygetServices()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
getExceptionClass()
protected function getExceptionClass(): string;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 GitHubThis file is part of the Phalcon Framework.
(c) Phalcon Team <[email protected]>
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
\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 GitHubThis file is part of the Phalcon Framework.
(c) Phalcon Team <[email protected]>
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\ConfigNotArrayOrObject
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\GroupedAdapterRequiresArray
ClassSource on GitHubThis file is part of the Phalcon Framework.
(c) Phalcon Team <[email protected]>
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\GroupedAdapterRequiresArray
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\InvalidMergeData
ClassSource on GitHubThis file is part of the Phalcon Framework.
(c) Phalcon Team <[email protected]>
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\InvalidMergeData
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\MissingConfigOption
ClassSource on GitHubThis file is part of the Phalcon Framework.
(c) Phalcon Team <[email protected]>
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
\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 GitHubThis file is part of the Phalcon Framework.
(c) Phalcon Team <[email protected]>
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingFileExtension
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();Config\Exceptions\MissingYamlExtension
ClassSource on GitHubThis file is part of the Phalcon Framework.
(c) Phalcon Team <[email protected]>
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
\ExceptionPhalcon\Config\ExceptionPhalcon\Config\Exceptions\MissingYamlExtension
Uses Phalcon\Config\Exception
Method Summary
Methods
__construct()
public function __construct();