예제 #1
0
 /**
  * Override moveUploadedFile
  *
  * If the request is not HTTP, or not a PUT or PATCH request, delegates to
  * the parent functionality.
  *
  * Otherwise, does a `rename()` operation, and returns the status of the
  * operation.
  *
  * @param string $sourceFile
  * @param string $targetFile
  * @return bool
  * @throws FilterRuntimeException in the event of a warning
  */
 protected function moveUploadedFile($sourceFile, $targetFile)
 {
     if (null === $this->request || !method_exists($this->request, 'isPut') || !$this->request->isPut() && !$this->request->isPatch()) {
         return parent::moveUploadedFile($sourceFile, $targetFile);
     }
     ErrorHandler::start();
     $result = rename($sourceFile, $targetFile);
     $warningException = ErrorHandler::stop();
     if (false === $result || null !== $warningException) {
         throw new FilterRuntimeException(sprintf('File "%s" could not be renamed. An error occurred while processing the file.', $sourceFile), 0, $warningException);
     }
     return $result;
 }
예제 #2
0
 /**
  * Overrides isValid()
  *
  * If the reason for failure is self::ATTACK, we can assume that
  * is_uploaded_file() has failed -- which is
  *
  * @param mixed $value
  * @return void
  */
 public function isValid($value)
 {
     if (null === $this->request || !method_exists($this->request, 'isPut') || !$this->request->isPut() && !$this->request->isPatch()) {
         // In absence of a request object, an HTTP request, or a PATCH/PUT
         // operation, just use the parent logic.
         return parent::isValid($value);
     }
     $result = parent::isValid($value);
     if ($result !== false) {
         return $result;
     }
     if (!isset($this->abstractOptions['messages'][static::ATTACK])) {
         return $result;
     }
     if (count($this->abstractOptions['messages']) > 1) {
         return $result;
     }
     unset($this->abstractOptions['messages'][static::ATTACK]);
     return true;
 }