This commit is contained in:
Markus
2022-04-28 09:40:10 +02:00
commit 795794f992
9586 changed files with 1146991 additions and 0 deletions

View 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
{
}

View 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'));
}
}
}

View 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'));
}
}

View 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
{
}

View 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;
}
}
}

View 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]));
}
}

View 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
{
}

View 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
{
}

View 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]));
}
}

View 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]));
}
}

View 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);
}
}

View 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]));
}
}