2017 © Pedro PelĆ”ez
 

symfony-bundle nami-core-bundle

Nami CMS - CORE Bundle

image

phpink/nami-core-bundle

Nami CMS - CORE Bundle

  • Sunday, June 5, 2016
  • by geofrwa
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Welcome to the NamiCoreBundle repository - a Symfony 2.7 bundle., (*1)

Nami Logo, (*2)

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., (*3)

1) Installation

Getting started

Run the following command to install the bundle :, (*4)

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 :, (*5)

        "doctrine/mongodb-odm-bundle": "3.0.*@dev",

Then, add the following line to your AppKernel.php :, (*6)

        new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),

Generate new RSA keys [optional]

Run the following OpenSSL commands to generate RSA keys for JSON Web Token authentication :, (*7)

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

2) API endpoints

All available endpoints are available in a Postman dump, (*8)

nami.postman_collection

Some http client you can run to test the API :, (*9)

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]

What's inside?

The bundle is configured with the following defaults:, (*10)

  • Twig is the only configured template engine;, (*11)

  • Translations are activated, (*12)

  • Doctrine ORM/DBAL or Doctrine MongoDB is configured;, (*13)

  • Swiftmailer is configured;, (*14)

  • Annotations for everything are enabled., (*15)

It comes pre-configured with the following bundles:, (*16)

Enjoy!, (*40)

API inner working

Controllers

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., (*41)

For example: NamiCoreBundle:Model\Orm\User entity & NamiCoreBundle:Form\UserType for NamiCoreBundle:Controller\UserController., (*42)

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 :, (*43)

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
}

Repositories

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., (*44)

They must implement a buildItemsQuery method that will be called to create the Doctrine QueryBuilder retrieving one or more item from the database., (*45)

As for creation & update, the controllers instantiate the form type related to the associated model., (*46)

Json TO Forms

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)., (*47)

It transforms json input booleans true,false into optional 0,1 checkboxes for FormTypes., (*48)

To execute specific code after an item creation or update, take a look at the UserController::onPostSave method that sends the user confirmation mail., (*49)

The Versions