public function testConvertToObjectConvertsToObjectCorrectly()
 {
     $array = array('testkey' => 'testvalue');
     $dumper = new \Symfony\Component\Yaml\Dumper();
     $yaml = $dumper->dump($array);
     $result = $this->adapter->convertToObject($yaml);
     $this->assertTrue(is_object($result));
 }
Example #2
0
 public function prepare(\Silex\Application $app, $locale)
 {
     $templatesPath = APP_DIR . '/templates';
     $untranslatedMessagesFile = APP_DIR . '/locales/' . $locale . '_untranslated.yml';
     $extractor = new \Symfony\Bridge\Twig\Translation\TwigExtractor($app['twig']);
     /***** All translations *****/
     $catalogueAll = new \Symfony\Component\Translation\MessageCatalogue($locale);
     $extractor->extract($templatesPath, $catalogueAll);
     $allMessages = $catalogueAll->all('messages');
     // String from controller, controller provider, etc.
     $finder = new \Symfony\Component\Finder\Finder();
     $finder->files()->in(ROOT_DIR . '/src');
     foreach ($finder as $file) {
         $fileMessageStrings = array();
         $filePath = $file->getRealpath();
         $fileContent = file_get_contents($filePath);
         $pregMatch = "#->trans.*\\(\\s*'(.+?)(?=')#m";
         preg_match_all($pregMatch, $fileContent, $matches);
         $matches = $matches[1];
         if ($matches) {
             foreach ($matches as $match) {
                 $fileMessageStrings[] = $match;
             }
         }
         if ($fileMessageStrings) {
             foreach ($fileMessageStrings as $fileMessageString) {
                 if (!isset($allMessages[$fileMessageString])) {
                     $allMessages[$fileMessageString] = $fileMessageString;
                 }
             }
         }
     }
     /***** Already translated *****/
     $app['application.translator']->setLocale($locale, $ignoreUntranslated = true);
     $translatedMessages = $app['translator']->getMessages($locale);
     $translatedMessages = $translatedMessages['messages'];
     /***** Untranslated *****/
     $untranslatedMessages = array();
     if ($allMessages) {
         foreach ($allMessages as $singleMessageKey => $singleMessage) {
             if (!isset($translatedMessages[$singleMessageKey])) {
                 $untranslatedMessages[$singleMessageKey] = $singleMessage;
             }
         }
     }
     if (!empty($untranslatedMessages)) {
         $dumper = new \Symfony\Component\Yaml\Dumper();
         $yaml = $dumper->dump($untranslatedMessages, 1);
         if (file_exists($untranslatedMessagesFile)) {
             unlink($untranslatedMessagesFile);
         }
         file_put_contents($untranslatedMessagesFile, $yaml);
     }
     return array('allMessages' => $allMessages, 'translatedMessages' => $translatedMessages, 'untranslatedMessages' => $untranslatedMessages);
 }
 /**
  * Save current comics to a YAML file
  *
  * @param string $file
  */
 public function saveYaml($file)
 {
     $dumper = new \Symfony\Component\Yaml\Dumper();
     $array = array();
     foreach ($this->comics as $c) {
         /** @var $c Entry */
         $array[$c->getId()] = $c->getYamlArray();
     }
     $yaml = $dumper->dump($array, 2);
     file_put_contents($file, $yaml);
 }
Example #4
0
File: TAP.php Project: Zarbisi/todo
 /**
  * A failure occurred.
  *
  * @param PHPUnit_Framework_Test                 $test
  * @param PHPUnit_Framework_AssertionFailedError $e
  * @param float                                  $time
  */
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $this->writeNotOk($test, 'Failure');
     $message = explode("\n", PHPUnit_Framework_TestFailure::exceptionToString($e));
     $diagnostic = array('message' => $message[0], 'severity' => 'fail');
     if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
         $cf = $e->getComparisonFailure();
         if ($cf !== null) {
             $diagnostic['data'] = array('got' => $cf->getActual(), 'expected' => $cf->getExpected());
         }
     }
     $yaml = new Symfony\Component\Yaml\Dumper();
     $this->write(sprintf("  ---\n%s  ...\n", $yaml->dump($diagnostic, 2, 2)));
 }
