| 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\Parser; |
| 27: | |
| 28: | use Kint\Object\BasicObject; |
| 29: | |
| 30: | class TimestampPlugin extends Plugin |
| 31: | { |
| 32: | public static $blacklist = array( |
| 33: | 2147483648, |
| 34: | 2147483647, |
| 35: | 1073741824, |
| 36: | 1073741823, |
| 37: | ); |
| 38: | |
| 39: | public function getTypes() |
| 40: | { |
| 41: | return array('string', 'integer'); |
| 42: | } |
| 43: | |
| 44: | public function getTriggers() |
| 45: | { |
| 46: | return Parser::TRIGGER_SUCCESS; |
| 47: | } |
| 48: | |
| 49: | public function parse(&$var, BasicObject &$o, $trigger) |
| 50: | { |
| 51: | if (\is_string($var) && !\ctype_digit($var)) { |
| 52: | return; |
| 53: | } |
| 54: | |
| 55: | if (\in_array($var, self::$blacklist, true)) { |
| 56: | return; |
| 57: | } |
| 58: | |
| 59: | $len = \strlen($var); |
| 60: | |
| 61: | // Guess for anything between March 1973 and November 2286 |
| 62: | if (9 === $len || 10 === $len) { |
| 63: | // If it's an int or string that's this short it probably has no other meaning |
| 64: | // Additionally it's highly unlikely the shortValue will be clipped for length |
| 65: | // If you're writing a plugin that interferes with this, just put your |
| 66: | // parser plugin further down the list so that it gets loaded afterwards. |
| 67: | $o->value->label = 'Timestamp'; |
| 68: | $o->value->hints[] = 'timestamp'; |
| 69: | } |
| 70: | } |
| 71: | } |
| 72: |