Kod klas jest jeszcze w fazie beta, więc zamieszczam przykład ich użycia.
Co myślicie o takim rozszerzaniu metod i pól klas?
<?php
class fooBar
{
public function test( $text )
{
}
}
class fooBar1Extention extends oeExtention
{
public function test( oeExtendable $extendable, $text )
{
return oeResponse::give(OE_ORIGINAL)->with('Noting to lose.');
// Returns original method with first parameter:
// 'Noting to lose.'
}
}
class fooBar2Extention extends oeExtention
{
public function test( oeExtendable $extendable, $text )
{
{
return oeResponse::give(OE_SKIP)->with(null);
// Returns null, and not skipping call original method.
// You can use that too:
// return null;
// for not creating oeResponse object and faster compilation.
}
return oeResponse::give(OE_ORIGINAL);
// Returns result of original method. You can use that too:
// return false;
// as alternative method.
}
}
class fooBar3Extention extends oeExtention
{
public function test( oeExtendable $extendable, $text )
{
{
return oeResponse::give(OE_ORIGINAL);
// Returns result of original method.
}
return oeResponse::give(OE_ORIGINAL)->with('I dont work with non numeric values.');
// Returns original method with first parameter:
// 'I dont work with numeric values.'
}
}
$foo = oeExtendable::instance( new fooBar() );
$foo->test(13);
$foo->test('Hello World!');
$foo->__extend( new fooBar1Extention() );
$foo->test(13);
$foo->test('Hello World!');
$foo->__extend( new fooBar2Extention() );
$foo->test(13);
$foo->test('Hello World!');
$foo->__extend( new fooBar3Extention() );
$foo->test(13);
$foo->test('Hello World!');
?>
Co daje w rezultacie wyświetlenie:
Cytat
13
Hello World!
___FOOBAR1___
Noting to lose.
Noting to lose.
___FOOBAR2___
[13]Hello World!
___FOOBAR3___
13
I dont work with numeric values.
Ten post edytował tuner 3.06.2007, 19:56:04