<?php
namespace ModulesAbstract\ImportedOrdersFileManager\Model\Filters; class Content extends AbstractFilterCached { protected function validateInput($input) { return true; } protected function checkFileAndUpdateAttributes($file) { $extractor = new \App\Utils\BaseParser\Utils\Extractor\Multiple(); $matches = $extractor->find($this->input, $this->getFileContent($file)); $valid = false; if ($matches->hasValue()) { $matches->cleanup(); switch ($this->filterMode) { case 'match': $valid = true; break; case 'count': $matchesCount = $matches->getCount(); if ($matchesCount >= $this->minCount && $matchesCount <= $this->maxCount) { $file->setCountMatches($matchesCount); $valid = true; } break; case 'extract': foreach ($matches->getMatches() as $match) { $file->addExtractedData($match->extract); } $valid = true; break; default: throw new \ModulesAbstract\ImportedOrdersFileManager\Model\Filters\Exception(sprintf("The filter mode %s is not valid for class %s", $this->filterMode, __CLASS__)); } } return $valid; } public function checkFileAndExtractMatches($file) { $extractor = new \App\Utils\BaseParser\Utils\Extractor\Multiple(); $matches = $extractor->find($this->input, $this->getFileContent($file)); $valid = false; if ($matches->hasValue()) { return $matches; } return new \App\Utils\BaseParser\Utils\Extractor\SingleFindResponse(0, []); } protected function getFileContent($file) { return $file->getContent(); } }