Skip to content

Commit

Permalink
Merge pull request #6 from RSQueue/feature/adding-cluster
Browse files Browse the repository at this point in the history
Feature/adding cluster
  • Loading branch information
mmoreram authored Jan 31, 2018
2 parents 1bd8c37 + 703e033 commit 866915d
Show file tree
Hide file tree
Showing 19 changed files with 525 additions and 175 deletions.
6 changes: 2 additions & 4 deletions .formatter.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use-sort:
group:
- _main
- RSQueueBundle
group-type: each
sort-type: alph
sort-direction: asc

strict: true
header: |
/*
* This file is part of the RSQueue library
*
* Copyright (c) 2016 Marc Morera
* Copyright (c) 2016 - now() Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
31 changes: 12 additions & 19 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<?php

return Symfony\CS\Config\Config::create()
// use SYMFONY_LEVEL:
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
// and extra fixers:
->fixers(array(
'concat_with_spaces',
'multiline_spaces_before_semicolon',
'short_array_syntax',
'-remove_lines_between_uses',
'-empty_return',
'-phpdoc_var_without_name',
'-phpdoc_to_comment',
))
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in('Collector/')
->in('DependencyInjection/')
->in('Tests/')
)
$finder = PhpCsFixer\Finder::create()
->exclude('Resources')
->exclude('travis')
->exclude('vendor')
->in(__DIR__)
;
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'@Symfony' => true,
])
->setFinder($finder)
;
1 change: 1 addition & 0 deletions .php_cs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"php":"7.1.12-1+ubuntu16.04.1+deb.sury.org+1","version":"2.10.0:v2.10.0#513a3765b56dd029175f9f32995566657ee89dda","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_closure":true},"class_definition":{"singleLine":true},"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"binary_operator_spaces":true,"blank_line_after_opening_tag":true,"blank_line_before_statement":{"statements":["return"]},"cast_spaces":true,"class_attributes_separation":{"elements":["method"]},"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"function_typehint_space":true,"include":true,"increment_style":true,"lowercase_cast":true,"magic_constant_casing":true,"native_function_casing":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["curly_brace_block","extra","parenthesis_brace_block","square_brace_block","throw","use"]},"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unneeded_curly_braces":true,"no_unneeded_final_method":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_align":{"tags":["method","param","property","return","throws","type","var"]},"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"protected_to_private":true,"return_type_declaration":true,"self_accessor":true,"semicolon_after_instruction":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true},"hashes":{"Tests\/RSQueueFunctionalTest.php":3341026368,"Tests\/Services\/ProducerTest.php":2364093899,"Tests\/Services\/PublisherTest.php":115614915,"Tests\/Services\/ConsumerTest.php":1511805715,"Tests\/ClusterRedisTest.php":2686785634,"Tests\/SimpleRedisTest.php":26860270,"RSQueueBundle.php":1122671989,"Collector\/RSQueueCollector.php":909912693,"DependencyInjection\/RSQueueConfiguration.php":3942909266,"DependencyInjection\/RSQueueExtension.php":3738381686}}
5 changes: 3 additions & 2 deletions Collector/RSQueueCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the RSQueue library
*
* Copyright (c) 2016 Marc Morera
* Copyright (c) 2016 - now() Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,6 +13,8 @@
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace RSQueueBundle\Collector;

use Exception;
Expand Down Expand Up @@ -132,7 +134,6 @@ public function reset()
{
$this->total = 0;
$this->data = [

'prod' => [],
'publ' => [],
'total' => 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the RSQueue library
*
* Copyright (c) 2016 Marc Morera
* Copyright (c) 2016 - now() Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,26 +13,25 @@
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace RSQueueBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Mmoreram\BaseBundle\DependencyInjection\BaseConfiguration;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
* Class RSQueueConfiguration.
*/
class Configuration implements ConfigurationInterface
class RSQueueConfiguration extends BaseConfiguration
{
/**
* {@inheritdoc}
* Configure the root node.
*
* @param ArrayNodeDefinition $rootNode Root node
*/
public function getConfigTreeBuilder()
protected function setupTree(ArrayNodeDefinition $rootNode)
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('rs_queue');

$rootNode
->addDefaultsIfNotSet()
->children()
Expand All @@ -49,6 +48,9 @@ public function getConfigTreeBuilder()
->arrayNode('redis')
->addDefaultsIfNotSet()
->children()
->scalarNode('cluster')
->defaultFalse()
->end()
->scalarNode('host')
->defaultValue('127.0.0.1')
->end()
Expand All @@ -63,7 +65,5 @@ public function getConfigTreeBuilder()
->end()
->end()
->end();

return $treeBuilder;
}
}
135 changes: 89 additions & 46 deletions DependencyInjection/RSQueueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the RSQueue library
*
* Copyright (c) 2016 Marc Morera
* Copyright (c) 2016 - now() Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,66 +13,109 @@
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace RSQueueBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Mmoreram\BaseBundle\DependencyInjection\BaseExtension;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class RSQueueExtension extends Extension
class RSQueueExtension extends BaseExtension
{
/**
* {@inheritdoc}
* Returns the recommended alias to use in XML.
*
* This alias is also the mandatory prefix to use when using YAML.
*
* @return string The alias
*/
public function load(array $configs, ContainerBuilder $container)
public function getAlias()
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter(
'rs_queue.queues',
$config['queues']
);

$container->setParameter(
'rs_queue.serializer.class',
$config['serializer']
);

$container->setParameter(
'rs_queue.server.redis',
$config['server']['redis']
);
return 'rs_queue';
}

