Page MenuHomeDevCentral

WithLegacyMethods.php
No OneTemporary

WithLegacyMethods.php

<?php
namespace Keruald\Database;
use BadMethodCallException;
trait WithLegacyMethods {
private static function getNewMethodName (string $legacyName) : string {
return match ($legacyName) {
'sql_nextid' => 'nextId',
'sql_query_express' => 'queryScalar',
'sql_fetchrow' => 'fetchRow',
'sql_numrows' => 'numRows',
default => substr($legacyName, 4),
};
}
protected function callByLegacyMethodName (string $name, array $arguments) {
$newMethodName = self::getNewMethodName($name);
if (!method_exists($this, $newMethodName)) {
$className = get_class($this);
throw new BadMethodCallException(
"Legacy method doesn't exist: $className::$name"
);
}
trigger_error(<<<EOF
\$db->$name calls shall be replaced by \$db->$newMethodName calls.
EOF
, E_USER_DEPRECATED);
return call_user_func_array(
[$this, $newMethodName], $arguments
);
}
}

File Metadata

Mime Type
text/x-php
Expires
Thu, Dec 26, 17:08 (21 h, 41 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2314253
Default Alt Text
WithLegacyMethods.php (1 KB)

Event Timeline