Problems with Geoplugin in Symfony 3.4 - symfony

I am trying to upgrading my existing Symfony 2.8 web site to 3.4.
I have faced and fixed many issues but I am stuck with a Geoplugin issue.
I have updated like the following my AppBundle/Resources/config/services.yml to respect the new YAML directives (thus I have added '' around #variables) :
app.ipgeo:
class: AppBundle\Utils\Geo\Geoplugin
arguments: ['#request', '#doctrine.orm.entity_manager', '#service_container']
scope: request
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onLoad }
But I get a PHP Fatal error when accessing the web site :
AH01071: Got error 'PHP message: PHP Fatal error: Call to a member function getUri() on string in /var/www/vhosts/alpclic-dev.fr/httpdocs/dev.scenes-locales.com/src/AppBundle/Utils/Geo/Geoplugin.php on line 58
PHP message: PHP Fatal error: Call to a member function getUri() on string in
/var/www/vhosts/alpclic-dev.fr/httpdocs/dev.scenes-locales.com/src/AppBundle/Utils/Geo/Geoplugin.php
on line 58\n'
Any idea ?
Of course, it was perfectly working in 2.8 with the following configuration :
app.ipgeo:
class: AppBundle\Utils\Geo\Geoplugin
arguments: [#request, #doctrine.orm.entity_manager, #service_container]
scope: request
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onLoad }

Not so easy and "self-explanatory" !
I had to migrate to 'request_stack' service as mentioned here : How to inject the #request into a service?

Related

Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "!service_locator"

I am trying to add the webpack-encore-bundle to my Drupal site, I have this in services.yml file:
services:
webpack_encore.twig_entry_files_extension:
class: Symfony\WebpackEncoreBundle\Twig\EntryFilesTwigExtension
arguments:
['#service_container']
tags:
- { name: twig.extension }
webpack_encore.tag_renderer:
class: Symfony\WebpackEncoreBundle\Asset\TagRenderer
tags:
- { name: kernel.reset}
arguments:
['#webpack_encore.entrypoint_lookup_collection', '#assets.packages']
assets.packages:
class: Symfony\Component\Asset\Packages
webpack_encore.default_entrypoint:
class: Symfony\WebpackEncoreBundle\Asset\EntrypointLookup
arguments:
- 'web/themes/custom/mytheme_base/public/build/entrypoints.json'
webpack_encore.entrypoint_lookup_collection:
class: Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection
arguments:
- !service_locator
_default: '#webpack_encore.default_entrypoint'
But I am getting this error:
In YamlSymfony.php line 40:
Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "!service_locator" at line 27 (near "!service_locator").
In Parser.php line 1157:
Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "!service_locator" at line 27 (near "!service_locator").
Do you know how to fix it?
If using custom tags in your code : see Symfony documentation : https://symfony.com/doc/5.4/components/yaml.html#parsing-and-dumping-custom-tags
If you are getting this error when running bin/console.php lint:yaml my/repository, try running it with the option "--parse-tags" : bin/console.php lint:yaml --parse-tags my/repository

Symfony3 404 exception response return with status code 200 instead of 500

I am new in symfony,I have facing one problem in Production Environment after I add kernel.event_subscriber in service.yml. problem is before adding event subscriber in service.yml file It return 500 HTTP_STATUS_CODE & Resource Not Found exception occur with my custom page in twingbuddle That I set, below page it show before add event_subscriber In Service.yml When I go to URL: http://localhost/meopin_2/trunk/web/en/login/ddssssssssss,
Then I add below code in Service.yml
kernel.event_subscriber:
class: AppBundle\EventSubscriber\TokenSubscriber
arguments: ["#security.http_utils","#service_container","#router", {}, {}, {},{}]
tags:
- { name: kernel.event_subscriber, channel: 'kernel' ,event: onKernelController,method: onKernelController}
and make a File Event Describer. Now issue is When I go to Same URL: http://localhost/meopin_2/trunk/web/en/login/ddssssssssss
It Return me Error as a Text Message with HTTP_STATUS_CODE 200, Below response It Return Me Instead of My Previous 404 Page in Production Environment.
What I missing or Wrong So that It return error as a text message in Production Environment ?
Thanks In Advance if Any one help me.

How do I configure my Twig / Symfony2 services for this?

How do I configure my services for this?
https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php
I'm guessing it's something like this:
twig.extension.anyName:
class: Bundle\Twig\RoutingExtension
arguments:
- "twig.extension.routing"
tags:
- { name: twig.extension }
...but it errors with:
Catchable Fatal Error: Argument 1 passed to Bundle\Twig\RoutingExtension::__construct() must implement interface Symfony\Component\Routing\Generator\UrlGeneratorInterface, string given...
Valid syntax for referencing other services is # symbol followed by service name. Currently you are passing string "twig.extension.routing" to your service constructor.
If you want pass service instance to your service, it could look something like this
twig.extension.anyName:
class: Bundle\Twig\RoutingExtension
arguments:
- "#twig.extension.routing"
tags:
- { name: twig.extension }

Dependency Injection Symfony 2 simple code returning error

I was under the impression I could get the request object like in the code below. Something to do with Dependency Injection.
This below is activated as a service and everything seems to be setup correctly except for the first argument which gives this error:
ErrorException: Catchable Fatal Error: Argument 1 passed to....
namespace Acme\Bundle\BundleName\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class RequestListener
{
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
// etc....
I'm guessing the above is not how you do it?
If you want to declare an event listener on the kernel request, you should declare it that way (notice the tags parameters):
services:
acme.demobundle.listener.request:
class: Acme\Bundle\BundleName\EventListener\RequestListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
Otherwise, if you want to create just a service, you should declare it that way
services:
acme.demobundle.demo.service:
class: Acme\Bundle\BundleName\Service\DemoService
arguments: [#service_container]
For a service or a listener, I'd advise injecting only the services that are needed.
It's good to know that a service will be initialized on the first call.
A service, a listener and a twig extension can be accessed through the container.
$this->container->get('your.listener.name')
$this->container->get('your.service.name')
$this->container->get('your.extension.name')

Symfony 2.1 controller overwrite in kernel.request results "Allowed memory size exhausted"

Greetings there coders,
I try to create a request route based controller overwrite feature as a kernel.request listener by the following way:
public function onKernelRequest(GetResponseEvent $event){
$requested_uri = $event->getRequest()->getRequestUri();
if($requested_uri == '/' || $requested_uri == '/index.php' || $requested_uri == '/index_dev.php'){
$event->getRequest()->attributes->set('_controller', 'TestHomeBundle:Home:index');
}
}
However it shows the following error in the apache log:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 39 bytes) in /vendor/symfony/symfony/src/Symfony/Component/Routing/Generator/UrlGenerlGenerator.php on line 182
I registered it in the following way.
kernel.listener.homepage_rewrite_listener:
class: Test\HomeBundle\EventListener\HomepageRewriteListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 35 }
The main problem is that I cannot give this more memory. Any Ideas are welcome. Thank you in advance.

Resources