Skip to content

Commit b8004b2

Browse files
author
Martynas Sudintas
committed
Merge pull request #229 from martiis/issue-228
Implemented Repository#getManager method
2 parents 0e905aa + 3f47d88 commit b8004b2

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

ORM/Repository.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct($manager, $repositories)
7373
protected function getTypes()
7474
{
7575
$types = [];
76-
$meta = $this->manager->getBundlesMapping($this->namespaces);
76+
$meta = $this->getManager()->getBundlesMapping($this->namespaces);
7777

7878
foreach ($meta as $namespace => $metadata) {
7979
$types[] = $metadata->getType();
@@ -94,16 +94,16 @@ public function find($id)
9494
{
9595
if (count($this->types) == 1) {
9696
$params = [
97-
'index' => $this->manager->getConnection()->getIndexName(),
97+
'index' => $this->getManager()->getConnection()->getIndexName(),
9898
'type' => $this->types[0],
9999
'id' => $id,
100100
];
101101

102-
$result = $this->manager->getConnection()->getClient()->get($params);
102+
$result = $this->getManager()->getConnection()->getClient()->get($params);
103103

104104
$converter = new Converter(
105-
$this->manager->getTypesMapping(),
106-
$this->manager->getBundlesMapping()
105+
$this->getManager()->getTypesMapping(),
106+
$this->getManager()->getBundlesMapping()
107107
);
108108

109109
return $converter->convertToDocument($result);
@@ -192,7 +192,7 @@ public function scan(
192192
$scrollDuration = Search::SCROLL_DURATION,
193193
$resultsType = self::RESULTS_OBJECT
194194
) {
195-
$results = $this->manager->getConnection()->scroll($scrollId, $scrollDuration);
195+
$results = $this->getManager()->getConnection()->scroll($scrollId, $scrollDuration);
196196

197197
return $this->parseResult($results, $resultsType, $scrollDuration);
198198
}
@@ -215,7 +215,7 @@ public function suggest($suggesters)
215215
foreach ($suggesters as $suggester) {
216216
$body = array_merge($suggester->toArray(), $body);
217217
}
218-
$results = $this->manager->getConnection()->getClient()->suggest(['body' => $body]);
218+
$results = $this->getManager()->getConnection()->getClient()->suggest(['body' => $body]);
219219
unset($results['_shards']);
220220

221221
return new SuggestionIterator($results);
@@ -233,12 +233,12 @@ public function remove($id)
233233
{
234234
if (count($this->types) == 1) {
235235
$params = [
236-
'index' => $this->manager->getConnection()->getIndexName(),
236+
'index' => $this->getManager()->getConnection()->getIndexName(),
237237
'type' => $this->types[0],
238238
'id' => $id,
239239
];
240240

241-
$response = $this->manager->getConnection()->getClient()->delete($params);
241+
$response = $this->getManager()->getConnection()->getClient()->delete($params);
242242

243243
return $response;
244244
} else {
@@ -262,7 +262,7 @@ private function checkFields($searchArray, $fields = ['_parent', '_ttl'])
262262

263263
// Checks if cache is loaded.
264264
if (empty($this->fieldsCache)) {
265-
foreach ($this->manager->getBundlesMapping($this->namespaces) as $ns => $properties) {
265+
foreach ($this->getManager()->getBundlesMapping($this->namespaces) as $ns => $properties) {
266266
$this->fieldsCache = array_unique(
267267
array_merge(
268268
$this->fieldsCache,
@@ -306,8 +306,8 @@ private function parseResult($raw, $resultsType, $scrollDuration)
306306
if (isset($raw['_scroll_id'])) {
307307
$iterator = new DocumentScanIterator(
308308
$raw,
309-
$this->manager->getTypesMapping(),
310-
$this->manager->getBundlesMapping()
309+
$this->getManager()->getTypesMapping(),
310+
$this->getManager()->getBundlesMapping()
311311
);
312312
$iterator
313313
->setRepository($this)
@@ -319,8 +319,8 @@ private function parseResult($raw, $resultsType, $scrollDuration)
319319

320320
return new DocumentIterator(
321321
$raw,
322-
$this->manager->getTypesMapping(),
323-
$this->manager->getBundlesMapping()
322+
$this->getManager()->getTypesMapping(),
323+
$this->getManager()->getBundlesMapping()
324324
);
325325
case self::RESULTS_ARRAY:
326326
return $this->convertToNormalizedArray($raw);
@@ -381,8 +381,18 @@ public function createDocument()
381381
);
382382
}
383383

384-
$class = $this->manager->getBundlesMapping()[reset($this->namespaces)]->getProxyNamespace();
384+
$class = $this->getManager()->getBundlesMapping()[reset($this->namespaces)]->getProxyNamespace();
385385

386386
return new $class();
387387
}
388+
389+
/**
390+
* Returns elasticsearch manager used in this repository for getting/setting documents.
391+
*
392+
* @return Manager
393+
*/
394+
public function getManager()
395+
{
396+
return $this->manager;
397+
}
388398
}

Tests/Functional/ORM/RepositoryTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,16 @@ public function testGetRepositoryWithDoucmentSuffix()
554554
);
555555
}
556556

557+
/**
558+
* Tests if repository returns same manager as it was original.
559+
*/
560+
public function testGetManager()
561+
{
562+
$manager = $this->getManager();
563+
$repository = $manager->getRepository('AcmeTestBundle:Color');
564+
$this->assertEquals($manager, $repository->getManager());
565+
}
566+
557567
/**
558568
* Assert suggestion score is set.
559569
*

0 commit comments

Comments
 (0)