first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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 implements HasExitCodeInterface
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
public function getExitCode(): int
|
||||
{
|
||||
return EXIT_CONFIG;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forDisabledMigrations()
|
||||
{
|
||||
return new static(lang('Migrations.disabled'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forCannotSetFilePath(string $path)
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetFilepath', [$path]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forCannotSetBinary()
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetBinary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forNotFoundDownloadSource()
|
||||
{
|
||||
return new static(lang('HTTP.notFoundDownloadSource'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forCannotSetCache()
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetCache'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forCannotSetStatusCode(int $code, string $reason)
|
||||
{
|
||||
return new static(lang('HTTP.cannotSetStatusCode', [$code, $reason]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forEnabledZlibOutputCompression()
|
||||
{
|
||||
return new static(lang('Core.enabledZlibOutputCompression'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forInvalidFile(string $path)
|
||||
{
|
||||
return new static(lang('Core.invalidFile', [$path]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forInvalidDirectory(string $path)
|
||||
{
|
||||
return new static(lang('Core.invalidDirectory', [$path]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forCopyError(string $path)
|
||||
{
|
||||
return new static(lang('Core.copyError', [$path]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*
|
||||
* @deprecated 4.5.0 No longer used.
|
||||
*/
|
||||
public static function forMissingExtension(string $extension)
|
||||
{
|
||||
if (str_contains($extension, 'intl')) {
|
||||
// @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forNoHandlers(string $class)
|
||||
{
|
||||
return new static(lang('Core.noHandlers', [$class]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forFabricatorCreateFailed(string $table, string $reason)
|
||||
{
|
||||
return new static(lang('Fabricator.createFailed', [$table, $reason]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Interface for Exceptions that has exception code as HTTP status code.
|
||||
*/
|
||||
interface HTTPExceptionInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Interface for Exceptions that has exception code as exit code.
|
||||
*/
|
||||
interface HasExitCodeInterface
|
||||
{
|
||||
/**
|
||||
* Returns exit status code.
|
||||
*/
|
||||
public function getExitCode(): int;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forNoPrimaryKey(string $modelName)
|
||||
{
|
||||
return new static(lang('Database.noPrimaryKey', [$modelName]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forNoDateFormat(string $modelName)
|
||||
{
|
||||
return new static(lang('Database.noDateFormat', [$modelName]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forMethodNotAvailable(string $modelName, string $methodName)
|
||||
{
|
||||
return new static(lang('Database.methodNotAvailable', [$modelName, $methodName]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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, HTTPExceptionInterface
|
||||
{
|
||||
use DebugTraceableTrait;
|
||||
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $code = 404;
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forPageNotFound(?string $message = null)
|
||||
{
|
||||
return new static($message ?? self::lang('HTTP.pageNotFound'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forEmptyController()
|
||||
{
|
||||
return new static(self::lang('HTTP.emptyController'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forControllerNotFound(string $controller, string $method)
|
||||
{
|
||||
return new static(self::lang('HTTP.controllerNotFound', [$controller, $method]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forMethodNotFound(string $method)
|
||||
{
|
||||
return new static(self::lang('HTTP.methodNotFound', [$method]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forLocaleNotSupported(string $locale)
|
||||
{
|
||||
return new static(self::lang('HTTP.localeNotSupported', [$locale]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function forInvalidMockClass(string $name)
|
||||
{
|
||||
return new static(lang('Test.invalidMockClass', [$name]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user