<?php
/**
 * @package         Tassos Code Snippets
 * @version         1.0.1-RC2 Free
 *
 * @author          Tassos Marinos <info@tassos.gr>
 * @link            https://www.tassos.gr
 * @copyright       Copyright © 2026 Tassos Marinos All Rights Reserved
 * @license         GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
 */

namespace Tassos\CodeSnippets\Administrator\Snippet;

use Tassos\Framework\Executer;

class PhpSnippet extends Snippet
{
    /**
     * Display color used for the snippet (hex).
     *
     * @var string
     */
    protected $color = '#6f20b0';

    public function run()
    {
        $code = $this->snippet->code ?? '';

        if (empty($code))
        {
            return null;
        }

        // Remove PHP opening and closing tags if present
        $code = preg_replace('/^\s*<\?php\s*/', '', $code);
        $code = preg_replace('/\s*\?>\s*$/', '', $code);

        $executer = new Executer();

        return $executer->runFile($code, $this->attributes);
    }
}
