codice:<?php //4 //5 /** * Functions "FROM path IMPORT data" * A list of functions to import from a folder one or more files. * Emulates python sintax with something like: * from('classes') . import('*'); * How to: * from( $files_folder ) . import( $array_string_or_all ); * @param String path where you want import* files * *import as require_once * @param Mixed single char '*' to import all files * class or file name 'Example' without extensions * array with a list of files without extensions * ------------------------------- * EXAMPLE: * require_once('from_import.php'); * from('classes') . import(Array('MyDBClass', 'MyOtherClass')); * _______________________________ * @author Andrea Giammarchi * @date 2005/06/01 11:00 * @site www.devpro.it * _______________________________ */ function from($folder){ $temp_folder = $folder; do { $last = substr($temp_folder, -1); $temp_folder = substr($temp_folder, 0, -1); $pos = isSet($pos) ? $pos++ : 0; } while(in_array($last, Array('\\\', '/'))); $folder = $pos === 0 ? $folder : substr($folder, 0, $pos); $GLOBALS['__FROM_IMPORT_FOLDER__'] = &$folder; } function import($what) { if( isset( $GLOBALS['__FROM_IMPORT_FOLDER__'] ) && is_dir( $GLOBALS['__FROM_IMPORT_FOLDER__'] ) ) if(@$handle = &opendir( $GLOBALS['__FROM_IMPORT_FOLDER__'] )) { while(($file = readdir($handle)) !== false) __fileImporter($file, $what); closedir($handle); unset( $GLOBALS['__FROM_IMPORT_FOLDER__'] ); } } function __fileImporter(&$file, &$what) { if( $file !== '.' && $file !== '..' && isset( $GLOBALS['__FROM_IMPORT_FOLDER__'] ) && !is_dir( $GLOBALS['__FROM_IMPORT_FOLDER__'] .'/'. $file ) && is_file( $GLOBALS['__FROM_IMPORT_FOLDER__'] .'/'. $file ) ) { $requred = false; if($what === '*') $requred = true; else { $temp_file = array_shift(explode('.', $file)); if(!class_exists($temp_file)) { if(!is_array($what) && $temp_file === $what){ $requred = true; } elseif(is_array($what) && in_array($temp_file, $what)) $requred = true; } } if($requred === true) @require_once( $GLOBALS['__FROM_IMPORT_FOLDER__'] .'/'. $file ); } } ?>