Overview

Namespaces

  • Alchemy
    • core
      • query
      • schema
    • dialect
    • engine
    • orm
    • tests
    • util
      • promise
  • PHP

Classes

  • Column
  • Foreign
  • ForeignKey
  • Index
  • Table
  • TableElement
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Alchemy\core\schema;
 4: 
 5: 
 6: /**
 7:  * Class for representing an index in SQL
 8:  */
 9: class Index extends TableElement {
10: 
11:     protected $columns;
12: 
13: 
14:     /**
15:      * Get the index name
16:      *
17:      * @return string
18:      */
19:     public function getName() {
20:         if ($this->name) {
21:             return $this->name;
22:         }
23: 
24:         $this->resolve();
25: 
26:         $names = array();
27:         foreach ($this->columns as $column) {
28:             $names[] = $column->getName();
29:         }
30: 
31:         return implode('_', $names);
32:     }
33: 
34: 
35:     /**
36:      * List the columns used by this index
37:      *
38:      * @return array
39:      */
40:     public function listColumns() {
41:         $this->resolve();
42:         return $this->columns;
43:     }
44: 
45: 
46:     protected function resolve() {
47:         if ($this->columns) return;
48: 
49:         if (!isset($this->args[0]) || count($this->args[0]) == 0) {
50:             throw new \Exception("Index did not receive any columns.");
51:         }
52: 
53:         foreach ($this->args[0] as $column) {
54:             $this->columns[] = is_string($column)
55:                 ? Column::find($column, $this->table)
56:                 : $column;
57:         }
58:     }
59: }
60: 
API documentation generated by ApiGen 2.8.0