Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Annotation/AbstractProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace ONGR\ElasticsearchBundle\Annotation;

use ONGR\ElasticsearchBundle\Mapping\AbstractAnnotationCamelizer;
use ONGR\ElasticsearchBundle\Mapping\Caser;
use ONGR\ElasticsearchBundle\Mapping\DumperInterface;

/**
* Makes sure thats annotations are well formated.
*/
abstract class AbstractProperty extends AbstractAnnotationCamelizer implements DumperInterface
abstract class AbstractProperty implements DumperInterface
{
/**
* {@inheritdoc}
Expand All @@ -37,7 +37,7 @@ function ($value) {
return array_combine(
array_map(
function ($key) {
return $this->underscore($key);
return Caser::snake($key);
},
array_keys($array)
),
Expand Down
10 changes: 1 addition & 9 deletions Annotation/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Document
/**
* @var bool
*/
public $create;
public $create = true;

/**
* @var string
Expand All @@ -48,12 +48,4 @@ final class Document
* @var array
*/
public $all;

/**
* Constructor.
*/
public function __construct()
{
$this->create = true;
}
}
15 changes: 15 additions & 0 deletions Annotation/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,19 @@ final class Property extends AbstractProperty
* @var string
*/
public $indexName;

/**
* @var bool
*/
public $geohash;

/**
* @var bool
*/
public $geohashPrefix;

/**
* @var string
*/
public $geohashPrecision;
}
47 changes: 0 additions & 47 deletions Mapping/AbstractAnnotationCamelizer.php

This file was deleted.

47 changes: 47 additions & 0 deletions Mapping/Caser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\Mapping;

use Doctrine\Common\Inflector\Inflector;

/**
* Utility for string case transformations.
*/
class Caser
{
/**
* Transforms string to camel case.
*
* @param string $string Text to transform.
*
* @return string
*/
public static function camel($string)
{
return Inflector::camelize($string);
}

/**
* Transforms string to snake case.
*
* @param string $string Text to transform.
*
* @return string
*/
public static function snake($string)
{
$string = preg_replace('#([A-Z\d]+)([A-Z][a-z])#', '\1_\2', self::camel($string));
$string = preg_replace('#([a-z\d])([A-Z])#', '\1_\2', $string);

return strtolower(strtr($string, '-', '_'));
}
}
11 changes: 3 additions & 8 deletions Tests/Unit/Annotation/PropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ class PropertyTest extends \PHPUnit_Framework_TestCase
*/
public function testFilter()
{
$type = new Property(
[
'object_name' => 'foo/bar',
'type' => 'string',
]
);

$this->assertEquals('foo/bar', $type->objectName, 'Properties should be camelized');
$type = new Property();

$type->name = 'id';
$type->index = 'no_index';
$type->objectName = 'foo/bar';
$type->type = 'string';
$type->analyzer = null;

$this->assertEquals(
Expand Down
26 changes: 13 additions & 13 deletions Tests/app/fixture/Acme/TestBundle/Document/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class Product extends Item
* @var PriceLocationSuggesting
*
* @ES\Suggester\ContextSuggesterProperty(
* name = "suggestions",
* objectName = "AcmeTestBundle:PriceLocationSuggesting",
* payloads = true,
* context = {
* @ES\Suggester\Context\GeoLocationContext(name="location", precision = "5m", neighbors = true, default = "u33"),
* @ES\Suggester\Context\CategoryContext(name="price", default = {"red", "green"}, path = "description")
* name="suggestions",
* objectName="AcmeTestBundle:PriceLocationSuggesting",
* payloads=true,
* context={
* @ES\Suggester\Context\GeoLocationContext(name="location", precision="5m", neighbors=true, default="u33"),
* @ES\Suggester\Context\CategoryContext(name="price", default={"red", "green"}, path="description")
* }
* )
*/
Expand All @@ -55,11 +55,11 @@ class Product extends Item
* @var CompletionSuggesting
*
* @ES\Suggester\CompletionSuggesterProperty(
* name = "completion_suggesting",
* objectName = "AcmeTestBundle:CompletionSuggesting",
* index_analyzer = "simple",
* search_analyzer = "simple",
* payloads = false,
* name="completion_suggesting",
* objectName="AcmeTestBundle:CompletionSuggesting",
* indexAnalyzer="simple",
* searchAnalyzer="simple",
* payloads=false,
* )
*/
public $completionSuggesting;
Expand All @@ -74,7 +74,7 @@ class Product extends Item
/**
* @var string
*
* @ES\Property(type="geo_point", name="location", geohash="true", geohash_prefix="true", geohash_precision="1km")
* @ES\Property(type="geo_point", name="location", geohash=true, geohashPrefix=true, geohashPrecision="1km")
*/
public $location;

Expand Down Expand Up @@ -116,7 +116,7 @@ class Product extends Item
/**
* @var string
*
* @ES\Property(type="string", name="limited", index="not_analyzed", ignore_above=20)
* @ES\Property(type="string", name="limited", index="not_analyzed", ignoreAbove=20)
*/
public $limited;

Expand Down