https://github.com/jerodev/go-php-tools
A set of PHP language tools in Go
https://github.com/jerodev/go-php-tools
Last synced: about 1 month ago
JSON representation
A set of PHP language tools in Go
- Host: GitHub
- URL: https://github.com/jerodev/go-php-tools
- Owner: jerodev
- Created: 2024-04-07T16:22:02.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-24T14:19:25.000Z (about 1 year ago)
- Last Synced: 2025-01-02T06:55:29.478Z (about 1 year ago)
- Language: Go
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Go PHP Tools
A bundle of tools for interaction between Go and PHP written in Go
- [PHP Tools](#php-tools)
- [Laravel Tools](#laravel-tools)
- [Queue Redis job](#queue-redis-job)
- [Queue Broadcasting event](#queue-broadcasting-event)
## PHP Tools
### Serialize data
The `serialize()` functions takes a go variable and serializes it to PHP serialization format.
```go
package main
import (
"fmt"
"github.com/jerodev/go-php-tools/php"
)
type User struct {
Name string `php:"username"`
Age int `php:"age"`
}
func main() {
php, _ := php.Serialize(User{
Name: "Jerodev",
Age: 30,
})
fmt.Println(php) // O:4:"User":2:{s:8:"username";s:7:"Jerodev";s:3:"age";i:30;}
}
```
## Laravel Tools
### Queue Redis job
Queue a job on a queue that can be executed by a laravel queue worker.
The struct passed to the `NewQueueJob` function should match the data required in the actual PHP job class.
```go
package main
import (
"github.com/jerodev/go-php-tools/laravel"
"github.com/redis/go-redis/v9"
)
type Job struct {
Contents string `php:"contents"`
}
func main() {
job, _ := laravel.NewQueueJob("App\\Jobs\\LaravelTestJob", Job{
Contents: "Lorem Ipsum",
})
conn := laravel.NewRedisQueueClient("LaraQueue", &redis.Options{
Addr: "127.0.0.1:6379",
})
conn.Dispatch(job)
}
```
### Queue Broadcasting event
In the same way that this package can queue jobs, it can also queue broadcasting events to be picked up by your Laravel
application or Laravel Reverb.
```go
package main
import (
"github.com/jerodev/go-php-tools/laravel"
"github.com/redis/go-redis/v9"
)
type OrderUpdated struct {
OrderId int `php:"order_id"`
}
func main() {
job, _ := laravel.NewBroadcastEvent("App\\Events\\OrderUpdated", OrderUpdated{
OrderId: 42,
})
conn := laravel.NewRedisQueueClient("LaraQueue", &redis.Options{
Addr: "127.0.0.1:6379",
})
conn.Dispatch(job)
}
```