1: <?php
2:
3: namespace vierbergenlars\Forage\ODM;
4:
5: use vierbergenlars\Forage\Client;
6: use vierbergenlars\Forage\ODM\SearchQuery;
7: use vierbergenlars\Forage\Transport\TransportInterface;
8: use vierbergenlars\Forage\SearchQuery\QueryBuilder;
9:
10: /**
11: * The document mapper
12: */
13: class DocumentMapper extends Client
14: {
15: /**
16: * Settings for parameter injection
17: * @var \vierbergenlars\Forage\ODM\HydrationSettingsInterface
18: */
19: protected $hydrationSettings;
20:
21: /**
22: * Creates a new document mapper
23: * @param \vierbergenlars\Forage\Transport\TransportInterface $transport The transport to use
24: * @param \vierbergenlars\Forage\ODM\HydrationSettingsInterface $hydrationSettings
25: */
26: public function __construct(TransportInterface $transport,
27: HydrationSettingsInterface $hydrationSettings)
28: {
29: $this->hydrationSettings = $hydrationSettings;
30: parent::__construct($transport);
31: }
32:
33: /**
34: * Creates a new query builder, with a search result that is automatically hydrated.
35: * @return \vierbergenlars\Forage\SearchQuery\QueryBuilder
36: */
37: public function createQueryBuilder() {
38: $query = new SearchQuery($this->transport, $this->hydrationSettings);
39: return new QueryBuilder($query);
40: }
41:
42: /**
43: * Gets the search index
44: * @return \vierbergenlars\Forage\ODM\SearchIndex
45: */
46: public function getIndex() {
47: return new SearchIndex($this->transport, $this->hydrationSettings);
48: }
49: }
50: