/** * Return search specs * * @param string $filename config file name * * @return array */ public function get($filename) { // Load data if it is not already in the object's cache: if (!isset($this->searchSpecs[$filename])) { // Connect to searchspecs cache: $sm = $this->getServiceLocator(); $cache = is_object($sm) && $sm->has('CacheManager') ? $sm->get('CacheManager')->getCache('searchspecs') : false; // Determine full configuration file path: $fullpath = Reader::getBaseConfigPath($filename); $local = Reader::getLocalConfigPath($filename); // Generate cache key: $key = $filename . '-' . filemtime($fullpath); if (!empty($local)) { $key .= '-local-' . filemtime($local); } $key = md5($key); // Generate data if not found in cache: if (!$cache || !($results = $cache->getItem($key))) { $results = Yaml::load(file_get_contents($fullpath)); if (!empty($local)) { $localResults = Yaml::load(file_get_contents($local)); foreach ($localResults as $key => $value) { $results[$key] = $value; } } if ($cache) { $cache->setItem($key, $results); } } $this->searchSpecs[$filename] = $results; } return $this->searchSpecs[$filename]; }
protected function conditionalInclude($definition, &$value, $key) { $parsed = $this->parse($definition); $yamlFile = $parsed[0]; if (count($parsed) == 1) { $result = true; } else { if (count($parsed) == 2) { $leftValue = $parsed[1]; $operation = 'eq'; $rightValue = $parsed[2]; } else { $leftValue = $parsed[1]; $operation = $parsed[2]; $rightValue = $parsed[3]; } $result = $this->checkCondition($operation, $leftValue, $rightValue); } if ($result) { $yaml = Horde_Yaml::load(file_get_contents($this->props['path'] . '/' . $yamlFile)); if (is_array($yaml) && count($yaml) == 1 && array_key_exists($key, $yaml)) { $value = $yaml[$key]; } else { $value = $yaml; } } return $result; }
/** * @dataProvider includeDataProvider */ public function testInclude($yamlFile, $yamlResultFile) { $yamlString = file_get_contents($this->fixtures . $yamlFile); $yaml = Horde_Yaml::load($yamlString); $yamlResultString = file_get_contents($this->fixtures . $yamlResultFile); $yamlResult = Horde_Yaml::load($yamlResultString); $this->directives->process($yaml); $this->assertEquals(json_encode($yamlResult), json_encode($yaml)); }
function __construct($directory, $profileName) { $this->filePath = "{$directory}/{$profileName}.yml"; $this->externalWriter = new Tiki_Profile_Writer_ExternalWriter("{$directory}/{$profileName}"); if (file_exists($this->filePath)) { $content = file_get_contents($this->filePath); $this->data = Horde_Yaml::load($content); } else { $this->data = array('permissions' => array(), 'preferences' => array(), 'objects' => array(), 'unknown_objects' => array()); } }
function getData() { if ($this->data) { return $this->data; } $defaults = array('preserve' => 'n', 'guards' => array()); $data = array_merge($defaults, $this->obj->getData()); foreach ($data['guards'] as &$guard) { if (is_string($guard[2])) { $guard[2] = reset(Horde_Yaml::load("- " . $guard[2])); } } $data = Tiki_Profile::convertYesNo($data); return $this->data = $data; }
/** * NOTE: libsyck extension doesn't have a 'string' loader, so we have to write a tmp file. Kinda slow... in any case though shouldn't really use YAML strings * for anything but testing stuff anyway * * @param * @return * @throws */ public static function loadString($string) { if (function_exists('yaml_parse')) { // returns array() if no data, NULL if error. $a = yaml_parse($string); if ($a === NULL || $a === false) { throw new WFException("Error processing YAML string."); } return $a; } else { if (function_exists('syck_load')) { // extension version $file = tempnam("/tmp", 'syck_yaml_tmp_'); file_put_contents($file, $string); return self::loadFile($file); } else { // php version return Horde_Yaml::load($string); } } }
/** * Support method for _getSearchSpecs() -- load the specs from cache or disk. * * @return void * @access private */ private function _loadSearchSpecs() { // Generate cache key: $key = md5(basename($this->searchSpecsFile) . '-' . filemtime($this->searchSpecsFile)); // Load cache manager: $cache = new VuFindCache($this->_specCache, 'searchspecs'); // Generate data if not found in cache: if (!($results = $cache->load($key))) { $results = Horde_Yaml::load(file_get_contents($this->searchSpecsFile)); $cache->save($results, $key); } $this->_searchSpecs = $results; }
private function loadYaml($content) { $this->pageContent = $content; $pos = 0; $this->data = array(); $matches = WikiParser_PluginMatcher::match($content); $parser = new WikiParser_PluginArgumentParser(); foreach ($matches as $match) { $arguments = $parser->parse($match->getArguments()); if ($match->getName() == 'code' && isset($arguments['caption']) && $arguments['caption'] == 'YAML' || $match->getName() == 'profile') { $yaml = $match->getBody(); $data = Horde_Yaml::load($yaml); foreach ($data as $key => $value) { if (array_key_exists($key, $this->data)) { $this->data[$key] = $this->mergeData($this->data[$key], $value); } else { $this->data[$key] = $value; } } } } $this->fetchExternals(); $this->getObjects(); }
public function testShouldNotWrapStringsWithCommentDelimiterForFoldedStrings() { // stringWithHash: 'string # this is part of the string, not a comment' $value = array('foo' => 'string # this is not a comment but it is a long string that gets folded', 'bar' => 2); $expected = "---\n" . "foo: >\n" . " string # this is not a comment but it is\n" . " a long string that gets folded\n" . "bar: 2\n"; $actual = $this->dumper->dump($value); $this->assertEquals($expected, $actual); // round-trip assert $this->assertEquals($value, Horde_Yaml::load($actual), "Error: expected: " . print_r($value, true) . ", actual: " . print_r(Horde_Yaml::load($actual), true) . ", from: >" . $actual . "<"); // fails presently due to bug in loader which causes an extra "\n" at end of string }
/** * Handle PHP serialized data. * * @param string &$data Data to check for serialized PHP types. */ protected function _unserialize(&$data) { if (substr($data, 0, 5) != '!php/') { return; } $first_space = strpos($data, ' '); $type = substr($data, 5, $first_space - 5); $class = null; if (strpos($type, '::') !== false) { list($type, $class) = explode('::', $type); if (!in_array($class, Horde_Yaml::$allowedClasses)) { throw new Horde_Yaml_Exception("{$class} is not in the list of allowed classes"); } } switch ($type) { case 'object': if (!class_exists($class)) { throw new Horde_Yaml_Exception("{$class} is not defined"); } $reflector = new ReflectionClass($class); if (!$reflector->implementsInterface('Serializable')) { throw new Horde_Yaml_Exception("{$class} does not implement Serializable"); } $class_data = substr($data, $first_space + 1); $serialized = 'C:' . strlen($class) . ':"' . $class . '":' . strlen($class_data) . ':{' . $class_data . '}'; $data = unserialize($serialized); break; case 'array': case 'hash': $array_data = substr($data, $first_space + 1); $array_data = Horde_Yaml::load('a: ' . $array_data); if (is_null($class)) { $data = $array_data['a']; } else { if (!class_exists($class)) { throw new Horde_Yaml_Exception("{$class} is not defined"); } $array = new $class(); if (!$array instanceof ArrayAccess) { throw new Horde_Yaml_Exception("{$class} does not implement ArrayAccess"); } foreach ($array_data['a'] as $key => $val) { $array[$key] = $val; } $data = $array; } break; } }
private function loadYaml($url) { $content = tiki_get_remote_file($url); $content = html_entity_decode($content); $content = str_replace("\r", '', $content); $begin = strpos($content, "\n\n"); if (!$begin) { return false; } $content = substr($content, $begin + 2); $this->pageContent = $content; $base = strpos($content, '{CODE(caption=>YAML'); $begin = strpos($content, ')}', $base) + 2; $end = strpos($content, '{CODE}', $base); if (false === $base || false === $begin || false === $end) { return false; } $yaml = substr($content, $begin, $end - $begin); $this->data = Horde_Yaml::load($yaml); $this->getObjects(); }
// create a request mapper object to regex-match the URI to a Route $request = new Mapper(); // add a new Route $request->connect('static/:staticresource', array('requirements' => array('[A-Za-z0-9_.]+'))); // load static-file-cache and debug aspects //include $GLOBALS['PATH']['plugins'] . 'renderer.php'; // this doesn't do anything because the aspect-filter was deleted XXX //$request->routematch(); $request->connect('admin', array('action' => 'index', 'resource' => 'admin')); /** * read the configuration file */ include $GLOBALS['PATH']['library'] . 'yaml.php'; $loader = new Horde_Yaml(); if (file_exists($app . 'config.yml')) { extract($loader->load(file_get_contents($app . 'config.yml'))); extract(${$env}['enable_db']); } else { $env = array('app_folder' => 'app'); } // if app folder exists, re-config for the app if (is_dir($env['app_folder'])) { $app = $env['app_folder'] . DIRECTORY_SEPARATOR; $appdir = $app; if (file_exists($app . 'config' . DIRECTORY_SEPARATOR . 'config.yml')) { extract($loader->load(file_get_contents($app . 'config' . DIRECTORY_SEPARATOR . 'config.yml'))); extract(${$env}['enable_db']); if (isset($env['boot'])) { $appdir = $app . $env['boot'] . DIRECTORY_SEPARATOR; } else { $appdir = $app . 'omb' . DIRECTORY_SEPARATOR;
public function getMenuActions($account, $menu) { static $menuActions; if (!empty($menuActions[$menu])) { return $menuActions[$menu]; } $sql = "SELECT accounts.code AS account, menus.name AS description, " . "actions.name AS action, menu_entries.digit AS digit, " . "menu_entries.args AS args FROM menu_entries " . "INNER JOIN menus ON menu_entries.menu_id = menus.id " . "INNER JOIN actions ON menu_entries.action_id = actions.id " . "INNER JOIN accounts ON menus.account_id = accounts.id " . "WHERE accounts.code = ? AND menus.name = ?"; $values = array($account, $menu); $msg = 'SQL query in Shout_Driver_Sql#getMenuActions(): ' . $sql; Horde::log($msg, 'DEBUG'); $result = $this->_db->query($sql, $values); if ($result instanceof PEAR_Error) { throw new Shout_Exception($result); } $row = $result->fetchRow(DB_FETCHMODE_ASSOC); if ($row instanceof PEAR_Error) { throw new Shout_Exception($row); } $menuActions[$menu] = array(); while ($row && !$row instanceof PEAR_Error) { $menuActions[$menu][$row['digit']] = array('digit' => $row['digit'], 'action' => $row['action'], 'args' => Horde_Yaml::load($row['args'])); $row = $result->fetchRow(DB_FETCHMODE_ASSOC); } $result->free(); return $menuActions[$menu]; }
/** * Support method for _getSearchSpecs() -- load the specs from cache or disk. * * @return void * @access private */ private function _loadSearchSpecs() { global $configArray; // Turn relative path into absolute path: $fullPath = $configArray['Site']['local'] . '/' . $this->searchSpecsFile; // Check for a local override file: $local = str_replace('.yaml', '.local.yaml', $fullPath); $local = file_exists($local) ? $local : false; // Generate cache key: $key = basename($fullPath) . '-' . filemtime($fullPath); if ($local) { $key .= '-' . basename($local) . '-' . filemtime($local); } $key = md5($key); // Load cache manager: $cache = new VuFindCache($this->_specCache, 'searchspecs'); // Generate data if not found in cache: if (!($results = $cache->load($key))) { $results = Horde_Yaml::load(file_get_contents($fullPath)); if ($local) { $localResults = Horde_Yaml::load(file_get_contents($local)); foreach ($localResults as $key => $value) { $results[$key] = $value; } } $cache->save($results, $key); } $this->_searchSpecs = $results; }
public function parseYaml($yaml, $entity = null) { if (empty($yaml)) { return null; } return Horde_Yaml::load($yaml); }
public function testComplexParse() { $yaml = "databases:\n" . " - name: spartan\n" . " notes:\n" . " - Needs to be backed up\n" . " - Needs to be normalized\n" . " type: mysql\n"; $expected = array('databases' => array(array('name' => 'spartan', 'notes' => array('Needs to be backed up', 'Needs to be normalized'), 'type' => 'mysql'))); $actual = Horde_Yaml::load($yaml); $this->assertEquals($expected, $actual); }
/** * Parse the fixture data from the given array. This will * take the yaml file and validate and set the records/options. */ private function _parseYml($ymlName, $fixturesPath) { // only parse if not in cache if (!isset(self::$_ymlCache[$ymlName])) { $fixtureFile = "{$fixturesPath}/{$ymlName}.yml"; // Parse yml file if (!file_exists($fixtureFile)) { throw new Mad_Test_Exception('The fixture file: "' . $fixtureFile . '" does not exist.'); } // dynamic fixtures ob_start(); include "madview://{$fixtureFile}"; $fixtureData = ob_get_clean(); $records = Horde_Yaml::load($fixtureData); // Parse options $options = isset($records['options']) ? $records['options'] : array(); $valid = array('table' => $ymlName, 'log' => null, 'requires' => array(), 'before' => array(), 'after' => array(), 'teardown' => array()); $options = Mad_Support_Base::assertValidKeys($options, $valid); unset($records['options']); self::$_ymlCache[$ymlName] = array('records' => $records, 'options' => $options); } $this->_records = self::$_ymlCache[$ymlName]['records']; $this->_options = self::$_ymlCache[$ymlName]['options']; // Parse required fixtures for this load foreach ($this->_options['requires'] as $required) { $this->_required[] = new Mad_Test_Fixture_Base($this->_connection, $required); } }
/** * YAML形式の設定をパースします。 * @param $yaml YAML形式の文字列 * @return array config */ public function parseYAML($yaml) { $yamlConfig = Horde_Yaml::load($yaml); if (!is_array($yamlConfig)) { throw new Teeple_Exception("Validationの設定を解析できませんでした。"); } //$this->log->debug(var_export($yamlConfig, true)); $validationConfig = array(); foreach ($yamlConfig as $field => $validations) { $oneConfig = array(); $fields = explode('.', $field, 2); if (count($fields) == 2) { $oneConfig['label'] = $fields[1]; } $oneConfig['name'] = $fields[0]; $oneConfig['validation'] = $validations; array_push($validationConfig, $oneConfig); } //$this->log->debug(var_export($validationConfig, true)); return $validationConfig; }
function unserialize($type, $data) { $parts = explode(';', $type); $type = trim($parts[0]); if (empty($data)) { return null; } switch ($type) { case 'application/json': case 'text/javascript': if ($out = json_decode($data, true)) { return $out; } // Handle invalid JSON too... $fixed = preg_replace('/(\\w+):/', '"$1":', $data); $out = json_decode($fixed, true); return $out; case 'text/x-yaml': require_once 'Horde/Yaml.php'; require_once 'Horde/Yaml/Loader.php'; require_once 'Horde/Yaml/Node.php'; return Horde_Yaml::load($data); default: // Attempt anything... if ($out = $this->unserialize('application/json', $data)) { return $out; } if ($out = $this->unserialize('text/x-yaml', $data)) { return $out; } } }
/** * Converterを実行します。 * * @param Teeple_ActionBase $action * @param array $params */ private function doConverter($action, &$params) { $className = get_class($action); if (!defined($className . "::CONVERTER_CONFIG")) { return; } $yamlConfig = Horde_Yaml::load(constant($className . "::CONVERTER_CONFIG")); if (!is_array($yamlConfig)) { throw new Teeple_Exception("Converterの設定を解析できませんでした。"); } //$this->log->debug(var_export($yamlConfig, true)); $this->converterManager->execute($params, $yamlConfig); }