Skip to content

Commit ab176b0

Browse files
authored
Merge pull request #8 from Spameri/version-one
Version one
2 parents 039c4f0 + f8e9fa0 commit ab176b0

File tree

329 files changed

+8241
-8182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+8241
-8182
lines changed

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Package CI
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
checks:
8+
name: Checks
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
php: [ 7.4, 8.0, 8.1 ]
13+
version: [ lowest, standard ]
14+
elastic: [ 7.12.1 ]
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
22+
- name: Configure sysctl limits
23+
run: |
24+
sudo swapoff -a
25+
sudo sysctl -w vm.swappiness=1
26+
sudo sysctl -w fs.file-max=262144
27+
sudo sysctl -w vm.max_map_count=262144
28+
29+
- name: Start Elasticsearch
30+
uses: elastic/elastic-github-actions/elasticsearch@master
31+
with:
32+
stack-version: ${{ matrix.elastic }}
33+
34+
- if: matrix.version == 'lowest'
35+
name: Composer lowest
36+
run: make composer-lowest
37+
38+
- if: matrix.version == 'standard'
39+
name: Composer standard
40+
run: make composer
41+
42+
- if: matrix.php == '7.4'
43+
name: Coding standard
44+
run: make cs
45+
46+
- if: matrix.php == '7.4' && matrix.version == 'lowest'
47+
name: PHPStan lowest
48+
run: make phpstan-lowest
49+
50+
- if: matrix.php == '7.4' && matrix.version == 'standard'
51+
name: PHPStan standard
52+
run: make phpstan
53+
54+
- name: Tests
55+
run: make tests
56+

.travis.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

composer.json

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@
2424
}
2525
],
2626
"require": {
27-
"php": ">=7.1",
27+
"php": ">=7.4",
2828
"ext-json": "*",
29-
"nette/di": "^2.4.10",
30-
"nette/security": "^2.3.0",
31-
"nette/utils": "^2.4.10",
32-
"spameri/elastic-query": "^0.6.0",
33-
"elasticsearch/elasticsearch": "^6.0",
34-
"kdyby/console": "^2.7.1",
35-
"kdyby/datetime-provider": "v1.0.0",
36-
"kdyby/monolog": "^1.3.2",
37-
"tracy/tracy": "^2.4.18"
29+
"ext-curl": "*",
30+
"spameri/elastic-query": "^v1.0.0",
31+
"elasticsearch/elasticsearch": "^7.12.0",
32+
"nette/di": "^3.0.5",
33+
"nette/utils": "^3.2.5",
34+
"symfony/console": "^4.4.26",
35+
"tracy/tracy": "^2.6.7",
36+
"monolog/monolog": "^2.0.2",
37+
"ezimuel/ringphp": "^1.2"
3838
},
3939
"require-dev": {
4040
"spameri/coding-standard": "dev-master",
4141
"spameri/dependency-mocker": "^1.3",
42-
"nette/tester": "^2.2.0",
43-
"phpstan/phpstan-shim": "^0.11.5",
42+
"nette/tester": "^2.4",
43+
"phpstan/phpstan": "0.12.84",
4444
"php-coveralls/php-coveralls": "^2.1",
45-
"nette/bootstrap": "2.4",
46-
"nette/http": "^2.4.7",
47-
"mockery/mockery": "^1.2"
45+
"nette/bootstrap": "^3.0",
46+
"nette/http": "^3.0.7",
47+
"kdyby/console": "^4.0.0",
48+
"mockery/mockery": "^1.5"
4849
},
4950
"autoload": {
5051
"psr-4": {
@@ -54,9 +55,11 @@
5455
"autoload-dev": {
5556
"psr-4": {
5657
"SpameriTests\\": "tests/SpameriTests"
57-
},
58-
"classmap": [
59-
"tests/SpameriTests/Elastic/Migration/migrations"
60-
]
58+
}
59+
},
60+
"config": {
61+
"allow-plugins": {
62+
"dealerdirect/phpcodesniffer-composer-installer": true
63+
}
6164
}
6265
}

doc/00_quick_start.md

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ In your configuration neon file you need to add these lines to `extension:` sect
2020
```yaml
2121
extensions:
2222
spameriElasticSearch: \Spameri\Elastic\DI\SpameriElasticSearchExtension
23-
console: Kdyby\Console\DI\ConsoleExtension
24-
monolog: Kdyby\Monolog\DI\MonologExtension
2523
```
2624

