<commit_before><?php
namespace Exedra;

/**
 * General loader for exedra, available on every 3 major instance. Exedra, Application and Exec.
 */
class Path implements \ArrayAccess
{
	/**
	 * Based directory this loader is based on.
	 * @var string
	 */
	protected $basePath;

	/**
	 * Registry of paths
	 * @var array
	 */
	protected $pathRegistry = array();

	/**
	 * List of autoloaded dirs and namespaces
	 * @var array
	 */
	protected $autoloadRegistry = array();

	public function __construct($basePath = null)
	{
		$this->basePath = !$basePath ? null : rtrim($basePath, '/\\');

		$this->autoloadRegister();
	}

	/**
	 * Required the file.
	 * @param string file
	 * @param array data
	 * @return required file
	 */
	public function load($file, array $data = array())
	{
		return $this->loadFile($file, $data, false);
	}

	/**
	 * Similar with load, but only require the file once.
	 * @param mixed file
	 * @param array data
	 * @return required file
	 */
	public function loadOnce($file, array $data = array())
	{
		return $this->loadFile($file, $data, true);
	}

	/**
	 * Do a buffered file inclusion
	 * @param string file
	 * @param array data
	 * @return string
	 */
	public function loadBuffered($file, array $data = array())
	{
		ob_start();

		$this->load($file, $data);

		return ob_get_clean();
	}

	/**
	 * Abstract function for load and loadOnce
	 * @param mixed file
	 * @param array data
	 * @param boolean once
	 * @return required file
	 */
	protected function loadFile($file, $data, $once = false)
	{
		$file = $this->basePath.'/'.ltrim($file, '/\\');

		if(!file_exists($file))
			throw new \Exedra\Exception\NotFoundException("File [$file] not found");

		extract($data);

		if($once)
			return require_once $file;
		else
			return require $file;

	}

	/**
	 * Whether given path exists
	 * @param string path to file.
	 * @return boolean
	 */
	public function has($path)
	{
		return file_exists($this->basePath.'/'.ltrim($path, '/\\'));
	}

	public function isExists()
	{
		return file_exists($this->basePath);
	}

	/**
	 * PSR-4 autoloader path register
	 * @param string basePath
	 * @param string prefix (optional), a namespace prefix
	 * @param boolean relative (optional, default : true), if false, will consider the basePath given as absolute.
	 */
	public function registerAutoload($basePath, $prefix = '', $relative = true)
	{
		$this->autoloadRegistry[] = array($basePath, $prefix, $relative);<commit_msg>\Exedra\Path::isExists now take optional argument<commit_after><?php
namespace Exedra;

/**
 * General loader for exedra, available on every 3 major instance. Exedra, Application and Exec.
 */
class Path implements \ArrayAccess
{
	/**
	 * Based directory this loader is based on.
	 * @var string
	 */
	protected $basePath;

	/**
	 * Registry of paths
	 * @var array
	 */
	protected $pathRegistry = array();

	/**
	 * List of autoloaded dirs and namespaces
	 * @var array
	 */
	protected $autoloadRegistry = array();

	public function __construct($basePath = null)
	{
		$this->basePath = !$basePath ? null : rtrim($basePath, '/\\');

		$this->autoloadRegister();
	}

	/**
	 * Required the file.
	 * @param string file
	 * @param array data
	 * @return required file
	 */
	public function load($file, array $data = array())
	{
		return $this->loadFile($file, $data, false);
	}

	/**
	 * Similar with load, but only require the file once.
	 * @param mixed file
	 * @param array data
	 * @return required file
	 */
	public function loadOnce($file, array $data = array())
	{
		return $this->loadFile($file, $data, true);
	}

	/**
	 * Do a buffered file inclusion
	 * @param string file
	 * @param array data
	 * @return string
	 */
	public function loadBuffered($file, array $data = array())
	{
		ob_start();

		$this->load($file, $data);

		return ob_get_clean();
	}

	/**
	 * Abstract function for load and loadOnce
	 * @param mixed file
	 * @param array data
	 * @param boolean once
	 * @return required file
	 */
	protected function loadFile($file, $data, $once = false)
	{
		$file = $this->basePath.'/'.ltrim($file, '/\\');

		if(!file_exists($file))
			throw new \Exedra\Exception\NotFoundException("File [$file] not found");

		extract($data);

		if($once)
			return require_once $file;
		else
			return require $file;

	}

	/**
	 * Whether given path exists
	 * @param string path to file.
	 * @return boolean
	 */
	public function has($path)
	{
		return file_exists($this->basePath.'/'.ltrim($path, '/\\'));
	}

	/**
	 * Alias to has()
	 * But with optional argument
	 * Which can also be used to check the base path existence
	 * @param string|null path
	 * @return boolean
	 */
	public function isExists($path = null)
	{
		return file_exists($this->basePath.($path ? '/'.ltrim($path, '/\\') : ''));
	}

	/**
	 * PSR-4 autoloader path register
	 * @param string basePath
	 * @param string prefix (optional), a namespace prefix
	 * @param boolean relative (optional, default : true), if false, will consider the basePath given as absolute.
	 */
	public function registerAutoload($basePath, $prefix = '', $relative = true)
	{
		$this->autoloadRegistry[] = array($basePath, $prefix, $relative);
{'fraction_non_alphanumeric': 0.14677827525793263, 'fraction_numerical': 0.0007786645902277594, 'mean_word_length': 3.4178847807394668, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6387053', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1563, 'n_words': 500}