This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/Rails/ActiveRecord/Base/Methods/ModelSchemaMethods.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2013-10-02 08:12:58 +02:00
<?php
namespace Rails\ActiveRecord\Base\Methods;
use Rails\ActiveRecord\ModelSchema;
/**
* These methods offer information about the table corresponding
* to this model, with which the ModelSchema object will be created.
*/
trait ModelSchemaMethods
{
static public function table()
{
$cn = get_called_class();
if (!isset(self::$tables[$cn])) {
$table = static::initTable();
$table->reloadSchema();
self::$tables[$cn] = $table;
}
return self::$tables[$cn];
}
static public function tableName()
{
$cn = str_replace('\\', '_', get_called_class());
$inf = \Rails::services()->get('inflector');
$tableName = $inf->underscore($inf->pluralize($cn));
return static::tableNamePrefix() . $tableName . static::tableNameSuffix();
}
static public function tableNamePrefix()
{
return '';
}
static public function tableNameSuffix()
{
return '';
}
/**
* @return ModelSchema
*/
static protected function initTable()
{
return new ModelSchema(static::tableName(), static::connection());
}
}