1: <?php
2:
3: /*
4: * Copyright (c) 2016 Geraldo B. Landre
5: *
6: * See the file LICENSE for copying permission.
7: */
8:
9: namespace pgn\tags;
10:
11: use utils\Parser;
12:
13: /**
14: * Description of ECO:
15: * 9.4.1: Tag: ECO
16: *
17: * This uses a string of either the form "XDD" or the form "XDD/DD" where the "X"
18: * is a letter from "A" to "E" and the "D" positions are digits; this is used for
19: * an opening designation from the five volume _Encyclopedia of Chess Openings_.
20: * This tag pair is associated with the use of the EPD opcode "eco" described in a
21: * later section of this document.
22: *
23: * @see pgn_standard.txt
24: * @author Geraldo
25: */
26: class ECO extends Tag {
27:
28: public function getName() {
29: $parsed = Parser::parseClassName(get_class());
30: return $parsed['className'];
31: }
32:
33: /**
34: *
35: * @assert("A00") === true
36: * @assert("A00/00") === true
37: * @assert("E99") === true
38: * @assert("E99/99") === true
39: * @assert("C12/34") === true
40: * @assert("C21") === true
41: * @assert(NULL) === false
42: * @assert("A") === false
43: * @assert("A0") === false
44: * @assert("A00/0") === false
45: * @assert("asdf") === false
46: * @assert(123) === false
47: * @assert("*") === false
48: * @assert("????.??.??") === false
49: *
50: * @param mixed $data
51: * @return boolean returns if a data is valid
52: */
53: public function validate($data) {
54: if(!parent::validate($data)) {
55: return false;
56: }
57:
58: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
59: }
60:
61: /**
62: * Get the regex pattern of a valid ECO tag string
63: * @return string regex pattern of a valid ECO tag string
64: */
65: static public function validPattern() {
66: return "[A-E]\d\d(\/\d\d)?";
67: }
68:
69: }
70: