浏览代码

Refactoring frontend

develop
Guillaume 3 年前
父节点
当前提交
6dfacd908f
共有 5 个文件被更改,包括 91 次插入5 次删除
  1. +1
    -1
      Model/File/FileModel.php
  2. +5
    -0
      Repository/AbstractRepositoryQuery.php
  3. +13
    -3
      Repository/AbstractStore.php
  4. +58
    -0
      Twig/MetaTwigExtension.php
  5. +14
    -1
      Twig/TwigExtension.php

+ 1
- 1
Model/File/FileModel.php 查看文件

@@ -39,7 +39,7 @@ abstract class FileModel implements SortableInterface, BlameableInterface, Times


public function __toString(){
return $this->getLegend();
return ''.$this->getLegend();
}

public function getPath(): ?string

+ 5
- 0
Repository/AbstractRepositoryQuery.php 查看文件

@@ -133,6 +133,11 @@ abstract class AbstractRepositoryQuery implements RepositoryQueryInterface
return $this->andWhere('.'.$field.' = :'.$field)->setParameter($field, $value);
}

public function filterByOldUrl(string $oldUrl): self
{
return $this->andWhere(':oldUrl IN .oldUrls')->setParameter('oldUrl', $oldUrl);
}

/*
* DEVALIAS
*/

+ 13
- 3
Repository/AbstractStore.php 查看文件

@@ -57,7 +57,7 @@ abstract class AbstractStore implements StoreInterface

public function getOneBySlug(string $slug, bool $isOnline = true, $query = null)
{
$query = $this->createDefaultQuery($query);
$query = $this->createQuery($query);
$query->filterBySlug($slug);

if ($isOnline) {
@@ -69,14 +69,14 @@ abstract class AbstractStore implements StoreInterface

public function getOneByDevAlias(string $devAlias, $query = null)
{
$query = $this->createDefaultQuery($query);
$query = $this->createQuery($query);
$query->filterByDevAlias($devAlias);
return $query->findOne();
}

public function getOneOnlineByDevAlias(string $devAlias, $query = null)
{
$query = $this->createDefaultQuery($query);
$query = $this->createQuery($query);
$query
->filterByDevAlias($devAlias)
->filterIsOnline();
@@ -84,6 +84,16 @@ abstract class AbstractStore implements StoreInterface
return $query->findOne();
}

public function getOneByOldUrl(string $oldUrl, $query = null)
{
$query = $this->createQuery($query);
$query
->filterByOldUrl($oldUrl)
->filterIsOnline();

return $query->findOne();
}

public function get($query = null)
{
$query = $this->createDefaultQuery($query);

+ 58
- 0
Twig/MetaTwigExtension.php 查看文件

@@ -0,0 +1,58 @@
<?php

namespace Lc\SovBundle\Twig;

use Lc\SovBundle\Component\MetaComponent;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class MetaTwigExtension extends AbstractExtension
{
protected MetaComponent $metaComponent;

public function __construct(MetaComponent $metaComponent)
{
$this->metaComponent = $metaComponent;
}

public function getFunctions()
{
return [
new TwigFunction('sov_meta_title', [$this, 'getMetaTitle']),
new TwigFunction('sov_meta_description', [$this, 'getMetaDescription']),
new TwigFunction('sov_opengraph_title', [$this, 'getOpengraphTitle']),
new TwigFunction('sov_opengraph_description', [$this, 'getOpengraphDescription']),
new TwigFunction('sov_opengraph_image', [$this, 'getOpengraphImage']),
];
}

public function getFilters()
{
return [];
}

public function getMetaTitle($entity): string
{
return $this->metaComponent->getMetaTitle($entity);
}

public function getMetaDescription($entity): string
{
return $this->metaComponent->getMetaDescription($entity);
}

public function getOpenGraphTitle($entity): string
{
return $this->metaComponent->getOpenGraphTitle($entity);
}

public function getOpenGraphDescription($entity): string
{
return $this->metaComponent->getOpenGraphDescription($entity);
}

public function getOpenGraphImage($entity): string
{
return $this->metaComponent->getOpenGraphImage($entity);
}
}

+ 14
- 1
Twig/TwigExtension.php 查看文件

@@ -4,6 +4,8 @@ namespace Lc\SovBundle\Twig;

use App\Repository\ReminderRepository;
use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Component\MetaComponent;
use Lc\SovBundle\Component\StringComponent;
use Lc\SovBundle\Form\Newsletter\NewsletterType;
use Lc\SovBundle\Repository\Reminder\ReminderStore;
use Lc\SovBundle\Translation\TranslatorAdmin;
@@ -32,6 +34,7 @@ class TwigExtension extends AbstractExtension
protected $reminderStore;
protected $security;
protected FormFactoryInterface $formFactory;
protected StringComponent $stringComponent;

public function __construct(
KernelInterface $kernel,
@@ -44,7 +47,9 @@ class TwigExtension extends AbstractExtension
TranslatorAdmin $translatorAdmin,
ReminderStore $reminderStore,
Security $security,
FormFactoryInterface $formFactory
FormFactoryInterface $formFactory,
StringComponent $stringComponent,
MetaComponent $metaComponent
) {
$this->kernel = $kernel;
$this->parameterBag = $parameterBag;
@@ -57,6 +62,8 @@ class TwigExtension extends AbstractExtension
$this->reminderStore = $reminderStore;
$this->security = $security;
$this->formFactory = $formFactory;
$this->stringComponent = $stringComponent;
$this->metaComponent = $metaComponent;
}

public function getFunctions()
@@ -69,6 +76,7 @@ class TwigExtension extends AbstractExtension
new TwigFunction('lc_format_price', [$this, 'formatPrice']),
new TwigFunction('die', [$this, 'die']),
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
new TwigFunction('sov_limit_text', [$this, 'limitText']),
];
}

@@ -152,4 +160,9 @@ class TwigExtension extends AbstractExtension
return $form->createView();
}

public function limitText(string $text, int $limit)
{
return $this->stringComponent->limitText($text, $limit);
}

}

正在加载...
取消
保存