<commit_before><?php
/*
 * This file is part of the Artscore Studio Framework package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ASF\CoreBundle\Model\Manager;

use Doctrine\ORM\EntityManager;

/**
 * Base class for Artscore Studio Framework Entity Managers
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
abstract class ASFEntityManagerModel implements ASFEntityManagerInterface
{
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    protected $entityManager;
    
    /**
     * @var string
     */
    protected $entityName;
    
    /**
     * @param EntityManager $entity_manager
     */
    public function __construct(EntityManager $entity_manager, $entity_name)
    {
        $this->entityManager = $entity_manager;
        if ( $this->isFQCNFormat($entity_name) ) {
            $this->entityName = $entity_name;
        } else {
            $this->entityName = $this->getFQCN($entity_name);
        }
    }
    
    /**
     * Check if the given entity class name is in format AcmeDemoBundle:EntityName
     * 
     * @param string $entity_name
     * @return boolean
     */
    protected function isFQCNFormat($entity_name)
    {
        return 1 === preg_match('/^([A-Z][a-zA-Z]+[\\\\]{1})([A-Z][a-zA-Z]+[\\\\]{1})+([A-Z][a-zA-Z]+)$/', $entity_name);
    }
    
    /**
     * Return FQCN entity name
     * 
     * @param string $entity_name
     * @return string
     */
    protected function getFQCN($entity_name)
    {
        $parts = explode(':', $entity_name);
        $entity = end($parts);
        
        if ( 1 === preg_match('/^([A-Z][a-zA-Z]+)([A-Z][a-zA-Z]+)(Bundle)$/', $parts[0], $matches) ) {
           return $matches[1].'\\'.$matches[2].$matches[3].'\\'.$entity;
        }
    }
    
    /**
     * Create new instance of the entity
     * 
     * @return object
     */
    public function createInstance()
    {
        $class = new \ReflectionClass($this->entityName);
        return $class->newInstanceArgs();
    }
    
    /**
     * @return \Doctrine\ORM\EntityManager<commit_msg>Add alphanumeric in regexp for FQCN detection in ASFEntityManager<commit_after><?php
/*
 * This file is part of the Artscore Studio Framework package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ASF\CoreBundle\Model\Manager;

use Doctrine\ORM\EntityManager;

/**
 * Base class for Artscore Studio Framework Entity Managers
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
abstract class ASFEntityManagerModel implements ASFEntityManagerInterface
{
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    protected $entityManager;
    
    /**
     * @var string
     */
    protected $entityName;
    
    /**
     * @param EntityManager $entity_manager
     */
    public function __construct(EntityManager $entity_manager, $entity_name)
    {
        $this->entityManager = $entity_manager;
        if ( $this->isFQCNFormat($entity_name) ) {
            $this->entityName = $entity_name;
        } else {
            $this->entityName = $this->getFQCN($entity_name);
        }
    }
    
    /**
     * Check if the given entity class name is in format AcmeDemoBundle:EntityName
     * 
     * @param string $entity_name
     * @return boolean
     */
    protected function isFQCNFormat($entity_name)
    {
        return 1 === preg_match('/^([A-Z][a-zA-Z0-9]+[\\\\]{1})([A-Z][a-zA-Z0-9]+[\\\\]{1})+([A-Z][a-zA-Z0-9]+)$/', $entity_name);
    }
    
    /**
     * Return FQCN entity name
     * 
     * @param string $entity_name
     * @return string
     */
    protected function getFQCN($entity_name)
    {
        $parts = explode(':', $entity_name);
        $entity = end($parts);
        
        if ( 1 === preg_match('/^([A-Z][a-zA-Z]+)([A-Z][a-zA-Z]+)(Bundle)$/', $parts[0], $matches) ) {
           return $matches[1].'\\'.$matches[2].$matches[3].'\\'.$entity;
        }
    }
    
    /**
     * Create new instance of the entity
     * 
     * @return object
     */
    public function createInstance()
    {
        $class = new \ReflectionClass($this->entityName);
        return $class->newInstanceArgs();
    }
    
    /**
     * @return \Doctrine\ORM\EntityManager
{'fraction_non_alphanumeric': 0.1549942594718714, 'fraction_numerical': 0.005051664753157291, 'mean_word_length': 2.3, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '3384995', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1376, 'n_words': 293}