Server IP : 23.254.227.96 / Your IP : 216.73.216.120 Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64 User : viralblo ( 1001) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/viralblo/instantblog/vendor/fakerphp/faker/src/Faker/ORM/Mandango/ |
Upload File : |
<?php namespace Faker\ORM\Mandango; use Mandango\Mandango; /** * Service class for populating a database using Mandango. * A Populator can populate several tables using ActiveRecord classes. */ class Populator { protected $generator; protected $mandango; protected $entities = []; protected $quantities = []; public function __construct(\Faker\Generator $generator, Mandango $mandango) { $this->generator = $generator; $this->mandango = $mandango; } /** * Add an order for the generation of $number records for $entity. * * @param mixed $entity A Propel ActiveRecord classname, or a \Faker\ORM\Propel\EntityPopulator instance * @param int $number The number of entities to populate */ public function addEntity($entity, $number, $customColumnFormatters = []) { if (!$entity instanceof \Faker\ORM\Mandango\EntityPopulator) { $entity = new \Faker\ORM\Mandango\EntityPopulator($entity); } $entity->setColumnFormatters($entity->guessColumnFormatters($this->generator, $this->mandango)); if ($customColumnFormatters) { $entity->mergeColumnFormattersWith($customColumnFormatters); } $class = $entity->getClass(); $this->entities[$class] = $entity; $this->quantities[$class] = $number; } /** * Populate the database using all the Entity classes previously added. * * @return array A list of the inserted entities. */ public function execute() { $insertedEntities = []; foreach ($this->quantities as $class => $number) { for ($i = 0; $i < $number; ++$i) { $insertedEntities[$class][] = $this->entities[$class]->execute($this->mandango, $insertedEntities); } } $this->mandango->flush(); return $insertedEntities; } }