<?php
namespace AdLabs\ParserBundle\Parsers;
/**
* Класс парсинга данных
* @author Syomik Dmitriy <dsemik@gmail.com>
*/
class Parsers{
/**
* put your comment there...
*
* @var \stdClass
*/
protected $inputData;
/**
* Укзаатель на менеджер сущностей
*
* @var mixed
*/
protected $entityManager;
/**
* логгер
*
* @var mixed
*/
protected $logger;
/**
* Контент файла
*
* @var string
*/
protected $fileContent;
/**
* Массив общих шаблонов парсинга
*
* @var array
*/
protected $patterns;
/**
* Объект класса данных
*
* @var ParsersObjectData
*/
protected $objectData;
/**
* Статус отработки основого шаблона
*
* @var boolean
*/
protected $patternStatus;
/**
* put your comment there...
*
* @param mixed $objectData объект данных
* @param mixed $entityManager Entity Manager
* @param mixed $logger логер
*
* @return Parsers
*/
public function __construct($objectData, $entityManager, $logger)
{
$this->objectData = $objectData;
$this->entityManager = $entityManager;
$this->logger = $logger;
}
/**
* Установить входящие данные
*
* @param \StdClass $inputData входящие данные (запрос, путь к файлу)
*
*/
public function setInputData(\StdClass $inputData)
{
$this->inputData = $inputData;
}
/**
* Получить объект данных
*
* @return ParsersObjectData
*/
public function getObjectData()
{
return $this->objectData;
}
/**
* Инициализация поисковой системы и шаблонов для парсинга
*
* @return boolean
*/
public function init()
{
$infoParseResult = $this->pathInfoParse();
$patternResult = $this->getPatterns();
$contentResult = $this->getContent();
return $infoParseResult && $patternResult && $contentResult;
}
/**
* Получить все шаблоны для текущей поисковой системы
*
* @return boolen
*/
private function getPatterns()
{
$this->patterns = $this->entityManager
->getRepository("AdLabsParserBundle:PoiskovikPattern")
->getPatterns($this->objectData->getSearchEngine(), $this->objectData->getDataType());
if (!empty($this->patterns)) {
return true;
} else {
$this->logger->write('Patterns not found '.__CLASS__.' '.__METHOD__);
}
return false;
}
/**
* Инит поисковой системы из имени файла
*
* @param string $parsePath
*
* @return boolen
*/
private function pathInfoParse()
{
$parsePath = (string) $this->inputData->path;
$pathInfo = pathinfo($parsePath);
if (!empty($pathInfo['extension'])) {
$this->objectData->setDataType($pathInfo['extension']);
$this->objectData->setSearchEngine((string) $this->inputData->searchEngine);
$this->objectData->setQuery((string) $this->inputData->query);
return true;
}
$this->logger->write('Error init search engine');
return false;
}
/**
* Получить контент файла
*
* @return boolen
*/
private function getContent()
{
$filePath = (string) $this->inputData->path;
if (is_file($filePath)) {
$this->fileContent = file_get_contents($filePath);
if (!empty($this->fileContent)) {
return true;
} else {
$this->logger->write('File '.$filePath.' is empty');
}
} else {
$this->logger->write('Parse file '.$filePath.' not found');
}
return false;
}
}
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
- Parse error: syntax error, unexpected T_STRING in /in/i7gne on line 2
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_STRING in /in/i7gne on line 2
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/i7gne on line 2
Process exited with code 255.
preferences:
322.51 ms | 401 KiB | 460 Q