ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PluginSerializer.php
Go to the documentation of this file.
2 
9 
16 {
17  const DIVIDER = '|';
18 
19 
23  public function serialize(IdentificationInterface $identification) : string
24  {
28  $divider = self::DIVIDER;
29 
30  $str = "{$identification->getPluginId()}{$divider}{$identification->getClassName()}{$divider}{$identification->getInternalIdentifier()}";
31 
32  if (strlen($str) > SerializerInterface::MAX_LENGTH) {
33  throw new \LogicException("Serialized Identifications MUST be shorter than " . SerializerInterface::MAX_LENGTH . " characters");
34  }
35 
36  return $str;
37  }
38 
39 
43  public function unserialize(string $serialized_string, IdentificationMap $map, ProviderFactoryInterface $provider_factory) : IdentificationInterface
44  {
45  list($plugin_id, $class_name, $internal_identifier) = explode(self::DIVIDER, $serialized_string);
46 
47  if (!$provider_factory->isInstanceCreationPossible($class_name) || !$provider_factory->isRegistered($class_name)) {
48  return new NullPluginIdentification($plugin_id, $serialized_string, $internal_identifier);
49  }
50 
51  $f = new PluginIdentificationProvider($provider_factory->getProviderByClassName($class_name), $plugin_id, $this, $map);
52 
53  return $f->identifier($internal_identifier);
54  }
55 
56 
60  public function canHandle(string $serialized_identification) : bool
61  {
62  return preg_match('/(.*?)\|(.*?)\|(.*)/m', $serialized_identification) > 0;
63  }
64 }
serialize(IdentificationInterface $identification)
The string MUST be shorter than 64 characters.
unserialize(string $serialized_string, IdentificationMap $map, ProviderFactoryInterface $provider_factory)
IdentificationInterface