<commit_before><?php

abstract class CM_Site_Abstract extends CM_Class_Abstract {

	protected $_themes = array();
	protected $_namespaces = array();
	/**
	 * @var CM_EventHandler_EventHandler
	 */
	protected $_eventHandler = null;

	/**
	 * Default constructor to set CM namespace
	 */
	public function __construct() {
		$this->_setNamespace('CM');
	}

	/**
	 * @return string
	 */
	public function getEmailAddress() {
		return self::_getConfig()->emailAddress;
	}

	/**
	 * @return CM_EventHandler_EventHandler
	 */
	public function getEventHandler() {
		if (!$this->_eventHandler) {
			$this->_eventHandler = new CM_EventHandler_EventHandler();
			$this->bindEvents($this->_eventHandler);
		}
		return $this->_eventHandler;
	}

	/**
	 * @param CM_EventHandler_EventHandler $eventHandler
	 */
	public function bindEvents(CM_EventHandler_EventHandler $eventHandler) {
	}

	/**
	 * @return string
	 */
	public function getNamespace() {
		return $this->_namespaces[0];
	}

	/**
	 * @return string[]
	 */
	public function getNamespaces() {
		return $this->_namespaces;
	}

	/**
	 * @return CM_Menu[]
	 */
	public function getMenus() {
		return array();
	}

	/**
	 * @param CM_Page_Abstract $page
	 * @return CM_MenuEntry[]
	 */
	public function getMenuEntriesActive(CM_Page_Abstract $page) {
		$menuEntries = array();
		foreach ($this->getMenus() as $menu) {
			foreach ($menu->findEntries($page) as $menuEntry) {
				$menuEntries[] = $menuEntry;
				foreach ($menuEntry->getParents() as $parentEntry) {
					$menuEntries[] = $parentEntry;
				}
			}
		}
		return $menuEntries;
	}

	/**
	 * @return string
	 */
	public function getName() {
		return self::_getConfig()->name;
	}

	/**
	 * @return string Theme
	 */
	public function getTheme() {
		return $this->_themes[0];
	}

	/**
	 * @return string[]
	 */
	public function getThemes() {
		return $this->_themes;
	}

	/**
	 * @return string
	 */
	public function getUrlCdn() {
		return self::_getConfig()->urlCdn;
	}

	/**
	 * @return string
	 */
	public function getUrl() {
		return self::_getConfig()->url;
	}

	/**
	 * @param CM_Response_Page $response
	 */
	public function preprocessPageResponse(CM_Response_Page $response) {
	}

	/**
	 * @param CM_Request_Abstract $request
	 */
	public function rewrite(CM_Request_Abstract $request) {
		if ($request->getPath() == '/') {
			$request->setPath('/index');
		}
	}

	/**
	 * @param string $theme
	 * @return CM_Site_Abstract
	 */
	protected function _addTheme($theme) {
		array_unshift($this->_themes, (string) $theme);
		return $this;
	}

	/**
	 * @param string $namespace
	 * @return CM_Site_Abstract
	 */
	protected function _setNamespace($namespace) {
		array_unshift($this->_namespaces, (string) $namespace);
		// Resets themes if new namespace is set
		$this->_themes = array('default');
		return $this;
	}

	/**
	 * @param CM_Request_Abstract $request
	 * @return boolean
	 */
	public static function match(CM_Request_Abstract $request) {
		return false;
	}

	/**
	 * @param int|null $type
	 * @return CM_Site_Abstract
	 * @throws CM_Exception
	 */
	public static function factory($type = null) {
		$class = self::_getClassName($type);
		return new $class();
	}

	/**
	 * @return int Site id
	 */
	public function getId() {
		return $this->getType();
	}

	/**
	 * @param CM_Request_Abstract $request
	 * @return CM_Site_Abstract
	 * @throws CM_Exception_Invalid
	 */
	public static function findByRequest(CM_Request_Abstract $request) {
		/** @var CM_Site_Abstract $className */
		foreach (array_reverse(static::getClassChildren()) as $className) {
			if ($className::match($request)) {
				return new $className();
			}
		}
		throw new CM_Exception_Invalid('Cannot identify site from current request');
	}
}
<commit_msg>Match default site in request matching<commit_after><?php

