<commit_before><?php
/*
 * Doctrine Admin
 * Copyright (C) 2013 <NAME>, <EMAIL>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


namespace Bast1aan\DoctrineAdmin {
	
	use Doctrine\Common\Persistence\Mapping\ClassMetadata;
	use ArrayAccess;
	use Countable;
	
	class Entity implements ArrayAccess {
		/**
		 * @var object
		 */
		private $entity;
		
		/**
		 * @var ClassMetadata
		 */
		private $classMetaData;
		
		/**
		 *
		 * @var string[]
		 */
		private $fieldNames;
		
		/**
		 *
		 * @var string[]
		 */
		private $associationNames;
		
		/**
		 *
		 * @var string[]
		 */
		private $identifierNames;
		
		/**
		 * @var DoctrineAdmin
		 */
		private $doctrineAdmin;
		
		/**
		 * 
		 * @param object $entity
		 * @param DoctrineAdmin $da
		 * @return Entity
		 */
		public static function factory($entity, DoctrineAdmin $da) {
			$config = $da->getConfig();
			if ($config != null) {
				$daEntity = $config->getDoctrineAdminEntityByNativeEntity($entity);
			}
			if ($daEntity == null) {
				$daEntity = new Entity($entity);
			}
			$daEntity->setDoctrineAdmin($da);
			return $daEntity;
		}
		
		public function __construct($entity, DoctrineAdmin $doctrineAdmin = null) {
			$this->entity = $entity;
			if ($doctrineAdmin != null) {
				$this->setDoctrineAdmin($doctrineAdmin);
			}
		}
		
		public function setDoctrineAdmin(DoctrineAdmin $doctrineAdmin) {
			$this->doctrineAdmin = $doctrineAdmin;
			$this->classMetaData = $doctrineAdmin->getEntityManager()->getClassMetadata(get_class($this->entity));
			$this->fieldNames = $this->classMetaData->getFieldNames();
			$this->associationNames = $this->classMetaData->getAssociationNames();
			$this->identifierNames = $this->classMetaData->getIdentifierFieldNames();
		}
		
		/**
		 * @return string[]
		 */
		public function getAssociationNames() {
			return $this->associationNames;
		}
		
		/**
		 * @return string[]
		 */
		public function getFieldNames() {
			return $this->fieldNames;
		}
		
		/**
		 * @return string[]
		 */
		public function getIdentifierNames() {
			return $this->identifierNames;
		}
		
		public function offsetExists($offset) {
			return in_array($offset, $this->fieldNames) || in_array($offset, $this->associationNames);
		}

		public function offsetGet($offset) {
			return $this->getColumn($offset);
		}
		
		/**
		 * @param string $columnName
		 * @return Property
		 */
		public function getColumn($offset) {
			if ($this->offsetExists($offset)) {
				$clazz = $this->classMetaData->getReflectionClass();
				$prop = $clazz->getProperty($offset);
				$prop->setAccessible(true);
				$value = $prop->getValue($this->entity);
				$type = $this->classMetaData->getTypeOfField($offset);
				if (in_array($offset, $this->fieldNames)) {
					return new ScalarProperty($offset, $value, $type, $this->doctrineAdmin);
				} elseif (is_array($value) || $value instanceof Countable) {
					return new CollectionAssociationProperty($offset, $value, $type, $this->doctrineAdmin);
				} else {
						//				print $value instanceof Countable;
					return new AssociationProperty($offset, $value, $type, $this->doctrineAdmin);
				}
				
			}
		}
		
		public function offsetSet($offset, $value) {
			
		}

		public function offsetUnset($offset) {
			
		}
		
		/**
		 * 
		 * @return object
		 */
		public function getOriginalEntity() {
			return $this->entity;
		}
		<commit_msg>Added Entity::setColumn(), that sets the value of the column back to the entity<commit_after><?php
/*
 * Doctrine Admin
 * Copyright (C) 2013 <NAME>, <EMAIL>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


namespace Bast1aan\DoctrineAdmin {
	
	use Doctrine\Common\Persistence\Mapping\ClassMetadata;
	use ArrayAccess;
	use Countable;
	
	class Entity implements ArrayAccess {
		/**
		 * @var object
		 */
		private $entity;
		
		/**
		 * @var ClassMetadata
		 */
		private $classMetaData;
		
		/**
		 *
		 * @var string[]
		 */
		private $fieldNames;
		
		/**
		 *
		 * @var string[]
		 */
		private $associationNames;
		
		/**
		 *
		 * @var string[]
		 */
		private $identifierNames;
		
		/**
		 * @var DoctrineAdmin
		 */
		private $doctrineAdmin;
		
		/**
		 * 
		 * @param object $entity
		 * @param DoctrineAdmin $da
		 * @return Entity
		 */
		public static function factory($entity, DoctrineAdmin $da) {
			$config = $da->getConfig();
			if ($config != null) {
				$daEntity = $config->getDoctrineAdminEntityByNativeEntity($entity);
			}
			if ($daEntity == null) {
				$daEntity = new Entity($entity);
			}
			$daEntity->setDoctrineAdmin($da);
			return $daEntity;
		}
		
		public function __construct($entity, DoctrineAdmin $doctrineAdmin = null) {
			$this->entity = $entity;
			if ($doctrineAdmin != null) {
				$this->setDoctrineAdmin($doctrineAdmin);
			}
		}
		
		public function setDoctrineAdmin(DoctrineAdmin $doctrineAdmin) {
			$this->doctrineAdmin = $doctrineAdmin;
			$this->classMetaData = $doctrineAdmin->getEntityManager()->getClassMetadata(get_class($this->entity));
			$this->fieldNames = $this->classMetaData->getFieldNames();
			$this->associationNames = $this->classMetaData->getAssociationNames();
			$this->identifierNames = $this->classMetaData->getIdentifierFieldNames();
		}
		
		/**
		 * @return string[]
		 */
		public function getAssociationNames() {
			return $this->associationNames;
		}
		
		/**
		 * @return string[]
		 */
		public function getFieldNames() {
			return $this->fieldNames;
		}
		
		/**
		 * @return string[]
		 */
		public function getIdentifierNames() {
			return $this->identifierNames;
		}
		
		public function offsetExists($offset) {
			return in_array($offset, $this->fieldNames) || in_array($offset, $this->associationNames);
		}

		public function offsetGet($offset) {
			return $this->getColumn($offset);
		}
		
		/**
		 * @param string $columnName
		 * @return Property
		 */
		public function getColumn($offset) {
			if ($this->offsetExists($offset)) {
				$clazz = $this->classMetaData->getReflectionClass();
				$prop = $clazz->getProperty($offset);
				$prop->setAccessible(true);
				$value = $prop->getValue($this->entity);
				$type = $this->classMetaData->getTypeOfField($offset);
				if (in_array($offset, $this->fieldNames)) {
					return new ScalarProperty($offset, $value, $type, $this->doctrineAdmin);
				} elseif (is_array($value) || $value instanceof Countable) {
					return new CollectionAssociationProperty($offset, $value, $type, $this->doctrineAdmin);
				} else {
						//				print $value instanceof Countable;
					return new AssociationProperty($offset, $value, $type, $this->doctrineAdmin);
				}
				
			}
		}
		
		public function setColumn(Property $property) {
			$offset = $property->getName();
			if ($this->offsetExists($offset)) {
				$clazz = $this->classMetaData->getReflectionClass();
				$prop = $clazz->getProperty($offset);
				$prop->setAccessible(true);
				$prop->setValue($this->entity, $property->getValue());
			}
		}
		
		public function offsetSet($offset, $value) {
			
		}

		public function offsetUnset($offset) {
			
		}
		
		/**
		 * 
		 * @return object
		 */
		public function getOriginalEntity() {
			return $this->entity;
		}
		
{'fraction_non_alphanumeric': 0.13375646450399623, 'fraction_numerical': 0.004231311706629055, 'mean_word_length': 3.381565396498455, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 94, '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': '351213', 'n_tokens_mistral': 3020, 'n_tokens_neox': 2442, 'n_words': 655}