1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace Atk4\Data\Model\Scope;
6:
7: use Atk4\Data\Exception;
8: use Atk4\Data\Model;
9:
10: /**
11: * The root scope object used in the Model::$scope property
12: * All other conditions of the Model object are elements of the root scope
13: * Scope elements are joined always using AND junction.
14: */
15: class RootScope extends Model\Scope
16: {
17: /** @var Model */
18: protected $model;
19:
20: protected function __construct(array $conditions = [])
21: {
22: parent::__construct($conditions, self::AND);
23: }
24:
25: /**
26: * @return $this
27: */
28: public function setModel(Model $model)
29: {
30: $model->assertIsModel();
31:
32: if ($this->model !== $model) {
33: $this->model = $model;
34:
35: $this->onChangeModel();
36: }
37:
38: return $this;
39: }
40:
41: #[\Override]
42: public function getModel(): Model
43: {
44: return $this->model;
45: }
46:
47: #[\Override]
48: public function negate(): self
49: {
50: throw new Exception('Model scope cannot be negated');
51: }
52:
53: /**
54: * @return Model\Scope
55: */
56: public static function createAnd(...$conditions) // @phpstan-ignore-line
57: {
58: return (parent::class)::createAnd(...$conditions);
59: }
60:
61: /**
62: * @return Model\Scope
63: */
64: public static function createOr(...$conditions) // @phpstan-ignore-line
65: {
66: return (parent::class)::createOr(...$conditions);
67: }
68: }
69: