1: <?php
2:
3: /*
4: * The MIT License (MIT)
5: *
6: * Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
7: *
8: * Permission is hereby granted, free of charge, to any person obtaining a copy of
9: * this software and associated documentation files (the "Software"), to deal in
10: * the Software without restriction, including without limitation the rights to
11: * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12: * the Software, and to permit persons to whom the Software is furnished to do so,
13: * subject to the following conditions:
14: *
15: * The above copyright notice and this permission notice shall be included in all
16: * copies or substantial portions of the Software.
17: *
18: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20: * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21: * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22: * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23: * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24: */
25:
26: namespace Kint\Renderer\Rich;
27:
28: use Kint\Object\Representation\Representation;
29:
30: class BinaryPlugin extends Plugin implements TabPluginInterface
31: {
32: public static $line_length = 0x10;
33: public static $chunk_length = 0x4;
34:
35: public function renderTab(Representation $r)
36: {
37: $out = '<pre>';
38:
39: $chunks = \str_split($r->contents, self::$line_length);
40:
41: foreach ($chunks as $index => $chunk) {
42: $out .= \sprintf('%08X', $index * self::$line_length).":\t";
43: $out .= \implode(' ', \str_split(\str_pad(\bin2hex($chunk), 2 * self::$line_length, ' '), self::$chunk_length));
44: $out .= "\t".\preg_replace('/[^\\x20-\\x7E]/', '.', $chunk)."\n";
45: }
46:
47: $out .= '</pre>';
48:
49: return $out;
50: }
51: }
52: