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\Validation\Constraints;
13:
14: use Chromabits\Nucleus\Meditation\Constraints\AbstractConstraint;
15:
16: /**
17: * Class EmailConstraint.
18: *
19: * @author Eduardo Trujillo <ed@chromabits.com>
20: * @package Chromabits\Nucleus\Validation\Constraints
21: */
22: class EmailConstraint extends AbstractConstraint
23: {
24: /**
25: * Check if the constraint is met.
26: *
27: * @param mixed $value
28: * @param array $context
29: *
30: * @return mixed
31: */
32: public function check($value, array $context = [])
33: {
34: return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
35: }
36:
37: /**
38: * Get string representation of this constraint.
39: *
40: * @return mixed
41: */
42: public function toString()
43: {
44: return '{email}';
45: }
46:
47: /**
48: * Get the description of the constraint.
49: *
50: * @return string
51: */
52: public function getDescription()
53: {
54: return 'The value is expected to be a valid email address.';
55: }
56: }
57: