{@inheritdoc}

@return bool|ContactSourceEvent

@throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
430469
protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null)
    {
        if (!$entity instanceof ContactSource) {
            throw new MethodNotAllowedHttpException(['ContactSource']);
        }

        switch ($action) {
            case 'pre_save':
                $name = ContactSourceEvents::PRE_SAVE;
                break;
            case 'post_save':
                $name = ContactSourceEvents::POST_SAVE;
                break;
            case 'pre_delete':
                $name = ContactSourceEvents::PRE_DELETE;
                break;
            case 'post_delete':
                $name = ContactSourceEvents::POST_DELETE;
                break;
            default:
                return null;
        }

        if ($this->dispatcher->hasListeners($name)) {
            if (empty($event)) {
                $event = new ContactSourceEvent($entity, $isNew);
                $event->setEntityManager($this->em);
            }

            $this->dispatcher->dispatch($name, $event);

            return $event;
        } else {
            return null;
        }
    }
352536
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();

        // /app_dev.php/contacts?5454
        $requestUri = $request->getRequestUri();

        // /contacts
        $pathInfo = $request->getPathInfo();

        // /app_dev.php
        $baseUrl = $request->getBaseUrl();

        $uri = str_replace($baseUrl, '', $requestUri);

        $em = $this->doctrine->getManager();

        /** @var RedirectRepository $redirectRepository */
        $redirectRepository = $em->getRepository('CompoRedirectBundle:Redirect');

        /** @var Redirect $redirect */
        $redirect = $redirectRepository->findOneBy(
            [
                'urIn' => array_unique([$uri, $pathInfo]),
                'enabled' => true,
            ]
        );

        if ($redirect) {
            $event->setResponse(new RedirectResponse($baseUrl . $redirect->getUrOut(), 301));
            $event->stopPropagation();
        }

        $pageRepository = $em->getRepository(Page::class);

        $lastSlash = mb_substr($pathInfo, -1);

        if ('/' !== $lastSlash) {
            $page = $pageRepository->findOneBy(
                [
                    'url' => [$pathInfo . '/'],
                ]
            );

            if ($page) {
                $event->setResponse(new RedirectResponse($baseUrl . $pathInfo . '/', 301));
                $event->stopPropagation();
            }
        }
    }
1097546
function getById($contactId){
        return new Contact(
            $this->getContext(),
            new ResourcePathEntity($this->getContext(),$this->getResourcePath(),$contactId)
        );
    }
807693
public function add()
    {
        if (!$this->request->isAll(['ajax', 'post'])) {
            throw new MethodNotAllowedException();
        }

        $model = $this->request->data('model');
        $foreignKey = (int)$this->request->data('foreign_key');
        $languageId = Wasabi::contentLanguage()->id;
        $url = $this->_formatUrl($this->request->data('url'));
        $routeType = (int)$this->request->data('route_type');
        $element = $this->request->data('element');

        $routeData = [
            'url' => $url,
            'model' => $model,
            'foreign_key' => $foreignKey,
            'language_id' => $languageId,
        ];

        $route = $this->_addRoute($routeType, $routeData);

        $this->_render($route, $element);
    }
1299181
public function start()
    {
        $routeMethodSep = '>';
        $storage = $this->routeService->getStorage();
        foreach ($storage as $match => $route) {
            if (($matched = $this->matchHttpRequest($match)) !== false) {
                if (!in_array($this->request->getMethod(), $route->methods)) {
                    throw new MethodNotAllowedException();
                }
                $this->request->withAttributes($matched);

                $middleWares = new MiddleWares($this->getMiddleWareFromRoute($route));
                $decorators = $route->decorators;

                if (\is_string($route->callback)) {
                    if (strpos($route->callback, $routeMethodSep) !== false) {
                        list($controller, $method) = explode($routeMethodSep, $route->callback);
                        return $this->connectMiddlewares($controller, $method, $middleWares, $decorators);
                    }
                }

                return $this->connectMiddlewares($route->callback, '__invoke', $middleWares, $decorators);
            }
        }

        throw new NotFoundException();
    }
