/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); $tables = util::array_get($config['tables']); if ($tables) { foreach ($tables as $tableDef) { $id = util::array_get($tableDef['id']); Ensure::isNotEmpty($id, "Missing [id] option in twentysteps_auto_tables table definition"); $json = util::array_get($tableDef['dataTablesOptions']) ?: '{}'; Ensure::isTrue($this->isValidJson($json), 'Encountered illegal JSON for twentysteps_auto_tables table with id [%s] in config: %s', $id, $json); $container->setParameter('twentysteps_auto_tables.config.' . $id, $tableDef); } } $defaultOpts = util::array_get($config['default_datatables_options']) ?: '{}'; Ensure::isTrue($this->isValidJson($defaultOpts), 'Encountered illegal JSON in config: %s', $defaultOpts); $container->setParameter('twentysteps_auto_tables.default_datatables_options', $defaultOpts); $container->setParameter('twentysteps_auto_tables.config', $config); }
private function fetchtableId($request) { $tableId = $request->request->get('tableId'); if (!$tableId) { $tableId = $request->query->get('tableId'); } Ensure::isNotEmpty($tableId, 'tableId must not be empty'); return $tableId; }
/** * Returns the CrudService according to the given config. * @return AutoTablesCrudService */ public function fetchCrudService(AutoTablesConfiguration $config) { if ($config->getServiceId()) { $this->logger->info(sprintf('Create CrudService from serviceId [%s]', $config->getServiceId())); $crudService = $this->get($config->getServiceId()); Ensure::isNotNull($crudService, 'No service [%s] found', $crudService); Ensure::isTrue($crudService instanceof AutoTablesCrudService, 'Service [%s] has to implement %s', $config->getServiceId(), 'AutoTablesCrudService'); } else { $this->logger->info(sprintf('Create CrudService from repositoryId [%s]', $config->getRepositoryId())); Ensure::isNotEmpty($config->getRepositoryId(), 'Neither [serviceId] nor [repositoryId] defined for datatables of type [%s]', $config->getId()); $repository = $this->doctrine->getRepository($config->getRepositoryId()); Ensure::isNotNull($repository, 'Repository with id [%s] not found', $config->getRepositoryId()); $crudService = new RepositoryAutoTablesCrudService($this->doctrine->getManager(), $repository); } return $crudService; }
public function testEnsureNotEmptyFailed() { $this->setExpectedException(self::ENSURE_EXCEPTION, 'check 1 2 3'); Ensure::isNotEmpty('', 'check %s %s %s', 1, 2, 3); }
private function mergeColumnsConfiguration(AutoTablesConfiguration $config, $args) { $newColArgs = util::array_get($args['columns'], array()); foreach ($newColArgs as $newColArg) { $selector = $newColArg['selector']; Ensure::isNotEmpty($selector, 'Missing selector in column configuration'); $colArg = util::array_get($config->getColumns()[$selector], null); if ($colArg) { // overwrite the settings $config->putColumn($selector, array_merge($colArg, $newColArg)); } else { // define a new entry $config->putColumn($selector, $newColArg); } } return $config; }