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 White:
13: * The White tag value is the name of the player or players of the white pieces.
14: * The names are given as they would appear in a telephone directory. The family
15: * or last name appears first. If a first name or first initial is available, it
16: * is separated from the family name by a comma and a space. Finally, one or more
17: * middle initials may appear. (Wherever a comma appears, the very next character
18: * should be a space. Wherever an initial appears, the very next character should
19: * be a period.) If the name is unknown, a single question mark should appear as
20: * the tag value.
21: *
22: * The intent is to allow meaningful ASCII sorting of the tag value that is
23: * independent of regional name formation customs. If more than one person is
24: * playing the white pieces, the names are listed in alphabetical order and are
25: * separated by the colon character between adjacent entries. A player who is
26: * also a computer program should have appropriate version information listed
27: * after the name of the program.
28: *
29: * The format used in the FIDE Rating Lists is appropriate for use for player name
30: * tags.
31: *
32: * Examples:
33: *
34: * [White "Tal, Mikhail N."]
35: *
36: * [White "van der Wiel, Johan"]
37: *
38: * [White "Acme Pawngrabber v.3.2"]
39: *
40: * @see pgn_standard.txt
41: * @author Geraldo
42: */
43: class WhiteNA extends Tag {
44:
45: /**
46: * @assert () === 'WhiteNA'
47: * @return string WhiteNA
48: */
49: public function getName() {
50: $parsed = Parser::parseClassName(get_class());
51: return $parsed['className'];
52: }
53:
54: /**
55: * @assert("-") === true
56: * @assert("email@domain.com") === true
57: * @assert("http://www.meusite.com") === true
58: * @assert("http://www.meusite.com/diretorio") === true
59: * @assert("http://www.meusite.com/diretorio/pagina.html") === true
60: * @assert("https://meusite.com/diretorio/pagina.html") === true
61: * Tests based on description:
62: * @assert("Tal, Mikhail N.") === false
63: * @assert("van der Wiel, Johan") === false
64: * @assert("Acme Pawngrabber v.3.2") === false
65: * @assert("?") === false
66: * Basic path tests:
67: * @assert (NULL) === false
68: * @assert ("ab") === false
69: * @assert (", ") === false
70: * @assert (",a") === false
71: * @assert ("a") === false
72: * @param string $data
73: * @return bool true if data is valid and false if not.
74: */
75: public function validate($data) {
76: if (!parent::validate($data)) {
77: return false;
78: }
79:
80: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
81: }
82:
83: /**
84: *
85: * @return string Valid Regular Expression Pattern for Network Address
86: */
87: static public function validPattern() {
88: return "-|\w+@\w+\.\w+|http(s)?\:\/\/.+";
89: }
90:
91: }
92: