private function generateConfig() { $path = "module/{$this->module}/config/table.config.php"; if (file_exists($path)) { copy($path, $path . '.' . date('mdHis')); $config = (include $path); } else { $config = ['tables' => []]; } $itemConfig = ['table' => $this->table]; if ($this->params('db')) { $itemConfig['adapter'] = $this->params('db'); } if ($this->params('schema')) { $itemConfig['schema'] = $this->params('schema'); } if ($this->params('t')) { $itemConfig['invokable'] = "{$this->module}\\Model\\{$this->name}Table"; } if ($this->params('e')) { $itemConfig['row'] = "{$this->module}\\Model\\{$this->name}"; } if ($this->params('re')) { $itemConfig['row'] = true; } $primaries = []; foreach ($this->getTableMeta()->getConstraints($this->table, $this->schema) as $constraint) { /** @var $constraint \Zend\Db\Metadata\Object\ConstraintObject */ if ($constraint->getType() == 'PRIMARY KEY') { $primaries[] = current($constraint->getColumns()); } } if (count($primaries) == 1) { $primaries = current($primaries); } $itemConfig['primary'] = $primaries; $config['tables'][$this->name . 'Table'] = $itemConfig; ConfigFactory::toFile($path, $config); echo 'Generate config success!'; }
public function testFactoryCanRegisterCustomWriterPlugin() { $dummyWriter = new Writer\TestAssets\DummyWriter(); Factory::getWriterPluginManager()->setService('DummyWriter', $dummyWriter); Factory::registerWriter('dum', 'DummyWriter'); $file = $this->getTestAssetFileName('dum'); $res = Factory::toFile($file, array('one' => 1)); $this->assertEquals($res, true); }
<?php use Zend\Config\Factory; $env = getenv('APP_ENV') ?: 'dev'; $mergedConfigFile = __DIR__ . '/../data/cache/config_cache.php'; // If in production and merged config exists, return it if ($env === 'pro' && is_file($mergedConfigFile)) { return include $mergedConfigFile; } // Merge configuration files $mergedConfig = Factory::fromFiles(glob(__DIR__ . '/autoload/{,*.}{global,local}.php', GLOB_BRACE)); // If in production, cache merged config if ($env === 'pro') { Factory::toFile($mergedConfigFile, $mergedConfig); } // Finally, Return the merged configuration return $mergedConfig;