mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 13:16:45 +02:00
feat(expressions): add Url
expression
This commit is contained in:
41
src/flextype/core/Entries/Expressions/UrlExpression.php
Normal file
41
src/flextype/core/Entries/Expressions/UrlExpression.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
|
||||
* and with the full functionality of a traditional CMS!
|
||||
*
|
||||
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
|
||||
*
|
||||
* Licensed under The MIT License.
|
||||
*
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*/
|
||||
|
||||
namespace Flextype\Entries\Expressions;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
class UrlExpression implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new ExpressionFunction('urlFor', fn(string $routeName, array $data = [], array $queryParams = []) => 'urlFor($routeName, $data, $queryParams)', fn(string $routeName, array $data = [], array $queryParams = []) => urlFor($routeName, $data, $queryParams)),
|
||||
new ExpressionFunction('fullUrlFor', fn(Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = [], array $queryParams = []) => 'fullUrlFor($request, $routeName, $data, $queryParams)', fn(Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = [], array $queryParams = []) => fullUrlFor($request, $routeName, $data = [], $queryParams = [])),
|
||||
new ExpressionFunction('isCurrentUrl', fn(Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = []) => 'isCurrentUrl($request, $routeName, $data)', fn(Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = []) => isCurrentUrl($request, $routeName, $data = [])),
|
||||
new ExpressionFunction('getCurrentUrl', fn(Psr\Http\Message\ServerRequestInterface $request, bool $withQueryString = false) => 'getCurrentUrl($request, $withQueryString)', fn(Psr\Http\Message\ServerRequestInterface $request, bool $withQueryString = false) => getCurrentUrl($request, $withQueryString)),
|
||||
new ExpressionFunction('getBasePath', fn() => 'getBasePath()', fn() => getBasePath()),
|
||||
new ExpressionFunction('getBaseUrl', fn() => 'getBaseUrl()', fn() => getBaseUrl()),
|
||||
new ExpressionFunction('setBasePath', fn(string $basePath) => 'setBasePath($basePath)', fn(string $basePath) => setBasePath($basePath)),
|
||||
new ExpressionFunction('getBaseUrl', fn() => 'getBaseUrl()', fn() => getBaseUrl()),
|
||||
new ExpressionFunction('getAbsoluteUrl', fn() => 'getAbsoluteUrl()', fn() => getAbsoluteUrl()),
|
||||
new ExpressionFunction('getProjectUrl', fn() => 'getProjectUrl()', fn() => getProjectUrl()),
|
||||
new ExpressionFunction('getUriString', fn() => 'getUriString()', fn() => getUriString()),
|
||||
new ExpressionFunction('redirect', fn(string $routeName, array $data = [], array $queryParams = [], int $status = 301) => 'redirect($routeName, $data, $queryParams, $status)', fn(string $routeName, array $data = [], array $queryParams = [], int $status = 301) => redirect($routeName, $data, $queryParams, $status))
|
||||
];
|
||||
}
|
||||
}
|
@@ -121,6 +121,9 @@ entries:
|
||||
const:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\ConstExpression"
|
||||
url:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\UrlExpression"
|
||||
directives:
|
||||
expressions:
|
||||
enabled: true
|
||||
|
Reference in New Issue
Block a user