beautify code
This commit is contained in:
16
app/Modules/Excell/Excell.php
Normal file
16
app/Modules/Excell/Excell.php
Normal 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;
|
||||
}
|
||||
}
|
||||
48
app/Modules/Excell/ExcellModule.php
Normal file
48
app/Modules/Excell/ExcellModule.php
Normal 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;
|
||||
}
|
||||
}
|
||||
8
app/Modules/Excell/Fonts/Fonts.php
Normal file
8
app/Modules/Excell/Fonts/Fonts.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Excell\Fonts;
|
||||
|
||||
class FONTS
|
||||
{
|
||||
public const TIMES_NEW_ROMAN = 'Times New Roman';
|
||||
}
|
||||
67
app/Modules/Excell/Types/iRichText/RichTextWrapper.php
Normal file
67
app/Modules/Excell/Types/iRichText/RichTextWrapper.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Excell\Types\RichText\Traits;
|
||||
|
||||
trait HasExcellRichTextWrappers {}
|
||||
Reference in New Issue
Block a user