How to fix ParameterCircularReferenceException? - php

I have a symfony2 appliciation. We have previously set up a docker-compose stack for development, and this is why we want all its configuration to bet set via environment variables instead of the parameters.yml.
Hence I replaced the content of my parameters.yml from:
parameters:
locale: 'en'
secret: 'SOME_SECURITY_TOKEN'
...
to:
parameters:
locale: '%locale%'
secret: '%secret%'
...
My docker-compose.yml file contains:
my_app:
hostname: my-app
build: .
dockerfile: Dockerfile.dev
ports:
- "9080:80"
- "9043:433"
environment:
LOCALE: en
SECRET: SOME_SECURITY_TOKEN
...
Yet after rebuilding my container I get the exception:
ParameterCircularReferenceException in ParameterBag.php line 209: Circular reference detected for parameter "secret" ("secret" > "secret").
1. in ParameterBag.php line 209
2. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
3. at ParameterBag->resolveValue('%secret%', array('secret' => true)) in ParameterBag.php line 214
4. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
5. at ParameterBag->resolveValue('%secret%', array()) in ParameterBag.php line 175
6. at ParameterBag->resolveValue(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null, 'csrf_protection' =>
null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null, 'trusted_proxies' => null,
'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array()) in ParameterBag.php line 175
7. at ParameterBag->resolveValue(array(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null,
'csrf_protection' => null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null,
'trusted_proxies' => null, 'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array('router' =>
array('resource' => '%kernel.root_dir%/config/routing_dev.yml', 'strict_requirements' => true), 'profiler' => array('only_exceptions' => false)))) in MergeExtensionConfigurationPass.php line 45
8. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in MergeExtensionConfigurationPass.php line 39
9. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in Compiler.php line 107
10. at Compiler->compile(object(ContainerBuilder)) in ContainerBuilder.php line 589
11. at ContainerBuilder->compile() in bootstrap.php.cache line 2687
12. at Kernel->initializeContainer() in bootstrap.php.cache line 2465
13. at Kernel->boot() in bootstrap.php.cache line 2496
14. at Kernel->handle(object(Request)) in app_dev.php line 30
Yet in my container I do see the env variables:
le-container:/var/www/my-app# env
SECRET=SOME_SECURITY_TOKEN
LOCALE=en
What am I doing wrong and how to fix it?

For some reason, adding a prefix to my environment variable fixed the issue:
parameters:
locale: '%foo_locale%'
secret: '%foo_secret%'
and of course whenever the variable is set as well. My current working theory is that symfony doesn't like having the same parameter name and env variable, yet I am not sure.

parameters:
locale: '%locale%'
secret: '%secret%'
Is useless construction, locale and secret already is parameters. Just remove this block.

There is a solution to use external parameters. Prefix your variables with "SYMFONY__". In your case it would be:
my_app:
...
environment:
SYMFONY__APP__LOCALE: en
SYMFONY__APP__SECRET: SOME_SECURITY_TOKEN
...
And in your parameters you can call it as followed:
parameters:
locale: %app.locale%
secret: %app.secret%

Related

Symfony2 application not working when moving vendor directory

