summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/Table.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/Table.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/Table.php130
1 files changed, 130 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/Table.php b/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/Table.php
new file mode 100644
index 00000000..5565bda9
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/Table.php
@@ -0,0 +1,130 @@
+<?php
+
+namespace SMW\SQLStore\TableBuilder;
+
+use RuntimeException;
+
+/**
+ * @private
+ *
+ * @license GNU GPL v2+
+ * @since 2.5
+ *
+ * @author mwjames
+ */
+class Table {
+
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @var array
+ */
+ private $attributes = [];
+
+ /**
+ * @since 2.5
+ *
+ * @param string $name
+ */
+ public function __construct( $name ) {
+ $this->name = $name;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param string
+ */
+ public function getName() {
+ return $this->name;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param string
+ */
+ public function getHash() {
+ return json_encode( $this->attributes );
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param array
+ */
+ public function getAttributes() {
+ return $this->attributes;
+ }
+
+ /**
+ * @since 3.0
+ *
+ * @param string $key
+ *
+ * @param mixed
+ */
+ public function get( $key ) {
+
+ if ( !isset( $this->attributes[$key] ) ) {
+ throw new RuntimeException( "$key is a reserved option key." );
+ }
+
+ return $this->attributes[$key];
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param string $fieldName
+ * @param string|array $fieldType
+ */
+ public function addColumn( $fieldName, $fieldType ) {
+ $this->attributes['fields'][$fieldName] = $fieldType;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param string|array $index
+ * @param string|null $key
+ */
+ public function addIndex( $index, $key = null ) {
+ if ( $key !== null ) {
+ $this->attributes['indices'][$key] = $index;
+ } else {
+ $this->attributes['indices'][] = $index;
+ }
+ }
+
+ /**
+ * @since 3.0
+ *
+ * @param string $fieldName
+ * @param string|int $default
+ */
+ public function addDefault( $fieldName, $default ) {
+ $this->attributes['defaults'][$fieldName] = $default;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param string $key
+ * @param string|array $option
+ *
+ * @throws RuntimeException
+ */
+ public function addOption( $key, $option ) {
+
+ if ( $key === 'fields' || $key === 'indices' || $key === 'defaults' ) {
+ throw new RuntimeException( "$key is a reserved option key." );
+ }
+
+ $this->attributes[$key] = $option;
+ }
+
+}