Example #5
0
 /**
  * Tests that the solver doesn't come to false conclusions
  *
  * Verifies only that all cells marked by the solver correspond to the actual solution
  * Does *not* check that the solver solved all cells (unknown cells are skipped)
  * @test
  * @param $filepath
  *
  * @dataProvider testSolverAllDataProvider
  */
 public function testSolverAll($filename)
 {
     $grid = $this->loadFile($filename . '.dat');
     $cellsExpected = $grid->getCells();
     $labels = $grid->getLabels();
     $labelsRaw['columns'] = $labels->getCol();
     $labelsRaw['rows'] = $labels->getRow();
     $labelFactory = new \Nonogram\Label\Factory(new \Nonogram\Label\LabelProviderCells());
     $labelFactory->setContainer($this->container);
     $parserYaml = new \Nonogram\LevelParser\LevelParserYaml($labelFactory, new \Symfony\Component\Yaml\Parser());
     $solver = $this->container->get('solver');
     $yamlDumper = new \Symfony\Component\Yaml\Dumper();
     $parserYaml->setRawData($yamlDumper->dump($labelsRaw));
     $labelsLoaded = $parserYaml->getLabels();
     $cellsActual = $solver->solve($labelsLoaded);
     $this->assertGridsEqual($cellsExpected, $cellsActual, $filename);
 }
Example #6
0
 /**
  * Write the PHPCI config.yml file.
  * @param array $config
  */
 protected function writeConfigFile(array $config)
 {
     $dumper = new \Symfony\Component\Yaml\Dumper();
     $yaml = $dumper->dump($config, 2);
     file_put_contents(PHPCI_DIR . 'PHPCI/config.yml', $yaml);
 }
 /**
  * {@inheritdoc}
  */
 public function getResponseObjectRepresentation()
 {
     $dumper = new \Symfony\Component\Yaml\Dumper();
     return $dumper->dump(json_decode(json_encode($this->responseObject), true), 100);
 }
