src/Prospekta/FileBundle/EventListener/FileSaver.php
/**
     * prePersist Doctrine listener
     * 
     * This method listens if any File instance is persisted in Doctrine database. If so, it stores associated file and creates thumbnails if needed.
     * 
     * @param \Doctrine\ORM\Event\LifecycleEventArgs $args
     */
prePersist Doctrine listener

This method listens if any File instance is persisted in Doctrine database. If so, it stores associated file and creates thumbnails if needed.


prePersist Doctrine listener This method listens if any File instance is persisted in Doctrine database . If so it stores associated file and creates thumbnails if needed .
public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();
        $entityManager = $args->getEntityManager();
        if ($entity instanceof File)
        {
            if (!$entity->isFileSet())            
            {
                throw new \Exception('You cannot persist FileBundle\Entity\File instance without setting a file');
            }
            $newHandle = $this->storageManager->getEngine()->store($entity);
            $entity->setFilehandle($newHandle);
            if ($entity instanceof ImageFile)
            {
                foreach($entity->getThumbnails() as $size)
                {
                    $x = $size[0];
                    $y = $size[1];
                    $this->storageManager->getEngine()->storeThumbnail($entity, $x, $y);
                }
            }
        } 
    }
public function prePersist ( LifecycleEventArgs $ args ) { $ entity = $ args -> getEntity ( ) ; $ entityManager = $ args -> getEntityManager ( ) ; if ( $ entity instanceof File ) { if ( ! $ entity -> isFileSet ( ) ) { throw new \ Exception ( 'You cannot persist FileBundle\Entity\File instance without setting a file' ) ; } $ newHandle = $ this -> storageManager -> getEngine ( ) -> store ( $ entity ) ; $ entity -> setFilehandle ( $ newHandle ) ; if ( $ entity instanceof ImageFile ) { foreach ( $ entity -> getThumbnails ( ) as $ size ) { $ x = $ size [ 0 ] ; $ y = $ size [ 1 ] ; $ this -> storageManager -> getEngine ( ) -> storeThumbnail ( $ entity , $ x , $ y ) ; } } } }
prePersist Doctrine listener
prePersist Doctrine listener