Dispatch an AJAX request
@param string
@param \DataContainer
332804
public function dispatchAjaxRequest($strAction, \DataContainer $dc)
    {
        switch ($strAction) {
            // Upload the file
            /** @noinspection PhpMissingBreakStatementInspection */
            case 'fineuploader_upload':
                $arrData['strTable'] = $dc->table;
                $arrData['id'] = $dc->id; // @todo what was $this->strAjaxName for?
                $arrData['name'] = \Input::post('name');

                /** @var FineUploaderWidget $objWidget */
                $objWidget = new $GLOBALS['BE_FFL']['fineUploader']($arrData, $dc);
                $strFile = $objWidget->validateUpload();

                if ($objWidget->hasErrors()) {
                    $arrResponse = array('success' => false, 'error' => $objWidget->getErrorAsString(), 'preventRetry' => true);
                } else {
                    $arrResponse = array('success' => true, 'file' => $strFile);
                }

                $response = new \Haste\Http\Response\JsonResponse($arrResponse);
                $response->send();
            // no break, response exits script

            // Reload the widget
            case 'fineuploader_reload':
                $intId = \Input::get('id');
                $strField = $dc->field = \Input::post('name');

                // Handle the keys in "edit multiple" mode
                if (\Input::get('act') == 'editAll') {
                    $intId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', $strField);
                    $strField = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $strField);
                }

                // The field does not exist
                if (!isset($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField])) {
                    System::log('Field "' . $strField . '" does not exist in DCA "' . $dc->table . '"', __METHOD__, TL_ERROR);
                    header('HTTP/1.1 400 Bad Request');
                    die('Bad Request');
                }

                $objRow = null;
                $varValue = null;

                // Load the value
                if ($GLOBALS['TL_DCA'][$dc->table]['config']['dataContainer'] == 'File') {
                    $varValue = $GLOBALS['TL_CONFIG'][$strField];
                } elseif ($intId > 0 && Database::getInstance()->tableExists($dc->table)) {
                    $objRow = Database::getInstance()->prepare("SELECT * FROM " . $dc->table . " WHERE id=?")
                        ->execute($intId);

                    // The record does not exist
                    if ($objRow->numRows < 1) {
                        System::log('A record with the ID "' . $intId . '" does not exist in table "' . $dc->table . '"', __METHOD__, TL_ERROR);
                        header('HTTP/1.1 400 Bad Request');
                        die('Bad Request');
                    }

                    $varValue = $objRow->$strField;
                    $dc->activeRecord = $objRow;
                }

                // Call the load_callback
                if (is_array($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'])) {
                    foreach ($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'] as $callback) {
                        if (is_array($callback)) {
                            $varValue = System::importStatic($callback[0])->{$callback[1]}($varValue, $dc);
                        } elseif (is_callable($callback)) {
                            $varValue = $callback($varValue, $dc);
                        }
                    }
                }

                $varValue = \Input::post('value', true);

                // Convert the selected values
                if ($varValue != '') {
                    $varValue = trimsplit(',', $varValue);

                    foreach ($varValue as $k => $v) {
                        if (\Validator::isUuid($v) && !is_file(TL_ROOT . '/' . $v)) {
                            $varValue[$k] = \StringUtil::uuidToBin($v);
                        }
                    }

                    $varValue = serialize($varValue);
                }

                // Build the attributes based on the "eval" array
                $arrAttribs = $GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['eval'];

                $arrAttribs['id'] = $dc->field;
                $arrAttribs['name'] = $dc->field;
                $arrAttribs['value'] = $varValue;
                $arrAttribs['strTable'] = $dc->table;
                $arrAttribs['strField'] = $strField;
                $arrAttribs['activeRecord'] = $dc->activeRecord;

                $objWidget = new $GLOBALS['BE_FFL']['fineUploader']($arrAttribs);
                $response = new \Haste\Http\Response\HtmlResponse($objWidget->parse());
                $response->send();
        }
    }
43938
public function executePostActions(DataContainerInterface $container)
    {
        \header('Content-Type: text/html; charset=' . $GLOBALS['TL_CONFIG']['characterSet']);

        $this->objDc = $container;

        $action = $this->getEnvironment()->getInputProvider()->getValue('action');

        if (\in_array(
            $action,
            [
                // This is impossible to handle generically in DcGeneral.
                'toggleFeatured',
                // DcGeneral handles sub palettes differently.
                'toggleSubpalette'
            ]
        )) {
            return;
        }

        if (\in_array(
            $action,
            [
                // Load nodes of the page structure tree. Compatible between 2.X and 3.X.
                'loadStructure',
                // Load nodes of the file manager tree.
                'loadFileManager',
                // Load nodes of the page tree.
                'loadPagetree',
                // Load nodes of the file tree.
                'loadFiletree',
                // Reload the page/file picker.
                'reloadPagetree',
                'reloadFiletree',
                'setLegendState'
            ]
        )) {
            $this->{$action}();
            return;
        }

        $ajax = new ContaoAjax($action);
        $ajax->executePreActions();
        $ajax->executePostActions(new DcCompat($this->getEnvironment(), $this->getActiveModel()));
    }
