v1.9.0
This commit is contained in:
commit
6d0afb50b0
282 changed files with 19937 additions and 0 deletions
61
src/core/String/FileInformationBuilder.php
Normal file
61
src/core/String/FileInformationBuilder.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\String;
|
||||
|
||||
use App\Core\FileManager\FsFileManager;
|
||||
use App\Core\Repository\FileInformationRepositoryQuery;
|
||||
|
||||
/**
|
||||
* class FileInformationBuilder.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class FileInformationBuilder
|
||||
{
|
||||
protected FsFileManager $fsManager;
|
||||
protected FileInformationRepositoryQuery $query;
|
||||
|
||||
public function __construct(FsFileManager $fsManager, FileInformationRepositoryQuery $query)
|
||||
{
|
||||
$this->fsManager = $fsManager;
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
public function replaceTags(string $value)
|
||||
{
|
||||
preg_match_all(
|
||||
'#\{\{\s*fattr://(?P<hash>[a-z0-9]+)\/(?P<label>.+)\s*\}\}#isU',
|
||||
$value,
|
||||
$match,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
|
||||
$fileInfos = [];
|
||||
|
||||
foreach ($match as $block) {
|
||||
$hash = $block['hash'];
|
||||
$label = $block['label'];
|
||||
$tagValue = null;
|
||||
|
||||
if (!isset($fileInfos[$hash])) {
|
||||
$fileInfos[$hash] = $this->query->create()
|
||||
->where('.id LIKE :hash')
|
||||
->setParameter(':hash', $hash.'%')
|
||||
->findOne()
|
||||
;
|
||||
}
|
||||
|
||||
if ($fileInfos[$hash]) {
|
||||
foreach ($fileInfos[$hash]->getAttributes() as $attribute) {
|
||||
if ($attribute['label'] === $label) {
|
||||
$tagValue = htmlspecialchars($attribute['value'], ENT_HTML5 | ENT_QUOTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$value = str_replace($block[0], $tagValue, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
47
src/core/String/StringBuilder.php
Normal file
47
src/core/String/StringBuilder.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\String;
|
||||
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
/**
|
||||
* class StringBuilder.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class StringBuilder
|
||||
{
|
||||
protected PropertyAccessor $propertyAccessor;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
|
||||
->disableExceptionOnInvalidPropertyPath()
|
||||
->getPropertyAccessor()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a string and inject values from given object.
|
||||
*
|
||||
* @param mixed $object
|
||||
*/
|
||||
public function build(string $format, $object): string
|
||||
{
|
||||
if (!is_array($object) && !is_object($object)) {
|
||||
return $format;
|
||||
}
|
||||
|
||||
preg_match_all('/\{([a-zA-Z0-9\._]+)\}/i', $format, $matches, PREG_SET_ORDER);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$propertyValue = $this->propertyAccessor->getValue($object, $match[1]);
|
||||
|
||||
$format = u($format)->replace($match[0], (string) $propertyValue);
|
||||
}
|
||||
|
||||
return $format;
|
||||
}
|
||||
}
|
||||
65
src/core/String/UrlBuilder.php
Normal file
65
src/core/String/UrlBuilder.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\String;
|
||||
|
||||
use App\Core\Site\SiteRequest;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* class UrlBuilder.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class UrlBuilder
|
||||
{
|
||||
protected UrlGeneratorInterface $urlGenerator;
|
||||
protected SiteRequest $siteRequest;
|
||||
|
||||
public function __construct(UrlGeneratorInterface $urlGenerator, SiteRequest $siteRequest)
|
||||
{
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->siteRequest = $siteRequest;
|
||||
}
|
||||
|
||||
public function replaceTags(string $value): string
|
||||
{
|
||||
preg_match_all(
|
||||
'#\{\{\s*url://(?P<route>[a-z0-9_]+)(\?(?P<params>.*))?\s*\}\}#isU',
|
||||
$value,
|
||||
$match,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
|
||||
$domain = $this->siteRequest->getDomain();
|
||||
|
||||
foreach ($match as $block) {
|
||||
$url = null;
|
||||
|
||||
try {
|
||||
$block['params'] = $block['params'] ?? '';
|
||||
$block['params'] = str_replace(['&', ' '], ['&', '%20'], $block['params']);
|
||||
$route = $block['route'];
|
||||
parse_str($block['params'], $params);
|
||||
|
||||
if (!isset($params['_domain'])) {
|
||||
$params['_domain'] = $domain;
|
||||
}
|
||||
|
||||
$url = $this->urlGenerator->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
|
||||
parse_str(parse_url($url)['query'] ?? '', $infos);
|
||||
|
||||
if (isset($infos['_domain'])) {
|
||||
unset($params['_domain']);
|
||||
|
||||
$url = $this->urlGenerator->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$value = str_replace($block[0], $url, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue