Welcome to the NamiCoreBundle repository - a Symfony 2.7 bundle.
PhpInk\Nami\CoreBundle is the main bundle of a Nami CMS application. It contains the dependencies configuration, Doctrine ORM/ODM mapping and FOSRest controllers to provide an API.
- Installation
Run the following command to install the bundle :
composer require phpink/nami-core-bundle
To get NAMI working with MongoDB, after specifying the configuration driver to ''odm''' instead of '''orm''', add the following line to your composer.json :
"doctrine/mongodb-odm-bundle": "3.0.*@dev",
Then, add the following line to your AppKernel.php :
new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
Run the following OpenSSL commands to generate RSA keys for JSON Web Token authentication :
openssl genrsa -out app/var/jwt/private.pem -aes256 4096
openssl rsa -pubout -in app/var/jwt/private.pem -out app/var/jwt/public.pem
- API endpoints
All available endpoints are available in a Postman dump
nami.postman_collection
Some http client you can run to test the API :
GET http://host/api-doc/ REST API documentation [HTML]
GET http://host/api/ REST API ping [JSON]
POST http://host/api/token API token getter [JSON]
GET http://host/api/pages API get all method [JSON]
GET http://host/api/pages/1 API get one method [JSON]
POST http://host/api/pages/1 API update one method [JSON]
DELETE http://host/api/pages/1 API delete one method [JSON]
The bundle is configured with the following defaults:
-
Twig is the only configured template engine;
-
Translations are activated
-
Doctrine ORM/DBAL or Doctrine MongoDB is configured;
-
Swiftmailer is configured;
-
Annotations for everything are enabled.
It comes pre-configured with the following bundles:
-
FrameworkBundle - The core Symfony framework bundle
-
SensioFrameworkExtraBundle - Adds several enhancements, including template and routing annotation capability
-
DoctrineBundle - Adds support for the Doctrine ORM
-
DoctrineMongoDBBundle - Adds support for the Doctrine ODM
-
DoctrineExtensions - Doctrine2 behavioral extensions
-
DoctrineFixtures (in dev/test env) - Load data fixtures into the Doctrine ORM
-
TwigBundle - Adds support for the Twig templating engine
-
SecurityBundle - Adds security by integrating Symfony's security component
-
SwiftmailerBundle - Adds support for Swiftmailer, a library for sending emails
-
MonologBundle - Adds support for Monolog, a logging library
-
AsseticBundle - Adds support for Assetic, an asset processing library
-
WebProfilerBundle (in dev/test env) - Adds profiling functionality and the web debug toolbar
-
SensioDistributionBundle (in dev/test env) - Adds functionality for configuring and working with Symfony distributions
-
SensioGeneratorBundle (in dev/test env) - Adds code generation capabilities
-
FOSRestBundle - Adds rest functionality
-
FOSHttpCacheBundle - This bundle offers tools to improve HTTP caching with Symfony2
-
NelmioApiDocBundle - Add API documentation features
-
BazingaHateoasBundle - Adds HATEOAS support
-
HautelookTemplatedUriBundle - Adds Templated URIs (RFC 6570) support
-
LexikJWTAuthenticationBundle - JSON Web Token generation
-
GfreeauGetJWTBundle - JSON Web Token authentication
-
LiipImagineBundle - Image thumbnail generation
Enjoy!
CoreBundle controllers extend a base AbstractController
, which contains a set of methods for the Doctrine CRUD worflow.
Associated Doctrine model/repository & FormType class names are guessed automatically.
For example: NamiCoreBundle:Model\Orm\User
entity & NamiCoreBundle:Form\UserType
for NamiCoreBundle:Controller\UserController
.
The doctrine repository used by the controller to run the generic CRUD commands is the one associated by default to the model. A different one can be called :
public function getEntitiesAction() {
$productRepo = $this->getRepository('Product'); // From model name
// or
$productRepo = $this->getRepository('\PhpInk\Nami\CoreBundle\Model\Orm\Products'); // More specific
...
return $this->restView(...); // Returns a JSON response
}
Core repositories extend a base AbstractRepository
, which contains all the CRUD methods called from controllers.
Repositories can overload the base properties, such as orderByFields
, filterByFields
.
They must implement a buildItemsQuery
method that will be called to create the Doctrine QueryBuilder retrieving one or more item from the database.
As for creation & update, the controllers instantiate the form type related to the associated model.
A JsonDecoder is implemented and modifies the input request data.
It is called from the FosRest body listener (configuration is in
src/PhpInk/CoreBundle/DependencyInjection/NamiCoreBundleExtension.php
).
It transforms json input booleans true,false
into optional 0,1
checkboxes for FormTypes.
To execute specific code after an item creation or update, take a look at the UserController::onPostSave
method that sends the user confirmation mail.