public function createMarshaller($object, array $args = array())
    {
        if ($object instanceof QtiComponent) {
            // Asking for a Marshaller...
            $qtiClassName = $object->getQtiClassName();
            
            if ($this->isWebComponentFriendly() === true && in_array($qtiClassName, Marshaller::$webComponentFriendlyClasses)) {
                $qtiClassName = XmlUtils::webComponentFriendlyClassName($qtiClassName);
            }
        } elseif ($object instanceof DOMElement) {
            // Asking for an Unmarshaller...
            $qtiClassName = $object->localName;
        }

        if (isset($qtiClassName)) {

            try {
                // Look for a mapping entry.
                if ($object instanceof DOMElement && $this->hasMappingEntry($qtiClassName, $object->namespaceURI)) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->namespaceURI));
                } elseif ($object instanceof ExternalQtiComponent && $this->hasMappingEntry($qtiClassName, $object->getTargetNamespace())) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->getTargetNamespace()));
                } elseif ($this->hasMappingEntry($qtiClassName)) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName));
                } else {
                    // No qtiClassName/mapping entry found.
                    $msg ="No mapping entry found for QTI class name '${qtiClassName}'.";
                    throw new MarshallerNotFoundException($msg, $qtiClassName);
                    
                }
            } catch (ReflectionException $e) {
                $msg = "No marshaller implementation could be found for component '${qtiClassName}'.";
                throw new MarshallerNotFoundException($msg, $qtiClassName, $e);
            }

            $marshaller = $this->instantiateMarshaller($class, $args);
            $marshaller->setMarshallerFactory($this);

            return $marshaller;
        } else {
            $msg = "The object argument must be a QtiComponent or a DOMElementObject, '" . gettype($object) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
public function createMarshaller($object, array $args = array())
    {
        if ($object instanceof QtiComponent) {
            // Asking for a Marshaller...
            $qtiClassName = $object->getQtiClassName();
            
            if ($this->isWebComponentFriendly() === true && in_array($qtiClassName, Marshaller::$webComponentFriendlyClasses)) {
                $qtiClassName = XmlUtils::webComponentFriendlyClassName($qtiClassName);
            }
        } elseif ($object instanceof DOMElement) {
            // Asking for an Unmarshaller...
            $qtiClassName = $object->localName;
        }

        if (isset($qtiClassName)) {

            try {
                // Look for a mapping entry.
                if ($object instanceof DOMElement && $this->hasMappingEntry($qtiClassName, $object->namespaceURI)) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->namespaceURI));
                } elseif ($object instanceof ExternalQtiComponent && $this->hasMappingEntry($qtiClassName, $object->getTargetNamespace())) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->getTargetNamespace()));
                } elseif ($this->hasMappingEntry($qtiClassName)) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName));
                } else {
                    // No qtiClassName/mapping entry found.
                    $msg ="No mapping entry found for QTI class name '${qtiClassName}'.";
                    throw new MarshallerNotFoundException($msg, $qtiClassName);
                    
                }
            } catch (ReflectionException $e) {
                $msg = "No marshaller implementation could be found for component '${qtiClassName}'.";
                throw new MarshallerNotFoundException($msg, $qtiClassName, $e);
            }

            $marshaller = $this->instantiateMarshaller($class, $args);
            $marshaller->setMarshallerFactory($this);

            return $marshaller;
        } else {
            $msg = "The object argument must be a QtiComponent or a DOMElementObject, '" . gettype($object) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
public function createMarshaller ( $ object , array $ args = array ( ) ) { if ( $ object instanceof QtiComponent ) { // Asking for a Marshaller... $ qtiClassName = $ object -> getQtiClassName ( ) ; if ( $ this -> isWebComponentFriendly ( ) === true && in_array ( $ qtiClassName , Marshaller :: $ webComponentFriendlyClasses ) ) { $ qtiClassName = XmlUtils :: webComponentFriendlyClassName ( $ qtiClassName ) ; } } elseif ( $ object instanceof DOMElement ) { // Asking for an Unmarshaller... $ qtiClassName = $ object -> localName ; } if ( isset ( $ qtiClassName ) ) { try { // Look for a mapping entry. if ( $ object instanceof DOMElement && $ this -> hasMappingEntry ( $ qtiClassName , $ object -> namespaceURI ) ) { $ class = new ReflectionClass ( $ this -> getMappingEntry ( $ qtiClassName , $ object -> namespaceURI ) ) ; } elseif ( $ object instanceof ExternalQtiComponent && $ this -> hasMappingEntry ( $ qtiClassName , $ object -> getTargetNamespace ( ) ) ) { $ class = new ReflectionClass ( $ this -> getMappingEntry ( $ qtiClassName , $ object -> getTargetNamespace ( ) ) ) ; } elseif ( $ this -> hasMappingEntry ( $ qtiClassName ) ) { $ class = new ReflectionClass ( $ this -> getMappingEntry ( $ qtiClassName ) ) ; } else { // No qtiClassName/mapping entry found. $ msg = "No mapping entry found for QTI class name '${qtiClassName}'." ; throw new MarshallerNotFoundException ( $ msg , $ qtiClassName ) ; } } catch ( ReflectionException $ e ) { $ msg = "No marshaller implementation could be found for component '${qtiClassName}'." ; throw new MarshallerNotFoundException ( $ msg , $ qtiClassName , $ e ) ; } $ marshaller = $ this -> instantiateMarshaller ( $ class , $ args ) ; $ marshaller -> setMarshallerFactory ( $ this ) ; return $ marshaller ; } else { $ msg = "The object argument must be a QtiComponent or a DOMElementObject, '" . gettype ( $ object ) . "' given." ; throw new InvalidArgumentException ( $ msg ) ; } }
Create a marshaller for a given QtiComponent or DOMElement object, depending on the current mapping
of the MarshallerFactory. If no mapping entry can be found, the factory will perform a ultimate
trial in the qtism\\data\\storage\\xml\\marshalling namespace to find the relevant Marshaller object.

The newly created marshaller will be set up with the MarshallerFactory itself as its MarshallerFactory
object (yes, we know, this is highly recursive but necessary x)).

@param \DOMElement|\qtism\data\QtiComponent $object A QtiComponent or DOMElement object you want to get the corresponding Marshaller object.
@param array $args An optional array of arguments to be passed to the Marshaller constructor.
@throws \InvalidArgumentException If $object is not a QtiComponent nor a DOMElement object.
@throws \RuntimeException If no Marshaller object can be created for the given $object.
@throws \qtism\data\storage\xml\marshalling\MarshallerNotFoundException If no Marshaller mapping is set for a given $object.
@return \qtism\data\storage\xml\marshalling\Marshaller The corresponding Marshaller object.
Create a marshaller for a given QtiComponent or DOMElement object depending on the current mapping of the MarshallerFactory . If no mapping entry can be found the factory will perform a ultimate trial in the qtism \\ data \\ storage \\ xml \\ marshalling namespace to find the relevant Marshaller object .