| 1 | <?php |
||
| 15 | class Describe |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | protected $columns = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var \Rougin\Describe\Driver\DriverInterface |
||
| 24 | */ |
||
| 25 | protected $driver; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param \Rougin\Describe\Driver\DriverInterface $driver |
||
| 29 | */ |
||
| 30 | 27 | public function __construct(DriverInterface $driver) |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Gets the primary key in the specified table. |
||
| 37 | * |
||
| 38 | * @param string $table |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | 9 | public function getPrimaryKey($table) |
|
| 42 | { |
||
| 43 | 9 | $result = ''; |
|
| 44 | |||
| 45 | 9 | if (empty($this->columns)) { |
|
| 46 | 9 | $this->columns = $this->driver->getTable($table); |
|
| 47 | } |
||
| 48 | |||
| 49 | foreach ($this->columns as $column) { |
||
| 50 | if ($column->isPrimaryKey()) { |
||
| 51 | $result = $column->get_field(); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | return $result; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns the result. |
||
| 60 | * |
||
| 61 | * @param string $table |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | 9 | public function getTable($table) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Returns the result. |
||
| 71 | * |
||
| 72 | * @param string $table |
||
| 73 | * @return array |
||
| 74 | */ |
||
| 75 | public function get_table($table) |
||
| 76 | { |
||
| 77 | return $this->driver->getTable($table); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Gets the primary key in the specified table. |
||
| 82 | * |
||
| 83 | * @param string $table |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | public function get_primary_key($table) |
||
| 87 | { |
||
| 88 | return $this->getPrimaryKey($table); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Shows the list of tables. |
||
| 93 | * |
||
| 94 | * @return array |
||
| 95 | */ |
||
| 96 | 9 | public function showTables() |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Shows the list of tables. |
||
| 103 | * |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | 3 | public function show_tables() |
|
| 110 | } |
||
| 111 |