From 043f936497babe19931d296daa3431abc7fca3f6 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Thu, 4 Sep 2025 17:07:50 +0200 Subject: [PATCH] feat: Implement export of ebook references with path to the files --- src/Command/KanjiExtractCommand.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Command/KanjiExtractCommand.php b/src/Command/KanjiExtractCommand.php index a8d6f73..cc77b61 100644 --- a/src/Command/KanjiExtractCommand.php +++ b/src/Command/KanjiExtractCommand.php @@ -12,12 +12,14 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\VarExporter\VarExporter; #[AsCommand('app:extract', 'Create list recursively from path')] class KanjiExtractCommand extends Command { - public function __construct() - { + public function __construct( + private string $varBasepath, + ) { parent::__construct(); } @@ -52,15 +54,21 @@ class KanjiExtractCommand extends Command $kanjiStr = Japanese::getOnlyKanji($line); foreach (Japanese::mbIterate($kanjiStr) as $char) { if (!key_exists($char, $kanji)) { - $kanji[$char] ??= 0; + $kanji[$char] ??= []; echo $char; if (count($kanji) % 40 === 0) echo "\n"; } - $kanji[$char]++; + + if (count($kanji[$char]) < 50) { + $kanji[$char][$fileinfo->getPathname()] ??= 0; + $kanji[$char][$fileinfo->getPathname()]++; + } } } } + file_put_contents("$this->varBasepath/ebook-ref.php", '