Skip to content

Commit 9e13ca4

Browse files
committed
temp
1 parent 220b48e commit 9e13ca4

11 files changed

+262
-95
lines changed

composer.json

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,75 @@
11
{
2-
"name": "meilisearch/search-bundle",
3-
"description": "Seamless integration of Meilisearch into your Symfony project.",
4-
"keywords": [
5-
"meilisearch",
6-
"instant",
7-
"search",
8-
"api",
9-
"symfony",
10-
"bundle"
11-
],
12-
"type": "symfony-bundle",
13-
"license": "MIT",
14-
"authors": [
15-
{
16-
"name": "David Sanchez",
17-
"email": "[email protected]"
18-
}
19-
],
20-
"require": {
21-
"php": "^7.4|^8.0",
22-
"ext-json": "*",
23-
"doctrine/doctrine-bundle": "^2.4",
24-
"illuminate/collections": "^8.47",
25-
"meilisearch/meilisearch-php": "^0.24.0",
26-
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
27-
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
28-
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
29-
},
30-
"require-dev": {
31-
"doctrine/orm": "^2.9",
32-
"friendsofphp/php-cs-fixer": "^3.0",
33-
"nyholm/psr7": "^1.3",
34-
"phpstan/extension-installer": "^1.1",
35-
"phpstan/phpstan": "^0.12.90",
36-
"phpstan/phpstan-doctrine": "^0.12.39",
37-
"phpstan/phpstan-phpunit": "^0.12.20",
38-
"phpstan/phpstan-symfony": "^0.12.37",
39-
"phpunit/php-code-coverage": "^9.2",
40-
"phpunit/phpunit": "^9.5",
41-
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
42-
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
43-
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
44-
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
45-
},
46-
"autoload": {
47-
"psr-4": {
48-
"MeiliSearch\\Bundle\\": "src/"
49-
}
50-
},
51-
"autoload-dev": {
52-
"psr-4": {
53-
"MeiliSearch\\Bundle\\Test\\": "tests/"
54-
}
55-
},
56-
"config": {
57-
"sort-packages": true,
58-
"allow-plugins": {
59-
"phpstan/extension-installer": true
60-
}
61-
},
62-
"scripts": {
63-
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
64-
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
65-
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
66-
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
67-
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
2+
"name": "meilisearch/search-bundle",
3+
"description": "Seamless integration of Meilisearch into your Symfony project.",
4+
"keywords": [
5+
"meilisearch",
6+
"instant",
7+
"search",
8+
"api",
9+
"symfony",
10+
"bundle"
11+
],
12+
"type": "symfony-bundle",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "David Sanchez",
17+
"email": "[email protected]"
6818
}
19+
],
20+
"repositories": {
21+
"meilisearch/meilisearch-php": {
22+
"type": "git",
23+
"url": "https://github.com/meilisearch/meilisearch-php"
24+
}
25+
},
26+
"require": {
27+
"php": "^7.4|^8.0",
28+
"ext-json": "*",
29+
"doctrine/doctrine-bundle": "^2.4",
30+
"illuminate/collections": "^8.47",
31+
"meilisearch/meilisearch-php": "dev-bump-meilisearch-v0.28.0 as 1.2.3",
32+
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
33+
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
34+
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
35+
},
36+
"require-dev": {
37+
"doctrine/orm": "^2.9",
38+
"friendsofphp/php-cs-fixer": "^3.0",
39+
"nyholm/psr7": "^1.3",
40+
"phpstan/extension-installer": "^1.1",
41+
"phpstan/phpstan": "^0.12.90",
42+
"phpstan/phpstan-doctrine": "^0.12.39",
43+
"phpstan/phpstan-phpunit": "^0.12.20",
44+
"phpstan/phpstan-symfony": "^0.12.37",
45+
"phpunit/php-code-coverage": "^9.2",
46+
"phpunit/phpunit": "^9.5",
47+
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
48+
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
49+
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
50+
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
51+
},
52+
"autoload": {
53+
"psr-4": {
54+
"MeiliSearch\\Bundle\\": "src/"
55+
}
56+
},
57+
"autoload-dev": {
58+
"psr-4": {
59+
"MeiliSearch\\Bundle\\Test\\": "tests/"
60+
}
61+
},
62+
"config": {
63+
"sort-packages": true,
64+
"allow-plugins": {
65+
"phpstan/extension-installer": true
66+
}
67+
},
68+
"scripts": {
69+
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
70+
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
71+
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
72+
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
73+
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
74+
}
6975
}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- ./:/home/package:rw,cached
1717

1818
meilisearch:
19-
image: getmeili/meilisearch:latest
19+
image: getmeili/meilisearch:v0.28.0rc1
2020
ports:
2121
- "7700"
2222
environment:

