0

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.

Simon Willan
  • 378
  • 3
  • 14
  • You could try increasing `xdebug.max_nesting_level` in your php.ini . Try setting it to 200, and then if that doesn't work try 1000. If that still doesn't fix your problem, something is most likely causing infinite recursion. If that's the case, debug with xdebug and determine where the first cyclic call is made that is recurring indefinitely as a first step to debugging the problem. – Paul Jun 17 '15 at 23:29
  • I assume just increasing the nesting level isn't really a fix, more of a work around? On my home computer I don't have xdebug installed. However I have commited to a new branch and will pull when I get to work where I DO have xdebug – Simon Willan Jun 17 '15 at 23:31
  • It's not obvious to me what is causing the error, but I suspect there is some sort of infinite recursion going on, in which case increasing the limit won't fix anything, but it will help provide evidence that my suspicion is correct. – Paul Jun 17 '15 at 23:34
  • Interestingly a Symfony requirement is setting `xdebug.max_nesting_level` to 250, and as Silex is mostly Symfony the same could be applied here. Source: https://github.com/symfony/symfony-standard/blob/2.7/app/SymfonyRequirements.php#L521 – Adam Elsodaney Jun 19 '15 at 09:13

1 Answers1

1

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.

Julien
  • 4,434
  • 3
  • 16
  • 19