From: Raphaƫl Gertz Date: Mon, 3 Oct 2022 03:05:12 +0000 (+0200) Subject: Drop useless url X-Git-Tag: 0.2.1~7 X-Git-Url: https://git.rapsys.eu/packbundle/commitdiff_plain/17218a9f78d87562272e141d6d16597a2d5866e9?hp=813df402ddf427f38d429737b03798884ee35a04 Drop useless url Replace package usage with route Cleanup --- diff --git a/Util/FacebookUtil.php b/Util/FacebookUtil.php index ea3393d..e2c891c 100644 --- a/Util/FacebookUtil.php +++ b/Util/FacebookUtil.php @@ -11,9 +11,10 @@ namespace Rapsys\PackBundle\Util; -use Symfony\Component\Asset\PackageInterface; use Symfony\Component\Filesystem\Exception\IOExceptionInterface; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\RouterInterface; /** * Helps manage facebook images @@ -41,25 +42,16 @@ class FacebookUtil { protected $path; /** - * The public url + * The prefix * * @var string */ - protected $url; + protected $prefix; /** - * The package instance - * - * @var PackageInterface + * The RouterInterface instance */ - protected $package; - - /** - * The prefix - * - * @var string - */ - protected $prefix; + protected RouterInterface $router; /** * The source @@ -69,15 +61,14 @@ class FacebookUtil { protected $source; /** - * Creates a new osm util + * Creates a new facebook util * - * @param PackageInterface $package The package instance + * @param RouterInterface $router The RouterInterface instance * @param string $cache The cache directory * @param string $path The public path - * @param string $url The public url * @param string $prefix The prefix */ - function __construct(PackageInterface $package, string $cache, string $path, string $url, string $prefix = 'facebook', string $source = 'png/facebook.png', array $fonts = [ 'default' => 'ttf/default.ttf' ]) { + function __construct(RouterInterface $router, string $cache = '../var/cache', string $path = './bundles/rapsyspack', string $prefix = 'facebook', string $source = 'png/facebook.png', array $fonts = [ 'default' => 'ttf/default.ttf' ]) { //Set cache $this->cache = $cache.'/'.$prefix; @@ -87,11 +78,8 @@ class FacebookUtil { //Set path $this->path = $path.'/'.$prefix; - //Set url - $this->url = $url.'/'.$prefix; - - //Set package instance - $this->package = $package; + //Set router + $this->router = $router; //Set prefix key $this->prefix = $prefix; @@ -138,8 +126,7 @@ class FacebookUtil { //Return image data return [ - #'og:image' => $this->package->getAbsoluteUrl('@RapsysAir/facebook/'.$mtime.$pathInfo.'.jpeg'), - 'og:image' => $this->package->getAbsoluteUrl($this->url.'/'.$mtime.$pathInfo.'.jpeg'), + 'og:image' => $this->router->generate('rapsys_pack_facebook', ['mtime' => $mtime, 'path' => $pathInfo], UrlGeneratorInterface::ABSOLUTE_URL), 'og:image:alt' => str_replace("\n", ' ', implode(' - ', array_keys($texts))), 'og:image:height' => $height, 'og:image:width' => $width @@ -379,7 +366,7 @@ class FacebookUtil { //Return image data return [ - 'og:image' => $this->package->getAbsoluteUrl($this->url.'/'.stat($path)['mtime'].$pathInfo.'.jpeg'), + 'og:image' => $this->router->generate('rapsys_pack_facebook', ['mtime' => stat($path)['mtime'], 'path' => $pathInfo], UrlGeneratorInterface::ABSOLUTE_URL), 'og:image:alt' => str_replace("\n", ' ', implode(' - ', array_keys($texts))), 'og:image:height' => $height, 'og:image:width' => $width