From 8256f0c7575e043abce10d432389fa9eadce17b1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Jul 2017 13:33:32 +0200 Subject: [PATCH 1/7] Dropped AnnotatedFactory in commands and replaced by ConfigAbstractFactory --- composer.json | 2 + module/CLI/config/dependencies.config.php | 68 ++++++++++++---- .../CLI/src/Command/Api/DisableKeyCommand.php | 9 --- .../src/Command/Api/GenerateKeyCommand.php | 11 +-- .../CLI/src/Command/Api/ListKeysCommand.php | 11 +-- .../Command/Config/GenerateCharsetCommand.php | 9 +-- .../Command/Config/GenerateSecretCommand.php | 9 +-- .../Shortcode/GeneratePreviewCommand.php | 11 --- .../Shortcode/GenerateShortcodeCommand.php | 10 --- .../Command/Shortcode/GetVisitsCommand.php | 9 --- .../Shortcode/ListShortcodesCommand.php | 12 +-- .../Command/Shortcode/ResolveUrlCommand.php | 9 --- .../CLI/src/Command/Tag/CreateTagCommand.php | 10 --- .../CLI/src/Command/Tag/DeleteTagsCommand.php | 10 --- .../CLI/src/Command/Tag/ListTagsCommand.php | 10 --- .../CLI/src/Command/Tag/RenameTagCommand.php | 10 --- .../Command/Visit/ProcessVisitsCommand.php | 11 --- module/Common/config/dependencies.config.php | 3 + .../DottedAccessConfigAbstractFactory.php | 79 +++++++++++++++++++ 19 files changed, 141 insertions(+), 162 deletions(-) create mode 100644 module/Common/src/Factory/DottedAccessConfigAbstractFactory.php diff --git a/composer.json b/composer.json index 637a66ab..4e909e5e 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,8 @@ "acelaya/zsm-annotated-services": "^1.0", "acelaya/ze-content-based-error-handler": "^2.0", "doctrine/orm": "^2.5", + "doctrine/collections": "^1.4 <1.5", + "doctrine/common": "^2.7 <2.8", "guzzlehttp/guzzle": "^6.2", "symfony/console": "^3.0", "symfony/process": "^3.0", diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php index 565ab8bc..641b58db 100644 --- a/module/CLI/config/dependencies.config.php +++ b/module/CLI/config/dependencies.config.php @@ -1,8 +1,14 @@ [ Application::class => ApplicationFactory::class, - Command\Shortcode\GenerateShortcodeCommand::class => AnnotatedFactory::class, - Command\Shortcode\ResolveUrlCommand::class => AnnotatedFactory::class, - Command\Shortcode\ListShortcodesCommand::class => AnnotatedFactory::class, - Command\Shortcode\GetVisitsCommand::class => AnnotatedFactory::class, - Command\Shortcode\GeneratePreviewCommand::class => AnnotatedFactory::class, - Command\Visit\ProcessVisitsCommand::class => AnnotatedFactory::class, - Command\Config\GenerateCharsetCommand::class => AnnotatedFactory::class, - Command\Config\GenerateSecretCommand::class => AnnotatedFactory::class, - Command\Api\GenerateKeyCommand::class => AnnotatedFactory::class, - Command\Api\DisableKeyCommand::class => AnnotatedFactory::class, - Command\Api\ListKeysCommand::class => AnnotatedFactory::class, - Command\Tag\ListTagsCommand::class => AnnotatedFactory::class, - Command\Tag\CreateTagCommand::class => AnnotatedFactory::class, - Command\Tag\RenameTagCommand::class => AnnotatedFactory::class, - Command\Tag\DeleteTagsCommand::class => AnnotatedFactory::class, + Command\Shortcode\GenerateShortcodeCommand::class => ConfigAbstractFactory::class, + Command\Shortcode\ResolveUrlCommand::class => ConfigAbstractFactory::class, + Command\Shortcode\ListShortcodesCommand::class => ConfigAbstractFactory::class, + Command\Shortcode\GetVisitsCommand::class => ConfigAbstractFactory::class, + Command\Shortcode\GeneratePreviewCommand::class => ConfigAbstractFactory::class, + Command\Visit\ProcessVisitsCommand::class => ConfigAbstractFactory::class, + Command\Config\GenerateCharsetCommand::class => ConfigAbstractFactory::class, + Command\Config\GenerateSecretCommand::class => ConfigAbstractFactory::class, + Command\Api\GenerateKeyCommand::class => ConfigAbstractFactory::class, + Command\Api\DisableKeyCommand::class => ConfigAbstractFactory::class, + Command\Api\ListKeysCommand::class => ConfigAbstractFactory::class, + Command\Tag\ListTagsCommand::class => ConfigAbstractFactory::class, + Command\Tag\CreateTagCommand::class => ConfigAbstractFactory::class, + Command\Tag\RenameTagCommand::class => ConfigAbstractFactory::class, + Command\Tag\DeleteTagsCommand::class => ConfigAbstractFactory::class, ], ], + ConfigAbstractFactory::class => [ + Command\Shortcode\GenerateShortcodeCommand::class => [ + Service\UrlShortener::class, + 'translator', + 'config.url_shortener.domain', + ], + Command\Shortcode\ResolveUrlCommand::class => [Service\UrlShortener::class, 'translator'], + Command\Shortcode\ListShortcodesCommand::class => [Service\ShortUrlService::class, 'translator'], + Command\Shortcode\GetVisitsCommand::class => [Service\VisitsTracker::class, 'translator'], + Command\Shortcode\GeneratePreviewCommand::class => [ + Service\ShortUrlService::class, + PreviewGenerator::class, + 'translator' + ], + Command\Visit\ProcessVisitsCommand::class => [ + Service\VisitService::class, + IpLocationResolver::class, + 'translator' + ], + Command\Config\GenerateCharsetCommand::class => ['translator'], + Command\Config\GenerateSecretCommand::class => ['translator'], + Command\Api\GenerateKeyCommand::class => [ApiKeyService::class, 'translator'], + Command\Api\DisableKeyCommand::class => [ApiKeyService::class, 'translator'], + Command\Api\ListKeysCommand::class => [ApiKeyService::class, 'translator'], + Command\Tag\ListTagsCommand::class => [Service\Tag\TagService::class, Translator::class], + Command\Tag\CreateTagCommand::class => [Service\Tag\TagService::class, Translator::class], + Command\Tag\RenameTagCommand::class => [Service\Tag\TagService::class, Translator::class], + Command\Tag\DeleteTagsCommand::class => [Service\Tag\TagService::class, Translator::class], + ], + ]; diff --git a/module/CLI/src/Command/Api/DisableKeyCommand.php b/module/CLI/src/Command/Api/DisableKeyCommand.php index 48d9d564..fbf02992 100644 --- a/module/CLI/src/Command/Api/DisableKeyCommand.php +++ b/module/CLI/src/Command/Api/DisableKeyCommand.php @@ -1,8 +1,6 @@ apiKeyService = $apiKeyService; diff --git a/module/CLI/src/Command/Api/GenerateKeyCommand.php b/module/CLI/src/Command/Api/GenerateKeyCommand.php index 75d94e65..7d436669 100644 --- a/module/CLI/src/Command/Api/GenerateKeyCommand.php +++ b/module/CLI/src/Command/Api/GenerateKeyCommand.php @@ -1,8 +1,6 @@ apiKeyService = $apiKeyService; $this->translator = $translator; - parent::__construct(null); + parent::__construct(); } public function configure() diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index b08c1ece..8be23ec1 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -1,9 +1,7 @@ apiKeyService = $apiKeyService; $this->translator = $translator; - parent::__construct(null); + parent::__construct(); } public function configure() diff --git a/module/CLI/src/Command/Config/GenerateCharsetCommand.php b/module/CLI/src/Command/Config/GenerateCharsetCommand.php index 22369934..bf0f2b6d 100644 --- a/module/CLI/src/Command/Config/GenerateCharsetCommand.php +++ b/module/CLI/src/Command/Config/GenerateCharsetCommand.php @@ -1,7 +1,6 @@ translator = $translator; - parent::__construct(null); + parent::__construct(); } public function configure() diff --git a/module/CLI/src/Command/Config/GenerateSecretCommand.php b/module/CLI/src/Command/Config/GenerateSecretCommand.php index bef5c86a..e27bf751 100644 --- a/module/CLI/src/Command/Config/GenerateSecretCommand.php +++ b/module/CLI/src/Command/Config/GenerateSecretCommand.php @@ -1,7 +1,6 @@ translator = $translator; - parent::__construct(null); + parent::__construct(); } public function configure() diff --git a/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php b/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php index b224ad61..68b7189e 100644 --- a/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php +++ b/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php @@ -1,11 +1,8 @@ visitsTracker = $visitsTracker; diff --git a/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php b/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php index a8594db7..1c8e17f8 100644 --- a/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php +++ b/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php @@ -1,10 +1,8 @@ shortUrlService = $shortUrlService; @@ -88,12 +79,11 @@ class ListShortcodesCommand extends Command public function execute(InputInterface $input, OutputInterface $output) { - $page = intval($input->getOption('page')); + $page = (int) $input->getOption('page'); $searchTerm = $input->getOption('searchTerm'); $tags = $input->getOption('tags'); $tags = ! empty($tags) ? explode(',', $tags) : []; $showTags = $input->getOption('showTags'); - $orderBy = $input->getOption('orderBy'); /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); diff --git a/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php b/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php index a94b47ad..3344b7af 100644 --- a/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php +++ b/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php @@ -1,9 +1,7 @@ urlShortener = $urlShortener; diff --git a/module/CLI/src/Command/Tag/CreateTagCommand.php b/module/CLI/src/Command/Tag/CreateTagCommand.php index 8a06d38c..530ee569 100644 --- a/module/CLI/src/Command/Tag/CreateTagCommand.php +++ b/module/CLI/src/Command/Tag/CreateTagCommand.php @@ -1,14 +1,11 @@ tagService = $tagService; diff --git a/module/CLI/src/Command/Tag/DeleteTagsCommand.php b/module/CLI/src/Command/Tag/DeleteTagsCommand.php index 0a4e271b..394eac40 100644 --- a/module/CLI/src/Command/Tag/DeleteTagsCommand.php +++ b/module/CLI/src/Command/Tag/DeleteTagsCommand.php @@ -1,14 +1,11 @@ tagService = $tagService; diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php index eb120226..97037406 100644 --- a/module/CLI/src/Command/Tag/ListTagsCommand.php +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -1,15 +1,12 @@ tagService = $tagService; diff --git a/module/CLI/src/Command/Tag/RenameTagCommand.php b/module/CLI/src/Command/Tag/RenameTagCommand.php index e3ee678e..89f267d3 100644 --- a/module/CLI/src/Command/Tag/RenameTagCommand.php +++ b/module/CLI/src/Command/Tag/RenameTagCommand.php @@ -1,15 +1,12 @@ tagService = $tagService; diff --git a/module/CLI/src/Command/Visit/ProcessVisitsCommand.php b/module/CLI/src/Command/Visit/ProcessVisitsCommand.php index 195d891c..8b4f82a8 100644 --- a/module/CLI/src/Command/Visit/ProcessVisitsCommand.php +++ b/module/CLI/src/Command/Visit/ProcessVisitsCommand.php @@ -1,12 +1,9 @@ 'Logger_Shlink', LoggerInterface::class => 'Logger_Shlink', ], + 'abstract_factories' => [ + Factory\DottedAccessConfigAbstractFactory::class, + ], ], ]; diff --git a/module/Common/src/Factory/DottedAccessConfigAbstractFactory.php b/module/Common/src/Factory/DottedAccessConfigAbstractFactory.php new file mode 100644 index 00000000..7d0e03b6 --- /dev/null +++ b/module/Common/src/Factory/DottedAccessConfigAbstractFactory.php @@ -0,0 +1,79 @@ + 0; + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * @return object + * @throws InvalidArgumentException + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $parts = explode('.', $requestedName); + $serviceName = array_shift($parts); + if (! $container->has($serviceName)) { + throw new ServiceNotCreatedException(sprintf( + 'Defined service "%s" could not be found in container after resolving dotted expression "%s".', + $serviceName, + $requestedName + )); + } + + $array = $container->get($serviceName); + return $this->readKeysFromArray($parts, $array); + } + + /** + * @param array $keys + * @param array|\ArrayAccess $array + * @return mixed|null + * @throws InvalidArgumentException + */ + private function readKeysFromArray(array $keys, $array) + { + $key = array_shift($keys); + + // When one of the provided keys is not found, throw an exception + if (! isset($array[$key])) { + throw new InvalidArgumentException(sprintf( + 'The key "%s" provided in the dotted notation could not be found in the array service', + $key + )); + } + + $value = $array[$key]; + if (! empty($keys) && (is_array($value) || $value instanceof \ArrayAccess)) { + $value = $this->readKeysFromArray($keys, $value); + } + + return $value; + } +} From 54cb40f6ed0e8e4a3f389a26dd422353a3010439 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Jul 2017 13:41:41 +0200 Subject: [PATCH 2/7] Replaced more ussages of AnnotatedFactory by ConfigAbstractFactory --- bin/install | 21 ++++++++++---- bin/update | 21 ++++++++++---- .../src/Factory/InstallApplicationFactory.php | 4 +-- module/Common/config/dependencies.config.php | 28 +++++++++++++------ .../src/Middleware/LocaleMiddleware.php | 7 ----- .../Common/src/Service/IpLocationResolver.php | 7 ----- .../Common/src/Service/PreviewGenerator.php | 10 ------- .../Twig/Extension/TranslatorExtension.php | 7 ----- 8 files changed, 53 insertions(+), 52 deletions(-) diff --git a/bin/install b/bin/install index 43a07cd3..e8ecb3c9 100755 --- a/bin/install +++ b/bin/install @@ -1,9 +1,11 @@ #!/usr/bin/env php [ - Application::class => InstallApplicationFactory::class, - Filesystem::class => InvokableFactory::class, - QuestionHelper::class => InvokableFactory::class, -]]); +$container = new ServiceManager([ + 'factories' => [ + Application::class => InstallApplicationFactory::class, + Filesystem::class => InvokableFactory::class, + QuestionHelper::class => InvokableFactory::class, + ], + 'services' => [ + 'config' => [ + ConfigAbstractFactory::class => [ + DatabaseConfigCustomizerPlugin::class => [QuestionHelper::class, Filesystem::class] + ], + ], + ], +]); $container->build(Application::class)->run(); diff --git a/bin/update b/bin/update index 164e20b0..d4203528 100755 --- a/bin/update +++ b/bin/update @@ -1,9 +1,11 @@ #!/usr/bin/env php [ - Application::class => InstallApplicationFactory::class, - Filesystem::class => InvokableFactory::class, - QuestionHelper::class => InvokableFactory::class, -]]); +$container = new ServiceManager([ + 'factories' => [ + Application::class => InstallApplicationFactory::class, + Filesystem::class => InvokableFactory::class, + QuestionHelper::class => InvokableFactory::class, + ], + 'services' => [ + 'config' => [ + ConfigAbstractFactory::class => [ + DatabaseConfigCustomizerPlugin::class => [QuestionHelper::class, Filesystem::class] + ], + ], + ], +]); $container->build(Application::class, ['isUpdate' => true])->run(); diff --git a/module/CLI/src/Factory/InstallApplicationFactory.php b/module/CLI/src/Factory/InstallApplicationFactory.php index 742b5b70..387b2321 100644 --- a/module/CLI/src/Factory/InstallApplicationFactory.php +++ b/module/CLI/src/Factory/InstallApplicationFactory.php @@ -1,7 +1,6 @@ get(Filesystem::class), new ConfigCustomizerPluginManager($container, ['factories' => [ - Plugin\DatabaseConfigCustomizerPlugin::class => AnnotatedFactory::class, + Plugin\DatabaseConfigCustomizerPlugin::class => ConfigAbstractFactory::class, Plugin\UrlShortenerConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class, Plugin\LanguageConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class, Plugin\ApplicationConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class, diff --git a/module/Common/config/dependencies.config.php b/module/Common/config/dependencies.config.php index 06250b3a..dd64b026 100644 --- a/module/Common/config/dependencies.config.php +++ b/module/Common/config/dependencies.config.php @@ -1,45 +1,44 @@ [ - 'invokables' => [ - Filesystem::class => Filesystem::class, - ], 'factories' => [ EntityManager::class => Factory\EntityManagerFactory::class, GuzzleHttp\Client::class => InvokableFactory::class, Cache::class => Factory\CacheFactory::class, 'Logger_Shlink' => Factory\LoggerFactory::class, + Filesystem::class => InvokableFactory::class, Translator::class => Factory\TranslatorFactory::class, - TranslatorExtension::class => AnnotatedFactory::class, - LocaleMiddleware::class => AnnotatedFactory::class, + TranslatorExtension::class => ConfigAbstractFactory::class, + LocaleMiddleware::class => ConfigAbstractFactory::class, Image\ImageBuilder::class => Image\ImageBuilderFactory::class, - Service\IpLocationResolver::class => AnnotatedFactory::class, - Service\PreviewGenerator::class => AnnotatedFactory::class, + Service\IpLocationResolver::class => ConfigAbstractFactory::class, + Service\PreviewGenerator::class => ConfigAbstractFactory::class, ], 'aliases' => [ 'em' => EntityManager::class, 'httpClient' => GuzzleHttp\Client::class, 'translator' => Translator::class, 'logger' => LoggerInterface::class, - AnnotatedFactory::CACHE_SERVICE => Cache::class, Logger::class => 'Logger_Shlink', LoggerInterface::class => 'Logger_Shlink', ], @@ -48,4 +47,15 @@ return [ ], ], + ConfigAbstractFactory::class => [ + TranslatorExtension::class => ['translator'], + LocaleMiddleware::class => ['translator'], + Service\IpLocationResolver::class => ['httpClient'], + Service\PreviewGenerator::class => [ + ImageBuilder::class, + Filesystem::class, + 'config.preview_generation.files_location', + ], + ], + ]; diff --git a/module/Common/src/Middleware/LocaleMiddleware.php b/module/Common/src/Middleware/LocaleMiddleware.php index 0cb81502..fe0ff2c6 100644 --- a/module/Common/src/Middleware/LocaleMiddleware.php +++ b/module/Common/src/Middleware/LocaleMiddleware.php @@ -1,7 +1,6 @@ translator = $translator; diff --git a/module/Common/src/Service/IpLocationResolver.php b/module/Common/src/Service/IpLocationResolver.php index 0bfa80ce..287760a3 100644 --- a/module/Common/src/Service/IpLocationResolver.php +++ b/module/Common/src/Service/IpLocationResolver.php @@ -1,7 +1,6 @@ httpClient = $httpClient; diff --git a/module/Common/src/Service/PreviewGenerator.php b/module/Common/src/Service/PreviewGenerator.php index 03fa392f..d85bf50b 100644 --- a/module/Common/src/Service/PreviewGenerator.php +++ b/module/Common/src/Service/PreviewGenerator.php @@ -1,10 +1,8 @@ location = $location; diff --git a/module/Common/src/Twig/Extension/TranslatorExtension.php b/module/Common/src/Twig/Extension/TranslatorExtension.php index 48ee3f11..807c3099 100644 --- a/module/Common/src/Twig/Extension/TranslatorExtension.php +++ b/module/Common/src/Twig/Extension/TranslatorExtension.php @@ -1,7 +1,6 @@ translator = $translator; From 6300982b071490520b7eaab659172da57621ad81 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Jul 2017 13:48:30 +0200 Subject: [PATCH 3/7] Replaced more ussages of AnnotatedFactory by ConfigAbstractFactory --- module/Core/config/dependencies.config.php | 39 ++++++++++++++----- module/Core/src/Action/PreviewAction.php | 10 ----- module/Core/src/Action/QrCodeAction.php | 10 ----- module/Core/src/Action/RedirectAction.php | 11 ------ .../src/Middleware/QrCodeCacheMiddleware.php | 7 ---- module/Core/src/Service/ShortUrlService.php | 9 +---- module/Core/src/Service/Tag/TagService.php | 7 ---- module/Core/src/Service/UrlShortener.php | 18 ++------- module/Core/src/Service/VisitService.php | 7 ---- module/Core/src/Service/VisitsTracker.php | 7 ---- 10 files changed, 34 insertions(+), 91 deletions(-) diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index 1ef7257c..a25c82fb 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -1,9 +1,13 @@ Options\AppOptionsFactory::class, // Services - Service\UrlShortener::class => AnnotatedFactory::class, - Service\VisitsTracker::class => AnnotatedFactory::class, - Service\ShortUrlService::class => AnnotatedFactory::class, - Service\VisitService::class => AnnotatedFactory::class, - Service\Tag\TagService::class => AnnotatedFactory::class, + Service\UrlShortener::class => ConfigAbstractFactory::class, + Service\VisitsTracker::class => ConfigAbstractFactory::class, + Service\ShortUrlService::class => ConfigAbstractFactory::class, + Service\VisitService::class => ConfigAbstractFactory::class, + Service\Tag\TagService::class => ConfigAbstractFactory::class, // Middleware - Action\RedirectAction::class => AnnotatedFactory::class, - Action\QrCodeAction::class => AnnotatedFactory::class, - Action\PreviewAction::class => AnnotatedFactory::class, - Middleware\QrCodeCacheMiddleware::class => AnnotatedFactory::class, + Action\RedirectAction::class => ConfigAbstractFactory::class, + Action\QrCodeAction::class => ConfigAbstractFactory::class, + Action\PreviewAction::class => ConfigAbstractFactory::class, + Middleware\QrCodeCacheMiddleware::class => ConfigAbstractFactory::class, ], ], + ConfigAbstractFactory::class => [ + // Services + Service\UrlShortener::class => ['httpClient', 'em', Cache::class, 'config.url_shortener.shortcode_chars'], + Service\VisitsTracker::class => ['em'], + Service\ShortUrlService::class => ['em'], + Service\VisitService::class => ['em'], + Service\Tag\TagService::class => ['em'], + + // Middleware + Action\RedirectAction::class => [Service\UrlShortener::class, Service\VisitsTracker::class, 'Logger_Shlink'], + Action\QrCodeAction::class => [RouterInterface::class, Service\UrlShortener::class, 'Logger_Shlink'], + Action\PreviewAction::class => [PreviewGenerator::class, Service\UrlShortener::class], + Middleware\QrCodeCacheMiddleware::class => [Cache::class], + ], + ]; diff --git a/module/Core/src/Action/PreviewAction.php b/module/Core/src/Action/PreviewAction.php index 291225be..12c57435 100644 --- a/module/Core/src/Action/PreviewAction.php +++ b/module/Core/src/Action/PreviewAction.php @@ -1,16 +1,13 @@ previewGenerator = $previewGenerator; diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index 3970d740..efef3400 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -1,7 +1,6 @@ cache = $cache; diff --git a/module/Core/src/Service/ShortUrlService.php b/module/Core/src/Service/ShortUrlService.php index 59c76565..c7ae94c9 100644 --- a/module/Core/src/Service/ShortUrlService.php +++ b/module/Core/src/Service/ShortUrlService.php @@ -1,7 +1,6 @@ em = $em; @@ -60,7 +53,7 @@ class ShortUrlService implements ShortUrlServiceInterface $shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy([ 'shortCode' => $shortCode, ]); - if (! isset($shortUrl)) { + if ($shortUrl === null) { throw InvalidShortCodeException::fromNotFoundShortCode($shortCode); } diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php index 52708a39..97fdca2d 100644 --- a/module/Core/src/Service/Tag/TagService.php +++ b/module/Core/src/Service/Tag/TagService.php @@ -1,7 +1,6 @@ em = $em; diff --git a/module/Core/src/Service/UrlShortener.php b/module/Core/src/Service/UrlShortener.php index 9d6927bf..67e32626 100644 --- a/module/Core/src/Service/UrlShortener.php +++ b/module/Core/src/Service/UrlShortener.php @@ -1,7 +1,6 @@ chars); $code = ''; while ($id > 0) { // Determine the value of the next higher character in the short code and prepend it - $code = $this->chars[intval(fmod($id, $length))] . $code; + $code = $this->chars[(int) fmod($id, $length)] . $code; $id = floor($id / $length); } - return $this->chars[intval($id)] . $code; + return $this->chars[(int) $id] . $code; } /** diff --git a/module/Core/src/Service/VisitService.php b/module/Core/src/Service/VisitService.php index d8e46c31..375cc57e 100644 --- a/module/Core/src/Service/VisitService.php +++ b/module/Core/src/Service/VisitService.php @@ -1,7 +1,6 @@ em = $em; diff --git a/module/Core/src/Service/VisitsTracker.php b/module/Core/src/Service/VisitsTracker.php index 94647086..92bafa71 100644 --- a/module/Core/src/Service/VisitsTracker.php +++ b/module/Core/src/Service/VisitsTracker.php @@ -1,7 +1,6 @@ em = $em; From 7ca22f862928579aa3a97f18c4bbeaef930299de Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Jul 2017 14:20:40 +0200 Subject: [PATCH 4/7] Removed any remaining reference to AnnotatedFactory --- composer.json | 2 +- module/Rest/config/dependencies.config.php | 60 ++++++++++++++----- module/Rest/src/Action/AuthenticateAction.php | 11 ---- .../Rest/src/Action/CreateShortcodeAction.php | 12 ---- .../src/Action/EditShortcodeTagsAction.php | 10 ---- module/Rest/src/Action/GetVisitsAction.php | 10 ---- .../Rest/src/Action/ListShortcodesAction.php | 10 ---- module/Rest/src/Action/ResolveUrlAction.php | 10 ---- .../Rest/src/Action/Tag/CreateTagsAction.php | 9 --- .../Rest/src/Action/Tag/DeleteTagsAction.php | 9 --- module/Rest/src/Action/Tag/ListTagsAction.php | 9 --- .../Rest/src/Action/Tag/UpdateTagAction.php | 11 ---- module/Rest/src/Authentication/JWTService.php | 7 --- .../CheckAuthenticationMiddleware.php | 11 +--- module/Rest/src/Service/ApiKeyService.php | 7 --- 15 files changed, 46 insertions(+), 142 deletions(-) diff --git a/composer.json b/composer.json index 4e909e5e..3b8a744e 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,9 @@ "zendframework/zend-config": "^3.0", "zendframework/zend-i18n": "^2.7", "zendframework/zend-config-aggregator": "^0.1", - "acelaya/zsm-annotated-services": "^1.0", "acelaya/ze-content-based-error-handler": "^2.0", "doctrine/orm": "^2.5", + "doctrine/annotations": "^1.4 <1.5", "doctrine/collections": "^1.4 <1.5", "doctrine/common": "^2.7 <2.8", "guzzlehttp/guzzle": "^6.2", diff --git a/module/Rest/config/dependencies.config.php b/module/Rest/config/dependencies.config.php index a36f7590..8f2227c0 100644 --- a/module/Rest/config/dependencies.config.php +++ b/module/Rest/config/dependencies.config.php @@ -1,34 +1,62 @@ [ 'factories' => [ - JWTService::class => AnnotatedFactory::class, - Service\ApiKeyService::class => AnnotatedFactory::class, + JWTService::class => ConfigAbstractFactory::class, + ApiKeyService::class => ConfigAbstractFactory::class, - Action\AuthenticateAction::class => AnnotatedFactory::class, - Action\CreateShortcodeAction::class => AnnotatedFactory::class, - Action\ResolveUrlAction::class => AnnotatedFactory::class, - Action\GetVisitsAction::class => AnnotatedFactory::class, - Action\ListShortcodesAction::class => AnnotatedFactory::class, - Action\EditShortcodeTagsAction::class => AnnotatedFactory::class, - Action\Tag\ListTagsAction::class => AnnotatedFactory::class, - Action\Tag\DeleteTagsAction::class => AnnotatedFactory::class, - Action\Tag\CreateTagsAction::class => AnnotatedFactory::class, - Action\Tag\UpdateTagAction::class => AnnotatedFactory::class, + Action\AuthenticateAction::class => ConfigAbstractFactory::class, + Action\CreateShortcodeAction::class => ConfigAbstractFactory::class, + Action\ResolveUrlAction::class => ConfigAbstractFactory::class, + Action\GetVisitsAction::class => ConfigAbstractFactory::class, + Action\ListShortcodesAction::class => ConfigAbstractFactory::class, + Action\EditShortcodeTagsAction::class => ConfigAbstractFactory::class, + Action\Tag\ListTagsAction::class => ConfigAbstractFactory::class, + Action\Tag\DeleteTagsAction::class => ConfigAbstractFactory::class, + Action\Tag\CreateTagsAction::class => ConfigAbstractFactory::class, + Action\Tag\UpdateTagAction::class => ConfigAbstractFactory::class, - Middleware\BodyParserMiddleware::class => AnnotatedFactory::class, + Middleware\BodyParserMiddleware::class => InvokableFactory::class, Middleware\CrossDomainMiddleware::class => InvokableFactory::class, Middleware\PathVersionMiddleware::class => InvokableFactory::class, - Middleware\CheckAuthenticationMiddleware::class => AnnotatedFactory::class, + Middleware\CheckAuthenticationMiddleware::class => ConfigAbstractFactory::class, ], ], + ConfigAbstractFactory::class => [ + JWTService::class => [AppOptions::class], + ApiKeyService::class => ['em'], + + Action\AuthenticateAction::class => [ApiKeyService::class, JWTService::class, 'translator', 'Logger_Shlink'], + Action\CreateShortcodeAction::class => [ + Service\UrlShortener::class, + 'translator', + 'config.url_shortener.domain', + 'Logger_Shlink' + ], + Action\ResolveUrlAction::class => [Service\UrlShortener::class, 'translator'], + Action\GetVisitsAction::class => [Service\VisitsTracker::class, 'translator', 'Logger_Shlink'], + Action\ListShortcodesAction::class => [Service\ShortUrlService::class, 'translator', 'Logger_Shlink'], + Action\EditShortcodeTagsAction::class => [Service\ShortUrlService::class, 'translator', 'Logger_Shlink'], + Action\Tag\ListTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], + Action\Tag\DeleteTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], + Action\Tag\CreateTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], + Action\Tag\UpdateTagAction::class => [Service\Tag\TagService::class, Translator::class, LoggerInterface::class], + + Middleware\CheckAuthenticationMiddleware::class => [JWTService::class, 'translator', 'Logger_Shlink'], + ], + ]; diff --git a/module/Rest/src/Action/AuthenticateAction.php b/module/Rest/src/Action/AuthenticateAction.php index a4b15920..1403e88e 100644 --- a/module/Rest/src/Action/AuthenticateAction.php +++ b/module/Rest/src/Action/AuthenticateAction.php @@ -1,12 +1,10 @@ appOptions = $appOptions; diff --git a/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php b/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php index d7d922ad..93537d35 100644 --- a/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php +++ b/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php @@ -1,7 +1,6 @@ em = $em; From abf802093c04339b05390bb9e271b448e15d730c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Jul 2017 08:42:57 +0200 Subject: [PATCH 5/7] Ensured all doctrine components are not updated to latest releases, which require PHP 7.1 --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3b8a744e..60856299 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "zendframework/zend-i18n": "^2.7", "zendframework/zend-config-aggregator": "^0.1", "acelaya/ze-content-based-error-handler": "^2.0", - "doctrine/orm": "^2.5", + "doctrine/orm": "^2.5 <2.6", + "doctrine/dbal": "^2.5 <2.6", "doctrine/annotations": "^1.4 <1.5", "doctrine/collections": "^1.4 <1.5", "doctrine/common": "^2.7 <2.8", From 574f407a906e7266d99626e9d5a0160f14b6c656 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Jul 2017 11:51:47 +0200 Subject: [PATCH 6/7] Ensured a doctrine/cache version which requires PHP 7.1 is not installed --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 60856299..e7fd3a4a 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "doctrine/annotations": "^1.4 <1.5", "doctrine/collections": "^1.4 <1.5", "doctrine/common": "^2.7 <2.8", + "doctrine/cache": "^1.6 <1.7", "guzzlehttp/guzzle": "^6.2", "symfony/console": "^3.0", "symfony/process": "^3.0", From 960c7a08356d0da85d7fbdaf890766aaba2cd827 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 19 Aug 2017 19:41:07 +0200 Subject: [PATCH 7/7] Added security-advisories dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e7fd3a4a..faab4cb7 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ ], "require": { "php": "^5.6 || ^7.0", + "roave/security-advisories": "dev-master", "zendframework/zend-expressive": "^2.0", "zendframework/zend-expressive-fastroute": "^2.0", "zendframework/zend-expressive-twigrenderer": "^1.4", @@ -43,7 +44,6 @@ "require-dev": { "phpunit/phpunit": "^5.7 || ^6.0", "squizlabs/php_codesniffer": "^2.3", - "roave/security-advisories": "dev-master", "filp/whoops": "^2.0", "symfony/var-dumper": "^3.0", "vlucas/phpdotenv": "^2.2",