Callback called after executing action.
Transforms requests to a format ExtJs accepts.
Also turns on caching, because this request might be chained.

@return Void
551394
public function postDispatch() {
        parent::postDispatch();
        if (!empty($this->_postModifyMethods)) {
            $response = Zend_Json::decode($this->view->response, Zend_Json::TYPE_ARRAY);
            $modifiedResponse = array();
            /**
             * Check if this was a batch request. In that case the array is a plain array of
             * arrays. If not, there will be a 'jsonrpc' key in the root of the array.
             */
            $batch = !array_key_exists('jsonrpc', $response);
            if (!$batch) {
                $response = array($response);
            }
            /**
             * Post modify methods are recorded from $this:preDispatch()
             */
            foreach ($this->_postModifyMethods as $i => $postMethod) {
                if (!empty($response[$i]) && !empty($this->_originalRequests[$i])) {
                    $modifyMethod = '_modifyAfter' . ucfirst($postMethod);
                    $response[$i] = $this->{$modifyMethod}(
                        $response[$i],
                        $this->_originalRequests[$i]
                    );
                }
            }
            if ($batch) {
                $this->view->response = Zend_Json::encode($response);
            } else {
                $this->view->response = Zend_Json::encode($response[0]);
            }
        }
        $this->_toggleCache(true);
    }
898597
public function afterRegistry()
    {
        parent::afterRegistry();

        // Loaded from tracker and tracker does not always have the request as source value
        if (! $this->request instanceof \Zend_Controller_Request_Abstract) {
            $this->request = \Zend_Controller_Front::getInstance()->getRequest();
        }
    }
1182376
public function onFinish()
    {
        if ($this->eofTerminated) {
            $this->requestFinished();
            $this->onResponse->executeAll($this, false);
            parent::onFinish();
            return;
        }
        if ($this->protocolError) {
            $this->onResponse->executeAll($this, false);
        } else {
            if (($this->state !== self::STATE_ROOT) && !$this->onResponse->isEmpty()) {
                $this->requestFinished();
            }
        }
        parent::onFinish();
    }
751991
private function after(callable $after): void
    {
        if ($after instanceof Closure) {
            $this->options["after"] = $after->bindTo($this);
        } else {
            $this->options["after"] = $after;
        }
    }
345526
public function execute($action = NULL)
	{
		$action = ($action == NULL)
			? strtolower($this->request->getMethod())
			: $action;

		$this->before();
		$this->{$action}();
		$this->after();
	}
668354
public function runAfter() {
        if($this->_afterController !== null) {
            foreach($this->_afterController as $hookProvider) {
                $hookProvider->doAfter();
            }
        }
    }
708217
public function onWpLoaded()
    {
        if ($this->c::isCli()) {
            return; // Not applicable.
        } elseif (empty($_REQUEST[$this->var])) {
            return; // Not applicable.
        }
        $this->action = (string) $_REQUEST[$this->var];
        $this->action = $this->c::unslash($this->action);
        $this->action = $this->c::mbTrim($this->action);

        $this->c::noCacheFlags(); // Flag as do NOT cache.
        $this->c::noCacheHeaders(); // Send headers also.

        if ($this->viaAjax($this->action)) {
            header('content-type: application/json; charset=utf-8');
            $this->c::isAjax(true);
        } elseif ($this->viaApi($this->action)) {
            header('content-type: application/json; charset=utf-8');
            $this->api_version = $this->parseApiVersion($this->action);
            $this->action      = $this->stripApiVersion($this->action);
            $this->c::isApi(true);
        }
        $this->c::doingRestAction($this->action); // w/o API version.

        if (!isset($this->registered_actions[$this->action])) {
            $this->s::dieInvalid(); // Unregistered!
        }
        $actor = $this->registered_actions[$this->action];

        if ($actor['requires_valid_nonce']) {
            $this->s::requireValidNonce($this->action);
        }
        $Utility = $this->App->Utils->{$actor['class']};
        $Utility->{$actor['method']}($this->action);
    }
1099528
public function execute()
    {
        // Execute the before execution event
        $this->runtimeManager->executeEvent('\\Zepi\\Turbo\\Event\\BeforeExecution');
        
        // Get the event name for the request and execute the event
        $eventName = $this->routeManager->getEventNameForRoute($this->request);
        $eventName = $this->runtimeManager->executeFilter('\\Zepi\\Turbo\\Filter\\VerifyEventName', $eventName);

        if ($eventName !== false && $eventName != '') {
            $this->runtimeManager->executeEvent($eventName);
        } else {
            $this->runtimeManager->executeEvent('\\Zepi\\Turbo\\Event\\RouteNotFound');
        }
        
        // Execute the after execution event
        $this->runtimeManager->executeEvent('\\Zepi\\Turbo\\Event\\AfterExecution');

        // Finalize the output
        $this->runtimeManager->executeEvent('\\Zepi\\Turbo\\Event\\FinalizeOutput');
        
        // Execute the before output event
        $this->runtimeManager->executeEvent('\\Zepi\\Turbo\\Event\\BeforeOutput');
        
        // Print the output
        echo $this->response->getOutput();
        
        // Execute the after output event
        $this->runtimeManager->executeEvent('\\Zepi\\Turbo\\Event\\AfterOutput');
    }
1169636
public function handleRequest(): void
	{
		global $save, $restore;

		$request = $this->getRequest();
		if ((!empty($save) || !empty($restore)) && $request->isPost() && check_bitrix_sessid()) {
			if (!empty($restore)) {
				// Restore defaults
				Option::delete(ADMIN_MODULE_NAME);
				CAdminMessage::showMessage([
					'MESSAGE' => Loc::getMessage('REFERENCES_OPTIONS_RESTORED'),
					'TYPE' => 'OK',
				]);
			} else {
				try {
					// Save options
					foreach ($this->options->getFields() as $id => $opt) {
						switch ($opt['type']) {
							case 'checkbox':
								$value = $request->getPost($id) ? true : false;
								break;

							case 'number':
								$value = (int)$request->getPost($id);
								break;

							case 'text':
							default:
								$value = $request->getPost($id);
								break;
						}

						$event = new Event(ADMIN_MODULE_NAME, 'OnBeforeSetOption_' . $id, ['value' => &$value]);
						$event->send();

						$event = new Event(ADMIN_MODULE_NAME, 'OnBeforeSetOption', ['value' => &$value, 'name' => $id]);
						$event->send();

						Option::set(ADMIN_MODULE_NAME, $id, $value);
					}

					$event = new Event(ADMIN_MODULE_NAME, 'OnAfterSaveOptions');
					$event->send();

					CAdminMessage::showMessage([
						'MESSAGE' => Loc::getMessage('REFERENCES_OPTIONS_SAVED'),
						'TYPE' => 'OK',
					]);
				} catch (\Exception $exception) {
					CAdminMessage::showMessage($exception->getMessage());
				}
			}
		}
	}
808449
protected function processRequest()
    {
        /** @var \Zend\Http\PhpEnvironment\Request $request */
        $request = $this->sm->get('Request');
        $url = explode('?', $request->getRequestUri());
        $this->url = $url[0];
        $params = $request->getQuery();
        if ($params->get('page')) {
            //set page
            $this->setPage((int)$params->get('page'));
        }

        if ($params->get('limit')) {
            //set limit
            $this->setLimit((int)$params->get('limit'));
        }

        foreach ($this->allowedOrders as $column) {
            $columnMod = str_replace('.', '_', $column);
            $order = $params->get('order-' . $columnMod);

            if ($order) {
                $this->setOrder([
                    $column => $order
                ]);
            }
        }

        foreach ($this->allowedFilters as $column) {
            $columnMod = str_replace('.', '_', $column);
            $filter = $params->get('filter-' . $columnMod);
            if ($filter) {
                $this->setFilter([$column => $filter]);
            }
        }
    }
513567
public function afterFilter() {
        if(!isset($this->_afterFilters[$this->_action])) {
            return false;
        }

        foreach($this->_afterFilters[$this->_action] as $method) {
            call_user_func($method);
        }
    }
97387
private function finalise()
    {
        // Send output to email
        $this->emailOutput();

        // Call any callback defined
        if (is_callable($this->after)) {
            call_user_func($this->after, $this->output, $this->returnCode);
        }
    }
567710
public function onAfterWrite()
    {
        parent::onAfterWrite();
        // Update all pages of this page type.
        foreach ($this->Pages() as $page){;
            $page->forceChange()->setPresets($this->Regions()->sort('Sort ASC'))->write();
        }
    }
565036
public function postFlush()
    {
        if (!$this->enabled || $this->isHandling) {
            return;
        }

        $this->isHandling = true;

        $aliaser = $this->container->get($this->aliaserServiceId);

        while (list($record, $action) = array_shift($this->records)) {
            $aliaser->createAlias($record, $action);
        }

        $this->isHandling = false;
    }
903781
public function exec(): void
    {
        if (Application::route()->isAjax()) {
            // if is ajax
            $this->handleExceptionInAjax($this->e);
        } else {
            // normal request
            $this->handleExceptionInNormalRequest($this->e);
        }
    }
