graph-tools-php
58 строк · 1.9 Кб
1<?php
2
3namespace Smoren\GraphTools\Filters;
4
5use Smoren\GraphTools\Conditions\FilterCondition;
6use Smoren\GraphTools\Conditions\Interfaces\FilterConditionInterface;
7use Smoren\GraphTools\Conditions\Interfaces\VertexConditionInterface;
8use Smoren\GraphTools\Conditions\VertexCondition;
9use Smoren\GraphTools\Filters\Interfaces\TraverseFilterInterface;
10use Smoren\GraphTools\Structs\Interfaces\TraverseContextInterface;
11
12/**
13* Constant traverse filter
14* @author Smoren <ofigate@gmail.com>
15*/
16class ConstTraverseFilter extends ConfigurableTraverseFilter implements TraverseFilterInterface
17{
18/**
19* @var FilterConditionInterface|FilterCondition condition of next traverse behavior
20*/
21protected FilterConditionInterface $passCondition;
22/**
23* @var VertexConditionInterface|VertexCondition condition of current vertex handling
24*/
25protected VertexConditionInterface $handleCondition;
26
27/**
28* ConstTraverseFilter constructor
29* @param FilterConditionInterface|null $passCondition condition of next traverse behavior
30* @param VertexConditionInterface|null $handleCondition condition of current vertex handling
31* @param array<int> $config filter config
32*/
33public function __construct(
34?FilterConditionInterface $passCondition = null,
35?VertexConditionInterface $handleCondition = null,
36array $config = []
37) {
38parent::__construct($config);
39$this->passCondition = $passCondition ?? new FilterCondition();
40$this->handleCondition = $handleCondition ?? new VertexCondition();
41}
42
43/**
44* @inheritDoc
45*/
46protected function getDefaultPassCondition(TraverseContextInterface $context): FilterConditionInterface
47{
48return $this->passCondition;
49}
50
51/**
52* @inheritDoc
53*/
54protected function getDefaultHandleCondition(TraverseContextInterface $context): VertexConditionInterface
55{
56return $this->handleCondition;
57}
58}
59