From 1ec2e45497f234610c9bcff0d533fe8e1fca99f8 Mon Sep 17 00:00:00 2001 From: Michael Reichardt <30837295+reimic@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:22:50 +0100 Subject: [PATCH] Add new Blueprint examples (#68) - 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. --- README.md | 12 +++- .../blueprint_compiling.php | 12 ++-- examples/json_string_compiling.php | 60 +++++++++++++++++++ 3 files changed, 75 insertions(+), 9 deletions(-) rename blueprint_compiling.php => examples/blueprint_compiling.php (93%) create mode 100644 examples/json_string_compiling.php diff --git a/README.md b/README.md index d0282496..92fb07c1 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,18 @@ composer install vendor/bin/phpunit --testdox ``` -### Run a Blueprint with +### Run Blueprints in a variety of ways + +#### using the PHP Blueprint builder: + +```shell + php examples/blueprint_compiling.php +``` + +#### using a string containg a Blueprint (in JSON): ```shell -php blueprint_compiling.php + php examples/json_string_compiling.php ``` ### Regenerate models files from JSON schema with diff --git a/blueprint_compiling.php b/examples/blueprint_compiling.php similarity index 93% rename from blueprint_compiling.php rename to examples/blueprint_compiling.php index a8082860..98686598 100644 --- a/blueprint_compiling.php +++ b/examples/blueprint_compiling.php @@ -38,10 +38,10 @@ // ->withContent( 'https://raw.githubusercontent.com/WordPress/theme-test-data/master/themeunittestdata.wordpress.xml' ) ->withSiteUrl( 'http://localhost:8081' ) ->andRunSQL( <<<'SQL' - CREATE TABLE `tmp_table` ( id INT ); - INSERT INTO `tmp_table` VALUES (1); - INSERT INTO `tmp_table` VALUES (2); - SQL +CREATE TABLE `tmp_table` ( id INT ); +INSERT INTO `tmp_table` VALUES (1); +INSERT INTO `tmp_table` VALUES (2); +SQL ) ->withFile( 'wordpress.txt', 'Data' ) ->toBlueprint(); @@ -54,7 +54,7 @@ public static function getSubscribedEvents() { ]; } - protected ProgressBar $progress_bar; + protected $progress_bar; public function __construct() { ProgressBar::setFormatDefinition( 'custom', ' [%bar%] %current%/%max% -- %message%' ); @@ -84,5 +84,3 @@ public function onDone( DoneEvent $event ) { 'progressSubscriber' => $subscriber, ] ); - -//var_dump( $results ); diff --git a/examples/json_string_compiling.php b/examples/json_string_compiling.php new file mode 100644 index 00000000..012426a0 --- /dev/null +++ b/examples/json_string_compiling.php @@ -0,0 +1,60 @@ + '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, + ) +);