1: <?php
2: /*
3: * Copyright (c) 2016 Geraldo B. Landre
4: *
5: * See the file LICENSE for copying permission.
6: */
7: namespace pgn\tags;
8:
9: use utils\Parser;
10:
11: /**
12: * Description of WhiteType:
13: * These tags use string values; these describe the player types. The value
14: * "human" should be used for a person while the value "program" should be used
15: * for algorithmic (computer) players.
16: *
17: * @see pgn_standard.txt
18: * @author Geraldo
19: */
20: class WhiteType extends Tag {
21:
22: public function getName() {
23: $parsed = Parser::parseClassName(get_class());
24: return $parsed['className'];
25: }
26:
27: /**
28: * @assert("human") === true
29: * @assert("program") === true
30: * @assert("person") === false
31: * @assert("software") === false
32: * @assert(3.1) === false
33: * @assert("4.1.2") === false
34: * @assert("-") === false
35: * @assert(NULL) === false
36: * @assert("A") === false
37: * @assert("asdf") === false
38: * @assert("*") === false
39: * @param string $data
40: * @return boolean
41: */
42: public function validate($data) {
43:
44: if(!parent::validate($data)) {
45: return false;
46: }
47:
48: if($data === '?') {
49: return true;
50: }
51:
52: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
53: }
54:
55: /**
56: *
57: * @return string Valid Regular Expression Pattern for PGN Rounds
58: */
59: static public function validPattern() {
60: return "human|program";
61: }
62:
63: }
64: