note 103482 deleted from function.require-once by danbrown
| From: | danbrown@php.net | Date: | Fri, 15 Apr 2011 14:01:35 +0000 |
| Subject: | note 103482 deleted from function.require-once by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178876@lists.php.net to get a copy of this message | ||
Note Submitter: spark at limao dot com dot br
Reason: 0
----
perfected the import fuction:
- removed the session bug, now the restrictions are per-file.
- now it's recursive, it will get into subpackages too.
- files are still required to be ".class.php";
<?php
function import($path=""){
if($path == ""){ //no parameter returns the file import info tree;
$report = $_SESSION['imports'];
foreach($report as &$item) $item = array_flip($item);
return $report;
}
$current = str_replace("\\","/",getcwd())."/";
$path = $current.str_replace(".","/",$path);
if(substr($path,-1) != "*") $path .= ".class.php";
$imports = &$_SESSION['imports'];
if(!is_array($imports)) $imports = array();
$control = &$imports[$_SERVER['SCRIPT_FILENAME']];
if(!is_array($control)) $control = array();
foreach(glob($path) as $file){
$file = str_replace($current,"",$file);
if(is_dir($file)) import($file.".*");
if(substr($file,-10) != ".class.php") continue;
if($control[$file]) continue;
$control[$file] = count($control);
require_once($file);
}
}
?>