<?php
/**
- * Phergie
+ * Phergie
*
* PHP version 5
*
* It is also available through the world-wide-web at this URL:
* http://phergie.org/license
*
- * @category Phergie
+ * @category Phergie
* @package Phergie
* @author Phergie Development Team <team@phergie.org>
* @copyright 2008-2010 Phergie Development Team (http://phergie.org)
/**
* Data structure for connection metadata.
*
- * @category Phergie
+ * @category Phergie
* @package Phergie
* @author Phergie Development Team <team@phergie.org>
* @license http://phergie.org/license New BSD License
protected $host;
/**
- * Port on which the client will connect, defaults to the standard IRC
+ * Port on which the client will connect, defaults to the standard IRC
* port
*
* @var int
protected $port;
/**
- * Transport for the connection, defaults to tcp but can be set to ssl
+ * Transport for the connection, defaults to tcp but can be set to ssl
* or variations thereof to connect over SSL
*
- * @var string
+ * @var string
*/
protected $transport;
+ /**
+ * Encoding method for the connection, defaults to ISO-8859-1 but can
+ * be set to UTF8 if necessary
+ *
+ * @var strng
+ */
+ protected $encoding;
+
/**
* Nick that the client will use
*
/**
* Constructor to initialize instance properties.
*
- * @param array $options Optional associative array of property values
+ * @param array $options Optional associative array of property values
* to initialize
*
* @return void
public function __construct(array $options = array())
{
$this->transport = 'tcp';
+ $this->encoding = 'ISO-8859-1';
+ // @note this may need changed to something different, for broader support.
+ // @note also may need to make use of http://us.php.net/manual/en/function.stream-encoding.php
$this->setOptions($options);
}
);
}
}
-
+
/**
* Returns a hostmask that uniquely identifies the connection.
*
);
}
- return $this->hostmask;
+ return $this->hostmask;
}
/**
*
* @param string $host Hostname
*
- * @return Phergie_Connection Provides a fluent interface
+ * @return Phergie_Connection Provides a fluent interface
*/
public function setHost($host)
{
return $this;
}
-
+
/**
- * Returns the host to which the client will connect if it is set or
+ * Returns the host to which the client will connect if it is set or
* emits an error if it is not set.
*
* @return string
*
* @param int $port Port
*
- * @return Phergie_Connection Provides a fluent interface
+ * @return Phergie_Connection Provides a fluent interface
*/
public function setPort($port)
{
}
/**
- * Sets the transport for the connection to use.
+ * Sets the transport for the connection to use.
*
- * @param string $transport Transport (ex: tcp, ssl, etc.)
+ * @param string $transport Transport (ex: tcp, ssl, etc.)
*
* @return Phergie_Connection Provides a fluent interface
*/
}
/**
- * Returns the transport in use by the connection.
+ * Returns the transport in use by the connection.
*
- * @return string Transport (ex: tcp, ssl, etc.)
+ * @return string Transport (ex: tcp, ssl, etc.)
*/
public function getTransport()
{
return $this->transport;
}
+ /**
+ * Sets the encoding for the connection to use.
+ *
+ * @param string $encoding Encoding to use (ex: ASCII, ISO-8859-1, UTF8, etc.)
+ *
+ * @return Phergie_Connection Provides a fluent interface
+ */
+ public function setEncoding($encoding)
+ {
+ $this->encoding = (string) $encoding;
+
+ if (!in_array($this->encoding, mb_list_encodings())) {
+ throw new Phergie_Connection_Exception(
+ 'Encoding ' . $this->encoding . ' is not supported',
+ Phergie_Connection_Exception::ENCODING_NOT_SUPPORTED
+ );
+ }
+
+ return $this;
+ }
+
+ /**
+ * Returns the encoding in use by the connection.
+ *
+ * @return string Encoding (ex: ASCII, ISO-8859-1, UTF8, etc.)
+ */
+ public function getEncoding()
+ {
+ return $this->encoding;
+ }
+
/**
* Sets the nick that the client will use.
*
* @param string $nick Nickname
*
- * @return Phergie_Connection Provides a fluent interface
+ * @return Phergie_Connection Provides a fluent interface
*/
public function setNick($nick)
{
*
* @param string $username Username
*
- * @return Phergie_Connection Provides a fluent interface
+ * @return Phergie_Connection Provides a fluent interface
*/
public function setUsername($username)
{
*
* @param string $realname Real name
*
- * @return Phergie_Connection Provides a fluent interface
+ * @return Phergie_Connection Provides a fluent interface
*/
public function setRealname($realname)
{
*
* @param string $password Password
*
- * @return Phergie_Connection Provides a fluent interface
+ * @return Phergie_Connection Provides a fluent interface
*/
public function setPassword($password)
{
/**
* Sets multiple connection settings using an array.
*
- * @param array $options Associative array of setting names mapped to
+ * @param array $options Associative array of setting names mapped to
* corresponding values
*
- * @return Phergie_Connection Provides a fluent interface
+ * @return Phergie_Connection Provides a fluent interface
*/
public function setOptions(array $options)
{