Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit. #1

Merged
merged 14 commits into from
Nov 10, 2023
Merged
7 changes: 7 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Contributing to Yii2
====================

- [Report an issue](https://github.com/yiisoft/yii2/blob/master/docs/internals/report-an-issue.md)
- [Translate documentation or messages](https://github.com/yiisoft/yii2/blob/master/docs/internals/translation-workflow.md)
- [Give us feedback or start a design discussion](https://forum.yiiframework.com/c/yii-2-0/general-discussions/16)
- [Contribute to the core code or fix bugs](https://github.com/yiisoft/yii2/blob/master/docs/internals/git-workflow.md)
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

open_collective: yiisoft
tidelift: "packagist/yiisoft/yii2-elasticsearch"
12 changes: 8 additions & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<!--
Please use this issue tracker for bugs and feature requests only. In case you need support please use one of
Yii communities listed at https://github.com/yiisoft/yii2/wiki/communities
-->

### What steps will reproduce the problem?

### What is the expected result?
### What's expected?

### What do you get instead?


### Additional info

| Q | A
| ---------------- | ---
| Version | 1.0.?
| PHP version |
| Yii version |
| PHP version |
| Operating system |
6 changes: 6 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Security Policy

Please use the [security issue form](https://www.yiiframework.com/security) to report to us any security issue you find in Yii.
DO NOT use the issue tracker or discuss it in the public forum as it will cause more damage than help.

Please note that as a non-commercial OpenSource project we are not able to pay bounties at the moment.
72 changes: 65 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,68 @@ on:
name: build

jobs:
phpunit:
uses: yiisoft/actions/.github/workflows/phpunit.yml@master
with:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.1', '8.2', '8.3']
tests:
name: PHP ${{ matrix.php }} / ES ${{ matrix.es }}

env:
extensions: curl, mbstring, dom, intl

runs-on: ubuntu-latest

strategy:
matrix:
php:
- 8.1
- 8.2
- 8.3

es:
- 8.1.3
- 7.14.0
- 7.7.0
- 6.8.9
- 5.6.16

steps:
- name: Service elastisearch 8.1.3.
if: matrix.es == '8.1.3'
run: |
docker network create somenetwork
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" -e "indices.id_field_data.enabled=true" -e "xpack.security.enabled=false" elasticsearch:${{ matrix.es }}

- name: Service elastisearch < 8.1.3.
if: matrix.es != '8.1.3'
run: |
docker network create somenetwork
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" elasticsearch:${{ matrix.es }}

- name: Checkout.
uses: actions/checkout@v3

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'

- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Wait for Elasticsearch server to start.
run: wget --retry-connrefused --waitretry=3 --timeout=30 -t 10 -O /dev/null http://127.0.0.1:9200

- name: Run tests with phpunit.
if: matrix.php != '8.1'
run: ES_VERSION=${{ matrix.es }} vendor/bin/phpunit --colors=always

- name: Run tests with phpunit and generate coverage.
if: matrix.php == '8.1'
run: ES_VERSION=${{ matrix.es }} vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov.
if: matrix.php == '8.1'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
71 changes: 53 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center">
<a href="https://github.com/yii2-extensions/template" target="_blank">
<a href="https://github.com/yii2-extensions/elasticsearch" target="_blank">
<img src="https://www.yiiframework.com/image/yii_logo_light.svg" height="100px;">
</a>
<h1 align="center">Yii2-Template.</h1>
<h1 align="center">Elasticsearch Query and ActiveRecord.</h1>
<br>
</p>

Expand All @@ -13,32 +13,67 @@
<a href="https://github.com/yiisoft/yii2/tree/2.2" target="_blank">
<img src="https://img.shields.io/badge/Yii2%20version-2.2-blue" alt="yii2-version">
</a>
<a href="https://github.com/yii2-extensions/template/actions/workflows/build.yml" target="_blank">
<img src="https://github.com/yii2-extensions/template/actions/workflows/build.yml/badge.svg" alt="PHPUnit">
<a href="https://github.com/yii2-extensions/elasticsearch/actions/workflows/build.yml" target="_blank">
<img src="https://github.com/yii2-extensions/elasticsearch/actions/workflows/build.yml/badge.svg" alt="PHPUnit">
</a>
<a href="https://codecov.io/gh/yii2-extensions/template" target="_blank">
<img src="https://codecov.io/gh/yii2-extensions/template/branch/main/graph/badge.svg?token=MF0XUGVLYC" alt="Codecov">
<a href="https://codecov.io/gh/yii2-extensions/elasticsearch" target="_blank">
<img src="https://codecov.io/gh/yii2-extensions/elasticsearch/branch/main/graph/badge.svg?token=MF0XUGVLYC" alt="Codecov">
</a>
<a href="https://github.com/yii2-extensions/template/actions/workflows/static.yml" target="_blank">
<img src="https://github.com/yii2-extensions/gii/actions/workflows/static.yml/badge.svg" alt="PHPStan">
<a href="https://github.com/yii2-extensions/elasticsearch/actions/workflows/static.yml" target="_blank">
<img src="https://github.com/yii2-extensions/elasticsearch/actions/workflows/static.yml/badge.svg" alt="PHPStan">
</a>
<a href="https://github.com/yii2-extensions/template/actions/workflows/static.yml" target="_blank">
<img src="https://img.shields.io/badge/PHPStan%20level-2-blue" alt="PHPStan level">
<a href="https://github.com/yii2-extensions/elasticsearch/actions/workflows/static.yml" target="_blank">
<img src="https://img.shields.io/badge/PHPStan%20level-1-blue" alt="PHPStan level">
</a>
<a href="https://github.styleci.io/repos/710193992?branch=main" target="_blank">
<img src="https://github.styleci.io/repos/710193992/shield?branch=main" alt="Code style">
</a>
<a href="https://github.styleci.io/repos/698621511?branch=main" target="_blank">
<img src="https://github.styleci.io/repos/698621511/shield?branch=main" alt="Code style">
</a>
</p>

## Requirements
This extension provides the [Elasticsearch](https://www.elastic.co/products/elasticsearch) integration for the [Yii framework 2.0](https://www.yiiframework.com).
It includes basic querying/search support and also implements the `ActiveRecord` pattern that allows you to store active
records in Elasticsearch.

Requirements
------------

- PHP 8.1 or higher.

Depending on the version of Elasticsearch you are using you need a different version of this extension.

- For Elasticsearch 1.6.0 to 1.7.6 use extension version 2.0.x
- For Elasticsearch 5.x or above use extension version 2.1.x

Installation
------------

The preferred way to install this extension is through [composer](https://getcomposer.org/download/):


The minimun version of `PHP` required by this package is `PHP 8.1`.
```
composer require --prefer-dist yiisoft/yii2-elasticsearch:"~2.1.0"
```

For install this package, you need [composer](https://getcomposer.org/).
Configuration
-------------

## Usage
To use this extension, you have to configure the Connection class in your application configuration:

[Check the documentation docs](/docs/README.md) to learn about usage.
```php
return [
//....
'components' => [
'elasticsearch' => [
'class' => 'yii\elasticsearch\Connection',
'nodes' => [
['http_address' => '127.0.0.1:9200'],
// configure more hosts if you have a cluster
],
'dslVersion' => 7, // default is 5
],
]
];
```

## Testing

Expand Down
7 changes: 7 additions & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"symbol-whitelist": [
"YII_BEGIN_TIME",
"YII_DEBUG",
"YII_ENV"
]
}
23 changes: 15 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
{
"name": "yii2/template",
"type": "library",
"description": "_____",
"name": "yii2-extensions/elasticsearch",
"description": "Elasticsearch integration and ActiveRecord for the Yii framework.",
"keywords": [
"_____"
"yii2",
"elasticsearch",
"active-record",
"search",
"fulltext"
],
"type": "yii2-extension",
"license": "mit",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"yii2-extensions/debug": "dev-main",
"yiisoft/yii2": "^2.2"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.6",
"phpunit/phpunit": "^10.2",
"phpunit/phpunit": "^10.4",
"yii2-extensions/phpstan": "dev-main"
},
"autoload": {
"psr-4": {
"yii\\template\\": "src"
"yii\\elasticsearch\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"yii\\template\\tests\\": "tests"
"yiiunit\\extensions\\elasticsearch\\": "tests"
}
},
"extra": {
Expand Down
5 changes: 5 additions & 0 deletions constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

defined('YII_BEGIN_TIME') || define('YII_BEGIN_TIME', microtime(true));
6 changes: 5 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
includes:
- vendor/yii2-extensions/phpstan/extension.neon

parameters:
bootstrapFiles:
- constants.php

dynamicConstantNames:
- YII_DEBUG
- YII_ENV
- YII_ENV_DEV
- YII_ENV_PROD
- YII_ENV_TEST

level: 2
level: 1

paths:
- src
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
Expand All @@ -11,7 +11,7 @@
stopOnFailure="false"
>
<testsuites>
<testsuite name="Template">
<testsuite name="Yii2-Elasticsearch">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand Down
Loading