backports murph-skeleton
This commit is contained in:
parent
e244d994fa
commit
cb44f7539a
11
config/packages/knp.yaml
Normal file
11
config/packages/knp.yaml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
knp_paginator:
|
||||||
|
page_range: 4
|
||||||
|
default_options:
|
||||||
|
page_name: page # page query parameter name
|
||||||
|
sort_field_name: sort # sort field query parameter name
|
||||||
|
sort_direction_name: direction # sort direction query parameter name
|
||||||
|
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
|
||||||
|
template:
|
||||||
|
pagination: '@Core/pager/sliding.html.twig' # sliding pagination controls template
|
||||||
|
sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template
|
||||||
|
filtration: '@KnpPaginator/Pagination/filtration.html.twig' # filters template
|
51
core/Cache/SymfonyCacheManager.php
Normal file
51
core/Cache/SymfonyCacheManager.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Cache;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class SymfonyCacheManager.
|
||||||
|
*
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
class SymfonyCacheManager
|
||||||
|
{
|
||||||
|
protected KernelInterface $kernel;
|
||||||
|
|
||||||
|
public function __construct(KernelInterface $kernel)
|
||||||
|
{
|
||||||
|
$this->kernel = $kernel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cleanRouting()
|
||||||
|
{
|
||||||
|
$finder = new Finder();
|
||||||
|
$finder
|
||||||
|
->in($this->kernel->getCacheDir())
|
||||||
|
->depth('== 0')
|
||||||
|
->name('url_*.php*')
|
||||||
|
;
|
||||||
|
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
unlink((string) $file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cleanAll()
|
||||||
|
{
|
||||||
|
$application = new Application($this->kernel);
|
||||||
|
$application->setAutoExit(false);
|
||||||
|
|
||||||
|
$input = new ArrayInput([
|
||||||
|
'command' => 'cache:clear',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$output = new BufferedOutput();
|
||||||
|
$application->run($input, $output);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
{% set value = form.vars.data %}
|
{% set value = form.vars.data %}
|
||||||
|
|
||||||
{% if value %}
|
{% if value %}
|
||||||
{% if value and value.extension in ['jpg', 'gif', 'png'] %}
|
{% if value and value.extension in ['jpeg', 'jpg', 'gif', 'png'] %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-img-top bg-dark text-center">
|
<div class="card-img-top bg-dark text-center">
|
||||||
<a href="{{ asset(value.pathname) }}" target="_blank">
|
<a href="{{ asset(value.pathname) }}" target="_blank">
|
||||||
|
|
76
core/Resources/views/pager/sliding.html.twig
Normal file
76
core/Resources/views/pager/sliding.html.twig
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
{% if pageCount > 1 %}
|
||||||
|
<ul class="pagination pagination-sm justify-content-end">
|
||||||
|
{% if previous is defined %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a rel="prev" href="{{ path(route, query|merge({(pageParameterName): previous})) }}" class="page-link">
|
||||||
|
<span class="fa fa-chevron-left"></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">
|
||||||
|
<span class="fa fa-chevron-left"></span>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if startPage > 1 %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a href="{{ path(route, query|merge({(pageParameterName): 1})) }}" class="page-link">1</a>
|
||||||
|
</li>
|
||||||
|
{% if startPage == 3 %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a href="{{ path(route, query|merge({(pageParameterName): 2})) }}" class="page-link">2</a>
|
||||||
|
</li>
|
||||||
|
{% elseif startPage != 2 %}
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">…</span>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for page in pagesInRange %}
|
||||||
|
{% if page != current %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a href="{{ path(route, query|merge({(pageParameterName): page})) }}" class="page-link">{{ page }}</a>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="active page-item">
|
||||||
|
<span class="page-link">{{ page }}</span>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if pageCount > endPage %}
|
||||||
|
{% if pageCount > (endPage + 1) %}
|
||||||
|
{% if pageCount > (endPage + 2) %}
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">…</span>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a href="{{ path(route, query|merge({(pageParameterName): (pageCount - 1)})) }}" class="page-link">{{ pageCount -1 }}</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ path(route, query|merge({(pageParameterName): pageCount})) }}" class="page-link">{{ pageCount }}</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if next is defined %}
|
||||||
|
<li class="page-item">
|
||||||
|
<a rel="next" class="page-link" href="{{ path(route, query|merge({(pageParameterName): next})) }}">
|
||||||
|
<span class="fa fa-chevron-right"></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">
|
||||||
|
<span class="fa fa-chevron-right"></span>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
125
core/Twig/Extension/RoutingExtension.php
Normal file
125
core/Twig/Extension/RoutingExtension.php
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Twig\Extension;
|
||||||
|
|
||||||
|
use App\Core\Entity\Site\Node;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\Node\Expression\ArrayExpression;
|
||||||
|
use Twig\Node\Expression\ConstantExpression;
|
||||||
|
use Twig\Node\Node as TwigNode;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
class RoutingExtension extends AbstractExtension
|
||||||
|
{
|
||||||
|
private UrlGeneratorInterface $generator;
|
||||||
|
|
||||||
|
public function __construct(UrlGeneratorInterface $generator)
|
||||||
|
{
|
||||||
|
$this->generator = $generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFunctions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new TwigFunction('node_url', [$this, 'getNodeUrl'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||||
|
new TwigFunction('node_path', [$this, 'getNodePath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||||
|
new TwigFunction('safe_node_url', [$this, 'getSafeNodeUrl'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||||
|
new TwigFunction('safe_node_path', [$this, 'getSafeNodePath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||||
|
new TwigFunction('safe_url', [$this, 'getSafeUrl'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||||
|
new TwigFunction('safe_path', [$this, 'getSafePath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSafePath(string $route, array $parameters = [], bool $relative = false): ?string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->generator->generate(
|
||||||
|
$route,
|
||||||
|
$parameters,
|
||||||
|
$relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH
|
||||||
|
);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSafeUrl(string $route, array $parameters = [], bool $schemeRelative = false): ?string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->generator->generate(
|
||||||
|
$route,
|
||||||
|
$parameters,
|
||||||
|
$schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL
|
||||||
|
);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNodePath(Node $node, array $parameters = [], bool $relative = false): ?string
|
||||||
|
{
|
||||||
|
if ($node->hasExternalUrl()) {
|
||||||
|
return $node->getUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->generator->generate(
|
||||||
|
$node->getRouteName(),
|
||||||
|
$parameters,
|
||||||
|
$relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNodeUrl(Node $node, array $parameters = [], bool $schemeRelative = false): ?string
|
||||||
|
{
|
||||||
|
if ($node->hasExternalUrl()) {
|
||||||
|
return $node->getUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->generator->generate(
|
||||||
|
$node->getRouteName(),
|
||||||
|
$parameters,
|
||||||
|
$schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSafeNodePath(Node $node, array $parameters = [], bool $relative = false): ?string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->getNodePath($node, $parameters, $relative);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSafeNodeUrl(Node $node, array $parameters = [], bool $schemeRelative = false): ?string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->getNodeUrl($node, $parameters, $schemeRelative);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Symfony\Bridge\Twig\Extension\RoutingExtension::isUrlGenerationSafe
|
||||||
|
*/
|
||||||
|
public function isUrlGenerationSafe(TwigNode $argsNode): array
|
||||||
|
{
|
||||||
|
// support named arguments
|
||||||
|
$paramsNode = $argsNode->hasNode('parameters') ? $argsNode->getNode('parameters') : (
|
||||||
|
$argsNode->hasNode(1) ? $argsNode->getNode(1) : null
|
||||||
|
);
|
||||||
|
|
||||||
|
if (null === $paramsNode || $paramsNode instanceof ArrayExpression && \count($paramsNode) <= 2 &&
|
||||||
|
(!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof ConstantExpression)
|
||||||
|
) {
|
||||||
|
return ['html'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue