Skip to content

Commit

Permalink
Adding toArray() and getDomain() function (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
pschur authored Jul 31, 2023
1 parent e69b21e commit 607de00
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/entity/CrawledResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ final class CrawledResult
* @param string[] $allUrls
* @param string[] $followedUrls
* @param string[] $openedUrls
* @param array<string, array<int, string>> $urlReferences
* @param array<string,array<int,string>> $urlReferences
* @param Url[] $urls
* @param array<int, array{url: string, message: string, trace: array<int, mixed>}> $errors
* @param array<int,array{url: string, message: string, trace: array<int,mixed>}> $errors
*/
public function __construct(
private array $allUrls,
Expand Down Expand Up @@ -55,7 +55,7 @@ public function getOpenedUrls(): array


/**
* @return array<string, array<int, string>>
* @return array<string,array<int,string>>
*/
public function getUrlReferences(): array
{
Expand Down Expand Up @@ -85,4 +85,23 @@ public function getRobots(): ?string
{
return $this->robots;
}

/**
* get all data as array
*
* @return array<string, mixed>
*/
public function toArray(): array {
return [
'allUrls' => $this->allUrls,
'followedUrls' => $this->followedUrls,
'openedUrls' => $this->openedUrls,
'urlReferences' => $this->urlReferences,
'urls' => array_map(function(Url $url) {
return $url->toArray();
}, $this->urls),
'errors' => $this->errors,
'robots' => $this->robots,
];
}
}
20 changes: 20 additions & 0 deletions src/entity/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,24 @@ public function getHttpCode(): int
{
return $this->httpCode;
}


public function getDomain(){
return $this->url->getHost();
}

public function toArray(): array{
return [
'url' => $this->url->getAbsoluteUrl(),
'html' => $this->html,
'size' => $this->size,
'title' => $this->title,
'texts' => $this->texts,
'uniqueTexts' => $this->uniqueTexts,
'headers' => $this->headers,
'links' => $this->links,
'loadingTime' => $this->loadingTime,
'httpCode' => $this->httpCode,
];
}
}

0 comments on commit 607de00

Please sign in to comment.