PHP code example of smart-information-systems / file-bundle

1. Go to this page and download the library: Download smart-information-systems/file-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/ */

    

smart-information-systems / file-bundle example snippets


class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new SmartInformationSystems\FileBundle\SmartInformationSystemsFileBundle(),
            // ...
        );
    }
}

use SmartInformationSystems\FileBundle\Entity\Image;
use SmartInformationSystems\FileBundle\Annotations as Files;

class Brand
{
    /**
     * Логотип
     *
     * @var Image
     *
     * @ORM\OneToOne(targetEntity="SmartInformationSystems\FileBundle\Entity\Image", cascade="all")
     * @ORM\JoinColumn(name="logo_id", referencedColumnName="id", nullable=true)
     *
     * @Files\Image(
     *   width=370, height=210,
     *   previews={
     *     @Files\Image\Preview(name="admin", width=100, height=100),
     *   }
     * )
     */
    private $logo;
}

use SmartInformationSystems\FileBundle\Entity\Image;
use SmartInformationSystems\FileBundle\Annotations as Files;

class ProductImage
{
    /**
     * Товар
     *
     * @var Product
     *
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="images")
     * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false)
     */
    private $good;

    /**
     * Изображение.
     *
     * @var Image
     *
     * @ORM\OneToOne(targetEntity="SmartInformationSystems\FileBundle\Entity\Image", cascade="all")
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id", nullable=false)
     *
     * @Files\Image(
     *   width=700, height=700,
     *   previews={
     *     @Files\Image\Preview(name="admin", width=100, height=100, crop=true),
     *     @Files\Image\Preview(name="small", width=65, height=65, crop=true),
     *     @Files\Image\Preview(name="medium", width=250, height=250, crop=true)
     *   }
     * )
     */
    private $image;
}

class BrandAdmin extends AbstractAdmin
{
    $listMapper->add('logo', 'string', [
        'template' => 'SmartInformationSystemsFileBundle:sonata-admin:list_image.html.twig',
    ]);
}

use SmartInformationSystems\FileBundle\Form\Type\FileType;

class BrandAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper->add('logo', FileType::class, [
            'entity_class' => Brand::class,
            'data_class' => Image::class,
            '