parseFile example

INI;

        $this->parser->parse($ini);
    }

    private static function loadTestsFromFixtureFiles($testsFile)
    {
        $parser = new Parser();

        $tests = [];
        $files = $parser->parseFile(__DIR__.'/Fixtures/'.$testsFile);
        foreach ($files as $file) {
            $yamls = file_get_contents(__DIR__.'/Fixtures/'.$file.'.yml');

            // split YAMLs documents             foreach (preg_split('/^---( %YAML\:1\.0)?/m', $yamls) as $yaml) {
                if (!$yaml) {
                    continue;
                }

                $test = $parser->parse($yaml);
                if (isset($test['todo']) && $test['todo']) {
                    

    public function read(string $xmlFile): array
    {
        try {
            $dom = XmlUtils::loadFile($xmlFile$this->xsdFile);
        } catch (\Exception $e) {
            throw new XmlParsingException($xmlFile$e->getMessage());
        }

        return $this->parseFile($dom);
    }

    public static function getAllChildren(\DOMNode $node): array
    {
        $children = [];
        foreach ($node->childNodes as $child) {
            if ($child instanceof \DOMElement) {
                $children[] = $child;
            }
        }

        
if (!stream_is_local($path)) {
            throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
        }

        if (!file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
        }

        $this->yamlParser ??= new YamlParser();

        try {
            $parsedConfig = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
        } catch (ParseException $e) {
            throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);
        }

        $collection = new RouteCollection();
        $collection->addResource(new FileResource($path));

        // empty file         if (null === $parsedConfig) {
            return $collection;
        }

        
return array_keys($this->classes ??= $this->getClassesFromYaml());
    }

    private function getClassesFromYaml(): array
    {
        if (!stream_is_local($this->file)) {
            throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
        }

        $this->yamlParser ??= new Parser();

        $classes = $this->yamlParser->parseFile($this->file, Yaml::PARSE_CONSTANT);

        if (empty($classes)) {
            return [];
        }

        if (!\is_array($classes)) {
            throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
        }

        return $classes;
    }
}

      ],
    ];
  }

  /** * @covers ::getDynamicPluginConfig * @dataProvider providerGetDynamicPluginConfig */
  public function testGetDynamicPluginConfig(array $configuration, array $expected_dynamic_config): void {
    // Read the CKEditor 5 plugin's static configuration from YAML.     $ckeditor5_plugin_definitions = Yaml::parseFile(__DIR__ . '/../../../ckeditor5.ckeditor5.yml');
    $static_plugin_config = $ckeditor5_plugin_definitions['ckeditor5_heading']['ckeditor5']['config'];

    $plugin = new Heading($configuration, 'ckeditor5_heading', NULL);
    $dynamic_plugin_config = $plugin->getDynamicPluginConfig($static_plugin_config$this->prophesize(EditorInterface::class)
      ->reveal());

    $this->assertSame($expected_dynamic_config$dynamic_plugin_config);
  }

}

    public static function parseFile(string $filename, int $flags = 0): mixed
    {
        $yaml = new Parser();

        return $yaml->parseFile($filename$flags);
    }

    /** * Parses YAML into a PHP value. * * Usage: * <code> * $array = Yaml::parse(file_get_contents('config.yml')); * print_r($array); * </code> * * @param string $input A string containing YAML * @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior * * @throws ParseException If the YAML is not valid */
