ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CoreSerializer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
34{
35 public const DIVIDER = '|';
36
37 public function serialize(IdentificationInterface $identification): string
38 {
39 $divider = self::DIVIDER;
40
41 $str = "{$identification->getClassName()}{$divider}{$identification->getInternalIdentifier()}";
42
43 if (strlen($str) > SerializerInterface::MAX_LENGTH) {
44 throw new \LogicException("Serialized Identifications MUST be shorter than " . SerializerInterface::MAX_LENGTH . " characters");
45 }
46
47 return $str;
48 }
49
53 public function unserialize(string $serialized_string, IdentificationMap $map, ProviderFactory $provider_factory): IdentificationInterface
54 {
55 [$class_name, $internal_identifier] = explode(self::DIVIDER, $serialized_string);
56
57 if (!$provider_factory->isInstanceCreationPossible($class_name) || !$provider_factory->isRegistered($class_name)) {
58 return new LostIdentification($serialized_string);
59 }
60
61 $f = new CoreIdentificationProvider($provider_factory->getProviderByClassName($class_name), $this, $map);
62
63 return $f->identifier($internal_identifier);
64 }
65
69 public function canHandle(string $serialized_identification): bool
70 {
71 return preg_match('/(.*?)\|(.*)/m', $serialized_identification) > 0;
72 }
73}
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