easyappointments/src/engine/Types/Type.php

53 lines
1.4 KiB
PHP
Raw Normal View History

2016-07-09 11:05:33 +03:00
<?php
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
2017-01-31 09:35:34 +03:00
* @copyright Copyright (c) 2013 - 2017, Alex Tselegidis
2016-07-09 11:05:33 +03:00
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyappointments.org
* @since v1.2.0
* ---------------------------------------------------------------------------- */
2016-07-09 11:33:13 +03:00
namespace EA\Engine\Types;
2016-07-09 11:05:33 +03:00
/**
* Abstract Type Class
*
* This class needs to be extended by the type classes which must implement the validation logic.
*/
abstract class Type {
/**
* Class Constructor
*
* @param mixed $value The type value to be validated.
*/
public function __construct($value) {
2016-07-09 12:03:34 +03:00
if (!$this->_validate($value)) {
throw new \InvalidArgumentException(__CLASS__ . ': Invalid argument value provided (' . $value . ')');
}
2016-07-09 11:05:33 +03:00
$this->value = $value;
}
/**
* Get the type value.
*
* @return mixed
*/
public function get() {
return $this->value;
}
/**
* Implement the validation logic in the children classes.
2016-07-09 12:03:34 +03:00
*
* @param mixed $value The value to be validated.
2016-07-09 11:05:33 +03:00
*
2016-07-09 12:03:34 +03:00
* @return bool Returns whether the value is valid or not.
2016-07-09 11:05:33 +03:00
*/
2016-07-09 12:03:34 +03:00
abstract protected function _validate($value);
2016-07-09 11:05:33 +03:00
}