1. Go to this page and download the library: Download prewk/seriplating 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/ */
prewk / seriplating example snippets
use Prewk\Seriplating\GenericDeserializer;
use Prewk\Seriplating\GenericSerializer;
use Prewk\Seriplating\IdFactory;
use Prewk\Seriplating\IdResolver;
use Prewk\Seriplating\HierarchicalTemplate;
use Prewk\SeriplatingTemplate;
use Prewk\Seriplating\Seriplater;
use Prewk\Seriplating\Rule;
// Boilerplate classes
$t = new Seriplater(new Rule);
$idFactory = new IdFactory;
$idResolver = new IdResolver;
$genericSerializer = new GenericSerializer($idFactory);
$genericDeserializer = new GenericDeserializer($idResolver);
$hierarchy = new HierarchicalTemplate($idResolver);
// Bring your own repositories, implement Prewk\Seriplating\Contracts\RepositoryInterface
$fooRepository = new FooRepository;
$barRepository = new BarRepository;
$bazRepository = new BazRepository;
// A Foo entity has two Bars and a Baz
// Corresponding database tables could be foos, bars, and bazes
// Construct the serialization templates
// ..for Foo
$fooSeriplater = new GenericSerializer($genericSerializer, $genericDeserializer, fooRepository, [
"id" => $t->id("foos"),
"setting" => $t->value(),
"bars" => $t->hasMany("bars"),
]);
// ..for Bar
$barSeriplater = new GenericSerializer($genericSerializer, $genericDeserializer, barRepository, [
"id" => $t->id("bars"),
"sort_order" => $t->increments(),
"baz_id" => $t->references("bazes"),
]);
// ..for Baz
$bazSeriplater = new GenericSerializer($genericSerializer, $genericDeserializer, bazRepository, [
"id" => $t->id("bazes"),
"content" => $t->value(),
]);
// Register them in the hierarchical templating class
$hierarchy
->register($fooSeriplater)
->register($barSeriplater)
->register($bazSeriplater);
// Deserialize
$deserialized = $hierarchy->deserialize("foos", $serialization);
// The appropriate provided repositories will now have been called and entities will be created in the db
$fooId = $deserialized["id"];