Initial
This commit is contained in:
21
system/Exceptions/AlertError.php
Normal file
21
system/Exceptions/AlertError.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
use Error;
|
||||
|
||||
/**
|
||||
* Error: Action must be taken immediately (system/db down, etc)
|
||||
*/
|
||||
class AlertError extends Error
|
||||
{
|
||||
}
|
||||
54
system/Exceptions/CastException.php
Normal file
54
system/Exceptions/CastException.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
/**
|
||||
* Cast Exceptions.
|
||||
*
|
||||
* @deprecated use CodeIgniter\Entity\Exceptions\CastException instead.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class CastException extends CriticalError
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $code = 3;
|
||||
|
||||
public static function forInvalidJsonFormatException(int $error)
|
||||
{
|
||||
switch ($error) {
|
||||
case JSON_ERROR_DEPTH:
|
||||
return new static(lang('Cast.jsonErrorDepth'));
|
||||
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
return new static(lang('Cast.jsonErrorStateMismatch'));
|
||||
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
return new static(lang('Cast.jsonErrorCtrlChar'));
|
||||
|
||||
case JSON_ERROR_SYNTAX:
|
||||
return new static(lang('Cast.jsonErrorSyntax'));
|
||||
|
||||
case JSON_ERROR_UTF8:
|
||||
return new static(lang('Cast.jsonErrorUtf8'));
|
||||
|
||||
default:
|
||||
return new static(lang('Cast.jsonErrorUnknown'));
|
||||
}
|
||||
}
|
||||
}
|
||||
32
system/Exceptions/ConfigException.php
Normal file
32
system/Exceptions/ConfigException.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception for automatic logging.
|
||||
*/
|
||||
class ConfigException extends CriticalError
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $code = 3;
|
||||
|
||||
public static function forDisabledMigrations()
|
||||
{
|
||||
return new static(lang('Migrations.disabled'));
|
||||
}
|
||||
}
|
||||
21
system/Exceptions/CriticalError.php
Normal file
21
system/Exceptions/CriticalError.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
use Error;
|
||||
|
||||
/**
|
||||
* Error: Critical conditions, like component unavailable, etc.
|
||||
*/
|
||||
class CriticalError extends Error
|
||||
{
|
||||
}
|
||||
41
system/Exceptions/DebugTraceableTrait.php
Normal file
41
system/Exceptions/DebugTraceableTrait.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* This trait provides framework exceptions the ability to pinpoint
|
||||
* accurately where the exception was raised rather than instantiated.
|
||||
*
|
||||
* This is used primarily for factory-instantiated exceptions.
|
||||
*/
|
||||
trait DebugTraceableTrait
|
||||
{
|
||||
/**
|
||||
* Tweaks the exception's constructor to assign the file/line to where
|
||||
* it is actually raised rather than were it is instantiated.
|
||||
*/
|
||||
final public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
$trace = $this->getTrace()[0];
|
||||
|
||||
if (isset($trace['class']) && $trace['class'] === static::class) {
|
||||
[
|
||||
'line' => $this->line,
|
||||
'file' => $this->file,
|
||||
] = $trace;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
system/Exceptions/DownloadException.php
Normal file
47
system/Exceptions/DownloadException.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class DownloadException
|
||||
*/
|
||||
class DownloadException extends RuntimeException implements ExceptionInterface
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
public static function forCannotSetFilePath(string $path)
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetFilepath', [$path]));
|
||||
}
|
||||
|
||||
public static function forCannotSetBinary()
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetBinary'));
|
||||
}
|
||||
|
||||
public static function forNotFoundDownloadSource()
|
||||
{
|
||||
return new static(lang('HTTP.notFoundDownloadSource'));
|
||||
}
|
||||
|
||||
public static function forCannotSetCache()
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetCache'));
|
||||
}
|
||||
|
||||
public static function forCannotSetStatusCode(int $code, string $reason)
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetStatusCode', [$code, $reason]));
|
||||
}
|
||||
}
|
||||
21
system/Exceptions/EmergencyError.php
Normal file
21
system/Exceptions/EmergencyError.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
use Error;
|
||||
|
||||
/**
|
||||
* Error: system is unusable
|
||||
*/
|
||||
class EmergencyError extends Error
|
||||
{
|
||||
}
|
||||
22
system/Exceptions/ExceptionInterface.php
Normal file
22
system/Exceptions/ExceptionInterface.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
/**
|
||||
* Provides a domain-level interface for broad capture
|
||||
* of all framework-related exceptions.
|
||||
*
|
||||
* catch (\CodeIgniter\Exceptions\ExceptionInterface) { ... }
|
||||
*/
|
||||
interface ExceptionInterface
|
||||
{
|
||||
}
|
||||
66
system/Exceptions/FrameworkException.php
Normal file
66
system/Exceptions/FrameworkException.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class FrameworkException
|
||||
*
|
||||
* A collection of exceptions thrown by the framework
|
||||
* that can only be determined at run time.
|
||||
*/
|
||||
class FrameworkException extends RuntimeException implements ExceptionInterface
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
public static function forEnabledZlibOutputCompression()
|
||||
{
|
||||
return new static(lang('Core.enabledZlibOutputCompression'));
|
||||
}
|
||||
|
||||
public static function forInvalidFile(string $path)
|
||||
{
|
||||
return new static(lang('Core.invalidFile', [$path]));
|
||||
}
|
||||
|
||||
public static function forCopyError(string $path)
|
||||
{
|
||||
return new static(lang('Core.copyError', [$path]));
|
||||
}
|
||||
|
||||
public static function forMissingExtension(string $extension)
|
||||
{
|
||||
if (strpos($extension, 'intl') !== false) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$message = sprintf(
|
||||
'The framework needs the following extension(s) installed and loaded: %s.',
|
||||
$extension
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
} else {
|
||||
$message = lang('Core.missingExtension', [$extension]);
|
||||
}
|
||||
|
||||
return new static($message);
|
||||
}
|
||||
|
||||
public static function forNoHandlers(string $class)
|
||||
{
|
||||
return new static(lang('Core.noHandlers', [$class]));
|
||||
}
|
||||
|
||||
public static function forFabricatorCreateFailed(string $table, string $reason)
|
||||
{
|
||||
return new static(lang('Fabricator.createFailed', [$table, $reason]));
|
||||
}
|
||||
}
|
||||
28
system/Exceptions/ModelException.php
Normal file
28
system/Exceptions/ModelException.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
/**
|
||||
* Model Exceptions.
|
||||
*/
|
||||
class ModelException extends FrameworkException
|
||||
{
|
||||
public static function forNoPrimaryKey(string $modelName)
|
||||
{
|
||||
return new static(lang('Database.noPrimaryKey', [$modelName]));
|
||||
}
|
||||
|
||||
public static function forNoDateFormat(string $modelName)
|
||||
{
|
||||
return new static(lang('Database.noDateFormat', [$modelName]));
|
||||
}
|
||||
}
|
||||
63
system/Exceptions/PageNotFoundException.php
Normal file
63
system/Exceptions/PageNotFoundException.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
use Config\Services;
|
||||
use OutOfBoundsException;
|
||||
|
||||
class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $code = 404;
|
||||
|
||||
public static function forPageNotFound(?string $message = null)
|
||||
{
|
||||
return new static($message ?? self::lang('HTTP.pageNotFound'));
|
||||
}
|
||||
|
||||
public static function forEmptyController()
|
||||
{
|
||||
return new static(self::lang('HTTP.emptyController'));
|
||||
}
|
||||
|
||||
public static function forControllerNotFound(string $controller, string $method)
|
||||
{
|
||||
return new static(self::lang('HTTP.controllerNotFound', [$controller, $method]));
|
||||
}
|
||||
|
||||
public static function forMethodNotFound(string $method)
|
||||
{
|
||||
return new static(self::lang('HTTP.methodNotFound', [$method]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translated system message
|
||||
*
|
||||
* Use a non-shared Language instance in the Services.
|
||||
* If a shared instance is created, the Language will
|
||||
* have the current locale, so even if users call
|
||||
* `$this->request->setLocale()` in the controller afterwards,
|
||||
* the Language locale will not be changed.
|
||||
*/
|
||||
private static function lang(string $line, array $args = []): string
|
||||
{
|
||||
$lang = Services::language(null, false);
|
||||
|
||||
return $lang->getLine($line, $args);
|
||||
}
|
||||
}
|
||||
25
system/Exceptions/TestException.php
Normal file
25
system/Exceptions/TestException.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception for automatic logging.
|
||||
*/
|
||||
class TestException extends CriticalError
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
public static function forInvalidMockClass(string $name)
|
||||
{
|
||||
return new static(lang('Test.invalidMockClass', [$name]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user