466955
public function sendRequest()
    {
        if ($this->getError()->hasError()) {
            return;
        }

        if (class_exists($this->dispatcher)) {
            $dispatcherClass = $this->dispatcher;
            $dispatcher = new $dispatcherClass($this->instance->getQuery());
            if ($dispatcher instanceof AbstractDispatcher) {
                try {
                    $client = new \SoapCLient($this->getUrl(), array('trace' => 1));

                    $config = $this->config->getRawConfig();
                    $sql = $this->instance->getQuery()->toString();
                    $limit = $this->instance->getQuery()->getLimit();
                    $offset = $this->instance->getQuery()->getOffset();
                    $single = $this->instance->getQuery()->isSingle();

                    if ($this->method == 'getAvailableDrivers') {
                        $this->availableDrivers = $client->getAvailableDrivers();
                    } elseif ($this->method == 'getServerVersion') {
                        $res = $client->getServerVersion();
                        $this->serverVersion = isset($res['version']) ? $res['version'] : null;
                    } else {
                        $response = $client->getResult($config, $sql, $limit, $offset, $single, $this->getKey(), 'array');
                        $dispatcher->dispatch($response);
                    }
                } catch (\SoapFault $e) {
                    $this->getError()->setMessage($e->getMessage());
                } catch (\Exception $e) {
                    $this->getError()->setMessage('Error server response');
                }
            } else {
                $this->getError()->setMessage(sprintf(
                    'Dispatcher class must be instance of %s, %s given',
                    AbstractDispatcher::class,
                    (string) $this->dispatcher
                ));
            }
        } else {
            $this->getError()->setMessage(sprintf('Class %s not found', (string) $this->dispatcher));
        }
    }
718682
public void dispatchEvent(Event event, String eventName) {
    int typeInt = Event.getTypeInt(eventName);
    Object[] handlerData = $(element).data(EVENT_DATA);
    for (int i = 0, l = elementEvents.length(); i < l; i++) {
      BindFunction listener = elementEvents.get(i);
      String namespace = JsUtils.prop(event, "namespace");
      boolean matchEV = listener != null && (listener.hasEventType(typeInt) || listener.isTypeOf(eventName));
      boolean matchNS = matchEV && (isNullOrEmpty(namespace) || listener.nameSpace.equals(namespace));
      if (matchEV && matchNS) {
        if (!listener.fire(event, typeInt, eventName, handlerData)) {
          event.stopPropagation();
          event.preventDefault();
        }
      }
    }
  }
592991
protected function handleRequest(): void
    {
        $validator = Validator::make(
            $this->getAttribute('request')->only('rowsNumber', 'search', 'sortBy', 'sortDir'),
            [
                'rowsNumber' => 'required|numeric',
                'search'     => 'nullable|string',
                'sortBy'     => 'nullable|string|in:' . $this->getAttribute('columns')->implode('attribute', ','),
                'sortDir'    => 'nullable|string|in:asc,desc',
            ]
        );
        if ($validator->fails()) {
            $this->getAttribute('request')->merge([
                'rowsNumber' => $this->getAttribute('rowsNumber')
                    ? $this->getAttribute('rowsNumber')
                    : config('tablelist.value.rows_number'),
                'search'     => null,
                'sortBy'     => $this->getAttribute('sortBy'),
                'sortDir'    => $this->getAttribute('sortDir'),
            ]);
        } else {
            $this->setAttribute('rowsNumber', $this->getAttribute('request')->rowsNumber);
            $this->setAttribute('search', $this->getAttribute('request')->search);
        }
    }
183242
function dispatch($uri) {

    # E_USER_ERROR|E_USER_WARNING|E_USER_NOTICE|E_RECOVERABLE_ERROR = 5888
    $old_handler = set_error_handler(array($this, 'error_handler'), 5888);

    ob_start();
    $level = ob_get_level();

    $this->map_uri_to_response($this->clean_request_uri((string) $uri))->output();

    while (ob_get_level() >= $level) {
      ob_end_flush();
    }

    if (isset($old_handler)) {
      set_error_handler($old_handler);
    }
  }
655804
public function call(string $event, $data = null)
    {
        if (!$this->eventExists($event)) {
            return;
        }

        // inject request param on connect event
        $isConnect = $event === static::EVENT_CONNECT;
        $dataKey   = $isConnect ? 'request' : 'data';

        return $this->app->invoke($this->callbacks[$event], [
            'websocket' => $this,
            $dataKey    => $data,
        ]);
    }
170255
public function execute(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
		$httpRequestResponse = new HTTPRequestResponseContainer($request, $response);

		$this->dispatchRequestFilters($httpRequestResponse);

		$this->dispatchResponseFilters($httpRequestResponse);

		return $httpRequestResponse->getResponse();
	}
155261
public function handle(
        ServerRequestInterface $request,
        ResponseInterface $response = null,
        $catch = self::DEFAULT_ERROR_CATCH
    )
    {
        /** @var ResponseInterface $response */
        // Passes the request to the container
        if (!$this->getContainer()->has(ServerRequestInterface::class)) {
            $this->getContainer()->share(ServerRequestInterface::class, $request);
        }

        //inject request content type
        $contentType = ServerRequestFactory::getHeader('content-type', $this->getRequest()->getHeaders(), '');
        $this->setContentType($contentType);

        if ($response === null) {
            $response = $this->getResponse();
        }

        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);

        try {
            $response = $this->handleResponse($this->handleRequest($request), $response);
        }catch (\Exception $exception){
            $notFoundException = $exception instanceof NotFoundException;
            $response = $this->handleError($exception, $request, $response, $catch)
                ->withStatus($notFoundException ? 404 : 500);
        }

        // validate response
        $response = $this->validateContract($response, ResponseInterface::class);

        // update content type
        $this->setContentType(ServerRequestFactory::getHeader('content-type', $response->getHeaders(), ''));

        return $response;
    }
477676
private function load(iterable $data, $item, $key, bool $flush, int &$flushCounter, int &$totalCounter): void
    {
        try {
            ($this->load)($data, $key, $this);
            $this->eventDispatcher->dispatch(new ItemEvent(EtlEvents::LOAD, $item, $key, $this));
        } catch (\Throwable $e) {
            /** @var ItemExceptionEvent $event */
            $event = $this->eventDispatcher->dispatch(new ItemExceptionEvent(EtlEvents::LOAD_EXCEPTION, $item, $key, $this, $e));
            if ($event->shouldThrowException()) {
                throw $e;
            }
            $flushCounter--;
            $totalCounter--;
        }

        if (true === $flush) {
            $this->flush($flushCounter, true);
        }
    }
903781
public function exec(): void
    {
        if (Application::route()->isAjax()) {
            // if is ajax
            $this->handleExceptionInAjax($this->e);
        } else {
            // normal request
            $this->handleExceptionInNormalRequest($this->e);
        }
    }
1313724
public function doDispatch(DispatchEvent $event)
    {
        $controller = $event->getContext();
        $action     = $event->getParam('action') . 'Action';

        $server   = $this->getServer();
        $request  = $server->getRequest()->withAddedAttributes($event->getParams());
        $response = $server->getResponse();

        $result = call_user_func_array([$controller, $action], [$request, $response]);
        $event->setResult($result);
    }
609492
public function dispatchEvent($event) {
		$type = $event->getType();
		if (isset($this->eventsListeners[$type])) {
			for ($j = 0; $j < count($this->eventsListeners[$type]); $j++) {
				list($plugin, $action) = explode(':', $this->eventsListeners[$type][$j]);
				//加载plugin && 调用action
				//echo $type.'<br/>';
				$this->app->runPluginAction($plugin, $action, $event);
			}
		}
		
	}
355235
function _data_handler($parser, $data)
    {
        if (!isset($this->current) || is_object($this->current)) {
            return;
        }
        $this->current.= trim($data);
    }
821791
protected function dispatch($request, $response)
    {
        $this->setRequest($request);
        $this->setResponse($response);
        if (!$this->responder) {
            $this->responder = Respond::getResponder();
        }
        return $this->_execInternalMethods();
    }
950
protected function dispatchToRouter() : Closure
    {
        return function ($request) {
            return $this->router->setContainer($this->container)->dispatch($request);
        };
    }
715591
function (type, data) {
    if (!_.isString(type)) {
      console.warn('Action types are required when calling dispatcher.dispatch()');
      return;
    }

    this.dispatcher.dispatch({
      type: type,
      data: data
    });
  }