![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/CoreBundle/Shortener/ |
<?php declare(strict_types=1); namespace Mautic\CoreBundle\Shortener; use Mautic\CoreBundle\Helper\CoreParametersHelper; class Shortener { public const SHORTENER_SERVICE = 'shortener_service'; /** * @var ShortenerServiceInterface[] */ private array $services = []; public function __construct( private CoreParametersHelper $coreParametersHelper ) { } public function addService(ShortenerServiceInterface $shortener): void { $this->services[$shortener::class] = $shortener; } public function getService(): ShortenerServiceInterface { $name = $this->coreParametersHelper->get(self::SHORTENER_SERVICE); if (isset($this->services[$name])) { return $this->services[$name]; } throw new \InvalidArgumentException(sprintf('There is not a shortener service %s', $name)); } /** * @return ShortenerServiceInterface[] */ public function getServices(): array { return $this->services; } /** * @return ShortenerServiceInterface[] */ public function getEnabledServices(): array { return array_filter($this->services, fn ($service) => $service->isEnabled()); } public function shortenUrl(string $url): string { try { return $this->getService()->shortenUrl($url); } catch (\InvalidArgumentException) { return $url; } } }