Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

741 B
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Exports\ValueBinders;

use HiEvents\Services\Infrastructure\Export\SpreadsheetFormulaEscaper;
use Maatwebsite\Excel\DefaultValueBinder;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;

class FormulaSafeValueBinder extends DefaultValueBinder
{
    private ?SpreadsheetFormulaEscaper $escaper = null;

    public function bindValue(Cell $cell, mixed $value): bool
    {
        $this->escaper ??= app(SpreadsheetFormulaEscaper::class);

        if ($this->escaper->isFormulaTrigger($value)) {
            $cell->setValueExplicit($value, DataType::TYPE_STRING);

            return true;
        }

        return parent::bindValue($cell, $value);
    }
}