Beispiel #1
0
 /**
  */
 public function testToArray()
 {
     $column = $this->_table->getColumn('id');
     $columnArray = $column->toArray();
     $this->assertInternalType('array', $columnArray);
     $arrayFields = array('table_catalog', 'table_schema', 'table_name', 'column_name', 'ordinal_position', 'column_default', 'is_nullable', 'data_type', 'character_maximum_length', 'character_octet_length', 'numeric_precision', 'numeric_scale', 'character_set_name', 'collation_name', 'column_type', 'column_comment', 'is_unique');
     foreach ($arrayFields as $field) {
         $this->assertArrayHasKey($field, $columnArray);
     }
 }
Beispiel #2
0
 public function testToArray()
 {
     $idKey = new \Model\Cluster\Schema\Table\Index\Key('id', array($this->_table->getColumn('id')));
     $array = $idKey->toArray(false);
     $this->assertArrayNotHasKey('columns', $array);
     $this->assertArrayHasKey('type', $array);
     $this->assertEquals('Model\\Cluster\\Schema\\Table\\Index\\Key', $array['type']);
     $this->assertArrayHasKey('name', $array);
     $this->assertEquals('id', $array['name']);
     $array = $idKey->toArray();
     $this->assertArrayHasKey('columns', $array);
     $this->assertEquals('id', $array['columns'][0]['column_name']);
 }
Beispiel #3
0
 /**
  * @param                             $xml
  * @param \Model\Cluster\Schema\Table $table
  * @return mixed
  * @throws \Model\Exception\ErrorException
  */
 public static function fromXml($xml, Table $table)
 {
     if (is_array($xml)) {
         $data = $xml;
     } else {
         $xml = simplexml_load_string($xml);
         $data = json_decode(json_encode((array) $xml), 1);
     }
     $data = Column::prepareXmlArray($data);
     $columnArray = array_map('trim', explode(',', $data['@attributes']['columns']));
     $columns = array();
     foreach ($columnArray as $column) {
         $col = $table->getColumn($column);
         if (!$col) {
             throw new \Model\Exception\ErrorException('Column ' . $column . ' not found');
         }
         $columns[] = $col;
     }
     switch (strtolower($data['@attributes']['type'])) {
         case 'primary':
             $type = self::TYPE_PRIMARY;
             break;
         case 'unique':
             $type = self::TYPE_UNIQUE;
             break;
         case 'key':
             $type = self::TYPE_KEY;
             break;
     }
     return new $type($data['@attributes']['name'], $columns);
 }