コード例 #1
0
ファイル: Heartbeat.class.php プロジェクト: xp-forge/nsca
 /**
  * Setup the class instance. A dsn string must be given with the relevant information
  * about the server and script:
  *
  * Eg: nagios://nagios.xp_framework.net:5667/service_to_monitor
  *
  * @param   string dsn
  */
 public function setup($dsn)
 {
     $url = new URL($dsn);
     $this->server = $url->getHost();
     $this->port = $url->getPort(5667);
     $this->version = $url->getParam('version', NscaProtocol::VERSION_2);
     $this->service = trim($url->getPath(), '/');
     $this->host = $url->getParam('hostname', System::getProperty('host.name'));
     if (false !== $url->getParam('domain', false)) {
         $this->host .= '.' . ltrim($url->getParam('domain'), '.');
     }
 }
コード例 #2
0
 public function scalar_parameter_overwritten_by_hash()
 {
     $u = new URL('http://unittest.localhost/includes/orderSuccess.inc.php?&glob=1&cart_order_id=1&glob[rootDir]=http://cirt.net/rfiinc.txt?');
     $this->assertEquals(['rootDir' => 'http://cirt.net/rfiinc.txt?'], $u->getParam('glob'));
 }
コード例 #3
0
 /**
  * Parse DSN
  *
  * @param   string dsn
  * @return  bool success
  */
 protected function _parsedsn($dsn)
 {
     if (null === $dsn) {
         return true;
     }
     $u = new URL($dsn);
     if (!$u->getHost()) {
         throw new \lang\IllegalArgumentException('DSN parsing failed ["' . $dsn . '"]');
     }
     // Scheme
     switch (strtoupper($u->getScheme())) {
         case 'ESMTP':
             $this->ext = true;
             break;
         case 'SMTP':
             $this->ext = false;
             break;
         default:
             throw new \lang\IllegalArgumentException('Scheme "' . $u->getScheme() . '" not supported');
     }
     // Copy host and port
     $this->host = $u->getHost();
     $this->port = $u->getPort() ? $u->getPort() : 25;
     // User & password
     if ($u->getUser()) {
         $this->auth = $u->getParam('auth', SMTP_AUTH_PLAIN);
         $this->user = $u->getUser();
         $this->pass = $u->getPassword();
     }
 }
コード例 #4
0
 public function handleSessionInitializationError()
 {
     $req = $this->newRequest('GET', new URL('http://localhost/?psessionid=MALFORMED'));
     $res = new HttpScriptletResponse();
     $s = newinstance('scriptlet.HttpScriptlet', [], ['needsSession' => function ($request) {
         return true;
     }, 'handleSessionInitialization' => function ($request) {
         if (!preg_match('/^a-f0-9$/', $request->getSessionId())) {
             throw new IllegalArgumentException('Invalid characters in session id');
         }
         parent::handleSessionInitialization($request);
     }, 'handleSessionInitializationError' => function ($request, $response) {
         $request->getURL()->addParam('relogin', 1);
         return $request->session->initialize(null);
     }]);
     $s->service($req, $res);
     $this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals('/', $redirect->getPath());
     $this->assertEquals(session_id(), $redirect->getParam('psessionid'));
     $this->assertEquals('1', $redirect->getParam('relogin'));
 }
コード例 #5
0
ファイル: Connection.class.php プロジェクト: xp-forge/stomp
 private function _sendAuthenticateFrame(URL $url)
 {
     $frame = $this->sendFrame(new LoginFrame($url->getUser(), $url->getPassword(), $url->getParam('vhost', $url->getHost()), $url->hasParam('versions') ? explode(',', $url->getParam('versions')) : ['1.0', '1.1']));
     if (!$frame instanceof Frame) {
         throw new ProtocolException('Did not receive frame, got: ' . \xp::stringOf($frame));
     }
     if ($frame instanceof ErrorFrame) {
         throw new AuthenticationException('Could not establish connection to broker "' . $url->toString() . '": ' . $frame->getBody(), $url->getUser(), strlen($url->getPassword() > 0) ? 'with password' : 'no password');
     }
     if (!$frame instanceof ConnectedFrame) {
         throw new AuthenticationException('Could not log in to stomp broker "' . $url->toString() . '": Got "' . $frame->command() . '" frame', $url->getUser(), strlen($url->getPassword() > 0) ? 'with password' : 'no password');
     }
     $this->debug('~ Connected to server; server ' . ($frame->getProtocolVersion() ? 'chose protocol version ' . $frame->getProtocolVersion() : 'did not indicate protocol version'));
 }
コード例 #6
0
 public function arrayParamOverwritesParamWithoutFatalError()
 {
     $u = new URL('http://unittest.localhost/includes/orderSuccess.inc.php?&glob=1&cart_order_id=1&glob[rootDir]=http://cirt.net/rfiinc.txt?');
     $this->assertEquals(array('rootDir' => 'http://cirt.net/rfiinc.txt?'), $u->getParam('glob'));
 }
コード例 #7
0
ファイル: URLTest.class.php プロジェクト: johannes85/core
 public function parseUnencodedAssociativeArray()
 {
     $u = new URL('http://example.com/ajax?load=getXML&data[projectName]=project&data[langCode]=en');
     $this->assertEquals(['projectName' => 'project', 'langCode' => 'en'], $u->getParam('data'));
 }