We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to configure symfony components in phalcon project

I am trying to use Symfony's security component in a phalcon project. I read symfony security.yml documentation but I am not sure how that configuration gets injected and how can I make it available in phalcon project.

So far, I have configured TokenStorage as a service in phalcon services.php

/**
* Symfony TokenStorage
 */
$di->setShared( 'tokenStorage', function () use ( $di )
{
    $session = $di->getSession();
    if ( $session->has( 'tokenStorage' ) )
    {
        return $session->get( 'tokenStorage' );
    } else
    {
        $session->set( 'tokenStorage', new \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage(
                                 $di[ 'authProvider' ]
                             )
        );

        return $session->get( 'tokenStorage' );

    }
}
);

Any help much appreciated. Thanks in advance.



43.9k

Hi,

well, did you already load your symphony components (with composer autoload, or any other way to do that) ?

and what happends when you call "tokenStorage" elsewhere in your app ? (I mean any error message) ?



2.4k

Yes, I have loaded symfony security components using composer. I can use tokenStorage elsewhere in the system. However at the moment I am not using symfony's authentication mechanism as it requires yml file configuration and i dont know how do i get started with yml configuration for symfony component in phalcon.

Maybe im stupid, but why use symfony here anyway? What's wrong with phalcon ACL + dispatcher beforeRouteExecute?