Parse sends a base64 payload to the PHP process and reads the JSON result.
(base64Payload string)
| 81 | |
| 82 | // Parse sends a base64 payload to the PHP process and reads the JSON result. |
| 83 | func (p *PHPProcess) Parse(base64Payload string) (*ParseResult, error) { |
| 84 | p.mu.Lock() |
| 85 | defer p.mu.Unlock() |
| 86 | |
| 87 | // Send payload line. |
| 88 | if _, err := fmt.Fprintf(p.stdin, "%s\n", base64Payload); err != nil { |
| 89 | return nil, fmt.Errorf("write to PHP: %w", err) |
| 90 | } |
| 91 | |
| 92 | // Read response line. |
| 93 | line, err := p.stdout.ReadString('\n') |
| 94 | if err != nil { |
| 95 | return nil, fmt.Errorf("read from PHP: %w", err) |
| 96 | } |
| 97 | |
| 98 | var result ParseResult |
| 99 | if err := json.Unmarshal([]byte(line), &result); err != nil { |
| 100 | return nil, fmt.Errorf("unmarshal PHP response: %w", err) |
| 101 | } |
| 102 | |
| 103 | if result.Error != "" { |
| 104 | return nil, fmt.Errorf("PHP parser error: %s", result.Error) |
| 105 | } |
| 106 | |
| 107 | return &result, nil |
| 108 | } |
| 109 | |
| 110 | // Stop terminates the PHP process. |
| 111 | func (p *PHPProcess) Stop() { |
no outgoing calls