🚧 ajout du parser manque partie sur l'image

feature/Admin
Maxime POINT 1 year ago
parent 67b0b30be8
commit 156d749bfb

@ -4,6 +4,7 @@ namespace metier;
class Flux class Flux
{ {
private string $id;
private string $flux; private string $flux;
/** /**
@ -21,4 +22,12 @@ class Flux
{ {
$this->flux = $flux; $this->flux = $flux;
} }
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
} }

@ -0,0 +1,42 @@
<?php
namespace model;
use DOMDocument;
use metier\Article;
use metier\Flux;
class Parser
{
public function parseArticles(Flux $flux){
$dom = new DOMDocument();
$tabArticle = array();
$dom->load($flux->getFlux());
$items = $dom->getElementsByTagName('item');
foreach ($items as $item) {
$title = $item->getElementsByTagName('title')[0]->nodeValue;
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
$guid = $item->getElementsByTagName('guid')[0]->nodeValue;
$link = $item->getElementsByTagName('link')[0]->nodeValue;
$description = $item->getElementsByTagName('description')[0]->nodeValue;
//manque ajout de l'image
$tabArticle[] = new Article((int)Null, $title, $date, $description, $guid, $link, $description, $flux->getId());
}
return $tabArticle;
}
public function parseAll(Flux $fluxes){
foreach ($fluxes as $flux){
$tabArticles[] =$this->parseArticles($flux);
}
return $tabArticles;
}
}
Loading…
Cancel
Save