Class Phalcon\Config\Adapter\Yaml

extends class Phalcon\Config

implements Countable, ArrayAccess

Source on GitHub

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

Given the following configuration file:

  1. <?php
  2. phalcon:
  3. baseuri: /phalcon/
  4. controllersDir: !approot /app/controllers/
  5. models:
  6. metadata: memory

You can read it as follows:

  1. <?php
  2. define(
  3. "APPROOT",
  4. dirname(__DIR__)
  5. );
  6. $config = new \Phalcon\Config\Adapter\Yaml(
  7. "path/config.yaml",
  8. [
  9. "!approot" => function($value) {
  10. return APPROOT . $value;
  11. },
  12. ]
  13. );
  14. echo $config->phalcon->controllersDir;
  15. echo $config->phalcon->baseuri;
  16. echo $config->models->metadata;

Methods

public __construct (mixed $filePath, [array $callbacks])

Phalcon\Config\Adapter\Yaml constructor

public offsetExists (mixed $index) inherited from Phalcon\Config

Allows to check whether an attribute is defined using the array-syntax

  1. <?php
  2. var_dump(
  3. isset($config["database"])
  4. );

public get (mixed $index, [mixed $defaultValue]) inherited from Phalcon\Config

Gets an attribute from the configuration, if the attribute isn’t defined returns null If the value is exactly null or is not defined the default value will be used instead

  1. <?php
  2. echo $config->get("controllersDir", "../app/controllers/");

public offsetGet (mixed $index) inherited from Phalcon\Config

Gets an attribute using the array-syntax

  1. <?php
  2. print_r(
  3. $config["database"]
  4. );

public offsetSet (mixed $index, mixed $value) inherited from Phalcon\Config

Sets an attribute using the array-syntax

  1. <?php
  2. $config["database"] = [
  3. "type" => "Sqlite",
  4. ];

public offsetUnset (mixed $index) inherited from Phalcon\Config

Unsets an attribute using the array-syntax

  1. <?php
  2. unset($config["database"]);

public merge (Phalcon\Config $config) inherited from Phalcon\Config

Merges a configuration into the current one

  1. <?php
  2. $appConfig = new \Phalcon\Config(
  3. [
  4. "database" => [
  5. "host" => "localhost",
  6. ],
  7. ]
  8. );
  9. $globalConfig->merge($appConfig);

public toArray () inherited from Phalcon\Config

Converts recursively the object to an array

  1. <?php
  2. print_r(
  3. $config->toArray()
  4. );

public count () inherited from Phalcon\Config

Returns the count of properties set in the config

  1. <?php
  2. print count($config);

or

  1. <?php
  2. print $config->count();

public static __set_state (array $data) inherited from Phalcon\Config

Restores the state of a Phalcon\Config object

final protected Config merged config _merge (Config $config, [mixed $instance]) inherited from Phalcon\Config

Helper method for merge configs (forwarding nested config instance)