Skip to content

Commit 5c9b4e3

Browse files
committed
Update FontAwesome services.
1 parent 6a12eaf commit 5c9b4e3

22 files changed

Lines changed: 231 additions & 385 deletions

src/Controller/LogController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use App\Model\TranslatableFlashMessage;
2626
use App\Report\LogsReport;
2727
use App\Resolver\DataQueryValueResolver;
28-
use App\Service\FontAwesomeService;
28+
use App\Service\FontAwesomeCellService;
2929
use App\Service\LogService;
3030
use App\Spreadsheet\LogsDocument;
3131
use App\Table\DataQuery;
@@ -146,7 +146,7 @@ public function index(
146146
* Export to PDF the content of the log file.
147147
*/
148148
#[PdfRoute]
149-
public function pdf(FontAwesomeService $service): Response
149+
public function pdf(FontAwesomeCellService $service): Response
150150
{
151151
$logFile = $this->getLogFile();
152152
if (!$logFile instanceof LogFile) {

src/Controller/TestExportController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
use App\Repository\CustomerRepository;
3030
use App\Response\PdfResponse;
3131
use App\Response\WordResponse;
32+
use App\Service\FontAwesomeCellService;
3233
use App\Service\FontAwesomeImageService;
33-
use App\Service\FontAwesomeService;
3434
use App\Service\PdfLabelService;
3535
use App\Traits\RenderPdfDocumentTrait;
3636
use App\Traits\RenderWordDocumentTrait;
@@ -116,7 +116,7 @@ public function exportMemoryImage(
116116
string $iconFile,
117117
#[Autowire('%kernel.project_dir%/public/images/screenshots/home_light.png')]
118118
string $screenshotFile,
119-
FontAwesomeService $service
119+
FontAwesomeCellService $service
120120
): PdfResponse {
121121
$report = new MemoryImageReport(
122122
helper: $this,

src/Controller/UserController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
use App\Response\PdfResponse;
4242
use App\Response\SpreadsheetResponse;
4343
use App\Service\ApplicationService;
44-
use App\Service\FontAwesomeService;
44+
use App\Service\FontAwesomeCellService;
4545
use App\Service\MailerService;
4646
use App\Service\PasswordTooltipService;
4747
use App\Service\ResetPasswordService;
@@ -208,7 +208,7 @@ public function password(Request $request, User $item, PasswordTooltipService $s
208208
public function pdf(
209209
StorageInterface $storage,
210210
RoleService $roleService,
211-
FontAwesomeService $fontService,
211+
FontAwesomeCellService $fontService,
212212
): PdfResponse {
213213
$entities = $this->getEntitiesByUserName();
214214
$report = new UsersReport($this, $entities, $storage, $roleService, $fontService);
@@ -365,7 +365,7 @@ public function rightsExcel(RoleService $roleService, RoleBuilderService $roleBu
365365
public function rightsPdf(
366366
RoleService $roleService,
367367
RoleBuilderService $roleBuilderService,
368-
FontAwesomeService $fontAwesomeService
368+
FontAwesomeCellService $fontAwesomeService
369369
): PdfResponse {
370370
$entities = $this->getEntitiesByUserName();
371371
$parameters = $this->getApplicationParameters();

src/Pdf/Interfaces/PdfColorInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public function applyFillColor(PdfDocument $doc): void;
4444
*/
4545
public function applyTextColor(PdfDocument $doc): void;
4646

47+
/**
48+
* Gets the hexadecimal representation of these values.
49+
*
50+
* @param string $prefix the optional prefix to prepend
51+
*
52+
* @return string the hexadecimal value as six lower case characters (like <code>'ff8040'</code>)
53+
*/
54+
public function asHex(string $prefix = ''): string;
55+
4756
/**
4857
* Gets this value converted to RGB.
4958
*

src/Pdf/Traits/PdfColorTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function applyTextColor(PdfDocument $doc): void
4141
$this->getTextColor()->updateDocument($doc);
4242
}
4343

44+
public function asHex(string $prefix = ''): string
45+
{
46+
return $this->getTextColor()->asHex($prefix);
47+
}
48+
4449
public function asRGB(): array
4550
{
4651
return [

src/Report/FontAwesomeReport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function createTable(): PdfTable
7878

7979
private function renderImage(PdfTable $table, int $index, FontAwesomeIcon $icon): void
8080
{
81-
$image = $this->service->getFontAwesomeImage($icon) ?? throw PdfException::format('Unable to get image: "%s".', $icon->getKey());
81+
$image = $this->service->getImage($icon) ?? throw PdfException::format('Unable to get image: "%s".', $icon->getKey());
8282
if (0 === $index % self::COLUMNS) {
8383
$table->startRow();
8484
}

src/Report/LogsReport.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
use App\Model\LogFile;
2121
use App\Model\LogLevel;
2222
use App\Pdf\Colors\PdfTextColor;
23-
use App\Pdf\Html\HtmlBootstrapColor;
2423
use App\Pdf\PdfCell;
2524
use App\Pdf\PdfColumn;
2625
use App\Pdf\PdfFontAwesomeCell;
2726
use App\Pdf\PdfStyle;
2827
use App\Pdf\PdfTable;
2928
use App\Pdf\Traits\PdfMemoryImageTrait;
30-
use App\Service\FontAwesomeImageService;
31-
use App\Service\FontAwesomeService;
29+
use App\Service\FontAwesomeCellService;
3230
use App\Utils\FormatUtils;
3331
use App\Utils\StringUtils;
3432
use fpdf\Enums\PdfMove;
@@ -57,7 +55,7 @@ public function __construct(
5755
DocumentHelperInterface $helper,
5856
private readonly LogFile $logFile,
5957
string $relativePath,
60-
private readonly FontAwesomeService $service
58+
private readonly FontAwesomeCellService $service
6159
) {
6260
parent::__construct($helper, PdfOrientation::LANDSCAPE);
6361
$this->setTranslatedTitle('log.title')
@@ -111,7 +109,7 @@ private function getCell(string $text, FontAwesomeIcon $icon, ?string $color = n
111109
if (isset($this->cells[$key])) {
112110
return $this->cells[$key];
113111
}
114-
$cell = $this->service->getFontAwesomeCell(icon: $icon, color: $color, text: $text) ?? $text;
112+
$cell = $this->service->getCell(icon: $icon, color: $color, text: $text) ?? $text;
115113

116114
return $this->cells[$key] = $cell;
117115
}
@@ -144,7 +142,7 @@ private function getImageIcon(LogLevel|LogChannel $value, string $text): PdfCell
144142
}
145143

146144
$alignment = PdfTextAlignment::CENTER;
147-
$cell = $this->service->getFontAwesomeCell(
145+
$cell = $this->service->getCell(
148146
icon: $icon,
149147
color: $color,
150148
text: $text,
@@ -162,9 +160,9 @@ private function getLevelColor(string $level): string
162160
if (\array_key_exists($level, $this->colors)) {
163161
return $this->colors[$level];
164162
}
165-
166-
$levelColor = LogLevel::instance($level)->getLevelColor();
167-
$color = HtmlBootstrapColor::parseTextColor($levelColor)?->asHex('#') ?? FontAwesomeImageService::BLACK_COLOR;
163+
$color = LogLevel::instance($level)
164+
->getLevelBootstrapColor()
165+
->asHex('#');
168166

169167
return $this->colors[$level] = $color;
170168
}

0 commit comments

Comments
 (0)