本文整理汇总了PHP中YAML::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP YAML::parse方法的具体用法?PHP YAML::parse怎么用?PHP YAML::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YAML
的用法示例。
在下文中一共展示了YAML::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
/**
* Fetch an L10n content string
*
* @param $key string YAML key of the desired text string
* @param $language string Optionally override the desired language
* @return mixed
*/
public static function fetch($key, $language = null, $lower = false)
{
$app = \Slim\Slim::getInstance();
$language = $language ? $language : Config::getCurrentLanguage();
$value = $key;
/*
|--------------------------------------------------------------------------
| Check for new language
|--------------------------------------------------------------------------
|
| English is loaded by default. If requesting a language not already
| cached, go grab it.
|
*/
if (!isset($app->config['_translations'][$language])) {
$app->config['_translations'][$language] = YAML::parse(Config::getTranslation($language));
}
/*
|--------------------------------------------------------------------------
| Resolve translation
|--------------------------------------------------------------------------
|
| If the set language is found and the key exists, return it. Falls back to
| English, and then falls back to the slug-style key itself.
|
*/
if (array_get($app->config['_translations'][$language]['translations'], $value, false)) {
$value = array_get($app->config['_translations'][$language]['translations'], $value);
} else {
$value = array_get($app->config['_translations']['en']['translations'], $value, $value);
}
return $lower ? strtolower($value) : $value;
}
示例2: __construct
/**
* Singleton pattern.
*
* @throws Exceptions\DatacashRequestException
*/
protected function __construct()
{
// Get the default configurations.
$env_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/environment.yaml"));
$datacash_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/datacash.yaml"));
$datacash_config = $datacash_config[$env_config['environment']]['parameters'];
// Set the configurations for the request.
if (!empty($datacash_config['server_url'])) {
$this->hostName = $datacash_config['server_url'];
} else {
throw new DatacashRequestException("Not set or invalid hostname.");
}
if (!empty($datacash_config['timeout'])) {
$this->timeout = $datacash_config['timeout'];
}
if (!empty($datacash_config['datacash_network_ssl_path'])) {
$this->sslCertPath = $datacash_config['datacash_network_ssl_path'];
// Do not set cert SSL verifiation if we don't have a certificate.
if (!empty($datacash_config['datacash_network_ssl_verify'])) {
$this->sslVerify = $datacash_config['datacash_network_ssl_verify'];
}
} else {
$this->sslVerify = FALSE;
}
// Use proxy only if proxy url is available.
if (!empty($datacash_config['proxy_url'])) {
$this->proxyUrl = $datacash_config['proxy_url'];
}
}
示例3: getRedirectUrl
/**
* Get datacash redirect URL for payment page.
*
* @return string
*/
public function getRedirectUrl()
{
// Get the default configurations.
$env_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/environment.yaml"));
$datacash_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/datacash.yaml"));
$datacash_config = $datacash_config[$env_config['environment']]['parameters'];
return $datacash_config['redirect_url'] . $this->HpsTxn->session_id->getValue();
}
示例4: set
/**
* Sets the current environment to the given $environment
*
* @param string $environment Environment to set
* @param array $config Config to set to
* @return void
*/
public static function set($environment, &$config)
{
$config['environment'] = $environment;
$config['is_' . $environment] = true;
$environment_config = YAML::parse("_config/environments/{$environment}.yaml");
if (is_array($environment_config)) {
$config = array_merge($config, $environment_config);
}
}
示例5: fetch
public static function fetch($form_name)
{
$filename = dirname(__DIR__) . '/forms/' . $form_name . '.yaml';
if (file_exists($filename)) {
return YAML::parse(file_get_contents($filename));
} else {
$error = 'missing form: ' . $filename;
throw new Exception($error);
}
}
示例6: set
/**
* Sets the current environment to the given $environment
*
* @param string $environment Environment to set
* @return void
*/
public static function set($environment)
{
$app = \Slim\Slim::getInstance();
$app->config['environment'] = $environment;
$app->config['is_' . $environment] = TRUE;
$environment_config = YAML::parse("_config/environments/{$environment}.yaml");
if (is_array($environment_config)) {
$app->config = array_merge($app->config, $environment_config);
}
}
示例7: convertYAML
/**
* Parse YAML data into an array
* @param {String} the text to be parsed
*
* @return {Array} the parsed content
*/
public static function convertYAML($text)
{
try {
$yaml = YAML::parse($text);
} catch (ParseException $e) {
printf("unable to parse documentation: %s..\n", $e->getMessage());
}
// single line of text won't throw a YAML error. returns as string
if (gettype($yaml) == "string") {
$yaml = array();
}
return $yaml;
}
示例8: getUserProfile
/**
* Returns a given user's profile
*
* @param string $username Username's profile to return
* @return array
*/
public static function getUserProfile($username)
{
if (!UserAuth::isUser($username)) {
return null;
}
$content = substr(File::get(Config::getConfigPath() . "/users/" . $username . ".yaml"), 3);
$divide = strpos($content, "\n---");
$front_matter = trim(substr($content, 0, $divide));
$content_raw = trim(substr($content, $divide + 4));
$profile = YAML::parse($front_matter);
$profile['biography_raw'] = $content_raw;
$profile['biography'] = Content::transform($content_raw);
$profile['username'] = $username;
return $profile;
}
示例9: testYAMLSerializer
public function testYAMLSerializer()
{
$yaml_output = $this->debtAmortizatorFactory->getSerializedResult(new YAMLSerializer());
$yamlObject = YAML::parse($yaml_output);
// WE WILL TEST EACH AND EVERY PROPERTY OF THIS OBJECT
// Debt principal
$this->assertEquals("40000", $yamlObject["debtPrincipal"]);
// Debt number of compounding periods
$this->assertEquals("6", $yamlObject["debtNoOfCompoundingPeriods"]);
// Debt length period
$this->assertEquals("1", $yamlObject["debtPeriodLength"]["years"]);
$this->assertEquals("12", $yamlObject["debtPeriodLength"]["months"]);
$this->assertEquals("360", $yamlObject["debtPeriodLength"]["days"]);
// Debt interest
$this->assertEquals("0.12", $yamlObject["debtInterest"]);
// Debt discount factor
$this->assertEquals("0.89", $this->round2DP($yamlObject["debtDiscountFactor"]));
// Debt duration
$this->assertEquals("6", $yamlObject["debtDuration"]["years"]);
$this->assertEquals("72", $yamlObject["debtDuration"]["months"]);
$this->assertEquals("2160", $yamlObject["debtDuration"]["days"]);
// Debt amount of single repayment
$INDIVIDUAL_REPAYMENT = "9729.03";
$this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtSingleRepayment"]));
// Debt repayments (principal part, interest part, total = principal part + interest part)
$this->assertEquals("4929.03", $this->round2DP($yamlObject["debtRepayments"]["1"]["principalAmount"]));
$this->assertEquals("4800.00", $this->round2DP($yamlObject["debtRepayments"]["1"]["interestAmount"]));
$this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["1"]["totalAmount"]));
$this->assertEquals("5520.51", $this->round2DP($yamlObject["debtRepayments"]["2"]["principalAmount"]));
$this->assertEquals("4208.52", $this->round2DP($yamlObject["debtRepayments"]["2"]["interestAmount"]));
$this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["2"]["totalAmount"]));
$this->assertEquals("6182.97", $this->round2DP($yamlObject["debtRepayments"]["3"]["principalAmount"]));
$this->assertEquals("3546.06", $this->round2DP($yamlObject["debtRepayments"]["3"]["interestAmount"]));
$this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["3"]["totalAmount"]));
$this->assertEquals("6924.93", $this->round2DP($yamlObject["debtRepayments"]["4"]["principalAmount"]));
$this->assertEquals("2804.10", $this->round2DP($yamlObject["debtRepayments"]["4"]["interestAmount"]));
$this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["4"]["totalAmount"]));
$this->assertEquals("7755.92", $this->round2DP($yamlObject["debtRepayments"]["5"]["principalAmount"]));
$this->assertEquals("1973.11", $this->round2DP($yamlObject["debtRepayments"]["5"]["interestAmount"]));
$this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["5"]["totalAmount"]));
$this->assertEquals("8686.63", $this->round2DP($yamlObject["debtRepayments"]["6"]["principalAmount"]));
$this->assertEquals("1042.4", $this->round2DP($yamlObject["debtRepayments"]["6"]["interestAmount"]));
$this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["6"]["totalAmount"]));
}
示例10: run
public function run($depth, $ext, $path, $pathName, $name)
{
// load default vars
$patternTypeDash = PatternData::getPatternTypeDash();
// should this pattern get rendered?
$hidden = $name[0] == "_";
// set-up the names, $name == foo.json
$pattern = str_replace("." . $ext, "", $name);
// foo
$patternDash = $this->getPatternName($pattern, false);
// foo
$patternPartial = $patternTypeDash . "-" . $patternDash;
// atoms-foo
if (!$hidden) {
$patternStoreData = array("category" => "pattern");
$file = file_get_contents(Config::getOption("patternSourceDir") . "/" . $pathName);
if ($ext == "json") {
$data = json_decode($file, true);
if ($jsonErrorMessage = JSON::hasError()) {
JSON::lastErrorMsg($name, $jsonErrorMessage, $data);
}
} else {
try {
$data = YAML::parse($file);
} catch (ParseException $e) {
printf("unable to parse " . $pathNameClean . ": %s..\n", $e->getMessage());
}
// single line of text won't throw a YAML error. returns as string
if (gettype($data) == "string") {
$data = array();
}
}
$patternStoreData["data"] = $data;
// create a key for the data store
$patternStoreKey = $patternPartial;
// if the pattern data store already exists make sure it is merged and overwrites this data
$patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData;
PatternData::setOption($patternStoreKey, $patternStoreData);
}
}
示例11: update
/**
* Updates the internal content cache
*
* @return boolean
*/
public static function update()
{
// start measuring
$content_hash = Debug::markStart('caching', 'content');
// track if any files have changed
$files_changed = false;
$settings_changed = false;
$members_changed = false;
// grab length of content type extension
$content_type = Config::getContentType();
$full_content_root = rtrim(Path::tidy(BASE_PATH . "/" . Config::getContentRoot()), "/");
$content_type_length = strlen($content_type) + 1;
// the cache files we'll use
$cache_file = BASE_PATH . '/_cache/_app/content/content.php';
$settings_file = BASE_PATH . '/_cache/_app/content/settings.php';
$structure_file = BASE_PATH . '/_cache/_app/content/structure.php';
$time_file = BASE_PATH . '/_cache/_app/content/last.php';
$members_file = BASE_PATH . '/_cache/_app/members/members.php';
$now = time();
// start measuring settings hash
$settings_hash = Debug::markStart('caching', 'settings');
// check for current and new settings
$settings = unserialize(File::get($settings_file));
if (!is_array($settings)) {
$settings = array('site_root' => '', 'site_url' => '', 'timezone' => '', 'date_format' => '', 'time_format' => '', 'content_type' => '', 'taxonomy' => '', 'taxonomy_case_sensitive' => '', 'taxonomy_force_lowercase' => '', 'entry_timestamps' => '', 'base_path' => '', 'app_version' => '');
}
// look up current settings
$current_settings = array('site_root' => Config::getSiteRoot(), 'site_url' => Config::getSiteURL(), 'timezone' => Config::get('timezone'), 'date_format' => Config::get('date_format'), 'time_format' => Config::get('time_format'), 'content_type' => Config::get('content_type'), 'taxonomy' => Config::getTaxonomies(), 'taxonomy_case_sensitive' => Config::getTaxonomyCaseSensitive(), 'taxonomy_force_lowercase' => Config::getTaxonomyForceLowercase(), 'entry_timestamps' => Config::getEntryTimestamps(), 'base_path' => BASE_PATH, 'app_version' => STATAMIC_VERSION);
// have cache-altering settings changed?
if ($settings !== $current_settings) {
// settings have changed
$settings_changed = true;
// clear the cache and set current settings
$cache = self::getCleanCacheArray();
$settings = $current_settings;
$last = null;
} else {
// grab the existing cache
$cache = unserialize(File::get($cache_file));
if (!is_array($cache)) {
$cache = self::getCleanCacheArray();
}
$last = File::get($time_file);
}
// mark end of settings hash measuring
Debug::markEnd($settings_hash);
// grab a list of all content files
$files = File::globRecursively(Path::tidy(BASE_PATH . '/' . Config::getContentRoot() . '/*'), Config::getContentType());
// grab a separate list of files that have changed since last check
$updated = array();
$current_files = array();
// loop through files, getting local paths and checking for updated files
foreach ($files as $file) {
$local_file = Path::trimFilesystemFromContent(Path::standardize($file));
// add to current files
$current_files[] = $local_file;
// is this updated?
if ($last && File::getLastModified($file) >= $last) {
$updated[] = $local_file;
}
}
// get a diff of files we know about and files currently existing
$known_files = array();
foreach ($cache['urls'] as $url_data) {
array_push($known_files, $url_data['path']);
}
$new_files = array_diff($current_files, $known_files);
// create a master list of files that need updating
$changed_files = array_unique(array_merge($new_files, $updated));
// store a list of changed URLs
$changed_urls = array();
// add to the cache if files have been updated
if (count($changed_files)) {
$files_changed = true;
// build content cache
foreach ($changed_files as $file) {
$file = $full_content_root . $file;
$local_path = Path::trimFilesystemFromContent($file);
// before cleaning anything, check for hidden or draft content
$is_hidden = Path::isHidden($local_path);
$is_draft = Path::isDraft($local_path);
// now clean up the path
$local_filename = Path::clean($local_path);
// file parsing
$content = substr(File::get($file), 3);
$divide = strpos($content, "\n---");
$front_matter = trim(substr($content, 0, $divide));
$content_raw = trim(substr($content, $divide + 4));
// parse data
$data = YAML::parse($front_matter);
if ($content_raw) {
$data['content'] = 'true';
$data['content_raw'] = 'true';
}
// set additional information
//.........这里部分代码省略.........
示例12: loadProfile
private function loadProfile($profile)
{
$profile_file = "./profiles/{$profile}.yml";
if (file_exists($profile_file)) {
$data = YAML::parse(file_get_contents($profile_file));
if (isset($data['pct'])) {
foreach ($data['pct'] as $var => $val) {
$this->{$var} = $val;
}
}
if (isset($data['files'])) {
foreach ($data['files'] as $var => $val) {
$this->{$var} = $val;
}
}
if (isset($data['addBaseUrls']) && $data['addBaseUrls'] === FALSE) {
$this->addBaseUrls = FALSE;
}
// Load geo data.
if (isset($this->geoFile) && file_exists($this->geoFile)) {
$this->loadGeo();
}
// Load cat data.
if (isset($this->catFile) && file_exists($this->catFile)) {
$this->loadCat();
}
// Load SPs.
if (isset($this->spsFile) && file_exists($this->spsFile)) {
$this->loadSps();
}
} else {
throw new Exception('Profile not found.');
}
}
示例13:
use DMS\Service\Meetup\MeetupKeyAuthClient;
use Symfony\Component\Yaml\Yaml;
use Neoxygen\NeoClient\ClientBuilder;
$skipSchemaSetup = false;
$dropDbOnInit = false;
if (!isset($argv[1]) || empty($argv[1])) {
throw new \InvalidArgumentException('You need to pass the event ID as argument : php import.php 12345678');
}
if (isset($argv[2]) && true == (bool) $argv[2]) {
$skipSchemaSetup = true;
}
if (isset($argv[3]) && (bool) $argv[3] == true) {
$dropDbOnInit = true;
}
$eventId = (int) $argv[1];
$config = YAML::parse(file_get_contents(__DIR__ . '/config.yml'));
$meetupClient = MeetupKeyAuthClient::factory(array('key' => $config['meetup_api_key']));
$neoClient = ClientBuilder::create()->addConnection('default', $config['neo4j_scheme'], $config['neo4j_host'], $config['neo4j_port'], true, $config['neo4j_user'], $config['neo4j_password'])->setAutoFormatResponse(true)->build();
// Creating Schema Indexes And Constraints
if (!$skipSchemaSetup) {
$neoClient->createUniqueConstraint('Event', 'id');
$neoClient->createUniqueConstraint('Member', 'id');
$neoClient->createUniqueConstraint('Topic', 'id');
$neoClient->createUniqueConstraint('Country', 'code');
$neoClient->createIndex('City', 'name');
echo 'Schema created' . "\n";
} else {
echo 'Skipping Schema Creation' . "\n";
}
if ($dropDbOnInit) {
echo 'Dropping DB' . "\n";
示例14: loadMemberData
/**
* Loads a Member's profile
*
* @param string $username username to load data for
* @return array
* @throws Exception
*/
private static function loadMemberData($username)
{
// pull profile data from filesystem
$file = Config::getConfigPath() . '/users/' . $username . '.yaml';
$raw_profile = substr(File::get($file), 3);
// no profile found, throw an exception
if (!$raw_profile) {
throw new Exception('Member `' . $username . '` not found.');
}
// split out the profile into parts
$divide = strpos($raw_profile, "\n---");
$front_matter = trim(substr($raw_profile, 0, $divide));
$content_raw = trim(substr($raw_profile, $divide + 4));
// create data array for populating into the Member object
$data = YAML::parse($front_matter);
$data['biography_raw'] = $content_raw;
$data['biography'] = Content::transform($content_raw);
$data['username'] = $username;
// return the Member data
return $data;
}
示例15: nav_count
public static function nav_count()
{
$default_config = YAML::parse(Config::getAppConfigPath() . '/default.settings.yaml');
$admin_nav = array_merge($default_config['_admin_nav'], Config::get('_admin_nav', array()));
return count(array_filter($admin_nav, 'strlen'));
}