Skip to content

Commit

Permalink
Missing Identifier management in PhpQtiDatatypeMarshaller.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Oct 6, 2015
1 parent efcac02 commit e9e749c
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use qtism\common\datatypes\Duration;
use qtism\common\datatypes\Pair;
use qtism\common\datatypes\Coords;
use qtism\common\datatypes\Identifier;
use qtism\common\datatypes\QtiDatatype;

/**
Expand Down Expand Up @@ -65,6 +66,10 @@ public function marshall()
} elseif ($toMarshall instanceof Point) {
$this->marshallPoint();

return;
} else if ($toMarshall instanceof Identifier) {
$this->marshallIdentifier();

return;
}
} catch (PhpMarshallingException $e) {
Expand Down Expand Up @@ -184,6 +189,32 @@ protected function marshallDuration()
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
}

/**
* Marshall an Identifier QTI datatype object.
*
* @throws \qtism\data\storage\php\marshalling\PhpMarshallingException
*/
protected function marshallIdentifier()
{
$identifier = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();

try {
$varName = $ctx->generateVariableName($identifier);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($identifier->getValue())));
$access->writeInstantiation(get_class($identifier), $args);
$access->writeSemicolon($ctx->mustFormatOutput());

$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling an Identifier object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
}

/**
* Marshall a Point QTI datatype object.
Expand Down

0 comments on commit e9e749c

Please sign in to comment.