/** * 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'), '.'); } }
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')); }
/** * 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(); } }
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')); }
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')); }
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')); }
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')); }