ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CoreSerializer.php
Go to the documentation of this file.
2 
8 
15 {
16  const DIVIDER = '|';
17 
18 
22  public function serialize(IdentificationInterface $identification) : string
23  {
24  $divider = self::DIVIDER;
25 
26  $str = "{$identification->getClassName()}{$divider}{$identification->getInternalIdentifier()}";
27 
28  if (strlen($str) > SerializerInterface::MAX_LENGTH) {
29  throw new \LogicException("Serialized Identifications MUST be shorter than " . SerializerInterface::MAX_LENGTH . " characters");
30  }
31 
32  return $str;
33  }
34 
35 
39  public function unserialize(string $serialized_string, IdentificationMap $map, ProviderFactoryInterface $provider_factory) : IdentificationInterface
40  {
41  list($class_name, $internal_identifier) = explode(self::DIVIDER, $serialized_string);
42 
43  if (!$provider_factory->isInstanceCreationPossible($class_name) || !$provider_factory->isRegistered($class_name)) {
44  return new NullIdentification();
45  }
46 
47  $f = new CoreIdentificationProvider($provider_factory->getProviderByClassName($class_name), $this, $map);
48 
49  return $f->identifier($internal_identifier);
50  }
51 
52 
56  public function canHandle(string $serialized_identification) : bool
57  {
58  return preg_match('/(.*?)\|(.*)/m', $serialized_identification) > 0;
59  }
60 }
serialize(IdentificationInterface $identification)
The string MUST be shorter than 64 characters.string
unserialize(string $serialized_string, IdentificationMap $map, ProviderFactoryInterface $provider_factory)
IdentificationInterface