Files
sysPass/lib/SP/Core/Exceptions/SPException.php
Rubén D b640b6d695 chore(refactor): LDAP auth refactoring.
- Decouple from ldap_* native functions
- Use Laminas/Ldap library
- Use enum for interface constants
- Move LDAP interfaces to domain
- Simplify LdapActions API

Signed-off-by: Rubén D <nuxsmin@syspass.org>
2023-06-03 21:40:20 +02:00

123 lines
3.1 KiB
PHP

<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Core\Exceptions;
use Exception;
defined('APP_ROOT') || die();
/**
* Extender la clase Exception para mostrar ayuda en los mensajes
*/
class SPException extends Exception
{
public const CRITICAL = 1;
public const WARNING = 2;
public const ERROR = 3;
public const INFO = 4;
protected int $type;
protected ?string $hint;
/**
* SPException constructor.
*
* @param string $message
* @param int $type
* @param string|null $hint
* @param int $code
* @param Exception|null $previous
*/
public function __construct(
string $message,
int $type = self::ERROR,
?string $hint = null,
int $code = 0,
Exception $previous = null
) {
$this->type = $type;
$this->hint = $hint;
parent::__construct($message, $code, $previous);
}
public static function error(
string $message,
?string $hint = null,
int $code = 0,
Exception $previous = null
): static {
return new static($message, SPException::ERROR, $hint, $code, $previous);
}
public static function critical(
string $message,
?string $hint = null,
int $code = 0,
Exception $previous = null
): static {
return new static($message, SPException::CRITICAL, $hint, $code, $previous);
}
public static function warning(
string $message,
?string $hint = null,
int $code = 0,
Exception $previous = null
): static {
return new static($message, SPException::WARNING, $hint, $code, $previous);
}
public static function info(
string $message,
?string $hint = null,
int $code = 0,
Exception $previous = null
): static {
return new static($message, SPException::INFO, $hint, $code, $previous);
}
/**
* @return string
*/
public function __toString(): string
{
return sprintf('%s: [%s]: %s (%s)', __CLASS__, $this->code, $this->message, $this->hint);
}
public function getHint(): ?string
{
return $this->hint;
}
/**
* @return int|string
*/
public function getType(): int|string
{
return $this->type;
}
}