Circular dependency test for #5651 #5948

Closed
wants to merge 2 commits into from

4 participants

@radnan

Additional test #5651 to check for circular dependencies and make sure loading a module from another module does not end up in an infinite loop.

@weierophinney weierophinney added this to the 2.3.1 milestone Mar 11, 2014
@Ocramius Ocramius closed this in 3d4c5a2 Apr 3, 2014
@Ocramius Ocramius added a commit that referenced this pull request Apr 3, 2014
@Ocramius Ocramius Merge branch 'tests/#5948-circular-dependency-tests-for-module-manage…
…r-init' into develop

Close #5948
Forward Port #5948
34b1cef
@Ocramius Ocramius self-assigned this Apr 3, 2014
@rettal

sorry to necro this but I'm getting this error now.

I can't work it out as I am only loading one module with bare bones app?

here is my SM config from module.config.php in my module:

(If i uncomment the lines in MyAuthStorage anon function, it works? (it doesn't throw error)

'service_manager' => array(
        'abstract_factories' => array(
            'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
            'Zend\Log\LoggerAbstractServiceFactory',
        ),
        'aliases' => array(
            'translator' => 'MvcTranslator',
        ),

        'factories'=>array(
            'MyAuthStorage' => function($sm) {
                    $namespace = 'zf_tutorial';
                    $member = null; //
                    $sessionManager = null;
                    $id = null;

                    //if ($sm->get('MyAuthService')->hasIdentity()) {
                        //$id = "259aa0dd6cd9465e193e753c6dcf38c4";
                    //}

                    return new \Application\Model\MyAuthStorage(
                        'zf_tutorial',
                        $member,
                        $sessionManager,
                        "259aa0dd6cd9465e193e753c6dcf38c4"
                    );
                },
            'MyAuthService' => function($sm) {
                    $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                    $dbTableAuthAdapter  = new Zend\Authentication\Adapter\DbTable\CredentialTreatmentAdapter($dbAdapter, 'users','username','password');

                    $authService = new \Application\Service\MyAuthService();
                    $authService->setAdapter($dbTableAuthAdapter);
                    $authService->setStorage($sm->get('MyAuthStorage'));

                    return $authService;
                },
            ),
    ),

Here is MyAuthStorage:

<?php

namespace Application\Model;

use Zend\Authentication\Storage;

class MyAuthStorage extends Storage\Session
{
    /**
     * Sets session storage options and initializes session namespace object
     *
     * @param mixed $namespace
     * @param mixed $member
     * @param SessionManager $manager
     */
    public function __construct($namespace = null, $member = null, SessionManager $manager = null, $id = null)
    {
        if ($id == null) {
            $sid = hash('md5', date("Y-m-d"));
        } else {
            $sid = $id;
        }
        session_id($sid);
        parent::__construct($namespace, $member, $manager);
    }

    public function setRememberMe($rememberMe = 0, $time = 1209600)
    {
         if ($rememberMe == 1) {
             $this->session->getManager()->rememberMe($time);
         }
    }

    public function forgetMe()
    {
        $this->session->getManager()->forgetMe();
    }

    public function setId($id)
    {
        $this->session->getManager()->setId($id);
    }
}

Here is MyAuthService:

<?php

namespace Application\Service;

class MyAuthService extends \Zend\Authentication\AuthenticationService
{
    /**
     * Constructor
     *
     * @param Storage\StorageInterface $storage
     * @param Adapter\AdapterInterface $adapter
     */
    public function __construct(Storage\StorageInterface $storage = null, Adapter\AdapterInterface $adapter = null)
    {
        parent::__construct($storage, $adapter);
    }
}

And here is the error:

File:

    C:\wamp\www\zf2\app\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:918

Message:

    Circular dependency for LazyServiceLoader was found for instance MyAuthStorage

Again, apologies for the necro but I just can't grok it? Thank you in advance :)

@gianarb gianarb pushed a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
@Ocramius Ocramius Adding `@group` annotation for tests of zendframework/zendframework#5948
1bbd0b4
@gianarb gianarb pushed a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
@Ocramius Ocramius Merge branch 'tests/zendframework/zf2#5948-circular-dependency-tests-…
…for-module-manager-init'

Close zendframework/zendframework#5948
8a9ab31
@gianarb gianarb pushed a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
@Ocramius Ocramius Merge branch 'tests/zendframework/zf2#5948-circular-dependency-tests-…
…for-module-manager-init' into develop

Close zendframework/zendframework#5948
Forward Port zendframework/zendframework#5948
8e8a5e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment