X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Flibraries%2Fsrc%2FExternalLibrary%2FDefinition%2FFileDefinitionDiscoveryBase.php;fp=web%2Fmodules%2Fcontrib%2Flibraries%2Fsrc%2FExternalLibrary%2FDefinition%2FFileDefinitionDiscoveryBase.php;h=0151f2794980042ce22a912823c93f5792d4373a;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/libraries/src/ExternalLibrary/Definition/FileDefinitionDiscoveryBase.php b/web/modules/contrib/libraries/src/ExternalLibrary/Definition/FileDefinitionDiscoveryBase.php new file mode 100644 index 000000000..0151f2794 --- /dev/null +++ b/web/modules/contrib/libraries/src/ExternalLibrary/Definition/FileDefinitionDiscoveryBase.php @@ -0,0 +1,82 @@ +serializer = $serializer; + $this->baseUri = $base_uri; + } + + /** + * {@inheritdoc} + */ + public function getDefinition($id) { + if (!$this->hasDefinition($id)) { + throw new LibraryDefinitionNotFoundException($id); + } + return $this->serializer->decode($this->getSerializedDefinition($id)); + } + + /** + * Gets the contents of the library file. + * + * @param $id + * The library ID to retrieve the serialized definition for. + * + * @return string + * The serialized library definition. + * + * @throws \Drupal\libraries\ExternalLibrary\Exception\LibraryDefinitionNotFoundException + */ + abstract protected function getSerializedDefinition($id); + + /** + * Returns the file URI of the library definition file for a given library ID. + * + * @param $id + * The ID of the external library. + * + * @return string + * The file URI of the file the library definition resides in. + */ + protected function getFileUri($id) { + $filename = $id . '.' . $this->serializer->getFileExtension(); + return "$this->baseUri/$filename"; + } + +}