public static function parseConfig($path) { try { $content = file_get_contents($path); self::$params = Neon::decode($content); } catch (Exception $e) { error_log($e->getMessage()); throw new configException('Cannot load config file'); } }
protected function attached($presenter) { parent::attached($presenter); if (!$presenter instanceof Presenter) { return; } //připojen presenter if (!isset($presenter->page)) { throw new InvalidStateException('FieldsPlugin attached to uncompatible Presenter'); } $this->page = $presenter->page; $this->template->page = $presenter->page; $this->template->lang = $presenter->lang; $this->template->setTranslator(new TranslationsModel($presenter->lang)); //parse fields $json = $this->page->getParent()->getMeta('.sectionFields'); $sectionFields = array(); try { if ($json) { $sectionFields = Neon::decode($json); } } catch (Exception $e) { $m = htmlspecialchars($e->getMessage()); $this->error .= "<div class='control-group' title=\"{$m}\">.sectionFields not valid</div>"; } $fields = array(); $json = $this->page->getMeta('.fields'); try { if ($json) { $fields = Neon::decode($json); } } catch (Exception $e) { $m = htmlspecialchars($e->getMessage() . "\""); $this->error .= "<div class='control-group' title=\"{$m}\">.fields not valid</div>"; } $fields = array_merge($fields, $sectionFields); foreach ($fields as $k => $f) { if (substr($k, -1) == '_') { $k .= $this->page->lang; } $this->fields[$k] = $f; } }
<pre> <?php require 'Neon.php'; $data = Neon::decode(' # neon file - edit it now! name: Homer address: street: 742 Evergreen Terrace city: Springfield country: USA phones: { home: 555-6528, work: 555-7334 } children: - Bart - Lisa - Maggie entity: Column(type="integer") '); print_r($data); echo '<hr>'; $neon = Neon::encode($data, Neon::BLOCK); echo $neon;
/** * Reads configuration from NEON file. * @param string file name * @return array */ public function load($file) { return $this->process((array) Neon::decode(file_get_contents($file))); }
/** * For each source check for a config file and mix in the options. * * @internal * @param array|string $sources * @return array */ protected function config($sources) { $sources = (array) $sources; $options = Config::get('apigen::default'); $options['source'] = array(); // Walk through each source and mix in any ApiGen options found. If // no options are found then we just add the source to the list. foreach ($sources as $path) { if (is_file($path . 'apigen.neon')) { $config = Neon::decode(file_get_contents($path . 'apigen.neon')); // Do not allow the user to override the destination, this // should be done using the bundle config file instead. unset($config['destination']); } else { $config = array(); } // If apigen.neon did not specify a source then we shall do it // ourselves. Note: source needs to be absolute or relative to // the base path, not the bundle path. if (!isset($config['source'])) { $config['source'] = $path; } // Recursively merge in the config so we get all the excludes. $options = array_merge_recursive($options, $config); } // Only allow a title when there's once source if (count($sources) > 1 and isset($options['title'])) { unset($options['title']); } return $options; }