<?php
namespace ModulesAbstract\ImportedOrdersFileManager\Model\Filters; abstract class FileParsedAbstract extends \ModulesAbstract\ImportedOrdersFileManager\Model\Filters\AbstractFilter { private $files= []; private $basePath = NULL; protected function validateInput($input) { if (!in_array($input, ['yes', 'no', 'all'])) { throw new \ModulesAbstract\ImportedOrdersFileManager\Model\Filters\Exception(sprintf("The filter input %s is not valid for class %s", $input, __CLASS__)); } } protected function checkFileAndUpdateAttributes($file) {} abstract protected function getFilesFromDatabase($basePath); public function valid() :bool { if (!$this->iterating) { $this->iterating = true; $this->currentIndex = -1; if ($this->input != 'all') { $this->basePath = str_replace( realpath($this->layoutHandler->getBasePath()).'/', '', realpath($this->layoutHandler->getBasePath().'/'.$this->layoutHandler->getLocalPath()) )."/"; $files = $this->getFilesFromDatabase($this->basePath); $this->files = array_combine($files, array_fill(0, count($files), true)); } } while ($this->source->valid()) { $file = $this->source->current(); $this->source->next(); if ($file) { switch ($this->input) { case 'all': $this->currentIndex++; $this->current = $file; return true; break; case 'yes': case 'no': if ($this->basePath == '/') { $basePath = ''; } else { $basePath = $this->basePath; } $return = array_key_exists($basePath.$file->getFullName(), $this->files); $valid = false; if ($this->input == 'yes' && $return) { $valid = true; } if ($this->input == 'no' && !$return) { $valid = true; } if ($valid) { $this->currentIndex++; $this->current = $file; return true; } break; default: throw new \ModulesAbstract\ImportedOrdersFileManager\Model\Filters\Exception(sprintf("The filter input %s is not valid for class %s", $this->input, __CLASS__)); } } } return false; } protected function sqlEscapeForRegexpString($word) { return addcslashes($word, '%_\'"[]<>\\\(\)\.\+\-\*\?\^\$'); } }