246221
public function handleRequest() {
		$files = array();
		$supportsGzip = false;
		$expiresOffset = $this->parseTime($this->settings["expires"]);
		$tinymceDir = dirname(__FILE__);

		// Plugins
		$plugins = self::getParam("plugins");
		if ($plugins) {
			$this->settings["plugins"] = $plugins;
		}

		$plugins = array_unique(preg_split('/,/', $this->settings["plugins"], -1, PREG_SPLIT_NO_EMPTY));

		// Themes
		$themes = self::getParam("themes");
		if ($themes) {
			$this->settings["themes"] = $themes;
		}

		$themes = array_unique(preg_split('/,/', $this->settings["themes"], -1, PREG_SPLIT_NO_EMPTY));

		// Languages
		$languages = self::getParam("languages");
		if ($languages) {
			$this->settings["languages"] = $languages;
		}

		$languages = array_unique(preg_split('/,/', $this->settings["languages"], -1, PREG_SPLIT_NO_EMPTY));

		// Files
		$tagFiles = self::getParam("files");
		if ($tagFiles) {
			$this->settings["files"] = $tagFiles;
		}

		// Diskcache option
		$diskCache = self::getParam("diskcache");
		if ($diskCache) {
			$this->settings["disk_cache"] = ($diskCache === "true");
		}

		// Source or minified version
		$src = self::getParam("src");
		if ($src) {
			$this->settings["source"] = ($src === "true");
		}

		// Add core js
		if (self::getParam("core", "true") === "true") {
			$files[] = "tinymce";
		}

		// Add core languages
		foreach ($languages as $language) {
			$files[] = "langs/" . $language;
		}

		// Add plugins
		foreach ($plugins as $plugin) {
			$files[] = "plugins/" . $plugin . "/plugin";

			foreach ($languages as $language) {
				$files[] = "plugins/" . $plugin . "/langs/" . $language;
			}
		}

		// Add themes
		foreach ($themes as $theme) {
			$files[] = "themes/" . $theme . "/theme";

			foreach ($languages as $language) {
				$files[] = "themes/" . $theme . "/langs/" . $language;
			}
		}

		// Add any specified files.
		$allFiles = array_merge($files, array_unique(preg_split('/,/', $this->settings['files'], -1, PREG_SPLIT_NO_EMPTY)));

		// Process source files
		for ($i = 0; $i < count($allFiles); $i++) {
			$file = $allFiles[$i];

			if ($this->settings["source"] && file_exists($file . ".js")) {
				$file .= ".js";
			} else if (file_exists($file . ".min.js"))  {
				$file .= ".min.js";
			} else {
				$file = "";
			}

			$allFiles[$i] = $file;
		}

		// Generate hash for all files
		// CUSTOM SilverStripe Webroot-specific caches
		$hash = md5(implode('', $allFiles) . $_SERVER['SCRIPT_NAME']);
		// CUSTOM END

		// Check if it supports gzip
		$zlibOn = ini_get('zlib.output_compression') || (ini_set('zlib.output_compression', 0) === false);
		$encodings = (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) ? strtolower($_SERVER['HTTP_ACCEPT_ENCODING']) : "";
		$encoding = preg_match( '/\b(x-gzip|gzip)\b/', $encodings, $match) ? $match[1] : "";

		// Is northon antivirus header
		if (isset($_SERVER['---------------'])) {
			$encoding = "x-gzip";
		}

		$supportsGzip = $this->settings['compress'] && !empty($encoding) && !$zlibOn && function_exists('gzencode');

		// Set cache file name
		$cacheFile = $this->settings["cache_dir"] . "/tinymce.gzip-" . $hash . ($supportsGzip ? ".gz" : ".js");

 		// Set headers
		header("Content-type: text/javascript");
		header("Vary: Accept-Encoding");  // Handle proxies
		header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
		header("Cache-Control: public, max-age=" . $expiresOffset);

		if ($supportsGzip) {
			header("Content-Encoding: " . $encoding);
		}

		// Use cached file
		if ($this->settings['disk_cache'] && file_exists($cacheFile)) {
			readfile($cacheFile);
			return;
		}

		// Set base URL for where tinymce is loaded from
		$buffer = "var tinyMCEPreInit={base:'" . dirname($_SERVER["SCRIPT_NAME"]) . "',suffix:'.min'};";

		// Load all tinymce script files into buffer
		foreach ($allFiles as $file) {
			if ($file) {
				$fileContents = $this->getFileContents($tinymceDir . "/" . $file);
//				$buffer .= "\n//-FILE-$tinymceDir/$file (". strlen($fileContents) . " bytes)\n";
				$buffer .= $fileContents;
			}
		}

		// Mark all themes, plugins and languages as done
		$buffer .= 'tinymce.each("' . implode(',', $files) . '".split(","),function(f){tinymce.ScriptLoader.markDone(tinyMCE.baseURL+"/"+f+".js");});';

		// Compress data
		if ($supportsGzip) {
			$buffer = gzencode($buffer, 9, FORCE_GZIP);
		}

		// Write cached file
		if ($this->settings["disk_cache"]) {
			@file_put_contents($cacheFile, $buffer);
		}

		// Stream contents to client
		echo $buffer;
	}
157815
protected function setAfterCleanupRoute()
    {
        // Default is just go to the index
        if ($this->cleanupAction && ($this->request->getActionName() !== $this->cleanupAction)) {
            $this->afterSaveRouteUrl = array(
                $this->request->getControllerKey() => $this->request->getControllerName(),
                $this->request->getActionKey() => $this->cleanupAction,
                );
        }
    }