Posted By

MMDeveloper on 02/24/09


Tagged

class php configuration Shared config


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


shared config class


 / Published in: PHP
 

URL: http://www.mechanicmatt.com/toDo/

This is just something I came up with for this new project I'm doing. It's an OOP way to have a configuration file and share it amongst several other things.

Further down is how you would share it in another application. Your class/script now has the OOP values of the config. Further more, you can code additional methods within your settings class to call which would dynamically modify your config even further. Possibilities are endless :P

  1. <?php
  2. require_once("../settings.php");
  3.  
  4. class sharedConfig {
  5.  
  6. public $host = "";
  7. public $db = "";
  8. public $un = "";
  9. public $pw = "";
  10. public $absolute = "http://www.mechanicmatt.com/toDo/";
  11. public $relative = "/toDo/";
  12. public $request = array();
  13. public $now = "";
  14. public $path = "";
  15.  
  16. public $skinDir = "skins/";
  17. public $skin = 0;
  18.  
  19. public function __construct() {
  20.  
  21. /*
  22. this is where you would run any processing code
  23. to add/edit/delete any additional configuration
  24. values programmatically. For example...
  25.  
  26. This config script includes my database connection
  27. values (host, username, password) from yet another
  28. shared config script.
  29. */
  30. global $sqlServer;
  31.  
  32. $this->host = $sqlServer["host"];
  33. $this->db = "mford_toDo";
  34. $this->un = $sqlServer["un"];
  35. $this->pw = $sqlServer["pw"];
  36. }
  37. }
  38. ?>
  39.  
  40.  
  41. //script using/sharing this file
  42. <?php
  43. class yourClass {
  44. private $config = stdClass;
  45.  
  46. public function __construct() {
  47. include("sharedConfig.php");
  48. $this->config = new sharedConfig();
  49. }
  50. }
  51. ?>

Report this snippet  

You need to login to post a comment.