1: <?php
2:
3: /**
4: * Copyright 2015, Eduardo Trujillo
5: *
6: * For the full copyright and license information, please view the LICENSE
7: * file that was distributed with this source code.
8: *
9: * This file is part of the Nucleus package
10: */
11:
12: namespace Chromabits\Nucleus\Meditation\Primitives;
13:
14: use Chromabits\Nucleus\Meditation\TypesDefinition;
15:
16: /**
17: * Class CompoundTypes.
18: *
19: * @author Eduardo Trujillo <ed@chromabits.com>
20: * @package Chromabits\Nucleus\Meditation\Primitives
21: */
22: class CompoundTypes extends TypesDefinition
23: {
24: const COMPOUND_ARRAY = 'array';
25: const COMPOUND_OBJECT = 'object';
26:
27: /**
28: * Get a list of names of all the types defined.
29: *
30: * @return string[]
31: */
32: public function getTypesDefined()
33: {
34: return $this->getValues();
35: }
36:
37: /**
38: * Get a list of names of all the compound types defined.
39: *
40: * @return string[]
41: */
42: public function getCompounds()
43: {
44: return $this->getValues();
45: }
46:
47: /**
48: * Type check a value.
49: *
50: * @param string $typeName
51: * @param mixed $value
52: *
53: * @return bool
54: */
55: public function check($typeName, $value)
56: {
57: switch ($typeName) {
58: case static::COMPOUND_ARRAY:
59: return is_array($value);
60: case static::COMPOUND_OBJECT:
61: return is_object($value);
62: default:
63: return false;
64: }
65: }
66: }
67: