Skip to content

Commit de15904

Browse files
Merge pull request #119 from cleverage/v3.0-dev
Merg V3.0 dev ->V3.1 dev
2 parents cf41019 + 52ffad0 commit de15904

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

Task/File/FileReaderTask.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of the CleverAge/ProcessBundle package.
4+
*
5+
* Copyright (C) 2017-2019 Clever-Age
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace CleverAge\ProcessBundle\Task\File;
12+
13+
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
14+
use CleverAge\ProcessBundle\Model\ProcessState;
15+
use Symfony\Component\Filesystem\Exception\IOException;
16+
use Symfony\Component\OptionsResolver\Exception\AccessException;
17+
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
18+
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
19+
use Symfony\Component\OptionsResolver\OptionsResolver;
20+
21+
/**
22+
* Read the whole file and output its content
23+
*
24+
* @todo Provide additional safeguards like if file exists and is readable
25+
*
26+
* @author Vincent Chalnot <[email protected]>
27+
*/
28+
class FileReaderTask extends AbstractConfigurableTask
29+
{
30+
/**
31+
* @param ProcessState $state
32+
*
33+
* @throws ExceptionInterface
34+
* @throws IOException
35+
*/
36+
public function execute(ProcessState $state)
37+
{
38+
$options = $this->getOptions($state);
39+
40+
$state->setOutput(file_get_contents($options['filename']));
41+
}
42+
43+
/**
44+
* @param OptionsResolver $resolver
45+
*
46+
* @throws AccessException
47+
* @throws UndefinedOptionsException
48+
*/
49+
protected function configureOptions(OptionsResolver $resolver)
50+
{
51+
$resolver->setRequired(
52+
[
53+
'filename',
54+
]
55+
);
56+
$resolver->setAllowedTypes('filename', ['string']);
57+
}
58+
}

Task/FilterTask.php

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function execute(ProcessState $state)
5252
{
5353
$input = $state->getInput();
5454
if (!$this->checkCondition($input, $this->getOptions($state))) {
55+
$state->setErrorOutput($input);
5556
$state->setSkipped(true);
5657

5758
return;

Transformer/CastTransformer.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of the CleverAge/ProcessBundle package.
4+
*
5+
* Copyright (C) 2017-2019 Clever-Age
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace CleverAge\ProcessBundle\Transformer;
12+
13+
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
14+
use Symfony\Component\OptionsResolver\OptionsResolver;
15+
16+
/**
17+
* Cast a value to a different PHP type
18+
*
19+
* @author Valentin Clavreul <[email protected]>
20+
* @author Vincent Chalnot <[email protected]>
21+
*/
22+
class CastTransformer implements ConfigurableTransformerInterface
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function transform($value, array $options = [])
28+
{
29+
settype($value, $options['type']);
30+
31+
return $value;
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function getCode()
38+
{
39+
return 'cast';
40+
}
41+
42+
/**
43+
* @param OptionsResolver $resolver
44+
*
45+
* @throws ExceptionInterface
46+
*/
47+
public function configureOptions(OptionsResolver $resolver)
48+
{
49+
$resolver->setRequired(
50+
[
51+
'type',
52+
]
53+
);
54+
$resolver->setAllowedTypes('type', ['string']);
55+
}
56+
}

0 commit comments

Comments
 (0)