Skip to content

Commit

Permalink
PrividerPass gets Elasticsearch manager name from its repository name…
Browse files Browse the repository at this point in the history
… dynamically

  - Test updated
  - Docs updated
  • Loading branch information
Lukas committed Feb 25, 2015
1 parent 284796e commit 4850af7
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 55 deletions.
19 changes: 17 additions & 2 deletions DependencyInjection/Compiler/ProviderPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,28 @@ protected function generateProvider(ContainerBuilder $container, $profile)
{
$id = "ongr_settings.dynamic_provider.{$profile}";

$manager = $container->getParameter('ongr_settings.connection.manager');
$managerName = $this->getElasticManagerFromRepository($container);

$provider = new Definition($container->getParameter('ongr_settings.settings_provider.class'), [$profile]);
$provider->addMethodCall('setManager', [new Reference($manager)]);
$provider->addMethodCall('setManager', [new Reference($managerName)]);
$provider->addTag('ongr_settings.settings_provider', ['profile' => $profile]);
$container->setDefinition($id, $provider);

return $id;
}

/**
* Gets Elasticsearch manager name from repository name.
*
* @param ContainerBuilder $container
*
* @return string
*/
private function getElasticManagerFromRepository(ContainerBuilder $container)
{
$repositoryName = $container->getParameter('ongr_settings.connection.repository');
$managerName = substr($repositoryName, 0, strrpos($repositoryName, '.'));

return $managerName;
}
}
4 changes: 0 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public function getConfigTreeBuilder()
->defaultValue('ongr-settings')
->info('Index name for settings')
->end()
->scalarNode('manager')
->defaultValue('es.manager.settings')
->info('Elasticsearch manager for settings')
->end()
->scalarNode('repository')
->defaultValue('es.manager.settings.setting')
->info('Elasticsearch repository for settings')
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/ONGRSettingsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('ongr_settings.connection.index_name', $config['connection']['index_name']);
$container->setParameter('ongr_settings.connection.port', $config['connection']['port']);
$container->setParameter('ongr_settings.connection.host', $config['connection']['host']);
$container->setParameter('ongr_settings.connection.manager', $config['connection']['manager']);
$container->setParameter('ongr_settings.connection.repository', $config['connection']['repository']);

// Set profiles.
Expand Down Expand Up @@ -94,7 +93,7 @@ protected function setFiltersManager(ContainerBuilder $container)
'ONGR\FilterManagerBundle\Search\FiltersManager',
[
new Reference('ongr_settings.filters_container'),
new Reference( $container->getParameter('ongr_settings.connection.repository') ),
new Reference($container->getParameter('ongr_settings.connection.repository')),
]
);
$container->setDefinition('ongr_settings.filters_manager', $definition);
Expand Down
16 changes: 15 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In your shell enter the following:

.. code-block:: bash
composer require ongr/SettingsBundle "~0.1"
composer require ongr/settings-bundle "~0.1"
..
Expand All @@ -62,6 +62,7 @@ Then register SettingsBundle and it dependant bundles in ``AppKernel.php``:
new Tedivm\StashBundle\TedivmStashBundle(),
new ONGR\CookiesBundle\ONGRCookiesBundle(),
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
new ONGR\FilterManagerBundle\ONGRFilterManagerBundle(),
new ONGR\SettingsBundle\ONGRSettingsBundle(),
];
}
Expand Down Expand Up @@ -121,6 +122,19 @@ You should add an entry to your ``config.yml`` you should add an entry:
Using this config, console command below will create an Elasticsearch index called ``settings``
with 2 shards and 0 replicas, after running the console command mentioned above.

In case if you wish to use different Elasticsearch connection options, you can configure manager used in SettingsBundle
with following ``config.yml`` entry:

.. code-block:: yaml
ongr_settings:
connection:
repository: es.manager.default.setting
..
This example shows how you can configure settings repository, that is access in manager called ``default``.

Second - new index in Elasticsearch should be created.
This can be done by running a command in console:

Expand Down
16 changes: 15 additions & 1 deletion Resources/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In your shell enter the following:

.. code-block:: bash
composer require ongr/SettingsBundle "~0.1"
composer require ongr/settings-bundle "~0.1"
..
Expand All @@ -62,6 +62,7 @@ Then register SettingsBundle and it dependant bundles in ``AppKernel.php``:
new Tedivm\StashBundle\TedivmStashBundle(),
new ONGR\CookiesBundle\ONGRCookiesBundle(),
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
new ONGR\FilterManagerBundle\ONGRFilterManagerBundle(),
new ONGR\SettingsBundle\ONGRSettingsBundle(),
];
}
Expand Down Expand Up @@ -121,6 +122,19 @@ You should add an entry to your ``config.yml`` you should add an entry:
Using this config, console command below will create an Elasticsearch index called ``settings``
with 2 shards and 0 replicas, after running the console command mentioned above.

