Adding some more base classes
This commit is contained in:
parent
c795414c3f
commit
2c91f5d572
10
src/Exceptions/ValidationException.php
Normal file
10
src/Exceptions/ValidationException.php
Normal 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
5
src/MatrixHttpApi.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Aryess\PhpMatrixSdk;
|
||||
|
||||
class MatrixHttpApi {}
|
40
src/Util.php
Normal file
40
src/Util.php
Normal 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 :");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue