Return the Container or a Service when calling a matching method

@param $event sfEvent
@return bool
182054
public function listenToMethodNotFound($event)
    {
        if ('getServiceContainer' == $event['method']) {
            $event->setReturnValue($this->containerManager->getServiceContainer());
            return true;
        }

        if ('getContainerBuilder' == $event['method']) {
            $event->setReturnValue($this->containerManager->getContainerBuilder());
            return true;
        }

        if ('getService' == $event['method']) {
            $event->setReturnValue($this->containerManager->getServiceContainer()->get($event['arguments'][0]));
            return true;
        }

        return false;
    }
144416
public function grabServiceFromContainer($service, array $parameters = [])
    {
        if (!$this->di->has($service)) {
            $this->fail("Service $service is not available in container");
        }

        return $this->di->get($service, $parameters);
    }
614918
public function getEventCallbacks($event = null)
    {
        if ($event === null) {
            return $this->eventCallbacks;
        }

        return $this->eventCallbacks[strtolower($event)] ?? [];
    }
517080
private function getHandlerQueue($event)
    {
        if (!isset($this->handlers[$event])) {
            $this->handlers[$event] = new Priority;
        }

        return $this->handlers[$event];
    }
849898
protected function getServicesFromEvent($serviceEvent)
    {
        if (false === isset($this->servicesEvents[$serviceEvent])) {
            $servicesInstances = [];
            foreach ($this->serviceInstances as $serviceInstance) {
                if ($serviceInstance instanceof $serviceEvent) {
                    $servicesInstances[] = $serviceInstance;
                }
            }

            $this->servicesEvents[$serviceEvent] = $servicesInstances;
        }

        return $this->servicesEvents[$serviceEvent];
    }
586192
public function determineEventBinding(Event $event)
    {
        switch ($event->getCode()) {
            case Event::RESOURCE_DELETED:
                return 'delete';
                break;
            case Event::RESOURCE_CREATED:
                return 'create';
                break;
            case Event::RESOURCE_MODIFIED:
                return 'modify';
            break;
        }
    }
814041
public function matches(Event $event)
    {
        /* @var \Cake\Http\ServerRequest $request */
        $request = $event->getData('request');
        $pass = true;
        if (!empty($this->_config['for'])) {
            $len = strlen('preg:');
            $for = $this->_config['for'];
            $url = $request->getRequestTarget();
            if (substr($for, 0, $len) === 'preg:') {
                $pass = (bool)preg_match(substr($for, $len), $url);
            } else {
                $pass = strpos($url, $for) === 0;
            }
        }
        if ($pass && !empty($this->_config['when'])) {
            $response = $event->getData('response');
            $pass = $this->_config['when']($request, $response);
        }

        return $pass;
    }
907226
public function get($service)
    {
        if ($this->has($service)) {
            return $this->container[$service];
        } else {
            throw new RuntimeException(sprintf(
                'Attempted to grab non-existing service "%s"', $service
            ));
        }
    }
35354
public function getContainer($service = null)
    {
        return is_null($service) ? ($this->container ?: app()) : ($this->container[$service] ?: app($service));
    }
607199
public function hasMatchingEvent()
    {
        // Retrieve the 'event' part of the payload
        $eventData = $this->payload->get('event');

        // If the event type isn't 'message' (which should go through BotMan::hears),
        // build a GenericEvent and return it
        if (isset($eventData['type']) && $eventData['type'] !== 'message') {
            $eventPayload = json_encode($eventData);
            if ($eventPayload !== false) {
                $event = new GenericEvent($eventPayload);
                $event->setName($eventData['type']);

                return $event;
            }
        }

        // Otherwise, fall back to the parent implementation
        return parent::hasMatchingEvent();
    }
1262339
public function getContainer()
    {
        if (property_exists(__CLASS__, 'container')) {
            return $this->container;
        } else {
            return parent::getContainer();
        }

        throw new RuntimeException(sprintf('The service container must be accessible from class %s to use this trait', __CLASS__));
    }
935320
public static function process($event)
    {
        // Link Lead with User
        if ($event->account_linking->status === 'linked') {
            $authorization_code = $event->account_linking->authorization_code;
            $user_id = str_replace('user_id:', '', $authorization_code);
            
            return self::linkWithExistingUser($event->sender->id, $user_id);
        } // Unlink, Logout user
        
        return self::unlinkWithExistingUser($event->sender->id);
    }
1361756
public function onEventRegistration(Event $event)
    {
        $this->unitOfWork->publishEvent($event, $this->eventBus);

        return $this->unitOfWork->invokeEventRegistrationListeners($event);
    }
1217017
public function isMatch(Event $event)
    {
        if (is_callable($this->checker)) {
            return call_user_func($this->checker, $event);
        }
        return false;
    }
1327050
public function wantToExecute($event)
    {
        return parent::wantToExecute($event)
            && (empty($this->operationName)
                || ($this->operationName === $event->getKey())
            );
    }
27224
public function has($event)
    {
        list($event, $payload) = $this->parseEventAndPayload($event, []);

        return array_key_exists($event, $this->listeners);
    }
109659
public function processEvent($event)
    {
        // Pass thread control to Inbox if Page Administrators move from Done to Inbox
        if (isset($event['request_thread_control'])) {
            return $this->passToInbox();
        }

        // Handle Account Linking and Unlinking
        if (isset($event['account_linking'])) {
            return AccountLinking::process($event);
        }

        // Handle message and postback
        if (!isset($event['message']) && !isset($event['postback'])) {
            return null;
        }

        if (isset($event['message'])) {
            $this->message = $event['message'];

            // Enabling NLP
            $this->initNlp($event['message']);
        }

        if (isset($event['postback'])) {
            $this->postback = $event['postback'];
        }

        // If current message is sent from Page
        if (isset($event['message']['is_echo'])) {
            $this->conversation->set('lead_id', $event['recipient']['id']);
            $this->conversation->set('page_id', $event['sender']['id']);
        }

        $this->conversation->set('received_input', $this->getReceivedInput());

        $this->setConfigData();

        // Save lead data if not exists.
        if (!isset($event['message']['is_echo'])) {
            $lead = $this->storage->pull();
        } else {
            $lead = Lead::withTrashed()->where('user_id', $this->getLeadId())->first();
        }

        $this->conversation->set('lead', $lead);
        
        // Message was sent by page, we don't need to response.
        if (isset($event['message']) && isset($event['message']['is_echo']) && $event['message']['is_echo'] == true) {
            return null;
        }

        DynamicParser::support([
            'type' => 'callback',
            'callback' => function ($content) use ($lead) {
                return $this->resolver->bind([
                    'bot' => $this,
                    'lead' => $lead,
                    'input' => $this->getReceivedInput(),
                ])->resolve($content);
            },
        ]);

        $type_pattern = $this->request->getTypeAndPattern($event);

        // We'll check to response intended action first
        if ($this->responseIntendedAction()) {
            return;
        }

        $nodes = $this->findNodes($type_pattern['type'], $type_pattern['pattern']);

        $this->response($nodes);
    }