Пример #1
0
 public function setLanguage($language)
 {
     $language = strtolower($language);
     if ($this->cacheStorage == null) {
         throw new InvalidStateException('Cache storage for translator is not set');
     }
     $cache = $this->cacheStorage->read('translator_' . $language);
     if ($cache == null) {
         $file = $this->languageDirectory . DIRECTORY_SEPARATOR . $language . '.neon';
         if (!file_exists($file)) {
             if ($this->fallbackLanguage === false || ($this->fallbackLanguage = $language)) {
                 throw new InvalidArgumentException('Language file "' . $file . '" does not exist');
             }
             return $this->setLanguage($this->fallbackLanguage);
         }
         $neon = Neon::decode(file_get_contents($file));
         $this->cacheStorage->write('translator_' . $language, $neon, []);
         $this->strings[$language] = $neon;
     } else {
         $this->strings[$language] = $cache;
     }
     $this->language = $language;
     if ($this->debug) {
         Debugger::getBar()->getPanel('Translator')->addLanguage($language, $this->strings[$language]);
     }
 }
Пример #2
0
 /**
  * @param array $resources
  * @param bool $minify
  * @param string $baseDir
  * @throws AssetsException
  * @return array
  */
 public function getAssets(array $resources, $minify, $baseDir)
 {
     $config = [];
     $return = [];
     foreach ($resources as $resource) {
         $contents = file_get_contents($resource);
         $decompiled = Strings::endsWith($resource, '.json') ? json_decode($contents, TRUE) : Neon::decode($contents);
         $config = \Nette\DI\Config\Helpers::merge($config, $decompiled);
     }
     foreach ($config as $moduleArray) {
         foreach ($moduleArray as $type => $typeArray) {
             if (!isset(self::$supportTypes[$type])) {
                 throw new AssetsException("Found section '{$type}', but expected one of " . implode(', ', array_keys(self::$supportTypes)));
             }
             foreach ($typeArray as $minified => $assets) {
                 if ($minify) {
                     $return[$type][$minified] = TRUE;
                     continue;
                 }
                 foreach ((array) $assets as $row) {
                     if (strpos($row, '*') !== FALSE) {
                         /** @var \SplFileInfo $file */
                         foreach (Finder::findFiles(basename($row))->in($baseDir . '/' . dirname($row)) as $file) {
                             $return[$type][$minified][] = dirname($row) . '/' . $file->getBasename();
                         }
                     } else {
                         $return[$type][$minified][] = $row;
                     }
                 }
             }
         }
     }
     return $return;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     try {
         $messages = Neon\Neon::decode(file_get_contents($resource));
     } catch (Nette\Utils\NeonException $e) {
         throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
     } catch (Nette\Neon\Exception $e) {
         throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
     }
     if (empty($messages)) {
         $messages = array();
     }
     if (!is_array($messages)) {
         throw new InvalidResourceException(sprintf('The file "%s" must contain a Neon array.', $resource));
     }
     $catalogue = parent::load($messages, $locale, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
Пример #4
0
 /**
  * @param string $schemaFile Path to a *.neon file to read from disk
  * @param string $prefix
  */
 function __construct($schemaFile, $prefix, $dbVersion)
 {
     $neonSchema = file_get_contents($schemaFile);
     $this->dbVersion = $dbVersion;
     $this->prefix = $prefix;
     $this->schema = $this->useSchemaForCurrentVersion(Neon::decode($neonSchema));
 }
Пример #5
0
 /**
  * @param $name
  * @return array
  */
 protected function loadConfiguration($name)
 {
     if (!$this->hasConfiguration($name)) {
         throw new InvalidArgumentException("Configuration with name '{$name}' not exist.", Exception::MISSING_CONFIGURATION);
     }
     return Nette\Neon\Neon::decode(file_get_contents($this->getFilePath($name)));
 }
Пример #6
0
 /**
  * @param Configurator $configurator
  */
 protected function loadConfigFiles(Configurator $configurator)
 {
     if ($this->autoloadConfig === TRUE || is_array($this->autoloadConfig)) {
         $scanDirs = $this->autoloadConfig === TRUE ? [$this->appDir] : $this->autoloadConfig;
         $cache = $this->createCache();
         $files = $cache->load(self::CACHE_NAMESPACE);
         if ($files === NULL) {
             $files = [0 => []];
             foreach (Finder::findFiles('*.neon')->from($scanDirs) as $path => $file) {
                 $content = Neon::decode(file_get_contents($path));
                 if (!is_array($content) || !array_key_exists('autoload', $content)) {
                     continue;
                 }
                 $autoload = Arrays::get($content, ['autoload', 0], FALSE);
                 if ($autoload === FALSE) {
                     continue;
                 }
                 $autoload = is_int($autoload) ? $autoload : 0;
                 if (!isset($files[$autoload])) {
                     $files[$autoload] = [];
                 }
                 $files[$autoload][] = $path;
             }
             $cache->save(self::CACHE_NAMESPACE, $files);
         }
         foreach ($files as $priorityFiles) {
             foreach ($priorityFiles as $config) {
                 $configurator->addConfig($config);
             }
         }
     }
     foreach ($this->configs as $config) {
         $configurator->addConfig($config);
     }
 }
Пример #7
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));
 }
