1. Go to this page and download the library: Download peekandpoke/slumber library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// we need an instance of a PSR-11 container (should be provided by the application)
$di = ...;
// we need a doctrine annotation reader (you should use caching, ideally APCU as cache)
$annotationReader = new AnnotationReader();
// SLUMBER: we need a configuration reader (you should wrap the reader with CachedEntityConfigLookUp for good performance)
$reader = new AnnotatedEntityConfigReader($di, $annotationReader, new ArrayCodecPropertyMarker2Mapper());
// SLUMBER: finally we get the codec
$codec = new ArrayCodec($reader);
// then use it for serializating objects into array data
$data = $codec->slumber(new Person());
// or use if for de-serializating array data back into objects
$person = $codec->awake($data, Person::class);
class C {
/**
* @Slumber\AsBool()
*/
private $val = true;
}
class C {
/**
* @Slumber\AsBool()
*/
private $val = 0;
}
class C {
/**
* @Slumber\AsDecimal()
*/
private $val = 1.23;
}
class C {
/**
* @Slumber\AsDecimal()
*/
private $val = "abc";
}
class C {
/**
* @Slumber\AsInteger()
*/
private $val = 1.23;
}
class C {
/**
* @Slumber\AsInteger()
*/
private $val = "abc";
}
class C {
/**
* @Slumber\AsAs()
*/
private $val = 1.23;
}
class C {
/**
* @Slumber\AsIs()
*/
private $val = "abc";
}
class C {
/**
* @Slumber\AsString()
*/
private $val = 1.23;
}
class C {
/**
* @Slumber\AsString()
*/
private $val = "abc";
}
class B {
/**
* @Slumber\AsString()
*/
private $name;
}
class C {
/**
* @Slumber\AsObject(B::class)
*/
private $val = new B(); // syntax error ... new B() only for demonstration purposes
}
class C {
/**
* @Slumber\AsString()
*/
private $val = "abc";
}
class Enum extends Enumerated {
/** @var Enum */
public static $ONE;
/** @var Enum */
public static $TWO;
}
Enum::init();
class C {
/**
* @Slumber\AsEnum(Enum::class)
*/
private $val = Enum::$ONE;
}
class C {
/**
* @Slumber\AsEnum(Enum::class)
*/
private $val = "abc";
}
class C {
/**
* @Slumber\AsList(
* @Slumber\AsDecimal()
* )
*/
private $val = [1.1, 2.2, 3.3];
}