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 ScalarTypes.
18: *
19: * @author Eduardo Trujillo <ed@chromabits.com>
20: * @package Chromabits\Nucleus\Meditation\Primitives
21: */
22: class ScalarTypes extends TypesDefinition
23: {
24: const SCALAR_STRING = 'string';
25: const SCALAR_INTEGER = 'integer';
26: const SCALAR_FLOAT = 'float';
27: const SCALAR_BOOLEAN = 'boolean';
28:
29: /**
30: * Get a list of names of all the types defined.
31: *
32: * @return string[]
33: */
34: public function getTypesDefined()
35: {
36: return $this->getValues();
37: }
38:
39: /**
40: * Get a list of names of all the scalar types defined.
41: *
42: * @return string[]
43: */
44: public function getScalars()
45: {
46: return $this->getValues();
47: }
48:
49: /**
50: * Type check a value.
51: *
52: * @param string $typeName
53: * @param mixed $value
54: *
55: * @return bool
56: */
57: public function check($typeName, $value)
58: {
59: switch ($typeName) {
60: case static::SCALAR_STRING:
61: return is_string($value);
62: case static::SCALAR_INTEGER:
63: return is_integer($value);
64: case static::SCALAR_FLOAT:
65: return is_float($value);
66: case static::SCALAR_BOOLEAN:
67: return is_bool($value);
68: default:
69: return false;
70: }
71: }
72: }
73: