<commit_before><?php

namespace SvImages\Parser;

use SvImages\Exception\RuntimeException;
use SvImages\Exception\TransformerNotFoundException;
use SvImages\Exception\UnexpectedValueException;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */
class UriParser
{
    /**
     * @var Result
     */
    protected $result;

    /**
     * @var array
     */
    protected $options;

    /**
     * @param array $options
     */
    public function __construct(array $options)
    {
        $this->options = $options;
        $this->result  = new Result();
        $this->result->setRouteOptions($options);
    }

    /**
     * @param $path
     *
     * @return Result|null
     */
    public function parseUri($path)
    {
        $container = $this->options['container'];
        if (!preg_match(
            '/^\/' . preg_quote($container) . '(?:\/(?<transformers>[a-zA-Z0-9_\-,\/]+))\/f_key(?<file_path>\/.+)$/',
            $path,
            $matches
        )) {
            return null;
        }

        $result = $this->result;
        $result->setUriPath($path);
        $result->setContainer($container);
        $result->setFilePath($matches['file_path']);
        $result->setTransformers($this->parseTransformers($matches['transformers']));

        return $result;
    }

    /**
     * @param $transformersFromUri
     *<commit_msg>does not allowed '/' in container name<commit_after><?php

namespace SvImages\Parser;

use SvImages\Exception\RuntimeException;
use SvImages\Exception\TransformerNotFoundException;
use SvImages\Exception\UnexpectedValueException;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */
class UriParser
{
    /**
     * @var Result
     */
    protected $result;

    /**
     * @var array
     */
    protected $options;

    /**
     * @param array $options
     */
    public function __construct(array $options)
    {
        $this->options = $options;
        $this->result  = new Result();
        $this->result->setRouteOptions($options);
    }

    /**
     * @param $path
     *
     * @return Result|null
     */
    public function parseUri($path)
    {
        $container = $this->options['container'];
        if (!preg_match(
            '/^\/' . preg_quote($container, '/') . '(?:\/(?<transformers>[a-zA-Z0-9_\-,\/]+))\/f_key(?<file_path>\/.+)$/',
            $path,
            $matches
        )) {
            return null;
        }

        $result = $this->result;
        $result->setUriPath($path);
        $result->setContainer($container);
        $result->setFilePath($matches['file_path']);
        $result->setTransformers($this->parseTransformers($matches['transformers']));

        return $result;
    }

    /**
     * @param $transformersFromUri
     *
{'fraction_non_alphanumeric': 0.1695970695970696, 'fraction_numerical': 0.0014652014652014652, 'mean_word_length': 2.175581395348837, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4299403', 'n_tokens_mistral': 828, 'n_tokens_neox': 817, 'n_words': 133}