ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SerializerFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
21 
23 
29 {
32 
33  public function core(): CoreSerializer
34  {
35  if (!isset(self::$core_instance)) {
36  self::$core_instance = new CoreSerializer();
37  }
38 
39  return self::$core_instance;
40  }
41 
42  public function plugin(): PluginSerializer
43  {
44  if (!isset(self::$plugin_instance)) {
45  self::$plugin_instance = new PluginSerializer();
46  }
47 
48  return self::$plugin_instance;
49  }
50 
55  public function fromSerializedIdentification(string $serialized_identification): SerializerInterface
56  {
57  $plugin = $this->plugin();
58  if ($plugin->canHandle($serialized_identification)) {
59  return $plugin;
60  }
61 
62  $core = $this->core();
63  if ($core->canHandle($serialized_identification)) {
64  return $core;
65  }
66 
67  throw new InvalidArgumentException("Nobody can handle serialized identification '$serialized_identification'.");
68  }
69 }