5 * Copyright 2018 Andy Street <andy@street.me.uk>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 use \InvalidArgumentException;
30 * Information about the copyright holder and any license governing use of
33 * @see https://www.topografix.com/GPX/1/1/#type_copyrightType
35 * @author Andy Street <andy@street.me.uk>
41 * The copyright holder.
48 * The year of copyright.
55 * Link to external file containing license text.
62 * Create new copyright information.
64 * @param string $author The copyright holder.
66 public function __construct(string $author)
68 $this->setAuthor($author);
72 * Fetch the name of the copyright holder.
74 * @return string The copyright holder.
76 public function getAuthor()
82 * Set the name of the copyright holder.
84 * @param string $author The name of the copyright holder.
87 public function setAuthor(string $author)
89 $this->author = $author;
93 * Fetch the year of copyright.
95 * NOTE: The GPX 1.1 schema defines this field as type "xsd:gYear". It is
96 * therefore possible that this function will return a timezone as
99 * @param boolean $asint Make the return value an integer (any timezones will
101 * @return string|int|null The copyright year or null if not set.
103 public function getYear(bool $asint = false)
105 return ($asint ? intval($this->year) : $this->year);
109 * Set the year of copyright.
111 * @param string|null $year The copyright year in xsd:gYear format or null to
114 * @throws InvalidArgumentException If the year is an invalid format.
116 public function setYear(string $year = null)
118 if ($year !== null) {
120 $regex = '/^(-?)([0-9]+)(Z|[+-][0-9]{2}:[0-9]{2})?$/';
121 if (preg_match($regex, $year, $matches)) {
124 str_pad($matches[2], 4, '0', STR_PAD_LEFT);
125 if (isset($matches[3]))
126 $year .= $matches[3];
128 throw new InvalidArgumentException(
129 sprintf('Copyright year is an invalid format "%s".', $year)
137 * Fetch the URL of the license terms.
139 * @return string|null The URL or null if not set.
141 public function getLicense()
143 return $this->license;
147 * Set the URL of the license terms.
149 * @param string|null $license The URL or null to delete.
152 public function setLicense(string $license = null)
154 $this->license = $license;