<commit_before><?php
namespace AssetCompress\View\Helper;

use AssetCompress\AssetTarget;
use AssetCompress\Config\ConfigFinder;
use AssetCompress\Factory;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Routing\Router;
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\View\View;
use RuntimeException;

/**
 * AssetCompress Helper.
 *
 * Handle inclusion assets using the AssetCompress features for concatenating and
 * compressing asset files.
 *
 */
class AssetCompressHelper extends Helper
{

    /**
     * Helpers used.
     *
     * @var array
     */
    public $helpers = array('Html');

    /**
     * Configuration object
     *
     * @var AssetConfig
     */
    protected $config;

    /**
     * Factory for other AssetCompress objects.
     *
     * @var AssetCompress\Factory
     */
    protected $factory;

    /**
     * AssetCollection for the current config set.
     *
     * @var AssetCompress\AssetCollection
     */
    protected $collection;

    /**
     * AssetWriter instance
     *
     * @var AssetCompress\AssetWriter
     */
    protected $writer;

    /**
     * Options for the helper
     *
     * - `autoIncludePath` - Path inside of webroot/js that contains autoloaded view js.
     *
     * @var array
     */
    public $options = array(
        'autoIncludePath' => 'views'
    );

    /**
     * Disable autoInclusion of view js files.
     *
     * @var string
     */
    public $autoInclude = true;

    /**
     * Constructor - finds and parses the ini file the plugin uses.
     *
     * @return void
     */
    public function __construct(View $View, $settings = array())
    {
        parent::__construct($View, $settings);
        if (empty($settings['noconfig'])) {
            $configFinder = new ConfigFinder();
            $this->assetConfig($configFinder->loadAll());
        }
    }

    /**
     * Modify the runtime configuration of the helper.
     * Used as a get/set for the ini file values.
     *
     * @param AssetCompress\AssetConfig $config The config instance to set.
     * @return Either the current config object or null.
     */
    public function assetConfig($config = null)
    {
        if ($config === null) {
            return $this->config;
        }
        $this->config = $config;
    }

    /**
     * Get the AssetCompress factory based on the config object.
     *
     * @return AssetCompress\Factory
     */
    protected function factory()
    {
        if (empty($this->factory)) {
            $this->config->theme($this->theme);
            $this->factory = new Factory($this->config);
        }
        return $this->factory;
    }

    /**
     * Get the AssetCollection
     *
     * @return AssetCompress\AssetCollection
     */
    protected function collection()
    {
        if (empty($this->collection)) {
            $this->collection = $this->factory()->assetCollection();
        }
        return $this->collection;
    }

    /**
     * Get the AssetWriter
     *
     * @return AssetCompress\AssetWriter
     */
    protected function writer()
    {
        if (empty($this->writer)) {
            $this->writer = $this->factory()->writer();
        }
        return $this->writer;
    }

    /**
     * AfterRender callback.
     *
     * Adds automatic view js files if enabled.
     * Adds css/js files that have been added to the concatenation lists.
     *
     * Auto file inclusion adopted from <NAME> helper
     * http://bakery.cakephp.org/articles/view/automatic-javascript-includer-helper
     *
     * @return void
     */
    public function afterRender($viewFile)
    {
        $this->_includeViewJs();
    }

    /**
     * Includes the auto view js files if enabled.
     *
     * @return void
     */
    protected function _includeViewJs()
    {
        if (!$this->autoInclude) {
            return;
        }
        $files = array(
            $this->params['controller'] . '.js',
            $this->params['controller'] . DS . $this->params['action'] . '.js'
        );

        foreach ($files as $file) {
            $includeFile = Configure::read('App.jsBaseUrl') . $this->options['autoIncludePath'] . DS . $file;
            if (file_exists($includeFile)) {
                $this->Html->script(
                    str_replace(DS, '/', $this->options['autoIncludePath'] . '/' . $file),
                    array('inline' => false)
                );
            }
        }
    }

    /**
     * Adds an extension if the file doesn't already end with it.
     *
     * @param string $file Filename
     * @param string $ext Extension with .
     * @return string
     */
    protected function _addExt($file, $ext)
    {
        if (substr($file, strlen($ext) * -1) !== $ext) {
            $file .= $ext;
        }
        return $file;
    }

    /**
     * Create a CSS file. Will generate link tags
     * for either the dynamic build controller, or the generated file if it exists.
     *<commit_msg>Remove the automatic javascript inclusion.<commit_after><?php
namespace AssetCompress\View\Helper;

use AssetCompress\AssetTarget;
use AssetCompress\Config\ConfigFinder;
use AssetCompress\Factory;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Routing\Router;
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\View\View;
use RuntimeException;

/**
 * AssetCompress Helper.
 *
 * Handle inclusion assets using the AssetCompress features for concatenating and
 * compressing asset files.
 *
 */
class AssetCompressHelper extends Helper
{

    /**
     * Helpers used.
     *
     * @var array
     */
    public $helpers = array('Html');

    /**
     * Configuration object
     *
     * @var AssetConfig
     */
    protected $config;

    /**
     * Factory for other AssetCompress objects.
     *
     * @var AssetCompress\Factory
     */
    protected $factory;

    /**
     * AssetCollection for the current config set.
     *
     * @var AssetCompress\AssetCollection
     */
    protected $collection;

    /**
     * AssetWriter instance
     *
     * @var AssetCompress\AssetWriter
     */
    protected $writer;

    /**
     * Constructor - finds and parses the ini file the plugin uses.
     *
     * @return void
     */
    public function __construct(View $View, $settings = array())
    {
        parent::__construct($View, $settings);
        if (empty($settings['noconfig'])) {
            $configFinder = new ConfigFinder();
            $this->assetConfig($configFinder->loadAll());
        }
    }

    /**
     * Modify the runtime configuration of the helper.
     * Used as a get/set for the ini file values.
     *
     * @param AssetCompress\AssetConfig $config The config instance to set.
     * @return Either the current config object or null.
     */
    public function assetConfig($config = null)
    {
        if ($config === null) {
            return $this->config;
        }
        $this->config = $config;
    }

    /**
     * Get the AssetCompress factory based on the config object.
     *
     * @return AssetCompress\Factory
     */
    protected function factory()
    {
        if (empty($this->factory)) {
            $this->config->theme($this->theme);
            $this->factory = new Factory($this->config);
        }
        return $this->factory;
    }

    /**
     * Get the AssetCollection
     *
     * @return AssetCompress\AssetCollection
     */
    protected function collection()
    {
        if (empty($this->collection)) {
            $this->collection = $this->factory()->assetCollection();
        }
        return $this->collection;
    }

    /**
     * Get the AssetWriter
     *
     * @return AssetCompress\AssetWriter
     */
    protected function writer()
    {
        if (empty($this->writer)) {
            $this->writer = $this->factory()->writer();
        }
        return $this->writer;
    }

    /**
     * Adds an extension if the file doesn't already end with it.
     *
     * @param string $file Filename
     * @param string $ext Extension with .
     * @return string
     */
    protected function _addExt($file, $ext)
    {
        if (substr($file, strlen($ext) * -1) !== $ext) {
            $file .= $ext;
        }
        return $file;
    }

    /**
     * Create a CSS file. Will generate link tags
     * for either the dynamic build controller, or the generated file if it exists.
     *
{'fraction_non_alphanumeric': 0.12158927716610819, 'fraction_numerical': 0.00023934897079942556, 'mean_word_length': 1.9582300884955752, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 57, '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': '7473222', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2330, 'n_words': 621}