| 

.NET C# Java Javascript Exception

1
Ich finde das Konzept von EBC cool. Und ich könnte mir vorstellen, dass das gerade für Services ideal ist. Lässt sich das auch mit PHP machen? Denn Delegaten gibt es ja wohl nicht unter PHP.
News:
04.02.2011
Sunny 31 1 2
2 Antworten
0
Geht nicht, gibt's nicht ;-) Schau dir z.B. mal folgendes Framework an: http://qphp.net/index.php
04.02.2011
Konstantin 3,7k 1 8
0
Delegaten gibt es nicht unter PHP. Aber du kannst sowas nachbauen.

class Delegate
{
public $object = null;
public $functionname = "";

public function __construct(&$object, $functionname)
{
$this->object = &$object;
$this->functionname = $functionname;
}

public function Invoke($value1, $value2 = null)
{
return call_user_func(array($this->object, $this->functionname), $value1, $value2);
}
}


Und wendest du dann so an:
class Ebc
{
public $SendDelegate = null;

public function Receive($value)
{
$this->Send($value);
}

protected function Send($value)
{
if (!is_null($this->SendDelegate))
return $this->SendDelegate->Invoke($value);
}
}

class FinalDestination
{
public function Receive($value)
{
echo $value;
}
}


und dann

$final = new FinalDestination();
$ebc = new Ebc();
$ebc->SendDelegate = new Delegate($final, "Receive");
$ebc->Receive("Hallo Welt");
04.02.2011
tboerner 509 8

Stelle deine Php-Frage jetzt!