Exemplo n.º 1
0
 public function saveInstalledFlag()
 {
     $file = $this->appDir . '/config/zaxcmsinstalled.neon';
     $config = Nette\Neon\Neon::decode(file_get_contents($file));
     $config['parameters']['CMSInstalled'] = TRUE;
     file_put_contents($file, Nette\Neon\Neon::encode($config, Nette\Neon\Encoder::BLOCK));
 }
Exemplo n.º 2
0
 protected function arrayToText($arr)
 {
     return empty($arr) ? '' : Nette\Neon\Neon::encode($arr, 1);
     /*$pairs = [];
     		foreach($arr as $key => $val) {
     			$pairs[] = $key . '=>' . $val;
     		}
     		return implode(PHP_EOL, $pairs);*/
 }
Exemplo n.º 3
0
 /**
  * Generates configuration in NEON format.
  * @return string
  */
 public function dump(array $data)
 {
     $tmp = array();
     foreach ($data as $name => $secData) {
         if ($parent = Helpers::takeParent($secData)) {
             $name .= ' ' . self::INHERITING_SEPARATOR . ' ' . $parent;
         }
         $tmp[$name] = $secData;
     }
     return "# generated by Nette\n\n" . Neon\Neon::encode($tmp, Neon\Neon::BLOCK);
 }
Exemplo n.º 4
0
 /**
  * Generates configuration in NEON format.
  * @return string
  */
 public function dump(array $data)
 {
     $tmp = array();
     foreach ($data as $name => $secData) {
         if ($parent = Helpers::takeParent($secData)) {
             $name .= ' ' . self::INHERITING_SEPARATOR . ' ' . $parent;
         }
         $tmp[$name] = $secData;
     }
     array_walk_recursive($tmp, function (&$val) {
         if ($val instanceof Statement) {
             $val = NeonAdapter::statementToEntity($val);
         }
     });
     return "# generated by Nette\n\n" . Neon\Neon::encode($tmp, Neon\Neon::BLOCK);
 }
Exemplo n.º 5
0
 /**
  * Persist changes to neon file
  */
 protected function persist()
 {
     $saveData = [];
     // remove id
     foreach ($this->neonData as $key => $value) {
         if (isset($this->neonData[$key]["id"])) {
             $id = $this->neonData[$key]["id"];
             unset($value["id"]);
         } else {
             $id = Uuid::generate(4);
         }
         $saveData[$id] = $value;
     }
     $data = $this->neon->encode($saveData, Nette\Neon\Encoder::BLOCK);
     file_put_contents($this->neonFile, $data);
 }
Exemplo n.º 6
0
 public static function dump(Composer\Script\Event $event)
 {
     $composer = $event->getComposer();
     Composer\Autoload\includeFile(implode(DIRECTORY_SEPARATOR, [$vendorDir = $composer->getConfig()->get('vendor-dir'), 'autoload.php']));
     $repository = $composer->getRepositoryManager()->getLocalRepository();
     $config = ['extensions' => []];
     foreach ($repository->getPackages() as $package) {
         $extra = array_filter($package->getExtra(), 'is_array');
         if (isset($extra['extensions'])) {
             $config['extensions'] += $extensions = array_filter(array_map([Nette\Neon\Neon::class, 'decode'], array_filter($extra['extensions'], 'is_string')), function ($class) {
                 return is_subclass_of($class instanceof Nette\Neon\Entity ? $class->value : $class, Nette\DI\CompilerExtension::class);
             });
             $config = array_merge_recursive($config, array_intersect_key($extra, $extensions));
         }
     }
     file_put_contents(implode(DIRECTORY_SEPARATOR, [$vendorDir, 'config.neon']), Nette\Neon\Neon::encode($config, Nette\Neon\Neon::BLOCK));
 }
