ReynierPM
ReynierPM

Reputation: 18660

Circular reference detected in routing_dev.yml

I'm getting crazy with this circular reference issue and I can't find what I'm doing wrong. This is the content of /app/config/routing.yml:

pd_one:
    resource: "@PDOneBundle/Controller/"
    type:     annotation
    prefix:   /

template:
    resource: "@TemplateBundle/Controller/"
    type:     annotation
    prefix:   /

fos_user:
    prefix: /admin
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

restful_services:
    resource: "@PDOneBundle/Resources/config/routing.yml"
    type:     rest
    prefix:   /api

nelmio_apidoc:
    resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
    prefix:   /api/doc

admin:
    resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix: /admin

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

This is the content of /app/config/routing_dev.yml:

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error

_main:
    resource: routing.yml

And finally this is the content of /src/PDI/PDOneBundle/Resources/config/routing.yml:

service_company:
    type: rest
    prefix: /v1
    resource: PDOneBundle\Controller\CompanyRestController
    name_prefix:  api_1_ # naming collision

Any time I tried some URL at dev env I got this error:

FileLoaderImportCircularReferenceException in classes.php line 7527: Circular reference detected in "/var/www/html/reptooln_admin/app/config/routing_dev.yml" ("/var/www/html/reptooln_admin/app/config/routing_dev.yml" > "/var/www/html/reptooln_admin/app/config/routing.yml" > "/var/www/html/reptooln_admin/src/PDI/PDOneBundle/Resources/config/routing.yml"

"/var/www/html/reptooln_admin/app/config/routing_dev.yml").

This is the full stack trace|logs:

in classes.php line 7527
at FileLoader->import('/var/www/html/reptooln_admin/app/config/routing_dev.yml', null, false, '/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml') in YamlFileLoader.php line 155
at YamlFileLoader->parseImport(object(RouteCollection), array('resource' => '/var/www/html/reptooln_admin/app/config/routing_dev.yml'), '/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', '/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml') in YamlFileLoader.php line 91
at YamlFileLoader->load('/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 45
at DelegatingLoader->load('/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 58
at DelegatingLoader->load('/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', 'yaml') in classes.php line 11649
at Router->getRouteCollection() in classes.php line 11619
at Router->getGeneratorDumperInstance() in classes.php line 11600
at Router->getGenerator() in classes.php line 11545
at Router->generate('_profiler', array('token' => 'ccd0d6')) in WebDebugToolbarListener.php line 66
at WebDebugToolbarListener->onKernelResponse(object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher))
at call_user_func(array(object(WebDebugToolbarListener), 'onKernelResponse'), object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher)) in WrappedListener.php line 61
at WrappedListener->__invoke(object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher))
at call_user_func(object(WrappedListener), object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher)) in classes.php line 12147
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(FilterResponseEvent)) in classes.php line 12080
at EventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in classes.php line 12241
at ContainerAwareEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in TraceableEventDispatcher.php line 112
at TraceableEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in bootstrap.php.cache line 3049
at HttpKernel->filterResponse(object(Response), object(Request), '2') in bootstrap.php.cache line 3044
at HttpKernel->handleRaw(object(Request), '2') in bootstrap.php.cache line 2991
at HttpKernel->handle(object(Request), '2', true) in bootstrap.php.cache line 3140
at ContainerAwareHttpKernel->handle(object(Request), '2', true) in ExceptionListener.php line 58
at ExceptionListener->onKernelException(object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
at call_user_func(array(object(ExceptionListener), 'onKernelException'), object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher)) in WrappedListener.php line 61
at WrappedListener->__invoke(object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher))
at call_user_func(object(WrappedListener), object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher)) in classes.php line 12147
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 12080
at EventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 12241
at ContainerAwareEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in TraceableEventDispatcher.php line 112
at TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in bootstrap.php.cache line 3061
at HttpKernel->handleException(object(FileLoaderLoadException), object(Request), '1') in bootstrap.php.cache line 2997
at HttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 3140
at ContainerAwareHttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 2384
at Kernel->handle(object(Request)) in app_dev.php line 14

Where is the issue? What I'm doing wrong? I'm trying to setup NelmioApiDoc and FOSRestBundle

EDIT 1

I have fixed the previous issue but got another similar. This are the changes I made.

/app/config/routing.yml

#PDOne 
# just leave in .yml file
pdone:
    resource: "@PDOneBundle/Resources/config/routing.yml"

# comment this out just for find where is the problem
#template:
#    resource: "@TemplateBundle/Controller/"
#    type:     annotation
#    prefix:   /

#FOSUserBundle
fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    prefix: /

NelmioApiDocBundle:
    resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
    prefix:   /api/doc

#SonataAdmin
admin:
    resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix: /admin

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

/src/PDI/PDOneBundle/Resources/config/routing.yml

#sets this one as annotation
pdone:
    type:     annotation
    prefix:   /
    resource: "@PDOneBundle/Controller/"

#this ones will be for restful API
companies:
    type: rest
    prefix: /api/v1/companies
    resource: PDOneBundle\Controller\Rest\CompanyRestController

And error change to this:

FileLoaderImportCircularReferenceException in classes.php line 13960: Circular reference detected in "/var/www/html/reptooln_admin/app/config/routing_dev.yml" ("/var/www/html/reptooln_admin/app/config/routing_dev.yml" > "/var/www/html/reptooln_admin/app/config/routing.yml" > "/var/www/html/reptooln_admin/src/PDI/PDOneBundle/Resources/config/routing.yml"

"PDOneBundle\Controller\Rest\CompanyRestController" > "/var/www/html/reptooln_admin/app/config/routing_dev.yml").

Where is the problem at /src/PDI/PDOneBundle/Resources/config/routing.yml? Can't live annotation and rest types at same YML file? How do I deal with this?

Upvotes: 1

Views: 2294

Answers (2)

ReynierPM
ReynierPM

Reputation: 18660

Thanks to users on Symfony2 group I have found a workaround and I will share here. After do a long research I found this SO topic among others and yes, theres is not mention around annotations and mix config files or whatever that was causing the circular reference, in a short, I just delete this:

companies:
    type: rest
    prefix: /api/v1/companies
    resource: PDOneBundle\Controller\Rest\CompanyRestController

from every place and just relies on annotations and that worked for me. This not help me to find the real issue but at least make my app works again. Hope this help anyone with same issue

Upvotes: 0

Wouter J
Wouter J

Reputation: 41934

The circular reference error is actually a wrong one, caused by an error while loading the routes (error triggers controller to call, controller requires routes to be loaded, routes loading triggers error again, ...).

You should check the PDOneBundle and TemplateBundle controllers for routing errors, like missing use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route and such errors.

Upvotes: 2

Related Questions