popo / symfony-bridge
Symfony bundle for POPO generator
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- popo/generator: ^6.3
- symfony/config: ^6.3
- symfony/dependency-injection: ^6.3
- symfony/http-kernel: ^6.3
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.2
README
Symfony bundle for POPO Generator.
Installation
composer require popo/symfony-bridge --dev
Setup
Create config/packages/popo.yaml
, and setup location of POPO schema files (e.g. config/packages/popo
).
Simple version
# config/packages/popo.yaml popo: config: - schemaPath: config/packages/popo
Full version
schemaPath
is required, all other options can be overwritten.
# config/packages/popo.yaml # schemaPath is required, other options can be defined in POPO schema file popo: default: # namespace: ExampleVendor\App\Example outputPath: tests namespaceRoot: ExampleVendor\ schemaPathFilter: # e.g. bundles schemaConfigFilename: # e.g. bundles/project.config.yml ignoreNonExistingSchemaFolder: false schemaFilenameMask: '*.popo.yaml' classPluginCollection: [] mappingPolicyPluginCollection: [] namespacePluginCollection: [] phpFilePluginCollection: [] propertyPluginCollection: [] config: # customer, settings here overwrite the default values - schemaPath: config/packages/popo/customer.popo.yaml # order, settings here overwrite the default values - schemaPath: config/packages/popo/order.popo.yaml # product, settings here overwrite the default values - schemaPath: config/packages/popo/product.popo.yaml # or simply load all at once - schemaPath: config/packages/popo
- See customer.popo.yaml
- See order.popo.yaml
- See product.popo.yaml
Usage
bin/console popo:generate
Generating POPO files... Customer:ExampleVendor\App\Customer\Customer -> tests/App/Customer/Customer.php Order:ExampleVendor\App\Order\Order -> tests/App/Order/Order.php Order:ExampleVendor\App\Order\OrderItem -> tests/App/Order/OrderItem.php Product:ExampleVendor\App\Product\Product -> tests/App/Product/Product.php All done.
See POPO Documentation for more options.
Extending generated classes with custom logic
Adding custom logic to generated POPO classes is easy with plugins.
For example to add helloWorld
method:
# config/packages/popo.yaml popo: default: classPluginCollection: - \PopoBundle\Plugin\HelloWorldPopoPlugin
HelloWorld plugin:
class HelloWorldPopoPlugin implements ClassPluginInterface { public function run(BuilderPluginInterface $builder): void { $builder->getClass() ->addMethod('helloWorld') ->setReturnType('string') ->setBody('return "Hello World";'); } }
Generated code:
public function helloWorld(): string { return "Hello World"; }
See POPO Plugins Documentation for more info.