/**
  * {@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);
 }
Exemplo n.º 2
0
 /**
  * @return AutoTablesConfiguration
  */
 private function fetchAutoTablesConfiguration($tableId)
 {
     $options = $this->container->getParameter('twentysteps_auto_tables.config.' . $tableId);
     Ensure::isNotNull($options, 'Missing configuration for twentysteps_auto_tables table [%s]', $tableId);
     return new AutoTablesConfiguration($tableId, $options, new AutoTablesGlobalConfiguration($this->container->getParameter('twentysteps_auto_tables.config')));
 }
 private function parseMethodColumnDescriptors(\ReflectionClass $reflClass, &$columnDescriptors, AutoTablesConfiguration $config)
 {
     foreach ($reflClass->getMethods() as $method) {
         $column = null;
         $annot = $this->reader->getMethodAnnotation($method, '\\twentysteps\\Bundle\\AutoTablesBundle\\Annotations\\Column');
         if ($annot) {
             $column = new MethodColumnDescriptor($method);
             Ensure::isTrue(count($method->getParameters()) == 0, 'Failed to use [%s] as getter method, only parameterless methods supported for @Column', $method->getName());
             Ensure::isTrue(StaticStringy::startsWith($method->getName(), 'get'), 'Illegal method name [%s], getter methods must start with a get prefix', $method->getName());
             $column->addAutoTablesAnnotation($annot);
             $column->addAutoTablesConfig($config, $method->getName());
         }
         if ($column && $column->isUsable()) {
             $methodName = 'set' . substr($method->getName(), 3);
             if ($reflClass->hasMethod($methodName)) {
                 $setterMethod = $reflClass->getMethod($methodName);
                 Ensure::isEqual(1, count($setterMethod->getParameters()), 'setter method [%s] needs to have exactly one parameter', $setterMethod->getName());
                 $column->setSetterMethod($setterMethod);
             }
             $column->validate();
             $this->columnDescriptorMap[$column->getId()] = $column;
             $columnDescriptors[] = $column;
         }
     }
 }
 /**
  * Throws an exception if the settings are inconsistent.
  */
 public function validate()
 {
     if ($this->initializer) {
         Ensure::isFalse($this->initializer->getRepository() && $this->initializer->getValue(), 'It makes no sense to define initializer repository and value simultaneously for column [%s]', $this->name);
     }
 }
Exemplo n.º 5
0
 public function testFail()
 {
     $this->setExpectedException(self::ENSURE_EXCEPTION, 'check 1 2 3');
     Ensure::fail('check %s %s %s', 1, 2, 3);
 }
 /**
  * @return AutoTablesConfiguration
  */
 private function fillModel(&$array)
 {
     $config = null;
     $entityDescriptor = null;
     $request = $this->requestStack->getCurrentRequest();
     if ($request) {
         $config = $request->get('tsAutoTablesConfig');
         $entityDescriptor = $request->get('tsAutoTablesEntityDescriptor');
         $array['entities'] = $request->get('tsAutoTablesEntities');
         $array['entityDescriptor'] = $entityDescriptor;
     }
     Ensure::isNotNull($config, 'Missing config, did you forget to use ts_auto_table_options?');
     Ensure::isNotNull($entityDescriptor, 'Missing entityDescriptor, did you forget to use ts_auto_table_options?');
     return $config;
 }