conserto / pomm-bundle
The Symfony bundle for Pomm
Installs: 7 178
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 0
Forks: 31
Type:symfony-bundle
Requires
- php: >=8.1
- conserto/pomm-cli: ^3.0
- conserto/pomm-model-manager: ^3.0
- conserto/pomm-symfony-bridge: ^4.0
- jdorn/sql-formatter: ~1.2
- symfony/framework-bundle: ^6.0|^7.0
- symfony/http-kernel: ^6.2|^7.0
- twig/twig: ~3.0
Requires (Dev)
- phpstan/phpstan: ^1.8
- squizlabs/php_codesniffer: ~3.7
- symfony/console: ^6.0|^7.0
Suggests
- symfony/web-profiler-bundle: Display queries log
- dev-main
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.x-dev
- 5.0.1
- 5.0.0
- 4.0.x-dev
- 4.0.1
- 4.0.0
- 3.0.0
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.2
- 2.3.1
- 2.3.0
- 2.3.0-rc.3
- 2.3.0-rc.2
- 2.3.0-rc.1
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- dev-feat/v5.1.0
- dev-feat/fix_containerawaretrait_deprecated
- dev-merge/5.0
- dev-fix/bundle_deprecations
- dev-fix/ci_tests
- dev-mdou/remove_sensio_framework_extra_bundle
- dev-report_forked_fixes_and_improvements
- dev-develop
This package is auto-updated.
Last update: 2024-10-11 14:08:14 UTC
README
This is a fork of the Pomm bundle component for the Pomm database framework.
This bundle provides a pomm
service to use the Pomm Model Manager with Symfony.
Note:
If you are looking for a bundle for Pomm 2.x then look up for pomm-project/pomm-bundle
on packagist.
If you are looking for a bundle for Pomm 1.x then look up for pomm/pomm-bundle
on packagist.
Installation
composer require conserto/pomm-bundle
Configuration
In the app/config
folder, store your db connection parameters in parameters.yml
:
parameters: db_host1: 127.0.0.1 db_port1: 5432 db_name1: my_db_name db_user1: user db_password1: pass db_host2: 127.0.0.1 # etc.
Sensitive information such as database credentials should not be committed in Git. To help you prevent committing those files and folders by accident, the Symfony Standard Distribution comes with a file called .gitignore which list resources that Git should ignore, included this parameters.yml
file.
You can now refer to these parameters elsewhere by surrounding them with percent (%).
Add an entry in config.yml
:
pomm: configuration: my_db1: dsn: "pgsql://%db_user1%:%db_password1%@%db_host1%:%db_port1%/%db_name1%" pomm:default: true my_db2: dsn: "pgsql://%db_user2%:%db_password2%@%db_host2%:%db_port2%/%db_name2%" session_builder: "pomm.session_builder" logger: service: "@logger"
And in routing_dev.yml
:
_pomm: resource: "@PommBundle/Resources/config/routing.yml" prefix: /_pomm
Command line interface
The Pomm CLI is available through the bin/console
utility. It is possible to browse the database or to generate model files.
$ ./bin/console pomm:generate:relation-all -d src -a 'AppBundle\Model' my_db1 student
If you want generate schema, you need to use the model manager session builder:
pomm: configuration: my_db1: dsn: "pgsql://%db_user1%:%db_password1%@%db_host1%:%db_port1%/%db_name1%" session_builder: "pomm.model_manager.session_builder"
Using Pomm from the controller
The Pomm service is available in the DIC as any other service:
function myAction($name) { $students = $this->get('pomm')['my_db2'] ->getModel('\AppBundle\Model\MyDb1\PublicSchema\StudentModel') ->findWhere('name = $*', [$name]) ; …
It is now possible to tune and create a model layer as described in the quick start guide.
Value resolver
This bundle provide a value resolver to convert request to a flexible entity. The resolver search in the request the parameters with names matching primary key.
You can specify witch connexion use in the attribute #[Entity]:
public function getAction(#[Entity('my_db2')] Student $student)
By default, the model used for find the entity is deduce by adding Model
to
entity class name. If you have a different class name, you can use the modelClass
option:
public function getAction(#[Entity(modelClass: 'StudentModel')] Student $student)
This feature require symfony/http-kernel.
Serializer
You can use the serializer component to serialize entities.
Property info
This bundle also provide property info support to retrieve flexible entity properties informations.
Poolers as service
If you need to add additional poolers into the session builder all you need to do is tag a service definition with pomm.pooler
Model and Model layer as a service
Model and model layer objects can be registered as a service.
For this to work properly you have to tag your service correctly and remove class:session_builder
from configuration.
Models must be tagged with pomm.model
and layers with pomm.model_layer
Both of those tags have the following parameters:
pooler
which is the name of a default pooler service, if left blank the default is usedsession
which is the name of a default session service this is used from, if left blank the default is used