From b95d1fcdca56cab3ffe1b55e171eb91257747e4a Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 6 Aug 2015 20:41:03 +0800 Subject: [PATCH] use get_object_vars to export all column properties Fixes: #116 --- src/LazyRecord/Schema/ColumnDeclare.php | 20 ++++++++------------ src/LazyRecord/Schema/DeclareSchema.php | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/LazyRecord/Schema/ColumnDeclare.php b/src/LazyRecord/Schema/ColumnDeclare.php index aa3af7409..4411d283a 100644 --- a/src/LazyRecord/Schema/ColumnDeclare.php +++ b/src/LazyRecord/Schema/ColumnDeclare.php @@ -202,27 +202,23 @@ public function validator() { $this->attributes['validator'] = $args[0]; } + + /** + * Export column attributes to an array + * + * @return array + */ public function export() { return array( 'name' => $this->name, - 'attributes' => array( - 'isa' => $this->isa, - 'type' => $this->type, - 'primary' => $this->primary, - ) + $this->attributes, + 'attributes' => array_merge(get_object_vars($this), $this->attributes), ); } public function toArray() { - $attrs = $this->attributes; - $attrs['name'] = $this->name; - $attrs['primary'] = $this->primary; - $attrs['unsigned'] = $this->unsigned; - $attrs['type'] = $this->type; - $attrs['notNull'] = $this->notNull; - return $attrs; + return array_merge(get_object_vars($this),$this->attributes); } public function dump() diff --git a/src/LazyRecord/Schema/DeclareSchema.php b/src/LazyRecord/Schema/DeclareSchema.php index aba39a025..ae208ffb0 100644 --- a/src/LazyRecord/Schema/DeclareSchema.php +++ b/src/LazyRecord/Schema/DeclareSchema.php @@ -226,7 +226,7 @@ public function findPrimaryKey() public function export() { $columnArray = array(); - foreach( $this->columns as $name => $column ) { + foreach ( $this->columns as $name => $column ) { // This idea is from: // http://search.cpan.org/~tsibley/Jifty-DBI-0.75/lib/Jifty/DBI/Schema.pm