예제 #1
0
 /**
  * @return array
  */
 public function indexAction()
 {
     /* @var $form Form */
     $form = $this->getService('FormElementManager')->get($this->getFormName());
     $prg = $this->prg();
     $config = $this->getService('config');
     $settings = isset($config[$this->getConfigKey()]) ? $config[$this->getConfigKey()] : [];
     if ($prg instanceof Response) {
         return $prg;
     } elseif (false === $prg) {
         $defaults = $settings;
         foreach ($settings as $key => $value) {
             // this needs moving to the form to set defaults there.
             if ($form->has($key) && $form->get($key) instanceof Fieldset) {
                 if (!array_key_exists($key, $defaults)) {
                     $defaults[$key] = $form->get($key)->getObject()->toArray();
                 } else {
                     $defaults[$key] = ArrayUtils::merge($form->get($key)->getObject()->toArray(), $defaults[$key]);
                 }
             }
         }
         $form->setData($defaults);
         return ['form' => $form];
     }
     $form->setData($prg);
     if ($form->isValid()) {
         $arrayOrObject = $form->getData();
         if (is_array($arrayOrObject)) {
             unset($arrayOrObject['button-submit']);
         }
         if ($arrayOrObject instanceof AbstractOptions) {
             $arrayOrObject = $arrayOrObject->toArray();
         }
         $filter = new UnderscoreToDash();
         $fileName = $filter->filter($this->getConfigKey());
         $config = new PhpArray();
         $config->setUseBracketArraySyntax(true);
         $config->toFile('./config/autoload/' . $fileName . '.local.php', [$this->getConfigKey() => $arrayOrObject]);
         $appConfig = $this->getService('Application\\Config');
         // delete cached config.
         if (true === $appConfig['module_listener_options']['config_cache_enabled']) {
             $configCache = $appConfig['module_listener_options']['cache_dir'] . '/module-config-cache.' . $appConfig['module_listener_options']['config_cache_key'] . '.php';
             if (file_exists($configCache)) {
                 unlink($configCache);
             }
         }
         $this->flashMessenger()->addSuccessMessage('Settings have been updated!');
     }
     return ['form' => $form];
 }
예제 #2
0
 protected function dash($name)
 {
     if ($this->filter == null) {
         $this->filter = new UnderscoreToDashFilter();
     }
     return $this->filter->filter($name);
 }