Skip to content

Commit

Permalink
🚑 Terminado
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo Montivero committed Dec 7, 2023
1 parent 5912070 commit 0db8766
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
$site_temporal: '%site_temporal%'
$site_podcasts: '%env(resolve:URL_PODCAST)%'
$queue_enable: '%queue_enable%'
$publicDir: '%kernel.project_dir%/public'

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand Down
26 changes: 23 additions & 3 deletions src/Twig/BaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use InvalidArgumentException;
use Psr\Container\ContainerInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
Expand All @@ -17,16 +18,20 @@ class BaseExtension extends AbstractExtension implements ServiceSubscriberInterf
{
protected $em;
private $container;
private string $publicDir;

/**
* BaseExtension constructor.
* @param EntityManagerInterface $em
* @param ContainerInterface $container
* @param string $publicDir
*/
public function __construct(EntityManagerInterface $em, ContainerInterface $container)
public function __construct(
EntityManagerInterface $em, ContainerInterface $container, string $publicDir)
{
$this->em = $em;
$this->container = $container;
$this->publicDir = $publicDir;
}

public function getFilters(): array
Expand All @@ -49,13 +54,14 @@ public function getFunctions(): array
new TwigFunction('capacidad_restante', [$this, 'capacidad_restante']),
new TwigFunction('capacidad_ocupada', [$this, 'capacidad_ocupada']),
new TwigFunction('redirection', [$this, 'redirection']),
new TwigFunction('encore_entry_css_source', [$this, 'getEncoreEntryCssSource']),
];
}

public function lema()
{
$lema = $this->em->getRepository(MetaBase::class)->findOneBy([]);
if(!$lema){
if (!$lema) {
return null;
}
return $lema->getLema();
Expand All @@ -65,7 +71,7 @@ public function metaDescripcion()
{
$base = $this->em->getRepository(MetaBase::class)->findOneBy([]);

if(!$base){
if (!$base) {
return null;
}

Expand Down Expand Up @@ -103,6 +109,7 @@ public static function getSubscribedServices()
return [
UploaderHelper::class,
EntityManagerInterface::class,
EntrypointLookupInterface::class
];
}

Expand All @@ -115,4 +122,17 @@ public function redirection(string $link)
echo "<meta http-equiv = 'refresh' content='0;url = $link' />";

}

public function getEncoreEntryCssSource(string $entryName): string
{
$entryPointLookupInterface = $this->container->get(EntrypointLookupInterface::class);
$entryPointLookupInterface->reset();
$files = $entryPointLookupInterface->getCssFiles($entryName);
$source = '';
foreach ($files as $file) {
$source .= file_get_contents($this->publicDir . $file);
}

return $source;
}
}

0 comments on commit 0db8766

Please sign in to comment.