<?php
namespace nur\data\types;

/**
 * Class GenericType: type de données générique, qui n'est ni formatable ni
 * analysable
 */
class FileType extends AbstractType {
  const TITLE = "information de fichier uploadé récupéré depuis \$_FILES";

  function getClass(): string {
    return "array";
  }

  function isInstance($value, bool $strict=false): bool {
    if ($value === null) return $this->ppAllowNull;
    return is_array($value);
  }

  function canFormat(): bool {
    return false;
  }

  protected function _verifix(&$value, array &$result=null): void {
    $orig = $value;
    if ($value === false) $this->verifixReplaceFalse($value);
    if ($value === null) $this->verifixReplaceNull($value);
    if ($value === null) {
      if ($this->ppAllowNull) {
        self::result_valid($result, $value, $orig);
      } else {
        $value = self::result_invalid($result, "null", $orig, null, false, false, $this->ppMessages);
      }
      return;
    }
    if ($value === false) {
      if ($this->ppAllowFalse) {
        self::result_valid($result, $value, $orig);
      } else {
        $value = self::result_invalid($result, "false", $orig, null, false, false, $this->ppMessages);
      }
      return;
    }

    if (is_array($value)) {
      self::result_valid($result, $value, $orig);
    } else {
      $value = self::result_invalid($result, "invalid", $orig, null, false, false, $this->ppMessages);
    }
  }
}
