Skip to content

Commit

Permalink
Remove deprecated HttpLoader methods
Browse files Browse the repository at this point in the history
Remove 4 deprecated methods interacting with the headless browser
helper. Users can directly call the methods on the browser helper.

Also remove deprecated method `RespondedRequest::cacheKeyFromRequest()`.
  • Loading branch information
otsch committed Aug 8, 2024
1 parent 4a89632 commit 1ed53fa
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 51 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* __BREAKING__: The return type of the `Crawler::loader()` method no longer allows `array`. This means it's no longer possible to provide multiple loaders from the crawler. Instead, use the new functionality to directly provide a custom loader to a step described below.
* __BREAKING__: Refactored the abstract `LoadingStep` class to a trait and removed the `LoadingStepInterface`. Loading steps should now extend the `Step` class and use the trait. As multiple loaders are no longer supported, the `addLoader` method was renamed to `setLoader`. Similarly, the methods `useLoader()` and `usesLoader()` for selecting loaders by key are removed. Now, you can directly provide a different loader to a single step using the trait's new `withLoader()` method (e.g., `Http::get()->withLoader($loader)`).
* __BREAKING__: Removed the `PaginatorInterface` to allow for better extensibility. The old `Crwlr\Crawler\Steps\Loading\Http\Paginators\AbstractPaginator` class has also been removed. Please use the newer, improved version `Crwlr\Crawler\Steps\Loading\Http\AbstractPaginator`. This newer version has also changed: the first argument `UriInterface $url` is removed from the `processLoaded()` method, as the URL also is part of the request (`Psr\Http\Message\RequestInterface`) which is now the first argument. Additionally, the default implementation of the `getNextRequest()` method is removed. Child implementations must define this method themselves. If your custom paginator still has a `getNextUrl()` method, note that it is no longer needed by the library and will not be called. The `getNextRequest()` method now fulfills its original purpose.
* __BREAKING__: Removed methods from `HttpLoader`:
* `$loader->setHeadlessBrowserOptions()` => use `$loader->browser()->setOptions()` instead
* `$loader->addHeadlessBrowserOptions()` => use `$loader->browser()->addOptions()` instead
* `$loader->setChromeExecutable()` => use `$loader->browser()->setExecutable()` instead
* `$loader->browserHelper()` => use `$loader->browser()` instead
* __BREAKING__: Removed method `RespondedRequest::cacheKeyFromRequest()`. Use `RequestKey::from()` instead.
* __BREAKING__: The `HttpLoader::retryCachedErrorResponses()` method now returns an instance of the new `Crwlr\Crawler\Loader\Http\Cache\RetryManager` class. This class provides the methods `only()` and `except()` to restrict retries to specific HTTP response status codes. Previously, this method returned the `HttpLoader` itself (`$this`), so if you're using it in a chain and calling other loader methods after it, you will need to refactor your code.
* __BREAKING__: Removed the `Microseconds` class from this package. It has been moved to the `crwlr/utils` package, which you can use instead.

Expand Down
40 changes: 0 additions & 40 deletions src/Loader/Http/HttpLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,38 +227,6 @@ public function usesHeadlessBrowser(): bool
return $this->useHeadlessBrowser;
}

/**
* @param array<string, mixed> $options
* @deprecated Will be removed in v2.0. Use `$loader->browser()->setOptions()` instead.
*/
public function setHeadlessBrowserOptions(array $options): static
{
$this->browser()->setOptions($options);

return $this;
}

/**
* @param array<string, mixed> $options
* @deprecated Will be removed in v2.0. Use `$loader->browser()->addOptions()` instead.
*/
public function addHeadlessBrowserOptions(array $options): static
{
$this->browser()->addOptions($options);

return $this;
}

/**
* @deprecated Will be removed in v2.0. Use `$loader->browser()->setExecutable()` instead.
*/
public function setChromeExecutable(string $executable): static
{
$this->browser()->setExecutable($executable);

return $this;
}

public function setMaxRedirects(int $maxRedirects): static
{
$this->maxRedirects = $maxRedirects;
Expand Down Expand Up @@ -322,14 +290,6 @@ public function useRotatingProxies(array $proxyUrls): void
$this->proxies = new ProxyManager($proxyUrls);
}

/**
* @deprecated Will be removed in v2.0. Use browser() instead, it's an alias.
*/
public function browserHelper(): HeadlessBrowserLoaderHelper
{
return $this->browser();
}

public function browser(): HeadlessBrowserLoaderHelper
{
if (!$this->browserHelper) {
Expand Down
8 changes: 0 additions & 8 deletions src/Loader/Http/Messages/RespondedRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ public static function fromArray(array $data): RespondedRequest
return $respondedRequest;
}

/**
* @deprecated You can use RequestKey::from() directly instead.
*/
public static function cacheKeyFromRequest(RequestInterface $request): string
{
return RequestKey::from($request);
}

/**
* @return mixed[]
* @throws MissingZlibExtensionException
Expand Down
3 changes: 0 additions & 3 deletions src/Steps/Loading/Http/AbstractPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public function logWhenFinished(LoggerInterface $logger): void
}
}

/**
* For v2. See above.
*/
abstract public function getNextRequest(): ?RequestInterface;

protected function registerLoadedRequest(RequestInterface|RespondedRequest $request): void
Expand Down
2 changes: 2 additions & 0 deletions src/Utils/RequestKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Crwlr\Crawler\Utils;

use Crwlr\Crawler\Cache\Exceptions\MissingZlibExtensionException;
use Crwlr\Crawler\Loader\Http\Messages\RespondedRequest;
use Crwlr\Crawler\Steps\Loading\Http;
use Psr\Http\Message\RequestInterface;
Expand All @@ -20,6 +21,7 @@ class RequestKey
* @param RequestInterface|RespondedRequest $request
* @param string[] $ignoreHeaders
* @return string
* @throws MissingZlibExtensionException
*/
public static function from(RequestInterface|RespondedRequest $request, array $ignoreHeaders = ['Cookie']): string
{
Expand Down

0 comments on commit 1ed53fa

Please sign in to comment.