🔊 Ajoute des logs
This commit is contained in:
@@ -31,6 +31,8 @@ class Deal
|
||||
protected $image2;
|
||||
/** @var \DateTime */
|
||||
protected $datecreation;
|
||||
/** @var string */
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Deal constructor.
|
||||
@@ -47,10 +49,10 @@ class Deal
|
||||
$crawler = $client->request('GET', $url);
|
||||
$deal = new self($crawler->filter('[data-savead-id]')->attr('data-savead-id'));
|
||||
$deal->setAccount($account);
|
||||
$deal->setSubject($crawler->filter('h1')->first()->text());
|
||||
$deal->setSubject(trim($crawler->filter('h1')->first()->text()));
|
||||
$deal->setCategory(array_search($crawler->filter('.breadcrumbsNav >ul >li')->eq(2)->text(), Categories::$categories));
|
||||
$deal->setType(self::TYPE_OFFER);
|
||||
$deal->setBody($crawler->filter('.properties_description')->first()->filter('p')->eq(1)->text());
|
||||
$deal->setBody(trim($crawler->filter('.properties_description')->first()->filter('p')->eq(1)->text()));
|
||||
$deal->setPrice($crawler->filter('[itemprop=price]')->first()->attr('content'));
|
||||
$date_node = $crawler->filter('[itemprop=availabilityStarts]')->first();
|
||||
$date = \DateTime::createFromFormat('Y-m-d', $date_node->attr('content'));
|
||||
@@ -254,15 +256,38 @@ class Deal
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $price
|
||||
* @param array|\DateTime|string $datecreation
|
||||
* @return Deal
|
||||
*/
|
||||
public function setDateCreation($datecreation)
|
||||
{
|
||||
if (is_array($datecreation)) {
|
||||
$datecreation = new \DateTime($datecreation['date']);
|
||||
} elseif (is_string($datecreation)) {
|
||||
$datecreation = new \DateTime($datecreation);
|
||||
}
|
||||
$this->datecreation = $datecreation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return Deal
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Account
|
||||
*/
|
||||
@@ -333,12 +358,14 @@ class Deal
|
||||
*/
|
||||
public static function fromJSON($json)
|
||||
{
|
||||
$path = dirname(realpath($json));
|
||||
$json = \json_decode(file_get_contents($json), true);
|
||||
$deal = new self();
|
||||
foreach ($json as $property => $value) {
|
||||
$method = sprintf('set%s', ucfirst($property));
|
||||
$deal->$method($value);
|
||||
}
|
||||
$deal->setPath($path);
|
||||
return $deal;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user