Yoast\WP\Lib

Model::class_name_to_table_name()protected staticYoast 1.0

Convert a namespace to the standard PEAR underscore format.

Then convert a class name in CapWords to a table name in lowercase_with_underscores.

Finally strip doubled up underscores.

For example, CarTyre would be converted to car_tyre. And Project\Models\CarTyre would be project_models_car_tyre.

Метод класса: Model{}

Хуков нет.

Возвращает

Строку. The table name.

Использование

$result = Model::class_name_to_table_name( $class_name );
$class_name(строка) (обязательный)
The class name to get the table name for.

Код Model::class_name_to_table_name() Yoast 22.3

protected static function class_name_to_table_name( $class_name ) {
	$find         = [
		'/\\\\/',
		'/(?<=[a-z])([A-Z])/',
		'/__/',
	];
	$replacements = [
		'_',
		'_$1',
		'_',
	];

	$class_name = \ltrim( $class_name, '\\' );
	$class_name = \preg_replace( $find, $replacements, $class_name );

	return \strtolower( $class_name );
}