Skip to content

Commit

Permalink
Merge pull request #967 from schmittjoh/2.0-compat
Browse files Browse the repository at this point in the history
Serializer 2.0 compatibility features
  • Loading branch information
goetas authored Jul 16, 2018
2 parents d328d9c + 63fa8b4 commit 942b566
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"extra": {
"branch-alias": {
"dev-1.x": "1.11-dev"
"dev-1.x": "1.13-dev"
}
}
}
11 changes: 11 additions & 0 deletions src/JMS/Serializer/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
abstract class Context
{
/**
* @deprecated use has/get/set attribute methods
* @var \PhpCollection\Map
*/
public $attributes;
Expand Down Expand Up @@ -96,6 +97,16 @@ public function getExclusionStrategy()
return $this->exclusionStrategy;
}

public function hasAttribute($key)
{
return $this->attributes->get($key)->isDefined();
}

public function getAttribute($key)
{
return $this->attributes->get($key)->get();
}

public function setAttribute($key, $value)
{
$this->assertMutable();
Expand Down
3 changes: 0 additions & 3 deletions src/JMS/Serializer/GraphNavigator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
*/
final class GraphNavigator implements GraphNavigatorInterface
{
const DIRECTION_SERIALIZATION = 1;
const DIRECTION_DESERIALIZATION = 2;

/**
* @var ExpressionLanguageExclusionStrategy
*/
Expand Down
2 changes: 2 additions & 0 deletions src/JMS/Serializer/GraphNavigatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
interface GraphNavigatorInterface
{
const DIRECTION_SERIALIZATION = 1;
const DIRECTION_DESERIALIZATION = 2;
/**
* Called for each node of the graph that is being traversed.
*
Expand Down
17 changes: 17 additions & 0 deletions src/JMS/Serializer/XmlSerializationVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,18 @@ public function getCurrentMetadata()
return $this->currentMetadata;
}

/**
* @param bool $create (default = false)
* @return \DOMDocument
*/
public function getDocument()
{
if (func_num_args() === 1) {
if (null === $this->document && func_get_arg(0) === true) {
$this->document = $this->createDocument();
}
}

return $this->document;
}

Expand All @@ -388,6 +398,13 @@ public function revertCurrentMetadata()
return $this->currentMetadata = $this->metadataStack->pop();
}

/**
* @deprecated Use $this->getDocument(true) instead
* @param null $version
* @param null $encoding
* @param bool $addRoot
* @return \DOMDocument
*/
public function createDocument($version = null, $encoding = null, $addRoot = true)
{
$doc = new \DOMDocument($version ?: $this->defaultVersion, $encoding ?: $this->defaultEncoding);
Expand Down

0 comments on commit 942b566

Please sign in to comment.