Debian Codegraph @

vendor/ipl/orm/src/Exception/InvalidRelationException.php

raw
1 <?php
2
3 namespace ipl\Orm\Exception;
4
5 use Exception;
6 use ipl\Orm\Model;
7
8 class InvalidRelationException extends Exception
9 {
10 /** @var string The relation name */
11 protected string $relation;
12
13 /** @var ?Model The target model */
14 protected ?Model $model = null;
15
16 /**
17 * Create a new InvalidRelationException
18 *
19 * @param string $relation The relation name
20 * @param ?Model $model The target model
21 */
22 public function __construct(string $relation, ?Model $model = null)
23 {
24 $this->relation = $relation;
25 $this->model = $model;
26
27 parent::__construct(sprintf(
28 'Cannot join relation "%s"%s. Relation not found.',
29 $relation,
30 $model ? ' in model ' . get_class($model) : ''
31 ));
32 }
33
34 /**
35 * Get the relation name
36 *
37 * @return string
38 */
39 public function getRelation(): string
40 {
41 return $this->relation;
42 }
43
44 /**
45 * Get the target model
46 *
47 * @return ?Model
48 */
49 public function getModel(): ?Model
50 {
51 return $this->model;
52 }
53 }