ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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, ProviderFactory $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 LostIdentification($serialized_string);
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}
An exception for terminatinating execution or to throw for unit testing.
canHandle(string $serialized_identification)
@inheritDoc
serialize(IdentificationInterface $identification)
The string MUST be shorter than 64 characters.string LogicException whn longer than 64 characters
unserialize(string $serialized_string, IdentificationMap $map, ProviderFactory $provider_factory)
IdentificationInterface