PipeSelector
in package
implements
PipeSelectorInterface
FinalYes
Represents a selector that applies a series of selectors sequentially to a source array view.
$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$selector = new PipeSelector([
new SliceSelector('::2'),
new MaskSelector([true, false, true, true, true]),
new IndexListSelector([0, 1, 2]),
new SliceSelector('1:'),
]);
$view = ArrayView::toView($originalArray);
$subview = $view->subview($selector);
print_r($subview[':']); // [5, 7]
$subview[':'] = [55, 77];
print_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]
Example with nested pipes
$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$selector = new PipeSelector([
new SliceSelector('::2'),
new PipeSelector([
new MaskSelector([true, false, true, true, true]),
new IndexListSelector([0, 1, 2]),
])
new SliceSelector('1:'),
]);
$view = ArrayView::toView($originalArray);
$subview = $view->subview($selector);
print_r($subview[':']); // [5, 7]
$subview[':'] = [55, 77];
print_r($originalArray); // [1, 2, 3, 4, 55, 6, 77, 8, 9, 10]
Table of Contents
Interfaces
- PipeSelectorInterface
- Interface for selector that applies a series of selectors sequentially to a source array view.
Methods
- __construct() : mixed
- Creates a new PipeSelector instance with the provided selectors array.
- compatibleWith() : bool
- Checks if the series of selectors are compatible with the given array view.
- getValue() : array<string|int, ArraySelectorInterface>
- Returns the array of selectors assigned to the PipeSelector.
- select() : ArrayViewInterface<string|int, T>
- Applies the series of selectors to the given source array view.
Methods
__construct()
Creates a new PipeSelector instance with the provided selectors array.
public
__construct(array<string|int, ArraySelectorInterface> $selectors) : mixed
Parameters
- $selectors : array<string|int, ArraySelectorInterface>
-
An array of selectors to be assigned to the PipeSelector.
compatibleWith()
Checks if the series of selectors are compatible with the given array view.
public
compatibleWith(ArrayViewInterface<string|int, T> $view) : bool
Parameters
- $view : ArrayViewInterface<string|int, T>
-
The array view to check compatibility with.
Tags
Return values
bool —True if all selectors are compatible with the array view, false otherwise.
getValue()
Returns the array of selectors assigned to the PipeSelector.
public
getValue() : array<string|int, ArraySelectorInterface>
Return values
array<string|int, ArraySelectorInterface> —The array of selectors.
select()
Applies the series of selectors to the given source array view.
public
select(ArrayViewInterface<string|int, T> $source[, bool|null $readonly = null ]) : ArrayViewInterface<string|int, T>
Parameters
- $source : ArrayViewInterface<string|int, T>
-
The source array view to select from.
- $readonly : bool|null = null
-
Optional parameter to specify if the view should be read-only.
Tags
Return values
ArrayViewInterface<string|int, T> —The resulting array view after applying all selectors.