Jackalope\Transport\Jackrabbit\Client::registerNamespace PHP Method

registerNamespace() public method

{@inheritDoc}
public registerNamespace ( $prefix, $uri )
    public function registerNamespace($prefix, $uri)
    {
        // seems jackrabbit always expects full list of namespaces
        $namespaces = $this->getNamespaces();
        // check if prefix is already mapped
        if (isset($namespaces[$prefix])) {
            if ($namespaces[$prefix] == $uri) {
                // nothing to do, we already have the mapping
                return;
            }
            // unregister old mapping
            throw new UnsupportedRepositoryOperationException("Trying to set existing prefix {$prefix} from " . $namespaces[$prefix] . " to different uri {$uri}, but unregistering namespace is not supported by jackrabbit backend. You can move the old namespace to a different prefix before adding this prefix to work around this issue.");
        }
        // if target uri already exists elsewhere, do not re-send or result is random
        /* weird: we can not unset this or we get the unregister not
                 * supported exception. but we can send two mappings and
                 * jackrabbit does the right guess what we want and moves the
                 * namespace to the new prefix
        
                if (false !== $expref = array_search($uri, $namespaces)) {
                    unset($namespaces[$expref]);
                }
                */
        $request = $this->getRequest(Request::PROPPATCH, $this->workspaceUri);
        $namespaces[$prefix] = $uri;
        $request->setBody($this->buildRegisterNamespaceRequest($namespaces));
        $request->execute();
    }

Usage Example

 /**
  * {@inheritDoc}
  */
 public function registerNamespace($prefix, $uri)
 {
     $this->transport->registerNamespace($prefix, $uri);
 }