$loader = new Loader\YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
/**
* Get the Config file location.
*
* @return string
*/
protected function getConfigFilesLocation(): string
{
return __DIR__.'/../Resources/config';
}

$loader->load('services.yml');
$loader->load('collector.yml');
$loader->load('redis.yml');
$loader->load('serializers.yml');
/**
* Config files to load.
*
* Each array position can be a simple file name if must be loaded always,
* or an array, with the filename in the first position, and a boolean in
* the second one.
*
* As a parameter, this method receives all loaded configuration, to allow
* setting this boolean value from a configuration value.
*
* return array(
* 'file1.yml',
* 'file2.yml',
* ['file3.yml', $config['my_boolean'],
* ...
* );
*
* @param array $config Config definitions
*
* @return array Config files
*/
protected function getConfigFiles(array $config): array
{
return [
'services',
'collector',
'redis',
'serializers',
];
}

// BC sf < 2.6
$definition = $container->getDefinition('rs_queue.serializer');
$definition->setFactory([
new Reference('rs_queue.serializer.factory'),
'get',
]);
/**
* Return a new Configuration instance.
*
* If object returned by this method is an instance of
* ConfigurationInterface, extension will use the Configuration to read all
* bundle config definitions.
*
* Also will call getParametrizationValues method to load some config values
* to internal parameters.
*
* @return ConfigurationInterface|null
*/
protected function getConfigurationInstance(): ? ConfigurationInterface
{
return new RSQueueConfiguration($this->getAlias());
}

// BC sf < 2.6
$definition = $container->getDefinition('rs_queue.redis');
$definition->setFactory([
new Reference('rs_queue.redis.factory'),
'get',
]);
/**
* Load Parametrization definition.
*
* return array(
* 'parameter1' => $config['parameter1'],
* 'parameter2' => $config['parameter2'],
* ...
* );
*
* @param array $config Bundles config values
*
* @return array
*/
protected function getParametrizationValues(array $config): array
{
return [
'rs_queue.queues' => $config['queues'],
'rs_queue.serializer.class' => $config['serializer'],
'rs_queue.server.redis' => $config['server']['redis'],
];
}
}
42 changes: 36 additions & 6 deletions RSQueueBundle.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
<?php

namespace RSQueueBundle;
/*
* This file is part of the RSQueue library
*
* Copyright (c) 2016 - now() Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/

use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
declare(strict_types=1);

namespace RSQueueBundle;

use Mmoreram\BaseBundle\BaseBundle;
use RSQueueBundle\DependencyInjection\RSQueueExtension;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* Main RSQueueBundle class
* Main RSQueueBundle class.
*/
class RSQueueBundle extends Bundle
class RSQueueBundle extends BaseBundle
{
/**
* Returns the bundle's container extension.
Expand All @@ -21,6 +37,20 @@ class RSQueueBundle extends Bundle
*/
public function getContainerExtension()
{
return new RSQueueExtension($this);
return new RSQueueExtension();
}

/**
* Return all bundle dependencies.
*
* Values can be a simple bundle namespace or its instance
*
* @return array
*/
public static function getBundleDependencies(KernelInterface $kernel): array
{
return [
FrameworkBundle::class,
];
}
}
9 changes: 6 additions & 3 deletions Resources/config/redis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
services:

rs_queue.redis.factory:
class: RSQueue\Factory\RedisFactory
rs_queue.redis_factory:
class: RSQueue\RedisFactory
arguments:
- "%rs_queue.server.redis%"

rs_queue.redis:
class: Redis
class: StdObject
factory:
- "@rs_queue.redis_factory"
- create
Loading

0 comments on commit 866915d

Please sign in to comment.