Symfony / Silex maximum function nesting level

139 views Asked by At

I have a Silex application with a few services registered.

$app->register(new \Silex\Provider\TranslationServiceProvider(), array(
    'locale_fallbacks' => array('en'),
    'translator.message' => array()
));

$app->register(new \Silex\Provider\SecurityServiceProvider(), array(
  'security.firewalls' => array(
    'login' => array(
        'pattern' => '^/admin/login$'
    ),
    'secured' => array(
        'pattern' => '^/admin/?.*$',
        'form' => array(
            'login_path'          => '/admin/login',
            'check_path'          => '/admin/login_check',
            'always_use_default_target_path' => true,
            'default_target_path' => '/admin/en',
            'failure_path'        => '/admin/login'
        ),
        // users are added from custom user repository
        'users' => $app->share(function() use ($app) {
            return $app['syn.user_repo'];
        })
    )
  )
));

$app['syn.user_repo'] = $app->share(function($app) {
    return new \Synergy\Application\User\UserRepository($app);
});

The User Repository returns a User() object with the credentials needed to log in. Everything works fine. However User(), is given access to the $app application variable. which it uses to set a member level _translator variable. See below:

class User implements UserInterface
{
    protected $_translator;

    public function __construct($data = array(), $app)
    {
        $this->_translator = $app['translator'];
    }

    ........

If I set $this->_translator, I get this error (which repeats a 100 times):

Fatal error: Maximum function nesting level of '100' reached, 
aborting! in var/www/silex.dev/vendor/symfony/debug/Exception/FlattenException.php
on line 261 Call Stack: 0.0000 6356.......

I don't understand why this is happening. I cannot set any symfony service as member level without this error occurring.

Does any one know what this might be?

Edit: I'm beginning to think this is a problem with storing a reference to something that contains Symfony Application within my UserRepo as a property, and only as part of the Security Service. I can do that usually, but when in relation to Security Service it breaks.

1

There are 1 answers

0
Julien On

I know this is an old question, but in case it helps someone new...

I had this error and finally found out why: I had defined a Controller Service which tried to include itself, something like:

$app['services.puppy'] = $app->share(function () use ($app) {
    return new PuppyService(
        $app['providers.puppy'],
        $app['services.kitten'],
        $app['services.doggy'],
        $app['services.puppy'] // This is the culprit
    );
});

I blame too much coffee and sleepless nights.