Пример #1
0
 /**
  * @return PhpArray
  */
 private function getWriter()
 {
     if (is_null($this->zendWriter)) {
         $this->zendWriter = new PhpArray();
         $this->zendWriter->setUseBracketArraySyntax(true);
     }
     return $this->zendWriter;
 }
Пример #2
0
 public function getServiceConfig()
 {
     return array('factories' => array('ZF\\Configuration\\ConfigWriter' => function ($services) {
         $useShortArray = false;
         if ($services->has('Config')) {
             $config = $services->get('Config');
             if (isset($config['zf-configuration']['enable_short_array'])) {
                 $useShortArray = (bool) $config['zf-configuration']['enable_short_array'];
             }
         }
         $writer = new PhpArray();
         if ($useShortArray && version_compare(PHP_VERSION, '5.4.0', '>=')) {
             $writer->setUseBracketArraySyntax(true);
         }
         return $writer;
     }, 'ZF\\Configuration\\ConfigResource' => function ($services) {
         $config = array();
         $file = 'config/autoload/development.php';
         if ($services->has('Config')) {
             $config = $services->get('Config');
             if (isset($config['zf-configuration']) && isset($config['zf-configuration']['config_file'])) {
                 $file = $config['zf-configuration']['config_file'];
             }
         }
         $writer = $services->get('ZF\\Configuration\\ConfigWriter');
         return new ConfigResource($config, $file, $writer);
     }, 'ZF\\Configuration\\ConfigResourceFactory' => function ($services) {
         $modules = $services->get('ZF\\Configuration\\ModuleUtils');
         $writer = $services->get('ZF\\Configuration\\ConfigWriter');
         return new ResourceFactory($modules, $writer);
     }, 'ZF\\Configuration\\ModuleUtils' => function ($services) {
         $modules = $services->get('ModuleManager');
         return new ModuleUtils($modules);
     }));
 }
 public function setVersions(array $versions)
 {
     $writer = new Config\Writer\PhpArray();
     $writer->setUseBracketArraySyntax(true);
     $writer->toFile($this->_config['path_to_file_versions'], new Config\Config($versions));
     @chmod($this->_config['path_to_file_versions'], 0666);
 }
Пример #4
0
 /**
  * @param ProgressAdapter|null $progressAdapter
  */
 public function updateAddressFormats(ProgressAdapter $progressAdapter = null)
 {
     $localeDataUri = $this->options->getLocaleDataUri();
     $dataPath = $this->options->getDataPath();
     $locales = json_decode($this->httpClient->setUri($localeDataUri)->send()->getContent());
     foreach (scandir($dataPath) as $file) {
         if (fnmatch('*.json', $file)) {
             unlink($dataPath . '/' . $file);
         }
     }
     $countryCodes = isset($locales->countries) ? explode('~', $locales->countries) : [];
     $countryCodes[] = 'ZZ';
     if ($progressAdapter !== null) {
         $progressBar = new ProgressBar($progressAdapter, 0, count($countryCodes));
     }
     foreach ($countryCodes as $countryCode) {
         file_put_contents($dataPath . '/' . $countryCode . '.json', $this->httpClient->setUri($localeDataUri . '/' . $countryCode)->send()->getContent());
         if (isset($progressBar)) {
             $progressBar->next();
         }
     }
     if (isset($progressBar)) {
         $progressBar->finish();
     }
     // We clearly don't want the "ZZ" in the array!
     array_pop($countryCodes);
     $writer = new PhpArrayWriter();
     $writer->setUseBracketArraySyntax(true);
     $writer->toFile($this->options->getCountryCodesPath(), $countryCodes, false);
 }
 /**
  * @param $moduleName
  *
  * @return bool
  */
 private function updateApplicationConfig($moduleName)
 {
     $path = new PathBuilder();
     $path = $path->addPart('config')->addPart('application.config.global.php')->getPath();
     $data = (include $path);
     $data['modules'][] = $moduleName;
     $writer = new PhpArray();
     $writer->setUseBracketArraySyntax(true);
     file_put_contents($path, $writer->toString($data));
     return true;
 }
 /**
  * Create and return a PhpArray config writer.
  *
  * @param ContainerInterface $container
  * @return PhpArray
  */
 public function __invoke(ContainerInterface $container)
 {
     $writer = new PhpArray();
     if ($this->discoverConfigFlag($container, 'enable_short_array')) {
         $writer->setUseBracketArraySyntax(true);
     }
     if ($this->discoverConfigFlag($container, 'class_name_scalars')) {
         $writer->setUseClassNameScalars(true);
     }
     return $writer;
 }
Пример #7
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];
 }
Пример #8
0
 /**
  * Generate/update mapping
  * @param ArrayObject $spec
  */
 public function create(ArrayObject $spec)
 {
     $filePath = $this->getConfig('path') . self::MAPPER_NAME;
     $configArray = new ArrayObject();
     foreach ($spec['entities'] as $entity) {
         if (isset($entity['entity'])) {
             $configArray[$entity['entity']] = $entity;
             unset($entity['entity']);
         }
     }
     $writer = new PhpArray();
     $writer->setUseBracketArraySyntax(true);
     $writer->toFile($filePath, $configArray);
 }