Example #1
0
 /**
  * get an endpoint
  *
  * @param string  $endpoint    endpoint
  * @param boolean $withHost    attach host name to the url
  * @param bool    $forceReload Switch to force a new api definition object will be provided.
  *
  * @return string
  */
 public function getEndpoint($endpoint, $withHost = false, $forceReload = false)
 {
     $this->loadApiDefinition($forceReload);
     $url = "";
     if ($withHost) {
         $url = empty($this->options['host']) ? $this->definition->getHost() : $this->options['host'];
     }
     $url .= $endpoint;
     return $url;
 }
Example #2
0
 /**
  * test add endpoint
  *
  * @return void
  */
 public function testAddEndpoints()
 {
     $host = "localhost:8000";
     $basePath = "/v2/default/path";
     $endpoints = ["/user", "/group", "/user/uploadImage"];
     $sut = new ApiDefinition();
     $sut->setBasePath($basePath);
     $sut->setHost($host);
     foreach ($endpoints as $endpoint) {
         $sut->addEndpoint($endpoint);
     }
     $apiEndpoints = $sut->getEndpoints(false, null);
     $this->assertEquals($host, $sut->getHost());
     $this->assertCount(3, $apiEndpoints);
     foreach ($endpoints as $id => $endpoint) {
         $this->assertTrue($sut->hasEndpoint($endpoint));
         $this->assertEquals($basePath . $endpoint, $apiEndpoints[$id]);
     }
 }