Overview

Namespaces

  • cassandra
  • None
  • PHP
  • phpcassa
    • Batch
    • Connection
    • Index
    • Iterator
    • Schema
      • DataType
    • Util
    • UUID

Classes

  • DataType
  • StrategyClass
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace phpcassa\Schema;
 3: 
 4: use phpcassa\Schema\DataType\CompositeType;
 5: 
 6: /**
 7:  * Maps type strings to packer and unpacker functions.
 8:  *
 9:  * @package phpcassa\Schema
10:  */
11: class DataType
12: {
13:     const BYTES_TYPE = "BytesType";
14:     const LONG_TYPE = "LongType";
15:     const INTEGER_TYPE = "IntegerType";
16:     const INT32_TYPE = "Int32Type";
17:     const FLOAT_TYPE = "FloatType";
18:     const DOUBLE_TYPE = "DoubleType";
19:     const ASCII_TYPE = "AsciiType";
20:     const UTF8_TYPE = "UTF8Type";
21:     const TIME_UUID_TYPE = "TimeUUIDType";
22:     const LEXICAL_UUID_TYPE = "LexicalUUIDType";
23:     const UUID_TYPE = "UUIDType";
24:     const DATE_TYPE = "DateType";
25: 
26:     public static $class_map;
27: 
28:     public static function init() {
29:         self::$class_map = array(
30:             'BytesType'       => 'phpcassa\Schema\DataType\BytesType',
31:             'AsciiType'       => 'phpcassa\Schema\DataType\AsciiType',
32:             'UTF8Type'        => 'phpcassa\Schema\DataType\UTF8Type',
33:             'LongType'        => 'phpcassa\Schema\DataType\LongType',
34:             'IntegerType'     => 'phpcassa\Schema\DataType\IntegerType',
35:             'FloatType'       => 'phpcassa\Schema\DataType\FloatType',
36:             'DoubleType'      => 'phpcassa\Schema\DataType\DoubleType',
37:             'TimeUUIDType'    => 'phpcassa\Schema\DataType\TimeUUIDType',
38:             'LexicalUUIDType' => 'phpcassa\Schema\DataType\LexicalUUIDType',
39:             'UUIDType'        => 'phpcassa\Schema\DataType\UUIDType',
40:             'BooleanType'     => 'phpcassa\Schema\DataType\BooleanType',
41:             'DateType'        => 'phpcassa\Schema\DataType\DateType',
42:             'Int32Type'        => 'phpcassa\Schema\DataType\Int32Type',
43:         );
44:     }
45: 
46:     protected static function extract_type_name($typestr) {
47:         if ($typestr == null or $typestr == '')
48:             return 'BytesType';
49: 
50:         $index = strrpos($typestr, '.');
51:         if ($index == false)
52:             return 'BytesType';
53: 
54:         $type = substr($typestr, $index + 1);
55:         if (!isset(self::$class_map[$type]))
56:             return 'BytesType';
57: 
58:         return $type;
59:     }
60: 
61:     /** Given a typestr like "Reversed(AsciiType)", returns "AsciiType". */
62:     protected static function get_inner_type($typestr) {
63:         $paren_index = strpos($typestr, '(');
64:         $end = strlen($typestr) - $paren_index;
65:         return substr($typestr, $paren_index + 1, $end - 2);
66:     }
67: 
68:     protected static function get_inner_types($typestr) {
69:         $inner = self::get_inner_type($typestr);
70:         $inner_typestrs = explode(',', $inner);
71:         $inner_types = array();
72: 
73:         foreach ($inner_typestrs as $inner_type) {
74:             $inner_types[] = self::get_type_for(trim($inner_type));
75:         }
76:         return $inner_types;
77:     }
78: 
79:     public static function get_type_for($typestr) {
80:         if (strpos($typestr, 'CompositeType') !== false) {
81:             return new CompositeType(self::get_inner_types($typestr));
82:         } else if (strpos($typestr, 'ReversedType') !== false) {
83:             return self::get_type_for(self::get_inner_type($typestr));
84:         } else {
85:             $type_name = self::extract_type_name($typestr);
86:             $type_class = self::$class_map[$type_name];
87:             return new $type_class;
88:         }
89:     }
90: }
91: 
92: DataType::init();
93: 
phpcassa API documentation generated by ApiGen 2.8.0