Skip to content

Commit 5141e84

Browse files
committed
[BC] Removed DocumentMetadata::getType()
Wait until ES server is up before running travis tests Updated typehints and docs
1 parent bd341b5 commit 5141e84

13 files changed

+50
-53
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ before_script:
2323
- export XDEBUG_MODE=coverage
2424

2525
script:
26+
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
2627
- vendor/bin/simple-phpunit --coverage-clover=Tests/App/build/clover.xml 2>/dev/null
2728
- vendor/bin/phpcs -np --standard=PSR2 --ignore=vendor/,Tests/App/,var/ ./
2829

Document/Provider/AbstractDoctrineProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ abstract class AbstractDoctrineProvider extends AbstractProvider
3838
protected $sourceDataHydration = AbstractQuery::HYDRATE_OBJECT;
3939

4040
/**
41-
* @param string $documentClass The type the provider is for
41+
* @param string $documentClass The document class the provider is for
4242
* @param EntityManagerInterface $em The Doctrine entity manager
4343
*/
44-
public function __construct($documentClass, EntityManagerInterface $em)
44+
public function __construct(string $documentClass, EntityManagerInterface $em)
4545
{
4646
parent::__construct($documentClass);
4747
$this->em = $em;
@@ -50,7 +50,7 @@ public function __construct($documentClass, EntityManagerInterface $em)
5050
/**
5151
* @param int $batchSize
5252
*/
53-
public function setBatchSize($batchSize)
53+
public function setBatchSize(int $batchSize)
5454
{
5555
$this->batchSize = $batchSize;
5656
}
@@ -60,7 +60,7 @@ public function setBatchSize($batchSize)
6060
*
6161
* @return Query
6262
*/
63-
abstract public function getQuery();
63+
abstract public function getQuery(): Query;
6464

6565
/**
6666
* Converts a Doctrine entity to Elasticsearch entity

Document/Provider/AbstractProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
abstract class AbstractProvider implements ProviderInterface
1111
{
1212
/**
13-
* @var string The type the provider is for
13+
* @var string The document class the provider is for
1414
*/
1515
private $documentClass;
1616

1717
/**
18-
* @param string $documentClass The type the provider is for
18+
* @param string $documentClass The document class the provider is for
1919
*/
20-
public function __construct($documentClass)
20+
public function __construct(string $documentClass)
2121
{
2222
$this->documentClass = $documentClass;
2323
}

Document/Provider/ElasticsearchProvider.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ElasticsearchProvider extends AbstractProvider
2323
protected $sourceIndexManager;
2424

2525
/**
26-
* @var string The type the data is coming from
26+
* @var string The document class the data is coming from
2727
*/
2828
protected $sourceDocumentClass;
2929

@@ -38,13 +38,17 @@ class ElasticsearchProvider extends AbstractProvider
3838
protected $chunkSize = 500;
3939

4040
/**
41-
* @param string $documentClass The type the provider is for
41+
* @param string $documentClass The document class the provider is for
4242
* @param DocumentMetadataCollector $metadataCollector The metadata collector
4343
* @param IndexManager $sourceIndexManager The index manager of the data source
44-
* @param string $sourceDocumentClass The type the data is coming from
44+
* @param string $sourceDocumentClass The document class the data is coming from
4545
*/
46-
public function __construct($documentClass, DocumentMetadataCollector $metadataCollector, IndexManager $sourceIndexManager, $sourceDocumentClass)
47-
{
46+
public function __construct(
47+
string $documentClass,
48+
DocumentMetadataCollector $metadataCollector,
49+
IndexManager $sourceIndexManager,
50+
string $sourceDocumentClass
51+
) {
4852
parent::__construct($documentClass);
4953
$this->sourceIndexManager = $sourceIndexManager;
5054
$this->metadataCollector = $metadataCollector;
@@ -87,7 +91,7 @@ public function getDocuments()
8791
*
8892
* @return array
8993
*/
90-
public function getDocument($id)
94+
public function getDocument($id): array
9195
{
9296
$params = [
9397
'index' => $this->sourceIndexManager->getLiveIndex(),

Document/Provider/ProviderRegistry.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
99

1010
/**
11-
* References persistence providers for each index and type.
11+
* References persistence providers for each index.
1212
*/
1313
class ProviderRegistry implements ContainerAwareInterface
1414
{
@@ -53,9 +53,9 @@ public function __construct(
5353

5454

5555
/**
56-
* Registers a provider service for the specified type entity.
56+
* Registers a provider service for the specified document class.
5757
*
58-
* @param string $documentClass The FQN or alias to the type entity
58+
* @param string $documentClass The FQN or alias to the document class
5959
* @param string $providerId The provider service id
6060
*/
6161
public function addProvider(string $documentClass, string $providerId) : void
@@ -64,19 +64,19 @@ public function addProvider(string $documentClass, string $providerId) : void
6464
}
6565

6666
/**
67-
* Unsets registered provider for the specified type entity.
67+
* Unsets registered provider for the specified document class.
6868
*
69-
* @param string $documentClass The FQN or alias to the type entity
69+
* @param string $documentClass The FQN or alias to the document class
7070
*/
7171
public function removeProvider(string $documentClass) : void
7272
{
7373
unset($this->providers[$this->documentMetadataCollector->getDocumentMetadata($documentClass)->getClassName()]);
7474
}
7575

7676
/**
77-
* Gets registered provider service id for the specified type entity.
77+
* Gets registered provider service id for the specified document class.
7878
*
79-
* @param string $documentClass The FQN or alias to the type entity
79+
* @param string $documentClass The FQN or alias to the document class
8080
*
8181
* @return string|null
8282
*/
@@ -88,13 +88,13 @@ public function getProviderId(string $documentClass) : ?string
8888
}
8989

9090
/**
91-
* Gets the provider for a type.
91+
* Gets the provider for a document class.
9292
*
9393
* @param string $documentClass FQN or alias (e.g App:Entity)
9494
*
9595
* @return ProviderInterface
9696
*
97-
* @throws \InvalidArgumentException if no provider was registered for the type
97+
* @throws \InvalidArgumentException if no provider was registered for the document class
9898
*/
9999
public function getProviderInstance(string $documentClass) : ProviderInterface
100100
{

Document/Repository/Repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Repository
3131
protected $finder;
3232

3333
/**
34-
* The type metadata
34+
* The document metadata
3535
*
3636
* @var DocumentMetadata
3737
*/

Mapping/DocumentMetadata.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ protected function configureOptions(OptionsResolver $optionsResolver)
4141
}
4242

4343
/**
44-
* Retrieves type mapping for the Elasticsearch client
44+
* Retrieves index mapping for the Elasticsearch client
4545
*
4646
* @return array
4747
*/
48-
public function getClientMapping()
48+
public function getClientMapping(): array
4949
{
5050
$mapping = array_filter(
5151
array_merge(
@@ -64,48 +64,40 @@ function ($value) {
6464
/**
6565
* @return array
6666
*/
67-
public function getProperties()
67+
public function getProperties(): array
6868
{
6969
return $this->metadata['properties'];
7070
}
7171

7272
/**
7373
* @return array
7474
*/
75-
public function getPropertiesMetadata()
75+
public function getPropertiesMetadata(): array
7676
{
7777
return $this->metadata['propertiesMetadata'];
7878
}
7979

8080
/**
8181
* @return array
8282
*/
83-
public function getFields()
83+
public function getFields(): array
8484
{
8585
return $this->metadata['fields'];
8686
}
8787

8888
/**
8989
* @return string|null
9090
*/
91-
public function getRepositoryClass()
91+
public function getRepositoryClass(): ?string
9292
{
9393
return $this->metadata['repositoryClass'];
9494
}
9595

9696
/**
9797
* @return string
9898
*/
99-
public function getClassName()
99+
public function getClassName(): string
100100
{
101101
return $this->metadata['className'];
102102
}
103-
104-
/**
105-
* @return string
106-
*/
107-
public function getType()
108-
{
109-
return $this->metadata['type'];
110-
}
111103
}

Resources/doc/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Creates a new index in Elasticsearch for the specified manager with the configur
1212

1313
Command name: `sineflow:es:index:build <index_manager_name>`
1414

15-
Rebuilds the data in the specified index, using the configured data providers for each type in the index. If no data providers are configured, by default a *self* provider is registered for each type, so the index would be rebuilt from itself - useful when mapping has changed and you need to update it.
15+
Rebuilds the data in the specified index, using the configured data provider. If no data provider is configured, by default a *self* provider is registered, so the index would be rebuilt from itself - useful when mapping has changed, and you need to update it.
1616

1717
An important thing to note is that currently this command will only work if you have set `use_aliases: true` in your index configuration. What it does is, it creates a new index and points the *write* alias to it, as well as to the old one.
1818
When building the new index is complete without errors, both read and write aliases are pointed to it and removed from the old one.

Resources/doc/dataproviders.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Simply put, data providers are the sources of data for your Elasticsearch indice
44

55
By default, each index is assigned a default *self* data provider (`ElasticsearchProvider`), which retrieves the data from the Elasticsearch index itself. This is useful when you want to rebuild the index (like if you changed the mapping and want to update it).
66

7-
In order to define your own custom data provider for a certain type, you have to create a service that implements `ProviderInterface` and tag it as `sfes.provider`, specifying the entity it is for in the `type` argument:
7+
In order to define your own custom data provider for an index, you have to create a service that implements `ProviderInterface` and tag it as `sfes.provider`, specifying the entity it is for in the `type` argument:
88

99
```
1010
services:

Resources/doc/mapping.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Elasticsearch bundle requires document mapping definitions to create the cor
44

55
## Document class annotations
66

7-
Elasticsearch type mappings are defined using annotations within document entity classes that implement DocumentInterface:
7+
Elasticsearch index mappings are defined using annotations within document entity classes that implement DocumentInterface:
88
```php
99
<?php
1010
namespace App\Document;
@@ -46,8 +46,6 @@ Each field within the document is specified using the `@ES\Property` annotation.
4646

4747
- `name` Specifies the name of the field (required).
4848

49-
- `type` Specifies the type of the field in Elasticsearch (required).
50-
5149
- `multilanguage` A flag that specifies whether the field will be multilanguage. For more information, see [declaring multilanguage properties](#mlproperties).
5250
```
5351
multilanguage=true

Resources/doc/search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $productsCount = $repo->count($searchBody);
3939

4040
## Searching in multiple types and indices
4141

42-
It is convenient to search in a single type as shown above, but sometime you may wish to search in multiple indices and/or types. The finder service comes in play:
42+
It is convenient to search in a single index as shown above, but sometime you may wish to search in multiple indices. The finder service comes in play:
4343

4444
```php
4545
$finder = $this->get('sfes.finder');

Resources/doc/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ sineflow_elasticsearch:
5151
5252
> This is the very basic example only, for a more detailed description of configuration options, please take a look at the [configuration](configuration.md) chapter.
5353
54-
A couple of things to note in this example: `dev_customer` is the name of the physical index in Elasticsearch and `App:Customer` represents the class where the document type mapping is defined. (more info at [the mapping chapter](mapping.md)).
54+
A couple of things to note in this example: `dev_customer` is the name of the physical index in Elasticsearch and `App:Customer` represents the class where the document mapping is defined. (more info at [the mapping chapter](mapping.md)).
5555

5656

5757
### Step 4: Define your Elasticsearch types as `Document` objects

Result/DocumentConverter.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DocumentConverter
3030
* @param DocumentMetadataCollector $metadataCollector
3131
* @param string $languageSeparator
3232
*/
33-
public function __construct(DocumentMetadataCollector $metadataCollector, $languageSeparator)
33+
public function __construct(DocumentMetadataCollector $metadataCollector, string $languageSeparator)
3434
{
3535
$this->metadataCollector = $metadataCollector;
3636
$this->languageSeparator = $languageSeparator;
@@ -45,7 +45,7 @@ public function __construct(DocumentMetadataCollector $metadataCollector, $langu
4545
*
4646
* @return DocumentInterface
4747
*/
48-
public function convertToDocument($rawData, $documentClass)
48+
public function convertToDocument(array $rawData, string $documentClass)
4949
{
5050
// Get document metadata
5151
$metadata = $this->metadataCollector->getDocumentMetadata($documentClass);
@@ -94,7 +94,7 @@ public function convertToDocument($rawData, $documentClass)
9494
*
9595
* @return ObjectInterface
9696
*/
97-
public function assignArrayToObject(array $array, ObjectInterface $object, array $propertiesMetadata)
97+
public function assignArrayToObject(array $array, ObjectInterface $object, array $propertiesMetadata): ObjectInterface
9898
{
9999
foreach ($propertiesMetadata as $esField => $propertyMetadata) {
100100
// Skip fields from the mapping that have no value set, unless they are multilanguage fields
@@ -160,8 +160,10 @@ public function assignArrayToObject(array $array, ObjectInterface $object, array
160160
* @param array $propertiesMetadata
161161
*
162162
* @return array
163+
*
164+
* @throws \ReflectionException
163165
*/
164-
public function convertToArray(ObjectInterface $object, $propertiesMetadata = [])
166+
public function convertToArray(ObjectInterface $object, $propertiesMetadata = []): array
165167
{
166168
if (empty($propertiesMetadata)) {
167169
$propertiesMetadata = $this->metadataCollector->getObjectPropertiesMetadata(get_class($object));
@@ -209,18 +211,18 @@ public function convertToArray(ObjectInterface $object, $propertiesMetadata = []
209211
}
210212

211213
/**
212-
* Check if object is the correct type
214+
* Check if object is the correct class
213215
*
214216
* @param ObjectInterface $object
215-
* @param array $expectedClass
217+
* @param string $expectedClass
216218
*
217219
* @throws \InvalidArgumentException
218220
*/
219-
private function checkObjectType(ObjectInterface $object, $expectedClass)
221+
private function checkObjectType(ObjectInterface $object, string $expectedClass)
220222
{
221223
if (get_class($object) !== $expectedClass) {
222224
throw new \InvalidArgumentException(
223-
sprintf('Expected object of type "%s", got "%s"', $expectedClass, get_class($object))
225+
sprintf('Expected object of "%s", got "%s"', $expectedClass, get_class($object))
224226
);
225227
}
226228
}

0 commit comments

Comments
 (0)