### XML Pipeline Configuration Example Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md An example of a typical pipeline configuration using XML. This format is clear for understanding pipeline structure and can be edited by non-developers. ```xml example vValue another example value outputParam1 outParam1 hello world finalOutput ``` -------------------------------- ### Key Path Example (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Demonstrates using a 'keypath' reference to extract a nested structure from a context parameter. The path 'data.2.attributes.details' is resolved within the 'decoded_payload' context. ```xml decoded_payload ``` -------------------------------- ### Context Reference Example (Programmatic) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Illustrates the programmatic equivalent of using context references. A ReferenceStageSetting is created to inject the 'raw_json' context parameter. ```php use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSettingType; $config->addSetting(new ReferenceStageSetting( ReferenceStageSettingType::plain, 'jsonString', 'raw_json' )); ``` -------------------------------- ### String Placeholder Example Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Demonstrates how string placeholders are resolved within XML parameters. The %%user_name%% placeholder is replaced with the corresponding context entry. ```xml Hello %%user_name%%! ``` -------------------------------- ### Array and List Manipulation Examples Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Provides examples of extracting nested arrays, capturing the last element of a list, and building strings from array data using placeholders. ```xml feed ``` ```xml recent_imports ``` ```xml Item %%currentItem[id]%% has status %%currentItem[status]%% ``` -------------------------------- ### Install Pipeflow using Composer Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Install the Pipeflow library into your project using Composer. This command adds the package and sets up autoloading. ```bash composer require marcosiino/pipeflow ``` -------------------------------- ### Literal Array Configuration Example Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Shows how to pass literal arrays from XML to a stage configuration. The `` elements are preserved as a PHP array. ```xml pending processing completed ``` -------------------------------- ### Context Reference Example (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Shows how to reference a context parameter using the 'contextReference' attribute in XML. The 'plain' type injects the entire value of the 'raw_json' context parameter. ```xml raw_json ``` -------------------------------- ### Execute a Pipeline from XML Configuration Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Register stages, create a Pipeline instance, load configuration from an XML file using setupWithXML, and then execute the pipeline. The result contains the processed context. ```php use Marcosiino\Pipeflow\Core\Pipeline; use Marcosiino\Pipeflow\PipeFlow; PipeFlow::registerStages(); $pipeline = new Pipeline(); $xml = file_get_contents('pipeline.xml'); $pipeline->setupWithXML($xml); // Validates against the bundled XSD, instantiates and configures the stages //... $result = $pipeline->execute(); $result //is contains the processed context with all the context parameters set by the pipeline ``` -------------------------------- ### Hello World Pipeline with XML Configuration Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md This snippet shows how to load and execute a pipeline defined in an XML file. The XML configuration must be validated. ```xml raw_json {"message":"Hello Pipeflow"} raw_json data ``` ```php $xml = file_get_contents('hello_pipeline.xml'); $pipeline = new Pipeline(); PipeFlow::registerStages(); $pipeline->setupWithXML($xml); $pipeline->execute(); ``` -------------------------------- ### Hello World Pipeline with Fluent PHP API Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md This snippet demonstrates setting a JSON string and then decoding it using the fluent PHP API. Ensure all necessary Pipeflow classes are imported. ```php use Marcosiino\Pipeflow\Core\Pipeline; use Marcosiino\Pipeflow\Core\PipelineContext; use Marcosiino\Pipeflow\Core\StageConfiguration\StageConfiguration; use Marcosiino\Pipeflow\Core\StageConfiguration\StageSetting; use Marcosiino\Pipeflow\Core\StageFactory; use Marcosiino\Pipeflow\PipeFlow; PipeFlow::registerStages(); $pipeline = new Pipeline(new PipelineContext()); // Stage 1: SetValue $setConfig = new StageConfiguration(); $setConfig->addSetting(new StageSetting('parameterName', 'raw_json')); $setConfig->addSetting(new StageSetting('parameterValue', '{"message":"Hello Pipeflow"}')); $pipeline->addStage(StageFactory::instantiateStageOfType('SetValue', $setConfig)); // Stage 2: JSONDecode $decodeConfig = new StageConfiguration(); $decodeConfig->addSetting(new StageSetting('jsonString', '%%raw_json%%')); $decodeConfig->addSetting(new StageSetting('resultTo', 'data')); $pipeline->addStage(StageFactory::instantiateStageOfType('JSONDecode', $decodeConfig)); $resultContext = $pipeline->execute(); var_dump($resultContext->getParameter('data')['message']); // "Hello Pipeflow" ``` -------------------------------- ### Configure SumOperation Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md PHP configuration for the SumOperation stage, defining operands and the result destination. Note the use of ReferenceStageSetting for operandA. ```php use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSettingType; $config = new StageConfiguration(); $config->addSetting(new ReferenceStageSetting( ReferenceStageSettingType::plain, 'operandA', 'line_totals' )); $config->addSetting(new StageSetting('operandB', '%%currentItem[price]%%')); $config->addSetting(new StageSetting('resultTo', 'line_totals')); $stage = StageFactory::instantiateStageOfType('SumOperation', $config); ``` -------------------------------- ### Programmatically Configure a Pipeline with Stages Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Instantiate a Pipeline, register stages, add configurations for stages like ArrayCount, and execute the pipeline. This method offers full control and dynamic wiring. ```php use Marcosiino\Pipeflow\PipeFlow; use Marcosiino\Pipeflow\Core\Pipeline; use Marcosiino\Pipeflow\Core\StageFactory; use Marcosiino\Pipeflow\Core\StageConfiguration\StageConfiguration; use Marcosiino\Pipeflow\Core\StageConfiguration\StageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSettingType; $pipeline = new Pipeline(); PipeFlow::registerStages(); // Seed the context with data by setting a context parameter order_ids with an array of order ids $pipeline->getCurrentContext()->setParameter('order_ids', [101, 102, 103]); // Use the ArrayCount stage to count the items of the array by storing the count in the orders_count context parameter $countConfig = new StageConfiguration(); $countConfig->addSetting(new StageSetting('arrayParameterName', 'order_ids')); $countConfig->addSetting(new StageSetting('resultTo', 'orders_count')); $pipeline->addStage(StageFactory::instantiateStageOfType('ArrayCount', $countConfig)); $output_context = $pipeline->execute(); //$output_context will contain the following context parameters: order_ids and order_counts ``` -------------------------------- ### WPFetchPostsStageFactory Implementation Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Implements AbstractStageFactory to instantiate WPFetchPostsStage and define its descriptor. Decouples stage instantiation and defines requirements. ```php use Marcosiino\Pipeflow\Interfaces\AbstractStageFactory; use Marcosiino\Pipeflow\Core\StageDescriptor; use Marcosiino\Pipeflow\Core\StageConfiguration\StageConfiguration; class WPFetchPostsStageFactory implements AbstractStageFactory { public function instantiate(StageConfiguration $configuration): AbstractPipelineStage { return new WPFetchPostsStage($configuration); } public function getStageDescriptor(): StageDescriptor { return new StageDescriptor( 'WPFetchPosts', 'Load posts from WordPress using get_posts()', ['status' => 'Optional post status filter.'], [], ['wp_posts' => 'List of WP_Post objects returned by get_posts()'] ); } } ``` -------------------------------- ### WPFetchPostsStage Implementation Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Extends AbstractPipelineStage to fetch WordPress posts based on configuration. Accepts StageConfiguration and returns a mutated PipelineContext. ```php use Marcosiino\Pipeflow\Interfaces\AbstractPipelineStage; use Marcosiino\Pipeflow\Core\StageConfiguration\StageConfiguration; use Marcosiino\Pipeflow\Core\PipelineContext; class WPFetchPostsStage extends AbstractPipelineStage { private StageConfiguration $config; public function __construct(StageConfiguration $config) { $this->config = $config; } public function execute(PipelineContext $context): PipelineContext { $status = $this->config->getSettingValue('status', $context, false, 'publish'); $posts = get_posts(['post_status' => $status]); // ... $context->setParameter('wp_posts', $posts); return $context; } } ``` -------------------------------- ### Configure Delay Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Instantiate the Delay stage in PHP, optionally setting the duration in milliseconds. Defaults to 1000ms if not specified. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('milliseconds', 500)); $stage = StageFactory::instantiateStageOfType('Delay', $config); ``` -------------------------------- ### Configure ExplodeString Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Instantiate and configure the ExplodeString stage in PHP, providing the input string, separator, and the key for the resulting array. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('inputString', 'tag1,tag2,tag3')); $config->addSetting(new StageSetting('separator', ',')); $config->addSetting(new StageSetting('resultTo', 'tags')); $stage = StageFactory::instantiateStageOfType('ExplodeString', $config); ``` -------------------------------- ### Configure RandomValue Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md PHP configuration for the RandomValue stage, setting the destination parameter name and optional min/max values. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('parameterName', 'captcha_seed')); $config->addSetting(new StageSetting('minValue', 100000)); $config->addSetting(new StageSetting('maxValue', 999999)); $stage = StageFactory::instantiateStageOfType('RandomValue', $config); ``` -------------------------------- ### Configure ArrayPath Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Instantiate and configure the ArrayPath stage in PHP, setting the array source, dot-notation path, and result key. ```php use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSettingType; $config = new StageConfiguration(); $config->addSetting(new ReferenceStageSetting( ReferenceStageSettingType::plain, 'array', 'decoded_payload' )); $config->addSetting(new StageSetting('path', 'data.0.attributes.details')); $config->addSetting(new StageSetting('resultTo', 'first_details')); $stage = StageFactory::instantiateStageOfType('ArrayPath', $config); ``` -------------------------------- ### Configure ArrayCount Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Use PHP to instantiate and configure the ArrayCount stage, setting the array parameter name and the result key. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('arrayParameterName', 'orders')); $config->addSetting(new StageSetting('resultTo', 'orders_count')); $stage = StageFactory::instantiateStageOfType('ArrayCount', $config); ``` -------------------------------- ### Configure Delay Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Set up the Delay stage in XML to pause the pipeline for a specified number of milliseconds. ```xml 500 ``` -------------------------------- ### Minimal XML Pipeline Configuration Source: https://github.com/marcosiino/pipeflow-php/blob/main/README.md Defines a basic pipeline with 'SetValue' and 'Echo' stages. This configuration can be managed without touching PHP code. ```xml message Hello Pipeflow! %%message%% ``` -------------------------------- ### Configure ArrayPath Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configure the ArrayPath stage using XML to specify the array, path, and result destination. ```xml decoded_payload data.0.attributes.details first_details ``` -------------------------------- ### For Stage Configuration (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configures a For stage in XML for a classic counted loop. Specify 'from', 'to', and 'step' to control the iteration range. The loop index is available in the context. ```xml 0 orders_count 1 loop_index last_index %%loop_index%% ``` -------------------------------- ### Configure ExplodeString Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configure the ExplodeString stage using XML to split a string into an array based on a separator. ```xml tag1,tag2,tag3 , tags ``` -------------------------------- ### ForEach Stage Configuration (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configures a ForEach stage in PHP. This allows for iterating over a collection and executing a block of sub-stages for each item. ```php use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSettingType; $forEachConfig = new StageConfiguration(); $forEachConfig->addSetting(new ReferenceStageSetting( ReferenceStageSettingType::plain, 'collection', 'products' )); $forEachStage = StageFactory::instantiateStageOfType('ForEach', $forEachConfig); $forEachStage->addSubStagesBlock('do', [$processProductStage]); $pipeline->addStage($forEachStage); ``` -------------------------------- ### Configure SumOperation Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md XML configuration for the SumOperation stage to add or merge two operands and store the result. ```xml line_totals %%currentItem[price]%% line_totals ``` -------------------------------- ### Configure SetValue Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md PHP configuration for the SetValue stage, specifying the parameter name and the value to be stored. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('parameterName', 'status')); $config->addSetting(new StageSetting('parameterValue', 'active')); $stage = StageFactory::instantiateStageOfType('SetValue', $config); ``` -------------------------------- ### ForEach Stage Configuration (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configures a ForEach stage in XML to iterate over a collection. Use this to process each item in an array, with `currentItem` and `currentItem_index` available in the context. ```xml products last_product_id %%currentItem[id]%% ``` -------------------------------- ### Configure JSONDecode Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Instantiate and configure the JSONDecode stage in PHP, setting the JSON string and the destination key for the associative array. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('jsonString', '%%raw_json%%')); $config->addSetting(new StageSetting('resultTo', 'payload')); $stage = StageFactory::instantiateStageOfType('JSONDecode', $config); ``` -------------------------------- ### Configure ArrayCount Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Use XML to configure the ArrayCount stage, specifying the array parameter name and the context key for the result. ```xml orders orders_count ``` -------------------------------- ### Configure SetValue Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md XML configuration for the SetValue stage to store a fixed value into the context. ```xml status active ``` -------------------------------- ### Configure JSONEncode Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Instantiate and configure the JSONEncode stage in PHP, specifying the associative array to encode and the context key for the resulting JSON string. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('associativeArray', 'payload')); $config->addSetting(new StageSetting('resultTo', 'payload_json')); $stage = StageFactory::instantiateStageOfType('JSONEncode', $config); ``` -------------------------------- ### If Stage Configuration (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configures an If stage in XML to conditionally execute 'then' or 'else' blocks based on a comparison. Use this for branching logic in your pipeline. ```xml orders_count greater 0 status Processing status Idle ``` -------------------------------- ### Configure RandomArrayItem Stage (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Use PHP to configure the RandomArrayItem stage, specifying the array parameter name and the result key. ```php $config = new StageConfiguration(); $config->addSetting(new StageSetting('arrayParameterName', 'products')); $config->addSetting(new StageSetting('resultTo', 'featured_product')); $stage = StageFactory::instantiateStageOfType('RandomArrayItem', $config); ``` -------------------------------- ### For Stage Configuration (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configures a For stage in PHP for a counted loop. This allows for executing a block of sub-stages a specific number of times, with the current index accessible. ```php use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSettingType; $forConfig = new StageConfiguration(); $forConfig->addSetting(new StageSetting('from', 0)); $forConfig->addSetting(new ReferenceStageSetting( ReferenceStageSettingType::plain, 'to', 'orders_count' )); $forConfig->addSetting(new StageSetting('step', 1)); $forConfig->addSetting(new StageSetting('indexParameterName', 'loop_index')); $forStage = StageFactory::instantiateStageOfType('For', $forConfig); $forStage->addSubStagesBlock('do', [$someStage]); $pipeline->addStage($forStage); ``` -------------------------------- ### Configure JSONDecode Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Use XML to configure the JSONDecode stage, specifying the JSON string source and the context key for the decoded array. ```xml raw_json payload ``` -------------------------------- ### If Stage Configuration (PHP) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configures an If stage in PHP using the PipeFlow library. This allows for programmatic conditional execution of sub-stages. ```php use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSetting; use Marcosiino\Pipeflow\Core\StageConfiguration\ReferenceStageSettingType; $ifConfig = new StageConfiguration(); $ifConfig->addSetting(new ReferenceStageSetting( ReferenceStageSettingType::plain, 'leftOperand', 'orders_count' )); $ifConfig->addSetting(new StageSetting('operator', 'greater')); $ifConfig->addSetting(new StageSetting('rightOperand', '0')); $ifStage = StageFactory::instantiateStageOfType('If', $ifConfig); $ifStage->addSubStagesBlock('then', [$approveStage]); $ifStage->addSubStagesBlock('else', [$fallbackStage]); $pipeline->addStage($ifStage); ``` -------------------------------- ### Configure RandomArrayItem Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Use XML to configure the RandomArrayItem stage to pick a random element from an array parameter. ```xml products featured_product ``` -------------------------------- ### Configure JSONEncode Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Configure the JSONEncode stage using XML to convert an associative array to a JSON string. ```xml payload payload_json ``` -------------------------------- ### Configure RandomValue Stage (XML) Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md XML configuration for the RandomValue stage to generate a random number within a specified range. ```xml captcha_seed 100000 999999 ``` -------------------------------- ### Registering a Custom Stage Factory Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Registers a custom stage factory with the StageFactory. This makes the custom stage available for use in pipelines. ```php use Marcosiino\Pipeflow\Core\StageFactory; StageFactory::registerFactory(new WPFetchPostsStageFactory()); ``` -------------------------------- ### Register Pipeflow Stages Source: https://github.com/marcosiino/pipeflow-php/blob/main/DOCUMENTATION.md Register all available stage factories for Pipeflow. This must be called before instantiating or parsing any pipeline. ```php use Marcosiino\Pipeflow\PipeFlow; PipeFlow::registerStages(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.