filemodel = $file; // @todo We should catch any exceptions if the default storage is s3 (it is) and we cannot find the file, or the s3 call fails $this->file_size = Storage::size($file->full_storage_path); $this->file_mtime = Storage::lastModified($file->full_storage_path); } else { if (! is_string($file)) throw new \Exception('Invalid object creation - file should be a string'); if (! file_exists($file)) throw new FileNotFoundException('Item doesnt exist: '.$file); if (! is_readable($file)) throw new UnreadableFileEncountered('Item cannot be read: '.$file); $this->file_name = $file; $x = stat($file); $this->file_size = $x['size']; $this->file_mtime = $x['mtime']; } break; case self::I_RECV; $keys = ['name','mtime','size']; if (! is_array($file) || array_diff(array_keys($file),$keys)) throw new \Exception('Invalid object creation - file is not a valid array :'.serialize(array_diff(array_keys($file),$keys))); $this->file_name = $file['name']; $this->file_size = $file['size']; $this->file_mtime = $file['mtime']; break; default: throw new \Exception('Unknown action: '.$action); } $this->action = $action; $this->type = $this->whatType(); } /** * @throws \Exception */ public function __get($key) { switch($key) { case 'mtime': if ($this instanceof Mail) $this->youngest()->timestamp; if ($this->action & self::I_RECV|self::I_SEND) return $this->{'file_'.$key}; throw new \Exception('Invalid request for key: '.$key); case 'name': if ($this instanceof Mail) return sprintf('%08x',timew($this->youngest())); if ($this->action & self::I_RECV|self::I_SEND) return $this->{'file_'.$key}; throw new \Exception('Invalid request for key: '.$key); case 'size': if ($this instanceof Mail) return strlen($this->file); if ($this->action & self::I_RECV|self::I_SEND) return $this->{'file_'.$key}; throw new \Exception('Invalid request for key: '.$key); case 'recvas': return $this->file_name; case 'sendas': if ($this instanceof Mail) return sprintf('%s.pkt',$this->name); return $this->file_name ? basename($this->file_name) : $this->filemodel->name; default: throw new \Exception('Unknown key: '.$key); } } protected function isType(int $type): bool { return $this->type & $type; } private function whatType(): int { static $ext = ['su','mo','tu','we','th','fr','sa','req']; $x = strrchr($this->file_name,'.'); if (! $x || (strlen(substr($x,1)) != 3)) return self::IS_FILE; if (strcasecmp(substr($x,2),'lo') === 0) return self::IS_FLO; if (strcasecmp(substr($x,1),'pkt') === 0) return self::IS_PKT; if (strcasecmp(substr($x,1),'req') === 0) return self::IS_REQ; if (strcasecmp(substr($x,1),'tic') === 0) return self::IS_TIC; for ($i=0;$i