Refactor query context

No more private collection map, uses new features from LimitedStructure.
From now on, Context tries to return Field objects instead of strings.

New context methods:
- getUnrestrictedFields()
- getPrivateFields()
- localizeField(Field) (signature changed)
- localizeFieldName(string)

QueryContext::localizeField() now takes a Field object, use localizeFieldName() if you want to pass a string.

Field::getIndexFieldName() renamed to Field::getIndexField().
Raw index fields are now obtained with Field::getIndexField(true).
This commit is contained in:
Mathieu Darse
2015-07-10 17:33:10 +02:00
parent 929705f13e
commit d778ab5126
7 changed files with 70 additions and 54 deletions

View File

@@ -17,7 +17,7 @@ class QueryContextTest extends \PHPUnit_Framework_TestCase
{
$structure = $this->prophesize(Structure::class)->reveal();
$available_locales = ['ab', 'cd', 'ef'];
$context = new QueryContext($structure, [], $available_locales, 'fr');
$context = new QueryContext($structure, $available_locales, 'fr');
$narrowed = $context->narrowToFields(['some_field']);
$this->assertEquals(['some_field'], $narrowed->getFields());
}
@@ -30,7 +30,7 @@ class QueryContextTest extends \PHPUnit_Framework_TestCase
$structure->get('foo')->willReturn($public_field);
$structure->get('bar')->willReturn($restricted_field);
$context = new QueryContext($structure->reveal(), [], [], 'fr');
$context = new QueryContext($structure->reveal(), [], 'fr');
$this->assertEquals('caption.foo', $context->normalizeField('foo'));
$this->assertEquals('private_caption.bar', $context->normalizeField('bar'));
}