Exemplo n.º 7
0
 private function buildFiles(\Project $project)
 {
     $translations = $project->getTranslations();
     $builder = new KdybyTranslationBuilder();
     $files = [];
     foreach ($translations as $translation) {
         $mask = '%s.' . $translation->getLocale() . '.neon';
         $dictionaryData = $this->translationFacade->getDictionaryData($translation);
         $outputFiles = $builder->build($mask, $dictionaryData);
         $files = array_merge($files, $outputFiles);
     }
     $zip = new ZipStream(sprintf('%s.zip', $project->getName()));
     foreach ($files as $fileName => $messages) {
         $data = Neon::encode($messages, Neon::BLOCK);
         $zip->addFile($fileName, $data);
     }
     $zip->finish();
 }
Exemplo n.º 8
0
 public function handleDownloadTranslation()
 {
     $dictionaryData = $this->translationFacade->getDictionaryData($this->translation);
     $builder = new KdybyTranslationBuilder();
     $mask = '%s.' . $this->translation->getLocale() . '.neon';
     $outputFiles = $builder->build($mask, $dictionaryData);
     if (count($outputFiles) === 1) {
         $name = key($outputFiles);
         $neon = Neon::encode(current($outputFiles), Neon::BLOCK);
         $response = new TextDownloadResponse($neon, $name, 'text/x-neon', 'UTF-8');
         $this->sendResponse($response);
         $this->terminate();
     } else {
         $zip = new ZipStream(sprintf('%s - %s.zip', $this->translation->getProject()->getName(), $this->translation->getLocale()));
         foreach ($outputFiles as $fileName => $data) {
             $neon = Neon::encode($data, Neon::BLOCK);
             $zip->addFile($fileName, $neon);
         }
         $zip->finish();
     }
 }
Exemplo n.º 9
0
 public function loadConfiguration()
 {
     $container = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     foreach ($config['paths'] as $name => $path) {
         if (!isset($container->parameters[$name])) {
             $container->parameters[$name] = $container->expand($path);
         }
     }
     if (!is_file($container->parameters['packagesDir'] . '/config.neon')) {
         file_put_contents($container->parameters['packagesDir'] . '/config.neon', Neon::encode(array('sources' => array('https://raw.github.com/venne/packages-metadata/master/metadata.json')), Neon::BLOCK));
     }
     $packagesConfig = Neon::decode(file_get_contents($container->parameters['packagesDir'] . '/config.neon'));
     $container->addDependency($container->parameters['packagesDir'] . '/config.neon');
     // load packages
     $container->parameters['packages'] = array();
     $packagesDir = $container->expand($config['paths']['packagesDir']);
     if (is_file($packagesDir . '/packages.php')) {
         $packages = (require $packagesDir . '/packages.php');
         foreach ($packages as $name => $items) {
             $container->parameters['packages'][$name] = $items;
             $container->parameters['packages'][$name]['path'] = $container->expand($items['path']);
         }
     }
     // packages
     $container->addDefinition($this->prefix('packageManager'))->setClass('Venne\\Packages\\PackageManager', array('@container', $container->parameters['configDir'], $container->parameters['libsDir'], $container->parameters['resourcesDir'], $container->parameters['packagesDir'], $container->expand($config['packageManager']['packageFiles']), $packagesConfig['sources']));
     // helpers
     $container->addDefinition($this->prefix('pathResolver'))->setClass('Venne\\Packages\\PathResolver', array($container->expand('%packages%')));
     // Commands
     $commands = array('packageSync' => 'Venne\\Packages\\Commands\\Sync', 'packageInstall' => 'Venne\\Packages\\Commands\\Install', 'packageUninstall' => 'Venne\\Packages\\Commands\\Uninstall', 'packageList' => 'Venne\\Packages\\Commands\\List');
     foreach ($commands as $name => $cmd) {
         $container->addDefinition($this->prefix(lcfirst($name) . 'Command'))->setClass(sprintf('%sCommand', $cmd))->addTag(ConsoleExtension::COMMAND_TAG);
     }
     // macros
     $container->getDefinition('nette.latteFactory')->addSetup('$s = Venne\\Packages\\Latte\\Macros\\UIMacros::install(?->getCompiler()); $s->injectPathResolver(?)', array('@self', '@Venne\\Packages\\PathResolver'));
 }
