Creating Graviton Services
Services
Generating a Service
The service generator MAY be called as follows.
php app/console graviton:generate:resource --entity=GravitonFooBundle:Bar --format=xml --fields="name:string" --with-repository --no-interaction
Please refer to php app/console generate:doctrine:entities --help
for further usage information.
After generating a new service you MUST review the code before committing it proper.
Service Anatomy
Each graviton service SHALL consist of the following files. The following example was taken from the /core/app
service.
File/Directory | Description |
---|---|
src/Graviton/CoreBundle |
bundle directory, contains all the files related to a bundle |
src/Graviton/CoreBundle/Controller/AppController.php |
controller for /core/app service, MUST extend Graviton\RestBundle\Controller\RestController |
src/Graviton/CoreBundle/DataFixtures/MongoDB/LoadAppData.php |
fixture loader, loads fixtures on initial install and during testing, MUST implement Doctrine\Common\DataFixtures\FixtureInterface |
src/Graviton/CoreBundle/Document/App.php |
service document, access a single instance of an item, SHOULD implement Graviton\I18nBundle\Document\TranslatableDocumentInterface |
src/Graviton/CoreBundle/Model/App.php |
service mode, wrapper around document and repository, adds schema information for a service, MUST extend Graviton\RestBundle\Model\DocumentModel |
src/Graviton/CoreBundle/Repository/AppRepository.php |
service repository, access collections of documents, MUST extend Doctrine\ODM\MongoDB\DocumentRepository |
src/Graviton/CoreBundle/Resources/config/doctrine/App.mongodb.xml |
MongoDB config, defines how data is persisted |
src/Graviton/CoreBundle/Resources/config/schema/App.json |
model config, schema information for the service |
src/Graviton/CoreBundle/Resources/config/serializer/Document.App.xml |
serializer config, defines how data is serialized and deserialized to the client |
src/Graviton/CoreBundle/Resources/config/services.xml |
DIC configuration, define services for classes needed by the service |
src/Graviton/CoreBundle/Resources/config/validation.xml |
Validation constraints for service data |
src/Graviton/CoreBundle/Tests/Controller/AppControllerTest.php |
service tests, e2e tests that make later refactoring possible, MUST extend Graviton\TestBundle\Test\RestTestCase |
You MAY look at CoreBundles code to see this in action.
If you want to manually create a service you MUST implement all the above elements. It is RECOMMENDED that you use the aformentioned graviton:generate:resource
for all you service creation needs.