iflrandevu/engine/Types/Type.php

58 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2016-07-09 11:05:33 +03:00
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, 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
* ---------------------------------------------------------------------------- */
namespace EA\Engine\Types;
2016-07-09 11:05:33 +03:00
/**
* Abstract Type Class
2016-07-09 11:05:33 +03:00
*
* @deprecated
*
2016-07-09 11:05:33 +03:00
* This class needs to be extended by the type classes which must implement the validation logic.
*/
abstract class Type {
/**
* Class Constructor
*
2016-07-09 11:05:33 +03:00
* @param mixed $value The type value to be validated.
*/
public function __construct($value)
{
if ( ! $this->validate($value))
{
throw new \InvalidArgumentException(__CLASS__ . ': Invalid argument value provided (' . $value . ')');
2016-07-09 12:03:34 +03:00
}
$this->value = $value;
2016-07-09 11:05:33 +03:00
}
/**
* Get the type value.
*
2016-07-09 11:05:33 +03:00
* @return mixed
*/
public function get()
{
2016-07-09 11:05:33 +03:00
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 12:03:34 +03:00
* @return bool Returns whether the value is valid or not.
2016-07-09 11:05:33 +03:00
*/
abstract protected function validate($value);
2016-07-09 11:05:33 +03:00
}