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\Constraints;
13:
14: /**
15: * Class ClassTypeConstraint.
16: *
17: * @author Eduardo Trujillo <ed@chromabits.com>
18: * @package Chromabits\Nucleus\Meditation\Constraints
19: */
20: class ClassTypeConstraint extends AbstractTypeConstraint
21: {
22: /**
23: * Expected class name.
24: *
25: * @var string
26: */
27: protected $className;
28:
29: /**
30: * Construct an instance of a ClassTypeConstraint.
31: *
32: * @param string $className
33: */
34: public function __construct($className)
35: {
36: parent::__construct();
37:
38: $this->className = $className;
39: }
40:
41: /**
42: * Check if the constraint is met.
43: *
44: * @param mixed $value
45: * @param array $context
46: *
47: * @return mixed
48: */
49: public function check($value, array $context = [])
50: {
51: return is_a($value, $this->className, false);
52: }
53:
54: /**
55: * Get string representation of this constraint.
56: *
57: * @return mixed
58: */
59: public function toString()
60: {
61: return $this->className;
62: }
63:
64: /**
65: * Get the description of the constraint.
66: *
67: * @return string
68: */
69: public function getDescription()
70: {
71: return vsprintf('The value is expected to be an instance of a %s.', [
72: $this->className,
73: ]);
74: }
75: }
76: