Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Circular dependency test for #5651 #5948

Closed
wants to merge 2 commits into from

Conversation

radnan
Copy link
Contributor

@radnan radnan commented Mar 11, 2014

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 added a commit that referenced this pull request Apr 3, 2014
@Ocramius Ocramius closed this in 3d4c5a2 Apr 3, 2014
Ocramius added a commit that referenced this pull request Apr 3, 2014
@Ocramius Ocramius self-assigned this Apr 3, 2014
@rettal
Copy link
Contributor

rettal commented Mar 4, 2015

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 pushed a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants