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

use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\View\View;

class FrontendBridgeHelper extends Helper {

/**
 * The helpers we need
 */
	public $helpers = array('Html');

/**
 * Holds the needed JS dependencies.
 *
 * @var array
 */
	protected $_dependencies = array(
		'/frontend_bridge/js/lib/basics.js',
		'/frontend_bridge/js/lib/jinheritance.js',
		'/frontend_bridge/js/lib/publish_subscribe_broker.js',
		'/frontend_bridge/js/lib/app.js',
		'/frontend_bridge/js/lib/controller.js',
		'/frontend_bridge/js/lib/component.js',
		'/frontend_bridge/js/lib/dialog.js',
		'/frontend_bridge/js/lib/router.js',
		'/frontend_bridge/js/lib/ui_blocker.js',
		'/frontend_bridge/js/vendor/jquery.blockUI.js'
	);

/**
 * Holds the frontendData array created by the Component
 *
 * @var array
 */
	protected $_frontendData = array(
		'jsonData' => array()
	);

/**
 * Array of plugin names of the plugin js controllers which are loaded.
 *
 * @var array
 */
	protected $_pluginJsNamespaces = [];

/**
 * Initialize the helper. Needs to be called before running it.
 *
 * @param array $frontendData Data to be passed to the frontend
 * @return void
 */
	public function init($frontendData) {
		$this->_frontendData = Hash::merge(
			$this->_frontendData, $frontendData
		);
		$this->_includeAppController();
		$this->_includeComponents();
	}

/**
 * Compiles an AssetCompress-compatible list of assets to be used in asset_compress.ini
 * files as a callback method
 *
 * @return array
 */
	public static function getAssetCompressFiles() {
		$helper = new FrontendBridgeHelper(new View());
		$dependencies = $helper->compileDependencies();
		$plugins = array_map('\Cake\Utility\Inflector::underscore', Plugin::loaded());

		foreach ($dependencies as $n => $dependency) {
			$parts = explode('/', $dependency);
			if (empty($parts[0]) && in_array($parts[1], $plugins)) {
				$prefix = '/' . $parts[1] . '/';
				$dependency = preg_replace('/^' . str_replace('/', '\/', $prefix) . '/', 'plugin:' . Inflector::camelize($parts[1]) . ':/', $dependency);
			}
			if (substr($dependency, 0, 4) == '/js/') {
				$dependency = substr($dependency, 4);
			}
			$dependencies[$n] = $dependency;
		}
		return $dependencies;
	}

/**
 * Constructs the classes for the element that represents the frontend controller's DOM
 * reference.
 *
 * @return string
 */
	public function getMainContentClasses() {
		$classes = ['controller'];
		$classes[] = Inflector::underscore($this->_View->request->controller) . '-' . Inflector::underscore($this->_View->request->action);
		return implode(' ', $classes);
	}

/**
 * Returns a full list of the dependencies (used in console build task)
 *
 * @param array $defaultControllers which JS controllers to include before all others<commit_msg>Fix for having plugin dependencies be loading correctly by AssetCompress if the app is running in a subdirectory<commit_after><?php
namespace FrontendBridge\View\Helper;

use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\View\View;

class FrontendBridgeHelper extends Helper {

/**
 * The helpers we need
 */
	public $helpers = array('Html');

/**
 * Holds the needed JS dependencies.
 *
 * @var array
 */
	protected $_dependencies = array(
		'/frontend_bridge/js/lib/basics.js',
		'/frontend_bridge/js/lib/jinheritance.js',
		'/frontend_bridge/js/lib/publish_subscribe_broker.js',
		'/frontend_bridge/js/lib/app.js',
		'/frontend_bridge/js/lib/controller.js',
		'/frontend_bridge/js/lib/component.js',
		'/frontend_bridge/js/lib/dialog.js',
		'/frontend_bridge/js/lib/router.js',
		'/frontend_bridge/js/lib/ui_blocker.js',
		'/frontend_bridge/js/vendor/jquery.blockUI.js'
	);

/**
 * Holds the frontendData array created by the Component
 *
 * @var array
 */
	protected $_frontendData = array(
		'jsonData' => array()
	);

/**
 * Array of plugin names of the plugin js controllers which are loaded.
 *
 * @var array
 */
	protected $_pluginJsNamespaces = [];

/**
 * Initialize the helper. Needs to be called before running it.
 *
 * @param array $frontendData Data to be passed to the frontend
 * @return void
 */
	public function init($frontendData) {
		$this->_frontendData = Hash::merge(
			$this->_frontendData, $frontendData
		);
		$this->_includeAppController();
		$this->_includeComponents();
	}

/**
 * Compiles an AssetCompress-compatible list of assets to be used in asset_compress.ini
 * files as a callback method
 *
 * @return array
 */
	public static function getAssetCompressFiles() {
		$helper = new FrontendBridgeHelper(new View());
		$dependencies = $helper->compileDependencies();
		$plugins = array_map('\Cake\Utility\Inflector::underscore', Plugin::loaded());

		foreach ($dependencies as $n => $dependency) {
			$parts = explode('/', $dependency);
			if (empty($parts[0]) && in_array($parts[1], $plugins)) {
				$prefix = '/' . $parts[1] . '/';
				$dependency = preg_replace('/^' . str_replace('/', '\/', $prefix) . '/', 'plugin:' . Inflector::camelize($parts[1]) . ':', $dependency);
			}
			if (substr($dependency, 0, 4) == '/js/') {
				$dependency = substr($dependency, 4);
			}
			$dependencies[$n] = $dependency;
		}
		return $dependencies;
	}

/**
 * Constructs the classes for the element that represents the frontend controller's DOM
 * reference.
 *
 * @return string
 */
	public function getMainContentClasses() {
		$classes = ['controller'];
		$classes[] = Inflector::underscore($this->_View->request->controller) . '-' . Inflector::underscore($this->_View->request->action);
		return implode(' ', $classes);
	}

/**
 * Returns a full list of the dependencies (used in console build task)
 *
 * @param array $defaultControllers which JS controllers to include before all others
{'fraction_non_alphanumeric': 0.15635451505016723, 'fraction_numerical': 0.0023411371237458192, 'mean_word_length': 4.11633875106929, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '919536', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1893, 'n_words': 466}