Neos\FluidAdaptor\Core\ViewHelper\ViewHelperResolver::addNamespace PHP Method

addNamespace() public method

The provided namespace can be either a single namespace or an array of namespaces, as strings. The identifier/alias is always a single, alpha-numeric ASCII string. Calling this method multiple times with different PHP namespaces for the same alias causes that namespace to be *extended*, meaning that the PHP namespace you provide second, third etc. are also used in lookups and are used *first*, so that if any of the namespaces you add contains a class placed and named the same way as one that exists in an earlier namespace, then your class gets used instead of the earlier one. Example: $resolver->addNamespace('my', 'My\Package\ViewHelpers'); Any ViewHelpers under this namespace can now be accessed using for example {my:example()} Now, assuming you also have an ExampleViewHelper class in a different namespace and wish to make that ExampleViewHelper override the other: $resolver->addNamespace('my', 'My\OtherPackage\ViewHelpers'); Now, since ExampleViewHelper exists in both places but the My\OtherPackage\ViewHelpers namespace was added *last*, Fluid will find and use My\OtherPackage\ViewHelpers\ExampleViewHelper. Alternatively, setNamespaces() can be used to reset and redefine all previously added namespaces - which is great for cases where you need to remove or replace previously added namespaces. Be aware that setNamespaces() also removes the default "f" namespace, so when you use this method you should always include the "f" namespace.
public addNamespace ( string $identifier, string | array $phpNamespace ) : void
$identifier string
$phpNamespace string | array
return void
    public function addNamespace($identifier, $phpNamespace)
    {
        if ($phpNamespace === null) {
            $this->namespaces[$identifier] = null;
            return;
        }
        if (!is_array($phpNamespace)) {
            $this->addNamespaceInternal($identifier, $phpNamespace);
            return;
        }
        foreach ($phpNamespace as $namespace) {
            $this->addNamespaceInternal($identifier, $namespace);
        }
    }