Skip to content

Commit

Permalink
Merge pull request #156 from josbeir/feature-cake36
Browse files Browse the repository at this point in the history
Adding 3.6 compatibility + fixes
  • Loading branch information
lorenzo authored May 15, 2018
2 parents 80865f9 + 170d0c6 commit ec0ae87
Show file tree
Hide file tree
Showing 24 changed files with 660 additions and 204 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
composer.lock
phpunit.xml
vendor
.env
composer.phar

# Tool specific files #
#######################
# vim
*~
*.swp
*.swo
# sublime text & textmate
*.sublime-*
*.stTheme.cache
*.tmlanguage.cache
*.tmPreferences.cache
# Eclipse
.settings/*
# JetBrains, aka PHPStorm, IntelliJ IDEA
.idea/*
# NetBeans
nbproject/*
# Visual Studio Code
.vscode

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
58 changes: 48 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can install Elasticsearch into your project using
following to your `composer.json` file:

"require": {
"cakephp/elastic-search": "^1.0"
"cakephp/elastic-search": "^2.0-beta"
}

And run `php composer.phar update`
Expand All @@ -26,12 +26,19 @@ And run `php composer.phar update`
After installing, you should tell your application to load the plugin:

```php
// in config/bootstrap.php
Plugin::load('Cake/ElasticSearch');
use Cake\ElasticSearch\Plugin as ElasticSearchPlugin;

// If you want the plugin to automatically configure the Elastic model provider
// and FormHelper do the following:
Plugin::load('Cake/ElasticSearch', ['bootstrap' => true]);
class Application extends BaseApplication
{
public function bootstrap()
{
$this->addPlugin(ElasticSearchPlugin::class);

// If you want to disable to automatically configure the Elastic model provider
// and FormHelper do the following:
// $this->addPlugin(ElasticSearchPlugin::class, [ 'bootstrap' => false ]);
}
}
```

## Defining a connection
Expand All @@ -51,9 +58,23 @@ a connection:
],
]
```
As an alternative you could use a link format if you like to use enviroment variables for example.

```php
// in config/app.php
'Datasources' => [
// other datasources
'elastic' => [
'url' => env('ELASTIC_URL', null)
]
]

// and make sure the folowing env variable is available:
// ELASTIC_URL="Cake\ElasticSearch\Datasource\Connection://127.0.0.1:9200?driver=Cake\ElasticSearch\Datasource\Connection"
```

You can enable request logging by setting the `log` config option to true. By
default, `Elastica\Log` will be used, which logs via `error_log`. You can also
default the `debug` Log profile will be used. You can also
define an `elasticsearch` log profile in `Cake\Log\Log` to customize where
Elasticsearch query logs will go. Query logging is done at a 'debug' level.

Expand All @@ -68,13 +89,30 @@ use Cake\ElasticSearch\IndexRegistry;
$comments = IndexRegistry::get('Comments');
```

Each `Index` object need a correspondent Elasticsearch _index_, just like most of `ORM\Table` needs a database _table_.
If you have loaded the plugin with bootstrap enabled you could load indexes using the model factory in your controllers
```php
class SomeController extends AppController
{
public function initialize()
{
$this->loadModel('Comments', 'elastic');
}

public function index()
{
$comments = $this->Comments->find();
}

...
```

Each `Index` object needs a correspondent Elasticsearch _index_, just like most of `ORM\Table` needs a database _table_.

In the above example, if you have defined a class as `CommentsIndex` and the `IndexRegistry` can found it, the `$comments` will receive a initialized object with inner configurations of connection and index. But if you don't have that class, a default one will be initialized and the index name on Elasticsearch mapped to the class.
In the above example, if you have defined a class as `CommentsIndex` and the `IndexRegistry` can find it, the `$comments` will receive a initialized object with inner configurations of connection and index. But if you don't have that class, a default one will be initialized and the index name on Elasticsearch mapped to the class.

## Defining a Index class

Creating your own `Index` allow you to define name of internal _index_ of Elasticsearch, and it mapping type. As you has to [use only one mapping type for each _index_](https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html), you can use the same name for both (this is the default behavior when _type_ is undefined).
Creating your own `Index` allows you to define the name of internal _index_ for Elasticsearch, and it mapping type. As you have to [use only one mapping type for each _index_](https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html), you can use the same name for both (this is the default behavior when _type_ is undefined). Index types will be removed from ES 7 and up.

```php
use Cake\ElasticSearch\Index;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"ruflin/elastica": "^6.0"
},
"require-dev": {
"cakephp/cakephp": "^3.6",
"cakephp/cakephp-codesniffer": "^3.0",
"psr/log": "~1.0",
"phpunit/phpunit": "^6.0",
"cakephp/cakephp": "~3.4.0"
"phpunit/phpunit": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
37 changes: 0 additions & 37 deletions config/bootstrap.php

This file was deleted.

15 changes: 15 additions & 0 deletions src/Association/Embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ public function entityClass($name = null)
* @return string
*/
public function alias()
{
deprecationWarning(
'Embedded::alias() is deprecated. ' .
'Use Embedded::getAlias() instead.'
);

return $this->alias;
}

/**
* Get the alias for this embed.
*
* @return string
*/
public function getAlias()
{
return $this->alias;
}
Expand Down
Loading

0 comments on commit ec0ae87

Please sign in to comment.