<commit_before><?php

/*
 * This file is part of the Sylius package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sylius\Bundle\ResourceBundle\Controller;

use FOS\RestBundle\Util\Pluralization;
use Symfony\Component\HttpFoundation\Request;

/**
 * Resource controller configuration.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class Configuration
{
    protected $bundlePrefix;
    protected $resourceName;
    protected $pluralResourceName;
    protected $templateNamespace;

    /**
     * @var Request
     */
    protected $request;

    public function __construct($bundlePrefix, $resourceName, $templateNamespace = null)
    {
        $this->bundlePrefix = $bundlePrefix;
        $this->resourceName = $resourceName;
        $this->pluralResourceName = Pluralization::pluralize($resourceName);
        $this->templateNamespace = $templateNamespace;
    }

    public function getBundlePrefix()
    {
        return $this->bundlePrefix;
    }

    public function getResourceName()
    {
        return $this->resourceName;
    }

    public function getPluralResourceName()
    {
        return $this->pluralResourceName;
    }

    public function getTemplateNamespace()
    {
        return $this->templateNamespace;
    }

    public function setRequest(Request $request)
    {
        $this->request = $request;
    }

    public function isHtmlRequest()
    {
        if (null === $this->request) {
            throw new \BadMethodCallException('Request is unknown, cannot check its format');
        }

        return 'html' === $this->request->getRequestFormat();
    }

    public function isApiRequest()
    {
        return !$this->isHtmlRequest();
    }

    public function getServiceName($service)
    {
        return sprintf('%s.%s.%s', $this->bundlePrefix, $service, $this->resourceName);
    }

    public function getEventName($event)
    {
        return sprintf('%s.%s.%s', $this->bundlePrefix, $this->resourceName, $event);
    }

    public function getIdentifierName()
    {
        return $this->get('_identifier', 'id');
    }

    public function getIdentifierValue()
    {
        return $this->request->get($this->getIdentifierName());
    }

    public function getIdentifierCriteria()
    {
        if (null === $this->request) {
            throw new \BadMethodCallException('Request is unknown, cannot get single resource criteria');
        }

        return array(
            $this->getIdentifierName() => $this->getIdentifierValue()
        );
    }

    public function getTemplate()
    {
        return $this->get('_template');
    }

    public function getFormType()
    {
        return $this->get('_form', $this->getDefaultFormType());
    }

    public function getDefaultFormType()
    {
        return sprintf('%s_%s', $this->bundlePrefix, $this->resourceName);
    }

    public function getRedirectRoute()
    {
        $redirect = $this->get('_redirect');

        if (is_array($redirect)) {
            return $redirect['route'];
        }

        return $redirect;
    }

    public function getRedirectParameters()
    {
        $redirect = $this->get('_redirect');

        if (!is_array($redirect)) {
            return array();
        }

        foreach ($redirect['parameters'] as $key => $parameter) {
            if ('$' === $parameter[0]) {
                $redirect['parameters'][$key] = $this->request->get(str_replace('$', '', $redirect['parameters'][$key]));
            }
        }

        return $redirect['parameters'];
    }

    public function isPaginated()
    {
        return (Boolean) $this->get('_paginate', true);
    }

    public function getPaginationMaxPerPage()
    {
        return (int) $this->get('_paginate', 10);
    }

    public function getLimit()
    {
        return (int) $this->get('_limit', 10);
    }

    public function isSortable()
    {
        return (Boolean) $this->get('_sortable', false);
    }

    public function isFilterable()
    {
        return (Boolean) $this->get('_filterable', false);
    }

    public function getCriteria()
    {
        $defaultCriteria = $this->get('_criteria', array());

        if ($this->isFilterable() && null !== $this->request) {
            return $this->request->get('criteria', $defaultCriteria);
        }

        return $defaultCriteria;
    }

    public function getSorting()
    {
        $defaultSorting = $this->get('_sorting', array());

        if ($this->isSortable() && null !== $this->request) {
            return $this->request->get('sorting', $defaultSorting);
        }

        return $defaultSorting;
    }

    public function getFlashMessage()
    {
        return $this->get('_flash');
    }

    public function getRoute()
    {
        return sprintf('%s_%s', $this->bundlePrefix, $this->resourceName);
    }

    public function getIndexRoute()
    {
        return sprintf('%s_%s', $this->bundlePrefix, $this->pluralResourceName);
    }

    public function getEngineParameterName()
    {
        return sprintf('%s.engine', $this->getBundlePrefix());
    }

    protected function get($parameter, $default = null)
    {
        if (null === $this->request) {
            return $default;
        }

        return $this->request->attributes->get($parameter, $default);
    }
}<commit_msg>Use _sylius Prefix Again<commit_after><?php

