File tree Expand file tree Collapse file tree 4 files changed +55
-1
lines changed Expand file tree Collapse file tree 4 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,4 @@ public function __toString()
3939 * @return string
4040 */
4141 abstract protected function generate ();
42- }
42+ }
Original file line number Diff line number Diff line change 99 */
1010class SpanIdentifier extends Identifier
1111{
12+ /**
13+ * @inheritdoc
14+ *
15+ * @param $fromString string Optional, creates identifier from string
16+ */
17+ public function __construct ($ fromString = null )
18+ {
19+ if ($ fromString && is_zipkin_span_identifier ($ fromString )) {
20+ $ this ->value = $ fromString ;
21+ } else {
22+ parent ::__construct ();
23+ }
24+ }
25+
1226 /**
1327 * Generates 128-bit hex-encoded identifier
1428 * http://zipkin.io/pages/instrumenting.html#trace-identifiers
Original file line number Diff line number Diff line change 99 */
1010class TraceIdentifier extends Identifier
1111{
12+ /**
13+ * @inheritdoc
14+ *
15+ * @param $fromString string Optional, creates identifier from string
16+ */
17+ public function __construct ($ fromString = null )
18+ {
19+ if ($ fromString && is_zipkin_trace_identifier ($ fromString )) {
20+ $ this ->value = $ fromString ;
21+ } else {
22+ parent ::__construct ();
23+ }
24+ }
25+
1226 /**
1327 * Generates 128-bit hex-encoded identifier
1428 * http://zipkin.io/pages/instrumenting.html#trace-identifiers
Original file line number Diff line number Diff line change @@ -25,3 +25,29 @@ function is_zipkin_timestamp($timestamp)
2525 return ctype_digit ((string ) $ timestamp ) && strlen ($ timestamp ) === 16 ;
2626 }
2727}
28+
29+ if (!function_exists ('is_zipkin_trace_identifier ' )) {
30+ /**
31+ * Is zipkin trace identifier
32+ *
33+ * @param $identifier string|\whitemerry\phpkin\Identifier\Identifier
34+ *
35+ * @return bool
36+ */
37+ function is_zipkin_trace_identifier ($ identifier ) {
38+ return ctype_xdigit ((string ) $ identifier ) && strlen ((string ) $ identifier ) === 32 ;
39+ }
40+ }
41+
42+ if (!function_exists ('is_zipkin_span_identifier ' )) {
43+ /**
44+ * Is zipkin span identifier
45+ *
46+ * @param $identifier string|\whitemerry\phpkin\Identifier\Identifier
47+ *
48+ * @return bool
49+ */
50+ function is_zipkin_span_identifier ($ identifier ) {
51+ return ctype_xdigit ((string ) $ identifier ) && strlen ((string ) $ identifier ) === 16 ;
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments