2017 © Pedro Peláez
 

symfony-bundle message-bundle

A user-to-user message bundle for Symfony2

image

cunningsoft/message-bundle

A user-to-user message bundle for Symfony2

  • Friday, July 7, 2017
  • by dmecke
  • Repository
  • 1 Watchers
  • 0 Stars
  • 64 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Installation

  1. Add the following to your composer.json file:, (*1)

    // composer.json
    {
        // ...
        require: {
            // ...
            "cunningsoft/message-bundle": "0.1.*"
        }
    }
    
  2. Run composer update cunningsoft/message-bundle to install the new dependencies., (*2)

  3. Register the new bundle in your AppKernel.php:, (*3)

    <?php
    // in AppKernel::registerBundles()
    $bundles = array(
        // ...
        new Cunningsoft\MessageBundle\CunningsoftMessageBundle(),
        // ...
    );
    
  4. Let your user entity implement the Cunningsoft\MessageBundle\Entity\UserInterface:, (*4)

    // Acme\ProjectBundle\Entity\User.php
    <?php
    
    namespace Acme\ProjectBundle\Entity;
    
    use Cunningsoft\MessageBundle\Entity\UserInterface as MessageUserInterface;
    
    class User implements MessageUserInterface
    {
        /**
         * @var int
         */
        protected $id;
    
        /**
         * @var string
         */
        protected $username;
    
        /**
         * @return int
         */
        public function getId()
        {
            return $this->id;
        }
    
        /**
         * @return string
         */
        public function getUsername()
        {
            return $this->username;
        }
        // ...
    
  5. Map the interface to your user entity in your config.yml:, (*5)

    // app/config/config.yml
    // ...
    doctrine:
        orm:
            resolve_target_entities:
                Cunningsoft\MessageBundle\Entity\UserInterface: Acme\ProjectBundle\Entity\User
    
  6. Update your database schema:, (*6)

    $ app/console doctrine:schema:update
    
  7. Import routes:, (*7)

    // app/config/routing.yml
    // ...
    cunningsoft_message_bundle:
        resource: "@CunningsoftMessageBundle/Controller"
        type: annotation
    
  8. Link to the messages list:, (*8)

    // src/Acme/ProjectBundle/Resources/views/Default/index.html.twig
    // ...
    <a href="{{ path('cunningsoft_message_list') }}">messages</a>
    // ...
    
  9. Create a child bundle to fetch users, (*9)

    mkdir src/Acme/MessageBundle
    
    // src/Acme/MessageBundle/AcmeMessageBundle.php
    <?php
    
    namespace Acme\MessageBundle;
    
    use Symfony\Component\HttpKernel\Bundle\Bundle;
    
    class AcmeMessageBundle extends Bundle
    {
        public function getParent()
        {
            return 'CunningsoftMessageBundle';
        }
    }
    
    // src/Acme/MessageBundle/Controller/MessageController.php
    <?php
    
    namespace Acme\MessageBundle\Controller;
    
    use Cunningsoft\MessageBundle\Controller\MessageController as BaseController;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    
    /**
     * @Route("/message")
     */
    class MessageController extends BaseController
    {
        public function findUser($id)
        {
            return $this->get('doctrine.orm.entity_manager')->getRepository('AcmeProjectBundle:User')->find($id);
        }
    
        public function findAllUsers()
        {
            return $this->get('doctrine.orm.entity_manager')->getRepository('AcmeProjectBundle:User')->findAll();
        }
    }
    

Changelog

  • 0.1 (master) First working version.

The Versions

07/07 2017

dev-master

9999999-dev https://github.com/dmecke/MessageBundle

A user-to-user message bundle for Symfony2

  Sources   Download

MIT

The Requires

 

message communication