Пример #8
0
 /**
  * @param  string  $fileName
  * @return array
  * @throws Exception
  */
 public function load($fileName)
 {
     $file = $this->getHome() . '/' . $fileName;
     if (!file_exists($file) && !touch($file)) {
         throw new \Exception();
     }
     return (array) Neon::decode(file_get_contents($file));
 }
Пример #9
0
 /**
  * @return EntityManager
  */
 static function create()
 {
     $devMode = true;
     $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__), $devMode);
     $neonConfig = file_get_contents(__DIR__ . '/../config/config.local.neon');
     // yuck
     $neonConfig = Neon::decode($neonConfig);
     return EntityManager::create($neonConfig['parameters']['doctrine'], $config);
 }
Пример #10
0
 /**
  * @return mixed
  */
 public function createMenu()
 {
     $neon = $this->cache->load('menu');
     if ($neon === NULL) {
         $neon = Neon::decode(file_get_contents($this->filename));
         $this->cache->save('menu', $neon, array(Cache::FILES => $this->filename));
     }
     return $neon;
 }
Пример #11
0
 /**
  * @param SplFileInfo $articleDirectory
  * @param string $relativePath
  * @return array
  */
 private function getMeta($articleDirectory, $relativePath)
 {
     $filePath = sprintf('%s/%s', $articleDirectory->getRealPath(), self::META_FILE_NAME);
     $data = Neon::decode(file_get_contents($filePath));
     $data['perex'] = $this->parsedown->text($data['perex']);
     $data['publishedAt'] = $data['publishedAt'] ? DateTime::from($data['publishedAt']) : null;
     $data['imagePath'] = "{$relativePath}/" . self::IMAGE_NAME;
     $data['keyIdentifier'] = $this->parseKeyIdentifier($relativePath);
     return $data;
 }
Пример #12
0
 /**
  * @param string $path
  * @return HashMap
  */
 public function load($path)
 {
     if (!file_exists($path)) {
         throw new FileNotFoundException("File '{$path}' not found.");
     }
     return HashMap::from($this->cache->load($path, function (&$dependencies) use($path) {
         $dependencies[Cache::FILES] = $path;
         return Neon::decode(file_get_contents($path));
     }), TRUE);
 }
Пример #13
0
 public function loadConfiguration()
 {
     $this->defaults = Nette\Neon\Neon::decode(file_get_contents(__DIR__ . '/defaults.neon'))['hyperrow'];
     $config = $this->getConfig($this->defaults);
     Validators::assertField($config, 'nestedTransactions', 'bool');
     $builder = $this->getContainerBuilder();
     $builder->addDefinition($this->prefix('config'))->setClass(Config::class, [$config]);
     $builder->addDefinition($this->prefix('factory'))->setClass(Factory::class, [$config['classes']['selection']['mapping'], $config['classes']['row']['mapping']]);
     $builder->addDefinition($this->prefix('generator'))->setClass(Generator::class, [$config])->setAutowired(FALSE);
 }
