<commit_before><?php
namespace wcf\system\application;
use wcf\system\cache\CacheHandler;
use wcf\system\SingletonFactory;

/**
 * Handles multi-application environments.
 * 
 * @author	<NAME>
 * @copyright	2001-20121 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.application
 * @category	Community Framework
 */
class ApplicationHandler extends SingletonFactory {
	/**
	 * application cache
	 * @var	array<array>
	 */	
	protected $cache = null;
	
	/**
	 * Initializes cache.
	 */
	protected function init() {
		$cacheName = 'application-'.PACKAGE_ID;
		CacheHandler::getInstance()->addResource(
			$cacheName,
			WCF_DIR.'cache/cache.'.$cacheName.'.php',
			'wcf\system\cache\builder\ApplicationCacheBuilder'
		);
		$this->cache = CacheHandler::getInstance()->get($cacheName);
	}
	
	/**
	 * Returns the primary application for current group. Will return current
	 * application equal to PACKAGE_ID if not within any group.
	 * 
	 * @return	wcf\data\application\Application
	 */
	public function getPrimaryApplication() {
		$packageID = ($this->cache['primary']) ?: PACKAGE_ID;
		return $this->cache['application'][$packageID];
	}
	
	/**
	 * Returns an application based upon it's abbreviation. Will return the
	 * primary application if $abbreviation equals to 'wcf'
	 * 
	 * @return	wcf\data\application\Application
	 */	 
	public function getApplication($abbreviation) {
		if ($abbreviation == 'wcf') {
			return $this->getPrimaryApplication();
		}
		
		if (isset($this->cache['abbreviation'][$abbreviation])) {
			$packageID = $this->cache['abbreviation'][$abbreviation];
			
			if (isset($this->cache['application'][$packageID])) {
				return $this->cache['application'][$packageID];
			}
		}
		
		return null;
	}
	
	/**
	 * Returns active application group or 'null' if current application
	 * is not within a group.
	 * 
	 * @return	wcf\data\application\group\ApplicationGroup
	 */	
	public function getActiveGroup() {
		return $this->cache['group'];
	}
	
	/**
	 * Returns pseudo-application representing WCF used for special cases,
	 * e.g. cross-domain files requestable through the webserver.
	 * 
	 * @return	wcf\data\application\Application
	 */
	public function getWCF() {
		return $this->cache['wcf'];
	}
	
	/**
	 * Returns the currently active application.
	 * 
	 * @return	wcf\data\application\Application
	 */	
	public function getActiveApplication() {
		return $this->cache['application'][PACKAGE_ID];
	}
	
	/**
	 * Returns a list of dependent applications.
	 * 
	 * @return	array<wcf\data\application\Application>
	 */	
	public function getDependentApplications() {
		$applications = array();
		foreach ($this->cache['application'] as $packageID => $application) {
			if ($packageID == PACKAGE_ID) continue;
			
			$applications[] = $application;
		}
		
		return $applications;
	}
	
	/**
	 * Returns abbreviation for a given package id or null if application is unknown.
	 * 
	 * @return	string
	 */
	public function getAbbreviation($packageID) {
		foreach ($this->cache['abbreviation'] as $abbreviation => $applicationID) {
			if ($packageID == $applicationID) {
				return $abbreviation;
			}
		}
		
		return null;
	}
}
<commit_msg>Added method to return all active applications<commit_after><?php
namespace wcf\system\application;
use wcf\system\cache\CacheHandler;
use wcf\system\SingletonFactory;

/**
 * Handles multi-application environments.
 * 
 * @author	<NAME>
 * @copyright	2001-20121 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.application
 * @category	Community Framework
 */
class ApplicationHandler extends SingletonFactory {
	/**
	 * application cache
	 * @var	array<array>
	 */	
	protected $cache = null;
	
	/**
	 * Initializes cache.
	 */
	protected function init() {
		$cacheName = 'application-'.PACKAGE_ID;
		CacheHandler::getInstance()->addResource(
			$cacheName,
			WCF_DIR.'cache/cache.'.$cacheName.'.php',
			'wcf\system\cache\builder\ApplicationCacheBuilder'
		);
		$this->cache = CacheHandler::getInstance()->get($cacheName);
	}
	
	/**
	 * Returns the primary application for current group. Will return current
	 * application equal to PACKAGE_ID if not within any group.
	 * 
	 * @return	wcf\data\application\Application
	 */
	public function getPrimaryApplication() {
		$packageID = ($this->cache['primary']) ?: PACKAGE_ID;
		return $this->cache['application'][$packageID];
	}
	
	/**
	 * Returns an application based upon it's abbreviation. Will return the
	 * primary application if $abbreviation equals to 'wcf'
	 * 
	 * @return	wcf\data\application\Application
	 */	 
	public function getApplication($abbreviation) {
		if ($abbreviation == 'wcf') {
			return $this->getPrimaryApplication();
		}
		
		if (isset($this->cache['abbreviation'][$abbreviation])) {
			$packageID = $this->cache['abbreviation'][$abbreviation];
			
			if (isset($this->cache['application'][$packageID])) {
				return $this->cache['application'][$packageID];
			}
		}
		
		return null;
	}
	
	/**
	 * Returns active application group or 'null' if current application
	 * is not within a group.
	 * 
	 * @return	wcf\data\application\group\ApplicationGroup
	 */	
	public function getActiveGroup() {
		return $this->cache['group'];
	}
	
	/**
	 * Returns pseudo-application representing WCF used for special cases,
	 * e.g. cross-domain files requestable through the webserver.
	 * 
	 * @return	wcf\data\application\Application
	 */
	public function getWCF() {
		return $this->cache['wcf'];
	}
	
	/**
	 * Returns the currently active application.
	 * 
	 * @return	wcf\data\application\Application
	 */	
	public function getActiveApplication() {
		return $this->cache['application'][PACKAGE_ID];
	}
	
	/**
	 * Returns a list of dependent applications.
	 * 
	 * @return	array<wcf\data\application\Application>
	 */	
	public function getDependentApplications() {
		$applications = array();
		foreach ($this->cache['application'] as $packageID => $application) {
			if ($packageID == PACKAGE_ID) continue;
			
			$applications[] = $application;
		}
		
		return $applications;
	}
	
	/**
	 * Returns a list of all active applications.
	 * 
	 * @return	array<wcf\data\application\Application>
	 */
	public function getApplications() {
		$applications = $this->getDependentApplications();
		$applications[] = $this->getActiveApplication();
		
		return $applications;
	}
	
	/**
	 * Returns abbreviation for a given package id or null if application is unknown.
	 * 
	 * @return	string
	 */
	public function getAbbreviation($packageID) {
		foreach ($this->cache['abbreviation'] as $abbreviation => $applicationID) {
			if ($packageID == $applicationID) {
				return $abbreviation;
			}
		}
		
		return null;
	}
}

{'fraction_non_alphanumeric': 0.136456509048453, 'fraction_numerical': 0.002626970227670753, 'mean_word_length': 3.856839121190645, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 48, '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': '2771857', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2001, 'n_words': 486}