Browse Source

Fixed fast mode

pull/3/head
Richard Dern 3 months ago
parent
commit
348664e6ba
  1. 49
      package/Analyzer.php

49
package/Analyzer.php

@ -48,7 +48,8 @@ class Analyzer extends GenericObject
'fileSize',
'lastModified',
'fetcher',
'analyzers'
'analyzers',
'fastMode'
];
/**
@ -64,7 +65,8 @@ class Analyzer extends GenericObject
'fileSize',
'lastModified',
'fetcher',
'analyzers'
'analyzers',
'fastMode'
];
/**
@ -73,7 +75,8 @@ class Analyzer extends GenericObject
* @var array
*/
protected $casts = [
'lastModified' => 'datetime'
'lastModified' => 'datetime',
'fastMode' => 'boolean'
];
/**
@ -83,13 +86,6 @@ class Analyzer extends GenericObject
*/
protected ?Filesystem $fileSystem = null;
/**
* Should we enable the fast mode ?
*
* @var boolean
*/
protected $fastMode = false;
# ----| Accessors |---------------------------------------------------------
/**
@ -135,29 +131,18 @@ class Analyzer extends GenericObject
# ----| Methods |-----------------------------------------------------------
# --------------------------------------------------------------------------
/**
* Indicates we should use the fast mode. Only of subset of data is
* returned. This subset is determined by each analyzer.
*
* @return self
*/
public function fast(): self
{
$this->fastMode = true;
return $this;
}
/**
* Analyze a URL. Uses Cyca's Fetcher to fetch file at target URL first.
*
* @param string $url
* @param bool $fastMode Enable fast mode. In this mode, some data won't be fetched.
* @return self
*/
public function analyzeUrl(string $url): self
public function analyzeUrl(string $url, bool $fastMode = false): self
{
$this->reset();
$this->fastMode = $fastMode;
$this->source = self::SOURCE_URL;
$this->sourceUrl = $url;
@ -167,7 +152,7 @@ class Analyzer extends GenericObject
$this->setAttribute('fetcher', $client->toArray());
return $this->analyzeFile($client->filename);
return $this->analyzeFile($client->filename, $fastMode);
}
/**
@ -176,18 +161,20 @@ class Analyzer extends GenericObject
* is the default behaviour.
*
* @param string $body
* @param bool $fastMode Enable fast mode. In this mode, some data won't be fetched.
* @param bool $deleteAfter Indicate if we should delete the file after analyzis.
* @return self
*/
public function analyzeBody(string $body, bool $deleteAfter = true): self
public function analyzeBody(string $body, bool $fastMode = false, bool $deleteAfter = true): self
{
$this->reset();
$this->source = self::SOURCE_BODY;
$this->fastMode = $fastMode;
$this->source = self::SOURCE_BODY;
$filename = $this->storeBodyOnDisk($body);
return $this->analyzeFile($filename, $deleteAfter);
return $this->analyzeFile($filename, $fastMode, $deleteAfter);
}
/**
@ -195,12 +182,14 @@ class Analyzer extends GenericObject
* can be deleted after analyziz. By default, file is preserved.
*
* @param string $file
* @param bool $fastMode Enable fast mode. In this mode, some data won't be fetched.
* @param bool $deleteAfter Delete file after analyzis
* @return self
*/
public function analyzeFile(string $file, bool $deleteAfter = false): self
public function analyzeFile(string $file, bool $fastMode = false, bool $deleteAfter = false): self
{
$this->source = self::SOURCE_FILE;
$this->fastMode = $fastMode;
$this->source = self::SOURCE_FILE;
$this->sourcePath = $file;
if (empty($this->fileSystem)) {

Loading…
Cancel
Save