Advertisement
haazee

Setup.php

Jun 6th, 2012
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Description of setup
  5.  *
  6.  * @author H.Z.
  7.  */
  8.  
  9.  
  10. abstract class Parameters {
  11.     protected $parameterObjectName;
  12.    
  13.    
  14.     function open(){
  15.         return;
  16.     }
  17.     function close(){
  18.         return;
  19.     }
  20.    
  21.     abstract function read();
  22.    
  23. }
  24.  
  25. class ParametersFromFile extends Parameters {
  26.     function __construct($parameterObjectNameArgument) {
  27.         $this->parameterObjectName=$parameterObjectNameArgument;
  28.     }
  29.     function read() {
  30.         return file_get_contents($this->parameterObjectName);
  31.     }
  32. }
  33.  
  34.  
  35. abstract class GeneralParser {
  36.     protected $parameterObject;
  37.    
  38.     function __construct(Parameters $parameterObjectArgument){
  39.         $this->parameterObject=$parameterObjectArgument;
  40.     }
  41.    
  42.     abstract function parse();
  43. }
  44.  
  45.  
  46. class IniParser extends GeneralParser {
  47.     function parse() {
  48.         return parse_ini_string($this->parameterObject->read());
  49.     }
  50. }
  51.  
  52.  
  53. class ApplicationSetup {
  54.     protected $setupData=array();
  55.     protected $parserObject;
  56.    
  57.     function __construct(GeneralParser $parserObjectArgument) {
  58.         $this->parserObject = $parserObjectArgument;
  59.         $this->loadDataFromIni();
  60.     }
  61.  
  62.     protected function loadDataFromIni(){
  63.         $this->setupData = $this->parserObject->parse();
  64.     }
  65.  
  66.     public function getAllParameters(){
  67.         return $this->setupData;
  68.     }
  69.    
  70.     public function getParameter($parameterIdentifier){
  71.         return NULL;    /* ezt még meg kell írni */
  72.     }
  73. }
  74.  
  75. error_reporting(E_ALL);
  76. require_once '../config/Setup.php';
  77. $setupParameters=new ApplicationSetup(new IniParser(new ParametersFromFile("../config/setup.ini")));
  78. var_dump($setupParameters->getAllParameters());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement