PHP code example of xervice / processor

1. Go to this page and download the library: Download xervice/processor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xervice / processor example snippets


    /**
     * @return \Xervice\Processor\Business\Model\InputHandler\InputHandlerInterface
     */
    public function getInputHandler(): InputHandlerInterface
    {
        return new RawJsonFileRowInputHandler();
    }

    /**
     * @return \Xervice\Validator\Business\Dependency\ValidatorConfigurationProviderPluginInterface[]
     */
    public function getValidatorConfigurationPlugins(): array
    {
        return [
            new TestValidator()
        ];
    }

    class TestValidator implements ValidatorConfigurationProviderPluginInterface
    {
        /**
         * @return array
         */
        public function getValidatorConfiguration(): array
        {
            return [
                [
                    'test' => [
                        '

    /**
     * @return \Xervice\Processor\Business\Dependency\ProcessHydratorPluginInterface[]
     */
    public function getHydratorPlugins(): array
    {
        return [
            new TestHydrator()
        ];
    }

class TestHydrator implements ProcessHydratorPluginInterface
{
    /**
     * @return array
     */
    public function getHydratorConfiguration(): array
    {
        return [
            [
                'newValues' => function (array $payload) {
                    return [
                        [
                            $payload['test'][0]
                        ],
                        [
                            $payload['test'][1]
                        ]
                    ];
                },
                'test'
            ]
        ];
    }
}

    /**
     * @return \Xervice\Processor\Business\Dependency\ProcessTranslationPluginInterface[]
     */
    public function getTranslatorPlugins(): array
    {
        return [
            new TestTranslator()
        ];
    }

class TestTranslator implements ProcessTranslationPluginInterface
{
    /**
     * @return array
     */
    public function getTranslationConfiguration(): array
    {
        return [
            [
                'TestTranslator',
                'TestTranslator' => [
                    'field' => 'transOne',
                    'source' => 'newValues'
                ],
                'transTwo' => function (array $payload) {
                    return $payload['transOne'] ?? null;
                }
            ]
        ];
    }
}

use Xervice\Processor\Business\Model\Translator\TranslatorInterface;

class TestTranslatorFunction implements TranslatorInterface
{
    /**
     * @return string
     */
    public function getName(): string
    {
        return 'TestTranslator';
    }

    /**
     * @param array $payload
     * @param array $options
     *
     * @return array
     */
    public function translate(array $payload, array $options = null): array
    {
        if (!isset($payload['isTranslated'])) {
            $payload['isTranslated'] = 0;
        }

        $payload['isTranslated']++;

        if (is_array($options)) {
            $payload[$options['field']] = $payload[$options['source']];
        }

        return $payload;
    }

}

class ProcessorDependencyProvider extends \Xervice\Processor\ProcessorDependencyProvider
{
    /**
     * @return \Xervice\Processor\Business\Dependency\ProcessConfigurationPluginInterface[]
     */
    protected function getProcessConfigurationPlugins(): array
    {
        return [
            new ProcessConfiguration()
        ];
    }

    /**
     * @return \Xervice\Processor\Business\Model\Translator\TranslatorInterface[]
     */
    protected function getTranslatorFunctions(): array
    {
        return [
            new TestTranslatorFunction()
        ];
    }
}

    /**
     * @param array $data
     *
     * @return array
     */
    public function process(array $data): array
    {
        $data['isProcessed'] = true;
        // $this->getFacade()->processYourOwnData($data);

        return $data;
    }

    /**
     * @return \Xervice\Processor\Business\Model\OutputHandler\OutputHandlerInterface
     */
    public function getOutputHandler(): OutputHandlerInterface
    {
        return new RawJsonFileOutputHandler();
    }

$processConfig = (new ProcessRunDataProvider())
   ->setName('YOUR_PROCESS_PROCESS')
   ->setInput('input')
   ->setOutput('output');

$processorFacade->runProcess($processConfig);