diff options
Diffstat (limited to 'src/Fragments/KeyFragment.php')
-rw-r--r-- | src/Fragments/KeyFragment.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Fragments/KeyFragment.php b/src/Fragments/KeyFragment.php index d84c9f6..1964cd2 100644 --- a/src/Fragments/KeyFragment.php +++ b/src/Fragments/KeyFragment.php @@ -67,6 +67,16 @@ class KeyFragment extends Fragment */ public $options; + + public function __construct($name = null, array $columns = array(), + $type = null, $options = null + ) { + $this->name = $name; + $this->columns = $columns; + $this->type = $type; + $this->options = $options; + } + /** * @param Parser $parser The parser that serves as context. * @param TokensList $list The list of tokens that are being parsed. @@ -131,6 +141,21 @@ class KeyFragment extends Fragment --$list->idx; return $ret; + } + /** + * @param KeyFragment $fragment The fragment to be built. + * + * @return string + */ + public static function build($fragment) + { + $ret = $fragment->type . ' '; + if (!empty($fragment->name)) { + $ret .= Context::escape($fragment->name) . ' '; + } + $ret .= '(' . implode(', ', Context::escape($fragment->columns)) . ')'; + $ret .= OptionsFragment::build($fragment->options); + return trim($ret); } } |