I have installed OroCommerce, a Symfony2 based application. I want to have the 'vendor' directory on a higher level outside the users directory. I followed the steps at http://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-vendor-directory but now the namespaces can't be found. I get the following error:
InvalidArgumentException in YamlFileLoader.php line 399: There is no extension able to load the configuration for "framework" (in /home/oro2/public_html/app/config/config_dev.yml). Looked for namespace "framework", found "web_profiler", "sensio_distribution", "debug"
in YamlFileLoader.php line 399
at YamlFileLoader->validate(array('imports' => array(array('resource' => 'config.yml')), 'framework' => array('router' => array('resource' => '%kernel.root_dir%/config/routing_dev.yml'), 'profiler' => array('only_exceptions' => false)), 'web_profiler' => array('toolbar' => true, 'intercept_redirects' => false), 'monolog' => array('handlers' => array('main' => array('type' => 'stream', 'path' => '%kernel.logs_dir%/%kernel.environment%.log', 'level' => 'debug'))), 'oro_assetic' => array('css_debug' => null, 'css_debug_all' => false), 'oro_message_queue' => array('client' => array('traceable_producer' => true))), '/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 369
at YamlFileLoader->loadFile('/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 44
at YamlFileLoader->load('/home/oro2/public_html/app/config/config_dev.yml', null) in DelegatingLoader.php line 45
at DelegatingLoader->load('/home/oro2/public_html/app/config/config_dev.yml') in AppKernel.php line 35
at AppKernel->registerContainerConfiguration(object(DelegatingLoader)) in bootstrap.php.cache line 2776
at Kernel->buildContainer() in bootstrap.php.cache line 2728
at Kernel->initializeContainer() in OroKernel.php line 290
at OroKernel->initializeContainer() in bootstrap.php.cache line 2507
at Kernel->boot() in OroKernel.php line 252
at OroKernel->boot() in bootstrap.php.cache line 2538
at Kernel->handle(object(Request)) in app_dev.php line 33
Am I forgetting something? Does anyone know how to solve this problem?
You are somewhere calling %kernel.root_dir%/config/routing_dev.yml which actually does not exist, because you have moved the config file dir

Twig_Error_Syntax: Unknown "template_from_string" function. Function became obsolete?

I remember after composer updating I got this error, but previously it worked perfectly, and in comparing the packages versions I didn't find differences. I used it in this way in template:
{{ include(template_from_string(page.body)) }}
where "page" is entity object from controller. Current versions are:
symfony/symfony v2.8.15
twig/extensions v1.4.1
twig/twig v1.30.0
Also in config.yml:
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'AppBundle::Form/form_override.html.twig'
Now there is in vendor/twig/twig/lib/twig/Twig/Extension/StringLoader.php visually correct file, but seems it still not working. Full stacktrace:
[1] Twig_Error_Syntax: Unknown "template_from_string" function.
at n/a
in ProjectDir\src\AppBundle/Resources/views/Page.html.twig line 22
at Twig_ExpressionParser->getFunctionNodeClass('template_from_string', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 374
at Twig_ExpressionParser->getFunctionNode('template_from_string', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 162
at Twig_ExpressionParser->parsePrimaryExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 102
at Twig_ExpressionParser->getPrimary()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 55
at Twig_ExpressionParser->parseExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 520
at Twig_ExpressionParser->parseArguments(true)
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 373
at Twig_ExpressionParser->getFunctionNode('include', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 162
at Twig_ExpressionParser->parsePrimaryExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 102
at Twig_ExpressionParser->getPrimary()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 55
at Twig_ExpressionParser->parseExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 147
at Twig_Parser->subparse(array(object(Twig_TokenParser_Block), 'decideBlockEnd'), true)
in ProjectDir\vendor\twig\twig\lib\Twig\TokenParser\Block.php line 40
at Twig_TokenParser_Block->parse(object(Twig_Token))
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 190
at Twig_Parser->subparse(null, false)
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 103
at Twig_Parser->parse(object(Twig_TokenStream))
in ProjectDir\app\cache\dev\classes.php line 3415
at Twig_Environment->parse(object(Twig_TokenStream))
in ProjectDir\app\cache\dev\classes.php line 3443
at Twig_Environment->compileSource(object(Twig_Source))
in ProjectDir\app\cache\dev\classes.php line 3291
at Twig_Environment->loadTemplate('AppBundle::Page.html.twig')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php line 126
at Symfony\Bridge\Twig\TwigEngine->load('AppBundle::Page.html.twig')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php line 50
at Symfony\Bridge\Twig\TwigEngine->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php line 72
at Symfony\Bundle\TwigBundle\TwigEngine->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php line 103
at Symfony\Bundle\TwigBundle\TwigEngine->renderResponse('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'), null)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php line 185
at Symfony\Bundle\FrameworkBundle\Controller\Controller->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\src\AppBundle\Controller\PageController.php line 35
at AppBundle\Controller\PageController->getPageAction('direktor')
in line
at call_user_func_array(array(object(PageController), 'getPageAction'), array('direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 144
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 64
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php line 69
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php line 185
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in ProjectDir\web\app_dev.php line 28
at require('ProjectDir\web\app_dev.php')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Resources\config\router_dev.php line 40
You must let the Service Container know about your Twig Extension:
# app/config/services.yml
acme.twig.extension.loader:
class: Twig_Extension_StringLoader
tags:
- { name: 'twig.extension' }
Symfony 4:
# config/services.yml
app.twig.extension.loader:
class: Twig\Extension\StringLoaderExtension
tags:
- { name: 'twig.extension' }
For symfony5 and twig3, the answer from here worked: Symfony 4: Add Twig_Extension_StringLoader
# config/services.yaml
services:
Twig\Extension\StringLoaderExtension:
As this is more easily findable in google, I'll add it here.

Symfony2 FOSUSER invalid resource

i'm trying to setup a simple FOSUser instance on my new symfony2 project (v2.8) i've followed the tutorial on the documentation exactly as it says. And i'm getting the current error
InvalidConfigurationException in ArrayNode.php line 317:
Unrecognized option "resource" under "fos_user"
in ArrayNode.php line 317
at ArrayNode->normalizeValue(array('db_driver' => 'orm', 'firewall_name' => 'main', 'user_class' => 'AuthBundle\Entity\User', 'resource' => '#FOSUserBundle\Resources\config outingll.xml')) in BaseNode.php line 264
at BaseNode->normalize(array('db_driver' => 'orm', 'firewall_name' => 'main', 'user_class' => 'AuthBundle\Entity\User', 'resource' => '#FOSUserBundle\Resources\config outingll.xml')) in Processor.php line 33
at Processor->process(object(ArrayNode), array(array('db_driver' => 'orm', 'firewall_name' => 'main', 'user_class' => 'AuthBundle\Entity\User', 'resource' => '#FOSUserBundle\Resources\config outingll.xml'))) in Processor.php line 50
at Processor->processConfiguration(object(Configuration), array(array('db_driver' => 'orm', 'firewall_name' => 'main', 'user_class' => 'AuthBundle\Entity\User', 'resource' => '#FOSUserBundle\Resources\config outingll.xml'))) in FOSUserExtension.php line 45
at FOSUserExtension->load(array(array('db_driver' => 'orm', 'firewall_name' => 'main', 'user_class' => 'AuthBundle\Entity\User', 'resource' => '#FOSUserBundle\Resources\config outingll.xml')), object(ContainerBuilder)) in MergeExtensionConfigurationPass.php line 55
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in Compiler.php line 107
at Compiler->compile(object(ContainerBuilder)) in ContainerBuilder.php line 593
at ContainerBuilder->compile() in Kernel.php line 511
at Kernel->initializeContainer() in Kernel.php line 133
at Kernel->boot() in Kernel.php line 182
at Kernel->handle(object(Request)) in app_dev.php line 30
at require('/home/sergio/Desktop/RSU/web/app_dev.php') in router_dev.php line 40
at config.yml i got the current identation
# fos
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: AuthBundle\Entity\User
resource: "#FOSUserBundle\Resources\config\routing\all.xml"
Everything is as in the tutorial, i commented the "resource" part and i could update DB schema, symfony can't find the FOSUserBundle\Resources\config\routing\all.xml it seams. any suggestion how to solve this ?
thank you.
You need to put the resource key under fos_user in routing.yml
# app/config/routing.yml
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
Documentation:
http://symfony.com/doc/current/bundles/FOSUserBundle/index.html#step-6-import-fosuserbundle-routing-files

Symfony2 fatal error You have requested a non-existent parameter java_path

im working in SmFony Project but i got some issues when i would get access on my poject via this URL : http://localhost/oksa-depannage/web/app_dev.php/login
"OKSA-DEPANNAGE" is a project name.
So i hope that my question is clear
Errors :
in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php line 106
at ParameterBag->get('java_path') in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php line 232
at ParameterBag->resolveString('%java_path%', array()) in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php line 203
at ParameterBag->resolveValue('%java_path%', array()) in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php line 193
at ParameterBag->resolveValue(array('debug' => '%kernel.debug%', 'use_controller' => false, 'bundles' => array('OksaTemplateBundle'), 'java' => '%java_path%', 'filters' => array('cssrewrite' => null, 'yui_css' => array('jar' => '%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar'), 'yui_js' => array('jar' => '%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar'))), array()) in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php line 193
at ParameterBag->resolveValue(array(array('debug' => '%kernel.debug%', 'use_controller' => false, 'bundles' => array('OksaTemplateBundle'), 'java' => '%java_path%', 'filters' => array('cssrewrite' => null, 'yui_css' => array('jar' => '%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar'), 'yui_js' => array('jar' => '%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar'))), array('use_controller' => true))) in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass.php line 44
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\Compiler.php line 117
at Compiler->compile(object(ContainerBuilder)) in C:\wamp\www\oksa-depannage\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ContainerBuilder.php line 619
at ContainerBuilder->compile() in C:\wamp\www\oksa-depannage\app\bootstrap.php.cache line 2491
at Kernel->initializeContainer() in C:\wamp\www\oksa-depannage\app\bootstrap.php.cache line 2270
at Kernel->boot() in C:\wamp\www\oksa-depannage\app\bootstrap.php.cache line 2301
at Kernel->handle(object(Request)) in C:\wamp\www\oksa-depannage\web\app_dev.php line 28
thanks for your helps.
Looks like symfony is trying to start the yui compressor, which is a java library.
This post has a workaround to make this situation work on windows: symfony2 assetics yui compressor on windows (path syntax)

cakePHP illegal offset type

I'm new to cakephp and following this tutorial for a user authentication system
http://bakery.cakephp.org/articles/SeanCallan/2007/04/17/simple-form-authentication-in-1-2-x-x
The only thing I changed is in the file login.ctp. I changed the pointers from
$form->
to
$this->Form->
I'm getting two errors and I can't figure out why. Here is the first
Warning (2): Illegal offset type [CORE\Cake\Model\Model.php, line 2603]
This is the code/context it displays
if ($type !== 'all') {
if ($this->findMethods[$type] === true) {
$type = array(
'username' => '',
'password' => '*****'
)
$query = array(
'conditions' => null,
'fields' => null,
'joins' => array(),
'limit' => null,
'offset' => null,
'order' => null,
'page' => (int) 1,
'group' => null,
'callbacks' => true,
(int) 0 => 'id',
(int) 1 => 'username'
)
$this = object(User) {}
This information was also displayed
Model::buildQuery() - CORE\Cake\Model\Model.php, line 2603
Model::find() - CORE\Cake\Model\Model.php, line 2562
User::validateLogin() - APP\Model\User.php, line 9
UsersController::login() - APP\Controller\UsersController.php, line 21
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 484
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 104
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 86
[main] - APP\webroot\index.php, line 96
Here is the second error
Warning (2): Illegal offset type [CORE\Cake\Model\Model.php, line 2579]
This is the code it displays
return $results;
} else {
if ($this->findMethods[$type] === true) {
$type = array(
'username' => '',
'password' => '*****'
)
$query = array(
'conditions' => null,
'fields' => null,
'joins' => array(),
'limit' => null,
'offset' => null,
'order' => array(
),
'page' => (int) 1,
'group' => null,
'callbacks' => true,
(int) 0 => 'id',
(int) 1 => 'username'
)
$results = array(
(int) 0 => array(
)
)
$this = object(User) {}
Here is the additional information
Model::find() - CORE\Cake\Model\Model.php, line 2579
User::validateLogin() - APP\Model\User.php, line 9
UsersController::login() - APP\Controller\UsersController.php, line 21
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 484
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 104
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 86
[main] - APP\webroot\index.php, line 96
I would suggest you follow the more recent tutorial at
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html
Which should follow your setup exactly since you are using cakephp 2.1. The one you are trying to follow now is for cakephp1.2 and was written on 2007 so I doubt it's going to be useful for you.

Categories