2017 © Pedro Peláez
 

library collection

some data collection tool library of the php

image

toolkit/collection

some data collection tool library of the php

  • Monday, April 30, 2018
  • by inhere
  • Repository
  • 1 Watchers
  • 1 Stars
  • 5 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 25 % Grown

The README.md

Config

License Php Version Latest Stable Version Actions Status, (*1)

🗂 Config load, management, merge, get, set and more., (*2)

  • Config data load, management
  • Support load multi config data, will auto merge
  • Supports INI,JSON,YAML,TOML,NEON,PHP format file
  • Support for exporting configuration data to file
  • Language data management

中文说明, (*3)

Install

composer, (*4)

composer require phppkg/config

Usage

create and load config data. load multi file, will auto merge data., (*5)

use PhpPkg\Config\ConfigBox;

$config = ConfigBox::new();
$config->loadFromFiles([
    __DIR__ . '/test/testdata/config.ini',
    __DIR__ . '/test/testdata/config.neon',
    __DIR__ . '/test/testdata/config.yml',
    __DIR__ . '/test/testdata/config.toml',
]);

Created in other ways

use PhpPkg\Config\ConfigBox;

$config = ConfigBox::newFromFiles([
    // ... config file list
]);

$config->loadIniFile('path/to/my.ini')

More load methods

  • loadFromFiles(array $filePaths, string $format = '')
  • loadFromStrings(string $format, string ...$strings)
  • loadFromSteam(string $format, resource $stream)
  • loadIniFile(string $filepath)
  • loadJsonFile(string $filepath)
  • loadJson5File(string $filepath)
  • loadYamlFile(string $filepath)
  • loadPhpFile(string $filepath)

Dump data

// dump config
vdump($config->getData());

Output:, (*6)

CALL ON PhpPkg\ConfigTest\ConfigBoxTest(24):
array(7) {
  ["name"]=> string(6) "inhere"
  ["age"]=> int(89)
  ["atIni"]=> string(6) "value0"
  ["arr0"]=> array(3) {
    [0]=> string(2) "ab"
    [1]=> int(23)
    [2]=> string(2) "de"
  }
  ["map0"]=> array(2) {
    ["key0"]=> string(4) "val0"
    ["key1"]=> string(4) "val1"
  }
  ["atNeon"]=> string(6) "value1"
  ["atYaml"]=> string(6) "value2"
  ["atToml"]=> string(6) "val at toml"
}

Get value

/** @var PhpPkg\Config\ConfigBox $config */
$config->getInt('age'); // int(89)
$config->getString('name'); // string('inhere')
$config->get('arr0');
$config->get('map0');

// get value by key-path.
$config->getInt('arr0.1'); // int(23)
$config->getString('map0.key0'); // string('val0')

Set value

/** @var PhpPkg\Config\ConfigBox $config */
$config->set('name', 'INHERE');
$config->set('map0.key0', 'new value');

// set multi at once
$config->sets([
    'key1' => 'value1',
    'key2' => 'value2',
    // ...
]);

Export to file

Export config data to file., (*7)

use PhpPkg\Config\ConfigBox;

/** @var ConfigBox $config */
$config->exportTo('/path/to/file.json');
$config->exportTo('/path/to/my.conf', ConfigBox::FORMAT_YAML);

PHPPkg Projects

License

MIT, (*8)

The Versions

30/04 2018

dev-master

9999999-dev https://github.com/php-toolkit/collection

some data collection tool library of the php

  Sources   Download

MIT

The Requires

 

php library tool

30/04 2018

v1.0.2

1.0.2.0 https://github.com/php-toolkit/collection

some data collection tool library of the php

  Sources   Download

MIT

The Requires

 

php library tool

08/03 2018

v1.0.1

1.0.1.0 https://github.com/php-mylib/collection

some data collection tool library of the php

  Sources   Download

MIT

The Requires

 

php library tool

30/01 2018

v1.0.0

1.0.0.0 https://github.com/php-mylib/collection

some data collection tool library of the php

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php library tool