Вход Регистрация
Файл: gapps/vendor/fzaninotto/faker/src/Faker/ORM/Mandango/Populator.php
Строк: 112
<?php

namespace FakerORMMandango;

use 
MandangoMandango;

/**
 * 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 = array();
    protected 
$quantities = array();

    
/**
     * @param FakerGenerator $generator
     * @param Mandango $mandango
     */
    
public function __construct(FakerGenerator $generatorMandango $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 FakerORMPropelEntityPopulator instance
     * @param int   $number The number of entities to populate
     */
    
public function addEntity($entity$number$customColumnFormatters = array())
    {
        if (!
$entity instanceof FakerORMMandangoEntityPopulator) {
            
$entity = new FakerORMMandangoEntityPopulator($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 = array();
        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;
    }
}
Онлайн: 2
Реклама