Download the PHP package popo/generator without Composer
On this page you can find all versions of the php package popo/generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popo/generator
More information about popo/generator
Files in popo/generator
Package generator
Short Description Plain Old PHP Object (POPO) / Data Structure / Data Transfer Object (DTO) Generator. Convert YAML schema to PHP class.
License MIT
Informations about the package generator
POPO
POPO - "Plain Old Php Object" was inspired by "Plain Old Java Object" (POJO) concept.
POPO generator can also locate, load, validate, and combine schemas to create PHP source code files, representing Arrays / Data Structures / Data Transfer Objects / Doctrine ORM Entities / MongoDB ODM Documents.
POPO Schema can be defined and extended on few levels, and it can be defined in multiple files.
Examples
Single schema file
Simple schema in YAML format, describing properties and relations of POPO objects.
Multiple schema files
The same example can be split into multiple files. However, this time, it's the Bar
that modifies the Foo
definition.
The generated code is the same, but the schema dependencies are inverted.
In both cases, Foo
object uses Bar
object as its dependency, and they are both defined under Example
schema name.
Generated code usage examples
Instantiate data structure from an array.
Output:
Display hierarchy of objects as an array.
Output:
Run bin/popo generate -s tests/fixtures/popo-readme.yml
or docker-popo generate -s tests/fixtures/popo-readme.yml
to generate files from this example.
Installation
Note: The installation can be skipped when using docker, see Docker support section.
Usage
You can either use it as composer dependency or as docker command.
-
Define schema file, see tests/fixtures for examples.
-
Generate POPO files, run:
-
with composer
- with docker
-
For example: bin/popo generate -s tests/fixtures/popo.yml
or docker-popo generate -s tests/fixtures/popo.yml
.
POPO Schema
POPO Schema can be defined and extended on few levels- and it can be defined in multiple files.
The schema supports key mapping- inheritance- collections and encapsulation of other POPO objects.
Schema Definition
Schema configuration options
namespace
Defines generated class namespace.
outputPath
Defines output directory.
namespaceRoot
Defines the begging of outputPath
that should be removed.
For example to generated files under src/Example
with App\Example
namespace.
extend
Which class should the generated class extend from. Must start with \ or contain ::class
.
implement
Which interface should the generated class implement. Must start with \ or contain ::class
.
comment
Class comment.
phpComment
Generated PHP file comment.
use
Import statements.
trait
Traits statements.
attribute
Class attributes value.
attributes
: array
Attribute value as collection. Supported values:
name
value
:mixed
classPluginCollection
: array
Additional plugins used to generate methods.
namespacePluginCollection
: array
Additional plugins used to generate namespace block.
propertyPluginCollection
: array
Additional plugins used to generate properties.
mappingPolicyPluginCollection
: array
Set of plugins used to map property names, e.g. fooId
=> FOO_ID
.
Property configuration options
name
The name of the property. The property related methods will be generated based on this value. For example getFooBar()
.
This is required parameter.
type
Property data type, supported are:
array
bool
float
int
string
mixed
const
popo
datetime
Default property type is string
.
comment
Docblock value for property and methods.
default: mixed
Default value.
extra: array
Used by datetime
data type. Supported values:
format
timezone
itemType
Used by array
data type together with itemName
element. Describes type of single array element.
itemName
Used by array
data type. Describes name of single array element. For example: setProducts(array $products)
, addProduct(Product $item)
.
attribute
Attribute value.
attributes
: array
Attribute value as collection. Supported values:
name
value
:mixed
mappingPolicy: array
Dynamically remaps property names, for example, fooId
=> FOO_ID
. Supported values:
none
lower
upper
camel-to-snake
snake-to-camel
mappingPolicyValue
Statically remaps property names, for example, fooId
=> FOO_ID
.
Schema Inheritance
The popo-config
values override schema-file-config
values- and schema-file-config
values overwrite schema-config
values.
On top of that there is a global-config
that is defined when using --schemaConfigFilename
parameter.
schema-config
The configuration was defined as a Schema
property.
It will be used by all POPO objects in all files under given schema.
schema-file-config
The configuration was defined as a SchemaFile
property.
It will be used by all POPO objects in current file.
popo-config
The configuration was defined as a POPO
property.
It will be used by one specific POPO objects in current file.
See tests/fixtures for schema examples.
Property name remapping
POPO can remap property keys names, for example change foo_id
into fooId
.
See Property Name Remapping doc.
Pluggable architecture
New functionality can be provided on the command line, or via configuration.
See Plugins doc.
Doctrine Support
See Doctrine Support doc.
Command line options
See Command Line Options doc.
More Examples
See tests for more usage examples.
Composer script
Add popo scrip to composer and run composer popo
in a project.
Docker support
With docker you can generate files without installing POPO
as dependency in the project.
You can either run the command directly, or create an alias, e.g.:
For example:
See also: bin/docker-popo.
PHP version compatibility
- POPO
v1.x
- PHP 7.2+ - POPO
v2.x
- PHP 7.2+ - POPO
v3.x
- PHP 7.4+ - POPO
v4.x
- PHP 7.4+ - POPO
v5.x
- PHP 7.4+ - POPO
v6.x
- PHP 8+
POPO schema example
Schema example that produces generated PopoConfigurator class.
All versions of generator with dependencies
ext-ctype Version *
symfony/finder Version ^5|^6
symfony/console Version ^5|^6
symfony/yaml Version ^5|^6
nette/php-generator Version ^4
symfony/config Version ^5|^6
symfony/dependency-injection Version ^5|^6