Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from TomzxForks/features/connection-fluent-inte…
Browse files Browse the repository at this point in the history
…rface

Add fluent interface to the Connection class.
  • Loading branch information
elazar committed May 5, 2015
2 parents 97a2bde + c36d6e8 commit a17ff8f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ The recommended method of installation is [through composer](http://getcomposer.
```php
$connection = new \Phergie\Irc\Connection();

$connection->setServerHostname('hostname');
$connection->setServerPort(6668);
$connection->setPassword('password');
$connection->setNickname('nickname');
$connection->setUsername('username');
$connection->setHostname('hostname');
$connection->setServername('servername');
$connection->setRealname('realname');
$connection->setOption('option', 'value');
$connection
->setServerHostname('hostname')
->setServerPort(6668)
->setPassword('password')
->setNickname('nickname')
->setUsername('username')
->setHostname('hostname')
->setServername('servername')
->setRealname('realname')
->setOption('option', 'value');

echo $connection->getServerHostname();
echo $connection->getServerPort();
Expand Down
27 changes: 27 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ public function __construct(array $config = array())
* Implements ConnectionInterface::setServerHostname().
*
* @param string $hostname
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setServerHostname()
*/
public function setServerHostname($hostname)
{
$this->serverHostname = $hostname;

return $this;
}

/**
Expand All @@ -127,11 +130,14 @@ public function getServerHostname()
* Implements ConnectionInterface::setServerPort().
*
* @param int $port
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setServerPort()
*/
public function setServerPort($port)
{
$this->serverPort = $port;

return $this;
}

/**
Expand All @@ -149,11 +155,14 @@ public function getServerPort()
* Implements ConnectionInterface::setPassword().
*
* @param string $password
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setPassword()
*/
public function setPassword($password)
{
$this->password = $password;

return $this;
}

/**
Expand All @@ -171,11 +180,14 @@ public function getPassword()
* Implements ConnectionInterface::setNickname().
*
* @param string $nickname
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setNickname()
*/
public function setNickname($nickname)
{
$this->nickname = $nickname;

return $this;
}

/**
Expand All @@ -193,11 +205,14 @@ public function getNickname()
* Implements ConnectionInterface::setUsername().
*
* @param string $username
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setUsername()
*/
public function setUsername($username)
{
$this->username = $username;

return $this;
}

/**
Expand All @@ -215,11 +230,14 @@ public function getUsername()
* Implements ConnectionInterface::setHostname().
*
* @param string $hostname
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setHostname()
*/
public function setHostname($hostname)
{
$this->hostname = $hostname;

return $this;
}

/**
Expand All @@ -237,11 +255,14 @@ public function getHostname()
* Implements ConnectionInterface::setServername().
*
* @param string $servername
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setServername()
*/
public function setServername($servername)
{
$this->servername = $servername;

return $this;
}

/**
Expand All @@ -259,11 +280,14 @@ public function getServername()
* Implements ConnectionInterface::setRealname().
*
* @param string $realname
* @return $this
* @see \Phergie\Irc\ConnectionInterface::setRealname()
*/
public function setRealname($realname)
{
$this->realname = $realname;

return $this;
}

/**
Expand All @@ -282,10 +306,13 @@ public function getRealname()
*
* @param string $name Option name
* @param mixed $value Option value
* @return $this
*/
public function setOption($name, $value)
{
$this->options[$name] = $value;

return $this;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,17 @@ public function testGetOption()
$this->assertNull($this->connection->getOption('foo'));
$this->assertNull($this->connection->getOption('bar'));
}

public function testFluentInterface()
{
$this->assertSame($this->connection, $this->connection->setServerHostname('hostname'));
$this->assertSame($this->connection, $this->connection->setServerPort(6668));
$this->assertSame($this->connection, $this->connection->setPassword('password'));
$this->assertSame($this->connection, $this->connection->setNickname('nickname'));
$this->assertSame($this->connection, $this->connection->setUsername('username'));
$this->assertSame($this->connection, $this->connection->setHostname('hostname'));
$this->assertSame($this->connection, $this->connection->setServername('servername'));
$this->assertSame($this->connection, $this->connection->setRealname('realname'));
$this->assertSame($this->connection, $this->connection->setOption('foo', 'bar'));
}
}

0 comments on commit a17ff8f

Please sign in to comment.