Пример #14
0
 /**
  * Load biller configuration
  *
  * @param string|null $file
  */
 protected function loadConfiguration($file = NULL)
 {
     if ($file) {
         $this->config = Neon::decode(file_get_contents($file));
         return;
     }
     if (!$this->configFile) {
         throw new InvalidStateException("No configuration file set for biller '" . get_class($this) . "'");
     }
     $this->config = Neon::decode(file_get_contents($this->configFile));
 }
Пример #15
0
 protected function textToArray($text)
 {
     return strlen($text) === 0 ? NULL : Nette\Neon\Neon::decode($text);
     /*$data = [];
     		$pairs = explode(PHP_EOL, $text);
     		foreach($pairs as $pair) {
     			list($key, $value) = explode('=>', $pair);
     			$data[trim($key)] = trim($value);
     		}
     		return $data;*/
 }
Пример #16
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);
 }
Пример #17
0
 /**
  * @param string $file
  *
  * @return Configuration
  */
 private function readConfiguration($file)
 {
     $definition = Neon::decode(file_get_contents($file));
     $dir = dirname($file);
     assert(isset($definition['namespace']));
     assert(isset($definition['output']));
     $this->constants = isset($definition['constants']) ? $definition['constants'] : [];
     $this->values = isset($definition['values']) ? $definition['values'] : [];
     Helper::rmDirRec($dir . DIRECTORY_SEPARATOR . $definition['output'], true);
     return new Configuration($definition['output'], $definition['namespace'], $dir);
 }
 public static function getTypes()
 {
     if (!self::$types) {
         self::$types = [];
         $raw = file_get_contents(__DIR__ . '/../../../config/badges.neon');
         $config = Neon::decode($raw);
         foreach ($config['events']['subscribers'] as $class) {
             self::$types[] = $class;
         }
     }
     return self::$types;
 }
Пример #19
0
 /**
  * @return void
  */
 protected function loadTexts()
 {
     if (!is_null($this->texts)) {
         return;
     }
     $default = Neon::decode(file_get_contents("{$this->folder}/en.neon"));
     $lang = [];
     if ($this->lang != "en" and is_file("{$this->folder}/{$this->lang}.neon")) {
         $lang = Neon::decode(file_get_contents("{$this->folder}/{$this->lang}.neon"));
     }
     $this->texts = array_merge($default, $lang);
 }
Пример #20
0
 /**
  * @param string $path
  */
 public function generateFromNeonFile($path)
 {
     $definition = Neon::decode(file_get_contents($path));
     assert(isset($definition['class']));
     assert(isset($definition['type']));
     assert($definition['type'] === 'in-place');
     $data = $definition['data'];
     $output = $this->configuration->getDir() . DIRECTORY_SEPARATOR . $this->configuration->getOutputFolder() . DIRECTORY_SEPARATOR . $definition['class'] . '.php';
     $consts = Helper::createStringConstants($data);
     $node = $this->createClassFromData($definition['class'], $this->configuration->getNamespace(), $consts);
     $prettyPrinter = new PrettyPrinter\Standard();
     file_put_contents($output, $prettyPrinter->prettyPrintFile([$node]));
 }
Пример #21
0
 /**
  * Build phinx config from config.local.neon
  * @return array
  */
 private function buildConfig()
 {
     $configData = array('paths' => array('migrations' => '%%PHINX_CONFIG_DIR%%/migrations'), 'environments' => array('default_migration_table' => 'phinxlog', 'default_database' => 'local'));
     foreach (Finder::findFiles('config.*.neon')->in(__DIR__ . $this->configsDir) as $configFile) {
         $neon = Neon::decode(file_get_contents($configFile->getRealPath()));
         if ($neon) {
             $dbName = substr($configFile->getBaseName(), 7, -5);
             $dbData = $neon['parameters']['database']['default'];
             $configData['environments'][$dbName] = array('adapter' => $dbData['adapter'], 'host' => $dbData['host'], 'name' => $dbData['dbname'], 'user' => $dbData['user'], 'pass' => $dbData['password'], 'port' => 3306, 'chaarset' => 'utf8');
         }
     }
     return $configData;
 }
