Skip to content

Commit

Permalink
Merge pull request #52 from apisearch-io/feature/added-autowiring-sup…
Browse files Browse the repository at this point in the history
…port

Added autowiring support
  • Loading branch information
mmoreram authored Nov 6, 2019
2 parents 406dc8f + f46cbc2 commit 78280f6
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .php_cs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"php":"7.3.8-1+ubuntu16.04.1+deb.sury.org+1","version":"2.15.1:v2.15.1#20064511ab796593a3990669eff5f5b535001f7c","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_closure":true},"class_definition":{"single_line":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,"lowercase_static_reference":true,"magic_constant_casing":true,"magic_method_casing":true,"native_function_casing":true,"native_function_type_declaration_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_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"protected_to_private":true,"return_type_declaration":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,"single_trait_insert_per_statement":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":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\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/ApisearchBundleFunctionalTest.php":1130132530,"Tests\/Functional\/ProductWriteTransformer.php":4090808924,"Tests\/Functional\/Command\/IndexCommandTest.php":4092266881,"Tests\/Functional\/Command\/PrintIndicesCommandTest.php":481741707,"Tests\/Functional\/Command\/QueryCommandTest.php":2580406218,"Tests\/Functional\/Command\/AddDeleteTokensCommandTest.php":1868952970,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":1149363544,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":3052848166,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":1388027657,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":2500445244,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2956180423,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":271608124,"Translator\/AggregationTranslator.php":4238166597,"ApisearchBundle.php":3640212495,"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"Command\/ImportIndexCommand.php":3461230433,"Command\/CreateIndexCommand.php":3731774129,"Command\/ApisearchFormattedCommand.php":1111995920,"Command\/ResetIndexCommand.php":3426927232,"Command\/DeleteIndexCommand.php":1350714493,"Command\/ApisearchCommand.php":3872958448,"Command\/WithAppRepositoryBucketCommand.php":2197592132,"Command\/PrintIndicesCommand.php":2224987197,"Command\/DeleteTokensCommand.php":290859330,"Command\/AddTokenCommand.php":684681072,"Command\/PrintTokensCommand.php":1079623314,"Command\/ExportIndexCommand.php":1133721139,"Command\/ConfigureIndexCommand.php":2680853722,"Command\/WithRepositoryBucketCommand.php":3434324818,"Command\/DeleteTokenCommand.php":121828308,"Command\/QueryCommand.php":3024631832,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":863427065,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/ApisearchConfiguration.php":187997719,"DependencyInjection\/ApisearchExtension.php":112225700}}
{"php":"7.3.9-1+ubuntu18.04.1+deb.sury.org+1","version":"2.16.0:v2.16.0#ceaff36bee1ed3f1bbbedca36d2528c0826c336d","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_closure":true},"class_definition":{"single_line":true},"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":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,"array_syntax":{"syntax":"short"},"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":true,"declare_equal_normalize":true,"function_typehint_space":true,"include":true,"increment_style":true,"lowercase_cast":true,"lowercase_static_reference":true,"magic_constant_casing":true,"magic_method_casing":true,"native_function_casing":true,"native_function_type_declaration_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":true,"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_superfluous_phpdoc_tags":{"allow_mixed":true,"allow_unused_params":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,"ordered_imports":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_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_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"return_type_declaration":true,"semicolon_after_instruction":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_line_comment_style":{"comment_types":["hash"]},"single_line_throw":true,"single_quote":true,"single_trait_insert_per_statement":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":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\/Functional\/AService.php":3371820063,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":1794882875,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":3620326332,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":2286676217,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":3050954938,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":271608124,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2271614667,"Tests\/Functional\/ApisearchBundleFunctionalTest.php":1563748362,"Tests\/Functional\/ProductWriteTransformer.php":2899478219,"Tests\/Functional\/ProductBothTransformer.php":479133393,"Tests\/Functional\/Command\/PrintIndicesCommandTest.php":481741707,"Tests\/Functional\/Command\/QueryCommandTest.php":2580406218,"Tests\/Functional\/Command\/AddDeleteTokensCommandTest.php":1868952970,"Tests\/Functional\/Command\/IndexCommandTest.php":4092266881,"Tests\/Functional\/ProductReadTransformer.php":1717369761,"Tests\/Functional\/AutowiringTest.php":1216361311,"DependencyInjection\/ApisearchExtension.php":4206190540,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":3605104821,"DependencyInjection\/ApisearchConfiguration.php":1136730770,"Twig\/UrlBuilderExtension.php":1095204211,"Twig\/AggregationTranslationExtension.php":257790318,"Twig\/MethodAccessorExtension.php":2939807874,"Command\/ApisearchCommand.php":3928891909,"Command\/AddTokenCommand.php":3051589506,"Command\/WithRepositoryBucketCommand.php":1083077272,"Command\/DeleteTokensCommand.php":877678679,"Command\/ImportIndexCommand.php":3607079391,"Command\/ApisearchFormattedCommand.php":3862548494,"Command\/PrintTokensCommand.php":3348297778,"Command\/DeleteIndexCommand.php":1546190123,"Command\/DeleteTokenCommand.php":3627377100,"Command\/QueryCommand.php":2332984996,"Command\/WithAppRepositoryBucketCommand.php":759489361,"Command\/PrintIndicesCommand.php":885255525,"Command\/ResetIndexCommand.php":4125855051,"Command\/ConfigureIndexCommand.php":2323095110,"Command\/CreateIndexCommand.php":435275942,"Command\/ExportIndexCommand.php":3253784633,"Translator\/AggregationTranslator.php":3711919960,"ApisearchBundle.php":4293551145}}
38 changes: 25 additions & 13 deletions DependencyInjection/CompilerPass/RepositoryCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\DependencyInjection\CompilerPass;

use Apisearch\App\AppRepository;
use Apisearch\App\DiskAppRepository;
use Apisearch\App\HttpAppRepository;
use Apisearch\App\InMemoryAppRepository;
Expand All @@ -27,11 +28,13 @@
use Apisearch\Repository\DiskRepository;
use Apisearch\Repository\HttpRepository;
use Apisearch\Repository\InMemoryRepository;
use Apisearch\Repository\Repository;
use Apisearch\Repository\RepositoryReference;
use Apisearch\Repository\TransformableRepository;
use Apisearch\User\DiskUserRepository;
use Apisearch\User\HttpUserRepository;
use Apisearch\User\InMemoryUserRepository;
use Apisearch\User\UserRepository;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -110,7 +113,8 @@ private function createAppRepositories(
'app',
InMemoryAppRepository::class,
DiskAppRepository::class,
HttpAppRepository::class
HttpAppRepository::class,
AppRepository::class
);

$this->createStandardRepository(
Expand All @@ -121,7 +125,8 @@ private function createAppRepositories(
'user',
InMemoryUserRepository::class,
DiskUserRepository::class,
HttpUserRepository::class
HttpUserRepository::class,
UserRepository::class
);
}

Expand Down Expand Up @@ -162,7 +167,6 @@ private function createIndexRepositories(
*
* @param ContainerBuilder $container
* @param string $name
* @param string $name
* @param array $repositoryConfiguration
*/
private function createClientRetryMap(
Expand Down Expand Up @@ -226,19 +230,20 @@ private function createClient(
* Create a repository by connection configuration.
*
* @param ContainerBuilder $container
* @param string $name
* @param string $appName
* @param array $repositoryConfiguration
* @param string $indexName
*/
private function createSearchRepository(
ContainerBuilder $container,
string $name,
string $appName,
array $repositoryConfiguration,
string $indexName
) {
$repositoryName = "apisearch.repository_$name.$indexName";
$repositoryTransformableName = "apisearch.repository_transformable_$name.$indexName";
$clientName = "apisearch.client_$name";
$repositoryName = "apisearch.repository_$appName.$indexName";
$aliasName = rtrim(sprintf("apisearch %s %s repository", $appName, $indexName), '.');
$repositoryTransformableName = "apisearch.repository_transformable_$appName.$indexName";
$clientName = "apisearch.client_$appName";

switch ($repositoryConfiguration['adapter']) {
case 'in_memory':
Expand All @@ -250,7 +255,7 @@ private function createSearchRepository(
case 'disk':
$repositoryDefinition = $container
->register($repositoryName, DiskRepository::class)
->addArgument($repositoryConfiguration['disk_file'].'.'.$name)
->addArgument($repositoryConfiguration['disk_file'].'.'.$appName)
->setPublic($this->repositoryIsTest($repositoryConfiguration));
break;

Expand All @@ -272,7 +277,7 @@ private function createSearchRepository(

$this->injectRepositoryCredentials(
$repositoryDefinition,
$name,
$appName,
$repositoryConfiguration,
$indexName
);
Expand All @@ -286,7 +291,7 @@ private function createSearchRepository(

$this->injectRepositoryCredentials(
$definition,
$name,
$appName,
$repositoryConfiguration,
$indexName
);
Expand All @@ -295,9 +300,11 @@ private function createSearchRepository(
->getDefinition('apisearch.repository_bucket')
->addMethodCall(
'addRepository',
[$name, $indexName, new Reference($repositoryName)]
[$appName, $indexName, new Reference($repositoryName)]
)
->setPublic($this->repositoryIsTest($repositoryConfiguration));

$container->registerAliasForArgument($repositoryName, Repository::class, $aliasName);
}

/**
Expand All @@ -311,6 +318,7 @@ private function createSearchRepository(
* @param string $inMemoryRepositoryNamespace
* @param string $diskRepositoryNamespace
* @param string $httpRepositoryNamespace
* @param string $interfaceNamespace
*/
private function createStandardRepository(
ContainerBuilder $container,
Expand All @@ -320,9 +328,11 @@ private function createStandardRepository(
string $prefix,
string $inMemoryRepositoryNamespace,
string $diskRepositoryNamespace,
string $httpRepositoryNamespace
string $httpRepositoryNamespace,
string $interfaceNamespace
) {
$repositoryName = rtrim("apisearch.{$prefix}_repository_$appName.$indexName", '.');
$aliasName = rtrim(sprintf("apisearch %s %s %s repository", $appName, $indexName, $prefix), '.');
$tokenUUIDName = rtrim("apisearch.token_uuid.$appName");
$clientName = rtrim("apisearch.client_$appName", '.');

Expand Down Expand Up @@ -391,6 +401,8 @@ private function createStandardRepository(
[$appName, new Reference($repositoryName)]
)
->setPublic($this->repositoryIsTest($repositoryConfiguration));

$container->registerAliasForArgument($repositoryName, $interfaceNamespace, $aliasName);
}

/**
Expand Down
60 changes: 60 additions & 0 deletions Tests/Functional/AService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php


namespace Apisearch\Tests\Functional;

use Apisearch\App\AppRepository;
use Apisearch\Repository\Repository;
use Apisearch\User\UserRepository;

/**
* Class AService
*/
class AService
{
public $appRepo1;
public $appRepo2;
public $appRepo3;

public $userRepo1;
public $userRepo2;

public $repo1;
public $repo2;

/**
* AService constructor.
*
* @param AppRepository $apisearchMain2AppRepository
* @param AppRepository $apisearchApp123nameAppRepository
* @param AppRepository $apisearchMainAppRepository
*
* @param UserRepository $apisearchMainUserRepository
* @param UserRepository $apisearchApp123nameUserRepository
*
* @param Repository $apisearchMain2DefaultRepository
* @param Repository $apisearchApp123nameIndex123nameRepository
*/
public function __construct(
AppRepository $apisearchMain2AppRepository,
AppRepository $apisearchApp123nameAppRepository,
AppRepository $apisearchMainAppRepository,

UserRepository $apisearchMainUserRepository,
UserRepository $apisearchApp123nameUserRepository,

Repository $apisearchMain2DefaultRepository,
Repository $apisearchApp123nameIndex123nameRepository
)
{
$this->appRepo1 = $apisearchMain2AppRepository;
$this->appRepo2 = $apisearchApp123nameAppRepository;
$this->appRepo3 = $apisearchMainAppRepository;

$this->userRepo1 = $apisearchMainUserRepository;
$this->userRepo2 = $apisearchApp123nameUserRepository;

$this->repo1 = $apisearchMain2DefaultRepository;
$this->repo2 = $apisearchApp123nameIndex123nameRepository;
}
}
Loading

0 comments on commit 78280f6

Please sign in to comment.