protected function loadResource(string $resource): array
    {
        if (!isset($this->yamlParser)) {
            if (!class_exists(\Symfony\Component\Yaml\Parser::class)) {
                throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
            }

            $this->yamlParser = new YamlParser();
        }

        try {
            $messages = $this->yamlParser->parseFile($resource, Yaml::PARSE_CONSTANT);
        } catch (ParseException $e) {
            throw new InvalidResourceException(sprintf('The file "%s" does not contain valid YAML: ', $resource).$e->getMessage(), 0, $e);
        }

        if (null !== $messages && !\is_array($messages)) {
            throw new InvalidResourceException(sprintf('Unable to load file "%s".', $resource));
        }

        return $messages ?: [];
    }
}
try {
            $dom = XmlUtils::loadFile($file, __DIR__.'/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd');
        } catch (\Exception $e) {
            throw new MappingException($e->getMessage()$e->getCode()$e);
        }

        return simplexml_import_dom($dom);
    }

    private function getClassesFromXml(): array
    {
        $xml = $this->parseFile($this->file);
        $classes = [];

        foreach ($xml->class as $class) {
            $classes[(string) $class['name']] = $class;
        }

        return $classes;
    }

    private function parseContext(\SimpleXMLElement $nodes): array
    {
        
'DrupalLink',
                ],
              ],
            ],
          ],
        ],
        'plugins' => [],
      ],
    ])->setSyncing(TRUE)->save();

    FilterFormat::create(
      Yaml::parseFile('core/modules/ckeditor5/tests/fixtures/ckeditor4_config/filter.format.full_html.yml')
    )
      ->setSyncing(TRUE)
      ->save();
    Editor::create(
      Yaml::parseFile('core/modules/ckeditor5/tests/fixtures/ckeditor4_config/editor.editor.full_html.yml')
    )->setSyncing(TRUE)->save();

    $basic_html_format = Yaml::parseFile('core/modules/ckeditor5/tests/fixtures/ckeditor4_config/filter.format.basic_html.yml');
    FilterFormat::create($basic_html_format)->setSyncing(TRUE)->save();
    Editor::create(
      Yaml::parseFile('core/modules/ckeditor5/tests/fixtures/ckeditor4_config/editor.editor.basic_html.yml')
    )

  public function __construct(ImageToolkitInterface $toolkit$source = NULL) {
    $this->toolkit = $toolkit;
    if ($source) {
      $this->source = $source;
      $this->getToolkit()->setSource($this->source);
      // Defer image file validity check to the toolkit.       if ($this->getToolkit()->parseFile()) {
        $this->fileSize = filesize($this->source);
      }
    }
  }

  /** * {@inheritdoc} */
  public function isValid() {
    return $this->getToolkit()->isValid();
  }

  
$assert_session->assertWaitOnAjaxRequest();

    // Confirm allowed tags no longer has <drupal-media>.     $this->assertHtmlEsqueFieldValueEquals('filters[filter_html][settings][allowed_html]', $this->allowedElements);
  }

  /** * Tests full HTML text format. */
  public function testFullHtml() {
    FilterFormat::create(
      Yaml::parseFile('core/profiles/standard/config/install/filter.format.full_html.yml')
    )->save();
    FilterFormat::create(
      Yaml::parseFile('core/profiles/standard/config/install/filter.format.basic_html.yml')
    )->save();

    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // Add a node with text rendered via the Plain Text format.     $this->drupalGet('node/add');
    $page->fillField('title[0][value]', 'My test content');
    
if (!stream_is_local($file)) {
            throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
        }

        if (!is_file($file)) {
            throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
        }

        $this->yamlParser ??= new YamlParser();

        try {
            $configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
        } catch (ParseException $e) {
            throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $file).$e->getMessage(), 0, $e);
        }

        return $this->validate($configuration$file);
    }

    /** * Validates a YAML file. * * @throws InvalidArgumentException When service file is not valid */


    /** * Loads the YAML class descriptions from the given file. * * @throws \InvalidArgumentException If the file could not be loaded or did * not contain a YAML array */
    private function parseFile(string $path): array
    {
        try {
            $classes = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
        } catch (ParseException $e) {
            throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);
        }

        // empty file         if (null === $classes) {
            return [];
        }

        // not an array         if (!\is_array($classes)) {
            

      ],
    ];
  }

  /** * @covers ::getDynamicPluginConfig * @dataProvider providerGetDynamicPluginConfig */
  public function testGetDynamicPluginConfig(array $configuration, array $expected_dynamic_config): void {
    // Read the CKEditor 5 plugin's static configuration from YAML.     $ckeditor5_plugin_definitions = Yaml::parseFile(__DIR__ . '/../../../ckeditor5.ckeditor5.yml');
    $static_plugin_config = $ckeditor5_plugin_definitions['ckeditor5_alignment']['ckeditor5']['config'];

    $plugin = new Alignment($configuration, 'ckeditor5_alignment', NULL);
    $dynamic_plugin_config = $plugin->getDynamicPluginConfig($static_plugin_config$this->prophesize(EditorInterface::class)
      ->reveal());

    $this->assertSame($expected_dynamic_config$dynamic_plugin_config);
  }

}
'id' => 'filter_url',
          'provider' => 'filter',
          'status' => TRUE,
          'weight' => 10,
          'settings' => [
            'filter_url_length' => 72,
          ],
        ],
      ],
      'violations' => [],
    ];
    $restricted_html_format_filters = Yaml::parseFile(__DIR__ . '/../../../../../profiles/standard/config/install/filter.format.restricted_html.yml')['filters'];
    $data['INVALID: the default restricted_html text format'] = [
      'settings' => [
        'toolbar' => [
          'items' => [],
        ],
        'plugins' => [],
      ],
      'image_upload' => [
        'status' => FALSE,
      ],
      'filters' => $restricted_html_format_filters,
      
Home | Imprint | This part of the site doesn't use cookies.