logo
down
shadow

Deriving custom exception listener from Symfony default exception listener: What are the correct service arguments?


Deriving custom exception listener from Symfony default exception listener: What are the correct service arguments?

By : Berkan Dirim
Date : November 19 2020, 03:59 PM
around this issue Registering custom exception listener in on hand - is just registering some listener. The minimum code here is:
code :
class ExceptionListener
{
   public function listenExceptions(GetResponseForExceptionEvent $event)
   {
      // Some event management
   }
}
services:
  kernel.listener.custom_exception_listener:
    class: MyCompany\MyBundle\EventListener\ExceptionListener
    tags:
       - { name: kernel.event_listener, event: kernel.exception, method: listenExceptions, priority: -64 }


Share : facebook icon twitter icon
Symfony Circular Reference Exception for Doctrine onFlush Event Listener Service

Symfony Circular Reference Exception for Doctrine onFlush Event Listener Service


By : user2345462
Date : March 29 2020, 07:55 AM
hope this fix your issue The basic solution to this (as I indicated) is to remove the construct or setter injection of the EntityManager from the service definition (and the service class). Instead you have to pass the EntityManager into the function that needs it. This prevents the circular reference.
I opted for this instead of a creating a setEntityManager because it seems clunky to have to set that on the EntityHelper service, before calling the function. It seems better to just pass it to the functions that need it directly.
code :
# This is the helper class for all entities
gutensite_cms.entity_helper:
    class: Gutensite\CmsBundle\Service\EntityHelper
    # Do NOT pass in EntityManager via constructor or injector, because it causes a Circular Reference Error when this service is included in Event Listener


# An event listener for any entity that is Versionable
gutensite_cms.listener.is_versionable:
    class: Gutensite\CmsBundle\EventListener\IsVersionableListener
    #only pass in the services we need
    arguments: [ "@gutensite_cms.entity_helper" ]
    tags:
        - { name: doctrine.event_listener, event: onFlush }
namespace Gutensite\CmsBundle\Service;

use Doctrine\ORM\EntityManager;

class EntityHelper {


    /**
     * Get the bundle shortcut path for an entity based on it's namespace.
     *
     * As an example, if your entity is Gutensite\CmsBundle\Entity\View\ViewVersion the function will return
     * GutensiteCmsBundle:View\ViewVersion
     *
     * @param $entity
     * @return string
     */
    public function getEntityBundleShortcut(EventManager $eventManager, $entity) {
        // wrap get_class() in the entityManager metadata function to avoid returning cached proxy class
        $path = explode('\Entity\\', $eventManager->getClassMetadata(get_class($entity))->getName());
        return str_replace('\\', '', $path[0]).':'.$path[1];
    }

}
namespace Gutensite\CmsBundle\EventListener;

use Doctrine\ORM\Event\OnFlushEventArgs;
use Gutensite\CmsBundle\Service\EntityHelper;


/**
 * Class IsVersionableListener
 * @package Gutensite\CmsBundle\EventListener
 */
class IsVersionableListener
{

    /*
    private $entityHelper;

    public function __construct(EntityHelper $entityHelper) {
        $this->entityHelper = $entityHelper;
    }
    */

    public function onFlush(OnFlushEventArgs $eventArgs)
    {

        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();
        $updatedEntities = $uow->getScheduledEntityUpdates();

        foreach($updatedEntities AS $entity) {

            // This is generic listener for all entities that have an isVersionable method (e.g. ViewVersion)
            // TODO: at the moment, we only want to do the following code for the viewVersion entity

            if (method_exists($entity, 'isVersionable') && $entity->isVersionable()) {

                // Get the Correct Repo for this entity
                $entityShortcut = $this->entityHelper->getEntityBundleShortcut($em, $entity);
                $repo = $em->getRepository($entityShortcut);

                // If the repo for this entity has an onFlush method, use it.
                // This allows us to keep the functionality in the entity repo
                if(method_exists($repo, 'onFlush')) {
                    $repo->onFlush($em, $entity);
                }

            }
        }
    }
}
Exception in sent of the initiat request (lifecycle) for instance of listener class (listener event) com.sun.faces.confi

Exception in sent of the initiat request (lifecycle) for instance of listener class (listener event) com.sun.faces.confi


By : user3439062
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Hi Please help I would like to create a Dynamic project Spring/JSF. I use the technology : , The error is:
code :
GRAVE: Erreur lors de la configuration de la classe d'écoute de l'application (application listener) com.sun.faces.config.ConfigureListner
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListner
<listener>
     <listener-class>com.sun.faces.config.ConfigureListner</listener-class>
</listener>
<listener>
     <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
GRAVE: Une exception lors de l'envoi de requête a initié un évènement cycle de vie (lifecycle event) pour l'instance de classe à l'écoute (listener event) com.sun.faces.config.ConfigureListener
java.lang.UnsupportedOperationException
    at javax.faces.context.FacesContext.getExceptionHandler(FacesContext.java:287)
<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern> <!-- or one of your own --> 
</servlet-mapping>
Windows Service (TCP Client/Listener) Firewall Exception Blocks Traffic

Windows Service (TCP Client/Listener) Firewall Exception Blocks Traffic


By : Márton Gacsályi
Date : March 29 2020, 07:55 AM
With these it helps In order for selecting a specific executable to work, the path to the executable must match the path the firewall is expecting. Apparently the firewall GUI for some reason was converting the path so that is was relative to %USERPROFILE% ; I suspect this constitutes a bug in Windows.
(If I remember correctly, the firewall can in general cope with paths that use environment variables, e.g., %SystemRoot%, but obviously a per-user environment variable won't work, since the firewall rules are not evaluated in the correct user's context.)
Glide 4.7.1 listener not working for onResourceReady method and Exception listener

Glide 4.7.1 listener not working for onResourceReady method and Exception listener


By : Aashish Krishnan
Date : March 29 2020, 07:55 AM
This might help you there! I'm using glide to load images in my app. Previously I used Picasso and it worked but after migrating to the Glide (v4.7.1) I'm not able to use listener to get state of the resource. I attached code below please help me in this matter. , Try this
code :
    Glide.with(this)
            .load("")
            .apply(new RequestOptions()
                    .placeholder(R.color.colorPrimary)
                    .dontAnimate().skipMemoryCache(true))
            .listener(new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {

                    spinner.setVisibility(View.GONE);
                    return false;
                }

                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                    spinner.setVisibility(View.GONE);
                    return false;
                }
            })
            .into(imageView);
Symfony 4 - Console exception event listener

Symfony 4 - Console exception event listener


By : user1832448
Date : March 29 2020, 07:55 AM
Does that help I try to handle an exception from a Symfony console command in a Symfony 4 project. , The correct configuration is this:
code :
kernel.event_listener:
        class: App\Application\EventListener\ExceptionListener
        arguments:
            - '@logger'
            - '@jms_serializer'
            - '@translator.default'
        tags:
            - { name: kernel.event_listener, event: console.error }
namespace App\EventListener;

use Symfony\Component\Console\Event\ConsoleErrorEvent;

class ExceptionListener
{
    public function onConsoleError(ConsoleErrorEvent $event) {
        // your code here
    }
}
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org