getEventDispatcher() public method

public getEventDispatcher ( )
示例#1
0
$url = base64_decrypt($_GET['q']);
$proxy = new Proxy();
// load plugins
foreach (Config::get('plugins', array()) as $plugin) {
    $plugin_class = $plugin . 'Plugin';
    if (file_exists('./plugins/' . $plugin_class . '.php')) {
        // use user plugin from /plugins/
        require_once './plugins/' . $plugin_class . '.php';
    } else {
        if (class_exists('\\Proxy\\Plugin\\' . $plugin_class)) {
            // does the native plugin from php-proxy package with such name exist?
            $plugin_class = '\\Proxy\\Plugin\\' . $plugin_class;
        }
    }
    // otherwise plugin_class better be loaded already through composer.json and match namespace exactly \\Vendor\\Plugin\\SuperPlugin
    $proxy->getEventDispatcher()->addSubscriber(new $plugin_class());
}
try {
    // request sent to index.php
    $request = Request::createFromGlobals();
    // remove all GET parameters such as ?q=
    $request->get->clear();
    // forward it to some other URL
    $response = $proxy->forward($request, $url);
    // if that was a streaming response, then everything was already sent and script will be killed before it even reaches this line
    $response->send();
} catch (Exception $ex) {
    // if the site is on server2.proxy.com then you may wish to redirect it back to proxy.com
    if (Config::get("error_redirect")) {
        $url = render_string(Config::get("error_redirect"), array('error_msg' => rawurlencode($ex->getMessage())));
        // Cannot modify header information - headers already sent
示例#2
0
$url = base64_decrypt($_GET['q']);
$proxy = new Proxy();
// load plugins
foreach (Config::get('plugins', array()) as $plugin) {
    $plugin_class = $plugin . 'Plugin';
    if (file_exists('./plugins/' . $plugin_class . '.php')) {
        // use user plugin from /plugins/
        require_once './plugins/' . $plugin_class . '.php';
    } else {
        if (class_exists('\\Proxy\\Plugin\\' . $plugin_class)) {
            // does the native plugin from php-proxy package with such name exist?
            $plugin_class = '\\Proxy\\Plugin\\' . $plugin_class;
        }
    }
    // otherwise plugin_class better be loaded already and match namespace exactly \\Vendor\\Plugin\\SuperPlugin
    $proxy->getEventDispatcher()->addSubscriber(new $plugin_class());
}
// provide URL form
$proxy->getEventDispatcher()->addListener('request.complete', function ($event) {
    $request = $event['request'];
    $response = $event['response'];
    $url = $request->getUri();
    // we attach url_form only if this is a html response
    if (!is_html($response->headers->get('content-type'))) {
        return;
    }
    #	$url_form = render_template("./templates/url_form.php", array(
    #		'url' => $url
    #	));
    $output = $response->getContent();
    // does the html page contain <body> tag, if so insert our form right after <body> tag starts