Overview

Namespaces

  • None
  • Peg
    • Cli
      • Commands
    • Config
    • Custom
      • Command
        • Action
          • Generate
          • Parse
      • CommandLine
      • Config
      • Localization
      • Utilities
    • Lib
      • Definitions
        • Element
      • Generator
      • Lexers
      • Plugins
      • Signals
        • Data
          • Definitions
          • Lexers
        • Type
  • PHP

Classes

  • Base
  • INI
  • JSON
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: /**
 3:  * @author Jefferson González
 4:  * @license MIT
 5:  * @link http://github.com/peg-org/peg-custom Source code.
 6:  */
 7: 
 8: namespace Peg\Custom\Config;
 9: 
10: /**
11:  * Json implementation to manage configuration files.
12:  */
13: class JSON extends \Peg\Custom\Config\Base
14: {
15: 
16:     /**
17:      * Loads all configuration options of a given file and creates it if does
18:      * not exists.
19:      * @param string $directory
20:      * @param string $configuration_file
21:      */
22:     public function Load($directory, $configuration_file)
23:     {
24:         $this->preferences = array();
25: 
26:         $this->directory = $directory;
27: 
28:         $this->file = $this->directory . "/$configuration_file";
29: 
30:         if(file_exists($this->file))
31:         {
32:             $this->preferences = \Peg\Custom\Utilities\Json::Decode(
33:                 file_get_contents($this->file)
34:             );
35:         }
36:     }
37: 
38:     /**
39:      * Writes a configuration file using the settings array.
40:      */
41:     public function Write()
42:     {
43:         file_put_contents(
44:             $this->file, 
45:             \Peg\Custom\Utilities\Json::Encode($this->preferences)
46:         );
47:     }
48: 
49: }
PEG Api API documentation generated by ApiGen 2.8.0