Remove files older than given rule
(both Access time and Modified time will be checked
and only if both matches removal will take place)

@param array $inputArray
@return string
181179
public function removeFilesOlderThanGivenRule($inputArray)
    {
        $aFiles = $this->retrieveFilesOlderThanGivenRule($inputArray);
        if (is_array($aFiles)) {
            $filesystem = new \Symfony\Component\Filesystem\Filesystem();
            $filesystem->remove($aFiles);
            return $this->setArrayToJson($aFiles);
        }
        return $aFiles;
    }
964429
public function submit(array $inputData = [])
    {
        $this->validated = false;
        $this->isSubmitted = true;
        $this->isValid = true;

        /** @var ElementInterface $element */
        foreach ($this->elements() as $name => $element) {
            if ($element->isDisabled()) {
                continue;
            }
            $value = $inputData[$name] ?? '';
            $this->rawData[$name] = $value;
            $value = $this->filter($name, $value);
            $this->data[$name] = $value;
            $element->withValue($value);

            // only validate elements which are not disabled.
            if (! $this->validate($name, $element->value())) {
                $this->isValid = false;
            }
        }
    }
187196
protected function purge(array $idArchivesToDelete, Date $dateStart, $reason)
    {
        $deletedRowCount = 0;
        if (!empty($idArchivesToDelete)) {
            $deletedRowCount = $this->deleteArchiveIds($dateStart, $idArchivesToDelete);

            $this->logger->info(
                "Deleted {count} rows in archive tables (numeric + blob) for {reason} for {date}.",
                array(
                    'count' => $deletedRowCount,
                    'date' => $dateStart,
                    'reason' => $reason
                )
            );

            $this->logger->debug("[Deleted IDs: {deletedIds}]", array(
                'deletedIds' => implode(',', $idArchivesToDelete)
            ));
        } else {
            $this->logger->debug(
                "No archives for {reason} found in archive numeric table for {date}.",
                array('date' => $dateStart, 'reason' => $reason)
            );
        }

        return $deletedRowCount;
    }
1317184
protected function extractFile(InputInterface $input)
    {
        $resource = STDOUT;
        if (null !== $file = $input->getArgument('file')) {
            if (false === $resource = fopen($file, 'w')) {
                return null;
            }
        }

        return $resource;
    }
1280222
private function cleanArray(array $array = [], $replaceWith)
    {
        $dirtyKeys = $this->findBadWordsInArray($array);

        foreach ($dirtyKeys as $key) {

            $this->cleanArrayKey($key, $array, $replaceWith);
        }

        return $array;
    }
921694
public function clean($array)
	{
		//set the $inputElement
		$this->inputElement = $array;

		//loop throught the input array removing empty elements and return resultant array
		$this->outputElement = array_values(array_filter($array, function($item){

				return ! empty($item);

		}));

		//return this self same class
		return $this;

	}
191305
public static function cleanArray(array &$arr)
    {
        foreach ($arr as $k => $v) {
            if (is_array($v)) {
                self::cleanArray($arr[$k]);
            } else {
                $arr[$k] = stripslashes($v);
            }
        }
    }
95818
public function update(array $inputs)
    {
        $inputs = $this->purifyInputs($inputs);

        return $this->model->update($inputs);
    }
1155120
public function delete($path)
    {
        $result = Uploader::destroy($path, ['invalidate' => true]);

        return is_array($result) ? $result['result'] == 'ok' : false;
    }
785961
public static function filterDate($inputDate = '')
    {
        if ($inputDate != '') {
            // Get date
            if ($inputDate == 'back_1_day') {
                try {
                    $dateTime = new \DateTime("-1 day");
                    $result   = [
                        'date'       => $dateTime->format('Y-m-d'),
                        'day'        => $dateTime->format('Ymd'),
                        'month'      => $dateTime->format('Y-m'),
                        'monthTable' => $dateTime->format('Y_m')
                    ];
                }
                catch (\Exception $e) {
                    if (function_exists('log_message')) {
                        $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
                        log_message('error', $message);
                    }
                    $result = [
                        'date'       => date('Y-m-d', strtotime("-1 day", strtotime($inputDate))),
                        'day'        => date('Ymd', strtotime("-1 day", strtotime($inputDate))),
                        'month'      => date('Y-m', strtotime("-1 day", strtotime($inputDate))),
                        'monthTable' => date('Y_m', strtotime("-1 day", strtotime($inputDate)))
                    ];
                }
            } else {
                $result = [
                    'date'       => date('Y-m-d', strtotime($inputDate)),
                    'day'        => date('Ymd', strtotime($inputDate)),
                    'month'      => date('Y-m', strtotime($inputDate)),
                    'monthTable' => date('Y_m', strtotime($inputDate))
                ];
            }
        } else {
            $result = [
                'date'       => date('Y-m-d'),
                'day'        => date('Ymd'),
                'month'      => date('Y-m'),
                'monthTable' => date('Y_m')
            ];
        }

        return $result;
    }
