https://github.com/mweibel/php-to-go
Library for generating Go structs using sheriff out of PHP models which use JMS Serializer.
https://github.com/mweibel/php-to-go
go jms-serializer json marshalling php reflection
Last synced: 11 months ago
JSON representation
Library for generating Go structs using sheriff out of PHP models which use JMS Serializer.
- Host: GitHub
- URL: https://github.com/mweibel/php-to-go
- Owner: mweibel
- License: mit
- Created: 2018-02-24T08:15:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-26T14:34:09.000Z (about 8 years ago)
- Last Synced: 2025-07-25T11:27:18.369Z (11 months ago)
- Topics: go, jms-serializer, json, marshalling, php, reflection
- Language: PHP
- Homepage:
- Size: 32.2 KB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-to-go
[](https://travis-ci.org/mweibel/php-to-go)
[](https://coveralls.io/github/mweibel/php-to-go?branch=master)
Library for generating Go structs using [sheriff](https://github.com/liip/sheriff) out of PHP models which use [JMS Serializer](https://jmsyst.com/libs/serializer).
## Status
Alpha.
Has not been tested in real production workload yet. Has been tested locally against a test system using big models and quite some data.
Documentation of what it does should become better too.
## Contributions
Contributions in any form are welcome.
I try to keep this library as small as possible. If you plan a big PR it might be better to ask first in an issue.
If you change PHP code please ensure to accompany it with an automated test.
## Why
Can be used to turn an existing serialization solution using PHP and JMS Serializer into one based on Go and sheriff.
## How
```php
generate();
```
The generated files can then be incorporated into any Go program.
The code generator detects if there are methods annotated using `VirtualProperty`.
In this case the generated model needs an AfterMarshal function receiver on that type.
As the code generator will overwrite the files it generated (on repeated execution), customizations to the generated types
should go into a separate file.
Example noop `AfterMarshal` function on a type called `RootModel`:
```go
package models
import "github.com/liip/sheriff"
func (rm RootModel) AfterMarshal(options *sheriff.Options, data interface{}) (interface{}, error) {
return data, nil
}
```
If you want to interface with existing PHP code you can use e.g. [goridge](https://github.com/spiral/goridge).
# License
MIT (see LICENSE).