| [86442cb] | 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | namespace GnuBoat\Nmea;
|
|---|
| 20 |
|
|---|
| 21 | abstract class NmeaSentence
|
|---|
| 22 | {
|
|---|
| 23 | function __construct($type, $talker, $sentence)
|
|---|
| 24 | {
|
|---|
| 25 | $this->_talker = $talker;
|
|---|
| 26 | $this->_type = $type;
|
|---|
| 27 | $this->_sentence = $sentence;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | public function valid(&$errorMessage = "")
|
|---|
| 31 | {
|
|---|
| 32 | if(empty($this->talker())){
|
|---|
| 33 | $errorMessage = "Talker not set";
|
|---|
| 34 | return false;
|
|---|
| 35 | }
|
|---|
| 36 | if(empty($this->type())){
|
|---|
| 37 | $errorMessage = "Type not set";
|
|---|
| 38 | return false;
|
|---|
| 39 | }
|
|---|
| 40 | return $this->validate($errorMessage);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public function talker()
|
|---|
| 44 | {
|
|---|
| 45 | return $this->_talker;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | public function type()
|
|---|
| 49 | {
|
|---|
| 50 | return $this->_type;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | public function sentence()
|
|---|
| 54 | {
|
|---|
| 55 | return $this->_sentence;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | /**
|
|---|
| 59 | * @brief Abstract function to provide additional checks in your implementation.
|
|---|
| 60 | *
|
|---|
| 61 | * Called by valid() and must return true or false
|
|---|
| 62 | */
|
|---|
| 63 | abstract protected function validate(&$errorMessage);
|
|---|
| 64 |
|
|---|
| 65 | private $_talker;
|
|---|
| 66 | private $_type;
|
|---|
| 67 | private $_sentence;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | ?>
|
|---|