public function on_garbage_collection()
	{
		if (substr($GLOBALS['request']->server('SCRIPT_NAME'), -7) === 'app.php')
		{
			return;
		}

		// An Exception is throw because the TraceableEventDispatcher
		// stop all the events when KernelEvents::RESPONSE is trigger.
		// But because we are emulating the event through the
		// garbage_collection event, we got an exception at the end
		// of the dispatching of the event.
		// (stop() is called on an already stopped() event)
		set_exception_handler(array($this, 'exception_handler'));

		try {
			$response = new Response('<html><body></body></html>');
			$this->dispatcher->dispatch(KernelEvents::RESPONSE,
				new FilterResponseEvent(
					$this->http_kernel,
					$this->request_stack->getCurrentRequest(),
					HttpKernelInterface::MASTER_REQUEST,
					$response
				));

			if ($this->redirect_url !== null)
			{
				$url = $this->redirect_url;

				// Redirect via an HTML form for PITA webservers
				if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE')))
				{
					header('Refresh: 0; URL=' . $url);

					echo '<!DOCTYPE html>';
					echo '<html dir="Direction" lang="en">';
					echo '<head>';
					echo '<meta charset="utf-8">';
					echo '<meta http-equiv="refresh" content="0; url=' . str_replace('&', '&amp;', $url) . '" />';
					echo '<title>Redirect</title>';
					echo '</head>';
					echo '<body>';
					echo '<div style="text-align: center;"><a href="' . str_replace('&', '&amp;', $url) . '">Redirect</a></div>';
					echo '</body>';
					echo '</html>';

					$this->dispatcher->dispatch(KernelEvents::TERMINATE,
					new PostResponseEvent($this->http_kernel,
							$this->request_stack->getCurrentRequest(),
							$response
						)
					);
					exit;
				}

				// Behave as per HTTP/1.1 spec for others
				header('Location: ' . $url);
				$this->dispatcher->dispatch(KernelEvents::TERMINATE,
					new PostResponseEvent($this->http_kernel,
						$this->request_stack->getCurrentRequest(),
						$response
					)
				);
				exit;
			}
			else if ($response->getContent() !== '<html><body></body></html>')
			{
				if ('<html><body></body></html>' !== $response->getContent())
				{
					echo $response->getContent();
				}
			}

			$this->dispatcher->dispatch(KernelEvents::TERMINATE,
				new PostResponseEvent($this->http_kernel,
					$this->request_stack->getCurrentRequest(),
					$response
				)
			);
		}
		catch (\Exception $e)
		{dump($e);
		}
	}
public function on_garbage_collection()
	{
		if (substr($GLOBALS['request']->server('SCRIPT_NAME'), -7) === 'app.php')
		{
			return;
		}

		// An Exception is throw because the TraceableEventDispatcher
		// stop all the events when KernelEvents::RESPONSE is trigger.
		// But because we are emulating the event through the
		// garbage_collection event, we got an exception at the end
		// of the dispatching of the event.
		// (stop() is called on an already stopped() event)
		set_exception_handler(array($this, 'exception_handler'));

		try {
			$response = new Response('<html><body></body></html>');
			$this->dispatcher->dispatch(KernelEvents::RESPONSE,
				new FilterResponseEvent(
					$this->http_kernel,
					$this->request_stack->getCurrentRequest(),
					HttpKernelInterface::MASTER_REQUEST,
					$response
				));

			if ($this->redirect_url !== null)
			{
				$url = $this->redirect_url;

				// Redirect via an HTML form for PITA webservers
				if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE')))
				{
					header('Refresh: 0; URL=' . $url);

					echo '<!DOCTYPE html>';
					echo '<html dir="Direction" lang="en">';
					echo '<head>';
					echo '<meta charset="utf-8">';
					echo '<meta http-equiv="refresh" content="0; url=' . str_replace('&', '&amp;', $url) . '" />';
					echo '<title>Redirect</title>';
					echo '</head>';
					echo '<body>';
					echo '<div style="text-align: center;"><a href="' . str_replace('&', '&amp;', $url) . '">Redirect</a></div>';
					echo '</body>';
					echo '</html>';

					$this->dispatcher->dispatch(KernelEvents::TERMINATE,
					new PostResponseEvent($this->http_kernel,
							$this->request_stack->getCurrentRequest(),
							$response
						)
					);
					exit;
				}

				// Behave as per HTTP/1.1 spec for others
				header('Location: ' . $url);
				$this->dispatcher->dispatch(KernelEvents::TERMINATE,
					new PostResponseEvent($this->http_kernel,
						$this->request_stack->getCurrentRequest(),
						$response
					)
				);
				exit;
			}
			else if ($response->getContent() !== '<html><body></body></html>')
			{
				if ('<html><body></body></html>' !== $response->getContent())
				{
					echo $response->getContent();
				}
			}

			$this->dispatcher->dispatch(KernelEvents::TERMINATE,
				new PostResponseEvent($this->http_kernel,
					$this->request_stack->getCurrentRequest(),
					$response
				)
			);
		}
		catch (\Exception $e)
		{dump($e);
		}
	}
