public function xInclude($validate = false) {
        
        if (($root = $this->getDocumentComponent()) !== null) {
            
            $baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
            $pathinfo = pathinfo($baseUri);
            $basePath = $pathinfo['dirname'];
            
            $iterator = new QtiComponentIterator($root, array('include'));
            foreach ($iterator as $include) {
                $parent = $iterator->parent();
                
                // Is the parent something we can deal with for replacement?
                $reflection = new ReflectionClass($parent);
                
                if ($reflection->hasMethod('getContent') === true && $parent->getContent() instanceof QtiComponentCollection) {
                    $href = $include->getHref();
                    
                    if (Url::isRelative($href) === true) {
                        $href = Url::rtrim($basePath) . '/' . Url::ltrim($href);
                        
                        $doc = new XmlDocument();
                        $doc->load($href, $validate);
                        $includeRoot = $doc->getDocumentComponent();
                        
                        if ($includeRoot instanceof Flow) {
                            // Derive xml:base...
                            $xmlBase = Url::ltrim(str_replace($basePath, '', $href));
                            $xmlBasePathInfo = pathinfo($xmlBase);
                            
                            if ($xmlBasePathInfo['dirname'] !== '.') {
                                $includeRoot->setXmlBase($xmlBasePathInfo['dirname'] . '/');
                            }
                        }
                        
                        $parent->getContent()->replace($include, $includeRoot);
                    }
                }
            }
        } else {
            $msg = "Cannot include fragments via XInclude before loading any file.";
            throw new LogicException($msg);
        }
    }
public function xInclude($validate = false) {
        
        if (($root = $this->getDocumentComponent()) !== null) {
            
            $baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
            $pathinfo = pathinfo($baseUri);
            $basePath = $pathinfo['dirname'];
            
            $iterator = new QtiComponentIterator($root, array('include'));
            foreach ($iterator as $include) {
                $parent = $iterator->parent();
                
                // Is the parent something we can deal with for replacement?
                $reflection = new ReflectionClass($parent);
                
                if ($reflection->hasMethod('getContent') === true && $parent->getContent() instanceof QtiComponentCollection) {
                    $href = $include->getHref();
                    
                    if (Url::isRelative($href) === true) {
                        $href = Url::rtrim($basePath) . '/' . Url::ltrim($href);
                        
                        $doc = new XmlDocument();
                        $doc->load($href, $validate);
                        $includeRoot = $doc->getDocumentComponent();
                        
                        if ($includeRoot instanceof Flow) {
                            // Derive xml:base...
                            $xmlBase = Url::ltrim(str_replace($basePath, '', $href));
                            $xmlBasePathInfo = pathinfo($xmlBase);
                            
                            if ($xmlBasePathInfo['dirname'] !== '.') {
                                $includeRoot->setXmlBase($xmlBasePathInfo['dirname'] . '/');
                            }
                        }
                        
                        $parent->getContent()->replace($include, $includeRoot);
                    }
                }
            }
        } else {
            $msg = "Cannot include fragments via XInclude before loading any file.";
            throw new LogicException($msg);
        }
    }
public function xInclude ( $ validate = false ) { if ( ( $ root = $ this -> getDocumentComponent ( ) ) !== null ) { $ baseUri = str_replace ( '\\' , '/' , $ this -> getDomDocument ( ) -> documentElement -> baseURI ) ; $ pathinfo = pathinfo ( $ baseUri ) ; $ basePath = $ pathinfo [ 'dirname' ] ; $ iterator = new QtiComponentIterator ( $ root , array ( 'include' ) ) ; foreach ( $ iterator as $ include ) { $ parent = $ iterator -> parent ( ) ; // Is the parent something we can deal with for replacement? $ reflection = new ReflectionClass ( $ parent ) ; if ( $ reflection -> hasMethod ( 'getContent' ) === true && $ parent -> getContent ( ) instanceof QtiComponentCollection ) { $ href = $ include -> getHref ( ) ; if ( Url :: isRelative ( $ href ) === true ) { $ href = Url :: rtrim ( $ basePath ) . '/' . Url :: ltrim ( $ href ) ; $ doc = new XmlDocument ( ) ; $ doc -> load ( $ href , $ validate ) ; $ includeRoot = $ doc -> getDocumentComponent ( ) ; if ( $ includeRoot instanceof Flow ) { // Derive xml:base... $ xmlBase = Url :: ltrim ( str_replace ( $ basePath , '' , $ href ) ) ; $ xmlBasePathInfo = pathinfo ( $ xmlBase ) ; if ( $ xmlBasePathInfo [ 'dirname' ] !== '.' ) { $ includeRoot -> setXmlBase ( $ xmlBasePathInfo [ 'dirname' ] . '/' ) ; } } $ parent -> getContent ( ) -> replace ( $ include , $ includeRoot ) ; } } } } else { $ msg = "Cannot include fragments via XInclude before loading any file." ; throw new LogicException ( $ msg ) ; } }
Resolve include components.

After the item has been loaded using the load or loadFromString method,
the include components can be resolved by calling this method. Files will
be included following the rules described by the XInclude specification.

@param boolean $validate Whether or not validate files being included. Default is false.
@throws \LogicException If the method is called prior the load or loadFromString method was called.
@throws \qtism\data\storage\xml\XmlStorageException If an error occured while parsing or validating files to be included.
Resolve include components .