Browse Source

implement namespace alias replacement

main
ghost 10 months ago
parent
commit
eb57f1bcad
  1. 24
      composer.lock
  2. 38
      src/Twig/AppExtension.php

24
composer.lock generated

@ -8,16 +8,16 @@
"packages": [ "packages": [
{ {
"name": "clitor-is-protocol/kevacoin", "name": "clitor-is-protocol/kevacoin",
"version": "1.0.0", "version": "1.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/clitor-is-protocol/kevacoin-php.git", "url": "https://github.com/clitor-is-protocol/kevacoin-php.git",
"reference": "23e7c13e915f6fc99a67173ac8bf1771e6cd2c0d" "reference": "80d4dc22e4826ba40fd8c619d5654abf242ee457"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/clitor-is-protocol/kevacoin-php/zipball/23e7c13e915f6fc99a67173ac8bf1771e6cd2c0d", "url": "https://api.github.com/repos/clitor-is-protocol/kevacoin-php/zipball/80d4dc22e4826ba40fd8c619d5654abf242ee457",
"reference": "23e7c13e915f6fc99a67173ac8bf1771e6cd2c0d", "reference": "80d4dc22e4826ba40fd8c619d5654abf242ee457",
"shasum": "" "shasum": ""
}, },
"type": "library", "type": "library",
@ -32,9 +32,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/clitor-is-protocol/kevacoin-php/issues", "issues": "https://github.com/clitor-is-protocol/kevacoin-php/issues",
"source": "https://github.com/clitor-is-protocol/kevacoin-php/tree/1.0.0" "source": "https://github.com/clitor-is-protocol/kevacoin-php/tree/1.0.1"
}, },
"time": "2023-12-13T18:54:41+00:00" "time": "2023-12-13T22:39:13+00:00"
}, },
{ {
"name": "dflydev/dot-access-data", "name": "dflydev/dot-access-data",
@ -162,16 +162,16 @@
}, },
{ {
"name": "kevachat/kevacoin", "name": "kevachat/kevacoin",
"version": "1.5.0", "version": "1.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/kevachat/kevacoin-php.git", "url": "https://github.com/kevachat/kevacoin-php.git",
"reference": "44608e688f69ff1545f2a3103c4504bfb3294831" "reference": "ad3aee526db3e367a368b237af0d17071a36f871"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/kevachat/kevacoin-php/zipball/44608e688f69ff1545f2a3103c4504bfb3294831", "url": "https://api.github.com/repos/kevachat/kevacoin-php/zipball/ad3aee526db3e367a368b237af0d17071a36f871",
"reference": "44608e688f69ff1545f2a3103c4504bfb3294831", "reference": "ad3aee526db3e367a368b237af0d17071a36f871",
"shasum": "" "shasum": ""
}, },
"type": "library", "type": "library",
@ -186,9 +186,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/kevachat/kevacoin-php/issues", "issues": "https://github.com/kevachat/kevacoin-php/issues",
"source": "https://github.com/kevachat/kevacoin-php/tree/1.5.0" "source": "https://github.com/kevachat/kevacoin-php/tree/1.6.0"
}, },
"time": "2023-12-09T18:55:04+00:00" "time": "2023-12-10T06:02:53+00:00"
}, },
{ {
"name": "league/commonmark", "name": "league/commonmark",

38
src/Twig/AppExtension.php

@ -185,12 +185,38 @@ class AppExtension extends AbstractExtension
string $text string $text
): string ): string
{ {
// check string not converted before to link by "/" prefix // Search not filtered namespaces
return preg_replace( if (preg_match_all('~(N[A-z0-9]{33})~i', $text, $matches))
'~[^/](N[A-z0-9]{33})~i', {
'[$1]($1#latest)', if (empty($matches[1]))
$text {
); return $text;
}
// Replace with _KEVA_NS_ value if defined
foreach ($matches[1] as $namespace)
{
$text = str_replace(
$namespace,
sprintf(
'[%s](%s)',
$this->kevaNamespaceValue(
$namespace
),
$this->container->get('router')->generate(
'room_namespace',
[
'namespace' => $namespace,
'_fragment' => 'latest'
]
)
),
$text
);
}
}
return $text;
} }
public function kevaNamespaceValue( public function kevaNamespaceValue(

Loading…
Cancel
Save