/** * Vytvoreni nove galerie * @param type $values - name,editor_id,public[bool],start_public,stop_public * * @return type */ public function addGallery($files, $galleryName, $conf = NULL) { if (!is_array($conf)) { $params = $this->context->getParameters(); $driveConfigPath = $params['projectDir'] . '/config/drive.neon'; if (!is_file($driveConfigPath)) { $driveConfigPath = __DIR__ . '/examples/gal.neon'; } $conf = \Nette\Utils\Neon::decode(file_get_contents($driveConfigPath)); $conf = $conf['gallery']; } $this->setStorage('gallery'); $userId = 0; if ($this->presenter) { $userId = $this->presenter->user->isLoggedIn() ? $this->presenter->user->getId() : 0; } $galPath = isset($conf['path']) && !empty($conf['path']) ? Strings::webalize($conf['path']) : ''; $id = $this->createGallery($galleryName, $userId, $galPath, serialize($conf)); $galleryFolder = $this->relativePath; $this->mkDir($this->getFullPath(TRUE) . '/thumbs', FALSE, TRUE); $this->mkDir($this->getFullPath(TRUE) . '/originals', FALSE, TRUE); $this->_addFilesToGallery($galleryFolder, $files, $userId, $id, $conf); if (isset($conf['preserveOriginals']) && !$conf['preserveOriginals']) { $this->setPath($galleryFolder); $this->rmDir($this->getFullPath(TRUE) . '/originals/'); } return $id; }
/** * Helper for string to array conversion. * * Here or ther I enable to use strings instead of arrays in parameters * of some methods. If you like the short array definition from PHP 5.4, * then you must like this, even better if you still have to rely on * PHP 5.3... * * The format is basically the Neon format ({@link http://ne-on.org/}, just * the surrounding brackets are added. So `a = b, e: mc2` will translate to * `array('a' => 'b', 'e' => 'mc2')` et cetera. * * @param array|string $value * @return array */ public static function strToArray($value) { if (!is_array($value)) { $value = Neon::decode('[' . $value . ']'); } return $value; }
private function parseConfig($path) { if (file_exists($path)) { return (array) \Nette\Utils\Neon::decode(file_get_contents($path)); } else { return array(); } }
/** * Generates configuration in NEON format. * @param array * @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::encode($tmp, Neon::BLOCK); }
/** * Constructor * * @param string $descriptionFile path to the file containing menu * description * @param string $htmlClass optional css class of the ul */ public function __construct($descriptionFile, $htmlId = null) { if (!is_file($descriptionFile)) { throw new Nette\FileNotFoundException("File {$descriptionFile} does not exists!"); } $data = file_get_contents($descriptionFile); if ($data === false) { throw new Nette\FileNotFoundException("File {$descriptionFile} is not readable!"); } $this->_items = Neon::decode($data); $this->_htmlId = $htmlId; }
public function createComponentMenu() { $file = APP_DIR . '/AdminModule/templates/menu.neon'; if (!is_file($file)) { throw new \Nette\FileNotFoundException("File {$file} does not exists!"); } $data = file_get_contents($file); if ($data === false) { throw new \Nette\FileNotFoundException("File {$file} is not readable!"); } return new \Menu(Neon::decode($data), 'menu'); }
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.'); } }
/** * @param LanguageEntity $language */ public function onSet(LanguageEntity $language) { if ($this->cache->load($language->id) === NULL) { $file = sprintf('%s/%s.neon', $this->localeDir, $language->code); $translations = []; if (file_exists($file) && is_readable($file)) { $translations = Neon::decode(file_get_contents($file)); $this->process($translations); } $this->cache->save($language->id, $translations, [Cache::FILES => $file]); } $this->translations = $this->cache->load($language->id); }
public function createComponentMenu() { $file = APP_DIR . '/SubmitModule/templates/menu.neon'; if (!is_file($file)) { throw new \Nette\FileNotFoundException("File {$file} does not exists!"); } $data = file_get_contents($file); if ($data === false) { throw new \Nette\FileNotFoundException("File {$file} is not readable!"); } $menuItems = Neon::decode($data); if ($this->user->isLoggedIn()) { $menuItems['Odhlásiť ' . $this->user->identity->data['login']] = 'Sign:out'; } else { $menuItems['Prihlásiť'] = 'Sign:in'; } return new \Menu($menuItems, 'menu'); }
public static function createForm($neonString, $form = null) { $config = Neon::decode($neonString); $form = is_null($form) ? new Form() : $form; if (is_null($config)) { return $form; } foreach (self::$properties as $atr) { if (isset($config[$atr])) { $form->{$atr} = $config[$atr]; } } if (isset($config['renderer'])) { $renderer = new $config['renderer']['class'](); $form->renderer = $renderer; } self::addControls($form, $config); return $form; }
public static function createGrid($model, $neonString) { $settings = Neon::decode($neonString); /** Create Grid and set the model */ $grid = new Grid(); $grid->setModel($model); /** Add columns */ foreach ($settings['columns'] as $key => $column) { $grid->addColumn($key, null, $column); } /** Create buttons */ foreach ($settings['buttons'] as $key => $button) { $call = empty($button['toolbar']) ? 'add' : 'addToolbar'; $call .= empty($button['window']) ? '' : 'Window'; $call .= empty($button['check']) ? 'Button' : 'CheckButton'; unset($button['toolbar']); unset($button['window']); unset($button['check']); call_user_func(array($grid, $call), $key, null, $button); } return $grid; }
private function decode($file) { $ext = \pathinfo($file, \PATHINFO_EXTENSION); switch ($ext) { case 'ini': $ini = \parse_ini_file('safe://' . $file, true, \INI_SCANNER_RAW); foreach ($ini as $key => $scope) { foreach ($scope as $key2 => $val) { $m = vBuilder\Parsers\ScalarParser::parseBool($val, $val); if (\is_numeric($m)) { $m = \intval($m); } $ini[$key][$key2] = $m; } } return $ini; case 'neon': return Nette\Utils\Neon::decode(file_get_contents('safe://' . $file)); default: return; } }
/** * Write NEON file. * @param mixed * @param string file * @return void */ public static function save($config, $file) { if (!file_put_contents($file, "# generated by Nette\n\n" . Neon::encode($config, Neon::BLOCK))) { throw new Nette\IOException("Cannot write file '$file'."); } }
public function parse($file) { $input = file_get_contents($file); return Neon::decode($input); }
public function __destruct() { file_put_contents(__DIR__ . '/../' . $this->neonPath, Utils\Neon::encode($this->neon, Utils\Neon::BLOCK)); }
/** * Prepares configuration. * * @return \ApiGen\Config * @throws \ApiGen\ConfigException If something in configuration is wrong. */ public function prepare() { // Command line options $cli = array(); $translator = array(); foreach ($this->options as $option => $value) { $converted = preg_replace_callback('~-([a-z])~', function ($matches) { return strtoupper($matches[1]); }, $option); $cli[$converted] = $value; $translator[$converted] = $option; } $unknownOptions = array_keys(array_diff_key($cli, self::$defaultConfig)); if (!empty($unknownOptions)) { $originalOptions = array_map(function ($option) { return (1 === strlen($option) ? '-' : '--') . $option; }, array_values(array_diff_key($translator, self::$defaultConfig))); $message = count($unknownOptions) > 1 ? sprintf('Unknown command line options "%s"', implode('", "', $originalOptions)) : sprintf('Unknown command line option "%s"', $originalOptions[0]); throw new ConfigException($message); } // Config file $neon = array(); if (empty($this->options) && $this->defaultConfigExists()) { $this->options['config'] = $this->getDefaultConfigPath(); } if (isset($this->options['config']) && is_file($this->options['config'])) { $neon = Neon::decode(file_get_contents($this->options['config'])); foreach (self::$pathOptions as $option) { if (!empty($neon[$option])) { if (is_array($neon[$option])) { foreach ($neon[$option] as $key => $value) { $neon[$option][$key] = $this->getAbsolutePath($value); } } else { $neon[$option] = $this->getAbsolutePath($neon[$option]); } } } $unknownOptions = array_keys(array_diff_key($neon, self::$defaultConfig)); if (!empty($unknownOptions)) { $message = count($unknownOptions) > 1 ? sprintf('Unknown config file options "%s"', implode('", "', $unknownOptions)) : sprintf('Unknown config file option "%s"', $unknownOptions[0]); throw new ConfigException($message); } } // Merge options $this->config = array_merge(self::$defaultConfig, $neon, $cli); // Compatibility with old option name "undocumented" if (!isset($this->config['report']) && isset($this->config['undocumented'])) { $this->config['report'] = $this->config['undocumented']; unset($this->config['undocumented']); } foreach (self::$defaultConfig as $option => $valueDefinition) { if (is_array($this->config[$option]) && !is_array($valueDefinition)) { throw new ConfigException(sprintf('Option "%s" must be set only once', $option)); } if (is_bool($this->config[$option]) && !is_bool($valueDefinition)) { throw new ConfigException(sprintf('Option "%s" expects value', $option)); } if (is_bool($valueDefinition) && !is_bool($this->config[$option])) { // Boolean option $value = strtolower($this->config[$option]); if ('on' === $value || 'yes' === $value || 'true' === $value || '' === $value) { $value = true; } elseif ('off' === $value || 'no' === $value || 'false' === $value) { $value = false; } $this->config[$option] = (bool) $value; } elseif (is_array($valueDefinition)) { // Array option $this->config[$option] = array_unique((array) $this->config[$option]); foreach ($this->config[$option] as $key => $value) { $value = explode(',', $value); while (count($value) > 1) { array_push($this->config[$option], array_shift($value)); } $this->config[$option][$key] = array_shift($value); } $this->config[$option] = array_filter($this->config[$option]); } // Check posssible values if (!empty(self::$possibleOptionsValues[$option])) { $values = self::$possibleOptionsValues[$option]; if (is_array($valueDefinition)) { $this->config[$option] = array_filter($this->config[$option], function ($value) use($values) { return in_array($value, $values); }); } elseif (!in_array($this->config[$option], $values)) { $this->config[$option] = ''; } } } // Unify character sets $this->config['charset'] = array_map('strtoupper', $this->config['charset']); // Process options that specify a filesystem path foreach (self::$pathOptions as $option) { if (is_array($this->config[$option])) { array_walk($this->config[$option], function (&$value) { if (file_exists($value)) { $value = realpath($value); } }); usort($this->config[$option], 'strcasecmp'); } else { if (file_exists($this->config[$option])) { $this->config[$option] = realpath($this->config[$option]); } } } // Unify directory separators foreach (array('exclude', 'skipDocPath') as $option) { $this->config[$option] = array_map(function ($mask) { return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $mask); }, $this->config[$option]); usort($this->config[$option], 'strcasecmp'); } // Unify prefixes $this->config['skipDocPrefix'] = array_map(function ($prefix) { return ltrim($prefix, '\\'); }, $this->config['skipDocPrefix']); usort($this->config['skipDocPrefix'], 'strcasecmp'); // Base url without slash at the end $this->config['baseUrl'] = rtrim($this->config['baseUrl'], '/'); // No progressbar in quiet mode if ($this->config['quiet']) { $this->config['progressbar'] = false; } // Check $this->check(); // Default template config $this->config['template'] = array('require' => array(), 'resources' => array(), 'templates' => array('common' => array(), 'optional' => array())); // Merge template config $this->config = array_merge_recursive($this->config, array('template' => Neon::decode(file_get_contents($fileName = $this->config['templateConfig'])))); $this->config['template']['config'] = realpath($fileName); // Check template $this->checkTemplate(); return $this; }
Nette\Utils\NeonEntity){$val=(object)array('value'=>$val->value,'attributes'=>$this->process($val->attributes));}$res[$key]=$val;}return$res;}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::encode($tmp,Neon::BLOCK);}}class