ruflin/Elastica — pull request #306 by simplechris (2013-01-17 18:51:51+00:00)
Title: Improve Util::getParamName()

**TL;DR: Only guess param names from classes in the Elastica namespace.**

When using a class that extends Elastica, guess the param name based on the parent Elastica class, not the child class.

e.g. Here I extend `Elastica\Query\BoolQuery`:

```php
namespace MyNamespace\Search\Query;

use Elastica\Query;

class ProductNameQuery extends Query\BoolQuery
{
public function __construct($productName)
{
$titleQuery = new Query\TextQuery();
$titleQuery->setFieldQuery('name.normalized', $productName);
$titleQuery->setFieldParam('name.normalized', 'analyzer', 'product_name');
$this->addShould($titleQuery);

$anotherTitleQuery = new Query\TextQuery();
$anotherTitleQuery->setFieldQuery('name', $productName);
$anotherTitleQuery->setFieldParam('name', 'analyzer', 'snowball');
$this->addShould($anotherTitleQuery);

}
}
```

Currently, when passing an instance of `ProductNameQuery` to `Elastica\Query` and performing the search, It will fail. This is because when serialized, the param name is guessed as `product_name` and not `bool`.

This change simply checks if the class is in the Elastica Namespace, and if not uses reflection to get to the parent class before guessing the param name.

Perhaps an unusual use-case, but helpful for me :+1: