-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds a script - json_string_compiling.php running the Blueprint from a string containing a JSON. - Creates the 'examples' directory to group all nonessential scrips added to showcase the lib's capabilities. - Moves the blueprint_compiling.php script to the 'examples' directory. - Fixes scrips to run with PHP >= 7.0.
- Loading branch information
Showing
3 changed files
with
75 additions
and
9 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
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,60 @@ | ||
<?php | ||
|
||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Input\StringInput; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use WordPress\Blueprints\ContainerBuilder; | ||
use WordPress\Blueprints\Progress\DoneEvent; | ||
use WordPress\Blueprints\Progress\ProgressEvent; | ||
use function WordPress\Blueprints\run_blueprint; | ||
|
||
if ( getenv( 'USE_PHAR' ) ) { | ||
require __DIR__ . '/dist/blueprints.phar'; | ||
} else { | ||
require 'vendor/autoload.php'; | ||
} | ||
|
||
$blueprint = '{"WordPressVersion":"https://wordpress.org/latest.zip","steps":[{"step":"mkdir","path":"dir"},{"step": "rm","path": "dir"}]}'; | ||
|
||
$subscriber = new class() implements EventSubscriberInterface { | ||
public static function getSubscribedEvents() { | ||
return array( | ||
ProgressEvent::class => 'onProgress', | ||
DoneEvent::class => 'onDone', | ||
); | ||
} | ||
|
||
protected $progress_bar; | ||
|
||
public function __construct() { | ||
ProgressBar::setFormatDefinition( 'custom', ' [%bar%] %current%/%max% -- %message%' ); | ||
|
||
$this->progress_bar = ( new SymfonyStyle( | ||
new StringInput( '' ), | ||
new ConsoleOutput() | ||
) )->createProgressBar( 100 ); | ||
$this->progress_bar->setFormat( 'custom' ); | ||
$this->progress_bar->setMessage( 'Start' ); | ||
$this->progress_bar->start(); | ||
} | ||
|
||
public function onProgress( ProgressEvent $event ) { | ||
$this->progress_bar->setMessage( $event->caption ); | ||
$this->progress_bar->setProgress( (int) $event->progress ); | ||
} | ||
|
||
public function onDone( DoneEvent $event ) { | ||
$this->progress_bar->finish(); | ||
} | ||
}; | ||
|
||
$results = run_blueprint( | ||
$blueprint, | ||
array( | ||
'environment' => ContainerBuilder::ENVIRONMENT_NATIVE, | ||
'documentRoot' => __DIR__ . '/new-wp', | ||
'progressSubscriber' => $subscriber, | ||
) | ||
); |