상속: extends Proxy\AbstractProxy, implements proxy\PublicKeyRequiredInterface, implements proxy\PublicKeyTempRequiredInterface, implements proxy\PublicKeyNotFoundInterface, implements proxy\PublicKeyTempNotFoundInterface, implements proxy\PrivateKeyNotFoundInterface, implements proxy\PrivateTempKeyNotFoundInterface, implements proxy\UserNotRegisteredInterface
예제 #1
0
 public function testProxyWithAMissingCachingObjectThrowsException()
 {
     $this->expectException(\DomainException::class);
     $p = new Proxy();
     $p->setSubjectObject($this->mockSubject);
     $p->foo();
 }
예제 #2
0
 /**
  * @test
  */
 public function to_sends_request()
 {
     $request = Request::createFromGlobals();
     $url = 'http://www.example.com';
     $adapter = $this->getMockBuilder('\\Proxy\\Adapter\\Dummy\\DummyAdapter')->getMock();
     $adapter->expects($this->once())->method('send')->with($request, $url)->willReturn(Response::create());
     $proxy = new Proxy($adapter);
     $proxy->forward($request)->to($url);
 }
예제 #3
0
 /**
  * @test
  */
 public function to_sends_request()
 {
     $request = new Request('http://localhost/path?query=yes', 'GET');
     $url = 'https://www.example.com';
     $adapter = $this->getMockBuilder('Proxy\\Adapter\\Dummy\\DummyAdapter')->getMock();
     $verifyParam = $this->callback(function (RequestInterface $request) use($url) {
         return $request->getUri() == 'https://www.example.com/path?query=yes';
     });
     $adapter->expects($this->once())->method('send')->with($verifyParam)->willReturn(new Response());
     $proxy = new Proxy($adapter);
     $proxy->forward($request)->to($url);
 }
예제 #4
0
 /**
  * action for routing all requests directly to the third party API
  *
  * @param Request $request request
  *
  * @return \Psr\Http\Message\ResponseInterface|Response
  */
 public function proxyAction(Request $request)
 {
     $api = $this->decideApiAndEndpoint($request->getUri());
     $this->registerProxySources();
     $url = $this->apiLoader->getEndpoint($api['endpoint'], true);
     if (parse_url($url, PHP_URL_SCHEME) === false) {
         $scheme = $request->getScheme();
         $url = $scheme . '://' . $url;
     }
     $response = null;
     try {
         $newRequest = Request::create($url, $request->getMethod(), array(), array(), array(), array(), $request->getContent(false));
         $newRequest->headers->add($request->headers->all());
         $newRequest = $this->transformationHandler->transformRequest($api['apiName'], $api['endpoint'], $request, $newRequest);
         $psrRequest = $this->diactorosFactory->createRequest($newRequest);
         $psrRequest = $psrRequest->withUri($psrRequest->getUri()->withPort(parse_url($url, PHP_URL_PORT)));
         $psrResponse = $this->proxy->forward($psrRequest)->to($this->getHostWithScheme($url));
         $response = $this->httpFoundationFactory->createResponse($psrResponse);
         $this->transformationHandler->transformResponse($api['apiName'], $api['endpoint'], $response, clone $response);
     } catch (ClientException $e) {
         $response = $e->getResponse();
     } catch (ServerException $serverException) {
         $response = $serverException->getResponse();
     }
     return $response;
 }
예제 #5
0
 /**
  * @test
  */
 public function to_request_filter_returns_new_request()
 {
     $replace = new Request();
     $this->proxy->addRequestFilter(function (Request $request) use($replace) {
         return $replace;
     });
     $this->proxy->forward(Request::createFromGlobals())->to('/');
     $this->assertEquals($this->proxy->getRequest(), $replace);
 }
예제 #6
0
} else {
    if (!isset($_GET['q'])) {
        // must be at homepage - should we redirect somewhere else?
        if (Config::get('index_redirect')) {
            // redirect to...
            header("HTTP/1.1 302 Found");
            header("Location: " . Config::get('index_redirect'));
        } else {
            echo render_template("./templates/main.php", array('version' => Proxy::VERSION));
        }
        exit;
    }
}
// decode q parameter to get the real URL
$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());
}
 /**
  * constructor 
  */
 public function __construct()
 {
     parent::__construct();
     $this->hmacObj = new \Hmac\Hmac();
     $this->dalObject = new \Dal\Dal();
 }
예제 #8
0
} else {
    if (!isset($_GET['q'])) {
        // must be at homepage - should we redirect somewhere else?
        if (Config::get('index_redirect')) {
            // redirect to...
            header("HTTP/1.1 302 Found");
            header("Location: " . Config::get('index_redirect'));
        } else {
            echo render_template("./templates/main.php", array('version' => Proxy::VERSION));
        }
        exit;
    }
}
// decode q parameter to get the real URL
$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());
}