Erebot  latest
A modular IRC bot for PHP 5.3+
Erebot\Identity Class Reference

Represents the identity of an IRC user. More...

+ Inheritance diagram for Erebot\Identity:

Public Member Functions

 __construct ($user)
 
 __toString ()
 
 getHost ($c10n)
 
 getIdent ()
 
 getMask ($c10n)
 
 getNick ()
 
 match ($pattern,\Erebot\Interfaces\IrcCollator $collator)
 

Static Protected Member Functions

static canonicalizeHost ($host, $c10n, $uncompressed)
 
static patternize ($pattern, $matchDot)
 
static stripLeading (&$number, $key)
 

Protected Attributes

 $host
 Host part for this user identity, either a string or null.
 
 $ident
 Identity string for this user identity, either a string or null.
 
 $nick
 Nickname for this user identity, either a string or null.
 

Additional Inherited Members

- Public Attributes inherited from Erebot\Interfaces\Identity
const CANON_IPV4 = 4
 Use an IPv6 mapped IPv4 representation (eg. "::ffff:127.0.0.1").
 
const CANON_IPV6 = 6
 Use a pure IPv6 representation (eg. "::ffff:7f00:1").
 

Detailed Description

Represents the identity of an IRC user.

Definition at line 27 of file Identity.php.

Constructor & Destructor Documentation

Erebot\Identity::__construct (   $user)

Creates a new object holding some user's identity.

Parameters
string$userA string, representing some user. This can be either a mask, such as "foo!ident@host" or just a nickname, such as "foo".
Exceptions
Erebot::InvalidValueExceptionThe given $user does not represent a valid identity.

Definition at line 49 of file Identity.php.

Member Function Documentation

Erebot\Identity::__toString ( )

This method works like Erebot::Interfaces::Identity::getNick(), except that if no information is available on the user's nickname, it should return a very distinctive value. Eg. an appropriate return value in such a case could be '?'.

Return values
stringThis user's nickname or a distinctive value if it is not available.

Implements Erebot\Interfaces\Identity.

Definition at line 307 of file Identity.php.

static Erebot\Identity::canonicalizeHost (   $host,
  $c10n,
  $uncompressed 
)
staticprotected

Canonicalizes a host.

Despite its name, this method may be applied to either a hostname or an IP address (v4 or v6).

Parameters
string$hostHostname or IP address to canonicalize.
opaque$c10nThe type of canonicalization to apply. This is either Erebot::Interfaces::Identity::CANON_IPV4 or Erebot::Interfaces::Identity::CANON_IPV6 depending on whether IPv6-mapped-IPv4 addresses should be rendered in dotted form or in the regular IPv6 form, respectively.
bool$uncompressedWhether to compress IP addresses or not. In compressed form, leading zeros in a colon group are omitted and a series of groups with all-zeros is represented with just "::".
Return values
stringThe original hostname or IP address in canonicalized (and optionally compressed) form.
Note
The only transformation that is applied to hostnames as part of this canonicalization method is one that lowercases them.
See also
See the various RFCs related to IP addresses for an exact description of the transformations that apply when compressing an IPv6 address.

Definition at line 165 of file Identity.php.

Erebot\Identity::getHost (   $c10n)

Returns the host of the user represented by this identity.

Parameters
opaque$c10nEither Erebot::Interfaces::Identity::CANON_IPV4 or Erebot::Interfaces::Identity::CANON_IPV6, indicating the type of IP canonicalization to use.
Return values
stringThis user's hostname or null if unavailable.

Implements Erebot\Interfaces\Identity.

Definition at line 289 of file Identity.php.

Erebot\Identity::getIdent ( )

Returns the identity string of the user represented by this identity.

Return values
mixedThis user's identity string or NULL if unavailable.
Note
The name of this method is somewhat misleading, as it returns the "identity" as defined by the user in his/her client. This is not the same as the "identity" represented here (which contains additional information). To try to disambiguate, the term "identity string" has been used when referring to the user-defined identity.

Implements Erebot\Interfaces\Identity.

Definition at line 98 of file Identity.php.

Erebot\Identity::getMask (   $c10n)

Returns a mask which can later be used to match against this user.

Parameters
opaque$c10nEither Erebot::Interfaces::Identity::CANON_IPV4 or Erebot::Interfaces::Identity::CANON_IPV6, indicating the type of IP canonicalization to use.
Return values
stringA mask matching against this user.
Note
Fields for which no value is available should be replaced with '*'. This can result in very generic masks (eg. "foo!*@*") if not enough information is known.

Implements Erebot\Interfaces\Identity.

Definition at line 300 of file Identity.php.

Erebot\Identity::getNick ( )

Returns the nickname of the user represented by this identity.

Return values
mixedThis user's nickname or NULL if unavailable.

Implements Erebot\Interfaces\Identity.

Definition at line 93 of file Identity.php.

Erebot\Identity::match (   $pattern,
\Erebot\Interfaces\IrcCollator  $collator 
)

Indicates whether this identity matches a given pattern.

Parameters
string$patternThe pattern this identity should be tested against. The '?' and '*' wildcard characters are supported.
Erebot::Interfaces::IrcCollator$collatorCollator object to use to compare IRC nicknames.
Return values
booltrue if this identity matches the given pattern, false otherwise.

Definition at line 326 of file Identity.php.

static Erebot\Identity::patternize (   $pattern,
  $matchDot 
)
staticprotected

Turn a basic pattern (optionally) containing wirldcards into a regular expression pattern, intended to match hostnames or IP addresses.

Parameters
string$patternBasic pattern, possibly containing wildcard characters ('*' and '?').
bool$matchDotWhether the '?' and '*' wildcard characters should also match dots '.' (true) or not (false).
Return values
stringA regular expression pattern that matches the criteria expressed in the original pattern.

Definition at line 457 of file Identity.php.

static Erebot\Identity::stripLeading ( $number,
  $key 
)
staticprotected

Strips leading '0' in front of a numeric string.

Parameters
string$numberNumeric string whose leading '0' should be stripped. Passed by reference and modified in-place.
opaque$keyUnused.
Returns
Nothing ($number is modified in-place).
Note
This method is meant to be used with the array_walk() PHP function.

Definition at line 122 of file Identity.php.


The documentation for this class was generated from the following file: