| @@ 24-62 (lines=39) @@ | ||
| 21 | use Graze\DataNode\NodeInterface; |
|
| 22 | use InvalidArgumentException; |
|
| 23 | ||
| 24 | class CopyFile extends Transfer implements FlowInterface |
|
| 25 | { |
|
| 26 | use InvokeTrait; |
|
| 27 | ||
| 28 | /** |
|
| 29 | * @var FileNodeInterface |
|
| 30 | */ |
|
| 31 | private $target; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * CopyFile constructor. |
|
| 35 | * |
|
| 36 | * @param FileNode $target |
|
| 37 | */ |
|
| 38 | public function __construct(FileNode $target) |
|
| 39 | { |
|
| 40 | $this->target = $target; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @param NodeInterface $node |
|
| 45 | * |
|
| 46 | * @return FileNode |
|
| 47 | */ |
|
| 48 | public function flow(NodeInterface $node) |
|
| 49 | { |
|
| 50 | if (!($node instanceof FileNode)) { |
|
| 51 | throw new InvalidArgumentException("Node: $node should be an instance of FileNode"); |
|
| 52 | } |
|
| 53 | ||
| 54 | if (substr($this->target->getPath(), -1) == '/') { |
|
| 55 | $target = $this->target->getClone()->setPath($this->target->getPath() . $node->getFilename()); |
|
| 56 | } else { |
|
| 57 | $target = $this->target; |
|
| 58 | } |
|
| 59 | ||
| 60 | return $this->copyTo($node, $target); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| @@ 23-61 (lines=39) @@ | ||
| 20 | use Graze\DataNode\NodeInterface; |
|
| 21 | use InvalidArgumentException; |
|
| 22 | ||
| 23 | class MoveFile extends Transfer implements FlowInterface |
|
| 24 | { |
|
| 25 | use InvokeTrait; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @var FileNode |
|
| 29 | */ |
|
| 30 | private $target; |
|
| 31 | ||
| 32 | /** |
|
| 33 | * CopyFile constructor. |
|
| 34 | * |
|
| 35 | * @param FileNode $target |
|
| 36 | */ |
|
| 37 | public function __construct(FileNode $target) |
|
| 38 | { |
|
| 39 | $this->target = $target; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @param NodeInterface $node |
|
| 44 | * |
|
| 45 | * @return FileNode |
|
| 46 | */ |
|
| 47 | public function flow(NodeInterface $node) |
|
| 48 | { |
|
| 49 | if (!($node instanceof FileNode)) { |
|
| 50 | throw new InvalidArgumentException("Node: $node should be an instance of FileNode"); |
|
| 51 | } |
|
| 52 | ||
| 53 | if (substr($this->target->getPath(), -1) == '/') { |
|
| 54 | $target = $this->target->getClone()->setPath($this->target->getPath() . $node->getFilename()); |
|
| 55 | } else { |
|
| 56 | $target = $this->target; |
|
| 57 | } |
|
| 58 | ||
| 59 | return $this->moveTo($node, $target); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||