<commit_before><?php
/**
 *	Brewery
 *
 *	Brewery is an object oriented, agile and scalable RESTful web applications framweork built for PHP 5.4 and later, which focuses on structured and enterprise-worthy application development for cloud based services and applications.
 *
 *	@link http://brewphp.org
 *
 *	@author <NAME> <<EMAIL>>
 *
 *	@license http://opensource.org/licenses/MIT MIT
 */

/* @namespace Brewery */
namespace Brewery;

/* Deny direct file access */
if(!defined('BREWERY_ROOT_PATH')) exit;



/**
 *	clean
 *
 *	Cleans input string from multiple occurances of input character.
 *
 *	@param string $string Uncleansed input string.
 *	@param string $character Character to use as delimiter.
 *
 *	@return string
 */
function clean($string, $character) {

	return preg_replace("#{$character}+#", $character, trim($string, $character));

}

/**
 *	path
 *
 *	Returns a clean and fully resolved path, either relative or absolute.
 *
 *	@param string $unresolvedPath Unresolved path string.
 *	@param bool $isAbsolute If set to true, output path is absolute.
 *
 *	@return string
 */
function path($unresolvedPath, $isAbsolute = false) {

	$delimiter = '/';

	$path = clean($unresolvedPath, $delimiter);

	$path = str_replace($delimiter, DIRECTORY_SEPARATOR, $path);

	if(substr($unresolvedPath, -1) === $delimiter) {

		$path .= DIRECTORY_SEPARATOR;

	}

	if($isAbsolute === true) {

		$path = BREWERY_ROOT_PATH . $path;

	}

	return $path;

}

/**
 *	import
 *
 *	Imports resources in libs/vendor based on namespace.
 *
 *	@param string $namespace Resource namespace.
 *
 *	@return void
 */
function import($namespace) {

	$path = clean(str_replace(NAMESPACE_SEPARATOR, '/', $namespace), '/');

	$path = path("libs/vendor/{$path}.php", true);

	if(file_exists($path) === true) {

		require_once $path;

	}

}

/**
 *	environment
 *
 *	Imports environment resource if it exists.
 *
 *	@param string $environmentResource Environment resource to load.
 *	@param bool $returnPath Return only path.
 *
 *	@return void
 */
function environment($environmentResource, $returnPath = false) {

	if(strpos($environmentResource, '.') < 0) {

		$environmentResource .= '.php';

	}

	$unresolvedPath = implode('/', [
		'/app/Environment/',
		ucfirst(strtolower(BREWERY_ENVIRONMENT)),
		"/{$environmentResource}"
	]);

	$environmentPath = path($unresolvedPath, true);

	if(file_exists($environmentPath) === true) {

		if($returnPath === true) {

			return $environmentPath;

		}

		require_once $environmentPath;

	}

}

/**
 *	asset
 *
 *	Returns clean assets path, either public or private assets path.
 *
 *	@param string $asset Asset to load.
 *	@param bool $isPublic If set to false, private assets are loaded, otherwise public.
 *
 *	@return string
 */
function asset($asset, $isPublic = true) {

	$visibility = ($isPublic === true) ? 'public' : 'private';

	$assetPath = path("/{$visibility}/assets/{$asset}");

	return "/{$assetPath}";

}


/**
 *	dump
 *
 *	Wraps a var_dump within <pre>-elements.
 *
 *	@return string
 */
function dump() {

	echo '<pre style="font: 14px monaco, monospace;">';

	$args = func_get_args();
<commit_msg>Quick change to asset()<commit_after><?php
/**
 *	Brewery
 *
 *	Brewery is an object oriented, agile and scalable RESTful web applications framweork built for PHP 5.4 and later, which focuses on structured and enterprise-worthy application development for cloud based services and applications.
 *
 *	@link http://brewphp.org
 *
 *	@author <NAME> <<EMAIL>>
 *
 *	@license http://opensource.org/licenses/MIT MIT
 */

/* @namespace Brewery */
namespace Brewery;

/* Deny direct file access */
if(!defined('BREWERY_ROOT_PATH')) exit;



/**
 *	clean
 *
 *	Cleans input string from multiple occurances of input character.
 *
 *	@param string $string Uncleansed input string.
 *	@param string $character Character to use as delimiter.
 *
 *	@return string
 */
function clean($string, $character) {

	return preg_replace("#{$character}+#", $character, trim($string, $character));

}

/**
 *	path
 *
 *	Returns a clean and fully resolved path, either relative or absolute.
 *
 *	@param string $unresolvedPath Unresolved path string.
 *	@param bool $isAbsolute If set to true, output path is absolute.
 *
 *	@return string
 */
function path($unresolvedPath, $isAbsolute = false) {

	$delimiter = '/';

	$path = clean($unresolvedPath, $delimiter);

	$path = str_replace($delimiter, DIRECTORY_SEPARATOR, $path);

	if(substr($unresolvedPath, -1) === $delimiter) {

		$path .= DIRECTORY_SEPARATOR;

	}

	if($isAbsolute === true) {

		$path = BREWERY_ROOT_PATH . $path;

	}

	return $path;

}

/**
 *	import
 *
 *	Imports resources in libs/vendor based on namespace.
 *
 *	@param string $namespace Resource namespace.
 *
 *	@return void
 */
function import($namespace) {

	$path = clean(str_replace(NAMESPACE_SEPARATOR, '/', $namespace), '/');

	$path = path("libs/vendor/{$path}.php", true);

	if(file_exists($path) === true) {

		require_once $path;

	}

}

/**
 *	environment
 *
 *	Imports environment resource if it exists.
 *
 *	@param string $environmentResource Environment resource to load.
 *	@param bool $returnPath Return only path.
 *
 *	@return void
 */
function environment($environmentResource, $returnPath = false) {

	if(strpos($environmentResource, '.') < 0) {

		$environmentResource .= '.php';

	}

	$unresolvedPath = implode('/', [
		'/app/environment/',
		ucfirst(strtolower(BREWERY_ENVIRONMENT)),
		"/{$environmentResource}"
	]);

	$environmentPath = path($unresolvedPath, true);

	if(file_exists($environmentPath) === true) {

		if($returnPath === true) {

			return $environmentPath;

		}

		require_once $environmentPath;

	}

}

/**
 *	asset
 *
 *	Returns clean assets path, either public or private assets path.
 *
 *	@param string $asset Asset to load.
 *
 *	@return string
 */
function asset($asset) {

	$patternImageAsset = '/(\.(jpe?g|png|gif|svgz?)$)/';

	$patternStylesheetAsset = '/(\.((c|sc|le)ss)$)/';

	$patternScriptAsset = '/(\.(js|coffee))$)/';

	if(preg_match($patternImageAsset, $asset) !== false) {

		$assetPath = path("public/assets/img/" . $asset);

	} else if(preg_match($patternStylesheetAsset, $asset) !== false) {

		$assetPath = path("public/assets/css/" . $asset);

	} else if(preg_match($patternScriptAsset, $asset) !== false) {

		$assetPath = path("public/assets/js/" . $asset);

	} else {

		$assetPath = path("public/assets" , $asset);

	}

	return $assetPath;

}


/**
 *	dump
 *
 *	Wraps a var_dump within <pre>-elements.
 *
 *	@return string
 */
function dump() {

	echo '<pre style="font: 14px monaco, monospace;">';

	$args = func_get_args();

{'fraction_non_alphanumeric': 0.15551537070524413, 'fraction_numerical': 0.0018083182640144665, 'mean_word_length': 4.0204236006051435, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, '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': '6939256', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2139, 'n_words': 565}