php: Move server code into new phpx package

This commit is contained in:
Tom Wiesing 2022-10-19 13:52:24 +02:00
parent 4df5f6387c
commit 2e47626900
No known key found for this signature in database
13 changed files with 134 additions and 86 deletions

35
internal/phpx/errors.go Normal file
View file

@ -0,0 +1,35 @@
package phpx
import "fmt"
// Common PHP Errors
const (
errInit = "Server initialization failed"
errClosed = "Server closed"
errReceive = "Failed to decode response"
)
// PHPError represents an error during PHPServer logic
type ServerError struct {
Message string
Err error
}
// Unwrap returns the underlying error
func (err ServerError) Unwrap() error {
return err.Err
}
func (err ServerError) Error() string {
if err.Err == nil {
return fmt.Sprintf("PHPServer: %s", err.Message)
}
return fmt.Sprintf("PHPServer: %s: %s", err.Message, err.Err)
}
// Throwable represents an error during php code
type Throwable string
func (throwable Throwable) Error() string {
return string(throwable)
}