Contract
5 years ago
Exception
5 years ago
InsertNode.php
5 years ago
MoveNode.php
5 years ago
MoveNodeProxy.php
5 years ago
NameCollision.php
5 years ago
RemoveNode.php
5 years ago
WalkNodes.php
5 years ago
MoveNodeProxy.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\FieldCollection; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\FieldCollection; |
| 6 | |
| 7 | /** |
| 8 | * Stores an reference to the node being moved for a fluent API. |
| 9 | * Combines `remove` and `insert*` methods for a declarative API. |
| 10 | */ |
| 11 | class MoveNodeProxy { |
| 12 | |
| 13 | /** @var FieldCollection */ |
| 14 | protected $collection; |
| 15 | |
| 16 | /** @var Node */ |
| 17 | protected $targetNode; |
| 18 | |
| 19 | /** |
| 20 | * @param FieldCollection $collection |
| 21 | */ |
| 22 | public function __construct( FieldCollection &$collection ) { |
| 23 | $this->collection = $collection; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @param Node $node |
| 28 | */ |
| 29 | public function move( $node ) { |
| 30 | $this->targetNode = $node; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param string $name The name of the node after which the target node should be inserted. |
| 35 | */ |
| 36 | public function after( $name ) { |
| 37 | $this->collection->remove( $this->targetNode->getName() ); |
| 38 | $this->collection->insertAfter( $name, $this->targetNode ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @param string $name The name of the node before which the target node should be inserted. |
| 43 | */ |
| 44 | public function before( $name ) { |
| 45 | $this->collection->remove( $this->targetNode->getName() ); |
| 46 | $this->collection->insertBefore( $name, $this->targetNode ); |
| 47 | } |
| 48 | } |
| 49 |