Пример #22
0
 protected function getNames($lang)
 {
     $neon = Neon::decode(file_get_contents(__DIR__ . '/simpleCalData.neon'));
     if (array_key_exists($lang, $neon)) {
         $wdays = $this->truncateWdays($neon[$lang]['wdays']);
         if ($this->firstDay === self::FIRST_MONDAY) {
             array_push($wdays, array_shift($wdays));
         }
         return array('monthNames' => $neon[$lang]['monthNames'], 'wdays' => $wdays);
     } else {
         throw new \LogicException('Specified language is not supported.');
     }
 }
Пример #23
0
 function __construct()
 {
     $defaultsFile = VERSIONPRESS_PLUGIN_DIR . '/vpconfig.defaults.neon';
     $customConfigFile = VERSIONPRESS_PLUGIN_DIR . '/vpconfig.neon';
     $this->defaults = array_merge($this->defaults, Neon::decode(file_get_contents($defaultsFile)));
     if (file_exists($customConfigFile)) {
         $this->customConfig = Neon::decode(file_get_contents($customConfigFile));
         if ($this->customConfig === null) {
             $this->customConfig = array();
         }
     }
     $this->mergedConfig = array_merge($this->defaults, $this->customConfig);
     $this->gitBinary = $this->mergedConfig['git-binary'];
 }
Пример #24
0
 /**
  * Loads the config file and parses it.
  *
  * @param string $config The path to the config file.
  * @throws \Exception on read error.
  */
 public function __construct($config)
 {
     try {
         // Open the file and surpress errors; we'll do our own error handling here.
         $data = @file_get_contents($config);
         if (!empty($data) && is_string($data)) {
             $this->config = Neon::decode(file_get_contents($config));
         } else {
             throw new ConfigurationException('The configuration could not be loaded. Please check the file ' . $config . ' exists and is readable/not corrupt.');
         }
     } catch (\Exception $e) {
         throw new ConfigurationException('Configuration syntax error: ' . $e->getMessage());
     }
 }
Пример #25
0
 /**
  * Configures VersionPress
  *
  * ## OPTIONS
  *
  * <key>
  * : The name of the option to set.
  *
  * [<value>]
  * : The new value. If missing, just prints out the option.
  *
  * @when before_wp_load
  */
 public function config($args, $assoc_args)
 {
     $configFile = __DIR__ . '/../../vpconfig.neon';
     $configContents = "";
     if (file_exists($configFile)) {
         $configContents = file_get_contents($configFile);
     }
     if (count($args) === 1) {
         $config = Neon::decode($configContents);
         WP_CLI::out(@$config[$args[0]]);
         return;
     }
     $configContents = $this->updateConfigValue($configContents, $args[0], $args[1]);
     file_put_contents($configFile, $configContents);
 }
Пример #26
0
 public function setup()
 {
     try {
         // Open the file and surpress errors; we'll do our own error handling here.
         $data = @file_get_contents(WPHP_ROOT_DIR . '/config.neon');
         if (!empty($data) && is_string($data)) {
             $decoded = Neon::decode($data);
         } else {
             throw new ConfigurationException('The configuration could not be loaded. Please check the file config.neon file exists and is readable/not corrupt.');
         }
     } catch (\Exception $e) {
         throw new ConfigurationException('Configuration syntax error: ' . $e->getMessage());
     }
     $this->storage = new ConfigurationStorage($decoded);
 }
Пример #27
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);
 }
Пример #28
0
 private function load($configPath)
 {
     if (!is_readable($configPath)) {
         throw new \InvalidArgumentException('Config is not readable.');
     }
     $config = Neon::decode(file_get_contents($configPath));
     if (isset($config['mdox'])) {
         $config = $config['mdox'];
     }
     if (isset($config['syntax'])) {
         $this->syntax = $config['syntax'];
     }
     if (isset($config['html5'])) {
         $this->html5 = (bool) $config['html5'];
     }
 }
Пример #29
0
 private function getConfig(InputInterface $input, OutputInterface $output)
 {
     $config = [];
     if ($configFile = $input->getOption('config')) {
         if (!file_exists($configFile)) {
             $output->writeLn("<error>Config file '{$configFile}' does not exist</errro>");
             exit(1);
         }
         $raw = file_get_contents($configFile);
         $config = Neon::decode($raw);
     }
     if (!isset($config['skip']) || !is_array($config['skip'])) {
         $config['skip'] = [];
     }
     return $config;
 }
Пример #30
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);
 }