2017 © Pedro Peláez
 

library serializer

The Serializer classes provide functional with serialization such as check if string is serialized. It is supported unicode text.

image

rundiz/serializer

The Serializer classes provide functional with serialization such as check if string is serialized. It is supported unicode text.

  • Tuesday, January 23, 2018
  • by ve3
  • Repository
  • 1 Watchers
  • 0 Stars
  • 32 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 39 % Grown

The README.md

Serializer Component

The Serializer classes provide functional with serialization such as check if string is serialized, maybe serialize, maybe unserialize, or is JSON encoded (valid JSON) for prevent double serialization. This Serializer also supported unicode text., (*1)

Latest Stable Version License Total Downloads, (*2)

Tested up to PHP 8.4., (*3)

Example:

Check if string is serialized:

$Serializer = new \Rundiz\Serializer\Serializer();

$serialized_string = 's:54:"this is a string. สตริงภาษาไทย";';
$faked_serialized_string = 's:12:"fake serialized string";';

var_dump($Serializer->isSerialized($serialized_string);// true
var_dump($Serializer->isSerialized($faked_serialized_string);// false

Or you can use static methods from \Rundiz\Serializer\SerializerStatic class with the same method as \Rundiz\Serializer\Serializer class., (*4)

$serialized_string = 's:54:"this is a string. สตริงภาษาไทย";';

var_dump(\Rundiz\Serializer\SerializerStatic::isSerialized($serialized_string));// true

Check first if data is not serialized then serialize it:

$raw_data = array('mango', 'tree' => array('mango', 'banana'));

echo $Serializer->maybeSerialize($raw_data);// a:2:{i:0;s:5:"mango";s:4:"tree";a:2:{i:0;s:5:"mango";i:1;s:6:"banana";}}
echo \Rundiz\Serializer\SerializerStatic::maybeSerialize($raw_data);// a:2:{i:0;s:5:"mango";s:4:"tree";a:2:{i:0;s:5:"mango";i:1;s:6:"banana";}}

Check first if data is not unserialized then unserialize it:

$serialized_data = 'i:-5436;';

echo $Serializer->maybeUnserialize($serialized_data);// -5436 (integer)
echo \Rundiz\Serializer\SerializerStatic::maybeUnserialize($serialized_data);// -5436 (integer)
echo \Rundiz\Serializer\SerializerStatic::maybeUnserialize(-5436);// -5436 (integer)

Working with JSON:

var_dump($Serializer->isJSONEncoded('"Hello world"'));// true
var_dump($Serializer->isJSONEncoded('012345'));// false
var_dump($Serializer->isJSONEncoded('true'));// true
var_dump($Serializer->isJSONEncoded('false'));// true
var_dump($Serializer->isJSONEncoded('null'));// true
var_dump($Serializer->isJSONEncoded(true));// true
var_dump($Serializer->isJSONEncoded(false));// false
var_dump($Serializer->isJSONEncoded(null));// false

Working with base64:

var_dump($Serializer->isBase64Encoded(5555));// false
var_dump($Serializer->isBase64Encoded('NTU1NQ=='));// true
var_dump($Serializer->isBase64Encoded('test'));// false
var_dump($Serializer->isBase64Encoded('dGVzdA=='));// true
var_dump($Serializer->isBase64Encoded(null));// false

For more example, please look inside tests folder., (*5)

The Versions

23/01 2018

dev-master

9999999-dev

The Serializer classes provide functional with serialization such as check if string is serialized. It is supported unicode text.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

serialized isserialized is serialized check if serialized

06/05 2017

v1.0.1

1.0.1.0

The Serializer classes provide functional with serialization such as check if string is serialized. It is supported unicode text.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

serialized isserialized is serialized check if serialized

29/04 2017

v1.0

1.0.0.0

The Serializer classes provide functional with serialization such as check if string is serialized.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

serialized isserialized is serialized check if serialized