Coder Social home page Coder Social logo

mweibel / php-to-go Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 1.0 33 KB

Library for generating Go structs using sheriff out of PHP models which use JMS Serializer.

License: MIT License

Go 18.26% PHP 81.74%
marshalling json reflection go php jms-serializer

php-to-go's Introduction

php-to-go

Build Status Coverage Status

Library for generating Go structs using sheriff out of PHP models which use JMS 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
// where to find your models
$srcGlob = './models/*.php';
// target directory of your Go files. Needs to be within $GOPATH.
$targetDirectory = getenv('GOPATH').'/src/github.com/mweibel/php-to-go-tests';
// package name of the Go structs
$packageName = 'models';
// list of ignored files within the target directory
$ignoredFiles = [];
// list of ignored property names (in case some are misbehaving or so)
$ignoredPropertyNames = [];
// echo what is being done
$verbose = true;

$generator = new PHPToGo\CodeGenerator($srcGlob, $targetDirectory, $packageName, $ignoredFiles, $ignoredPropertyNames, $verbose);
$generator->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:

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.

License

MIT (see LICENSE).

php-to-go's People

Contributors

michellesanver avatar mweibel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

michellesanver

php-to-go's Issues

Example of delegating serialization to Go needed

Can be used to turn an existing serialization solution using PHP and JMS Serializer into one based on Go and sheriff.

Could you please share an example of inflating structures in Go with the data from PHP?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.