Skip to content

Commit b7433ab

Browse files
Merge pull request #12 from codenamephp/feature/8-add-within-to-deployer-functions
Added within method
2 parents de4f074 + dccfef7 commit b7433ab

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

MIGRATION.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
## 2.x -> 3.x
44

5+
### Before Method
6+
57
The iAll interface was extended with the iBefore interface. If you created your own implementation of iAll you need to implement the iBefore interface as well.
68
If you use the All class you don't need to do anything.
79

10+
### Within Method
11+
12+
The iAll interface was extended with the iWithin interface. If you created your own implementation of iAll you need to implement the iWithin interface as well.
13+
If you use the All class you don't need to do anything.
14+
815
## 1.x -> 2.x
916

1017
The ssh connection string is now part of `\Deployer\Host\Host`. This means the

src/functions/All.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use function Deployer\runLocally;
4343
use function Deployer\set;
4444
use function Deployer\upload;
45+
use function Deployer\within;
4546

4647
/**
4748
* Implements all method interfaces so we a "all drop-in" class to easily access the methods
@@ -169,4 +170,8 @@ public function registerTask(iTaskWithName $task) : void {
169170
public function upload(string $source, string $destination, array $config = []) : void {
170171
upload($source, $destination, $config);
171172
}
173+
174+
public function within(string $path, callable $callback) : mixed {
175+
return within($path, $callback);
176+
}
172177
}

src/functions/iAll.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
*
2323
* The idea is to provide a stable, typed API and also a level of abstraction to the global deployer functions so testing is easier.
2424
*/
25-
interface iAll extends iAdd, iAfter, iBefore, iCurrentHost, iDownload, iGet, iHost, iInput, iLocalhost, iOn, iParse, iRun, iSet, iTask, iUpload {
25+
interface iAll extends iAdd, iAfter, iBefore, iCurrentHost, iDownload, iGet, iHost, iInput, iLocalhost, iOn, iParse, iRun, iSet, iTask, iUpload, iWithin {
2626

2727
}

src/functions/iWithin.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deployer\base\functions;
19+
20+
/**
21+
* Interface for the Deployer\within function
22+
*/
23+
interface iWithin {
24+
25+
/**
26+
* Execute a callback within a specific directory and revert back to the initial working directory.
27+
*
28+
* @param string $path The path to execute the callback in
29+
* @param callable():mixed $callback The callback to execute. No parameters and the return value is returned by this function
30+
* @return mixed|null Return value of the $callback function or null if callback throws an exception
31+
*/
32+
public function within(string $path, callable $callback) : mixed;
33+
}

0 commit comments

Comments
 (0)