<?php

namespace Sitecake\Event;

/**
 * Simple event object — replaces Cake\Event\Event.
 */
class Event
{
    protected string $name;
    protected $subject;
    protected array $data;
    protected $result = null;
    protected bool $stopped = false;

    public function __construct(string $name, $subject = null, array $data = [])
    {
        $this->name    = $name;
        $this->subject = $subject;
        $this->data    = $data;
    }

    public function getName(): string  { return $this->name; }
    public function getSubject()       { return $this->subject; }
    public function getData(string $key = null) { return $key === null ? $this->data : ($this->data[$key] ?? null); }
    public function getResult()        { return $this->result; }
    public function setResult($result): void { $this->result = $result; }
    public function stopPropagation(): void  { $this->stopped = true; }
    public function isStopped(): bool        { return $this->stopped; }
}
