Secciones

Class Phalcon\Config\Adapter\Grouped

Código fuente en GitHub

Namespace Phalcon\Config\Adapter   Uses Phalcon\Config\Config, Phalcon\Config\ConfigFactory, Phalcon\Config\ConfigInterface, Phalcon\Config\Exception, Phalcon\Factory\Exception   Extends Config

Lee múltiples ficheros (o vectores) y los combina todos juntos.

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étodos

public function __construct( array $arrayConfig, string $defaultAdapter = string );

Constructor Phalcon\Config\Adapter\Grouped

Class Phalcon\Config\Adapter\Ini

Código fuente en 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.

Dado el siguiente fichero de configuración:

[database]
adapter = Mysql
host = localhost
username = scott
password = cheetah
dbname = test_db

[phalcon]
controllersDir = "../app/controllers/"
modelsDir = "../app/models/"
viewsDir = "../app/views/"

Puede leerlo de la siguiente manera:

use Phalcon\Config\Adapter\Ini;

$config = new Ini("path/config.ini");

echo $config->phalcon->controllersDir;
echo $config->database->username;

Las constantes PHP también se pueden analizar en el fichero ini, así que si define una constante como un valor ini antes de llamar al constructor, el valor de la constante será integrada en los resultados. Para usarlo de esta forma debe especificar el segundo parámetro opcional como INI_SCANNER_NORMAL cuando llame al constructor:

$config = new \Phalcon\Config\Adapter\Ini(
    "path/config-with-constants.ini",
    INI_SCANNER_NORMAL
);

Métodos

public function __construct( string $filePath, int $mode = int );

Constructor Ini.

protected function cast( mixed $ini ): bool | null | double | int | string;

Tenemos que convertir valores manualmente porque parse_ini_file() tiene una implementación pobre.

protected function castArray( array $ini ): array;
protected function parseIniString( string $path, mixed $value ): array;

Construye un vector multidimensional desde una cadena

protected function phpParseIniFile( string $filename, bool $processSections = bool, int $scannerMode = int );

@todo to be removed when we get traits

Class Phalcon\Config\Adapter\Json

Código fuente en GitHub

Namespace Phalcon\Config\Adapter   Uses Phalcon\Config\Config, Phalcon\Support\Helper\Json\Decode   Extends Config

Reads JSON files and converts them to Phalcon\Config\Config objects.

Dado el siguiente fichero de configuración:

{"phalcon":{"baseuri":"\/phalcon\/"},"models":{"metadata":"memory"}}

Puede leerlo de la siguiente manera:

use Phalcon\Config\Adapter\Json;

$config = new Json("path/config.json");

echo $config->phalcon->baseuri;
echo $config->models->metadata;

Métodos

public function __construct( string $filePath );

Constructor Phalcon\Config\Adapter\Json

Class Phalcon\Config\Adapter\Php

Código fuente en GitHub

Namespace Phalcon\Config\Adapter   Uses Phalcon\Config\Config   Extends Config

Reads php files and converts them to Phalcon\Config\Config objects.

Dado el siguiente fichero de configuración:

<?php

return [
    "database" => [
        "adapter"  => "Mysql",
        "host"     => "localhost",
        "username" => "scott",
        "password" => "cheetah",
        "dbname"   => "test_db",
    ],
    "phalcon" => [
        "controllersDir" => "../app/controllers/",
        "modelsDir"      => "../app/models/",
        "viewsDir"       => "../app/views/",
    ],
];

Puede leerlo de la siguiente manera:

use Phalcon\Config\Adapter\Php;

$config = new Php("path/config.php");

echo $config->phalcon->controllersDir;
echo $config->database->username;

Métodos

public function __construct( string $filePath );

Constructor Phalcon\Config\Adapter\Php

Class Phalcon\Config\Adapter\Yaml

Código fuente en 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.

Dado el siguiente fichero de configuración:

phalcon:
  baseuri:        /phalcon/
  controllersDir: !approot  /app/controllers/
models:
  metadata: memory

Puede leerlo de la siguiente manera:

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étodos

public function __construct( string $filePath, array $callbacks = null );

Constructor Phalcon\Config\Adapter\Yaml

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

Código fuente en GitHub

Namespace Phalcon\Config   Uses Phalcon\Support\Collection   Extends Collection   Implements ConfigInterface

Phalcon\Config está diseñado para simplificar el acceso a, y el uso de, los datos de configuración de las aplicaciones. Proporciona una propiedad de objeto anidado basada en interfaz de usuario para acceder a estos datos de configuración dentro del código de la aplicación.

$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/",
        ],
    ]
);

Constantes

const DEFAULT_PATH_DELIMITER = .;

Propiedades

/**
 * @var string
 */
protected pathDelimiter;

Métodos

public function getPathDelimiter(): string;

Devuelve el delimitador de ruta por defecto

public function merge( mixed $toMerge ): ConfigInterface;

Combina una configuración con la actual

$appConfig = new \Phalcon\Config\Config(
    [
        "database" => [
            "host" => "localhost",
        ],
    ]
);

$globalConfig->merge($appConfig);
public function path( string $path, mixed $defaultValue = null, string $delimiter = null ): mixed;

Devuelve un valor de la configuración actual usando una ruta separada por puntos.

echo $config->path("unknown.path", "default", ".");
public function setPathDelimiter( string $delimiter = null ): ConfigInterface;

Establece el delimitador de la ruta predeterminada

public function toArray(): array;

Convierte recursivamente el objeto a un vector

print_r(
    $config->toArray()
);
final protected function internalMerge( array $source, array $target ): array;

Ejecuta una combinación recursivamente

protected function setData( mixed $element, mixed $value ): void;

Establece los datos de la colección

Class Phalcon\Config\ConfigFactory

Código fuente en GitHub

Namespace Phalcon\Config   Uses Phalcon\Config\Config, Phalcon\Config\ConfigInterface, Phalcon\Factory\AbstractFactory   Extends AbstractFactory

Carga la clase Config Adapter usando la opción ‘adapter’, si no se proporciona ninguna extensión será añadirá al filePath

use Phalcon\Config\ConfigFactory;

$options = [
    "filePath" => "path/config",
    "adapter"  => "php",
];

$config = (new ConfigFactory())->load($options);

Métodos

public function __construct( array $services = [] );

Constructor ConfigFactory.

public function load( mixed $config ): ConfigInterface;

Carga una configuración para crear una nueva instancia

public function newInstance( string $name, string $fileName, mixed $params = null ): ConfigInterface;

Devuelve una nueva instancia de configuración

protected function getExceptionClass(): string;
protected function getServices(): array;

Devuelve los adaptadores disponibles

protected function parseConfig( mixed $config ): array;

Interface Phalcon\Config\ConfigInterface

Código fuente en GitHub

Namespace Phalcon\Config   Uses Phalcon\Support\Collection\CollectionInterface   Extends CollectionInterface

Phalcon\Config\ConfigInterface

Interface for Phalcon\Config\Config class

Métodos

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

Código fuente en GitHub

Namespace Phalcon\Config   Extends \Exception

Las excepciones lanzadas en Phalcon\Config usarán esta clase