1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
<?php
/**
* Created by PhpStorm.
* Copyright: Bertschi AG, 2015
* User: jbaumann
* File: Version.php
* Date: 24.12.2015
* Time: 08:37
*/
namespace JRA\Config;
use JRA\Config\Helper\APIRoutes;
use JRA\config\helper\Versions;
use JRA\Exceptions\VersionException;
class Version
{
/**
* The version of cAPI which is used.
*
* @var int
*/
private $_version;
/**
* The api route for the specified version.
*
* @var string
*/
private $_APIRoute;
/**
* Version constructor.
*
* @param int $pVersion The cAPI version which is used.
*/
public function __construct($pVersion)
{
$this->_version = $pVersion;
$this->_validateVersion();
}
/**
* Validates if the version is supported and if a valid version number is given.
*
* @throws VersionException Throws an exception if something went wrong with version defining.
*/
private function _validateVersion()
{
switch ($this->_version) {
case Versions::API_VERSION_110:
$this->_APIRoute = APIRoutes::API_VERSION_110;
break;
case Versions::API_VERSION_105:
throw new VersionException('Version is not supported.', VersionException::VERSION_CONFIG_EXCEPTION_VERSION_NOT_SUPPORTED);
break;
default:
throw new VersionException();
break;
}
}
}