src/CollectionXX.php

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MeiliSearch\Bundle;
6+
7+
class CollectionXX implements \ArrayAccess, \Countable
8+
9+
// use Illuminate\Support\Collection;
10+
11+
// class CollectionXX extends Collection
12+
{
13+
public function getItems() {
14+
return $this->items;
15+
}
16+
17+
/**
18+
* Get the collection of items as a plain array.
19+
*
20+
* @return array
21+
*/
22+
public function toArray()
23+
{
24+
return $this->items;
25+
}
26+
27+
/**
28+
* The items contained in the collection.
29+
*
30+
* @var array
31+
*/
32+
protected $items = [];
33+
34+
/**
35+
* Create a new collection.
36+
*
37+
* @param mixed $items
38+
* @return void
39+
*/
40+
public function __construct($items = [])
41+
{
42+
$this->items = $items;
43+
}
44+
45+
/**
46+
* Get an item from the collection by key.
47+
*
48+
* @param mixed $key
49+
* @param mixed $default
50+
* @return mixed
51+
*/
52+
public function get($key, $default = null)
53+
{
54+
if ($this->offsetExists($key)) {
55+
return $this->items[$key];
56+
}
57+
58+
return $default;
59+
}
60+
61+
/**
62+
* Transform each item in the collection using a callback.
63+
*
64+
* @param callable $callback
65+
* @return $this
66+
*/
67+
public function transform(callable $callback)
68+
{
69+
$this->items = $this->map($callback)->all();
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* Run a map over each of the items.
76+
*
77+
* @param callable $callback
78+
* @return static
79+
*/
80+
public function map(callable $callback)
81+
{
82+
$keys = array_keys($this->items);
83+
84+
$items = array_map($callback, $this->items, $keys);
85+
86+
return new static(array_combine($keys, $items));
87+
}
88+
89+
/**
90+
* Count the number of items in the collection.
91+
*
92+
* @return int
93+
*/
94+
#[\ReturnTypeWillChange]
95+
public function count()
96+
{
97+
return count($this->items);
98+
}
99+
100+
/**
101+
* Get all of the items in the collection.
102+
*
103+
* @return array
104+
*/
105+
public function all()
106+
{
107+
return $this->items;
108+
}
109+
110+
/**
111+
* {@inheritDoc}
112+
*/
113+
public function offsetSet($offset, $value): void
114+
{
115+
$this->items[$offset] = $value;
116+
}
117+
118+
/**
119+
* {@inheritDoc}
120+
*/
121+
public function offsetExists($offset): bool
122+
{
123+
return isset($this->items[$offset]) || \array_key_exists($offset, $this->items);
124+
}
125+
126+
/**
127+
* {@inheritDoc}
128+
*/
129+
public function offsetUnset($offset): void
130+
{
131+
unset($this->items[$offset]);
132+
}
133+
134+
/**
135+
* {@inheritDoc}
136+
*/
137+
#[\ReturnTypeWillChange]
138+
public function offsetGet($offset)
139+
{
140+
if (isset($this->items[$offset])) {
141+
return $this->items[$offset];
142+
}
143+
144+
return null;
145+
}
146+
}

src/Command/IndexCommand.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace MeiliSearch\Bundle\Command;
66

7-
use Illuminate\Support\Collection;
7+
use MeiliSearch\Bundle\CollectionXX;
88
use MeiliSearch\Bundle\SearchService;
99
use Symfony\Component\Console\Command\Command;
1010
use Symfony\Component\Console\Input\InputInterface;
@@ -26,24 +26,23 @@ public function __construct(SearchService $searchService)
2626
parent::__construct();
2727
}
2828

29-
protected function getIndices(): Collection
29+
protected function getIndices(): CollectionXX
3030
{
31-
return collect($this->searchService->getConfiguration()->get('indices'))
32-
->transform(function (array $item) {
31+
return (new CollectionXX($this->searchService->getConfiguration()->get('indices')))->transform(function (array $item) {
3332
$item['name'] = $this->prefix.$item['name'];
3433

3534
return $item;
3635
});
3736
}
3837

39-
protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $output): Collection
38+
protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $output): CollectionXX
4039
{
4140
$indices = $this->getIndices();
42-
$indexNames = collect();
41+
$indexNames = new CollectionXX();
4342

4443
if ($indexList = $input->getOption('indices')) {
4544
$list = \explode(',', $indexList);
46-
$indexNames = collect($list)->transform(function (string $item): string {
45+
$indexNames = (new CollectionXX($list))->transform(function (string $item): string {
4746
// Check if the given index name already contains the prefix
4847
if (!str_contains($item, $this->prefix)) {
4948
return $this->prefix.$item;
@@ -58,11 +57,15 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
5857
'<comment>No indices specified. Please either specify indices using the cli option or YAML configuration.</comment>'
5958
);
6059

61-
return collect();
60+
return new CollectionXX();
6261
}
6362

6463
if (count($indexNames) > 0) {
65-
return $indices->reject(fn (array $item) => !in_array($item['name'], $indexNames->toArray(), true));
64+
foreach ($indices->getItems() as $key => $value) {
65+
if (!in_array($value['name'], $indexNames->toArray(), true)) {
66+
unset($indices[$key]);
67+
}
68+
}
6669
}
6770

6871
return $indices;

src/Command/MeiliSearchCreateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MeiliSearch\Bundle\Command;
66

7+
use MeiliSearch\Bundle\CollectionXX;
78
use MeiliSearch\Bundle\Exception\InvalidSettingName;
89
use MeiliSearch\Bundle\Exception\TaskException;
910
use MeiliSearch\Bundle\Model\Aggregator;
@@ -50,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5051
if (is_subclass_of($entityClassName, Aggregator::class)) {
5152
$indexes->forget($key);
5253

53-
$indexes = collect(array_merge(
54+
$indexes = new CollectionXX(array_merge(
5455
$indexes->toArray(),
5556
array_map(
5657
static fn ($entity) => ['name' => $index['name'], 'class' => $entity],

0 commit comments

Comments
 (0)