Пример #1
0
 /**
  * Convert an array into a YAML string.
  *
  * @param array $array The data to convert
  *
  * @return string The converted YAML
  */
 public static function convert(array $array)
 {
     if (function_exists('yaml_emit')) {
         $yaml = yaml_emit($array);
         // PHP-Yaml adds strange separators to the outputted YAML, we do
         // some manipulation of the outputted string to remove these.
         $yaml = explode("\n", $yaml);
         array_shift($yaml);
         array_pop($yaml);
         array_pop($yaml);
         return implode("\n", $yaml);
     }
     return spyc_dump($array);
 }
Пример #2
0
function yaml_encode($opts, $pipe = null, $offset = 0)
{
    $opts = get_opts_or_pipe($opts, $pipe);
    $yaml = spyc_dump($opts);
    if ($offset) {
        $offset_str = str_repeat('  ', $offset);
        $lines = explode("\n", $yaml);
        for ($i = 0; $i < count($lines); $i++) {
            $val = $lines[$i];
            if (trim($val) == '') {
                continue;
            }
            $lines[$i] = "{$offset_str}{$val}";
        }
        $yaml = implode("\n", $lines);
    }
    return $yaml;
}
Пример #3
0
 public function testShortSyntax()
 {
     $dump = spyc_dump(array('item1', 'item2', 'item3'));
     $awaiting = "- item1\n- item2\n- item3\n";
     $this->assertEquals($awaiting, $dump);
 }
Пример #4
0
            die("Failed to upload twice, stopping");
        }
    }
    echo "Uploaded.\n";
    $waitedTime = 0;
    $updated = false;
    while (!$updated) {
        echo "Waiting 5 minutes\n";
        sleep(5 * 60);
        $waitedTime += 5;
        $updatedURL = getCurrentSkin();
        echo " current url: {$updatedURL}\n";
        $updated = $updatedURL != $lastURL;
    }
    $images[$url] = $updatedURL;
    $yaml = spyc_dump($images);
    file_put_contents($mapFile, $yaml);
    echo "Updated YAML map\n";
    if ($waitedTime < 10) {
        $waitedTime = 10 - $waitedTime;
        echo "Waiting {$waitedTime} more minutes\n";
        sleep($waitedTime * 60);
    }
    echo "Waiting 2 more minutes\n";
    sleep(2 * 60);
}
if (file_exists($originalSkin)) {
    echo "Re-uploading original skin from {$originalSkin}\n";
    if (!uploadSkin($originalSkin)) {
        die("Failed to re-upload original skin!");
    } else {
Пример #5
0
    $executionMetrics['createdAmiId'] = $amiId;
    $logger->info("Packer build succeeded: Region '{$region}', AMI id '{$amiId}'");
    deleteQueueMessage($sqsClient, $queueUrl, $message['ReceiptHandle'], $logger);
    $executionMetrics['endTimestamp'] = microtime(true);
    $executionMetrics['endDateTime'] = date('r', $executionMetrics['endTimestamp']);
    $executionMetrics['processingDuration'] = $executionMetrics['endTimestamp'] - $executionMetrics['startTimestamp'];
} else {
    $executionMetrics['endedInError'] = true;
    $logger->error("The packer build execution returned non zero result: '{$returnCode}'");
    $logger->error("Last 20 lines of output: ", array_slice($result, -20));
}
$date = date('Y-m-d\\TH-i-s', $executionMetrics['startTimestamp']);
$shaForPath = substr($templateSha, 0, 7);
$s3ObjectPath = "builds/{$template}/{$date}/{$shaForPath}.yml";
$logger->info("Writing results to S3: '{$s3ObjectPath}'");
writeExecutionDigest($s3Client, $s3ObjectPath, $config->get('executionDigest'), spyc_dump($executionMetrics), $logger);
/**
 * @param \Aws\Sqs\SqsClient $sqsClient
 * @param $queueUrl
 * @param $messageReceiptHandle
 * @param \Psr\Log\LoggerInterface $logger
 */
function deleteQueueMessage(\Aws\Sqs\SqsClient $sqsClient, $queueUrl, $messageReceiptHandle, \Psr\Log\LoggerInterface $logger)
{
    try {
        $logger->info("deleting message on queue '{$queueUrl}' using message receipt: '{$messageReceiptHandle}'.");
        $result = $sqsClient->deleteMessage(['QueueUrl' => $queueUrl, 'ReceiptHandle' => $messageReceiptHandle]);
    } catch (\Aws\Sqs\Exception\SqsException $e) {
        $logger->error("SqsException deleting message on queue '{$queueUrl}' using message receipt: " . "'{$messageReceiptHandle}'. Error: {$e->getMessage()}");
        shutDown("ERROR deleting message on queue '{$queueUrl}' using message receipt: '{$messageReceiptHandle}'." . "Error: {$e->getMessage()}");
    } catch (Exception $e) {
Пример #6
0
 /**
  * The post's YAML frontmatter
  *
  * Returns String the YAML frontmatter, ready to be written to the file
  */
 function front_matter()
 {
     return "---\n" . spyc_dump($this->meta(), false, 0) . "---\n";
 }
Пример #7
0
 public function export($arr, $directory, $language)
 {
     $file = $directory . DIRECTORY_SEPARATOR . $language . '.yml';
     $fp = fopen($file, 'w');
     fwrite($fp, spyc_dump($arr));
     fclose($fp);
     return file_exists($file);
 }
Пример #8
0
 public function dumpYamlTo($filePath)
 {
     file_put_contents($filePath, spyc_dump($this->config));
 }