| 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: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | class RootScope extends Model\Scope |
| 16: | { |
| 17: | |
| 18: | protected $model; |
| 19: | |
| 20: | protected function __construct(array $conditions = []) |
| 21: | { |
| 22: | parent::__construct($conditions, self::AND); |
| 23: | } |
| 24: | |
| 25: | |
| 26: | |
| 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: | |
| 55: | |
| 56: | public static function createAnd(...$conditions) |
| 57: | { |
| 58: | return (parent::class)::createAnd(...$conditions); |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | public static function createOr(...$conditions) |
| 65: | { |
| 66: | return (parent::class)::createOr(...$conditions); |
| 67: | } |
| 68: | } |
| 69: | |