common-gateway / sim-xml-bundle
An example package for creating symfony flex bundles as plugins
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=7.4
- commongateway/corebundle: dev-master
Requires (Dev)
- symfony/dependency-injection: ~3.4|~4.1|~5.0
This package is auto-updated.
Last update: 2024-10-21 14:05:32 UTC
README
An example repository for creating php symfony flex bundles
Using this bundle
Installing with common-gateway admin user-interface
@todo!
Installing with php commands
To execute the following command you will need Composer or a dockerized installation which already has php and composer.
U can install this plugin by installing with command:
composer require common-gateway/sim-xml-bundle:dev-main
or dockerized: docker-compose exec php composer require common-gateway/sim-xml-bundle:dev-main
in the directory where your composer.json lives.
If you also want to install the schemas as entities you can install them with command:
php bin/console commongateway:install common-gateway/sim-xml-bundle
or dockerized: docker-compose exec php bin/console commongateway:install common-gateway/sim-xml-bundle
Creating your own bundle
Requirements
- GitHub account or organization
- Packagist account
- Composer or if your project is dockerized, Docker Desktop
Using this template
To create your own symfony bundle. You can copy this repository for a fast start.
- Login on GitHub
- Use this template
- Name your bundle (CamelCase)
- Press the green button
Create repository from template
- Update file names and namespace to your fitting
- Open composer.json, and change the name to your fitting. The first word should be the namespace and the second the name of your bundle. Check the autoload field to be set accordingly. Note: this is kebab-case. Also read: naming your package
- Open SimXmlBundle.php and change the Bundle name and namespace. The namespace should be the same as your package name in composer.json but in CamelCase. So common-gateway/sim-xml-bundle becomes CommonGateway/SimXMLBundle
- Rename the /Service and /ActionHandler accordingly (or delete if not used).
- Rename the /DependencyInjection/SimXmlExtension.php to your BundleNameExtension.php
- Rename the /Resources/config/services.yaml namespaces
Adding schemas
If you use your bundel with the common-gateway, you can add your own schemas that will be loaded as Entities. These Entities will be loaded into the database so you can work with your own objects/data.
These schemas are json schema's.
You can add existing schemas or create your own and add them in /Schema. There is also an example as /Schema/example.json.
Make sure your schema's have a version
property (required) so you can update your schema's!
Also make sure they have a unique $id
so that they can be related to other schema's.
All required properties are:
- 'version' can start on '0.1.0'
- '$schema' (https://json-schema.org/draft/2020-12/schema)
- '$id' (https://opencatalogi.nl/example.schema.json)
- 'type' must be 'object'
- 'properties' muste be schema properties
If you don't have all required properties in your schema the gateway won't install that schema and will claim it is invalid.
If you have added schema's you can also add objects/data for them, in /Data is an example you can use.
Upload to packagist
Before we can use our bundle and code, we must have it online on packagist so we can install with composer.
- Upload to packagist
- Go to Packagist
- Press
submit
in the top menu bar and paste your bundle's github repository link, the name from you composer.json will be used as package name. - If valid press
Submit
- Auto-update package
- Go to your packagist profile.
- Press
Show API Token
and copy - Go to your new bundle's github repository
- Go to your repository settings
- Go to webhooks, and press
Add webhook
- As Payload URL, set https://packagist.org/api/github?username=yourPackagistUsername
- Keep SSL verification enabled
- As secret, paste the copied API token from packagist
- Set event on
Just push the event
- Press
Add webhook
- If you push new code it will now push to packagis. On packagist you should not see the auto-update warning anymore. If its still there check if your username and secret are set properly on the github webhook.
Using your code
To use the code in your library we first have to install it with composer.
Note: for docker add docker-compose exec php
before all commands
- Navigate with a command line to where your composer.json lives in the project you want to use this bundle.
- Execute
composer require {full package name}:dev-main
- Docker users: restart your containers so symfony can recognize the new Bundle's namespace
- Execute
- Open a php file where you want to use a class.
- Add the correct use statement (example
use CommonGateway\SimXmlBundle\Service\SimXmlService;
) - U can now use your class!
- Add the correct use statement (example
In the common gateway, if you want to use your code when triggered by an event with a action, make sure the class of the action object is set as the handler name including the namespace. For example if I want to use the SimXmlService I can set the SimXmlHandler as CommonGateway\SimXmlBundle\ActionHandler\SimXmlHandler
.