In case if you wish to use different Elasticsearch connection options, you can configure manager used in SettingsBundle
with following ``config.yml`` entry:

.. code-block:: yaml
ongr_settings:
connection:
repository: es.manager.default.setting
..
This example shows how you can configure settings repository, that is access in manager called ``default``.

Second - new index in Elasticsearch should be created.
This can be done by running a command in console:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public function testProcess()
$container = new ContainerBuilder();
$container->setDefinition('ongr_settings.settings_container', new Definition());
$container->setParameter('ongr_settings.settings_container.profiles', ['default', 'custom']);
$container->setParameter('ongr_settings.connection.manager', 'es.manager');
$container->setParameter(
'ongr_settings.settings_provider.class',
'ONGR\\SettingsBundle\\Settings\\Personal\\Provider\\ManagerAwareSettingProvider.php'
);
$container->setParameter('ongr_settings.connection.repository', 'es.manager.setting');

$definition = new Definition();
$definition->addTag('ongr_settings.ongr_settings', ['profile' => 'custom']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testProcess()
'ongr_settings.settings_provider.class',
'ONGR\\SettingsBundle\\Settings\\Personal\\Provider\\ManagerAwareSettingProvider'
);
$container->setParameter('ongr_settings.connection.manager', 'es.manager');
$container->setParameter('ongr_settings.connection.repository', 'es.manager.default.setting');

$definition = new Definition();
$definition->addTag('ongr_settings.settings_provider', ['profile' => 'custom', 'priority' => 9]);
Expand Down
2 changes: 0 additions & 2 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function configurationData()
'index_name' => 'ongr-settings',
'host' => '127.0.0.1',
'port' => 9200,
'manager' => 'es.manager.settings',
'repository' => 'es.manager.settings.setting',
];

Expand All @@ -47,7 +46,6 @@ public function configurationData()
'index_name' => 'ongr-test',
'host' => '127.5.0.1',
'port' => 9205,
'manager' => 'es.manager.settings',
'repository' => 'es.manager.settings.setting',
];
$out[] = [
Expand Down
1 change: 0 additions & 1 deletion Tests/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function registerBundles()
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
new Tedivm\StashBundle\TedivmStashBundle(),

new ONGR\PagerBundle\ONGRPagerBundle(),
new ONGR\CookiesBundle\ONGRCookiesBundle(),
new ONGR\SettingsBundle\Tests\Fixtures\Acme\TestBundle\AcmeTestBundle(),
new ONGR\SettingsBundle\ONGRSettingsBundle(),
Expand Down
37 changes: 3 additions & 34 deletions Tests/app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,7 @@ ongr_elasticsearch:
number_of_replicas: 0
index:
refresh_interval: -1
analysis:
tokenizer:
pathTokenizer:
type : path_hierarchy
buffer_size: 2024
skip: 0
delimiter: /
filter:
incremental_filter:
type: edge_ngram
min_gram: 1
max_gram: 20
analyzer:
indexAnalyzer:
type: snowball
language: German2
stopwords: "der,die,das,mit,und,für"
searchAnalyzer:
type: snowball
language: German2
stopwords: "der,die,das,mit,und,für"
pathAnalyzer:
type: custom
tokenizer: pathTokenizer
urlAnalyzer:
type: custom
tokenizer: keyword
filter: [lowercase]
incrementalAnalyzer:
type: custom
tokenizer: standard
filter:
- lowercase
- incremental_filter

managers:
default:
connection: default
Expand Down Expand Up @@ -163,6 +130,8 @@ services:

ongr_settings:
profiles: [ test1, test2, default, meh ]
connection:
repository: es.manager.default.setting
admin_user:
categories:
category_1:
Expand Down
7 changes: 6 additions & 1 deletion Tests/app/config/config_test_container_creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ ongr_elasticsearch:
mappings:
- ONGRSettingsBundle

ongr_settings:
connection:
repository: es.manager.default.setting

services:
ongr_settings.settings_manager:
class: %ongr_settings.settings_manager.class%
Expand Down Expand Up @@ -124,4 +128,5 @@ services:
ongr_settings.pair_storage:
class: %ongr_settings.pair_storage.class%
arguments:
- @es.manager
- @es.manager

3 changes: 0 additions & 3 deletions Tests/app/config/parameters_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ parameters:
cdn_url_ssl: 'https:%cdn_base_url%'

ongr_settings.environment_variables_pass_test_param: unchanged_param

ongr_settings.connection.manager: es.manager
ongr_settings.connection.repository: es.manager.setting
2 changes: 0 additions & 2 deletions Tests/app/config/parameters_test_container_creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ parameters:

ongr_settings.authentication.secret: O0EKwvq8Sv30O3ImKdXT7aT

ongr_settings.connection.manager: es.manager
ongr_settings.connection.repository: es.manager.setting

0 comments on commit 4850af7

Please sign in to comment.