/**
  * @param Serializer $serializer
  * @param array      $value
  *
  * @return mixed
  */
 protected static function getTypedValue(Serializer $serializer, array $value)
 {
     foreach ($value as &$v) {
         $v = $serializer->unserialize($v);
     }
     return $value;
 }
 /**
  * @param Serializer $serializer
  * @param string     $className
  * @param array      $value
  *
  * @return object
  */
 public static function unserialize(Serializer $serializer, $className, array $value)
 {
     $ref = new ReflectionClass($className);
     foreach ($value as &$v) {
         if (is_array($v)) {
             $v = $serializer->unserialize($v);
         }
     }
     return $ref->newInstanceArgs($value);
 }
 /**
  * @param Serializer $serializer
  * @param string     $className
  * @param array      $value
  *
  * @return mixed
  */
 public static function unserialize(Serializer $serializer, $className, array $value)
 {
     $data = $serializer->unserialize($value[Serializer::SCALAR_VALUE]);
     /* @var SplFixedArray $instance */
     $ref = new ReflectionClass($className);
     $instance = $ref->newInstanceWithoutConstructor();
     $instance->setSize(count($data));
     foreach ($data as $k => $v) {
         $instance[$k] = $v;
     }
     return $instance;
 }
Esempio n. 4
0
 public function testSerializationOfAnArrayOfScalars()
 {
     $scalar = 'a string';
     $serializer = new Serializer(new \NilPortugues\Serializer\Strategy\JsonStrategy());
     $serialized = $serializer->serialize($scalar);
     $this->assertEquals($scalar, $serializer->unserialize($serialized));
 }