芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/vendor/fakerphp/faker/src/Faker/ORM/Mandango/EntityPopulator.php
class = $class; } /** * @return string */ public function getClass() { return $this->class; } public function setColumnFormatters($columnFormatters) { $this->columnFormatters = $columnFormatters; } /** * @return array */ public function getColumnFormatters() { return $this->columnFormatters; } public function mergeColumnFormattersWith($columnFormatters) { $this->columnFormatters = array_merge($this->columnFormatters, $columnFormatters); } /** * @return array */ public function guessColumnFormatters(\Faker\Generator $generator, Mandango $mandango) { $formatters = []; $nameGuesser = new \Faker\Guesser\Name($generator); $columnTypeGuesser = new \Faker\ORM\Mandango\ColumnTypeGuesser($generator); $metadata = $mandango->getMetadata($this->class); // fields foreach ($metadata['fields'] as $fieldName => $field) { if ($formatter = $nameGuesser->guessFormat($fieldName)) { $formatters[$fieldName] = $formatter; continue; } if ($formatter = $columnTypeGuesser->guessFormat($field)) { $formatters[$fieldName] = $formatter; continue; } } // references foreach (array_merge($metadata['referencesOne'], $metadata['referencesMany']) as $referenceName => $reference) { if (!isset($reference['class'])) { continue; } $referenceClass = $reference['class']; $formatters[$referenceName] = static function ($insertedEntities) use ($referenceClass) { if (isset($insertedEntities[$referenceClass])) { return Base::randomElement($insertedEntities[$referenceClass]); } return null; }; } return $formatters; } /** * Insert one new record using the Entity class. */ public function execute(Mandango $mandango, $insertedEntities) { $metadata = $mandango->getMetadata($this->class); $obj = $mandango->create($this->class); foreach ($this->columnFormatters as $column => $format) { if (null !== $format) { $value = is_callable($format) ? $format($insertedEntities, $obj) : $format; if (isset($metadata['fields'][$column]) || isset($metadata['referencesOne'][$column])) { $obj->set($column, $value); } if (isset($metadata['referencesMany'][$column])) { $adder = 'add' . ucfirst($column); $obj->$adder($value); } } } $mandango->persist($obj); return $obj; } }