mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 17:06:41 -06:00
Replaced more ussages of AnnotatedFactory by ConfigAbstractFactory
This commit is contained in:
parent
54cb40f6ed
commit
6300982b07
@ -1,9 +1,13 @@
|
||||
<?php
|
||||
use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Shlinkio\Shlink\Common\Service\PreviewGenerator;
|
||||
use Shlinkio\Shlink\Core\Action;
|
||||
use Shlinkio\Shlink\Core\Middleware;
|
||||
use Shlinkio\Shlink\Core\Options;
|
||||
use Shlinkio\Shlink\Core\Service;
|
||||
use Zend\Expressive\Router\RouterInterface;
|
||||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||
|
||||
return [
|
||||
|
||||
@ -12,18 +16,33 @@ return [
|
||||
Options\AppOptions::class => 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],
|
||||
],
|
||||
|
||||
];
|
||||
|
@ -1,16 +1,13 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Action;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Shlinkio\Shlink\Common\Service\PreviewGenerator;
|
||||
use Shlinkio\Shlink\Common\Service\PreviewGeneratorInterface;
|
||||
use Shlinkio\Shlink\Common\Util\ResponseUtilsTrait;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortener;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
|
||||
|
||||
class PreviewAction implements MiddlewareInterface
|
||||
@ -26,13 +23,6 @@ class PreviewAction implements MiddlewareInterface
|
||||
*/
|
||||
private $urlShortener;
|
||||
|
||||
/**
|
||||
* PreviewAction constructor.
|
||||
* @param PreviewGeneratorInterface $previewGenerator
|
||||
* @param UrlShortenerInterface $urlShortener
|
||||
*
|
||||
* @Inject({PreviewGenerator::class, UrlShortener::class})
|
||||
*/
|
||||
public function __construct(PreviewGeneratorInterface $previewGenerator, UrlShortenerInterface $urlShortener)
|
||||
{
|
||||
$this->previewGenerator = $previewGenerator;
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Action;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface;
|
||||
@ -11,7 +10,6 @@ use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Shlinkio\Shlink\Common\Response\QrCodeResponse;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortener;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
|
||||
use Zend\Expressive\Router\RouterInterface;
|
||||
|
||||
@ -30,14 +28,6 @@ class QrCodeAction implements MiddlewareInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* QrCodeAction constructor.
|
||||
* @param RouterInterface $router
|
||||
* @param UrlShortenerInterface $urlShortener
|
||||
* @param LoggerInterface $logger
|
||||
*
|
||||
* @Inject({RouterInterface::class, UrlShortener::class, "Logger_Shlink"})
|
||||
*/
|
||||
public function __construct(
|
||||
RouterInterface $router,
|
||||
UrlShortenerInterface $urlShortener,
|
||||
|
@ -1,16 +1,13 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Action;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortener;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
|
||||
use Shlinkio\Shlink\Core\Service\VisitsTracker;
|
||||
use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface;
|
||||
use Zend\Diactoros\Response\RedirectResponse;
|
||||
|
||||
@ -29,14 +26,6 @@ class RedirectAction implements MiddlewareInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* RedirectMiddleware constructor.
|
||||
* @param UrlShortenerInterface $urlShortener
|
||||
* @param VisitsTrackerInterface $visitTracker
|
||||
* @param LoggerInterface|null $logger
|
||||
*
|
||||
* @Inject({UrlShortener::class, VisitsTracker::class, "Logger_Shlink"})
|
||||
*/
|
||||
public function __construct(
|
||||
UrlShortenerInterface $urlShortener,
|
||||
VisitsTrackerInterface $visitTracker,
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Middleware;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface;
|
||||
@ -16,12 +15,6 @@ class QrCodeCacheMiddleware implements MiddlewareInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* QrCodeCacheMiddleware constructor.
|
||||
* @param Cache $cache
|
||||
*
|
||||
* @Inject({Cache::class})
|
||||
*/
|
||||
public function __construct(Cache $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Shlinkio\Shlink\Common\Paginator\Adapter\PaginableRepositoryAdapter;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
@ -19,12 +18,6 @@ class ShortUrlService implements ShortUrlServiceInterface
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* ShortUrlService constructor.
|
||||
* @param EntityManagerInterface $em
|
||||
*
|
||||
* @Inject({"em"})
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Service\Tag;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation as DI;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
@ -18,12 +17,6 @@ class TagService implements TagServiceInterface
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* VisitService constructor.
|
||||
* @param EntityManagerInterface $em
|
||||
*
|
||||
* @DI\Inject({"em"})
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\ORMException;
|
||||
@ -37,15 +36,6 @@ class UrlShortener implements UrlShortenerInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* UrlShortener constructor.
|
||||
* @param ClientInterface $httpClient
|
||||
* @param EntityManagerInterface $em
|
||||
* @param Cache $cache
|
||||
* @param string $chars
|
||||
*
|
||||
* @Inject({"httpClient", "em", Cache::class, "config.url_shortener.shortcode_chars"})
|
||||
*/
|
||||
public function __construct(
|
||||
ClientInterface $httpClient,
|
||||
EntityManagerInterface $em,
|
||||
@ -112,7 +102,7 @@ class UrlShortener implements UrlShortenerInterface
|
||||
* Tries to perform a GET request to provided url, returning true on success and false on failure
|
||||
*
|
||||
* @param UriInterface $url
|
||||
* @return bool
|
||||
* @return void
|
||||
*/
|
||||
protected function checkUrlExists(UriInterface $url)
|
||||
{
|
||||
@ -133,17 +123,17 @@ class UrlShortener implements UrlShortenerInterface
|
||||
*/
|
||||
protected function convertAutoincrementIdToShortCode($id)
|
||||
{
|
||||
$id = intval($id) + 200000; // Increment the Id so that the generated shortcode is not too short
|
||||
$id = ((int) $id) + 200000; // Increment the Id so that the generated shortcode is not too short
|
||||
$length = strlen($this->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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
||||
@ -13,12 +12,6 @@ class VisitService implements VisitServiceInterface
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* VisitService constructor.
|
||||
* @param EntityManagerInterface $em
|
||||
*
|
||||
* @Inject({"em"})
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
@ -17,12 +16,6 @@ class VisitsTracker implements VisitsTrackerInterface
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* VisitsTracker constructor.
|
||||
* @param EntityManagerInterface $em
|
||||
*
|
||||
* @Inject({"em"})
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
Loading…
Reference in New Issue
Block a user