PHP code example of symfony-helper / media-bundle

1. Go to this page and download the library: Download symfony-helper/media-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

symfony-helper / media-bundle example snippets


    public function registerBundles()
        {
            $bundles = [
                ...
                new SHelper\MediaBundle\SHelperMediaBundle(),
                ...
            ];
    
            ...
            
            return $bundles;
        }

/**
 * User
 *
 * @ORM\Table(name="`user`")
 * @ORM\Entity
 */
class User implements UserInterface
{
    ...
    /**
     * @var Image
     *
     * @ORM\OneToOne(targetEntity="SHelper\MediaBundle\Model\Entity\Image")
     * @ORM\JoinColumn(name="avatar_id", referencedColumnName="id", nullable=true)
     */
    private $avatar;
    ...
}

    class YourService
    {
        /** @var IImageService */
        private $imageService;
        
        public function __construct(IImageService $imageService)
        {
            $this->imageService = $imageService;
        }
        ...
        
        public function doSomething()
        {
            $imageBlob = file_get_contents('filename.jpg');
            $image = $this->imageService->createImageFromBlob($imageBlob);
            
            ...
            
            $user->setAvatar($image);
            //OR
            $article->setAvatar($image);
            //OR
            $someThingElse->setAvatar($image);
        }
    }