public function on_garbage_collection ( ) { if ( substr ( $ GLOBALS [ 'request' ] -> server ( 'SCRIPT_NAME' ) , - 7 ) === 'app.php' ) { return ; } // An Exception is throw because the TraceableEventDispatcher // stop all the events when KernelEvents::RESPONSE is trigger. // But because we are emulating the event through the // garbage_collection event, we got an exception at the end // of the dispatching of the event. // (stop() is called on an already stopped() event) set_exception_handler ( array ( $ this , 'exception_handler' ) ) ; try { $ response = new Response ( '<html><body></body></html>' ) ; $ this -> dispatcher -> dispatch ( KernelEvents :: RESPONSE , new FilterResponseEvent ( $ this -> http_kernel , $ this -> request_stack -> getCurrentRequest ( ) , HttpKernelInterface :: MASTER_REQUEST , $ response ) ) ; if ( $ this -> redirect_url !== null ) { $ url = $ this -> redirect_url ; // Redirect via an HTML form for PITA webservers if ( @ preg_match ( '#Microsoft|WebSTAR|Xitami#' , getenv ( 'SERVER_SOFTWARE' ) ) ) { header ( 'Refresh: 0; URL=' . $ url ) ; echo '<!DOCTYPE html>' ; echo '<html dir="Direction" lang="en">' ; echo '<head>' ; echo '<meta charset="utf-8">' ; echo '<meta http-equiv="refresh" content="0; url=' . str_replace ( '&' , '&amp;' , $ url ) . '" />' ; echo '<title>Redirect</title>' ; echo '</head>' ; echo '<body>' ; echo '<div style="text-align: center;"><a href="' . str_replace ( '&' , '&amp;' , $ url ) . '">Redirect</a></div>' ; echo '</body>' ; echo '</html>' ; $ this -> dispatcher -> dispatch ( KernelEvents :: TERMINATE , new PostResponseEvent ( $ this -> http_kernel , $ this -> request_stack -> getCurrentRequest ( ) , $ response ) ) ; exit ; } // Behave as per HTTP/1.1 spec for others header ( 'Location: ' . $ url ) ; $ this -> dispatcher -> dispatch ( KernelEvents :: TERMINATE , new PostResponseEvent ( $ this -> http_kernel , $ this -> request_stack -> getCurrentRequest ( ) , $ response ) ) ; exit ; } else if ( $ response -> getContent ( ) !== '<html><body></body></html>' ) { if ( '<html><body></body></html>' !== $ response -> getContent ( ) ) { echo $ response -> getContent ( ) ; } } $ this -> dispatcher -> dispatch ( KernelEvents :: TERMINATE , new PostResponseEvent ( $ this -> http_kernel , $ this -> request_stack -> getCurrentRequest ( ) , $ response ) ) ; } catch ( \ Exception $ e ) { dump ( $ e ) ; } }
Emulate the kernel response event
Emulate the kernel response event