PHP code example of fsi / doctrine-extensions-bundle
1. Go to this page and download the library: Download fsi/doctrine-extensions-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/ */
fsi / doctrine-extensions-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
return [
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
new FSi\Bundle\DoctrineExtensionsBundle\FSiDoctrineExtensionsBundle(),
];
}
namespace FSi\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FSi\Bundle\DoctrineExtensionsBundle\Validator\Constraints as FSiAssert;
use FSi\DoctrineExtensions\Uploadable\Mapping\Annotation as FSi;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity()
*/
class Article
{
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
*/
private $id;
/**
* It is important that this column is nullable, because the value is set
* after the entity is persisted.
*
* @ORM\Column(nullable=true)
* @FSi\Uploadable(targetField="photo")
*/
private $photoKey;
/**
* Currently there is no common interface for uploaded files.
*
* @var mixed
*
* @FSiAssert\Image(
* maxWidth = 1000,
* maxHeight = 460
* )
*/
private $photo;
public function getId(): int
{
return $this->id;
}
public function setPhoto($photo): void
{
$this->photo = $photo;
}
public function getPhoto()
{
return $this->photo;
}
public function setPhotoKey(?string $photoKey): void
{
$this->photoKey = $photoKey;
}
public function getPhotoKey(): ?string
{
return $this->photoKey;
}
}
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use FSi\DoctrineExtensions\Translatable\Mapping\Annotation as Translatable;
/**
* The entity's repository needs to implement the
* \FSi\DoctrineExtensions\Translatable\Model\TranslatableRepositoryInterface
*
* @ORM\Entity(repositoryClass="FSi\DoctrineExtensions\Translatable\Entity\Repository\TranslatableRepository")
*/
class Article
{
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
*/
private $id;
/**
* @var string
*
* @Translatable\Locale
*/
private $locale;
/**
* @var string
*
* @Translatable\Translatable(mappedBy="translations")
*/
private $title;
/**
* @var string
*
* @Translatable\Translatable(mappedBy="translations")
*/
private $contents;
/**
* @var Collection|ArticleTranslation[]
*
* @ORM\OneToMany(targetEntity="ArticleTranslation", mappedBy="article", indexBy="locale")
*/
private $translations;
public function __construct()
{
$this->translations = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function setTitle(?string $title): void
{
$this->title = $title;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setContents(?string $contents): void
{
$this->contents = $contents;
}
public function getContents(): ?string
{
return $this->contents;
}
public function setLocale(?string $locale): void
{
$this->locale = $locale;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function getTranslations(): Collection
{
return $this->translations;
}
}
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
use FSi\DoctrineExtensions\Translatable\Mapping\Annotation as Translatable;
/**
* @ORM\Entity
*/
class ArticleTranslation
{
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
*/
private $id;
/**
* @var string
*
* @Translatable\Locale
*
* @ORM\Column(length=2)
*/
private $locale;
/**
* @ORM\Column
* @var string
*/
private $title;
/**
* @var string
*
* @ORM\Column
*/
private $contents;
/**
* @var Article
*
* @ORM\ManyToOne(targetEntity="Article", inversedBy="translations")
*/
private $article;
public function setTitle(?string $title): void
{
$this->title = $title;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setContents(?string $contents): void
{
$this->contents = $contents;
}
public function getContents(): ?string
{
return $this->contents;
}
public function setLocale(?string $locale): void
{
$this->locale = $locale;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function setArticle(?Article $article): void
{
$this->article = $article;
}
public function getArticle(): ?Article
{
return $this->article;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.