/*
 * This file is part of the Sylius package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sylius\Bundle\ResourceBundle\Controller;

use FOS\RestBundle\Util\Pluralization;
use Symfony\Component\HttpFoundation\Request;

/**
 * Resource controller configuration.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class Configuration
{
    protected $bundlePrefix;
    protected $resourceName;
    protected $pluralResourceName;
    protected $templateNamespace;

    /**
     * @var Request
     */
    protected $request;

    public function __construct($bundlePrefix, $resourceName, $templateNamespace = null)
    {
        $this->bundlePrefix = $bundlePrefix;
        $this->resourceName = $resourceName;
        $this->pluralResourceName = Pluralization::pluralize($resourceName);
        $this->templateNamespace = $templateNamespace;
    }

    public function getBundlePrefix()
    {
        return $this->bundlePrefix;
    }

    public function getResourceName()
    {
        return $this->resourceName;
    }

    public function getPluralResourceName()
    {
        return $this->pluralResourceName;
    }

    public function getTemplateNamespace()
    {
        return $this->templateNamespace;
    }

    public function setRequest(Request $request)
    {
        $this->request = $request;
    }

    public function isHtmlRequest()
    {
        if (null === $this->request) {
            throw new \BadMethodCallException('Request is unknown, cannot check its format');
        }

        return 'html' === $this->request->getRequestFormat();
    }

    public function isApiRequest()
    {
        return !$this->isHtmlRequest();
    }

    public function getServiceName($service)
    {
        return sprintf('%s.%s.%s', $this->bundlePrefix, $service, $this->resourceName);
    }

    public function getEventName($event)
    {
        return sprintf('%s.%s.%s', $this->bundlePrefix, $this->resourceName, $event);
    }

    public function getIdentifierName()
    {
        return $this->get('_identifier', 'id');
    }

    public function getIdentifierValue()
    {
        return $this->request->get($this->getIdentifierName());
    }

    public function getIdentifierCriteria()
    {
        if (null === $this->request) {
            throw new \BadMethodCallException('Request is unknown, cannot get single resource criteria');
        }

        return array(
            $this->getIdentifierName() => $this->getIdentifierValue()
        );
    }

    public function getTemplate()
    {
        return $this->get('_template');
    }

    public function getFormType()
    {
        return $this->get('_form', $this->getDefaultFormType());
    }

    public function getDefaultFormType()
    {
        return sprintf('%s_%s', $this->bundlePrefix, $this->resourceName);
    }

    public function getRedirectRoute()
    {
        $redirect = $this->get('_redirect');

        if (is_array($redirect)) {
            return $redirect['route'];
        }

        return $redirect;
    }

    public function getRedirectParameters()
    {
        $redirect = $this->get('_redirect');

        if (!is_array($redirect)) {
            return array();
        }

        foreach ($redirect['parameters'] as $key => $parameter) {
            if ('$' === $parameter[0]) {
                $redirect['parameters'][$key] = $this->request->get(str_replace('$', '', $redirect['parameters'][$key]));
            }
        }

        return $redirect['parameters'];
    }

    public function isPaginated()
    {
        return (Boolean) $this->get('_paginate', true);
    }

    public function getPaginationMaxPerPage()
    {
        return (int) $this->get('_paginate', 10);
    }

    public function getLimit()
    {
        return (int) $this->get('_limit', 10);
    }

    public function isSortable()
    {
        return (Boolean) $this->get('_sortable', false);
    }

    public function isFilterable()
    {
        return (Boolean) $this->get('_filterable', false);
    }

    public function getCriteria()
    {
        $defaultCriteria = $this->get('_criteria', array());

        if ($this->isFilterable() && null !== $this->request) {
            return $this->request->get('criteria', $defaultCriteria);
        }

        return $defaultCriteria;
    }

    public function getSorting()
    {
        $defaultSorting = $this->get('_sorting', array());

        if ($this->isSortable() && null !== $this->request) {
            return $this->request->get('sorting', $defaultSorting);
        }

        return $defaultSorting;
    }

    public function getFlashMessage()
    {
        return $this->get('_flash');
    }

    public function getRoute()
    {
        return sprintf('%s_%s', $this->bundlePrefix, $this->resourceName);
    }

    public function getIndexRoute()
    {
        return sprintf('%s_%s', $this->bundlePrefix, $this->pluralResourceName);
    }

    public function getEngineParameterName()
    {
        return sprintf('%s.engine', $this->getBundlePrefix());
    }

    protected function get($parameter, $default = null)
    {
        if (null === $this->request) {
            return $default;
        }

        return $result = $this->request->attributes->get('_'.$this->bundlePrefix .'.'.  $parameter, $default);
    }
}
{'fraction_non_alphanumeric': 0.14129234167893961, 'fraction_numerical': 0.0009204712812960235, 'mean_word_length': 2.4935691318327975, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 138, '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': '6078007', 'n_tokens_mistral': 3089, 'n_tokens_neox': 3002, 'n_words': 653}