Exemplo n.º 10
0
    private function configureLocalNeon()
    {
        $config = Neon::decode(file_get_contents($this->dir . '/app/config/local.neon.example'));
        $config['parameters']['database']['host'] = $this->dbHost;
        $config['parameters']['database']['user'] = $this->dbUser;
        $config['parameters']['database']['password'] = $this->dbPassword;
        $config['parameters']['database']['dbname'] = $this->dbName;
        $config['parameters']['database']['dbname_test'] = $this->dbTestName;
        $config['parameters']['routes']['secure'] = $this->secureRoutes;
        $localNeonPath = $this->dir . '/app/config/local.neon';
        $localNeonHead = <<<EOT
#
# Local machine configuration.
# SECURITY WARNING: it is CRITICAL that this file & directory
# are NOT accessible directly via a web browser!
# This file should also NEVER be versioned.
#


EOT;
        if (file_put_contents($localNeonPath, $localNeonHead . str_replace("\t", '    ', Neon::encode($config, Neon::BLOCK))) === FALSE) {
            $this->errors[] = 'Local config could not be written at [' . $localNeonPath . ']';
        }
    }
Exemplo n.º 11
0
 private function configureErrorNotifyEmail()
 {
     $defaultNeonPath = $this->dir . '/app/config/default.neon';
     if (!file_exists($defaultNeonPath)) {
         $this->errors[] = 'Error notifications e-mail not written into default.neon - no app/config/default.neon file found.';
         return;
     }
     $defaultNeon = file_get_contents($defaultNeonPath);
     $count = 0;
     file_put_contents($defaultNeonPath, preg_replace('~errorNotifyEmail: .*~', 'errorNotifyEmail: ' . Neon::encode($this->errorNotifyEmail), $defaultNeon, -1, $count));
     if ($count === 0) {
         $this->errors[] = 'Error notifications e-mail not written into default.neon - string "errorNotifyEmail: " to be replaced not found.';
     }
 }
Exemplo n.º 12
0
 /**
  * Returns the formatted configuration file contents.
  *
  * @param array $contents configuration array
  *
  * @return string formatted configuration file contents
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function exportFormat($contents = null)
 {
     $this->prepVars($contents);
     return NeonParser::encode($contents);
 }
Exemplo n.º 13
0
 /**
  * @param mixed[] $data
  */
 private function saveConfig($data)
 {
     file_put_contents($this->getConfigPath(), Neon::encode($data, Neon::BLOCK));
 }
Exemplo n.º 14
0
 public function dump(array $data, $comment = "# generated by Translation Builder\n\n")
 {
     return $comment . Neon::encode($data, Neon::BLOCK);
 }
Exemplo n.º 15
0
 protected function saveConfig($config)
 {
     return file_put_contents($this->appDir . '/config/database.neon', Nette\Neon\Neon::encode($config, Nette\Neon\Encoder::BLOCK));
 }
Exemplo n.º 16
0
 /**
  * @param string $filePath
  * @param string $code
  * @param string $string
  */
 private function saveTranslationToNeonFile($filePath, $code, $string)
 {
     $actualCatalog = Nette\Neon\Neon::decode(file_get_contents($filePath));
     if (!is_array($actualCatalog)) {
         $actualCatalog = array();
     }
     $newCatalogMember = $this->createNestedArrayFromLanguageCode($code, $string);
     $result = array_replace_recursive($actualCatalog, $newCatalogMember);
     file_put_contents($filePath, Nette\Neon\Neon::encode($result, Nette\Neon\Neon::BLOCK));
 }
Exemplo n.º 17
0
 /**
  * {@inheritDoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     return Neon::encode($messages->all($domain), Neon::BLOCK);
 }
 /**
  * Funkce pro uložení konfigurace do souboru
  */
 public function saveConfig()
 {
     $encodedData = Neon::encode($this->data, Neon::BLOCK);
     file_put_contents($this->neonFileName, $encodedData);
 }