Skip to content

Commit 8f0e3c9

Browse files
committed
update readme
1 parent 69dc3b0 commit 8f0e3c9

File tree

1 file changed

+85
-2
lines changed

1 file changed

+85
-2
lines changed

README.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Install using composer.
1010
```json
1111
{
1212
"require": {
13-
"tarantool/mapper": "^2.2.3"
13+
"tarantool/mapper": "^2.5.0"
1414
}
1515
}
1616
```
@@ -274,7 +274,7 @@ echo $entity->id; // will be set when you create an instance
274274
If you want you can specify classes to use for repository and entity instances.
275275
Entity and repository class implementation are ommited, but you should just extend base classes.
276276
```php
277-
$userClasses = $mappr->addPlugin(Tarantool\Mapper\Plugins\UserClasses::class);
277+
$userClasses = $mapper->addPlugin(Tarantool\Mapper\Plugins\UserClasses::class);
278278
$userClasses->mapEntity('person', Application\Models\Person::class);
279279
$userClasses->mapRepository('person', Application\Repositories\Person::class);
280280

@@ -287,6 +287,89 @@ get_class($nekufa); // Application\Models\Person;
287287
$mapper->getSchema()->getSpace('person')->getRepository(); // will be instance of Application\Repositories\Person
288288
```
289289

290+
# DocBlock plugin
291+
You can describe your entities using dobclock. Mapper will create space, format and indexes for you.
292+
293+
```php
294+
namespace Entities;
295+
296+
use Tarantool\Mapper\Entity;
297+
298+
class Person extends Entity
299+
{
300+
/**
301+
* @var integer
302+
*/
303+
public $id;
304+
305+
/**
306+
* @var string
307+
*/
308+
public $name;
309+
}
310+
311+
class Post extends Entity
312+
{
313+
/**
314+
* @var integer
315+
*/
316+
public $id;
317+
318+
/**
319+
* @var string
320+
*/
321+
public $slug;
322+
323+
/**
324+
* @var string
325+
*/
326+
public $title;
327+
328+
/**
329+
* @var string
330+
*/
331+
public $body;
332+
333+
/**
334+
* @var Person
335+
*/
336+
public $author;
337+
}
338+
```
339+
If you want to index fields, extend repository and define indexes property
340+
```php
341+
namespace Repositories;
342+
343+
use Tarantool\Mapper\Repository;
344+
345+
class Post extends Repository
346+
{
347+
public $indexes = [
348+
['id'],
349+
['slug']
350+
];
351+
}
352+
```
353+
Register plugin and all your classes:
354+
```php
355+
$mapper->addPlugin(Tarantool\Mapper\Plugins\Sequence::class); // just not to fill id manually
356+
$mapper->addPlugin(Tarantool\Mapper\Plugins\DocBlock::class)
357+
->register(Entities\Person::class)
358+
->register(Entities\Post::class)
359+
->register(Repositories\Person::class)
360+
->migrate(); // sync code with database schema
361+
362+
$nekufa = $mapper->create('person', ['name' => 'dmitry']);
363+
364+
$post = $mapper->create('post', [
365+
'author' => $nekufa,
366+
'slug' => 'hello-world',
367+
'title' => 'Hello world',
368+
'body' => 'Now you can use mapper better way'
369+
]);
370+
371+
```
372+
290373
# Internals
291374
Mapper uses IdentityMap and query caching
292375
```php

0 commit comments

Comments
 (0)