PHP5 Include Path


/ Published in: PHP
Save to your folder(s)

Include Path PHP 5 class.

Usage:
$path = new fuselogic_include_path();
$path->add('/home/ekobudi/www/fuselogic');
$path->add('/home/ekobudi/www/pear');
$path->remove('/home/ekobudi/www/old_fuselgic');


Copy this code and paste it in your HTML
  1. <?php
  2. class fuselogic_include_path
  3. {
  4. function __construct($path = null)
  5. {
  6. if(!isset($this->setting_name))
  7. {
  8. $this->setting_name = 'include_path';
  9. $this->_get_separator();
  10. }
  11. if(isset($path)) $this->add($path);
  12. }
  13.  
  14. function add($variables)
  15. {
  16. $array = Array();
  17. if(is_array($variables))
  18. {
  19. $array = array_merge($this->to_array(),$variables);
  20. }else
  21. {
  22. $array = array_merge($this->to_array(),array($variables));
  23. }
  24.  
  25. $this->clear();
  26. $this->_unlink('.');
  27. for($i=0;$i<count($array);$i++) $array[$i] = str_replace('\\','/',$array[$i]);
  28. $unique = array_unique($array);
  29. foreach($unique as $variable)
  30. {
  31. if($variable !== '.') $this->_link($variable);
  32. }
  33. }
  34.  
  35. function remove($variables)
  36. {
  37. if(is_array($variables))
  38. {
  39. foreach($variables as $variable) $this->_unlink($variable);
  40. }else
  41. {
  42. $this->_unlink($variables);
  43. }
  44. }
  45.  
  46. function clear()
  47. {
  48. ini_set($this->setting_name,'.');
  49. }
  50.  
  51. function to_array()
  52. {
  53. return explode($this->_separator,ini_get($this->setting_name));
  54. }
  55.  
  56. function get_setting($setting = '')
  57. {
  58. if(empty($setting)) $setting = ini_get($this->setting_name);
  59. $setting = str_replace('\\','/',$setting);
  60. return $setting;
  61. }
  62.  
  63. function _link($directory = '')
  64. {
  65. if(!empty($directory))
  66. {
  67. $directory = str_replace('\\','/',$directory);
  68. $setting = $this->get_setting();
  69. $setting = str_replace($this->_separator.$directory,'',$setting);
  70. $setting .= $this->_separator.$directory;
  71. ini_set($this->setting_name,$setting);
  72. }
  73. }
  74.  
  75. function _get_separator()
  76. {
  77. $count = substr_count(ini_get($this->setting_name),';');
  78. if($count > 0)
  79. {
  80. $this->_separator = ';';
  81. }else{
  82. $this->_separator = ':';
  83. }
  84. }
  85.  
  86. function _unlink($directory = '')
  87. {
  88. if(!empty($directory))
  89. {
  90. $directory = str_replace('\\','/',$directory);
  91. $setting = $this->get_setting();
  92. $setting = str_replace($directory,'',$setting);
  93. $setting = str_replace($this->_separator.$this->_separator,$this->_separator,$setting);
  94. $setting .= $this->_separator.$this->_separator;
  95. $setting = str_replace($this->_separator.$this->_separator.$this->_separator,'',$setting);
  96. $setting = str_replace($this->_separator.$this->_separator,'',$setting);
  97. ini_set($this->setting_name,$setting);
  98. }
  99. }
  100. }
  101. ?>

URL: http://fuselogic.haltebis.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.