Example #8
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
return array('arg0' => 'generate:schema', 'command' => 'generate:schema', 'description' => 'Generate schema definition config.', 'run' => function ($args) use($commands) {
    $dest = Project::root(Project::DIRECTORY_NAME) . '/schema.yaml';
    @mkdir(dirname($dest), 0777, true);
    $client = new Client();
    $client->setRaiseExceptions(false);
    $cached_schema = $client->get('apps/schema');
    $yaml = new Symfony\Component\Yaml\Dumper();
    if (file_exists($dest)) {
        Console::output("You already have a schema.yaml file.\n" . "Your changes will be lost.\n" . "Overwrite? [y/n]");
        $overwrite = Console::readline() == 'y';
        if (!$overwrite) {
            throw new Exception("Aborted.");
        }
    }
    // format schema dump before save
    $schema_dump = "";
    if (!empty($cached_schema)) {
        $schema_dump = str_replace('  ', ' ', $yaml->dump(json_decode(json_encode($cached_schema), true), 3));
        $schema_dump = preg_replace('/^([a-z0-9_]+):\\n/m', "\n\$0", $schema_dump);
    }
    file_put_contents($dest, $schema_dump . file_get_contents(__DIR__ . '/../../templates/schema.yaml'));
    echo "Schema dumped at '{$dest}'." . PHP_EOL;
    if ($editor = getenv('EDITOR')) {
        $descriptors = array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w'));
        $process = proc_open("{$editor} {$dest}", $descriptors, $pipes);
    }
Example #9
0
 /**
  *
  *
  * @return Setup_Upgrade
  */
 protected function write_lock()
 {
     $date_obj = new DateTime();
     $dumper = new Symfony\Component\Yaml\Dumper();
     $datas = $dumper->dump(['percentage' => $this->get_percentage(), 'total_steps' => $this->total_steps, 'completed_steps' => $this->completed_steps, 'message' => $this->message, 'last_update' => $date_obj->format(DATE_ATOM)], 1);
     if (!file_put_contents(self::get_lock_file(), $datas)) {
         throw new Exception_Setup_CannotWriteLockFile(sprintf('Cannot write lock file to %s', self::get_lock_file()));
     }
     return $this;
 }
Example #10
0
 /**
  * Write the PHPCI config.yml file.
  * @param array $config
  */
 protected function writeConfigFile(array $config)
 {
     $dumper = new \Symfony\Component\Yaml\Dumper();
     $yaml = $dumper->dump($config, 4);
     file_put_contents($this->configFilePath, $yaml);
 }
Example #11
0
 function arrayToYaml(array $array, $mode = 1)
 {
     $dumper = new Symfony\Component\Yaml\Dumper();
     return $dumper->dump($array, $mode);
 }
Example #12
0
 /**
  * Format the data and return serialized string
  *
  * @return string
  */
 public function format()
 {
     $request_uri = sprintf('%s %s', $this->request->getMethod(), $this->request->getBasePath() . $this->request->getPathInfo());
     $ret = ['meta' => ['api_version' => $this->api_version, 'request' => $request_uri, 'response_time' => $this->response_time, 'http_code' => $this->http_code, 'error_type' => $this->error_type, 'error_message' => $this->error_message, 'error_details' => $this->error_details, 'charset' => 'UTF-8'], 'response' => $this->response];
     $this->app['dispatcher']->dispatch(PhraseaEvents::API_RESULT, new ApiResultEvent());
     if ($this->app['conf']->get(['main', 'api-timers'], false)) {
         $ret['timers'] = $this->app['api.timers']->toArray();
     }
     switch ($this->response_type) {
         case self::FORMAT_JSON:
         default:
             $return_value = p4string::jsonencode($ret);
             break;
         case self::FORMAT_YAML:
             if ($ret['response'] instanceof stdClass) {
                 $ret['response'] = [];
             }
             $dumper = new Symfony\Component\Yaml\Dumper();
             $return_value = $dumper->dump($ret, 8);
             break;
         case self::FORMAT_JSONP:
             $callback = trim($this->request->get('callback'));
             $return_value = $callback . '(' . p4string::jsonencode($ret) . ')';
             break;
     }
     return $return_value;
 }
function infonesy_export_post($pid, $data)
{
    $storage = $GLOBALS['mybb_infonesy']['push_dir'];
    $file = $storage . '/' . date('Ymd-His') . '--post-' . $pid . '.md';
    $message = $data['Message'];
    unset($data['Message']);
    $dumper = new Symfony\Component\Yaml\Dumper();
    $md = "---\n";
    $md .= $dumper->dump($data, 2);
    $md .= "---\n\n";
    $md .= trim(str_replace("\r", "", $message)) . "\n";
    file_put_contents($file, $md);
    chmod($file, 0666);
}
Example #14
0
File: dvm.php Project: bwood/dvm
        print "Error: Could not run '{$cmd}'\n";
        print implode("\n", $output);
    }
}
//TODO: test that these won't be added multiple times
if (!array_search($site_dir, array_column($yaml['vagrant_synced_folders'], 'local_path'))) {
    $yaml['vagrant_synced_folders'][] = array('local_path' => $site_dir, 'destination' => $site_dir_vm, 'type' => 'nfs', 'create' => 1);
}
if (!array_search($site_dir_vm, array_column($yaml['apache_vhosts'], 'documentroot'))) {
    $yaml['apache_vhosts'][] = array('servername' => "{$site_name}.localhost", 'documentroot' => $site_dir_vm, 'extra_parameters' => "ProxyPassMatch ^/(.*\\.php(/.*)?)\$ \"fcgi://127.0.0.1:9000{$site_dir_vm}\"");
}
if (!array_search($site_name, array_column($yaml['mysql_databases'], 'name'))) {
    $yaml['mysql_databases'][] = array('name' => $site_name, 'encoding' => "utf8", 'collation' => "utf8_general_ci");
}
// Write config.yml for drupalvm
$dumper = new Symfony\Component\Yaml\Dumper();
$yaml_dumped = $dumper->dump($yaml, 2);
//print $yaml_dumped . "\n";
//backup
//TODO: commit to git?
rename("{$dvm_dvm_dir}/config.yml", "{$dvm_dvm_dir}/config.yml-" . time());
file_put_contents("{$dvm_dvm_dir}/config.yml", $yaml_dumped);
// Restart the VM //
print "Restarting VM with new configuration.\n";
//TODO: enable
$cmd = "cd {$dvm_dvm_dir};vagrant halt;vagrant up --provision";
exec($cmd, $output, $return);
if ($return != 0) {
    print "Error: Failed to reload VM.\n";
    print implode("\n", $output);
    exit(1);
Example #15
0
            //
            // Read or extract certificate file
            // --------------------------------
            //
            if (file_exists($value)) {
                Console::output("Reading certificate file...");
                $ext = pathinfo($value, PATHINFO_EXTENSION);
                if ($ext == 'p12') {
                    $results = array();
                    $worked = openssl_pkcs12_read(file_get_contents($value), $results, null);
                    if ($worked) {
                        $value = $results['cert'] . $results['pkey'];
                    } else {
                        Console::error(openssl_error_string());
                    }
                } else {
                    if ($ext == 'pem') {
                        $value = file_get_contents($value);
                    }
                }
            }
            array_push($configs_to_add, array('name' => $name, 'value' => $value));
        }
    }
    foreach ($configs_to_add as $config) {
        Utils::array_set($configs, $config['name'], $config['value']);
    }
    $dumper = new Symfony\Component\Yaml\Dumper();
    file_put_contents($config_file, str_replace("  ", " ", $dumper->dump($configs, 10)));
    Console::output("Written successfully at: '{$config_file}'");
});