[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: EntityPopulator.php
<?php namespace Faker\ORM\Mandango; use Faker\Provider\Base; use Mandango\Mandango; /** * Service class for populating a table through a Mandango ActiveRecord class. */ class EntityPopulator { protected $class; protected $columnFormatters = []; /** * @param string $class A Mandango ActiveRecord classname */ public function __construct($class) { $this->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; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.57 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002