Example #1
0
 public function testBuild()
 {
     $registry = new Registry();
     $sculpt = new Sculpt($registry);
     $builder = $sculpt->build(new UserBlueprint($sculpt));
     $this->assertTrue($builder instanceof Builder);
 }
Example #2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Bestiary\Sculpt\Example\Blueprints\UserBlueprint;
use Bestiary\Sculpt\Example\Models\Post;
use Bestiary\Sculpt\Example\Models\User;
use Bestiary\Sculpt\Registry;
use Bestiary\Sculpt\Sculpt;
use Bestiary\Sculpt\Strategy\FilterStrategy;
use Bestiary\Sculpt\Strategy\GroupStrategy;
use Bestiary\Sculpt\Strategy\SortStrategy;
use Bestiary\Sculpt\Strategy\TransformStrategy;
$registry = new Registry(['with' => TransformStrategy::class, 'group' => GroupStrategy::class, 'sort' => SortStrategy::class, 'filter' => FilterStrategy::class]);
$sculpt = new Sculpt($registry);
$users = [new User(1, 'Kate', 18, 'W'), new User(2, 'John', 32, 'M'), new User(3, 'Robin', 11, 'M'), new User(4, 'Boris', 23, 'M')];
$posts = [new Post(1, 'Kate post 1'), new Post(1, 'Kate post 2'), new Post(3, 'Robin post'), new Post(4, 'Boris post')];
$ages = [1 => 11, 2 => 40, 3 => 24];
$single = $sculpt->build(new UserBlueprint())->single($users[0])->with('posts', $posts)->get();
$each = $sculpt->build(new UserBlueprint())->each($users)->with('posts', $posts)->filter('emptyPosts')->sort('byAge')->group('bySex')->get();
print_r(compact('single', 'each'));