Example #1
0
--TEST--
Environement parent
--FILE--
<?php 
use php\lang\Environment;
class X
{
    static $foo = 'bar';
}
function test()
{
    return 'foo';
}
$env = new Environment(Environment::current());
$env->execute(function () {
    ob_implicit_flush(true);
    var_dump(test());
    var_dump(X::$foo);
});
$env = new Environment(null);
$env->execute(function () {
    ob_implicit_flush(true);
    echo "class 'X' exists - " . (class_exists('X') ? 'true' : 'false'), "\n";
    echo "function 'test' exists - " . (function_exists('test') ? 'true' : 'false'), "\n";
});
?>
--EXPECT--
string(3) "foo"
string(3) "bar"
class 'X' exists - false
function 'test' exists - false
Example #2
0
--TEST--
Shared basic test
--FILE--
<?php 
use php\lang\Environment;
use php\util\Shared;
Shared::resetAll();
ob_implicit_flush(1);
$value = Shared::value('foobar');
var_dump($value->isEmpty());
var_dump($value->get());
$env1 = new Environment();
$env2 = new Environment();
$value->set('foobar');
$env1->execute(function () {
    var_dump(Shared::value('foobar')->get());
});
$env2->execute(function () {
    var_dump(Shared::value('foobar')->get());
});
?>
--EXPECT--
bool(true)
NULL
string(6) "foobar"
string(6) "foobar"
Example #3
0
--TEST--
Environement defineConstant
--FILE--
<?php 
use php\lang\Environment;
class X
{
    static $foo = FOOBAR;
}
define('FOOBAR', 'fail');
$env = new Environment();
$env->execute(function () {
    var_dump(FOOBAR);
});
$env->defineConstant('FOOBAR', 'success');
$env->importClass('X');
$env->execute(function () {
    var_dump(FOOBAR);
    var_dump(X::$foo);
});
?>
--EXPECTF--
string(6) "FOOBAR"
string(7) "success"
string(7) "success"
Notice: Use of undefined constant FOOBAR - assumed 'FOOBAR' in %s on line %d at pos %d
Example #4
0
--TEST--
Environement test
--FILE--
<?php 
use php\lang\Environment;
$env = new Environment();
var_dump($env->execute(function () {
    var_dump("success1");
    return 'success2';
}));
?>
--EXPECT--
string(8) "success1"
string(8) "success2"
Example #5
0
--TEST--
Shared creator test
--FILE--
<?php 
use php\lang\Environment;
use php\util\Shared;
ob_implicit_flush(1);
Shared::resetAll();
$env1 = new Environment();
$env2 = new Environment();
function foobar($value)
{
    return Shared::value('foobar', function () use($value) {
        return $value;
    });
}
$env1->importFunction('foobar');
$env2->importFunction('foobar');
$env1->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('x')->get());
});
$env2->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('y')->get());
});
var_dump(Shared::reset('foobar'));
$env2->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('y')->get());
});
Example #6
0
--TEST--
Environement import
--FILE--
<?php 
ob_implicit_flush(true);
use php\lang\Environment;
class Foo
{
}
function bar()
{
}
$env = new Environment();
$env->execute(function () {
    ob_implicit_flush(true);
    var_dump('class Foo exits: ', class_exists('Foo'));
    var_dump('function bar exits: ', function_exists('bar'));
});
echo "\nImport ...", "\n";
$env->importClass('Foo');
$env->importFunction('bar');
$env->execute(function () {
    ob_implicit_flush(true);
    var_dump('class Foo exits: ', class_exists('Foo'));
    var_dump('function bar exits: ', function_exists('bar'));
});
?>
--EXPECT--
string(17) "class Foo exits: "
bool(false)
string(20) "function bar exits: "
Example #7
0
$roommanager->getRoom(17);
$roommanager->getRoom(18);
$events = array();
$autoloader->loadEvents();
Console::WriteLine("Loaded " . count($events) . " events !");
$furnidataparser->setCache();
Console::WriteLine("Loaded " . count($furnidataparser->floorItems) . " floor items and " . count($furnidataparser->wallItems) . " wall items !");
$server = new ServerSocket();
$server->bind($config->get("game.tcp.bindip"), $config->get("game.tcp.port"));
$service = ThreadPool::createFixed($config->get("game.tcp.conlimit"));
$index = new IndexManager();
if ($config->get("api.webserver.enabled")) {
    $webserverapi->start($config->get("api.webserver.port"));
}
Console::WriteLine("Server -> READY! (" . $config->get("game.tcp.bindip") . ":" . $config->get("game.tcp.port") . ")");
$environment = new Environment();
foreach ($autoloader->getClassArray() as $class) {
    $environment->importClass($class);
}
foreach ($autoloader->getEventsArray() as $event) {
    $environment->importClass($event);
}
while (true) {
    $socket = $server->accept();
    $user = new User($socket, $socket->getAddress(), $socket->getPort());
    $index->socket[$user->socketid] =& $user;
    $util = new ClassContainer();
    $util->index =& $index;
    $util->HeaderManager =& $headermanager;
    $util->RSA =& $rsa;
    $util->Database =& $database;
Example #8
0
--TEST--
Environement current
--FILE--
<?php 
use php\lang\Environment;
$global = 'foobar';
$env = Environment::current();
$env->execute(function () {
    ob_implicit_flush(true);
    global $global;
    var_dump($global);
});
$env = new Environment();
$env->execute(function () {
    ob_implicit_flush(true);
    global $global;
    var_dump($global);
});
?>
--EXPECT--
string(6) "foobar"
NULL
Example #9
0
--TEST--
Environement sendMessage
--FILE--
<?php 
use php\lang\Environment;
$env = new Environment();
try {
    $env->sendMessage('one', 'two', 'three');
} catch (Exception $e) {
    var_dump($e->getMessage());
}
$env->onMessage(function ($arg1, $arg2, $arg3) {
    ob_implicit_flush(true);
    var_dump($arg1, $arg2, $arg3);
});
$env->sendMessage('one', 'two', 'three');
?>
--EXPECTF--
string(3) "one"
string(3) "two"
string(5) "three"
string(63) "Environment cannot receive messages, onMessage callback is NULL"