907799
public function initEventLog(ContactSource $source, Contact $contact, $lineNumber)
    {
        $eventLog = new ContactEventLog();
        $eventLog->setUserId($source->getCreatedBy())
            ->setUserName($source->getCreatedByUser())
            ->setBundle('lead')
            ->setObject('import')
            ->setObjectId($contact->getId())
            ->setProperties(
                [
                    'line' => $lineNumber,
                    'file' => $source->getOriginalFile(),
                ]
            );

        return $eventLog;
    }
263402
public function errorAction()
    {
        try {
            $order = $this->getPaymentHandler()->handleError($this->getCurrentRequest(), $this->getBasket());
        } catch (EntityNotFoundException $ex) {
            throw new NotFoundHttpException($ex->getMessage());
        } catch (InvalidTransactionException $ex) {
            throw new UnauthorizedHttpException($ex->getMessage());
        }

        return $this->render('SonataPaymentBundle:Payment:error.html.twig', [
            'order' => $order,
        ]);
    }
219765
public function deleteAddressAction($id)
    {
        if ('POST' !== $this->getCurrentRequest()->getMethod()) {
            throw new MethodNotAllowedHttpException(['POST']);
        }

        $address = $this->getAddressManager()->findOneBy(['id' => $id]);

        $this->checkAddress($address);

        $this->getAddressManager()->delete($address);

        $this->get('session')->getFlashBag()->add('sonata_customer_success', 'customer_address_delete');

        return new RedirectResponse($this->generateUrl('sonata_customer_addresses'));
    }
342689
public function handleNotAllowed(ServerRequestInterface $request, ResponseInterface $response, array $methods)
    {
        $status = ($request->getMethod() === 'OPTIONS') ? 200 : 405;

        $contents = [
            'message' => 'Method not allowed',
            'status' => $status,
            'allowed_methods' => implode(', ', $methods),
        ];

        return $this
            ->withHTML($response, $contents)
            ->withStatus($status);
    }
652644
protected function getValidMethod($method)
    {
        $method = strtolower($method);

        if (strpos(self::HTTP_METHODS, $method) === false) {
            throw new MethodNotSupportedException($method);
        }

        return $method;
    }
81872
protected function handleGET()
    {
        if (!empty($this->resource)) {
            /** @type ServiceTypeInterface $type */
            if (null === $type = ServiceManager::getServiceType($this->resource)) {
                throw new NotFoundException("Service type '{$this->resource}' not found.");
            }

            return $type->toArray();
        }

        $resources = [];
        $group = $this->request->getParameter('group');
        $types = ServiceManager::getServiceTypes($group);
        /** @type ServiceTypeInterface $type */
        foreach ($types as $type) {
            $resources[] = $type->toArray();
        }

        $asList = $this->request->getParameterAsBool(ApiOptions::AS_LIST);
        $idField = $this->request->getParameter(ApiOptions::ID_FIELD, static::getResourceIdentifier());
        $fields = $this->request->getParameter(ApiOptions::FIELDS, ApiOptions::FIELDS_ALL);

        return ResourcesWrapper::cleanResources($resources, $asList, $idField, $fields);
    }
829678
public function isMethodFailure(): bool
    {
        if ($this->isSuccess() || $this->allowedMethods === self::HTTP_METHOD_ANY) {
            return false;
        }

        return true;
    }
449510
public function methodNotAllowedResponse(RequestInterface $request)
    {
        if ($this->methodNotAllowedChain) {
            return $this->methodNotAllowedChain->execute(
                [$this->server, $request],
                $this->middlewares
            );
        }
        return Response::make('<html><head><title>405 Method Not Allowed</title></head><body bgcolor="white"><h1>405 Method Not Allowed</h1></body></html>', 405);
    }
316046
public function call($method, array $arguments = [])
    {
        if ($this->value === null || isset($this->whitelist[$method]) || isset($this->whitelist['*']) || ($this->value instanceof ProtectedContextAwareInterface && $this->value->allowsCallOfMethod($method))) {
            return parent::call($method, $arguments);
        }
        throw new NotAllowedException('Method "' . $method . '" is not callable in untrusted context', 1369043080);
    }
220236
public function actionIndex()
    {
        $this->requirePostRequest();

        // Only allow front end requests
        $request = Craft::$app->getRequest();
        if (!$request->getIsSiteRequest()) {
            throw new NotFoundHttpException();
        }

        // Make sure the section exists
        $sectionId = $request->getBodyParam('sectionId');
        $sectionUid = $request->getBodyParam('sectionUid');
        $sectionHandle = $request->getBodyParam('sectionHandle');

        $sectionService = Craft::$app->getSections();

        if ($sectionHandle) {
            $section = $sectionService->getSectionByHandle($sectionHandle);
        } else if ($sectionUid) {
            $section = $sectionService->getSectionByUid($sectionUid);
        } else {
            $section = $sectionService->getSectionById((int) $sectionId);
        }

        if (!$section) {
            throw new BadRequestHttpException('Section does not exist.');
        }

        $sectionUid = $section->uid;

        // Make sure the section allows guest submissions
        $settings = Plugin::getInstance()->getSettings();
        $sectionSettings = $settings->getSection($sectionUid);

        if (!$sectionSettings->allowGuestSubmissions) {
            throw new BadRequestHttpException('Section '.$section->handle.' does not allow guest submissions.');
        }

        // Populate the entry
        $entry = $this->_populateEntryModel($section, $sectionSettings, $request);

        // Fire an 'onBeforeSave' event
        $event = new SaveEvent(['entry' => $entry]);
        $this->trigger(self::EVENT_BEFORE_SAVE_ENTRY, $event);

        if (!$event->isValid) {
            return $this->_returnError($settings, $entry);
        }

        if ($event->isSpam) {
            Craft::info('Guest entry submission suspected to be spam.', __METHOD__);
            // Pretend it worked.
            return $this->_returnSuccess($entry, true);
        }

        // Try to save it
        if ($sectionSettings->runValidation) {
            $entry->setScenario(Element::SCENARIO_LIVE);
        }

        if (!Craft::$app->getElements()->saveElement($entry)) {
            return $this->_returnError($settings, $entry);
        }

        return $this->_returnSuccess($entry);
    }
15091
public function update()
    {
        if (!$this->request->is('post')) {
            if ($this->request->is('ajax')) {
                throw new MethodNotAllowedException();
            } else {
                $this->Flash->error($this->invalidRequestMessage);
                $this->redirect(['action' => 'index']);
                return;
            }
        }

        if (empty($this->request->data) && !$this->request->is('ajax')) {
            $this->Flash->warning(__d('wasabi_core', 'There are no permissions to update yet.'));
            $this->redirect(['action' => 'index']);
            return;
        }

        // save the new language positions
        $permissions = $this->GroupPermissions->patchEntities(
            $this->GroupPermissions->find('all'),
            $this->request->data
        );

        /** @var Connection $connection */
        $connection = $this->GroupPermissions->connection();
        $connection->begin();
        foreach ($permissions as $permission) {
            if (!$this->GroupPermissions->save($permission)) {
                $connection->rollback();
                break;
            }
        }

        if ($connection->inTransaction()) {
            $connection->commit();
            Cache::clear(false, 'wasabi/core/group_permissions');
            if ($this->request->is('ajax')) {
                $status = 'success';
                $this->set(compact('status'));
                $this->set('_serialize', ['status']);
            } else {
                $this->Flash->success(__d('wasabi_core', 'All permissions have been saved.'));
                $this->redirect(['action' => 'index']);
                return;
            }
        } else {
            $this->Flash->error($this->dbErrorMessage);
        }
    }
722630
public function onContactSourceDelete(ContactSourceEvent $event)
    {
        $entity = $event->getContactSource();
        $log    = [
            'bundle'    => 'contactsource',
            'object'    => 'contactsource',
            'objectId'  => $entity->deletedId,
            'action'    => 'delete',
            'details'   => ['name' => $entity->getName()],
            'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
        ];
        $this->auditLogModel->writeToLog($log);
    }