<commit_before><?php
declare(strict_types=1);

namespace Neos\Flow\ResourceManagement\EelHelper;

/*
 * This file is part of the Neos.Flow package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\I18n\Service as I18nService;

class StaticResourceHelper implements ProtectedContextAwareInterface
{
    /**
     * @Flow\Inject
     * @var ResourceManager
     */
    protected $resourceManager;

    /**
     * @Flow\Inject
     * @var I18nService
     */
    protected $i18nService;

    /**
     * Get the public uri of a package resource
     *
     * @param string $packageKey
     * @param string $pathAndFilename
     * @param bool $localize
     * @return string
     */
    public function uri(string $packageKey, string $pathAndFilename, bool $localize = false): string
    {
        $resourcePath = sprintf('resource://%s/%s', $packageKey, $pathAndFilename);
        if ($localize === true) {
            $resourcePath = $this->i18nService->getLocalizedFilename($resourcePath);
        }
        return $this->resourceManager->getPublicPackageResourceUriByPath($resourcePath);
    }

    /**
     * Get the content of a package resource
     *
     * @param string $packageKey
     * @param string $pathAndFilename
     * @param bool $localize
     * @return string
     */
    public function content(string $packageKey, string $pathAndFilename, bool $localize = false): string
    {
        $resourcePath = sprintf('resource://%s/%s', $packageKey, $pathAndFilename);
        if ($localize === true) {
            $resourcePath = $this->i18nService->getLocalizedFilename($resourcePath);
        }
        $content = file_get_contents($resourcePath);
        return $content ?: '';
    }

    /**
     * @param string $methodName
     * @return bool
     */
    public function allowsCallOfMethod($methodName)<commit_msg>BUGFIX: Adjust handling of localizations in static resources<commit_after><?php
declare(strict_types=1);

namespace Neos\Flow\ResourceManagement\EelHelper;

/*
 * This file is part of the Neos.Flow package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\I18n\Service as I18nService;

class StaticResourceHelper implements ProtectedContextAwareInterface
{
    /**
     * @Flow\Inject
     * @var ResourceManager
     */
    protected $resourceManager;

    /**
     * @Flow\Inject
     * @var I18nService
     */
    protected $i18nService;

    /**
     * Get the public uri of a package resource
     *
     * @param string $packageKey
     * @param string $pathAndFilename
     * @param bool $localize
     * @return string
     */
    public function uri(string $packageKey, string $pathAndFilename, bool $localize = false): string
    {
        $resourcePath = sprintf('resource://%s/%s', $packageKey, $pathAndFilename);
        if ($localize === true) {
            $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
            $resourcePath = $localizedResourcePathData[0] ?? $resourcePath;
        }
        return $this->resourceManager->getPublicPackageResourceUriByPath($resourcePath);
    }

    /**
     * Get the content of a package resource
     *
     * @param string $packageKey
     * @param string $pathAndFilename
     * @param bool $localize
     * @return string
     */
    public function content(string $packageKey, string $pathAndFilename, bool $localize = false): string
    {
        $resourcePath = sprintf('resource://%s/%s', $packageKey, $pathAndFilename);
        if ($localize === true) {
            $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
            $resourcePath = $localizedResourcePathData[0] ?? $resourcePath;
        }
        $content = file_get_contents($resourcePath);
        return $content ?: '';
    }

    /**
     * @param string $methodName
     * @return bool
     */
    public function allowsCallOfMethod($methodName)
{'fraction_non_alphanumeric': 0.10851860004402378, 'fraction_numerical': 0.0061633281972265025, 'mean_word_length': 3.0141342756183747, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3873880', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1272, 'n_words': 330}