25+
Optionaly you need some Symfony Console implementation ie:
26+
27+
`````yaml
28+
extensions:
29+
console: Kdyby\Console\DI\ConsoleExtension
30+
`````
31+
2732
### II. Configure
2833

2934
Now you need to tell library where is ElasticSearch running. Default values are **localhost**
@@ -38,37 +43,29 @@ spameriElasticSearch:
3843

3944
### III. Configure Entity
4045

41-
Next step is to configure your first entity. This entity is for e-shop product.
46+
Next step is to configure your first entity. In this example, entity is for e-shop product.
47+
48+
In neon configuration you need just index name. In this example it is just under parameters.elasticsSearch key, but can be anywhere.
4249

4350
```yaml
44-
1.| spameriElasticSearch:
45-
2.| entities:
46-
3.| SimpleProduct:
47-
4.| index: spameri_simple_product
48-
5.| dynamic: strict
49-
6.| config: @simpleProductConfig
50-
7.| properties:
51+
parameters:
52+
elasticSearch:
53+
SimpleProductIndex: spameri_simple_product
5154
```
52-
- First line is extensionName
53-
- Second line is entities config array
54-
- Third line is EntityName
55-
- Fourth line is index name for this entity
56-
- Fifth line is for specifying whether index should accept new not specified fields
57-
- Sixth line is reference to where is object with entity configuration
58-
- Seventh line is where you can configure your entity within this neon
5955

6056
---
6157

6258
## 3. Create entity class
6359

60+
Mainly you need entity class, which implements \Spameri\Elastic\Entity\ElasticEntityInterface interface.
6461
```php
6562
<?php declare(strict_types = 1);
6663

67-
class SimpleProduct implements \Spameri\Elastic\Entity\IElasticEntity
64+
class SimpleProduct implements \Spameri\Elastic\Entity\ElasticEntityInterface
6865
{
6966

7067
public function __construct(
71-
\Spameri\Elastic\Entity\Property\IElasticId $id,
68+
\Spameri\Elastic\Entity\Property\ElasticIdInterface $id,
7269
int $databaseId,
7370
string $name,
7471
?string $content,
@@ -86,8 +83,10 @@ class SimpleProduct implements \Spameri\Elastic\Entity\IElasticEntity
8683
}
8784
```
8885

86+
And then implement two methods. Method id is quite clear :) and entityVariables method returns all the properties you want inserted to Elastic.
87+
8988
```php
90-
public function id(): \Spameri\Elastic\Entity\Property\IElasticId
89+
public function id(): \Spameri\Elastic\Entity\Property\ElasticIdInterface
9190
{
9291
return $this->id;
9392
}
@@ -99,9 +98,11 @@ public function entityVariables(): array
9998
}
10099
```
101100

101+
To build entity from Elasticsearch and not use black magic🪄 you have to explicitly make factory class for that entity. And from hit object which represents result from Elasticsearch you have to extract all parameters. No magic, typed 🎖️
102+
102103
### Factory
103104
````php
104-
class SimpleProductFactory implements \Spameri\Elastic\Factory\IEntityFactory
105+
class SimpleProductFactory implements \Spameri\Elastic\Factory\EntityFactoryInterface
105106
{
106107

107108
public function create(\Spameri\ElasticQuery\Response\Result\Hit $hit) : \Generator
@@ -123,23 +124,27 @@ class SimpleProductFactory implements \Spameri\Elastic\Factory\IEntityFactory
123124
}
124125
````
125126

127+
In collection factory you need to specify our entity.
128+
126129
### CollectionFactory
127130
````php
128-
class SimpleProductCollectionFactory implements \Spameri\Elastic\Factory\ICollectionFactory
131+
class SimpleProductCollectionFactory implements \Spameri\Elastic\Factory\CollectionFactoryInterface
129132
{
130133

131134
public function create(
132-
\Spameri\Elastic\Model\IService $service
133-
, array $elasticIds = []
134-
, \Spameri\Elastic\Entity\IElasticEntity ... $entityCollection
135-
) : \Spameri\Elastic\Entity\IElasticEntityCollection
135+
\Spameri\Elastic\Model\ServiceInterface $service,
136+
array $elasticIds = [],
137+
\Spameri\Elastic\Entity\ElasticEntityInterface ... $entityCollection
138+
) : \Spameri\Elastic\Entity\ElasticEntityCollectionInterface
136139
{
137140
return new \App\ProductModule\Entity\ProductCollection($service, $elasticIds, ... $entityCollection);
138141
}
139142