1035784
public function sanitizeInput(array $input)
    {
        return $input = collect($input)->reject(function ($value) {
            return is_null($value) || empty($value);
        })->toArray();
    }
286060
public function clearExpired(&$Data)
    {
        if (!is_array($Data)) {
            return false;
        }
        $Cleared = false;
        $Updated = [];
        foreach ($Data as $Key => $Value) {
            if (is_array($Value)) {
                foreach ($Value as &$SubValue) {
                    if (is_array($SubValue)) {
                        if ($this->clearExpired($SubValue)) {
                            $Cleared = true;
                        }
                    }
                }
                unset($SubValue);
            }
            if (!is_array($Value) || !isset($Value['Time']) || $Value['Time'] > time()) {
                $Updated[$Key] = $Value;
            } else {
                $Cleared = true;
            }
        }
        $Data = $Updated;
        return $Cleared;
    }
148717
protected function purgeArray(array $array = array()) {

        $result = array();
        $keys   = array_keys($array);

        $this->addBasicPurgeFilters();

        if (!empty($keys) && !empty($this->purgeFilters)) {
            foreach ($keys as $key) {
                $allowed = true;

                foreach ($this->purgeFilters as $filter) {
                    $allowed = $filter($key);

                    if (!$allowed) {
                        break;
                    }
                }

                if ($allowed) {
                    $result[$key] = $array[$key];
                }
            }
        }

        return $result;
    }
599307
public static function removeOldFiles() {
		
		if (!is_dir(static::TEMP_FOLDER)) {
			return;
		}
		
		$app = Application::getInstance();
		$counter = 0;

		$files = Utilities::getDirectoryFilenames(static::TEMP_FOLDER);

		foreach ($files as $file) {

			$pathFile	= APPLICATION_PATH . '/' .static::TEMP_FOLDER . '/' . $file;
			$fileLife	= time() - filemtime($pathFile);
			$maxLife	= static::FILE_EXPIRE * 60;
			
			if ($fileLife > $maxLife) {
				$counter++;
				unlink($pathFile);
			}

		}
		
		if ($counter) {
			$app->logEvent($counter . ' files has been deleted from ' . static::TEMP_FOLDER);
		} else {
			$app->logEvent('No old files deleted from ' . static::TEMP_FOLDER);
		}
		
	}
836219
protected function uploadTemporary(LaravelUploadedFile $uploadedFile, array $input)
    {
        $file                    = $this->resolveTempFileName($uploadedFile);
        $uploadedFile->directory = $file['directory'];
        $uploadedFile->filename  = $file['filename'];

        Validator::resolver(function($translator, $data, $rules, $messages) {
            return new CsvCustomValidator($translator, $data, $rules, $messages);
        });
        $validation = $this->validator->on('upload')->with($input, [], [
            'source' => trans('antares/foundation::response.modules.validator.invalid-structure')
        ]);
        if ($validation->fails()) {
            return Response::make($validation->getMessageBag()->first(), 400);
        }
        return ($uploadedFile->move($uploadedFile->directory, $uploadedFile->filename)) ?
                Response::json(['path' => $uploadedFile->directory . DIRECTORY_SEPARATOR . $uploadedFile->filename], 200) :
                Response::make(trans('Unable to upload file.'), 400);
    }
1350897
public function eraseExpired() {
    $cacheData = $this->_loadCache();
    if (true === is_array($cacheData)) {
      $counter = 0;
      foreach ($cacheData as $key => $entry) {
        if (true === $this->_checkExpired($entry['time'], $entry['expire'])) {
          unset($cacheData[$key]);
          $counter++;
        }
      }
      if ($counter > 0) {
        $cacheData = json_encode($cacheData);
        file_put_contents($this->getCacheDir(), $cacheData);
      }
      return $counter;
    }
  }
1003187
protected function checkFiles(InputInterface $input, array $files): int
    {
        $filesPerLine = TypeCast::castInt($input->getOption('files-per-line'));
        $totalFiles = count($files);

        /** @var SplFileInfo[] $chunkFiles */
        $chunkFiles = array_chunk($files, $filesPerLine);

        $this->processFiles($chunkFiles, $filesPerLine, $totalFiles);

        return $totalFiles;
    }