PHP Classes
elePHPant
Icontem

Simple YAML Config Reader: Read configuration settings from YAML files

Recommend this page to a friend!
  Info   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2006-12-18 (10 years ago) RSS 2.0 feedNot enough user ratingsTotal: 1,041 All time: 3,452 This week: 679Up
Version License PHP version Categories
yamlconfig 1.0.0GNU General Publi...5.0PHP 5, Configuration
Description Author

This package can be used to read configuration settings from file YAML format.

It uses a separate class named SPYC, written by Chris Wanstrath, to parse YAML configuration files and returns an associative array with pairs of configuration options and the respective values.

The configuration class uses the singleton pattern, so a configuration file is loaded and parsed only once per script.

It automatic switches between configuration files depending on the machine the script is running.

It also checks the request query string for language parameter and automatically loads the contents of the relevant localization file into a global variable for easier use.

Name: Chavo <contact>
Classes: 1 package by
Country: Bulgaria Bulgaria
Age: 39
All time rank: 222717 in Bulgaria Bulgaria
Week rank: 1104 Up6 in Bulgaria Bulgaria Up

Details
This class reads site configuration settings from a file in YAML format and returns them as an array of strings. It uses the Singleton pattern, so the file is loaded and parsed only once per script, thus increasing its performance. The Settings class has the following features:

 - Reading and parsing configuration files in YAML format (uses SPYC class by Chris Wanstrath;
 - Automatic switching of the configuration files depending on the machine the script is running;
 - Checks the query string for language parameter and automaticaly loads the contents of the relevant localization file into a global variable for easier use (useful for multilanguage sites)
 - Very easy to use (all you need to do is to create an instance; it will contain all the settings right away);
 - Can be instantiated many times; the actual loading and parsing of the configuration files will take place only once per script.

Configuration and localization file format:
  Configuration and localization files must be in a valid YAML format (see http://www.yaml.org - they say it takes 5 minutes to learn ). For security reasons the configuration file is saved with .PHP extension and its contents is enclosed both in YAML and PHP comment tags. This prevents displaying file contents if someone guesses its url.

 FORMAT OF THE CONFIGURATION FILE:

  ---
  <key1>:<value>
  <key2>:
    <value1>
    <value2>
    .. 
   

  LOCATION OF THE FILES
  All configuration and localization files should be located in the same folder as the settings class file. 
  
  FILE NAME OF THE FILES
  Configuration file names consist of the name (or domain name) of the hosting server + .yml extension 

    Examples of configuration file names:
     localhost.yml  <- commonly used on developer machines
     someserver.com.yml  <-script is located at http://www.someserver.com 
     myapp.someserver.com.php  <- script is located at a host using subdomain : http://myapp.someserver.com

  Localization file names consist of the language code + .yml extension.
     
     Examples of localization file names:
       en.yml - file containing English localization strings
       fr.yml - file containing French localization strings, etc.

     For the script to be able to locate the localization files, their respective codes must be listed in the languages section of the main configuration file, 
     or in this example:
      
      ... other configuration settings ...

      languages:
        en:English
	fr:French

      ... other configuration settings ...
      


RESOURCES

  Information on the YAML format: http://www.yaml.org
  SPYC (YAML parser for PHP): http://spyc.sourceforge.net

EXAMPLE USAGE

  //create an instance of the class
  $settings = Settings::singleton();
  //now you can get all the settings right away
  echo $settings->get("db_name");
  Files folder image Files  
File Role Description
Plain text file settings.class.php Class Main Class
Accessible without login Plain text file localhost.yml Data Sample configuration file
Accessible without login Plain text file example.php Example Example script
Plain text file spyc.php Class YAML parser class
Accessible without login Plain text file en.yml Data Sample localization file
Accessible without login Plain text file fr.yml Data Sample localization file
Accessible without login Plain text file readme.txt Doc. Readme file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,041
This week:0
All time:3,452
This week:679Up
User Comments (1)
Really useful class, but your code needs to be better and per...
3 years ago (Andoitz Jordan Marmolejo)
72%StarStarStarStar