Skip to content

Commit 78d60ab

Browse files
authored
remove edlib 2 support (#10)
1 parent 72fa5cd commit 78d60ab

28 files changed

+6
-1542
lines changed

README.md

+4-195
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@ Create custom content types for [Edlib](https://edlib.com/).
66

77
## Requirements
88

9-
* PHP 8.2
10-
* A [PSR-17](https://www.php-fig.org/psr/psr-17/) implementation, e.g.
11-
[guzzlehttp/psr7](https://packagist.org/packages/guzzlehttp/psr7)
12-
* A [PSR-18](https://www.php-fig.org/psr/psr-18/) compatible HTTP client, e.g.
13-
[Guzzle 7](https://packagist.org/packages/guzzlehttp/guzzle)
14-
* Network access to Edlib internal services
15-
* A RabbitMQ instance shared with Edlib (optional)
9+
* PHP 8.2 or 8.3
1610

1711
## Installation
1812

1913
~~~sh
20-
composer require cerpus/edlib-resource-kit guzzlehttp/guzzle:^7 guzzlehttp/psr7
14+
composer require cerpus/edlib-resource-kit
2115
~~~
2216

23-
## Usage (Edlib 3)
17+
## Usage
2418

25-
Rather than communicating via bespoke APIs over private network connections,
26-
Edlib 3 is notified of new content via the [LTI Content-Item Message standard](http://www.imsglobal.org/specs/lticiv1p0/specification).
19+
Edlib is notified of new content via the [LTI Content-Item Message standard](http://www.imsglobal.org/specs/lticiv1p0/specification).
2720
Edlib Resource Kit provides message objects, mappers, and serialisers for
2821
working with Content-Item messages.
2922

@@ -96,196 +89,12 @@ Output:
9689
}
9790
```
9891

99-
## Usage (old Edlib)
100-
10192
### Framework integration
10293

10394
We provide [integration with
10495
Laravel](https://github.com/cerpus/php-edlib-resource-kit-laravel) that
10596
simplifies use of this package.
10697

107-
### Configuration
108-
109-
There are two ways of making Edlib aware of new resources:
110-
111-
* Using the message bus
112-
* Synchronous HTTP request
113-
114-
The HTTP approach is slower, but waits for the publishing of a resource to be
115-
completed, allowing for error handling.
116-
117-
When using the message bus approach, a RabbitMQ connection must be provided:
118-
119-
~~~php
120-
use Cerpus\EdlibResourceKit\ResourceKit;
121-
use Cerpus\PubSub\Connection\ConnectionFactory;
122-
123-
$connectionFactory = new ConnectionFactory('localhost', 5672, 'guest', 'guest');
124-
$resourceKit = new ResourceKit($connectionFactory);
125-
~~~
126-
127-
For the HTTP approach, other than providing the `synchronousResourceManager`
128-
flag, there is no mandatory configuration:
129-
130-
~~~php
131-
use Cerpus\EdlibResourceKit\ResourceKit;
132-
133-
$resourceKit = new ResourceKit(synchronousResourceManager: true);
134-
~~~~
135-
136-
Once you have a ResourceKit instance, you can begin to access the various
137-
components of it:
138-
139-
~~~php
140-
$resourceManager = $resourceKit->getResourceManager();
141-
$versionManager = $resourecKit->getResourceVersionManager();
142-
~~~~
143-
144-
### Notifying Edlib of content updates
145-
146-
Given a model class representing an item of your custom content type (in this
147-
case an article):
148-
149-
~~~php
150-
namespace App\Models;
151-
152-
use Cerpus\EdlibResourceKit\Contract\EdlibResource;
153-
154-
class Article
155-
{
156-
// Database-mapped article ID
157-
private string $id;
158-
159-
public function toEdlibResource(): EdlibResource
160-
{
161-
return new ArticleEdlibResource($this->id, /* ... */);
162-
}
163-
}
164-
~~~
165-
166-
Create an accompanying `EdlibResource` class:
167-
168-
~~~php
169-
namespace App\DataObjects;
170-
171-
use Cerpus\EdlibResourceKit\Contract\EdlibResource;
172-
173-
class ArticleEdlibResource implements EdlibResource
174-
{
175-
public function __construct(private string $systemId, /* ... */)
176-
{
177-
}
178-
179-
public function getSystemName(): string
180-
{
181-
return 'my-unique-and-persistent-system-name';
182-
}
183-
184-
public function getSystemId(): string
185-
{
186-
return $this->systemId;
187-
}
188-
189-
public function getContentType(): string|null
190-
{
191-
return 'article';
192-
}
193-
194-
// ... implement the remaining EdlibResource methods here
195-
}
196-
~~~
197-
198-
When the article is created or updated, a corresponding call to the resource
199-
manager must take place. The procedure will vary depending on your framework of
200-
choice, but here it is demonstrated using the observer pattern:
201-
202-
~~~php
203-
use Cerpus\EdlibResourceKit\Contract\EdlibResource;
204-
use Cerpus\EdlibResourceKit\Resource\ResourceManagerInterface;
205-
206-
class ArticleObserver
207-
{
208-
public function __construct(private ResourceManagerInterface $manager)
209-
{
210-
}
211-
212-
public function onCreate(Article $article): void
213-
{
214-
$this->save($article->toEdlibResource());
215-
}
216-
217-
public function onUpdate(Article $article): void
218-
{
219-
$this->save($article->toEdlibResource());
220-
}
221-
222-
private function save(EdlibResource $resource): void
223-
{
224-
try {
225-
return $this->manager->save($resource);
226-
} catch (ResourceSaveFailedException $e) {
227-
// handle the failure somehow
228-
}
229-
}
230-
}
231-
~~~
232-
233-
If everything went well, the resource should now be accessible from within
234-
Edlib.
235-
236-
## Advanced usage
237-
238-
### Overriding the HTTP client & message factories
239-
240-
This library will look for and make use of any PSR-17 compatible message
241-
factories and PSR-18 compatible HTTP clients that are installed (via
242-
[HTTPlug Discovery](https://github.com/php-http/discovery)). You can override
243-
these with factories & clients of your choosing:
244-
245-
~~~php
246-
use App\Http\MyClient;
247-
use App\Http\MyRequestFactory;
248-
use App\Http\MyStreamFactory;
249-
use Cerpus\EdlibResourceKit\ResourceKit;
250-
251-
$resourceKit = new ResourceKit(
252-
httpClient: new MyClient(),
253-
requestFactory: new MyRequestFactory(),
254-
streamFactory: new MyStreamFactory(),
255-
synchronousResourceManager: true,
256-
);
257-
~~~
258-
259-
By wiring up the HTTP client provided by your web framework, you may get better
260-
logging & debugging capabilities.
261-
262-
### Adding extra data when publishing resources
263-
264-
It might be necessary to add extra data to a resource before publishing it. This
265-
can be done using a custom serializer:
266-
267-
~~~php
268-
use Cerpus\EdlibResourceKit\Contract\EdlibResource;
269-
use Cerpus\EdlibResourceKit\ResourceKit;
270-
use Cerpus\EdlibResourceKit\Serializer\ResourceSerializer;
271-
272-
class MySerializer extends ResourceSerializer
273-
{
274-
public function serialize(EdlibResource $resource): array
275-
{
276-
$data = parent::serialize($resource);
277-
278-
if ($resource instanceof MyEdlibResource) {
279-
$data['some_custom_key'] => $resource->getMyCustomData();
280-
}
281-
282-
return $data;
283-
}
284-
}
285-
286-
$resourceKit = new ResourceKit($pubSub, resourceSerializer: new MySerializer());
287-
~~~
288-
28998
## License
29099

291100
This package is released under the GNU General Public License 3.0. See the

composer.json

+2-16
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,22 @@
2626
},
2727
"require": {
2828
"php": "8.2.*|8.3.*",
29-
"cerpus/pubsub": "^1.0",
30-
"php-http/discovery": "^1.14.1",
3129
"psr/clock": "^1.0",
3230
"psr/clock-implementation": "^1.0",
33-
"psr/http-client": "^1.0",
34-
"psr/http-client-implementation": "^1.0",
35-
"psr/http-factory": "^1.0",
36-
"psr/http-factory-implementation": "^1.0",
3731
"psr/simple-cache": "^1.0|^2.0|^3.0",
3832
"psr/simple-cache-implementation": "^1.0|^2.0|^3.0"
3933
},
4034
"require-dev": {
4135
"cache/array-adapter": "^1.2",
42-
"guzzlehttp/guzzle": "^7.4",
43-
"guzzlehttp/psr7": "^2.1",
4436
"phpunit/phpunit": "^10.1",
4537
"symfony/clock": "^6.3"
4638
},
4739
"config": {
48-
"sort-packages": true,
49-
"allow-plugins": {
50-
"php-http/discovery": true
51-
},
52-
"platform": {
53-
"ext-sockets": "8.2.99"
54-
}
40+
"sort-packages": true
5541
},
5642
"extra": {
5743
"branch-alias": {
58-
"dev-master": "0.7.x-dev"
44+
"dev-master": "0.8.x-dev"
5945
}
6046
}
6147
}

src/Contract/DraftAwareResource.php

-15
This file was deleted.

src/Contract/EdlibResource.php

-74
This file was deleted.

src/Exception/HttpException.php

-12
This file was deleted.

src/Exception/MissingDataException.php

-13
This file was deleted.

src/Exception/ResourceNotFoundException.php

-11
This file was deleted.

0 commit comments

Comments
 (0)