beautify code

This commit is contained in:
2024-11-12 23:00:03 +05:00
parent c4a2a947e2
commit 582c5dada5
10 changed files with 123 additions and 51 deletions

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Modules\Excell;
use App\Modules\Excell\Types\iRichText\RichTextWrapper;
class Excell
{
/**
* RichText wrapper
*/
public static function richText(): RichTextWrapper
{
return new RichTextWrapper;
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Modules\Excell;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class ExcellModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return true;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace App\Modules\Excell\Fonts;
class FONTS
{
public const TIMES_NEW_ROMAN = 'Times New Roman';
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Modules\Excell\Types\iRichText;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Style\Font;
class RichTextWrapper
{
public function __construct(
protected RichText $richText = new RichText,
protected string $defaultFontName = 'Calibri',
protected int $defaultSize = 12,
) {}
/**
* Default font name
*/
public function setDefaultFont(string $fontname): self
{
$this->defaultFontName = $fontname;
return $this;
}
/**
* Default font size
*/
public function setDefaultSize(int $size): self
{
$this->defaultSize = $size;
return $this;
}
/**
* Add or attach text
*
* @param array<int, string> $styles
*/
public function add(?string $text, array $styles = [], bool $bold = false): self
{
if (! $text) {
return $this;
}
$textRun = $this->richText->createTextRun($text);
$font = $textRun->getFont() ?: new Font;
$font->setName($this->defaultFontName)
->setSize($this->defaultSize);
if ($bold) {
$font->setBold(true);
}
return $this;
}
/**
* Return RichText
*/
public function toRichText(): RichText
{
return $this->richText;
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace App\Modules\Excell\Types\RichText\Traits;
trait HasExcellRichTextWrappers {}