Skip to content

Commit 655119f

Browse files
committed
Changed object cache from protected to protected static
1 parent 5fb14af commit 655119f

21 files changed

+24
-35
lines changed

src/DeepCopySerializer.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer;
1312

1413
use ReflectionClass;
@@ -24,15 +23,15 @@ class DeepCopySerializer extends Serializer
2423
*/
2524
protected function serializeObject($value)
2625
{
27-
if ($this->objectStorage->contains($value)) {
28-
return $this->objectStorage[$value];
26+
if (self::$objectStorage->contains($value)) {
27+
return self::$objectStorage[$value];
2928
}
3029

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

3433
$serialized = $this->serializeInternalClass($value, $className, $reflection);
35-
$this->objectStorage->attach($value, $serialized);
34+
self::$objectStorage->attach($value, $serialized);
3635

3736
return $serialized;
3837
}

src/JsonSerializer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer;
1312

1413
use NilPortugues\Serializer\Strategy\JsonStrategy;
1514

1615
class JsonSerializer extends Serializer
1716
{
17+
/**
18+
*
19+
*/
1820
public function __construct()
1921
{
2022
parent::__construct(new JsonStrategy());

src/Serializer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ class Serializer
2323
*
2424
* @var SplObjectStorage
2525
*/
26-
protected $objectStorage;
26+
protected static $objectStorage;
2727

2828
/**
2929
* Object mapping for recursion.
3030
*
3131
* @var array
3232
*/
33-
protected $objectMapping = [];
33+
protected static $objectMapping = [];
3434

3535
/**
3636
* Object mapping index.
3737
*
3838
* @var int
3939
*/
40-
protected $objectMappingIndex = 0;
40+
protected static $objectMappingIndex = 0;
4141

4242
/**
4343
* @var \NilPortugues\Serializer\Strategy\StrategyInterface|\NilPortugues\Serializer\Strategy\JsonStrategy
@@ -122,9 +122,9 @@ public function serialize($value)
122122
*/
123123
protected function reset()
124124
{
125-
$this->objectStorage = new SplObjectStorage();
126-
$this->objectMapping = [];
127-
$this->objectMappingIndex = 0;
125+
self::$objectStorage = new SplObjectStorage();
126+
self::$objectMapping = [];
127+
self::$objectMappingIndex = 0;
128128
}
129129

130130
/**
@@ -267,7 +267,7 @@ protected function unserializeObject(array $value)
267267
}
268268

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

273273
if (!class_exists($className)) {
@@ -299,7 +299,7 @@ protected function unserializeDateTimeFamilyObject(array $value, $className)
299299
}
300300

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

305305
return $obj;
@@ -354,7 +354,7 @@ protected function unserializeUserDefinedObject(array $value, $className)
354354
$ref = new ReflectionClass($className);
355355
$obj = $ref->newInstanceWithoutConstructor();
356356

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

360360
if (\method_exists($obj, '__wakeup')) {
@@ -432,11 +432,11 @@ protected function serializeArray(array $value)
432432
*/
433433
protected function serializeObject($value)
434434
{
435-
if ($this->objectStorage->contains($value)) {
436-
return [self::CLASS_IDENTIFIER_KEY => '@'.$this->objectStorage[$value]];
435+
if (self::$objectStorage->contains($value)) {
436+
return [self::CLASS_IDENTIFIER_KEY => '@'.self::$objectStorage[$value]];
437437
}
438438

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

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

src/Serializer/HHVM/DatePeriodSerializer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Serializer\HHVM;
1312

1413
/**

src/Serializer/HHVM/DateTimeImmutableSerializer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Serializer\HHVM;
1312

1413
use NilPortugues\Serializer\Serializer;

src/Serializer/HHVM/DateTimeSerializer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Serializer\HHVM;
1312

1413
use NilPortugues\Serializer\Serializer;

src/Serializer/InternalClasses/DateIntervalSerializer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Serializer\InternalClasses;
1312

1413
use DateInterval;

src/Serializer/InternalClasses/DatePeriodSerializer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Serializer\InternalClasses;
1312

1413
/**

src/Serializer/InternalClasses/DateTimeZoneSerializer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Serializer\InternalClasses;
1312

1413
use DateTimeZone;

src/Strategy/JsonStrategy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Strategy;
1312

1413
/**

src/Strategy/NullStrategy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Strategy;
1312

1413
/**

src/Strategy/StrategyInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Strategy;
1312

1413
interface StrategyInterface

src/Strategy/XmlStrategy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Strategy;
1312

1413
use NilPortugues\Serializer\Serializer;

src/Strategy/YamlStrategy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Strategy;
1312

1413
use Symfony\Component\Yaml\Yaml;

src/Transformer/AbstractTransformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Transformer;
1312

1413
use InvalidArgumentException;

src/Transformer/ArrayTransformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Transformer;
1312

1413
use NilPortugues\Serializer\Serializer;

src/Transformer/FlatArrayTransformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Transformer;
1312

1413
class FlatArrayTransformer extends ArrayTransformer

src/Transformer/XmlTransformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Transformer;
1312

1413
use DOMDocument;

src/Transformer/YamlTransformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer\Transformer;
1312

1413
use Symfony\Component\Yaml\Yaml;

src/XmlSerializer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer;
1312

1413
use NilPortugues\Serializer\Strategy\XmlStrategy;
1514

1615
class XmlSerializer extends Serializer
1716
{
17+
/**
18+
*
19+
*/
1820
public function __construct()
1921
{
2022
parent::__construct(new XmlStrategy());

src/YamlSerializer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11-
1211
namespace NilPortugues\Serializer;
1312

1413
use NilPortugues\Serializer\Strategy\YamlStrategy;
1514

1615
class YamlSerializer extends Serializer
1716
{
17+
/**
18+
*
19+
*/
1820
public function __construct()
1921
{
2022
parent::__construct(new YamlStrategy());

0 commit comments

Comments
 (0)