PortalFactory is a static service that manages portal registration and retrieval. It maintains a registry of all available portals and provides methods to access them by code or URL.
Properties
Returns a list of all registered portals.
Methods
registerPortal
Registers a single portal instance in the factory.The portal instance to register. The portal will be indexed by both its URL and code.
registerAll
Registers multiple portals at once.A list of portal instances to register.
fromCode
Retrieves a portal by its unique code identifier.The unique code identifier of the portal.
The portal instance matching the provided code.
ArgumentError if no portal is found with the given code.
Example:
fromUrl
Retrieves a portal by its URL origin.The URI to match against registered portal URLs. Only the origin is used for matching.
The portal instance matching the provided URL origin.
ArgumentError if no portal is found with the given URL.
Example:
fromJson
Deserializes a portal from JSON data.A JSON map containing a ‘code’ field that identifies the portal.
The portal instance identified by the code in the JSON data.
toJson
Serializes a portal to JSON data.The portal instance to serialize.
A JSON map containing the portal’s code.
Usage
ThePortalFactory maintains two internal registries:
- By URL origin: Enables quick lookup when processing book URLs
- By code: Enables lookup by portal identifier