public function test_toString_withExceptions_returnsString() { $uc = new UrlComposer(); $result = $uc->__toString(); $this->assertTrue(is_string($result)); }
/** * @param string $name * * @return bool * @throws Exception * @throws \Retrinko\UrlComposer\Exceptions\UrlException */ public function closeConnection($name) { // Build URL: /nodes[?memory=true] $url = new UrlComposer($this->apiUrl); $url->addToPath('connections')->addToPath($name); // Build request $request = new JsonRequest($url->__toString(), RequestInterface::REQUEST_METHOD_DELETE); $request->setAuth($this->user, $this->pass); // Execute request $this->executeRequest($request); return true; }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Retrinko\UrlComposer\UrlComposer; try { $urlComposer = new UrlComposer('http://my-url.com'); $urlComposer->setUser('user')->addToPath('blog')->addToQuery('id', '25')->setFragment('fragment'); $url = $urlComposer->compose(); printf('URL: %s' . PHP_EOL, $url); } catch (\Exception $e) { printf('Exception!: %s' . PHP_EOL, $e->getMessage()); }