2016-10-14 03:30:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Core\Tests\ObjectTest;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Object;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
|
|
|
|
class Extending extends Object implements TestOnly
|
|
|
|
{
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
private static $extensions = array(
|
|
|
|
Extending_Extension::class,
|
|
|
|
);
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function getResults(&$first, &$second, &$third)
|
|
|
|
{
|
|
|
|
// Before extending should be invoked second
|
|
|
|
$this->beforeExtending(
|
|
|
|
'updateResult',
|
|
|
|
function (&$first, &$second, &$third) {
|
|
|
|
if ($first === 1 && $second === 2 && $third === 3) {
|
|
|
|
$first = 11;
|
|
|
|
$second = 12;
|
|
|
|
$third = 13;
|
|
|
|
return 'before';
|
|
|
|
}
|
|
|
|
return 'before-error';
|
|
|
|
}
|
|
|
|
);
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
// After extending should be invoked fourth
|
|
|
|
$this->afterExtending(
|
|
|
|
'updateResult',
|
|
|
|
function (&$first, &$second, &$third) {
|
|
|
|
if ($first === 21 && $second === 22 && $third = 23) {
|
|
|
|
$first = 31;
|
|
|
|
$second = 32;
|
|
|
|
$third = 33;
|
|
|
|
return 'after';
|
|
|
|
}
|
|
|
|
return 'after-error';
|
|
|
|
}
|
|
|
|
);
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
// Function body invoked first
|
|
|
|
$result = $this->extend('updateResult', $first, $second, $third);
|
|
|
|
return array($result);
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
}
|