Skip to content

Commit

Permalink
Changed object cache from protected to protected static
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Nov 21, 2015
1 parent 5fb14af commit 655119f
Show file tree
Hide file tree
Showing 21 changed files with 24 additions and 35 deletions.
7 changes: 3 additions & 4 deletions src/DeepCopySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer;

use ReflectionClass;
Expand All @@ -24,15 +23,15 @@ class DeepCopySerializer extends Serializer
*/
protected function serializeObject($value)
{
if ($this->objectStorage->contains($value)) {
return $this->objectStorage[$value];
if (self::$objectStorage->contains($value)) {
return self::$objectStorage[$value];
}

$reflection = new ReflectionClass($value);
$className = $reflection->getName();

$serialized = $this->serializeInternalClass($value, $className, $reflection);
$this->objectStorage->attach($value, $serialized);
self::$objectStorage->attach($value, $serialized);

return $serialized;
}
Expand Down
4 changes: 3 additions & 1 deletion src/JsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer;

use NilPortugues\Serializer\Strategy\JsonStrategy;

class JsonSerializer extends Serializer
{
/**
*
*/
public function __construct()
{
parent::__construct(new JsonStrategy());
Expand Down
24 changes: 12 additions & 12 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ class Serializer
*
* @var SplObjectStorage
*/
protected $objectStorage;
protected static $objectStorage;

/**
* Object mapping for recursion.
*
* @var array
*/
protected $objectMapping = [];
protected static $objectMapping = [];

/**
* Object mapping index.
*
* @var int
*/
protected $objectMappingIndex = 0;
protected static $objectMappingIndex = 0;

/**
* @var \NilPortugues\Serializer\Strategy\StrategyInterface|\NilPortugues\Serializer\Strategy\JsonStrategy
Expand Down Expand Up @@ -122,9 +122,9 @@ public function serialize($value)
*/
protected function reset()
{
$this->objectStorage = new SplObjectStorage();
$this->objectMapping = [];
$this->objectMappingIndex = 0;
self::$objectStorage = new SplObjectStorage();
self::$objectMapping = [];
self::$objectMappingIndex = 0;
}

/**
Expand Down Expand Up @@ -267,7 +267,7 @@ protected function unserializeObject(array $value)
}

if ($className[0] === '@') {
return $this->objectMapping[substr($className, 1)];
return self::$objectMapping[substr($className, 1)];
}

if (!class_exists($className)) {
Expand Down Expand Up @@ -299,7 +299,7 @@ protected function unserializeDateTimeFamilyObject(array $value, $className)
}

$obj = $this->restoreUsingUnserialize($className, $value);
$this->objectMapping[$this->objectMappingIndex++] = $obj;
self::$objectMapping[self::$objectMappingIndex++] = $obj;
}

return $obj;
Expand Down Expand Up @@ -354,7 +354,7 @@ protected function unserializeUserDefinedObject(array $value, $className)
$ref = new ReflectionClass($className);
$obj = $ref->newInstanceWithoutConstructor();

$this->objectMapping[$this->objectMappingIndex++] = $obj;
self::$objectMapping[self::$objectMappingIndex++] = $obj;
$this->setUnserializedObjectProperties($value, $ref, $obj);

if (\method_exists($obj, '__wakeup')) {
Expand Down Expand Up @@ -432,11 +432,11 @@ protected function serializeArray(array $value)
*/
protected function serializeObject($value)
{
if ($this->objectStorage->contains($value)) {
return [self::CLASS_IDENTIFIER_KEY => '@'.$this->objectStorage[$value]];
if (self::$objectStorage->contains($value)) {
return [self::CLASS_IDENTIFIER_KEY => '@'.self::$objectStorage[$value]];
}

$this->objectStorage->attach($value, $this->objectMappingIndex++);
self::$objectStorage->attach($value, self::$objectMappingIndex++);

$reflection = new ReflectionClass($value);
$className = $reflection->getName();
Expand Down
1 change: 0 additions & 1 deletion src/Serializer/HHVM/DatePeriodSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Serializer\HHVM;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Serializer/HHVM/DateTimeImmutableSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Serializer\HHVM;

use NilPortugues\Serializer\Serializer;
Expand Down
1 change: 0 additions & 1 deletion src/Serializer/HHVM/DateTimeSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Serializer\HHVM;

use NilPortugues\Serializer\Serializer;
Expand Down
1 change: 0 additions & 1 deletion src/Serializer/InternalClasses/DateIntervalSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Serializer\InternalClasses;

use DateInterval;
Expand Down
1 change: 0 additions & 1 deletion src/Serializer/InternalClasses/DatePeriodSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Serializer\InternalClasses;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Serializer/InternalClasses/DateTimeZoneSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Serializer\InternalClasses;

use DateTimeZone;
Expand Down
1 change: 0 additions & 1 deletion src/Strategy/JsonStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Strategy;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Strategy/NullStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Strategy;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Strategy/StrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Strategy;

interface StrategyInterface
Expand Down
1 change: 0 additions & 1 deletion src/Strategy/XmlStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Strategy;

use NilPortugues\Serializer\Serializer;
Expand Down
1 change: 0 additions & 1 deletion src/Strategy/YamlStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Strategy;

use Symfony\Component\Yaml\Yaml;
Expand Down
1 change: 0 additions & 1 deletion src/Transformer/AbstractTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Transformer;

use InvalidArgumentException;
Expand Down
1 change: 0 additions & 1 deletion src/Transformer/ArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Transformer;

use NilPortugues\Serializer\Serializer;
Expand Down
1 change: 0 additions & 1 deletion src/Transformer/FlatArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Transformer;

class FlatArrayTransformer extends ArrayTransformer
Expand Down
1 change: 0 additions & 1 deletion src/Transformer/XmlTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Transformer;

use DOMDocument;
Expand Down
1 change: 0 additions & 1 deletion src/Transformer/YamlTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer\Transformer;

use Symfony\Component\Yaml\Yaml;
Expand Down
4 changes: 3 additions & 1 deletion src/XmlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer;

use NilPortugues\Serializer\Strategy\XmlStrategy;

class XmlSerializer extends Serializer
{
/**
*
*/
public function __construct()
{
parent::__construct(new XmlStrategy());
Expand Down
4 changes: 3 additions & 1 deletion src/YamlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Serializer;

use NilPortugues\Serializer\Strategy\YamlStrategy;

class YamlSerializer extends Serializer
{
/**
*
*/
public function __construct()
{
parent::__construct(new YamlStrategy());
Expand Down

0 comments on commit 655119f

Please sign in to comment.