Project

General

Profile

Actions

Feature #15208

closed

Best Practice: a) Funktion Path::join() besprechen, b) cache

Added by Carsten Rose over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Enis Nuredini
Target version:
-
Start date:
17.12.2022
Due date:
% Done:

0%

Estimated time:
Discuss:
Prio Planung:
No
Vote:

Description

    public static function join(...$pathPartsToAppend): string {
        $parts = $pathPartsToAppend;

        // concatenate all parts (arrays are flattened)
        $path = '';
        array_walk_recursive($parts, function ($part) use (&$path) {

            // filter out empty string and null arguments
            if (is_null($part) || $part === '') {
                return;
            }

            // first part added without '/'
            if ($path === '') {
                $path .= $part;
            } else {
                $part = (string)$part;

                $path .= ((($part[0] ?? '') === '/')?'':'/') . $part;
            }
        });

        // remove multiple occurrences of '/' (but keep http://)
        if (preg_match('/^\w*:\/\//', $path, $match)) {
            $protocol = $match[0];
            $path = substr($path, strlen($protocol));
        } else {
            $protocol = '';
        }
        $path = preg_replace('/\/{2,}/', '/', $path);

        return $protocol . $path;
    }

Files


Related issues

Related to QFQ - Feature #5715: PDF CachingClosedCarsten Rose20.03.2018

Actions
Actions

Also available in: Atom PDF