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\Object\Representation; |
27: | |
28: | class Representation |
29: | { |
30: | public $label; |
31: | public $implicit_label = false; |
32: | public $hints = array(); |
33: | public $contents = array(); |
34: | |
35: | protected $name; |
36: | |
37: | public function __construct($label, $name = null) |
38: | { |
39: | $this->label = $label; |
40: | |
41: | if (null === $name) { |
42: | $name = $label; |
43: | } |
44: | |
45: | $this->setName($name); |
46: | } |
47: | |
48: | public function getLabel() |
49: | { |
50: | if (\is_array($this->contents) && \count($this->contents) > 1) { |
51: | return $this->label.' ('.\count($this->contents).')'; |
52: | } |
53: | |
54: | return $this->label; |
55: | } |
56: | |
57: | public function getName() |
58: | { |
59: | return $this->name; |
60: | } |
61: | |
62: | public function setName($name) |
63: | { |
64: | $this->name = \preg_replace('/[^a-z0-9]+/', '_', \strtolower($name)); |
65: | } |
66: | |
67: | public function labelIsImplicit() |
68: | { |
69: | return $this->implicit_label; |
70: | } |
71: | } |
72: |