ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
CoreSerializer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
21 
27 
33 {
34  public const DIVIDER = '|';
35 
36  public function serialize(IdentificationInterface $identification): string
37  {
38  $divider = self::DIVIDER;
39 
40  $str = "{$identification->getClassName()}{$divider}{$identification->getInternalIdentifier()}";
41 
42  if (strlen($str) > SerializerInterface::MAX_LENGTH) {
43  throw new \LogicException("Serialized Identifications MUST be shorter than " . SerializerInterface::MAX_LENGTH . " characters");
44  }
45 
46  return $str;
47  }
48 
52  public function unserialize(string $serialized_string, IdentificationMap $map, ProviderFactory $provider_factory): IdentificationInterface
53  {
54  list($class_name, $internal_identifier) = explode(self::DIVIDER, $serialized_string);
55 
56  if (!$provider_factory->isInstanceCreationPossible($class_name) || !$provider_factory->isRegistered($class_name)) {
57  return new LostIdentification($serialized_string);
58  }
59 
60  $f = new CoreIdentificationProvider($provider_factory->getProviderByClassName($class_name), $this, $map);
61 
62  return $f->identifier($internal_identifier);
63  }
64 
68  public function canHandle(string $serialized_identification): bool
69  {
70  return preg_match('/(.*?)\|(.*)/m', $serialized_identification) > 0;
71  }
72 }
unserialize(string $serialized_string, IdentificationMap $map, ProviderFactory $provider_factory)
IdentificationInterface
serialize(IdentificationInterface $identification)
The string MUST be shorter than 64 characters.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...