-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from stellarwp/fix/ip-address-push-pull
Better management of on-up callbacks
- Loading branch information
Showing
6 changed files
with
164 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace StellarWP\Slic; | ||
|
||
class Callback_Stack { | ||
/** | ||
* A set of callbacks accumulated in the stack so far, by | ||
* priority. | ||
* | ||
* @var array<string,callable> | ||
*/ | ||
private $callbacks = []; | ||
|
||
public function call(): void { | ||
foreach ( $this->callbacks as $callback_id => $callback ) { | ||
$callback(); | ||
|
||
// Remove the callback from the stack after it has been called. | ||
$this->remove( $callback_id ); | ||
} | ||
} | ||
|
||
/** | ||
* Add a callback to the stack, with a specified priority. | ||
* | ||
* @param string $callback_id The callback ID. | ||
* @param callable $callback The callback to add. | ||
* | ||
* @return void The callback is added to the stack. | ||
*/ | ||
public function add( string $callback_id, callable $callback ): void { | ||
$this->callbacks[ $callback_id ] = $callback; | ||
} | ||
|
||
/** | ||
* Remove a callback from the stack. | ||
* | ||
* @param string $callback_id The callback ID. | ||
* | ||
* @return void The callback is removed from the stack. | ||
*/ | ||
private function remove( $callback_id ) { | ||
unset( $this->callbacks[ $callback_id ] ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* Provides functions for container notifications. | ||
*/ | ||
|
||
namespace StellarWP\Slic; | ||
|
||
function service_wordpress_notify() { | ||
echo colorize( PHP_EOL . "Your WordPress site is reachable at: <yellow>http://localhost:" . getenv( 'WORDPRESS_HTTP_PORT' ) . "</yellow>" . PHP_EOL ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.