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 SetUp:
15: * This tag takes an integer that denotes the "set-up" status of the game. A
16: * value of "0" indicates that the game has started from the usual initial array.
17: * A value of "1" indicates that the game started from a set-up position; this
18: * position is given in the "FEN" tag pair. This tag must appear for a game
19: * starting with a set-up position. If it appears with a tag value of "1", a FEN
20: * tag pair must also appear.
21: * @see pgn_standard.txt
22: * @author Geraldo
23: */
24: class SetUp extends Tag {
25:
26: public function getName() {
27: $parsed = Parser::parseClassName(get_class());
28: return $parsed['className'];
29: }
30:
31: /**
32: *
33: * @assert("") === true
34: * @assert("0") === true
35: * @assert("1") === true
36: * @assert("-1") === false
37: * @assert("2") === false
38: * @assert("a") === false
39: * @assert(NULL) === false
40: * @assert("A") === false
41: * @assert("*") === false
42: * @assert("2.1") === false
43: *
44: * @param mixed $data
45: * @return boolean returns if a data is valid
46: */
47: public function validate($data) {
48: if (!parent::validate($data)) {
49: return false;
50: }
51:
52: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
53: }
54:
55: /**
56: * Get the regex pattern of a valid SetUp tag string
57: * @return string regex pattern of a valid SetUp tag string
58: */
59: static public function validPattern() {
60: return "[0|1]";
61: }
62:
63: }
64: