ILIAS  release_7 Revision v7.30-3-g800a261c036
PluginSerializer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
21
28use LogicException;
29
35{
36 protected const DIVIDER = '|';
37
41 public function serialize(IdentificationInterface $identification) : string
42 {
46 $divider = self::DIVIDER;
47
48 $str = "{$identification->getPluginId()}{$divider}{$identification->getClassName()}{$divider}{$identification->getInternalIdentifier()}";
49
50 if (strlen($str) > SerializerInterface::MAX_LENGTH) {
51 throw new LogicException("Serialized Identifications MUST be shorter than " . SerializerInterface::MAX_LENGTH . " characters");
52 }
53
54 return $str;
55 }
56
60 public function unserialize(string $serialized_string, IdentificationMap $map, ProviderFactory $provider_factory) : IdentificationInterface
61 {
62 [$plugin_id, $class_name, $internal_identifier] = explode(self::DIVIDER, $serialized_string);
63
64 if (!$provider_factory->isInstanceCreationPossible($class_name) || !$provider_factory->isRegistered($class_name)) {
65 return new NullPluginIdentification($plugin_id, $serialized_string, $internal_identifier);
66 }
67
68 $f = new PluginIdentificationProvider($provider_factory->getProviderByClassName($class_name), $plugin_id, $this, $map);
69
70 return $f->identifier($internal_identifier);
71 }
72
76 public function canHandle(string $serialized_identification) : bool
77 {
78 return preg_match('/(.*?)\|(.*?)\|(.*)/m', $serialized_identification) > 0;
79 }
80}
An exception for terminatinating execution or to throw for unit testing.
canHandle(string $serialized_identification)
@inheritDoc
unserialize(string $serialized_string, IdentificationMap $map, ProviderFactory $provider_factory)
IdentificationInterface
serialize(IdentificationInterface $identification)
The string MUST be shorter than 64 characters.