22namespace GraphQL \Examples \Blog \Type \Scalar ;
33
44use GraphQL \Error \Error ;
5- use GraphQL \Examples \Blog \Type \BaseType ;
65use GraphQL \Language \AST \StringValueNode ;
76use GraphQL \Type \Definition \CustomScalarType ;
87use GraphQL \Utils ;
98
10- class EmailType extends BaseType
9+ class EmailType
1110{
12- public function __construct ()
11+ public static function create ()
1312 {
14- // Option #1: define scalar types using composition (see UrlType fo option #2 using inheritance)
15- $ this ->definition = new CustomScalarType ([
13+ return new CustomScalarType ([
1614 'name ' => 'Email ' ,
17- 'serialize ' => [$ this , 'serialize ' ],
18- 'parseValue ' => [$ this , 'parseValue ' ],
19- 'parseLiteral ' => [$ this , 'parseLiteral ' ],
15+ 'serialize ' => [__CLASS__ , 'serialize ' ],
16+ 'parseValue ' => [__CLASS__ , 'parseValue ' ],
17+ 'parseLiteral ' => [__CLASS__ , 'parseLiteral ' ],
2018 ]);
2119 }
2220
@@ -26,7 +24,7 @@ public function __construct()
2624 * @param string $value
2725 * @return string
2826 */
29- public function serialize ($ value )
27+ public static function serialize ($ value )
3028 {
3129 // Assuming internal representation of email is always correct:
3230 return $ value ;
@@ -42,7 +40,7 @@ public function serialize($value)
4240 * @param mixed $value
4341 * @return mixed
4442 */
45- public function parseValue ($ value )
43+ public static function parseValue ($ value )
4644 {
4745 if (!filter_var ($ value , FILTER_VALIDATE_EMAIL )) {
4846 throw new \UnexpectedValueException ("Cannot represent value as email: " . Utils::printSafe ($ value ));
@@ -57,7 +55,7 @@ public function parseValue($value)
5755 * @return string
5856 * @throws Error
5957 */
60- public function parseLiteral ($ valueNode )
58+ public static function parseLiteral ($ valueNode )
6159 {
6260 // Note: throwing GraphQL\Error\Error vs \UnexpectedValueException to benefit from GraphQL
6361 // error location in query:
0 commit comments