Skip to content

Commit 1b98618

Browse files
committed
Initial commit
0 parents  commit 1b98618

Some content is hidden

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

52 files changed

+3352
-0
lines changed

.github/workflows/tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: Tests
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
branches: [ master ]
10+
pull_request:
11+
branches: [ master ]
12+
13+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
14+
jobs:
15+
# This workflow contains a single job called "tests"
16+
tests:
17+
# The type of runner that the job will run on
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
php-versions: ['7.2.0', '7.3.0', '7.4.0']
23+
name: PHP ${{ matrix.php-versions }} Test
24+
25+
# Steps represent a sequence of tasks that will be executed as part of the job
26+
steps:
27+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
28+
- uses: actions/checkout@v2
29+
30+
# Validate Composer files
31+
- name: Validate composer.json and composer.lock
32+
run: composer validate
33+
34+
# Install dependencies
35+
- name: Install dependencies
36+
run: composer install --prefer-dist --no-progress --no-suggest
37+
38+
# Run MeiliSearch Docker instance
39+
- name: Docker setup
40+
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics=true
41+
42+
# Run test suite
43+
- name: Run test suite
44+
run: composer test:unit
45+
46+
# Run PHP CS Fixer
47+
- name: Run linter
48+
run: composer test:lint

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea
2+
/composer.lock
3+
/vendor/
4+
.phpunit.result.cache
5+
/var/
6+
.php_cs.cache
7+
/tests/cache/blog.sqlite

.php_cs.dist

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
if (!file_exists(__DIR__.'/src')) {
4+
exit(0);
5+
}
6+
7+
return PhpCsFixer\Config::create()
8+
->setRules(
9+
[
10+
'@Symfony' => true,
11+
'@Symfony:risky' => true,
12+
'@PHPUnit75Migration:risky' => true,
13+
'php_unit_dedicate_assert' => ['target' => 'newest'],
14+
'array_syntax' => ['syntax' => 'short'],
15+
'fopen_flags' => false,
16+
'protected_to_private' => false,
17+
'combine_nested_dirname' => true,
18+
'global_namespace_import' => [
19+
'import_classes' => true,
20+
'import_constants' => true,
21+
'import_functions' => true,
22+
],
23+
'phpdoc_no_package' => false,
24+
'no_superfluous_phpdoc_tags' => false,
25+
'ordered_imports' => ['sortAlgorithm' => 'none'],
26+
]
27+
)
28+
->setRiskyAllowed(true)
29+
->setFinder(
30+
PhpCsFixer\Finder::create()
31+
->in(__DIR__.'/src')
32+
->append([__FILE__])
33+
);

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM php:7.2.0-fpm-alpine as php
2+
3+
# persistent / runtime deps
4+
RUN apk add --no-cache \
5+
acl \
6+
fcgi \
7+
file \
8+
gettext \
9+
git \
10+
;
11+
12+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
13+
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
14+
ENV COMPOSER_ALLOW_SUPERUSER=1
15+
16+
WORKDIR /usr/src
17+
18+
# prevent the reinstallation of vendors at every changes in the source code
19+
COPY composer.json ./
20+
RUN set -eux; \
21+
composer install; \
22+
composer clear-cache
23+
24+
# copy only specifically what we need
25+
COPY src src/
26+
COPY tests tests/
27+
28+
CMD ["php-fpm"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Meili
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<p align="center">
2+
<img src="https://drive.google.com/uc?export=view&id=16hFZW-htUOv26djSxxxr8yhyLkRrM5-i" alt="MeiliSearch-Symfony" width="200" height="200" />
3+
</p>
4+
5+
<h1 align="center">MeiliSearch Symfony Bundle</h1>
6+
7+
<h4 align="center">
8+
<a href="https://github.com/meilisearch/MeiliSearch">MeiliSearch</a> |
9+
<a href="https://www.meilisearch.com">Website</a> |
10+
<a href="https://blog.meilisearch.com">Blog</a> |
11+
<a href="https://twitter.com/meilisearch">Twitter</a> |
12+
<a href="https://docs.meilisearch.com">Documentation</a> |
13+
<a href="https://docs.meilisearch.com/faq">FAQ</a>
14+
</h4>
15+
16+
<p align="center">
17+
<a href="https://packagist.org/packages/meilisearch/meilisearch-bundle"><img src="https://img.shields.io/packagist/v/meilisearch/meilisearch-bundle" alt="Latest Stable Version"></a>
18+
<a href="https://github.com/emulienfou/meilisearch-bundle/actions"><img src="https://github.com/emulienfou/meilisearch-bundle/workflows/Tests/badge.svg" alt="Test"></a>
19+
<a href="https://github.com/emulienfou/meilisearch-bundle/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
20+
<a href="https://slack.meilisearch.com"><img src="https://img.shields.io/badge/slack-MeiliSearch-blue.svg?logo=slack" alt="Slack"></a>
21+
</p>
22+
23+
24+
<p align="center">⚡ Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine MeiliSearch Symfony Bundle</p>
25+
26+
**MeiliSearchBundle** is a Bundle to integrate **MeiliSearch** within your Symfony Project.
27+
**MeiliSearch** is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box.
28+
29+
## Table of Contents <!-- omit in toc -->
30+
- [🤖 Compatibility with MeiliSearch](#-compatibility-with-meilisearch)
31+
- [✨ Features](#-features)
32+
- [📖 Documentation](#-documentation)
33+
- [⚙️ Development Workflow](#️-development-workflow)
34+
- [Run DOcker environment](#run-docker-environment)
35+
- [Release](#release)
36+
37+
## 🤖 Compatibility with MeiliSearch
38+
This package is compatible with the following MeiliSearch versions:
39+
- `v0.12.X`
40+
- `v0.11.X`
41+
42+
## ✨ Features
43+
* **Require** PHP 7.2 and later.
44+
* **Compatible** with Symfony 4.0 and later.
45+
* **Support** Doctrine ORM and Doctrine MongoDB.
46+
47+
## 📖 Documentation
48+
Complete documentation of the MeiliSearch Bundle is available in the [Uncyclo](https://github.com/emulienfou/meilisearch-bundle/wiki) section.
49+
50+
## ⚙️ Development Workflow
51+
If you want to contribute, this section describes the steps to follow.
52+
53+
Thank you for your interest in a MeiliSearch tool! ♥️
54+
55+
### Run Docker Environment
56+
To start and build your Docker environment, just execute the next command in a terminal:
57+
```sh
58+
docker-compose up -d
59+
```
60+
61+
#### Tests
62+
Each Pull Request should pass the tests, and the linter to be accepted.
63+
To execute the tests, run the next command:
64+
```sh
65+
docker-compose exec -e MEILISEARCH_URL=http://meilisearch:7700 php composer test:unit
66+
```
67+
68+
### Release
69+
70+
MeiliSearch tools follow the [Semantic Versioning Convention](https://semver.org/).
71+
72+
You must do a PR modifying the file `src/MeiliSearchBundle.php` with the right version.<br>
73+
74+
```php
75+
const VERSION = 'X.X.X';
76+
```
77+
78+
Then, you must create a release (with this name `vX.X.X`) via the GitHub interface.<br>
79+
A webhook will be triggered and push the new package on [Packagist](https://packagist.org/packages/meilisearch/meilisearch-bundle).
80+
81+
<hr>
82+
83+
**MeiliSearch** provides and maintains many **SDKs and Integration tools** like this one. We want to provide everyone with an **amazing search experience for any kind of project**. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the [integration-guides](https://github.com/meilisearch/integration-guides) repository.

composer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "meilisearch/meilisearch-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.2",
22+
"ext-json": "*",
23+
"meilisearch/meilisearch-php": "^0.11",
24+
"symfony/filesystem": "^4.0 || ^5.0",
25+
"symfony/property-access": "^4.0 || ^5.0",
26+
"symfony/serializer": "^4.0 || ^5.0"
27+
},
28+
"require-dev": {
29+
"doctrine/doctrine-bundle": "^2.0",
30+
"doctrine/orm": "^2.5",
31+
"friendsofphp/php-cs-fixer": "^2.16",
32+
"jms/serializer-bundle": "^3.0",
33+
"phpunit/phpunit": "^8.5",
34+
"symfony/doctrine-bridge": "^4.0 || ^5.0",
35+
"symfony/phpunit-bridge": "^4.0 || ^5.0",
36+
"symfony/yaml": "^4.0 || ^5.0"
37+
},
38+
"autoload": {
39+
"psr-4": {
40+
"MeiliSearch\\Bundle\\": "src/"
41+
}
42+
},
43+
"autoload-dev": {
44+
"psr-4": {
45+
"MeiliSearch\\Bundle\\Test\\": "tests/"
46+
}
47+
},
48+
"config": {
49+
"sort-packages": true
50+
},
51+
"scripts": {
52+
"test:unit": "phpunit --colors=always --verbose",
53+
"test:lint": "php-cs-fixer fix -v --config=.php_cs.dist --using-cache=no --dry-run"
54+
}
55+
}

docker-compose.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3.4'
2+
services:
3+
php:
4+
build:
5+
context: .
6+
target: php
7+
volumes:
8+
- .:/usr/src:rw,cached
9+
depends_on:
10+
- meilisearch
11+
12+
meilisearch:
13+
image: getmeili/meilisearch
14+
command: ./meilisearch --master-key=masterKey
15+
ports:
16+
- target: 7700
17+
published: 7700
18+
protocol: tcp

phpunit.xml.dist

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit colors="true" bootstrap="vendor/autoload.php" convertDeprecationsToExceptions="false">
3+
<php>
4+
<env name="KERNEL_CLASS" value="MeiliSearch\Bundle\Test\Kernel"/>
5+
<env name="APP_ENV" value="test"/>
6+
<env name="APP_DEBUG" value="false"/>
7+
<env name="MEILISEARCH_PREFIX" value="sf_phpunit_"/>
8+
<env name="MEILISEARCH_URL" value="http://127.0.0.1:7700"/>
9+
<env name="MEILISEARCH_MASTER_KEY" value="masterKey"/>
10+
<env name="TRAVIS_JOB_NUMBER" value=""/>
11+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
12+
</php>
13+
<testsuites>
14+
<testsuite name="TestCase">
15+
<directory suffix=".php">tests/TestCase/</directory>
16+
</testsuite>
17+
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory>src/</directory>
21+
<exclude>
22+
<file>src/DependencyInjection/MeiliSearchExtension.php</file>
23+
<file>src/Services/NullSearchService.php</file>
24+
</exclude>
25+
</whitelist>
26+
</filter>
27+
</phpunit>

src/Command/IndexCommand.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace MeiliSearch\Bundle\Command;
4+
5+
use MeiliSearch\Bundle\SearchService;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use function array_keys;
10+
use function count;
11+
use function explode;
12+
13+
/**
14+
* Class IndexCommand.
15+
*
16+
* @package MeiliSearch\Bundle\Command
17+
*/
18+
abstract class IndexCommand extends Command
19+
{
20+
/** @var SearchService */
21+
protected $searchService;
22+
23+
/**
24+
* IndexCommand constructor.
25+
*
26+
* @param SearchService $searchService
27+
* @param string|null $name
28+
*/
29+
public function __construct(SearchService $searchService, string $name = null)
30+
{
31+
$this->searchService = $searchService;
32+
parent::__construct($name);
33+
}
34+
35+
protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $output): array
36+
{
37+
$entities = [];
38+
$indexNames = [];
39+
40+
if ($indexList = $input->getOption('indices')) {
41+
$indexNames = explode(',', $indexList);
42+
}
43+
44+
$config = $this->searchService->getConfiguration();
45+
46+
if (0 === count($indexNames)) {
47+
$indexNames = array_keys($config['indices']);
48+
}
49+
50+
foreach ($indexNames as $name) {
51+
if (isset($config['indices'][$name])) {
52+
$entities[$name]['name'] = $config['indices'][$name]['class'];
53+
if (true === $input->hasOption('update-settings') && !empty($config['indices'][$name]['settings'])) {
54+
$entities[$name]['settings'] = $config['indices'][$name]['settings'];
55+
}
56+
} else {
57+
$output->writeln(
58+
'<comment>No index named <info>'.$name.'</info> was found. Check you configuration.</comment>'
59+
);
60+
}
61+
}
62+
63+
return $entities;
64+
}
65+
}

0 commit comments

Comments
 (0)