abstract class CM_Site_Abstract extends CM_Class_Abstract {

	protected $_themes = array();
	protected $_namespaces = array();
	/**
	 * @var CM_EventHandler_EventHandler
	 */
	protected $_eventHandler = null;

	/**
	 * Default constructor to set CM namespace
	 */
	public function __construct() {
		$this->_setNamespace('CM');
	}

	/**
	 * @return string
	 */
	public function getEmailAddress() {
		return self::_getConfig()->emailAddress;
	}

	/**
	 * @return CM_EventHandler_EventHandler
	 */
	public function getEventHandler() {
		if (!$this->_eventHandler) {
			$this->_eventHandler = new CM_EventHandler_EventHandler();
			$this->bindEvents($this->_eventHandler);
		}
		return $this->_eventHandler;
	}

	/**
	 * @param CM_EventHandler_EventHandler $eventHandler
	 */
	public function bindEvents(CM_EventHandler_EventHandler $eventHandler) {
	}

	/**
	 * @return string
	 */
	public function getNamespace() {
		return $this->_namespaces[0];
	}

	/**
	 * @return string[]
	 */
	public function getNamespaces() {
		return $this->_namespaces;
	}

	/**
	 * @return CM_Menu[]
	 */
	public function getMenus() {
		return array();
	}

	/**
	 * @param CM_Page_Abstract $page
	 * @return CM_MenuEntry[]
	 */
	public function getMenuEntriesActive(CM_Page_Abstract $page) {
		$menuEntries = array();
		foreach ($this->getMenus() as $menu) {
			foreach ($menu->findEntries($page) as $menuEntry) {
				$menuEntries[] = $menuEntry;
				foreach ($menuEntry->getParents() as $parentEntry) {
					$menuEntries[] = $parentEntry;
				}
			}
		}
		return $menuEntries;
	}

	/**
	 * @return string
	 */
	public function getName() {
		return self::_getConfig()->name;
	}

	/**
	 * @return string Theme
	 */
	public function getTheme() {
		return $this->_themes[0];
	}

	/**
	 * @return string[]
	 */
	public function getThemes() {
		return $this->_themes;
	}

	/**
	 * @return string
	 */
	public function getUrlCdn() {
		return self::_getConfig()->urlCdn;
	}

	/**
	 * @return string
	 */
	public function getUrl() {
		return self::_getConfig()->url;
	}

	/**
	 * @param CM_Response_Page $response
	 */
	public function preprocessPageResponse(CM_Response_Page $response) {
	}

	/**
	 * @param CM_Request_Abstract $request
	 */
	public function rewrite(CM_Request_Abstract $request) {
		if ($request->getPath() == '/') {
			$request->setPath('/index');
		}
	}

	/**
	 * @param string $theme
	 * @return CM_Site_Abstract
	 */
	protected function _addTheme($theme) {
		array_unshift($this->_themes, (string) $theme);
		return $this;
	}

	/**
	 * @param string $namespace
	 * @return CM_Site_Abstract
	 */
	protected function _setNamespace($namespace) {
		array_unshift($this->_namespaces, (string) $namespace);
		// Resets themes if new namespace is set
		$this->_themes = array('default');
		return $this;
	}

	/**
	 * @param CM_Request_Abstract $request
	 * @return boolean
	 */
	public static function match(CM_Request_Abstract $request) {
		return false;
	}

	/**
	 * @param int|null $type
	 * @return CM_Site_Abstract
	 * @throws CM_Exception
	 */
	public static function factory($type = null) {
		$class = self::_getClassName($type);
		return new $class();
	}

	/**
	 * @return int Site id
	 */
	public function getId() {
		return $this->getType();
	}

	/**
	 * @param CM_Request_Abstract $request
	 * @return CM_Site_Abstract
	 * @throws CM_Exception_Invalid
	 */
	public static function findByRequest(CM_Request_Abstract $request) {
		/** @var CM_Site_Abstract $className */
		foreach (array_reverse(static::getClassChildren()) as $className) {
			if ($className::match($request)) {
				return new $className();
			}
		}
		return self::factory();
	}
}

{'fraction_non_alphanumeric': 0.14866684621599785, 'fraction_numerical': 0.0005386479935362241, 'mean_word_length': 3.736607142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '6173514', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2325, 'n_words': 523}