-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add host model + loadbalancer add host by configuration
- Loading branch information
Nicolas Bastien
committed
Jul 12, 2016
1 parent
77108b4
commit c74fde2
Showing
4 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace NBN\LoadBalancer\Exception; | ||
|
||
/** | ||
* @author Nicolas Bastien <[email protected]> | ||
*/ | ||
class AlreadyRegisteredHostException extends \RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace NBN\LoadBalancer\Host; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @author Nicolas Bastien <[email protected]> | ||
*/ | ||
class Host implements HostInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* @param string $id | ||
* @param string $url | ||
* @param array $settings | ||
*/ | ||
public function __construct($id, $url, array $settings) | ||
{ | ||
$this->id = $id; | ||
$this->url = $url; | ||
$this->settings = $settings; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getUrl() | ||
{ | ||
return $this->url; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSettings() | ||
{ | ||
return $this->settings; | ||
} | ||
|
||
/** | ||
* @param string $name Setting name | ||
* @param mixed $default Default value is setting is not set | ||
* @return mixed | ||
*/ | ||
public function getSetting($name, $default = null) | ||
{ | ||
if (isset($this->settings[$name])) { | ||
return $this->settings[$name]; | ||
} | ||
|
||
return $default; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLoad() | ||
{ | ||
//if load is not defined presume it's overloaded | ||
return $this->getSetting('load', 1); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handleRequest(Request $request) | ||
{ | ||
$response = new Response(); | ||
$response->setStatusCode($this->getSetting('response-status', 200)); | ||
$response->setContent(sprintf($this->getSetting('response-content-format', '%s'), $request->getUri())); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters