public function validate($yamlFile, $dataToValidate, $validateSchema = false) { if (empty($yamlFile)) { return true; } if (!is_file($yamlFile)) { throw new SphringException("File '%s' cannot be found.", $yamlFile); } $this->yamlarh->setFileName($yamlFile); $schema = $this->yamlarh->parse(); $schema = new MetaYaml($schema, $validateSchema); return $schema->validate($dataToValidate); }
/** * Extend from a yml file * @param string $file */ public function addExtendFromFile($file) { if (!is_file($file)) { return; } $yamlarh = new Yamlarh($file); if (empty($yamlarh)) { return; } $parsedYml = $yamlarh->parse(); foreach ($parsedYml as $extendNodeName => $extendNodeNameInfo) { $this->addExtendFromArray($extendNodeName, $extendNodeNameInfo); } }
private function injectYaml($yamls, $beanId) { $array = array(); if (!is_array($yamls)) { $yamls = array($yamls); } foreach ($yamls as $key => $yaml) { if ($this->isNotFileAbsolute($yaml)) { $yaml = $this->pathinfoContext['dirname'] . '/' . $yaml; } else { $yaml = ROOT . '/' . $yaml; } try { $yamlArh = new Yamlarh($yaml); $array[$key] = $yamlArh->parse(); } catch (Exception $e) { throw new IocArtException("Error in bean '" . $beanId . "': " . $e->getMessage()); } } return $array; }
private function parseYaml() { $this->sphringEventDispatcher->dispatch(SphringEventEnum::SPHRING_START_LOAD_CONTEXT, new EventSphring($this)); if (empty($this->context)) { $this->context = $this->yamlarh->parse(); } $this->sphringEventDispatcher->dispatch(SphringEventEnum::SPHRING_FINISHED_LOAD_CONTEXT, new EventSphring($this)); }
- "arhframe/yamlarh: 1.*" CONFIG; // you need melody: https://github.com/sensiolabs/melody $template = __DIR__ . '/../template/plugin-description.yml'; use Arhframe\Yamlarh\Yamlarh; use Symfony\Component\Yaml\Yaml; $output = __DIR__ . '/../../repo-index.yml'; if (is_file($output)) { $currentData = Yaml::parse(file_get_contents($output)); $date = date('Y-m-d', $currentData['plugins']['created']); } else { $date = date('Y-m-d'); } $date_updated = date('Y-m-d'); $yamlarh = new Yamlarh($template); $data = $yamlarh->parse(); $binaries =& $data['plugins']['binaries']; foreach ($binaries as &$binary) { $path = pathinfo($binary['url'], PATHINFO_BASENAME); $checksum = sha1_file(__DIR__ . '/../../out/' . $path); $binary['checksum'] = $checksum; } $dataString = Yaml::dump($data, 10, 2); //sanitize just for repo-index.yml in cloudfoundry community plugin repo $dataString = str_replace("'", "", $dataString); $dataString = str_replace("null", "", $dataString); $dataString = str_replace("\n -", "", $dataString); $dataString = str_replace(" platform:", "- platform:", $dataString); $dataString = str_replace("authors:\n name:", "authors:\n - name:", $dataString); /*******************************/ file_put_contents($output, $dataString);
/** * @param $file * @return array */ public function loadYml($file) { $yamlArh = new Yamlarh($file); return $yamlArh->parse(); }