diff --git a/examples/using-extension-methods.php b/examples/using-extension-methods.php deleted file mode 100644 index 6adffdb..0000000 --- a/examples/using-extension-methods.php +++ /dev/null @@ -1,34 +0,0 @@ - - - -

Using Extension Methods | dibi

- - 'sqlite3', - 'database' => 'data/sample.s3db', -]); - - -// using the "prototype" to add custom method to class Dibi\Result -Dibi\Result::extensionMethod('fetchShuffle', function (Dibi\Result $obj) { - $all = $obj->fetchAll(); - shuffle($all); - return $all; -}); - - -// fetch complete result set shuffled -$res = $dibi->query('SELECT * FROM [customers]'); -$all = $res->fetchShuffle(); -Tracy\Dumper::dump($all); diff --git a/src/Dibi/Strict.php b/src/Dibi/Strict.php index 054431b..781e6f1 100644 --- a/src/Dibi/Strict.php +++ b/src/Dibi/Strict.php @@ -29,7 +29,9 @@ trait Strict */ public function __call($name, $args) { - if ($cb = self::extensionMethod(get_class($this) . '::' . $name)) { // back compatiblity + $class = get_class($this); + if ($cb = self::extensionMethod($class . '::' . $name)) { // back compatiblity + trigger_error("Extension methods such as $class::$name() are deprecated", E_USER_DEPRECATED); array_unshift($args, $this); return $cb(...$args); } @@ -104,6 +106,7 @@ trait Strict /** * @return mixed + * @deprecated */ public static function extensionMethod(string $name, callable $callback = null) { @@ -129,6 +132,7 @@ trait Strict return $cache = false; } else { // setter + trigger_error("Extension methods such as $class::$name() are deprecated", E_USER_DEPRECATED); $list[$class] = $callback; $list[''] = null; } diff --git a/tests/dibi/Strict.phpt b/tests/dibi/Strict.phpt index d586c1f..95f9bf0 100644 --- a/tests/dibi/Strict.phpt +++ b/tests/dibi/Strict.phpt @@ -148,12 +148,3 @@ Assert::exception(function () { }, LogicException::class, 'Attempt to unset undeclared property TestClass::$undeclared.'); Assert::false(isset($obj->undeclared)); - - -// extension method -TestClass::extensionMethod('join', $func = function (TestClass $that, $separator) { - return $that->foo . $separator . $that->bar; -}); - -$obj = new TestClass; -Assert::same('456*123', $obj->join('*'));