hassankhan / config

Config is a lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files
MIT License
971 stars 136 forks source link

Symfony errors trying to do basic instance #133

Closed samsong closed 2 years ago

samsong commented 2 years ago

Hi & thanks for your project! Trying to install & create a basic test I did the composer install but get error when try basic test:

require_once __DIR__ . '/composer/autoload_real.php';
$loaded = ComposerAutoloaderInit7ca851ff08ebc93947802056783fc23b::getLoader();

use Noodlehaus\Config;
use Noodlehaus\Parser\Json;
use Noodlehaus\Parser\Yaml;

$settingsJson = <<<FOOBAR
{
  "application": {
    "name": "configuration",
    "secret": "s3cr3t"
  },
  "host": "localhost",
  "port": 80,
  "servers": [
    "host1",
    "host2",
    "host3"
  ]
}
FOOBAR;

$settingsYaml = <<<FOOBAR
application:
    name: configuration
    secret: s3cr3t
host: localhost
port: 80
servers:
- host1
- host2
- host3

FOOBAR;

$conf = Config::load($settingsJson, new Json, true);
$conf = new Config($settingsYaml, new Yaml, true);

// Get value using key
$debug = $conf->get('debug');

// Get value using nested key
$secret = $conf->get('security.secret');

// Get a value with a fallback
$ttl = $conf->get('app.timeout', 3000);

ERROR:

Fatal error:  Uncaught Error: Class 'Symfony\Component\Yaml\Yaml' not found in G:\xampp\htdocs\php\config\config-2.2.0\vendor\hassankhan\config\src\Parser\Yaml.php:52
Stack trace:
#0 G:\xampp\htdocs\php\config\config-2.2.0\vendor\hassankhan\config\src\Config.php(171): Noodlehaus\Parser\Yaml->parseString('application:\n  ...')
#1 G:\xampp\htdocs\php\config\config-2.2.0\vendor\hassankhan\config\src\Config.php(77): Noodlehaus\Config->loadFromString('application:\n  ...', Object(Noodlehaus\Parser\Yaml))
#2 G:\xampp\htdocs\php\config\config-2.2.0\vendor\autoload.php(42): Noodlehaus\Config->__construct('application:\n  ...', Object(Noodlehaus\Parser\Yaml), true)
#3 {main}
  thrown in G:\xampp\htdocs\php\config\config-2.2.0\vendor\hassankhan\config\src\Parser\Yaml.php on line 52
DavidePastore commented 2 years ago

Hi @samsong. Thanks for using this library. If you want to read configuration from YAML files, you have to require the symfony/yaml dependency using the following command:

composer require symfony/yaml

You can find this additional step in the README.md file. Feel free to reopen the issue if you see that my fix doesn't work for you.