示例#1
0
文件: scan.php 项目: guillaum3f/codie
function stack_folder($path, $namespace, $mask = null)
{
    //record the folder path containing libs
    try {
        $directory = new \DirectoryIterator($path);
    } catch (Exception $e) {
        warning('filesystem', 'e001', $path);
        return;
    }
    //format eventual namespace
    //if namespace exist push namespace in stack as new javascript object
    if ($namespace != '') {
        $namespace = trim($namespace, '.');
        get_transmission()->stack('if(!' . $namespace . '){' . $namespace . ' = {};}');
        $namespace = $namespace . '.';
    }
    //scan the folder
    //exit if there is NO item, item is NOT (a folder or a file), item IS "dot" folder
    foreach ($directory as $object) {
        //get path of item
        $pathname = $object->getPathname();
        if ($object->isDir() && !$object->isDot()) {
            //get foldername
            $foldername = $object->getBasename();
            //build new namespace
            $newnamespace = $namespace . $foldername;
            //send new path and new namespace back to the function
            stack_folder($pathname, $newnamespace);
        } else {
            if ($object->isFile()) {
                //apply mask rule
                if ($mask) {
                    if (!preg_match('#' . $mask . '#', $pathname)) {
                        continue;
                    }
                }
                //get file content
                $filecontent = get_file($pathname);
                //add $namespace to the beginning of file content
                $filecontent = $namespace . $filecontent;
                //push javascript object with new namespace in stack
                get_transmission()->stack($filecontent);
            }
        }
    }
}
示例#2
0
 public function lib2namespace($path, $namespace = '', $mask = null)
 {
     stack_folder($path, $namespace, $mask);
 }