/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/migrations/src/Command
NameSizeModeActions
Phinx/-0755rm
BakeMigrationCommand.php75450644editdlrm
BakeMigrationDiffCommand.php207280644editdlrm
BakeMigrationSnapshotCommand.php51920644editdlrm
BakeSeedCommand.php73130644editdlrm
BakeSimpleMigrationCommand.php59500644editdlrm
MigrationsCacheBuildCommand.php8480644editdlrm
MigrationsCacheClearCommand.php8480644editdlrm
MigrationsCommand.php67150644editdlrm
MigrationsCreateCommand.php8400644editdlrm
MigrationsDumpCommand.php8360644editdlrm
MigrationsMarkMigratedCommand.php8520644editdlrm
MigrationsMigrateCommand.php8420644editdlrm
MigrationsRollbackCommand.php8440644editdlrm
MigrationsSeedCommand.php8360644editdlrm
MigrationsStatusCommand.php8400644editdlrm
SnapshotTrait.php30820644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/migrations/src/Command/BakeSeedCommand.php (7313B)
pathFragment; if ($this->plugin) { $path = $this->_pluginPath($this->plugin) . $this->pathFragment; } return str_replace('/', DS, $path); } /** * @inheritDoc */ public function template(): string { return 'Migrations.Seed/seed'; } /** * Get template data. * * @param \Cake\Console\Arguments $arguments The arguments for the command * @return array * @phpstan-return array */ public function templateData(Arguments $arguments): array { $namespace = Configure::read('App.namespace'); if ($this->plugin) { $namespace = $this->_pluginNamespace($this->plugin); } $table = Inflector::tableize((string)$arguments->getArgumentAt(0)); if ($arguments->hasOption('table')) { /** @var string $table */ $table = $arguments->getOption('table'); } $records = false; if ($arguments->getOption('data')) { $limit = (int)$arguments->getOption('limit'); /** @var string $fields */ $fields = $arguments->getOption('fields') ?: '*'; if ($fields !== '*') { $fields = explode(',', $fields); } $model = $this->getTableLocator()->get('BakeSeed', [ 'table' => $table, 'connection' => ConnectionManager::get($this->connection), ]); $query = $model->find('all') ->enableHydration(false); if ($limit) { $query->limit($limit); } if ($fields !== '*') { $query->select($fields); } /** @var array $records */ $records = $query->disableResultsCasting()->toArray(); $records = $this->prettifyArray($records); } return [ 'className' => $this->_name, 'namespace' => $namespace, 'records' => $records, 'table' => $table, ]; } /** * @inheritDoc */ public function bake(string $name, Arguments $args, ConsoleIo $io): void { $newArgs = new Arguments( $args->getArguments(), ['no-test' => true] + $args->getOptions(), ['name'] ); $this->_name = $name; parent::bake($name, $newArgs, $io); } /** * Gets the option parser instance and configures it. * * @param \Cake\Console\ConsoleOptionParser $parser Option parser to update. * @return \Cake\Console\ConsoleOptionParser */ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { $parser = parent::buildOptionParser($parser); $parser->setDescription( 'Bake seed class.' )->addOption('table', [ 'help' => 'The database table to use.', ])->addOption('data', [ 'boolean' => true, 'help' => 'Include data from the table to the seed', ])->addOption('fields', [ 'default' => '*', 'help' => 'If including data, comma separated list of fields to select (all fields by default)', ])->addOption('limit', [ 'short' => 'l', 'help' => 'If including data, max number of rows to select', ]); return $parser; } /** * Prettify var_export of an array output * * @param array $array Array to prettify * @param int $tabCount Initial tab count * @param string $indentCharacter Desired indent for the code. * @return string */ protected function prettifyArray(array $array, $tabCount = 3, $indentCharacter = ' ') { $content = var_export($array, true); $lines = explode("\n", $content); $inString = false; foreach ($lines as $k => &$line) { if ($k === 0) { // First row $line = '['; continue; } if ($k === count($lines) - 1) { // Last row $line = str_repeat($indentCharacter, --$tabCount) . ']'; continue; } $line = ltrim($line); if (!$inString) { if ($line === '),') { // Check for closing bracket $line = '],'; $tabCount--; } elseif (preg_match("/^\d+\s\=\>\s$/", $line)) { // Mark '0 =>' kind of lines to remove $line = false; continue; } //Insert tab count $line = str_repeat($indentCharacter, $tabCount) . $line; } $length = strlen($line); for ($j = 0; $j < $length; $j++) { if ($line[$j] === '\\') { // skip character right after an escape \ $j++; } elseif ($line[$j] === '\'') { // check string open/end $inString = !$inString; } } // check for opening bracket if (!$inString && trim($line) === 'array (') { $line = str_replace('array (', '[', $line); $tabCount++; } } unset($line); // Remove marked lines $lines = array_filter($lines, function ($line) { return $line !== false; }); return implode("\n", $lines); } }