M
M
Maxim2015-09-25 17:37:18
symfony
Maxim, 2015-09-25 17:37:18

How to use Bundle inheritance to overwrite bundle parts?

I would like to clarify some points regarding the inheritance of bundles.
I'm reading the FOSUserBundle documentation, it shows how inheritance works.

// src/Acme/UserBundle/AcmeUserBundle.php

namespace Acme\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeUserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

The question arises, is that all? The inheritance itself is achieved by the line "return 'FOSUserBundle';"
those. Can I also inherit other bundles? just by specifying return 'Your own bundle';?
and another nuance that interests me:
do I need to write my own routes?
I understand that if you leave everything as it is and go, for example, by /login, the main bundle and its controllers will work?
UPD
If you take a rewrite of the controller
namespace Acme\UserBundle\Controller;
 
use FOS\UserBundle\Controller\RegistrationController as BaseController;
 
class RegistrationController extends BaseController
{
    public function registerAction()
    {
        $response = parent::registerAction();
        // ... do custom stuff
        return $response;
    }
}

here it is clear that the parent controller belongs to that bundle

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-09-25
@maxpointn2point

concerning inheritance of bundles.

do not inherit bundles. And in general, bundles are from the evil one, but still, what kind of AppBundle can you leave. In other cases, bundles should be strictly independent, not inherited from anyone, and simply register services into the system.
Yes, in this way you tell which other kernel extension your extension is associated with, then the kernel will process everything in the right order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question