123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- declare(strict_types=1);
- /**
- * This file is part of Hyperf.
- *
- * @link https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact group@hyperf.io
- * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
- namespace Hyperf\Database\Model;
- use RuntimeException;
- class JsonEncodingException extends RuntimeException
- {
- /**
- * Create a new JSON encoding exception for the model.
- *
- * @param string $message
- * @param mixed $model
- * @return static
- */
- public static function forModel($model, $message)
- {
- return new static('Error encoding model [' . get_class($model) . '] with ID [' . $model->getKey() . '] to JSON: ' . $message);
- }
- /**
- * Create a new JSON encoding exception for an attribute.
- *
- * @param string $message
- * @param mixed $model
- * @param mixed $key
- * @return static
- */
- public static function forAttribute($model, $key, $message)
- {
- $class = get_class($model);
- return new static("Unable to encode attribute [{$key}] for model [{$class}] to JSON: {$message}.");
- }
- }
|