@@ -27,10 +27,11 @@ zend_class_entry *php_driver_timeuuid_ce = NULL;
2727void
2828php_driver_timeuuid_init (INTERNAL_FUNCTION_PARAMETERS )
2929{
30- long timestamp ;
3130 php_driver_uuid * self ;
31+ zval * param ;
32+ int version ;
3233
33- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "|l " , & timestamp ) == FAILURE ) {
34+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "|z " , & param ) == FAILURE ) {
3435 return ;
3536 }
3637
@@ -41,14 +42,34 @@ php_driver_timeuuid_init(INTERNAL_FUNCTION_PARAMETERS)
4142 self = PHP_DRIVER_GET_UUID (return_value );
4243 }
4344
45+
4446 if (ZEND_NUM_ARGS () == 0 ) {
4547 php_driver_uuid_generate_time (& self -> uuid TSRMLS_CC );
4648 } else {
47- if (timestamp < 0 ) {
48- zend_throw_exception_ex (php_driver_invalid_argument_exception_ce , 0 TSRMLS_CC , "Timestamp must be a positive integer, %d given" , timestamp );
49- return ;
50- }
51- php_driver_uuid_generate_from_time (timestamp , & self -> uuid TSRMLS_CC );
49+
50+ switch (Z_TYPE_P (param )) {
51+ case IS_LONG :
52+ if (Z_LVAL_P (param ) < 0 ) {
53+ zend_throw_exception_ex (php_driver_invalid_argument_exception_ce , 0 TSRMLS_CC , "Timestamp must be a positive integer, %d given" , Z_LVAL_P (param ));
54+ return ;
55+ }
56+ php_driver_uuid_generate_from_time (Z_LVAL_P (param ), & self -> uuid TSRMLS_CC );
57+ break ;
58+ case IS_STRING :
59+ if (cass_uuid_from_string (Z_STRVAL_P (param ), & self -> uuid ) != CASS_OK ) {
60+ zend_throw_exception_ex (php_driver_invalid_argument_exception_ce , 0 TSRMLS_CC , "Invalid UUID: '%.*s'" , Z_STRLEN_P (param ), Z_STRVAL_P (param ));
61+ return ;
62+ }
63+
64+ version = cass_uuid_version (self -> uuid );
65+ if (version != 1 ) {
66+ zend_throw_exception_ex (php_driver_invalid_argument_exception_ce , 0 TSRMLS_CC , "UUID must be of type 1, type %d given" , version );
67+ }
68+ break ;
69+ default :
70+ zend_throw_exception_ex (php_driver_invalid_argument_exception_ce , 0 TSRMLS_CC , "Invalid argument - integer or string expected" );
71+ }
72+
5273 }
5374}
5475
0 commit comments