parse() public méthode

Parses TOML string into a PHP value.
public parse ( string $value ) : mixed
$value string A TOML string
Résultat mixed A PHP value
Exemple #1
0
 /**
  * Parse TOML into a PHP array.
  *  
  * Usage:
  * <code>
  *  $array = Toml::parse('config.toml');
  *  print_r($array);
  *  
  *  $array = Toml::parse('key = "[1,2,3]"');
  *  print_r($array);
  * </code>
  * 
  * @return array The TOML converted to a PHP array
  */
 public static function parse($input)
 {
     $file = '';
     if (is_file($input)) {
         if (!is_readable($input)) {
             throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input));
         }
         $file = $input;
         $input = file_get_contents($input);
     }
     $parser = new Parser();
     try {
         return $parser->parse($input);
     } catch (ParseException $e) {
         if ($file) {
             $e->setParsedFile($file);
         }
         throw $e;
     }
 }
Exemple #2
0
 /**
  * @expectedException \Yosymfony\Toml\Exception\ParseException
  */
 public function testTableArrayWithSomeNameOfTable()
 {
     $filename = __DIR__ . '/fixtures/invalid/tableArrayWithSomeNameOfTable.toml';
     $parser = new Parser();
     $array = $parser->parse(file_get_contents($filename));
 }
Exemple #3
0
 public function testTableArrayOne()
 {
     $filename = __DIR__ . '/fixtures/valid/tableArrayOne.toml';
     $parser = new Parser();
     $array = $parser->parse(file_get_contents($filename));
     $this->assertNotNull($array);
     $this->assertCount(1, $array);
     $this->assertEquals('Bruce', $array['people'][0]['first_name']);
     $this->assertEquals('Springsteen', $array['people'][0]['last_name']);
 }