Skip to content

Commit

Permalink
Add StepBuilder::isLoadingStep method
Browse files Browse the repository at this point in the history
  • Loading branch information
otsch committed Sep 3, 2024
1 parent 9f4546e commit 972054e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
* Allow usage of `crwlr/crawler` v2.0.
* Method `StepBuilder::outputType()`, returning a `Crwlr\Crawler\Steps\StepOutputType` enum instance, informing about the possible output type of the underlying step. Currently, there is a default implementation in the abstract `StepBuilder` class, returning `StepOutputType::Mixed`. But this implementation will be removed in v3.0, so child classes should always explicitly define the possible output type. More info in the readme file. __Attention__: As `Crwlr\Crawler\Steps\StepOutputType` was introduced in `crwlr/crawler` v1.8.0, this is now the minimum required version of the crawler package.
* Method `StepBuilder::isLoadingStep()`, so the crwl.io app knows if it's dealing with a loading step. Default implementation just returns false, so in loading steps you need to provide an implementation of this method, returning true.

## [2.3.1] - 2024-06-18
### Fixed
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ public function configToStep(array $stepConfig): StepInterface
}
```

When creating a step builder for an HTTP loading step, please implement the following method:

```php
public function isLoadingStep(): bool
{
return true;
}
```

### ServiceProvider and Registering Package and Steps

To make your steps accessible in the crwl.io app, the final step is to register an extension package and all your steps using the `ExtensionPackageManager` included in this package. Since crwl.io is a [Laravel](https://laravel.com/) application, this is accomplished through a `ServiceProvider` class:
Expand Down
13 changes: 13 additions & 0 deletions src/StepBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ abstract class StepBuilder

public readonly string $outputType;

public readonly bool $isLoadingStep;

protected ?string $fileStoragePath = null;

/**
Expand All @@ -41,6 +43,8 @@ public function __construct()
StepOutputType::AssociativeArrayOrObject => 'array',
StepOutputType::Scalar => 'scalar',
};

$this->isLoadingStep = $this->isLoadingStep();
}

abstract public function stepId(): string;
Expand All @@ -61,6 +65,15 @@ public function outputType(): StepOutputType
return StepOutputType::Mixed;
}

/**
* When making a StepBuilder for a loading step, please add a child implementation of this method,
* returning true.
*/
public function isLoadingStep(): bool
{
return false;
}

/**
* @throws InvalidStepBuilderException
*/
Expand Down

0 comments on commit 972054e

Please sign in to comment.