<commit_before><?php


require_once('pudlCollection.php');



abstract class	pudlOrm
	extends		pudlObject
	implements	pudlId {




	public function __construct($item=false, $fetch=false) {
		if (static::classname === __CLASS__) {
			throw new pudlException('ORM const parameters were not overwritten');
		}

		if (is_array($item)) {
			$fetch ? $this->fetch($item)		: $this->replace($item);

		} else if (is_a($item, 'af_url')) {
			$this->fetch($item->id);

		} else if (is_a($item, 'getvar')) {
			$this->fetch($item->id());

		} else if (is_a($item, 'pudlResult')) {
			$fetch ? $this->fetch($item())		: $this->copy($item());

		} else if (is_a($item, 'Traversable')) {
			$fetch ? $this->fetch($item)		: $this->copy($item);

		} else if ($fetch  &&  (is_int($item)  ||  ctype_digit($item))) {
			$this->fetch($item);

		} else if (!empty($item)) {
			$this->{static::column} = $item;
		}


		//SET DEFAULT OBJECT ID AND FORCE INTEGER
		if (static::hash) {
			if (empty($this->{static::column})) {
				$this->{static::column} = '';
			}

		} else {
			$this->{static::column} = !empty($this->{static::column})
									?  (int) $this->{static::column}
									: 0;
		}
	}




	////////////////////////////////////////////////////////////////////////////
	//IF CONVERTING CLASS TO STRING, RETURNS THE CURRENT OBJECT ID NUMBER
	////////////////////////////////////////////////////////////////////////////
	public function __toString() {
		return (string) $this->{static::column};
	}




	////////////////////////////////////////////////////////////////////////////
	//RETURN THE CURRENT OBJECT ID NUMBER
	////////////////////////////////////////////////////////////////////////////
	public function id() {
		return (int) $this->{static::column};
	}




	////////////////////////////////////////////////////////////////////////////
	//CREATE A NEW INSTANCE OF THIS OBJECT IN THE DATABASE
	////////////////////////////////////////////////////////////////////////////
	public static function create($data=false) {
		global $db;
		return static::get($db->insert(static::table, $data));
	}




	////////////////////////////////////////////////////////////////////////////
	//GET AN INSTANCE OF THIS OBJECT FROM THE DATABASE
	////////////////////////////////////////////////////////////////////////////
	public static function get($id=false) {
		global $get, $afurl;

		if (tbx_array($id))	$id = $id[static::column];

		if (empty($id)  &&  $get instanceof getvar) {
			$id = $get->id();
		}

		if (empty($id)  &&  $afurl instanceof af_url) {
			$id = $afurl->id;
		}

		$id = (int) $id;

		$class = static::classname;
		return new $class($id, true);
	}




	////////////////////////////////////////////////////////////////////////////
	//GET AN INSTANCE OF THIS OBJECT FROM THE DATABASE FOR A GIVEN CLAUSE
	////////////////////////////////////////////////////////////////////////////
	public static function select(/* ...$selex */) {
		global $db;

		$args	= func_get_args();
		array_unshift($args, ['limit'=>1], static::schema());

		$data	= call_user_func_array([$db,'selex'], $args)->complete();
		$class	= static::classname;

		return is_array($data) ? new $class(reset($data)) : $data;
	}
<commit_msg>Fixing bug with pudlOrm::get() when passing in ID of 0<commit_after><?php


require_once('pudlCollection.php');



abstract class	pudlOrm
	extends		pudlObject
	implements	pudlId {




	public function __construct($item=false, $fetch=false) {
		if (static::classname === __CLASS__) {
			throw new pudlException('ORM const parameters were not overwritten');
		}

		if (is_array($item)) {
			$fetch ? $this->fetch($item)		: $this->replace($item);

		} else if (is_a($item, 'af_url')) {
			$this->fetch($item->id);

		} else if (is_a($item, 'getvar')) {
			$this->fetch($item->id());

		} else if (is_a($item, 'pudlResult')) {
			$fetch ? $this->fetch($item())		: $this->copy($item());

		} else if (is_a($item, 'Traversable')) {
			$fetch ? $this->fetch($item)		: $this->copy($item);

		} else if ($fetch  &&  (is_int($item)  ||  ctype_digit($item))) {
			$this->fetch($item);

		} else if (!empty($item)) {
			$this->{static::column} = $item;
		}


		//SET DEFAULT OBJECT ID AND FORCE INTEGER
		if (static::hash) {
			if (empty($this->{static::column})) {
				$this->{static::column} = '';
			}

		} else {
			$this->{static::column} = !empty($this->{static::column})
									?  (int) $this->{static::column}
									: 0;
		}
	}




	////////////////////////////////////////////////////////////////////////////
	//IF CONVERTING CLASS TO STRING, RETURNS THE CURRENT OBJECT ID NUMBER
	////////////////////////////////////////////////////////////////////////////
	public function __toString() {
		return (string) $this->{static::column};
	}




	////////////////////////////////////////////////////////////////////////////
	//RETURN THE CURRENT OBJECT ID NUMBER
	////////////////////////////////////////////////////////////////////////////
	public function id() {
		return (int) $this->{static::column};
	}




	////////////////////////////////////////////////////////////////////////////
	//CREATE A NEW INSTANCE OF THIS OBJECT IN THE DATABASE
	////////////////////////////////////////////////////////////////////////////
	public static function create($data=false) {
		global $db;
		return static::get($db->insert(static::table, $data));
	}




	////////////////////////////////////////////////////////////////////////////
	//GET AN INSTANCE OF THIS OBJECT FROM THE DATABASE
	////////////////////////////////////////////////////////////////////////////
	public static function get($id=false) {
		global $get, $afurl;

		if (tbx_array($id))	$id = $id[static::column];

		if ($id === false  &&  $get instanceof getvar) {
			$id = $get->id();
		}

		if ($id === false  &&  $afurl instanceof af_url) {
			$id = $afurl->id;
		}

		$id = (int) $id;

		$class = static::classname;
		return new $class($id, true);
	}




	////////////////////////////////////////////////////////////////////////////
	//GET AN INSTANCE OF THIS OBJECT FROM THE DATABASE FOR A GIVEN CLAUSE
	////////////////////////////////////////////////////////////////////////////
	public static function select(/* ...$selex */) {
		global $db;

		$args	= func_get_args();
		array_unshift($args, ['limit'=>1], static::schema());

		$data	= call_user_func_array([$db,'selex'], $args)->complete();
		$class	= static::classname;

		return is_array($data) ? new $class(reset($data)) : $data;
	}

{'fraction_non_alphanumeric': 0.3807161680359634, 'fraction_numerical': 0.0007750736319950396, 'mean_word_length': 1.4644766997708174, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '1293979', 'n_tokens_mistral': 2107, 'n_tokens_neox': 1832, 'n_words': 427}