ILIAS  release_7 Revision v7.30-3-g800a261c036
CoreSerializer.php
Go to the documentation of this file.
1<?php
2
19declare(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 [$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}
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.
unserialize(string $serialized_string, IdentificationMap $map, ProviderFactory $provider_factory)
IdentificationInterface