<commit_before><?php
namespace PHPHtmlParser;

use PHPHtmlParser\Dom\HtmlNode;
use PHPHtmlParser\Dom\TextNode;
use PHPHtmlParser\Exceptions\NotLoadedException;
use PHPHtmlParser\Exceptions\StrictException;

class Dom {
	
	/**
	 * The charset we would like the output to be in.
	 *
	 * @var string
	 */
	protected $defaultCharset = 'UTF-8';

	/**
	 * Contains the root node of this dom tree.
	 *
	 * @var HtmlNode
	 */
	public $root;

	/**
	 * The raw version of the document string.
	 *
	 * @var string
	 */
	protected $raw;

	/**
	 * The document string.
	 *
	 * @var Content
	 */
	protected $content = null;

	/**
	 * The original file size of the document.
	 *
	 * @var int
	 */
	protected $rawSize;
	
	/**
	 * The size of the document after it is cleaned.
	 *
	 * @var int
	 */
	protected $size;

	/**
	 * A global options array to be used by all load calls.
	 *
	 * @var array
	 */
	protected $globalOptions = [];

	/**
	 * A persistent option object to be used for all options in the 
	 * parsing of the file.
	 *
	 * @var Options
	 */
	protected $options;

	/**
	 * A list of tags which will always be self closing
	 *
	 * @var array
	 */
	protected $selfClosing = [
		'img',
		'br',
		'input',
		'meta',
		'link',
		'hr',
		'base',
		'embed',
		'spacer',
	];

	/**
	 * Returns the inner html of the root node.
	 *
	 * @return string
	 */
	public function __toString()
	{
		return $this->root->innerHtml();
	}

	/**
	 * A simple wrapper around the root node.
	 *
	 * @param string $name
	 * @return mixed
	 */
	public function __get($name)
	{
		return $this->root->$name;
	}

	/**
	 * Attempts to load the dom from any resource, string, file, or URL.
	 *
	 * @param string $str
	 * @param array $option
	 * @chainable
	 */
	public function load($str, $options = [])
	{
		// check if it's a file
		if (is_file($str))
		{
			return $this->loadFromFile($str, $options);
		}
		// check if it's a url
		if (preg_match("/^https?:\/\//i",$str))
		{
			return $this->loadFromUrl($str, $options);
		}

		return $this->loadStr($str, $options);
	}

	/**
	 * Loads the dom from a document file/url
	 *<commit_msg>Remove file loading - default to string loading<commit_after><?php
namespace PHPHtmlParser;

use PHPHtmlParser\Dom\HtmlNode;
use PHPHtmlParser\Dom\TextNode;
use PHPHtmlParser\Exceptions\NotLoadedException;
use PHPHtmlParser\Exceptions\StrictException;

class Dom {
	
	/**
	 * The charset we would like the output to be in.
	 *
	 * @var string
	 */
	protected $defaultCharset = 'UTF-8';

	/**
	 * Contains the root node of this dom tree.
	 *
	 * @var HtmlNode
	 */
	public $root;

	/**
	 * The raw version of the document string.
	 *
	 * @var string
	 */
	protected $raw;

	/**
	 * The document string.
	 *
	 * @var Content
	 */
	protected $content = null;

	/**
	 * The original file size of the document.
	 *
	 * @var int
	 */
	protected $rawSize;
	
	/**
	 * The size of the document after it is cleaned.
	 *
	 * @var int
	 */
	protected $size;

	/**
	 * A global options array to be used by all load calls.
	 *
	 * @var array
	 */
	protected $globalOptions = [];

	/**
	 * A persistent option object to be used for all options in the 
	 * parsing of the file.
	 *
	 * @var Options
	 */
	protected $options;

	/**
	 * A list of tags which will always be self closing
	 *
	 * @var array
	 */
	protected $selfClosing = [
		'img',
		'br',
		'input',
		'meta',
		'link',
		'hr',
		'base',
		'embed',
		'spacer',
	];

	/**
	 * Returns the inner html of the root node.
	 *
	 * @return string
	 */
	public function __toString()
	{
		return $this->root->innerHtml();
	}

	/**
	 * A simple wrapper around the root node.
	 *
	 * @param string $name
	 * @return mixed
	 */
	public function __get($name)
	{
		return $this->root->$name;
	}

	/**
	 * Attempts to load the dom from any resource, string, file, or URL.
	 *
	 * @param string $str
	 * @param array $option
	 * @chainable
	 */
	public function load($str, $options = [], $basic_mode = true)
	{
		if (!$basic_mode) {
			// check if it's a file
			if (is_file($str))
			{
				return $this->loadFromFile($str, $options);
			}
			// check if it's a url
			if (preg_match("/^https?:\/\//i",$str))
			{
				return $this->loadFromUrl($str, $options);
			}
		}

		return $this->loadStr($str, $options);
	}

	/**
	 * Loads the dom from a document file/url
	 *
{'fraction_non_alphanumeric': 0.14444960520204367, 'fraction_numerical': 0.00046446818392940084, 'mean_word_length': 2.607202680067002, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4979420', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1426, 'n_words': 462}