2017 © Pedro Peláez
 

library config-read-write

A package for reading and writing config file

image

senhung/config-read-write

A package for reading and writing config file

  • Tuesday, May 15, 2018
  • by senhung
  • Repository
  • 0 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

Config Read Write

Description

A PHP package for reading and setting configuration fast and easy., (*1)

Setup

  1. Add Dependency
$ composer require senhung/config-read-write
  1. Add a Configuration File

Create a file and input the configurations, (*2)

For example:, (*3)

# Some Comments
APP_NAME=config-read
VERSION=2.0.0

How To Use

Initialize

Configruation::initializeConfigs(
    [string $configFilePath [, bool $absolutePath [, string $separator]]]
): void

$configFilePath: the location your config file is placed (default: '.env'), (*4)

$absolutePath: the path defined is absolute path or relative path (default: true), (*5)

$separator: the separator between config keys and values (default: '='), (*6)

Config Entry

Add the following code in your program's main entry if you want to specify a different config file name or separator other than the default ones, (*7)

<?php

require_once 'vendor/autoload.php';

use Senhung\Config\Configuration;

/* Initialize config array in Configuration class */
Configuration::initializeConfigs('config_file_path', true, 'separator');

Note: you don't need to have this file if you are using .env as your config path and = as your separator., (*8)

Comment Config

Use # in config file to comment a line, (*9)

# This is a comment, will not be read by the tool
OTHER_CONFIG=will-be-read

Note: Set config will overwrite comments and empty lines in original config file, (*10)

Read Config

Configuration::read('<config-you-want-to-read>');

Write Config

Configuration::set('<config-you-want-to-write>', '<change-to>');

Note: Set config will overwrite comments and empty lines in original config file, (*11)

Example

Configuration File

# App Configs
APP_NAME=config-read
VERSION=2.0.0

Config Reading and Writing

<?php

require_once 'vendor/autoload.php';

use Senhung\Config\Configuration;

/* Read config APP_NAME */
echo Configuration::read('APP_NAME') . "\n";

/* Read config VERSION */
echo Configuration::read('VERSION') . "\n";

/* Set APP_NAME to config-write */
Configuration::set('APP_NAME', 'config-write');

/* Read APP_NAME again to see the changes */
echo Configuration::read('APP_NAME') . "\n";

Output:, (*12)

config-read
2.0.0
config-write

The Versions

15/05 2018

dev-master

9999999-dev

A package for reading and writing config file

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

by Senhung Wong

15/05 2018

v2.0.0

2.0.0.0

A package for reading and writing config file

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

by Senhung Wong

28/04 2018

1.1.0

1.1.0.0

A package for reading and writing config file

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

by Senhung Wong

28/04 2018

v1.1.0

1.1.0.0

A package for reading and writing config file

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

by Senhung Wong

27/04 2018

1.0.4

1.0.4.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

27/04 2018

1.0.3

1.0.3.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

27/04 2018

v1.0.3

1.0.3.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

27/04 2018

v1.0.4

1.0.4.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

27/04 2018

1.0.2

1.0.2.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

27/04 2018

v1.0.2

1.0.2.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

25/04 2018

1.0.1

1.0.1.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

25/04 2018

v1.0.1

1.0.1.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

25/04 2018

1.0.0

1.0.0.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong

25/04 2018

v1.0.0

1.0.0.0

A package for reading and writing config file

  Sources   Download

MIT

by Senhung Wong