Skip to content

Instantly share code, notes, and snippets.

@felipsmartins
Created August 25, 2016 20:32
Show Gist options
  • Select an option

  • Save felipsmartins/ddcc831cad40cfda345c08c8e35801ce to your computer and use it in GitHub Desktop.

Select an option

Save felipsmartins/ddcc831cad40cfda345c08c8e35801ce to your computer and use it in GitHub Desktop.
Convert campos de "decribe <table>" para propriedade de classes PHP
#!/usr/bin/env python
import sys
path = '/tmp/campos.txt'
campos = [l.strip().split(',') for l in open(path).readlines()]
attrs = ['type', 'null', 'key', 'default', 'extra']
doc_template = """
/**
* {}
*
* @var
*/
protected ${};
"""
for props in campos:
this_props = [p.replace("'", "") for p in props]
this_attrs = [":".join(x) for x in zip(attrs, this_props[1:])]
this_attrs = "; ".join(this_attrs)
print doc_template.format(this_attrs, this_props[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment