cerpus / edlib-resource-kit
Create resource types for Edlib
Requires
- php: 8.0.*|8.1.*|8.2.*
- cerpus/pubsub: ^1.0
- php-http/discovery: ^1.14.1
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-factory: ^1.0
- psr/http-factory-implementation: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.4
- guzzlehttp/psr7: ^2.1
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-21 12:26:53 UTC
README
Create custom content types for Edlib.
Requirements
- PHP 8.2, 8.3 or 8.4
Installation
composer require cerpus/edlib-resource-kit
Usage
Edlib is notified of new content via the LTI Content-Item Message standard. Edlib Resource Kit provides message objects, mappers, and serialisers for working with Content-Item messages.
Mapping
Map serialised Content-Item graphs to message objects:
use Cerpus\EdlibResourceKit\Lti\Lti11\Mapper\DeepLinking\ContentItemsMapper; $mapper = new ContentItemsMapper(); $items = $mapper->map(<<<EOJSON { "@context": "http://purl.imsglobal.org/ctx/lti/v1/ContentItem", "@graph": [ { "@type": "LtiLinkItem", "mediaType": "application/vnd.ims.lti.v1.ltilink", "title": "My Cool LTI Content", "url": "https://example.com/my-lti-content" } ] } EOJSON); echo count($items), "\n"; // 1 echo $items[0]->getTitle(), "\n"; // My Cool LTI Content
The JSON input must match the compacted JSON-LD representation, as can be seen in the LTI Deep Linking 1.0 specification. If the input does not match, a JSON-LD processor can be used to make the input compliant.
Serialisation
Convert Content-Item message objects to their serialised JSON representations:
use Cerpus\EdlibResourceKit\Lti\Message\DeepLinking\LtiLinkItem; use Cerpus\EdlibResourceKit\Lti\Lti11\Serializer\DeepLinking\ContentItemsSerializer; $items = [ new LtiLinkItem( mediaType: 'application/vnd.ims.lti.v1.ltilink', title: 'My Cool LTI Content', url: 'https://example.com/my-lti-content', ), ]; $serializer = new ContentItemsSerializer(); $serialized = $serializer->serialize($items); echo json_encode($serialized);
Output:
{ "@context": "http://purl.imsglobal.org/ctx/lti/v1/ContentItem", "@graph": [ { "@type": "LtiLinkItem", "mediaType": "application/vnd.ims.lti.v1.ltilink", "title": "My Cool LTI Content", "url": "https://example.com/my-lti-content" } ] }
Framework integration
We provide integration with Laravel that simplifies use of this package.
License
This package is released under the GNU General Public License 3.0. See the
LICENSE
file for more information.