This commit is contained in:
Jan Philipp Timme
2010-11-21 22:48:11 +00:00
parent 01018862f7
commit 952af43b97
23 changed files with 3314 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
$clientManager = new Client_ClientManager();
$clientManager->registerProtocol("irc", "Client_IrcClient");
$clientManager->registerProtocol("jpt", "Client_BotClient");
$freenode = $clientManager->createTcpConnection("freenode", "irc");
$clientManager->attachConfig(array(
"nick" => "Testinstanz",
"userident" => "uzuguck",
"channels" => array("#mstasty")
), $freenode);
$freenode->connect("irc.freenode.net", 6667);
$freenode = $clientManager->createTcpConnection("freenode", "irc");
$clientManager->attachConfig(array(
"nick" => "Testinstanz2",
"userident" => "uzuguck",
"channels" => array("#mstasty")
), $freenode);
$freenode->connect("irc.freenode.net", 6667);
/*$config_eloxoph = array(
"nick" => "Frischmilch",
"userident" => "olefolol",
"channels" => array("#eloxoph")
);
$eloxoph = $clientManager->createTcpConnection("eloxoph", "irc");
$clientManager->attachConfig($config_eloxoph, $eloxoph);
$eloxoph->connect("irc.eloxoph.com", 6667);*/
$srv = $clientManager->createTcpConnection("srv", "jpt");
$srv->bind("localhost", 7777);
$srv->listen();
while($clientManager->countConnections() > 0) {
$clientManager->work();
}
?>
+39
View File
@@ -0,0 +1,39 @@
<?php
$pool = new Connection_ConnectionPool();
$srv = $pool->createTcpConnection("raw_input");
$srv->bind("localhost", 7777);
$srv->listen();
$sock = $pool->createTcpConnection("freenode");
$sock->bind("192.168.0.101", 5456);
$sock->connect("irc.freenode.net", 6667);
$got_001 = FALSE;
$lines = 0;
$i = 0;
$authed = FALSE;
$joined = FALSE;
while(TRUE) {
$select = $pool->select();
while($read = $sock->read()) {
$pool->writeToGroup("raw_input", $read);
if(preg_match("/001/", $read)) $got_001 = TRUE;
$lines++;
}
if(!$authed && $lines > 1) {
$sock->write("USER as as as :Asdfg\r\n");
$sock->write("NICK :phptbt42\r\n");
$authed = TRUE;
}
if($got_001 && !$joined) {
$joined = TRUE;
$sock->write("JOIN #mstasty\r\n");
//$sock->write("PRIVMSG #mstasty :SocketTest abgeschlossen!\r\n");
}
echo $i++ . " ---\n";
}
?>
+61
View File
@@ -0,0 +1,61 @@
<?php
class TestException extends Exception{
function __construct($message) {
$this->message = $message;
}
}
class TestFailException extends Exception {
function __construct($msg) {
$this->message = "Error: ".$msg;
}
}
class Service_ExceptionTest {
function __construct() {
}
public function TestTheFail() {
$this->failAtThis();
}
public function CatchAndThrow() {
try {
$this->failAtThis();
}
catch (Exception $e) {
throw new TestFailException("moep:D");
}
}
public function internalCatch() {
try {
$this->failAtThis();
}
catch (Exception $e) {
var_dump($e);
}
}
function failAtThis() {
throw new TestException("I had to do this. Please forgive me :/");
}
}
try {
$ExceptionTest = new Service_ExceptionTest;
$ExceptionTest->CatchAndThrow();
} catch (Exception $e){
var_dump($e);
}
?>
+79
View File
@@ -0,0 +1,79 @@
<?php
/**
* Testclass
* @author jpt
*/
class Foo {
/**
* @var array Instances of Bar.
*/
protected $pool;
function __construct() {
$this->pool = array();
}
/**
* Adds an Instance of Bar to the Pool.
* @param Bar $bar
* @return void
*/
public function addBar($bar) {
array_push($this->pool, $bar);
}
/**
* Returns the internal instance of Bar for the specific ID.
* @param int $id
* @return Bar
*/
public function getBar($id) {
return $this->pool[$id];
}
/**
* Outputs the current state of the bars in the pool.
* @return void
*/
public function getTestResult() {
foreach($this->pool AS $id=>$bar) {
echo "ID: " . $id . ", Test: " . $bar->test . "\n";
}
}
}
/**
* Testclass #2
* @author jpt
*/
class Bar {
/**
* @var string Teststring.
*/
public $test;
/**
* Default constructor. Initializes test variable.
* @return void
*/
function __construct() {
$this->test = "failed";
}
}
$f = new Foo();
$f->addBar(new Bar());
$f->addBar(new Bar());
$f->addBar(new Bar());
$f->addBar(new Bar());
$f->getBar(1)->test = "success";
$f->getTestResult();
?>
+67
View File
@@ -0,0 +1,67 @@
<?php
/**
* Testclass in order to test phpdoc-stuff with the php reflection api
* Shall help in order to find out how this stuff works.
* @author jpt
*/
class TestClassForTestsWithReflection {
/**
* @var string
*/
public $public;
/**
* @var string
*/
protected $protected;
/**
* @var string
*/
private $privateStatic;
/**
* Testfunction
* @param Klasse $objekt
* @return void
*/
public function blablubblol(Klasse $objekt) {
$objekt = new ReflectionObject($objekt);
print $objekt->getName();
}
/**
* Tests the getDocComment() method
*
* @param array $ray
* @param int $zero
* @return string
* @specialtag
*/
protected function testfunctionWithCamelCase(array $ray, $zero = 0) {
return "bla";
}
}
//TestClassForTestsWithReflection ends here.
//create ReflectionClass
$class = new ReflectionClass("TestClassForTestsWithReflection");
//print class name
echo "Information about: " . $class->name . "\n";
//getDocs for all methods
foreach($class->getMethods() as $key=>$method) {
var_dump($method->name, $method->getDocComment());
echo "\n";
}
//getDocs for all properties
foreach($class->getProperties() as $key=>$property) {
var_dump($property->name, $property->getDocComment());
echo "\n";
}
?>
+2
View File
@@ -0,0 +1,2 @@
All the code in this directory is for testing only.
Just to make that clear ;-)