将事件记录到Symfony中的数据库

I followed this guide: https://nehalist.io/logging-events-to-database-in-symfony/

I made all steps except step 2, because I don't need that information.

The error:

Whoops, looks like something went wrong.
1/1 ClassNotFoundException in CompanySubscriber.php line 19: Attempted to load class "CompanyEvent" from namespace "AppBundle\Events".
Did you forget a "use" statement for another namespace?

in CompanySubscriber.php line 19
at CompanySubscriber::getSubscribedEvents() in classes.php line 3361
at ContainerAwareEventDispatcher->addSubscriberService('appbundle.subscriber.company_subscriber', 'AppBundle\\EventSubscriber\\CompanySubscriber')
at call_user_func_array(array(object(ContainerAwareEventDispatcher), 'addSubscriberService'), array('appbundle.subscriber.company_subscriber', 'AppBundle\\EventSubscriber\\CompanySubscriber')) in TraceableEventDispatcher.php line 227
at TraceableEventDispatcher->__call('addSubscriberService', array('appbundle.subscriber.company_subscriber', 'AppBundle\\EventSubscriber\\CompanySubscriber')) in appDevDebugProjectContainer.php line 660
at appDevDebugProjectContainer->getDebug_EventDispatcherService() in classes.php line 3090
at Container->get('debug.event_dispatcher') in appDevDebugProjectContainer.php line 4175
at appDevDebugProjectContainer->getSecurity_Authentication_ManagerService() in appDevDebugProjectContainer.php line 2554
at appDevDebugProjectContainer->getSecurity_AuthorizationCheckerService() in classes.php line 3090
at Container->get('security.authorization_checker', 2) in appDevDebugProjectContainer.php line 3596
at appDevDebugProjectContainer->getTwigService() in classes.php line 3090
at Container->get('twig') in appDevDebugProjectContainer.php line 501
at appDevDebugProjectContainer->getCacheWarmerService() in classes.php line 3090
at Container->get('cache_warmer') in Kernel.php line 499
at Kernel->initializeContainer() in Kernel.php line 116
at Kernel->boot() in Kernel.php line 165
at Kernel->handle(object(Request)) in app_dev.php line 30

services.yml

parameters:
services:
    monolog.db_handler:
        class: AppBundle\Util\MonologDBHandler
        arguments: ['@doctrine.orm.entity_manager']
    appbundle.subscriber.abstract_subscriber:
        class: AppBundle\EventSubscriber\AbstractSubscriber
        arguments: ['@service_container']

    appbundle.subscriber.company_subscriber:
        class: AppBundle\EventSubscriber\CompanySubscriber
        parent: appbundle.subscriber.abstract_subscriber
        tags:
            - { name: kernel.event_subscriber }

CompanyEvent.php

<?php

namespace AppBundle\Events;

/**
 * Class CompanyEvent
 * @package AppBundle\Events
 */
class CompanyEvent extends AbstractEvent
{
    const COMPANY_ADDED = 'company_added';
}

CompanySubscriber.php

<?php

namespace AppBundle\EventSubscriber;

use AppBundle\Events\CompanyEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Class CompanySubscriber
 * @package AppBundle\EventSubscriber
 */
class CompanySubscriber extends AbstractSubscriber implements EventSubscriberInterface
{
    /**
     * @return array
     */
    public static function getSubscribedEvents() {
        return [
            CompanyEvent::COMPANY_ADDED => 'onCompanyAdded',
        ];
    }

    /**
     * @param CompanyEvent $event
     */
    public function onCompanyAdded(CompanyEvent $event) {
        $this->logEntity(CompanyEvent::COMPANY_ADDED, [
            'Company' => $event->getEntity()->getCompany()
        ]);
    }

}

I checked multiple times. All pats and namespaces are correct. What did I do wrong?

The subscriber found your CompanySubscriber class and instance it without problems, does not appear as composer problem. Please review the path for AppBundle\Events, must be ../src/AppBundle/Events/CompanyEvent.php, review file name, lower and upper case etc

Sorry for bumping.

I double and triple checked all paths, uses, classes etc and it didn't work.

Then I updated the symfony (didn't noticed what exactly updated), but it started to work, so the question is closed.