コード例 #1
0
 /**
  * Deserialize the given data
  *
  * @param array $toDeserialize The serialized array to deserialize
  * @param array $inherited Data inherited from a parent entity (ignored)
  * @return array
  * @throws IntegrityException
  */
 public function deserialize(array $toDeserialize, array $inherited = [])
 {
     $container = [];
     foreach ($this->template as $key => $rule) {
         if ($rule instanceof RuleInterface && $rule->isId()) {
             if (isset($toDeserialize["_id"]) && !is_null($this->id)) {
                 $this->idResolver->bind($toDeserialize["_id"], $this->id);
                 $container[$key] = $this->id;
                 break;
             } else {
                 throw new IntegrityException("Couldn't find the id rule or value for the deserialization");
             }
         }
     }
     return $container;
 }
コード例 #2
0
ファイル: IdResolverTest.php プロジェクト: prewk/seriplating
 public function test_fallbacks()
 {
     $resolver = new IdResolver();
     $fooRepository = Mockery::mock("Prewk\\Seriplating\\Contracts\\RepositoryInterface");
     $barRepository = Mockery::mock("Prewk\\Seriplating\\Contracts\\RepositoryInterface");
     $resolver->bind("foos_0", 1);
     $resolver->defer("bars_2", $fooRepository, 1, "data.bars.0.bar_id");
     $resolver->defer("bars_3", $fooRepository, 1, "data.bars.1.bar_id", [], 0);
     $resolver->bind("foos_1", 2);
     $resolver->bind("bars_2", 3);
     $resolver->defer("foos_0", $barRepository, 3, "foo_id");
     $fooRepository->shouldReceive("update")->once()->with(1, ["data" => ["bars" => [["bar_id" => 3], ["bar_id" => 0]]]]);
     $barRepository->shouldReceive("update")->once()->with(3, ["foo_id" => 1]);
     $resolver->resolve();
 }