-
Notifications
You must be signed in to change notification settings - Fork 13
#155 Improve read file tasks #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
745db03
#155 Implement InputFileReaderTask, InputLineReaderTask and LineReade…
njoubert-cleverage 75a89e5
#155 Add docs for [Input][FileReader|LineReader|FolderBrowser]Tasks
njoubert-cleverage 55d4667
#155 php-cs-fixer
njoubert-cleverage f0480fa
#155 Update FolderBrowserTask doc for name_pattern
njoubert-cleverage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| FileReaderTask | ||
| ============= | ||
|
|
||
| Reads a file and return raw content as a string | ||
|
|
||
| Task reference | ||
| -------------- | ||
|
|
||
| * **Service**: `CleverAge\ProcessBundle\Task\File\FileReaderTask` | ||
|
|
||
| Accepted inputs | ||
| --------------- | ||
|
|
||
| Input is ignored | ||
|
|
||
| Possible outputs | ||
| ---------------- | ||
|
|
||
| `string`: raw content of the file. | ||
| Underlying method is [file_get_contents](https://www.php.net/manual/en/function.file-get-contents.php). | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| | Code | Type | Required | Default | Description | | ||
| |------------|----------|:---------:|----------|------------------------------------------| | ||
| | `filename` | `string` | **X** | | Path of the file to read from (absolute) | | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| ```yaml | ||
| # Task configuration level | ||
| code: | ||
| service: '@CleverAge\ProcessBundle\Task\File\FileReaderTask' | ||
| options: | ||
| filename: 'path/to/file.txt' | ||
| ``` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| FolderBrowserTask | ||
| ============= | ||
|
|
||
| Reads a folder and iterate on each file, returning absolute path as string. | ||
|
|
||
| Task reference | ||
| -------------- | ||
|
|
||
| * **Service**: `CleverAge\ProcessBundle\Task\File\FolderBrowserTask` | ||
| * **Iterable task** | ||
|
|
||
| Accepted inputs | ||
| --------------- | ||
|
|
||
| Input is ignored | ||
|
|
||
| Possible outputs | ||
| ---------------- | ||
|
|
||
| `string`: absolute path of the file. | ||
| Underlying method is [Symfony Finder component](https://symfony.com/doc/current/components/finder.html). | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| | Code | Type | Required | Default | Description | | ||
| |-------------------|-------------------------------|:---------:|---------------------------|------------------------------------| | ||
| | `folder_path` | `string` | **X** | | Path of the directory to read from | | ||
| | `name_pattern` | `null` or `string` or `array` | | null | Restrict files using a pattern | | ||
| | `empty_log_level` | `string` | | Psr\Log\LogLevel::WARNING | From Psr\Log\LogLevel constants | | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| ```yaml | ||
| # Task configuration level | ||
| code: | ||
| service: '@CleverAge\ProcessBundle\Task\File\FolderBrowserTask' | ||
| options: | ||
| folder_path: '%kernel.project_dir%/var/data' | ||
| ``` | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| InputFileReaderTask | ||
| ============= | ||
|
|
||
| Reads a file and return raw content as a string | ||
|
|
||
| Task reference | ||
| -------------- | ||
|
|
||
| * **Service**: `CleverAge\ProcessBundle\Task\File\InputFileReaderTask` | ||
|
|
||
| Accepted inputs | ||
| --------------- | ||
|
|
||
| `string`: file path | ||
|
|
||
| Possible outputs | ||
| ---------------- | ||
|
|
||
| `string`: raw content of the file. | ||
| Underlying method is [file_get_contents](https://www.php.net/manual/en/function.file-get-contents.php). | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| None | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| ```yaml | ||
| # Task configuration level | ||
| entry: | ||
| service: '@CleverAge\ProcessBundle\Task\File\FolderBrowserTask' | ||
| options: | ||
| folder_path: '%kernel.project_dir%/var/data' | ||
| outputs: read | ||
| read: | ||
| service: '@CleverAge\ProcessBundle\Task\File\InputFileReaderTask' | ||
| ``` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| InputFolderBrowserTask | ||
| ============= | ||
|
|
||
| Reads a folder and iterate on each file, returning absolute path as string. | ||
|
|
||
| Task reference | ||
| -------------- | ||
|
|
||
| * **Service**: `CleverAge\ProcessBundle\Task\File\InputFolderBrowserTask` | ||
| * **Iterable task** | ||
|
|
||
| Accepted inputs | ||
| --------------- | ||
|
|
||
| `string`: folder path | ||
|
|
||
| Possible outputs | ||
| ---------------- | ||
|
|
||
| `string`: absolute path of the file. | ||
| Underlying method is [Symfony Finder component](https://symfony.com/doc/current/components/finder.html). | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| | Code | Type | Required | Default | Description | | ||
| |--------------------|----------|:---------:|---------|---------------------------------------| | ||
| | `base_folder_path` | `string` | | | Concatenated with input `folder_path` | | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| ```yaml | ||
| # Task configuration level | ||
| entry: | ||
| service: '@CleverAge\ProcessBundle\Task\ConstantOutputTask' | ||
| options: | ||
| output: '/var/data' | ||
| outputs: directory | ||
| directory: | ||
| service: '@CleverAge\ProcessBundle\Task\File\InputFolderBrowserTask' | ||
| options: | ||
| base_folder_path: '%kernel.project_dir%' | ||
| outputs: read | ||
| ``` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| InputLineReaderTask | ||
| ============= | ||
|
|
||
| Reads a file and iterate on each line, returning content as string. Skips empty lines. | ||
|
|
||
| Task reference | ||
| -------------- | ||
|
|
||
| * **Service**: `CleverAge\ProcessBundle\Task\File\InputLineReaderTask` | ||
| * **Iterable task** | ||
|
|
||
| Accepted inputs | ||
| --------------- | ||
|
|
||
| `string`: file path | ||
|
|
||
| Possible outputs | ||
| ---------------- | ||
|
|
||
| `string`: foreach line, it will return content as string. | ||
| Underlying method is [SplFileObject](https://www.php.net/manual/en/class.splfileobject.php). | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| None | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| ```yaml | ||
| # Task configuration level | ||
| entry: | ||
| service: '@CleverAge\ProcessBundle\Task\File\FolderBrowserTask' | ||
| options: | ||
| folder_path: '%kernel.project_dir%/var/data' | ||
| outputs: read | ||
| read: | ||
| service: '@CleverAge\ProcessBundle\Task\File\InputLineReaderTask' | ||
| ``` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| LineReaderTask | ||
| ============= | ||
|
|
||
| Reads a file and iterate on each line, returning content as string. Skips empty lines. | ||
|
|
||
| Task reference | ||
| -------------- | ||
|
|
||
| * **Service**: `CleverAge\ProcessBundle\Task\File\LineReaderTask` | ||
| * **Iterable task** | ||
|
|
||
| Accepted inputs | ||
| --------------- | ||
|
|
||
| Input is ignored | ||
|
|
||
| Possible outputs | ||
| ---------------- | ||
|
|
||
| `string`: foreach line, it will return content as string. | ||
| Underlying method is [SplFileObject](https://www.php.net/manual/en/class.splfileobject.php). | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| | Code | Type | Required | Default | Description | | ||
| |------------|----------|:---------:|----------|------------------------------------------| | ||
| | `filename` | `string` | **X** | | Path of the file to read from (absolute) | | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| ```yaml | ||
| # Task configuration level | ||
| code: | ||
| service: '@CleverAge\ProcessBundle\Task\File\LineReaderTask' | ||
| options: | ||
| filename: 'path/to/file.txt' | ||
| ``` | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the CleverAge/ProcessBundle package. | ||
| * | ||
| * Copyright (c) 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\ProcessState; | ||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
|
||
| /** | ||
| * Reads the whole input file and outputs its content. | ||
| */ | ||
| class InputFileReaderTask extends FileReaderTask | ||
| { | ||
| protected function getOptions(ProcessState $state): array | ||
| { | ||
| $options = parent::getOptions($state); | ||
| if (null !== $state->getInput()) { | ||
| $options['filename'] = $state->getInput(); | ||
| } | ||
|
|
||
| return $options; | ||
| } | ||
|
|
||
| protected function configureOptions(OptionsResolver $resolver): void | ||
| { | ||
| parent::configureOptions($resolver); | ||
| $resolver->remove('filename'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the CleverAge/ProcessBundle package. | ||
| * | ||
| * Copyright (c) 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\ProcessState; | ||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
|
||
| /** | ||
| * Reads an input file line by line and outputs each line. | ||
| */ | ||
| class InputLineReaderTask extends LineReaderTask | ||
| { | ||
| protected function getOptions(ProcessState $state): array | ||
| { | ||
| $options = parent::getOptions($state); | ||
| if (null !== $state->getInput()) { | ||
| $options['filename'] = $state->getInput(); | ||
| } | ||
|
|
||
| return $options; | ||
| } | ||
|
|
||
| protected function configureOptions(OptionsResolver $resolver): void | ||
| { | ||
| parent::configureOptions($resolver); | ||
| $resolver->remove('filename'); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.