raw = $rawLine; $this->comments = $comments; $this->parse($rawLine); $this->id = md5(trim($rawLine)); } private function parse(string $line): void { // Remove inline comments (mas guarda para display) $line = preg_replace('/\s+#.*/', '', $line); // Suporte a @reboot, @hourly, etc. if (preg_match('/^(@\w+)\s+(.*)$/', $line, $matches)) { $this->special = $matches[1]; $this->schedule = $matches[1]; $rest = $matches[2]; } else { // Split schedule (5 campos) + comando $parts = preg_split('/\s+/', $line, 6); if (count($parts) < 6) { $this->schedule = ''; $this->command = ''; return; } [$min, $hour, $dom, $mon, $dow, $rest] = $parts; $this->schedule = "$min $hour $dom $mon $dow"; } // Separa comando, args e redirecionamentos if (preg_match('/^([^\s]+)(.*?)(\s+>\s*.+)?$/', $rest, $matches)) { $this->command = trim($matches[1]); $this->args = isset($matches[2]) ? trim($matches[2]) : null; $this->redirect = isset($matches[3]) ? trim($matches[3]) : null; } else { $this->command = trim($rest); } } public function toArray(): array { return [ 'id' => $this->id, 'schedule' => $this->schedule, 'command' => $this->command, 'args' => $this->args, 'redirect' => $this->redirect, 'raw' => $this->raw, 'comments' => $this->comments, 'special' => $this->special, ]; } }