ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SerializerFactory.php
Go to the documentation of this file.
2 
9 {
10 
14  private static $core_instance;
18  private static $plugin_instance;
19 
20 
24  public function core() : SerializerInterface
25  {
26  if (!isset(self::$core_instance)) {
27  self::$core_instance = new CoreSerializer();
28  }
29 
30  return self::$core_instance;
31  }
32 
33 
37  public function plugin() : SerializerInterface
38  {
39  if (!isset(self::$plugin_instance)) {
40  self::$plugin_instance = new PluginSerializer();
41  }
42 
43  return self::$plugin_instance;
44  }
45 
46 
52  public function fromSerializedIdentification(string $serialized_identification) : SerializerInterface
53  {
54  $plugin = $this->plugin();
55  if ($plugin->canHandle($serialized_identification)) {
56  return $plugin;
57  }
58 
59  $core = $this->core();
60  if ($core->canHandle($serialized_identification)) {
61  return $core;
62  }
63 
64  throw new \InvalidArgumentException("Nobody can handle serialized identification '$serialized_identification'.");
65  }
66 }