diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c563bc2..0000000 --- a/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# IDE -.idea - -# Binary -bin - -# Dependency -vendor - -# Lock -composer.lock diff --git a/Controller/EncodeController.php b/Controller/EncodeController.php index bf7e48c..3beb968 100644 --- a/Controller/EncodeController.php +++ b/Controller/EncodeController.php @@ -2,16 +2,21 @@ namespace Leopardd\Bundle\UrlShortenerBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; use Leopardd\Bundle\UrlShortenerBundle\Factory\ShortUrlFactory; use Leopardd\Bundle\UrlShortenerBundle\Service\EncodeService; use Leopardd\Bundle\UrlShortenerBundle\Exception\InvalidUrlException; -class EncodeController extends Controller +class EncodeController extends AbstractController { + + public function __construct(private ShortUrlFactory $shortUrlFactory,private EncodeService $encodeService) + { + + } /** * @param Request $request * @throws InvalidUrlException @@ -19,11 +24,6 @@ class EncodeController extends Controller */ public function indexAction(Request $request) { - /** @var ShortUrlFactory $shortUrlFactory */ - $shortUrlFactory = $this->get('leopardd_url_shortener.factory.short_url'); - - /** @var EncodeService $encodeService */ - $encodeService = $this->get('leopardd_url_shortener.service.encode'); $url = $request->request->get('url'); @@ -31,12 +31,12 @@ public function indexAction(Request $request) if (filter_var($url, FILTER_VALIDATE_URL) === false) throw new InvalidUrlException(); $url = rtrim($url, '/'); - $shortUrl = $shortUrlFactory->create($url); - $shortUrl = $encodeService->process($shortUrl); + $shortUrl = $this->shortUrlFactory->create($url); + $shortUrl = $this->encodeService->process($shortUrl); return new JsonResponse([ 'url' => $shortUrl->getUrl(), 'code' => $shortUrl->getCode() ]); } -} +} \ No newline at end of file diff --git a/Controller/RedirectController.php b/Controller/RedirectController.php index 22e861a..eedf97f 100644 --- a/Controller/RedirectController.php +++ b/Controller/RedirectController.php @@ -2,13 +2,18 @@ namespace Leopardd\Bundle\UrlShortenerBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; use Leopardd\Bundle\UrlShortenerBundle\Service\RedirectService; use Leopardd\Bundle\UrlShortenerBundle\Exception\InvalidCodeException; -class RedirectController extends Controller +class RedirectController extends AbstractController { + + public function __construct(private RedirectService $redirectService) + { + + } /** * @param string $code * @throws InvalidCodeException @@ -16,12 +21,10 @@ class RedirectController extends Controller */ public function indexAction($code) { - /** @var RedirectService $redirectService */ - $redirectService = $this->get('leopardd_url_shortener.service.redirect'); - $response = $redirectService->getRedirectResponse($code); + $response = $this->redirectService->getRedirectResponse($code); if ($response === null) throw new InvalidCodeException(); return $response; } -} +} \ No newline at end of file diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 80ec0a9..3eb5b96 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -17,9 +17,8 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('leopardd_url_shortener'); - + $builder = new TreeBuilder('leopardd_url_shortener'); + $rootNode = $builder->getRootNode(); // Here you should define the parameters that are allowed to // configure your bundle. See the documentation linked above for // more information on that topic. @@ -34,6 +33,7 @@ public function getConfigTreeBuilder() ->end() ->end(); - return $treeBuilder; + + return $builder; } -} +} \ No newline at end of file diff --git a/DependencyInjection/LeoparddUrlShortenerExtension.php b/DependencyInjection/LeoparddUrlShortenerExtension.php index 5bdb9db..d9994d9 100644 --- a/DependencyInjection/LeoparddUrlShortenerExtension.php +++ b/DependencyInjection/LeoparddUrlShortenerExtension.php @@ -14,30 +14,30 @@ */ class LeoparddUrlShortenerExtension extends Extension { - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) - { - $configuration = new Configuration(); - $config = $this->processConfiguration($configuration, $configs); + /** + * {@inheritdoc} + */ + public function load(array $configs, ContainerBuilder $container) + { + $configuration = new Configuration(); + $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('services.yml'); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('services.yml'); - // Hashids Config - if (isset($config['hashids'])) { - if (isset($config['hashids']['salt'])) { - $container->setParameter('leopardd_url_shortener.hashids.salt', $config['hashids']['salt']); - } + // Hashids Config + if (isset($config['hashids'])) { + if (isset($config['hashids']['salt'])) { + $container->setParameter('leopardd_url_shortener.hashids.salt', $config['hashids']['salt']); + } - if (isset($config['hashids']['min_length'])) { - $container->setParameter('leopardd_url_shortener.hashids.min_length', $config['hashids']['min_length']); - } + if (isset($config['hashids']['min_length'])) { + $container->setParameter('leopardd_url_shortener.hashids.min_length', $config['hashids']['min_length']); + } - if (isset($config['hashids']['alphabet'])) { - $container->setParameter('leopardd_url_shortener.hashids.alphabet', $config['hashids']['alphabet']); - } - } - } -} + if (isset($config['hashids']['alphabet'])) { + $container->setParameter('leopardd_url_shortener.hashids.alphabet', $config['hashids']['alphabet']); + } + } + } +} \ No newline at end of file diff --git a/Entity/ShortUrl.php b/Entity/ShortUrl.php index 32e0d58..e954ede 100644 --- a/Entity/ShortUrl.php +++ b/Entity/ShortUrl.php @@ -11,115 +11,116 @@ * Class ShortUrl * @package Leopardd\Bundle\UrlShortenerBundle\Entity * @ORM\Entity(repositoryClass="Leopardd\Bundle\UrlShortenerBundle\Repository\ShortUrlRepository") - * @ORM\Table(name="short_url", indexes={@ORM\Index(name="idx", columns={"id", "url"})}) + * @ORM\Table(name="short_url", indexes={@ORM\Index(name="idx", columns={"id", "url"}, options={"lengths": { null , 255 } })}) */ class ShortUrl implements ShortUrlInterface { - /** - * @var int - * @ORM\Id - * @ORM\Column(name="id", type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - * @JMS\Expose() - */ - protected $id; - - /** - * @var string - * @Assert\NotBlank(message="The code should not be blank") - * @ORM\Column(name="code", type="string", unique=true, nullable=true, options={"collation":"utf8_bin"}) - * @JMS\Expose() - */ - protected $code; - - /** - * @var string - * @Assert\NotBlank(message="The url should not be blank") - * @Assert\Length( - * max = 255, - * maxMessage = "The url cannot be longer than {{ limit }} characters" - * ) - * @ORM\Column(name="url", type="string", length=255) - * @JMS\Expose() - */ - protected $url; - - /** - * @var DateTime - * @ORM\Column(name="created", type="datetime") - * @JMS\Type("DateTime<'Y-m-d H:i:s', 'UTC'>") - * @JMS\Expose() - */ - private $created; - - /** - * ShortUrl constructor. - */ - public function __construct() - { - $this->created = new DateTime(); - } - - /** - * {@inheritdoc} - */ - public function getId() - { - return $this->id; - } - - /** - * {@inheritdoc} - */ - public function getCode() - { - return $this->code; - } - - /** - * {@inheritdoc} - */ - public function setCode($code) - { - $this->code = $code; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getUrl() - { - return $this->url; - } - - /** - * {@inheritdoc} - */ - public function setUrl($url) - { - $this->url = $url; - - return $this; - } - - /** - * @return DateTime - */ - public function getCreated() - { - return $this->created; - } - - /** - * @param DateTime $created - * @return ShortUrl - */ - public function setCreated($created) - { - $this->created = $created; - - return $this; - } -} + /** + * @var int + * @ORM\Id + * @ORM\Column(name="id", type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + * @JMS\Expose() + */ + protected $id; + + /** + * @var string + * @Assert\NotBlank(message="The code should not be blank") + * @ORM\Column(name="code", type="string", unique=true, nullable=true, options={"collation":"utf8_bin"}) + * @JMS\Expose() + */ + protected $code; + + /** + * @var string + * @Assert\NotBlank(message="The url should not be blank") + * @Assert\Length( + * max = 2000, + * maxMessage = "The url cannot be longer than {{ limit }} characters" + * ) + * @ORM\Column(name="url", type="text", length=2000) + * @JMS\Expose() + */ + protected $url; + + + /** + * @var DateTime + * @ORM\Column(name="created", type="datetime") + * @JMS\Type("DateTime<'Y-m-d H:i:s', 'UTC'>") + * @JMS\Expose() + */ + private $created; + + /** + * ShortUrl constructor. + */ + public function __construct() + { + $this->created = new DateTime(); + } + + /** + * {@inheritdoc} + */ + public function getId() + { + return $this->id; + } + + /** + * {@inheritdoc} + */ + public function getCode() + { + return $this->code; + } + + /** + * {@inheritdoc} + */ + public function setCode($code) + { + $this->code = $code; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getUrl() + { + return $this->url; + } + + /** + * {@inheritdoc} + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * @return DateTime + */ + public function getCreated() + { + return $this->created; + } + + /** + * @param DateTime $created + * @return ShortUrl + */ + public function setCreated($created) + { + $this->created = $created; + + return $this; + } +} \ No newline at end of file diff --git a/Event/ShortUrlCreatedEvent.php b/Event/ShortUrlCreatedEvent.php index 315b926..046533f 100644 --- a/Event/ShortUrlCreatedEvent.php +++ b/Event/ShortUrlCreatedEvent.php @@ -2,8 +2,8 @@ namespace Leopardd\Bundle\UrlShortenerBundle\Event; -use Symfony\Component\EventDispatcher\Event; use Leopardd\Bundle\UrlShortenerBundle\Entity\ShortUrlInterface; +use Symfony\Contracts\EventDispatcher\Event; /** * Class ShortUrlCreatedEvent @@ -30,4 +30,4 @@ public function getShortUrl() { return $this->shortUrl; } -} +} \ No newline at end of file diff --git a/Event/ShortUrlRedirectedEvent.php b/Event/ShortUrlRedirectedEvent.php index 4d59795..27798b7 100644 --- a/Event/ShortUrlRedirectedEvent.php +++ b/Event/ShortUrlRedirectedEvent.php @@ -2,8 +2,8 @@ namespace Leopardd\Bundle\UrlShortenerBundle\Event; -use Symfony\Component\EventDispatcher\Event; use Leopardd\Bundle\UrlShortenerBundle\Entity\ShortUrlInterface; +use Symfony\Contracts\EventDispatcher\Event; /** * Class ShortUrlRedirectedEvent @@ -30,4 +30,4 @@ public function getShortUrl() { return $this->shortUrl; } -} +} \ No newline at end of file diff --git a/Factory/ShortUrlFactory.php b/Factory/ShortUrlFactory.php index b601c82..9ab07a0 100644 --- a/Factory/ShortUrlFactory.php +++ b/Factory/ShortUrlFactory.php @@ -17,7 +17,7 @@ class ShortUrlFactory implements ShortUrlFactoryInterface * ShortUrlFactory constructor. * @param string $shortUrl shortUrl class */ - public function __construct($shortUrl) + public function __construct(string $shortUrl) { $this->shortUrl = new $shortUrl(); } @@ -31,4 +31,4 @@ public function create($url) return $this->shortUrl; } -} +} \ No newline at end of file diff --git a/Factory/ShortUrlFactoryInterface.php b/Factory/ShortUrlFactoryInterface.php index 6e89782..40032c0 100644 --- a/Factory/ShortUrlFactoryInterface.php +++ b/Factory/ShortUrlFactoryInterface.php @@ -4,6 +4,8 @@ use Leopardd\Bundle\UrlShortenerBundle\Entity\ShortUrlInterface; +// ok + /** * Interface ShortUrlFactoryInterface * @package Leopardd\Bundle\UrlShortenerBundle\Factory @@ -16,4 +18,4 @@ interface ShortUrlFactoryInterface * @return ShortUrlInterface */ public function create($url); -} +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a417b73 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Leopardd + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index c144c37..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -# The MIT License (MIT) - -Copyright (c) 2017 Nathachai Thongniran - -> Permission is hereby granted, free of charge, to any person obtaining a copy -> of this software and associated documentation files (the "Software"), to deal -> in the Software without restriction, including without limitation the rights -> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -> copies of the Software, and to permit persons to whom the Software is -> furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in -> all copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -> THE SOFTWARE. diff --git a/LeoparddUrlShortenerBundle.php b/LeoparddUrlShortenerBundle.php index ffe83d4..d38fb48 100644 --- a/LeoparddUrlShortenerBundle.php +++ b/LeoparddUrlShortenerBundle.php @@ -6,4 +6,4 @@ class LeoparddUrlShortenerBundle extends Bundle { -} +} \ No newline at end of file diff --git a/Repository/ShortUrlRepositoryInterface.php b/Repository/ShortUrlRepositoryInterface.php index 0b34109..f917e30 100644 --- a/Repository/ShortUrlRepositoryInterface.php +++ b/Repository/ShortUrlRepositoryInterface.php @@ -2,6 +2,8 @@ namespace Leopardd\Bundle\UrlShortenerBundle\Repository; +// ok + use Leopardd\Bundle\UrlShortenerBundle\Entity\ShortUrlInterface; /** @@ -27,4 +29,4 @@ public function findOneByUrl($url); * @return ShortUrlInterface */ public function save(ShortUrlInterface $shortUrl); -} +} \ No newline at end of file diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 73f82c2..5041886 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,11 +1,12 @@ leopardd_url_shortener_redirect: path: /{code} - defaults: { _controller: LeoparddUrlShortenerBundle:Redirect:index } + controller: Leopardd\Bundle\UrlShortenerBundle\Controller\RedirectController::indexAction methods: GET requirements: code: \S+ + leopardd_url_shortener_encode: path: / - defaults: { _controller: LeoparddUrlShortenerBundle:Encode:index } - methods: POST + controller: Leopardd\Bundle\UrlShortenerBundle\Controller\EncodeController::indexAction + methods: POST \ No newline at end of file diff --git a/Resources/config/services.yml b/Resources/config/services.yml index c326346..71585af 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -7,6 +7,22 @@ parameters: leopardd_url_shortener.class.repository: Leopardd\Bundle\UrlShortenerBundle\Repository\ShortUrlRepository services: + + Leopardd\Bundle\UrlShortenerBundle\Factory\ShortUrlFactory: '@leopardd_url_shortener.factory.short_url' + Hashids\Hashids: '@leopardd_url_shortener.hash.hashid' + Leopardd\Bundle\UrlShortenerBundle\Repository\ShortUrlRepositoryInterface: '@leopardd_url_shortener.repository.short_url' + Leopardd\Bundle\UrlShortenerBundle\Service\EncodeService: '@leopardd_url_shortener.service.encode' + Leopardd\Bundle\UrlShortenerBundle\Service\RedirectService: '@leopardd_url_shortener.service.redirect' + + + Leopardd\Bundle\UrlShortenerBundle\Controller\: + resource: '../../Controller/' + autowire: true # Automatically injects dependencies in your services. + autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + public: false + tags: ['controller.service_arguments'] + + leopardd_url_shortener.hash.hashid: class: Hashids\Hashids arguments: @@ -21,7 +37,7 @@ services: leopardd_url_shortener.repository.short_url: class: "%leopardd_url_shortener.class.repository%" - factory: 'doctrine.orm.entity_manager:getRepository' + factory: [ '@doctrine.orm.entity_manager' , getRepository ] arguments: - "%leopardd_url_shortener.class.entity%" @@ -31,10 +47,11 @@ services: - "@leopardd_url_shortener.hash.hashid" - "@leopardd_url_shortener.repository.short_url" - "@event_dispatcher" - + - "@router" +# leopardd_url_shortener.service.redirect: class: Leopardd\Bundle\UrlShortenerBundle\Service\RedirectService arguments: - "@leopardd_url_shortener.hash.hashid" - "@leopardd_url_shortener.repository.short_url" - - "@event_dispatcher" + - "@event_dispatcher" \ No newline at end of file diff --git a/Service/EncodeService.php b/Service/EncodeService.php index 6f5557b..5f3cd85 100644 --- a/Service/EncodeService.php +++ b/Service/EncodeService.php @@ -8,6 +8,7 @@ use Leopardd\Bundle\UrlShortenerBundle\Repository\ShortUrlRepositoryInterface; use Leopardd\Bundle\UrlShortenerBundle\Event\ShortUrlEvent; use Leopardd\Bundle\UrlShortenerBundle\Event\ShortUrlCreatedEvent; +use Symfony\Component\Routing\RouterInterface; /** * Class EncodeService @@ -15,14 +16,6 @@ */ class EncodeService { - /** @var Hashids */ - private $hashids; - - /** @var ShortUrlRepositoryInterface */ - private $shortUrlRepository; - - /** @var EventDispatcherInterface */ - private $dispatcher; /** * ProcessShortUrlService constructor. @@ -30,13 +23,18 @@ class EncodeService * @param ShortUrlRepositoryInterface $shortUrlRepository * @param EventDispatcherInterface $dispatcher */ - public function __construct($hashids, $shortUrlRepository, $dispatcher) + public function __construct(private Hashids $hashids, private ShortUrlRepositoryInterface $shortUrlRepository, private EventDispatcherInterface $dispatcher,private RouterInterface $router) { - $this->hashids = $hashids; - $this->shortUrlRepository = $shortUrlRepository; - $this->dispatcher = $dispatcher; + } + + public function getShortUrl($shortUrl,$referenceType = RouterInterface::ABSOLUTE_URL) // absolute url + { + + return $this->router->generate('leopardd_url_shortener_redirect',['code' => $shortUrl->getCode() ] , $referenceType) ; + + } /** * @param ShortUrlInterface $shortUrl * @return ShortUrlInterface @@ -55,8 +53,8 @@ public function process($shortUrl) $shortUrl = $this->shortUrlRepository->save($shortUrl); $event = new ShortUrlCreatedEvent($shortUrl); - $this->dispatcher->dispatch(ShortUrlEvent::SHORT_URL_CREATED, $event); + $this->dispatcher->dispatch($event,ShortUrlEvent::SHORT_URL_CREATED); return $shortUrl; } -} +} \ No newline at end of file diff --git a/Service/RedirectService.php b/Service/RedirectService.php index 6cde606..37cf650 100644 --- a/Service/RedirectService.php +++ b/Service/RedirectService.php @@ -16,14 +16,6 @@ */ class RedirectService { - /** @var Hashids */ - private $hashids; - - /** @var ShortUrlRepositoryInterface $repository */ - private $shortUrlRepository; - - /** @var EventDispatcherInterface $dispatcher */ - private $dispatcher; /** * ProcessShortUrlService constructor. @@ -31,11 +23,9 @@ class RedirectService * @param ShortUrlRepositoryInterface $shortUrlRepository * @param EventDispatcherInterface $dispatcher */ - public function __construct($hashids, $shortUrlRepository, $dispatcher) + public function __construct(private Hashids $hashids, private ShortUrlRepositoryInterface $shortUrlRepository, private EventDispatcherInterface $dispatcher) { - $this->hashids = $hashids; - $this->shortUrlRepository = $shortUrlRepository; - $this->dispatcher = $dispatcher; + } /** @@ -53,8 +43,8 @@ public function getRedirectResponse($code) if (!$shortUrl) return null; $event = new ShortUrlRedirectedEvent($shortUrl); - $this->dispatcher->dispatch(ShortUrlEvent::SHORT_URL_REDIRECTED, $event); + $this->dispatcher->dispatch($event,ShortUrlEvent::SHORT_URL_REDIRECTED); return new RedirectResponse($shortUrl->getUrl()); } -} +} \ No newline at end of file diff --git a/composer.json b/composer.json index e815d10..cc8faf8 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,9 @@ { "name": "leopardd/url-shortener-bundle", - "description": "Symfony Bundle to generate and redirect short url", + "description": "Symfony Bundle to generate and redirect short url working with symfony 5 and php 8", + "version": "dev-master", "type": "symfony-bundle", + "minimum-stability": "stable", "license": "MIT", "keywords": [ "url", @@ -18,15 +20,21 @@ "email": "inid3a@gmail.com", "homepage": "https://github.com/jojoee", "role": "Developer" + }, + { + "name": "David Nurdin", + "email": "david.nurdin@respawnsive.com", + "homepage": "https://github.com/davidnurdin", + "role": "Developer" } ], "require": { - "php": "~5.6|~7.0", - "symfony/framework-bundle": "~2.6|~3.0", + "php": "~8.0", + "symfony/framework-bundle": "~5.3", "doctrine/orm": "^2.5", - "doctrine/doctrine-bundle": "^1.6", - "hashids/hashids": "^2.0", - "jms/serializer-bundle": "^1.3" + "doctrine/doctrine-bundle": "^2.4", + "hashids/hashids": "^4.1.0", + "jms/serializer-bundle": "^3.0.0" }, "require-dev": { "phpspec/phpspec": "^3.1", @@ -47,4 +55,4 @@ "config": { "bin-dir": "bin" } -} +} \ No newline at end of file diff --git a/phpspec.yml b/phpspec.yml deleted file mode 100644 index 62d08f0..0000000 --- a/phpspec.yml +++ /dev/null @@ -1,4 +0,0 @@ -suites: - acme_suite: - namespace: Leopardd\Bundle\UrlShortenerBundle - psr4_prefix: Leopardd\Bundle\UrlShortenerBundle diff --git a/ruleset.xml b/ruleset.xml deleted file mode 100644 index 473ccfa..0000000 --- a/ruleset.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/spec/Service/EncodeServiceSpec.php b/spec/Service/EncodeServiceSpec.php deleted file mode 100644 index 93a74e6..0000000 --- a/spec/Service/EncodeServiceSpec.php +++ /dev/null @@ -1,84 +0,0 @@ -beConstructedWith($hashids, $shortUrlRepository, $dispatcher); - } - - function it_is_initializable() - { - $this->shouldHaveType(EncodeService::class); - } - - function it_process_existent_url( - ShortUrlInterface $shortUrl, - ShortUrlInterface $existentShortUrl, - ShortUrlRepositoryInterface $shortUrlRepository - ) { - $url = 'https://www.google.com'; - - $shortUrl->getUrl() - ->shouldBeCalled() - ->willReturn($url); - $shortUrlRepository->findOneByUrl($url) - ->shouldBeCalled() - ->willReturn($existentShortUrl); - - $this->process($shortUrl)->shouldReturn($existentShortUrl); - } - - function it_process( - EventDispatcherInterface $dispatcher, - Hashids $hashids, - ShortUrlInterface $shortUrl, - ShortUrlRepositoryInterface $shortUrlRepository - ) { - $id = 8; - $url = 'https://www.google.com'; - $code = 'abc'; - - $shortUrl->getUrl() - ->shouldBeCalled() - ->willReturn($url); - $shortUrlRepository->findOneByUrl($url) - ->shouldBeCalled() - ->willReturn(null); - $shortUrlRepository->save($shortUrl) - ->shouldBeCalledTimes(2) - ->willReturn($shortUrl); - $shortUrl->getId() - ->shouldBeCalled() - ->willReturn($id); - $hashids->encode($id) - ->willReturn($code); - $shortUrl->setCode($code) - ->shouldBeCalled(); - - $event = new ShortUrlCreatedEvent($shortUrl->getWrappedObject()); - $dispatcher->dispatch(ShortUrlEvent::SHORT_URL_CREATED, $event) - ->shouldBeCalled(); - - $this->process($shortUrl)->shouldReturn($shortUrl); - } -} diff --git a/spec/Service/RedirectServiceSpec.php b/spec/Service/RedirectServiceSpec.php deleted file mode 100644 index 8a91a72..0000000 --- a/spec/Service/RedirectServiceSpec.php +++ /dev/null @@ -1,93 +0,0 @@ -beConstructedWith($hashids, $shortUrlRepository, $dispatcher); - } - - function it_is_initializable() - { - $this->shouldHaveType(RedirectService::class); - } - - function it_get_redirect_response_by_invalid_code( - Hashids $hashids - ) { - $id = 'not numeric'; - $code = 'abc'; - - $hashids->decode($code) - ->shouldBeCalled() - ->willReturn($id); - - $this->shouldThrow(InvalidCodeException::class)->duringGetRedirectResponse($code); - } - - function it_get_redirect_response_by_nonexistent_code( - Hashids $hashids, - ShortUrlRepositoryInterface $shortUrlRepository - ) { - $ids = [8]; - $id = $ids[0]; - $code = 'abc'; - - $hashids->decode($code) - ->shouldBeCalled() - ->willReturn($ids); - $shortUrlRepository->findOneById($id) - ->shouldBeCalled() - ->willReturn(null); - - $this->getRedirectResponse($code)->shouldReturn(null); - } - - function it_get_redirect_response( - EventDispatcherInterface $dispatcher, - Hashids $hashids, - ShortUrlInterface $shortUrl, - ShortUrlRepositoryInterface $shortUrlRepository - ) { - $ids = [8]; - $id = $ids[0]; - $url = 'https://www.google.com'; - $code = 'abc'; - $redirectResponse = new RedirectResponse($url); - - $hashids->decode($code) - ->shouldBeCalled() - ->willReturn($ids); - $shortUrlRepository->findOneById($id) - ->shouldBeCalled() - ->willReturn($shortUrl); - $dispatcher->dispatch(ShortUrlEvent::SHORT_URL_REDIRECTED, Argument::type(ShortUrlRedirectedEvent::class)) - ->shouldBeCalled(); - $shortUrl->getUrl() - ->shouldBeCalled() - ->willReturn($url); - - $this->getRedirectResponse($code)->shouldBeLike($redirectResponse); - } -}