1. Go to this page and download the library: Download orbitale/doctrine-tools 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/ */
orbitale / doctrine-tools example snippets
composer
namespace AppBundle\Repository;
use Orbitale\Component\DoctrineTools\EntityRepositoryHelperTrait;
class PostRepository
{
use EntityRepositoryHelperTrait;
// Your custom logic here ...
}
$configuration = new Doctrine\ORM\Configuration();
$configuration->setDefaultRepositoryClassName('Orbitale\Component\DoctrineTools\EntityRepositoryHelperTrait');
// Build the EntityManager with its configuration...
namespace AppBundle\DataFixtures\ORM;
use App\Entity\Post;
use Orbitale\Component\DoctrineTools\AbstractFixture;
use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
class PostFixtures extends AbstractFixture implements ORMFixtureInterface
{
public function getEntityClass(): string
{
return Post::class;
}
public function getObjects(): array
{
return [
['title' => 'First post', 'description' => 'Lorem ipsum'],
['title' => 'Second post', 'description' => 'muspi meroL'],
];
}
}
namespace App\DataFixtures\ORM;
use App\Entity\Post;
use Orbitale\Component\DoctrineTools\AbstractFixture;
use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
class PostFixtures extends AbstractFixture implements ORMFixtureInterface
{
public function getEntityClass(): string
{
return Post::class;
}
/**
* With this, we can retrieve a Post reference with this method:
* $this->getReference('posts-1');
* where '1' is the post id.
* Only works with same object if it's flushed on every iteration.
*/
public function getReferencePrefix(): ?string
{
return 'posts-';
}
/**
* Set this to 1 so the first post is always persisted before the next one.
* This is mandatory as we are referencing the same object.
* If we had to use a reference to another object, only "getOrder()" would have to be overriden.
*/
public function flushEveryXIterations(): int
{
return 1;
}
public function getObjects(): array
{
return [
['id' => 'c5022243-343b-40c3-8c88-09c1a76faf78', 'title' => 'First post', 'parent' => null],
[
'title' => 'Second post',
'parent' => function(Post $object, AbstractFixture $fixture, EntityManagerInterface $manager) {
return $fixture->getReference('posts-c5022243-343b-40c3-8c88-09c1a76faf78');
},
],
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.