Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 72 additions & 66 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,75 @@
{
"name": "meilisearch/search-bundle",
"description": "Seamless integration of Meilisearch into your Symfony project.",
"keywords": [
"meilisearch",
"instant",
"search",
"api",
"symfony",
"bundle"
],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "David Sanchez",
"email": "[email protected]"
}
],
"require": {
"php": "^7.4|^8.0",
"ext-json": "*",
"doctrine/doctrine-bundle": "^2.4",
"illuminate/collections": "^8.47",
"meilisearch/meilisearch-php": "^0.24.0",
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"doctrine/orm": "^2.9",
"friendsofphp/php-cs-fixer": "^3.0",
"nyholm/psr7": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.90",
"phpstan/phpstan-doctrine": "^0.12.39",
"phpstan/phpstan-phpunit": "^0.12.20",
"phpstan/phpstan-symfony": "^0.12.37",
"phpunit/php-code-coverage": "^9.2",
"phpunit/phpunit": "^9.5",
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
},
"autoload": {
"psr-4": {
"MeiliSearch\\Bundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MeiliSearch\\Bundle\\Test\\": "tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
"name": "meilisearch/search-bundle",
"description": "Seamless integration of Meilisearch into your Symfony project.",
"keywords": [
"meilisearch",
"instant",
"search",
"api",
"symfony",
"bundle"
],
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "David Sanchez",
"email": "[email protected]"
}
],
"repositories": {
"meilisearch/meilisearch-php": {
"type": "git",
"url": "https://github.com/meilisearch/meilisearch-php"
}
},
"require": {
"php": "^7.4|^8.0",
"ext-json": "*",
"doctrine/doctrine-bundle": "^2.4",
"illuminate/collections": "^8.47",
"meilisearch/meilisearch-php": "dev-bump-meilisearch-v0.28.0 as 1.2.3",
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"doctrine/orm": "^2.9",
"friendsofphp/php-cs-fixer": "^3.0",
"nyholm/psr7": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.90",
"phpstan/phpstan-doctrine": "^0.12.39",
"phpstan/phpstan-phpunit": "^0.12.20",
"phpstan/phpstan-symfony": "^0.12.37",
"phpunit/php-code-coverage": "^9.2",
"phpunit/phpunit": "^9.5",
"symfony/doctrine-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/http-client": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
},
"autoload": {
"psr-4": {
"MeiliSearch\\Bundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MeiliSearch\\Bundle\\Test\\": "tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
}
}
146 changes: 146 additions & 0 deletions src/CollectionXX.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Bundle;

class CollectionXX implements \ArrayAccess, \Countable

// use Illuminate\Support\Collection;

// class CollectionXX extends Collection
{
public function getItems() {
return $this->items;
}

/**
* Get the collection of items as a plain array.
*
* @return array
*/
public function toArray()
{
return $this->items;
}

/**
* The items contained in the collection.
*
* @var array
*/
protected $items = [];

/**
* Create a new collection.
*
* @param mixed $items
* @return void
*/
public function __construct($items = [])
{
$this->items = $items;
}

/**
* Get an item from the collection by key.
*
* @param mixed $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
if ($this->offsetExists($key)) {
return $this->items[$key];
}

return $default;
}

/**
* Transform each item in the collection using a callback.
*
* @param callable $callback
* @return $this
*/
public function transform(callable $callback)
{
$this->items = $this->map($callback)->all();

return $this;
}

/**
* Run a map over each of the items.
*
* @param callable $callback
* @return static
*/
public function map(callable $callback)
{
$keys = array_keys($this->items);

$items = array_map($callback, $this->items, $keys);

return new static(array_combine($keys, $items));
}

/**
* Count the number of items in the collection.
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->items);
}

/**
* Get all of the items in the collection.
*
* @return array
*/
public function all()
{
return $this->items;
}

/**
* {@inheritDoc}
*/
public function offsetSet($offset, $value): void
{
$this->items[$offset] = $value;
}

/**
* {@inheritDoc}
*/
public function offsetExists($offset): bool
{
return isset($this->items[$offset]) || \array_key_exists($offset, $this->items);
}

/**
* {@inheritDoc}
*/
public function offsetUnset($offset): void
{
unset($this->items[$offset]);
}

/**
* {@inheritDoc}
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if (isset($this->items[$offset])) {
return $this->items[$offset];
}

return null;
}
}
21 changes: 12 additions & 9 deletions src/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MeiliSearch\Bundle\Command;

use Illuminate\Support\Collection;
use MeiliSearch\Bundle\CollectionXX;
use MeiliSearch\Bundle\SearchService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -26,24 +26,23 @@ public function __construct(SearchService $searchService)
parent::__construct();
}

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

return $item;
});
}

protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $output): Collection
protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $output): CollectionXX
{
$indices = $this->getIndices();
$indexNames = collect();
$indexNames = new CollectionXX();

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

return collect();
return new CollectionXX();
}

if (count($indexNames) > 0) {
return $indices->reject(fn (array $item) => !in_array($item['name'], $indexNames->toArray(), true));
foreach ($indices->getItems() as $key => $value) {
if (!in_array($value['name'], $indexNames->toArray(), true)) {
unset($indices[$key]);
}
}
}

return $indices;
Expand Down
5 changes: 4 additions & 1 deletion src/Command/MeiliSearchCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MeiliSearch\Bundle\Command;

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

$indexes = collect(array_merge(
$indexes = new CollectionXX(array_merge(
$indexes->toArray(),
array_map(
static fn ($entity) => ['name' => $index['name'], 'class' => $entity],
Expand Down Expand Up @@ -85,6 +86,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$task = $indexInstance->{$method}($value);

$indexInstance->waitForTask($task['taskUid']);
$task = $indexInstance->getTask($task['taskUid']);

if ('failed' === $task['status']) {
Expand Down
Loading