Start implementing web query

This commit is contained in:
Dennis Eichhorn 2017-02-14 23:27:54 +01:00
parent e69d12dbf6
commit 8531c1422f
3 changed files with 110 additions and 86 deletions

106
DataStorage/Web/Builder.php Normal file
View File

@ -0,0 +1,106 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace phpOMS\Utils\Crawler;
use phpOMs\DataStorage\Database\Query\Builder as DatabaseQueryBuilder;
/**
* Array utils.
*
* @category Framework
* @package phpOMS\Utils
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Builder extends DatabaseQueryBuilder
{
private function download($uri)
{
$finder = [];
$l11n = new Localization();
foreach($this->from as $from) {
$doc = new \DOMDocument();
$doc->loadHTML(Rest::request($l11n, new Http($from)));
$finder[$from] = new \DomXPath($doc);
}
return $finder;
}
public function get(string $xpath)
{
$nodes = $finder->query($xpath);
}
public function execute()
{
$finder = $this->download();
$result = [];
$table = null;
foreach($this->wheres as $column => $where) {
if($column === 'xpath') {
$table = $this->createTable($finder->query($where['value']));
}
}
foreach($this->columns as $column) {
}
}
private function createTable($node) : array
{
if(strtolower($node->tagName) === 'table') {
return $this->createTableFromTable();
} elseif(strtolower($node->tagName) === 'li') {
return $this->createTableFromList();
} else {
return $this->createTableFromContent();
}
}
private function createTableFromTable($node) : array
{
// todo: get header either thead or <th> (either first row or first column)
// todo: get rest except tfoot
// find first unique column and define as additional id (in addition to row number)
}
private function createTableFromList($node) : array
{
$table = [];
$children = $node->childNodes;
foreach($children as $child) {
$table[] = $child->asXML();
}
return $table;
}
private function createTableFromContent($node) : array
{
return [$node->asXML()];
}
}

View File

@ -30,26 +30,6 @@ namespace phpOMS\Message\Http;
*/
class Rest
{
/**
* Url.
*
* @var Request
* @since 1.0.0
*/
private $request = '';
/**
* Set url.
*
* @param Request $request Request
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function setRequest(Request $request) /* : void */
{
$this->request = $request;
}
/**
* Make request.
@ -61,16 +41,16 @@ class Rest
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function callApi($data = false) : string
public static function request(Request $request) : string
{
$curl = curl_init();
switch ($this->request->getMethod()) {
switch ($request->getMethod()) {
case RequestMethod::POST:
curl_setopt($curl, CURLOPT_POST, 1);
if ($data) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData());
}
break;
case RequestMethod::PUT:
@ -81,7 +61,7 @@ class Rest
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_URL, $this->request->getUri()->__toString());
curl_setopt($curl, CURLOPT_URL, $request->getUri()->__toString());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);

View File

@ -1,62 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace phpOMS\Utils\Crawler;
/**
* Array utils.
*
* @category Framework
* @package phpOMS\Utils
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class WebParser
{
private $uri = '';
private $doc = null;
private $finder = null;
public function __construct(string $uri)
{
$this->uri = $uri;
}
private function download($uri)
{
$handle = curl_init($uri);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$this->doc = new \DOMDocument();
$this->doc->loadHTML($this->content);
$this->finder = new \DomXPath($this->doc);
}
public function get(string $xpath)
{
$nodes = $finder->query($xpath);
}
private function parseTable($node)
{
}
private function parseList($node)
{
}
}