Example #1
0
/**
 * @internal Collects dependencies from a file
 */
function minify_collect_from_file($kind, $f, $debug_path = '')
{
    global $dependency_info, $res_file_storage, $ext_resources;
    if (!$f) {
        return;
    }
    $classname = fq_class_name(array_shift(explode('.', basename($f))));
    if (isset($res_file_storage[$classname]) || minify_forbidden($classname)) {
        return;
    }
    $order = array('static', 'inherited', 'instanciated', 'self');
    //:array('self','incontent','instanciated','inherited');
    $res_file_storage[$classname] = array();
    $content = file_get_contents($f);
    // remove block-comments
    $content = preg_replace("|/\\*.*\\*/|sU", "", $content);
    do {
        $c2 = preg_replace("|(.*)//.*\$|m", "\$1", $content);
        if ($content == $c2) {
            break;
        }
        $content = $c2;
    } while (true);
    foreach ($order as $o) {
        switch ($o) {
            case 'inherited':
                if (preg_match_all('/class\\s+[^\\s]+\\s+extends\\s+([^\\s]+)/', $content, $matches, PREG_SET_ORDER)) {
                    foreach ($matches as $m) {
                        $file_for_class = __search_file_for_class($m[1]);
                        if (!$file_for_class) {
                            continue;
                        }
                        $dependency_info[$classname][] = strtolower($m[1]);
                        minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname);
                    }
                }
                break;
            case 'instanciated':
                $matches = array();
                if (preg_match_all('/new\\s+([^\\(]+)\\(/', $content, $by_new, PREG_SET_ORDER)) {
                    $matches = array_merge($matches, $by_new);
                }
                if (preg_match_all('/\\s+([^:\\s\\(\\)]+)::Make\\(/Ui', $content, $by_make, PREG_SET_ORDER)) {
                    $matches = array_merge($matches, $by_make);
                }
                if (count($matches) > 0) {
                    foreach ($matches as $m) {
                        $file_for_class = __search_file_for_class($m[1]);
                        if (!$file_for_class) {
                            continue;
                        }
                        $dependency_info[$classname][] = strtolower($m[1]);
                        minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname);
                    }
                }
                break;
            case 'self':
                $simplecls = array_pop(explode("\\", $classname));
                if (resourceExists(strtolower("{$simplecls}.{$kind}"))) {
                    $tmp = resFile(strtolower("{$simplecls}.{$kind}"));
                    if (!in_array($tmp, $res_file_storage[$classname])) {
                        $res_file_storage[$classname][] = $tmp;
                    }
                }
                break;
            case 'static':
                try {
                    foreach (ResourceAttribute::Collect($classname) as $resource) {
                        $b = $resource->Resolve();
                        if ($resource instanceof \ScavixWDF\Reflection\ExternalResourceAttribute) {
                            $ext_resources[] = $b;
                            continue;
                        }
                        if (!ends_with($b, $kind)) {
                            continue;
                        }
                        $b = strtolower($b);
                        if (!in_array($b, $res_file_storage[$classname])) {
                            $res_file_storage[$classname][] = $b;
                        }
                    }
                } catch (Exception $ex) {
                }
                break;
        }
    }
}
Example #2
0
/**
 * @internal Collects dependencies from a file
 */
function minify_collect_from_file($kind, $f, $debug_path = '')
{
    global $dependency_info, $res_file_storage;
    if (!$f) {
        return;
    }
    $classname = strtolower(basename($f, ".class.php"));
    if (isset($res_file_storage[$classname]) || minify_forbidden($classname)) {
        return;
    }
    $order = array('static', 'inherited', 'instanciated', 'self');
    //:array('self','incontent','instanciated','inherited');
    $res_file_storage[$classname] = array();
    $content = file_get_contents($f);
    // remove block-comments
    $content = preg_replace("|/\\*.*\\*/|sU", "", $content);
    do {
        $c2 = preg_replace("|(.*)//.*\$|m", "\$1", $content);
        if ($content == $c2) {
            break;
        }
        $content = $c2;
    } while (true);
    foreach ($order as $o) {
        switch ($o) {
            case 'inherited':
                if (preg_match_all('/class\\s+[^\\s]+\\s+extends\\s+([^\\s]+)/', $content, $matches, PREG_SET_ORDER)) {
                    //					log_debug("minify_collect_from_file [$debug_path/$classname]: INHERITED",$matches);
                    foreach ($matches as $m) {
                        $file_for_class = __search_file_for_class($m[1]);
                        if (!$file_for_class) {
                            continue;
                        }
                        $dependency_info[$classname][] = strtolower($m[1]);
                        minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname);
                    }
                }
                break;
            case 'instanciated':
                if (preg_match_all('/new\\s+([^\\(]+)\\(/', $content, $matches, PREG_SET_ORDER)) {
                    //					log_debug("minify_collect_from_file [$debug_path/$classname]: INSTANCIATED",$matches);
                    foreach ($matches as $m) {
                        $file_for_class = __search_file_for_class($m[1]);
                        if (!$file_for_class) {
                            continue;
                        }
                        $dependency_info[$classname][] = strtolower($m[1]);
                        minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname);
                    }
                }
                break;
            case 'self':
                if (resourceExists(strtolower("{$classname}.{$kind}"))) {
                    $tmp = resFile(strtolower("{$classname}.{$kind}"));
                    if (!in_array($tmp, $res_file_storage[$classname])) {
                        $res_file_storage[$classname][] = $tmp;
                    }
                }
                break;
            case 'static':
                try {
                    $buf = ResourceAttribute::ResolveAll(ResourceAttribute::Collect($classname));
                    foreach ($buf as $b) {
                        if (!ends_with($b, $kind)) {
                            continue;
                        }
                        $b = strtolower($b);
                        if (!in_array($b, $res_file_storage[$classname])) {
                            $res_file_storage[$classname][] = $b;
                        }
                    }
                } catch (Exception $ex) {
                }
                break;
        }
    }
}