FOF30\Autoloader\Autoloader::addMap PHP Method

addMap() public method

Registers a set of PSR-4 directories for a given namespace, either appending or prefixing to the ones previously set for this namespace.
public addMap ( string $prefix, array | string $paths, boolean $prepend = false )
$prefix string The prefix/namespace, with trailing '\\'
$paths array | string The PSR-0 base directories
$prepend boolean Whether to prefix the directories
    public function addMap($prefix, $paths, $prepend = false)
    {
        if ($prefix) {
            $prefix = ltrim($prefix, '\\');
        }
        if (!$prefix) {
            // Register directories for the root namespace.
            if ($prepend) {
                $this->fallbackDirs = array_merge((array) $paths, $this->fallbackDirs);
                $this->fallbackDirs = array_unique($this->fallbackDirs);
            } else {
                $this->fallbackDirs = array_merge($this->fallbackDirs, (array) $paths);
                $this->fallbackDirs = array_unique($this->fallbackDirs);
            }
        } elseif (!isset($this->prefixDirs[$prefix])) {
            // Register directories for a new namespace.
            $length = strlen($prefix);
            if ('\\' !== $prefix[$length - 1]) {
                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
            }
            $this->prefixLengths[$prefix[0]][$prefix] = $length;
            $this->prefixDirs[$prefix] = (array) $paths;
        } elseif ($prepend) {
            // Prepend directories for an already registered namespace.
            $this->prefixDirs[$prefix] = array_merge((array) $paths, $this->prefixDirs[$prefix]);
            $this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
        } else {
            // Append directories for an already registered namespace.
            $this->prefixDirs[$prefix] = array_merge($this->prefixDirs[$prefix], (array) $paths);
            $this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
        }
        return $this;
    }