140143
}
141144
````
142145

146+
---
147+
143148
## 4. Index Configuring
144149
````php
145150
class SimpleProductConfig implements \Spameri\Elastic\Settings\IndexConfigInterface
@@ -306,7 +311,7 @@ $options = new \Spameri\Elastic\Import\Run\Options(600);
306311
// Clear index
307312
try {
308313
$this->delete->execute($this->simpleProductConfig->provide()->indexName());
309-
} catch (\Spameri\Elastic\Exception\ElasticSearchException $exception) {}
314+
} catch (\Spameri\Elastic\Exception\AbstractElasticSearchException $exception) {}
310315

311316
// Create index
312317
$this->create->execute(
@@ -330,7 +335,7 @@ class SimpleProductListPresenter extends \App\Presenter\BasePresenter
330335
try {
331336
$products = $this->productService->getAllBy($query);
332337

333-
} catch (\Spameri\Elastic\Exception\ElasticSearchException $exception) {
338+
} catch (\Spameri\Elastic\Exception\AbstractElasticSearchException $exception) {
334339
$products = [];
335340
}
336341

@@ -396,7 +401,7 @@ public function buildQuery(?string $queryString): \Spameri\ElasticQuery\ElasticQ
396401
{
397402
$query = new \Spameri\ElasticQuery\ElasticQuery();
398403
$query->addShouldQuery(
399-
new \Spameri\ElasticQuery\Query\Match(
404+
new \Spameri\ElasticQuery\Query\ElasticMatch(
400405
'name',
401406
$queryString
402407
)
@@ -418,7 +423,7 @@ $subQuery = new \Spameri\ElasticQuery\Query\QueryCollection();
418423

419424
```php
420425
$subQuery->addShouldQuery(
421-
new \Spameri\ElasticQuery\Query\Match(
426+
new \Spameri\ElasticQuery\Query\ElasticMatch(
422427
'name',
423428
$queryString,
424429
3,
@@ -441,7 +446,7 @@ $subQuery->addShouldQuery(
441446
)
442447
);
443448
$subQuery->addShouldQuery(
444-
new \Spameri\ElasticQuery\Query\Match(
449+
new \Spameri\ElasticQuery\Query\ElasticMatch(
445450
'content',
446451
$queryString,
447452
1,

doc/01_intro.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ Use composer `composer require spameri/elastic`
99
### 1. Config ElasticSearch
1010

1111
In your config neon, enable extensions. Kdyby/Console is there because we need it to do some command line commands.
12-
Monolog is required by elasticsearch/elasticsearch and we can use existing extension in Kdyby/Monolog.
1312

14-
```neon
13+
```yaml
1514
extensions:
1615
spameriElasticSearch: \Spameri\Elastic\DI\SpameriElasticSearchExtension
17-
console: Kdyby\Console\DI\ConsoleExtension
18-
monolog: Kdyby\Monolog\DI\MonologExtension
1916
```
2017

18+
Optionaly you need some Symfony Console implementation ie:
19+
20+
`````yaml
21+
extensions:
22+
console: Kdyby\Console\DI\ConsoleExtension
23+
`````
24+
2125
Then configure where is your ElasticSearch.
2226
```neon
2327
spameriElasticSearch:
@@ -37,8 +41,7 @@ $result = $this->clientProvider->client()->search(
3741
$index,
3842
new \Spameri\ElasticQuery\Document\Body\Plain(
3943
$elasticQuery->toArray()
40-
),
41-
$index
44+
)
4245
)
4346
)->toArray()
4447
);
@@ -52,8 +55,6 @@ what methods and arrays are supported.
5255

5356
### 2. First entity
5457

55-
#### [Neon file configuration](02_neon_configuration.md)
56-
5758
#### [Create entity class](03_entity_class.md)
5859

5960
#### [Create entity service](12_entity_service.md)

0 commit comments

Comments
 (0)