Adding some more base classes

This commit is contained in:
Yoann Celton 2018-11-27 23:30:54 +11:00 committed by Aryess
parent 4d64c6bce5
commit 0f51a1cf93
3 changed files with 55 additions and 0 deletions

View file

@ -0,0 +1,10 @@
<?php
namespace Aryess\PhpMatrixSdk\Exceptions;
/**
* Simple exception to differentiate validation exception from other exceptions
*
* @package Aryess\PhpMatrixSdk\Exceptions
*/
class ValidationException extends \Exception {}

5
src/MatrixHttpApi.php Normal file
View file

@ -0,0 +1,5 @@
<?php
namespace Aryess\PhpMatrixSdk;
class MatrixHttpApi {}

40
src/Util.php Normal file
View file

@ -0,0 +1,40 @@
<?php
namespace Aryess\PhpMatrixSdk;
use Aryess\PhpMatrixSdk\Exceptions\ValidationException;
class Util {
/**
* Check if provided roomId is valid
*
* @param string $roomId
* @throws ValidationException
*/
public static function checkRoomId(string $roomId) {
if(strpos($roomId, '!') !== 0) {
throw new ValidationException("RoomIDs start with !");
}
if(strpos($roomId, ':') === false) {
throw new ValidationException("RoomIDs must have a domain component, seperated by a :");
}
}
/**
* Check if provided userId is valid
*
* @param string $userId
* @throws ValidationException
*/
public static function checkUserId(string $userId) {
if(strpos($userId, '@') !== 0) {
throw new ValidationException("UserIDs start with @");
}
if(strpos($userId, ':') === false) {
throw new ValidationException("UserIDs must have a domain component, seperated by a :");
}
}
}