Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Task/File/FileReaderTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php declare(strict_types=1);
/*
* This file is part of the CleverAge/ProcessBundle package.
*
* Copyright (C) 2017-2019 Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\ProcessBundle\Task\File;

use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
use CleverAge\ProcessBundle\Model\ProcessState;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Read the whole file and output its content
*
* @todo Provide additional safeguards like if file exists and is readable
*
* @author Vincent Chalnot <[email protected]>
*/
class FileReaderTask extends AbstractConfigurableTask
{
/**
* @param ProcessState $state
*
* @throws ExceptionInterface
* @throws IOException
*/
public function execute(ProcessState $state)
{
$options = $this->getOptions($state);

$state->setOutput(file_get_contents($options['filename']));
}

/**
* @param OptionsResolver $resolver
*
* @throws AccessException
* @throws UndefinedOptionsException
*/
protected function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(
[
'filename',
]
);
$resolver->setAllowedTypes('filename', ['string']);
}
}
1 change: 1 addition & 0 deletions Task/FilterTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function execute(ProcessState $state)
{
$input = $state->getInput();
if (!$this->checkCondition($input, $this->getOptions($state))) {
$state->setErrorOutput($input);
$state->setSkipped(true);

return;
Expand Down
56 changes: 56 additions & 0 deletions Transformer/CastTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php declare(strict_types=1);
/*
* This file is part of the CleverAge/ProcessBundle package.
*
* Copyright (C) 2017-2019 Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\ProcessBundle\Transformer;

use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Cast a value to a different PHP type
*
* @author Valentin Clavreul <[email protected]>
* @author Vincent Chalnot <[email protected]>
*/
class CastTransformer implements ConfigurableTransformerInterface
{
/**
* {@inheritdoc}
*/
public function transform($value, array $options = [])
{
settype($value, $options['type']);

return $value;
}

/**
* {@inheritdoc}
*/
public function getCode()
{
return 'cast';
}

/**
* @param OptionsResolver $resolver
*
* @throws ExceptionInterface
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(
[
'type',
]
);
$resolver->setAllowedTypes('type', ['string']);
}
}