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

Utility methods for Erebot. More...

Static Public Member Functions

static getCallerObject ()
 
static getVStatic ($class, $name, $source=self::VSTATIC_CONST)
 
static humanSize ($size, $max=null, $system= 'si', $retstring= '%01.2f%s')
 
static isUTF8 ($text)
 
static parseHumanSize ($humanSize)
 
static stringifiable ($item)
 
static toUTF8 ($text, $from= 'iso-8859-1')
 

Public Attributes

const VSTATIC_CONST = 0x01
 Return the value of a constant.
 
const VSTATIC_VAR = 0x02
 Return the value of a static variable.
 

Detailed Description

Utility methods for Erebot.

Definition at line 27 of file Utils.php.

Member Function Documentation

static Erebot\Utils::getCallerObject ( )
static

Returns the object (if any) associated with the method that called the method which called Erebot::Utils::getCallerObject().

Consider the following example:

class Foo {
public function bar() {
}
}
class Bar {
public function baz() {
$foo = new Foo();
$foo->bar();
}
}
$bar = new Bar();
$bar->baz(); // Prints something like "object(Bar)#2 (0) {}".
Return values
objectThe caller object of the method which called Erebot::Utils::getCallerObject().

Definition at line 60 of file Utils.php.

static Erebot\Utils::getVStatic (   $class,
  $name,
  $source = self::VSTATIC_CONST 
)
static

Returns some static data from a class/object.

Parameters
string | object$classEither the name of a class or an instance of a class from which the static data will be retrieved.
string$nameThe name of the static data to return.
opaque$source(optional) The kind of static data to look for (either a constant or a static variable). Use Erebot::Utils::VSTATIC_CONST or Erebot::Utils::VSTATIC_VAR to select a specific source of data. The default is to look for a constant (same as if $source had been set to Erebot::Utils::VSTATIC_CONST).
Return values
mixedThe content of the static data whose name is $name.
Exceptions
Erebot::NotFoundExceptionNo data could be found which matches the given $name, using the specified $source of data.

Definition at line 218 of file Utils.php.

static Erebot\Utils::humanSize (   $size,
  $max = null,
  $system = 'si',
  $retstring = '%01.2f %s' 
)
static

Return human readable sizes.

Author
Aidan Lister aidan.nosp@m.@php.nosp@m..net
Version
1.3.0
See also
http://aidanlister.com/2004/04/human-readable-file-sizes/
Parameters
int$sizesize in bytes
string$maxmaximum unit
string$system'si' for SI, 'bi' for binary suffixes
string$retstringreturn string format
Return values
stringThe given size, in a human readable format.

Definition at line 280 of file Utils.php.

static Erebot\Utils::isUTF8 (   $text)
static

Can be used to determine if a string contains a sequence of valid UTF-8 encoded codepoints.

Parameters
string$textSome text to test for UTF-8 correctness.
Return values
trueThe $text contains a valid UTF-8 sequence.
falseThe $text is not a valid UTF-8 sequence.

Definition at line 80 of file Utils.php.

static Erebot\Utils::parseHumanSize (   $humanSize)
static

Does the opposite of Erebot::Utils::humanSize. That is, this method takes some size expressed in a human-friendly fashion and returns the actual size.

Parameters
string$humanSizeUser-friendly size.
Return values
mixedThe actual size as an integer or null if the size could not be determined.

Definition at line 319 of file Utils.php.

Referenced by Erebot\Core\handleSignal().

static Erebot\Utils::stringifiable (   $item)
static

Checks whether a variable can be safely cast to a string. This is the case when the variable is already a string or when it's an object with a __toString() method.

Parameters
mixed$itemVariable to test.
Return values
boolWhether the given $item can be safely cast to a string.

Definition at line 257 of file Utils.php.

Referenced by Erebot\IrcConnection\disconnect(), Erebot\Module\Base\sendCommand(), Erebot\Module\Base\sendMessage(), Erebot\Event\Match\Chan\setChan(), Erebot\Event\Match\TextAbstract\setPattern(), and Erebot\Event\Match\Source\setSource().

static Erebot\Utils::toUTF8 (   $text,
  $from = 'iso-8859-1' 
)
static

Transforms the given text into a UTF-8 sequence.

Parameters
string$textThe text to convert into a UTF-8 sequence.
null | string$from(optional) The encoding currently used by $text. A default of "iso-8859-1" is assumed.
Return values
stringThe original text, converted into UTF-8.
Exceptions
Erebot::NotImplementedExceptionRaised if no method could be found to convert the text. See also the notes for information on how to avoid this exception being raised.
Note
This method tries different technics to convert the text. If despite its best efforts, it still fails, you may consider installing one of PHP's extension for "Human Language and Character Encoding Support".

Definition at line 124 of file Utils.php.

Referenced by Erebot\LineIO\getLine().


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