你不能「觸發」的事件,它已經引發here:
/**
* Checks for file to upload.
*
* @param object $obj The object.
* @param string $fieldName The name of the field containing the upload (has to be mapped).
*/
public function upload($obj, $fieldName)
{
$mapping = $this->getMapping($obj, $fieldName);
// nothing to upload
if (!$this->hasUploadedFile($obj, $mapping)) {
return;
}
$this->dispatch(Events::PRE_UPLOAD, new Event($obj, $mapping));
$this->storage->upload($obj, $mapping);
$this->injector->injectFile($obj, $mapping);
$this->dispatch(Events::POST_UPLOAD, new Event($obj, $mapping));
}
你可以做的是手柄的事件,這是我想你指至。你可以通過創建一個監聽器來做到這一點,如概述here。監聽器將監聽POST_UPLOAD
事件,像這樣:
# app/config/services.yml
services:
app_bundle.listener.uploaded_file_listener:
class: AppBundle\EventListener\UploadedFileListener
tags:
- { name: kernel.event_listener, event: vich_uploader.post_upload, method: onPostUpload }
監聽器類將typehint像下面的VICH上傳事件:
// src/AppBundle/EventListener/AcmeRequestListener.php
namespace AppBundle\EventListener;
use Symfony\Component\HttpKernel\HttpKernel;
use Vich\UploaderBundle\Event\Event;
class UploadedFileListener
{
public function onPostUpload(Event $event)
{
$uploadedFile = $event->getObject();
// your custom logic here
}
}