From ab9c2f728a345081228c519dd10facfd014c142c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 19 Jul 2016 18:01:39 +0200 Subject: [PATCH] Created Core module --- composer.json | 2 -- config/autoload/services.global.php | 11 ---------- config/config.php | 2 ++ .../src/Command/GenerateShortcodeCommand.php | 7 +++---- module/CLI/src/Command/GetVisitsCommand.php | 4 ++-- .../CLI/src/Command/ListShortcodesCommand.php | 4 ++-- module/CLI/src/Command/ResolveUrlCommand.php | 6 +++--- .../Common/src}/Entity/AbstractEntity.php | 2 +- .../Core/config/routes.config.php | 4 ++-- module/Core/config/services.config.php | 20 +++++++++++++++++++ .../Core/src/Action}/RedirectMiddleware.php | 10 +++++----- module/Core/src/ConfigProvider.php | 13 ++++++++++++ {src => module/Core/src}/Entity/RestToken.php | 3 ++- {src => module/Core/src}/Entity/ShortUrl.php | 5 +++-- {src => module/Core/src}/Entity/Visit.php | 3 ++- .../Core/src/Exception/ExceptionInterface.php | 6 ++++++ .../Exception/InvalidArgumentException.php | 2 +- .../Exception/InvalidShortCodeException.php | 2 +- .../src}/Exception/InvalidUrlException.php | 2 +- .../Core/src}/Exception/RuntimeException.php | 2 +- .../src}/Repository/ShortUrlRepository.php | 5 ++--- .../ShortUrlRepositoryInterface.php | 2 +- .../Core/src}/Service/ShortUrlService.php | 6 +++--- .../src}/Service/ShortUrlServiceInterface.php | 4 ++-- .../Core/src}/Service/UrlShortener.php | 10 +++++----- .../src}/Service/UrlShortenerInterface.php | 8 ++++---- .../Core/src}/Service/VisitsTracker.php | 9 ++++----- .../src}/Service/VisitsTrackerInterface.php | 4 ++-- .../test}/Service/ShortUrlServiceTest.php | 8 ++++---- .../Core/test}/Service/UrlShortenerTest.php | 7 +++---- .../Core/test}/Service/VisitsTrackerTest.php | 6 +++--- .../src/Action/CreateShortcodeMiddleware.php | 6 +++--- .../Rest/src/Action/GetVisitsMiddleware.php | 6 +++--- .../src/Action/ListShortcodesMiddleware.php | 4 ++-- .../Rest/src/Action/ResolveUrlMiddleware.php | 6 +++--- .../src/Exception/AuthenticationException.php | 2 +- .../CheckAuthenticationMiddleware.php | 2 +- module/Rest/src/Service/RestTokenService.php | 4 ++-- .../src/Service/RestTokenServiceInterface.php | 4 ++-- module/Rest/src/Util/RestUtils.php | 2 +- src/Exception/ExceptionInterface.php | 6 ------ 41 files changed, 121 insertions(+), 100 deletions(-) rename {src => module/Common/src}/Entity/AbstractEntity.php (92%) rename config/autoload/routes.global.php => module/Core/config/routes.config.php (63%) create mode 100644 module/Core/config/services.config.php rename {src/Middleware/Routable => module/Core/src/Action}/RedirectMiddleware.php (91%) create mode 100644 module/Core/src/ConfigProvider.php rename {src => module/Core/src}/Entity/RestToken.php (95%) rename {src => module/Core/src}/Entity/ShortUrl.php (95%) rename {src => module/Core/src}/Entity/Visit.php (97%) create mode 100644 module/Core/src/Exception/ExceptionInterface.php rename {src => module/Core/src}/Exception/InvalidArgumentException.php (71%) rename {src => module/Core/src}/Exception/InvalidShortCodeException.php (90%) rename {src => module/Core/src}/Exception/InvalidUrlException.php (88%) rename {src => module/Core/src}/Exception/RuntimeException.php (68%) rename {src => module/Core/src}/Repository/ShortUrlRepository.php (93%) rename {src => module/Core/src}/Repository/ShortUrlRepositoryInterface.php (83%) rename {src => module/Core/src}/Service/ShortUrlService.php (88%) rename {src => module/Core/src}/Service/ShortUrlServiceInterface.php (70%) rename {src => module/Core/src}/Service/UrlShortener.php (94%) rename {src => module/Core/src}/Service/UrlShortenerInterface.php (74%) rename {src => module/Core/src}/Service/VisitsTracker.php (90%) rename {src => module/Core/src}/Service/VisitsTrackerInterface.php (86%) rename {tests => module/Core/test}/Service/ShortUrlServiceTest.php (86%) rename {tests => module/Core/test}/Service/UrlShortenerTest.php (96%) rename {tests => module/Core/test}/Service/VisitsTrackerTest.php (85%) delete mode 100644 src/Exception/ExceptionInterface.php diff --git a/composer.json b/composer.json index a64197a6..0211ed05 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,6 @@ }, "autoload": { "psr-4": { - "Acelaya\\UrlShortener\\": "src", "Shlinkio\\Shlink\\CLI\\": "module/CLI/src", "Shlinkio\\Shlink\\Rest\\": "module/Rest/src", "Shlinkio\\Shlink\\Core\\": "module/Core/src", @@ -46,7 +45,6 @@ }, "autoload-dev": { "psr-4": { - "AcelayaTest\\UrlShortener\\": "tests", "ShlinkioTest\\Shlink\\CLI\\": "module/CLI/test", "ShlinkioTest\\Shlink\\Rest\\": "module/Rest/test", "ShlinkioTest\\Shlink\\Core\\": "module/Core/test", diff --git a/config/autoload/services.global.php b/config/autoload/services.global.php index 00304e5f..dc99033c 100644 --- a/config/autoload/services.global.php +++ b/config/autoload/services.global.php @@ -1,7 +1,4 @@ Container\TemplatedErrorHandlerFactory::class, Template\TemplateRendererInterface::class => Twig\TwigRendererFactory::class, - - // Services - Service\UrlShortener::class => AnnotatedFactory::class, - Service\VisitsTracker::class => AnnotatedFactory::class, - Service\ShortUrlService::class => AnnotatedFactory::class, - - // Middleware - Middleware\Routable\RedirectMiddleware::class => AnnotatedFactory::class, ], 'aliases' => [ Router\RouterInterface::class => Router\FastRouteRouter::class, diff --git a/config/config.php b/config/config.php index 5b1fedf9..736b8fd4 100644 --- a/config/config.php +++ b/config/config.php @@ -1,6 +1,7 @@ 'long-url-redirect', 'path' => '/{shortCode}', - 'middleware' => Routable\RedirectMiddleware::class, + 'middleware' => RedirectMiddleware::class, 'allowed_methods' => ['GET'], ], ], diff --git a/module/Core/config/services.config.php b/module/Core/config/services.config.php new file mode 100644 index 00000000..cab7ca41 --- /dev/null +++ b/module/Core/config/services.config.php @@ -0,0 +1,20 @@ + [ + 'factories' => [ + // Services + Service\UrlShortener::class => AnnotatedFactory::class, + Service\VisitsTracker::class => AnnotatedFactory::class, + Service\ShortUrlService::class => AnnotatedFactory::class, + + // Middleware + RedirectMiddleware::class => AnnotatedFactory::class, + ], + ], + +]; diff --git a/src/Middleware/Routable/RedirectMiddleware.php b/module/Core/src/Action/RedirectMiddleware.php similarity index 91% rename from src/Middleware/Routable/RedirectMiddleware.php rename to module/Core/src/Action/RedirectMiddleware.php index 85b42eb6..5b1907ca 100644 --- a/src/Middleware/Routable/RedirectMiddleware.php +++ b/module/Core/src/Action/RedirectMiddleware.php @@ -1,13 +1,13 @@