/** * Returns a list of system information records. * * Please note that it is not defined which information is returned; the result * should be seen as "informational" to the system operator, not for automated purposes. * * @return SystemInformationRecord[] An array of SystemInformationRecords */ public function getSystemInformation() { $aData = []; $aData[] = new SystemInformationRecord('Doctrine ORM', ORMVersion::VERSION, 'Libraries'); $aData[] = new SystemInformationRecord('Doctrine DBAL', DBALVersion::VERSION, 'Libraries'); $aData[] = new SystemInformationRecord('PHP Version', phpversion(), 'System'); $os = new OperatingSystem(); $aData[] = new SystemInformationRecord('Operating System Type', $os->getPlatform(), 'System'); $aData[] = new SystemInformationRecord('Operating System Release', $os->getRelease(), 'System'); $aData[] = new SystemInformationRecord('memory_limit', ini_get('memory_limit'), 'PHP'); $aData[] = new SystemInformationRecord('post_max_size', ini_get('post_max_size'), 'PHP'); $aData[] = new SystemInformationRecord('upload_max_filesize', ini_get('upload_max_filesize'), 'PHP'); $aData[] = new SystemInformationRecord('allow_url_fopen', ini_get('allow_url_fopen'), 'PHP'); $aData[] = new SystemInformationRecord('max_execution_time', ini_get('max_execution_time'), 'PHP'); $queryCache = get_class($this->entityManager->getConfiguration()->getQueryCacheImpl()); $metadataCache = get_class($this->entityManager->getConfiguration()->getMetadataCacheImpl()); $aData[] = new SystemInformationRecord('Query Cache Implementation', $queryCache, 'PHP'); $aData[] = new SystemInformationRecord('Metadata Cache Implementation', $metadataCache, 'PHP'); $aData[] = new SystemInformationRecord('Disk Space (Total)', $this->format_bytes($this->getTotalDiskSpace()), 'PartKeepr'); $aData[] = new SystemInformationRecord('Disk Space (Free)', $this->format_bytes($this->getFreeDiskSpace()), 'PartKeepr'); $aData[] = new SystemInformationRecord('Disk Space (Used)', $this->format_bytes($this->getUsedDiskSpace()), 'PartKeepr'); $aData[] = new SystemInformationRecord('Data Directory', realpath($this->container->getParameter('partkeepr.filesystem.data_directory')), 'PartKeepr'); $aData[] = new SystemInformationRecord('PartKeepr Version', $this->versionService->getCanonicalVersion(), 'PartKeepr'); return $aData; }
/** * Returns a list of system information records. * * Please note that it is not defined which information is returned; the result * should be seen as "informational" to the system operator, not for automated purposes. * * @return SystemInformationRecord[] An array of SystemInformationRecords */ public function getSystemInformation() { $aData = array(); $aData[] = new SystemInformationRecord("Doctrine ORM", ORMVersion::VERSION, "Libraries"); $aData[] = new SystemInformationRecord("Doctrine DBAL", DBALVersion::VERSION, "Libraries"); $aData[] = new SystemInformationRecord("PHP Version", phpversion(), "System"); $os = new OperatingSystem(); $aData[] = new SystemInformationRecord("Operating System Type", $os->getPlatform(), "System"); $aData[] = new SystemInformationRecord("Operating System Release", $os->getRelease(), "System"); $aData[] = new SystemInformationRecord("memory_limit", ini_get("memory_limit"), "PHP"); $aData[] = new SystemInformationRecord("post_max_size", ini_get("post_max_size"), "PHP"); $aData[] = new SystemInformationRecord("upload_max_filesize", ini_get("upload_max_filesize"), "PHP"); $aData[] = new SystemInformationRecord("allow_url_fopen", ini_get("allow_url_fopen"), "PHP"); $aData[] = new SystemInformationRecord("max_execution_time", ini_get("max_execution_time"), "PHP"); $queryCache = get_class($this->entityManager->getConfiguration()->getQueryCacheImpl()); $metadataCache = get_class($this->entityManager->getConfiguration()->getMetadataCacheImpl()); $aData[] = new SystemInformationRecord("Query Cache Implementation", $queryCache, "PHP"); $aData[] = new SystemInformationRecord("Metadata Cache Implementation", $metadataCache, "PHP"); $aData[] = new SystemInformationRecord("Disk Space (Total)", $this->format_bytes($this->getTotalDiskSpace()), "PartKeepr"); $aData[] = new SystemInformationRecord("Disk Space (Free)", $this->format_bytes($this->getFreeDiskSpace()), "PartKeepr"); $aData[] = new SystemInformationRecord("Disk Space (Used)", $this->format_bytes($this->getUsedDiskSpace()), "PartKeepr"); $aData[] = new SystemInformationRecord("Data Directory", realpath($this->container->getParameter("partkeepr.filesystem.data_directory")), "PartKeepr"); $aData[] = new SystemInformationRecord("PartKeepr Version", $this->versionService->getVersion(), "PartKeepr"); return $aData; }
/** * @return AnnotationReader */ protected function getReaderFromEntityManager() { $configuration = $this->entityManager->getConfiguration(); /** @var AnnotationDriver $driver */ $driver = $configuration->getMetadataDriverImpl(); return $driver->getReader(); }
public function __construct($setConfigFiles = true) { if ($setConfigFiles) { $this->configFile = __DIR__ . '/../../../config.php'; $this->localConfigFile = __DIR__ . '/../../../config.local.php'; } parent::__construct(); $isDevMode = false; $cache = new \Doctrine\Common\Cache\FilesystemCache(__DIR__ . '/../../tmp'); $config = Setup::createConfiguration($isDevMode, __DIR__ . '/../../tmp', $cache); $config->setProxyDir(__DIR__ . '/../../tmp'); $config->setProxyNamespace('MyProject\\Proxies'); $config->setAutoGenerateProxyClasses(true); $paths = [__DIR__ . '/../Entity']; $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new AnnotationReader(), $paths); \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); $config->setMetadataDriverImpl($driver); //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); $conn = ['driver' => 'mysqli', 'host' => '127.0.0.1', 'user' => $this->databaseFactory->getUserName(), 'password' => $this->databaseFactory->getPassword(), 'dbname' => $this->databaseFactory->getDatabaseName()]; $this->entityManager = EntityManager::create($conn, $config); $this->entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); \Doctrine\DBAL\Types\Type::addType('enum', StringType::class); $this->entityManager->getConfiguration()->addCustomStringFunction('DATE', DateFunction::class); $this->user = $this->entityManager->createQueryBuilder()->select('u')->from(Sources\Tests\Entity\User::class, 'u'); }
/** * Generate doctrine proxy classes for extended entities for the given entity manager * * @param EntityManager $em */ protected function generateEntityManagerProxies(EntityManager $em) { $isAutoGenerated = $em->getConfiguration()->getAutoGenerateProxyClasses(); if (!$isAutoGenerated) { $proxyDir = $em->getConfiguration()->getProxyDir(); if (!empty($this->cacheDir) && $this->kernelCacheDir !== $this->cacheDir && strpos($proxyDir, $this->kernelCacheDir) === 0) { $proxyDir = $this->cacheDir . substr($proxyDir, strlen($this->kernelCacheDir)); } $metadataFactory = $em->getMetadataFactory(); $proxyFactory = $em->getProxyFactory(); $extendConfigs = $this->extendConfigProvider->getConfigs(null, true); foreach ($extendConfigs as $extendConfig) { if (!$extendConfig->is('is_extend')) { continue; } if ($extendConfig->in('state', [ExtendScope::STATE_NEW])) { continue; } $entityClass = $extendConfig->getId()->getClassName(); $proxyFileName = $proxyDir . DIRECTORY_SEPARATOR . '__CG__' . str_replace('\\', '', $entityClass) . '.php'; $metadata = $metadataFactory->getMetadataFor($entityClass); $proxyFactory->generateProxyClasses([$metadata], $proxyDir); clearstatcache(true, $proxyFileName); } } }
/** * @param EntityManager $em * @throws LogicException */ public function __construct(EntityManager $em) { $this->em = $em; $this->doctrine = $this->em->getConfiguration()->getMetadataDriverImpl(); if (!$this->doctrine instanceof AnnotationDriver) { throw new LogicException('Doxport expects Doctrine2 to be using an annotation metadata driver'); } }
/** * @throws \Doctrine\ORM\ORMException */ protected function setupDoctrine() { $databaseConfig = ['driver' => 'pdo_sqlite', 'dbname' => ':memory:']; $doctrineConfig = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(['tests/fixtures/'], false, getcwd() . '/build/tmp', new ArrayCache(), false); $doctrineConfig->setAutoGenerateProxyClasses(true); $this->entityManager = EntityManager::create($databaseConfig, $doctrineConfig); $this->annotationReader = $this->entityManager->getConfiguration()->getMetadataDriverImpl(); }
/** * {@inheritdoc} */ public function denormalize($data, $type, $format = null) { // Use alias namespace ? if (strrpos($type, ':') !== false) { list($namespaceAlias, $simpleClassName) = explode(':', $type); $type = $this->entityManager->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; } return parent::denormalize($data, $type, $format); }
/** * Bootstrap */ public function setUp() { parent::setUp(); $reader = new AnnotationReader(); $metadataDriver = new AnnotationDriver($reader, User::class); $this->em = $this->_getTestEntityManager(); $this->em->getConfiguration()->setMetadataDriverImpl($metadataDriver); $this->obj = $this->em->getRepository(User::class); }
/** * @param \Doctrine\ORM\EntityManager $entityManager */ public function __construct(\Doctrine\ORM\EntityManager $entityManager) { $this->entityManager = $entityManager; $config = $this->entityManager->getConfiguration(); $config->addCustomDatetimeFunction('DATE_FORMAT', "\\ModelModule\\Doctrine\\Functions\\DateFormat"); $config->addCustomDatetimeFunction('MONTH', "\\ModelModule\\Doctrine\\Functions\\Month"); $config->addCustomDatetimeFunction('MD5', "\\ModelModule\\Doctrine\\Functions\\Md5"); $this->queryBuilder = $this->entityManager->createQueryBuilder(); }
protected final function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $logger = new \CarFramework\ConsoleSQLLogger($output); $this->em->getConfiguration()->setSQLLogger($logger); $args = $input->getArgument("args"); $this->play($this->em, $args); $logger->finalize(); }
protected function setUp() { parent::setUp(); $this->enableSecondLevelCache(); $this->em = $this->_getTestEntityManager(); $this->region = new CacheRegionMock(); $this->queryCache = new DefaultQueryCache($this->em, $this->region); $this->cacheFactory = new CacheFactoryDefaultQueryCacheTest($this->queryCache, $this->region); $this->em->getConfiguration()->getSecondLevelCacheConfiguration()->setCacheFactory($this->cacheFactory); }
/** * Because the EntityManager gets closed when there's an error, it needs to * be created again * * @return EntityManager * @throws ORMException */ protected function getEntityManager() { if (!$this->em) { $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); } if (!$this->em->isOpen()) { $this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration()); } return $this->em; }
/** * @return string[] */ protected function getUpdateQueries() { $cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl(); if ($cache instanceof ClearableCache) { $cache->deleteAll(); } $schemaTool = new SchemaTool($this->entityManager); $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); $queries = $schemaTool->getUpdateSchemaSql($metadata, TRUE); return $queries; }
protected function setUp() { $this->em = $this->getTestEntityManager(); $config = $this->em->getConfiguration(); $metadataDriver = new AnnotationDriver(new AnnotationReader(), 'OroCRM\\Bundle\\ChannelBundle\\Tests\\Unit\\Stubs\\Entity'); $config->setMetadataDriverImpl($metadataDriver); $config->setEntityNamespaces(['OroCRMChannelBundle' => 'OroCRM\\Bundle\\ChannelBundle\\Tests\\Unit\\Stubs\\Entity']); $registry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em)); $this->helper = new ChannelHelper($registry); }
public function setUp() { $this->listener = new AttachEntityListenersListener(); $driver = $this->createAnnotationDriver(); $this->em = $this->_getTestEntityManager(); $evm = $this->em->getEventManager(); $this->factory = new ClassMetadataFactory(); $evm->addEventListener(Events::loadClassMetadata, $this->listener); $this->em->getConfiguration()->setMetadataDriverImpl($driver); $this->factory->setEntityManager($this->em); }
public function testSetDefaultOptions() { $reader = new AnnotationReader(); $metadataDriver = new AnnotationDriver($reader, 'Oro\\Bundle\\IntegrationBundle\\Tests\\Unit\\Fixture\\Entity'); $this->em->getConfiguration()->setMetadataDriverImpl($metadataDriver); $this->em->getConfiguration()->setEntityNamespaces(['OroIntegrationBundle' => 'Oro\\Bundle\\IntegrationBundle\\Tests\\Unit\\Fixture\\Entity']); $resolver = new OptionsResolver(); $this->type->setDefaultOptions($resolver); $resolved = $resolver->resolve(['configs' => ['placeholder' => 'testPlaceholder'], 'allowed_types' => ['testType']]); $this->assertInstanceOf('Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\EntityChoiceList', $resolved['choice_list']); }
public function setUp() { $this->em = $this->_getTestEntityManager(); $this->em->getConfiguration()->setEntityNamespaces(array('OroEntityConfigBundle' => 'Oro\\Bundle\\EntityConfigBundle\\Entity', 'Fixture' => 'Oro\\Bundle\\EntityConfigBundle\\Tests\\Unit\\Fixture')); $reader = new AnnotationReader(); $metadataDriver = new AnnotationDriver($reader, __DIR__ . '/Fixture'); $this->em->getConfiguration()->setMetadataDriverImpl($metadataDriver); $serviceLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock(); $serviceLink->expects($this->any())->method('getService')->will($this->returnValue($this->em)); $this->configModelManager = new ConfigModelManager($serviceLink); }
protected function setUp() { $this->em = $this->getTestEntityManager(); $metadataDriver = new AnnotationDriver(new AnnotationReader(), 'OroCRM\\Bundle\\ChannelBundle\\Tests\\Unit\\Stubs\\Entity'); $config = $this->em->getConfiguration(); $config->setMetadataDriverImpl($metadataDriver); $config->setEntityNamespaces(['OroCRMChannelBundle' => 'OroCRM\\Bundle\\ChannelBundle\\Tests\\Unit\\Stubs\\Entity']); $registry = $this->getMock('Symfony\\Bridge\\Doctrine\\RegistryInterface'); $registry->expects($this->any())->method('getManagerForClass')->will($this->returnValue($this->em)); $this->provider = new AmountProvider($registry); }
/** * generate entity objects automatically from mysql db tables * @return none */ function generate_classes() { $this->em->getConfiguration()->setMetadataDriverImpl(new DatabaseDriver($this->em->getConnection()->getSchemaManager())); $cmf = new DisconnectedClassMetadataFactory(); $cmf->setEntityManager($this->em); $metadata = $cmf->getAllMetadata(); $generator = new EntityGenerator(); $generator->setUpdateEntityIfExists(true); $generator->setGenerateStubMethods(true); $generator->setGenerateAnnotations(true); $generator->generate($metadata, APPPATH . "models/Entities"); }
protected function setUp() { self::bootKernel(); $this->em = static::$kernel->getContainer()->get('doctrine')->getManager(); $this->revisionManager = static::$kernel->getContainer()->get('opifer.revisions.revision_manager'); $driver = new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/Entity']); $this->em->getConfiguration()->setMetadataDriverImpl($driver); $this->em->getFilters()->enable('draft'); $this->em->getFilters()->disable('softdeleteable'); $schemaTool = new SchemaTool($this->em); $schemaTool->createSchema($this->getClasses()); }
public function setUp() { $this->contextRegistry = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Context\\ContextRegistry')->disableOriginalConstructor()->setMethods(array('getByStepExecution'))->getMock(); $this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $reader = new AnnotationReader(); $metadataDriver = new AnnotationDriver($reader, 'Oro\\Bundle\\IntegrationBundle\\Entity'); $ownershipMetadataProvider = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Owner\\Metadata\\OwnershipMetadataProvider')->disableOriginalConstructor()->getMock(); $this->em = $this->getTestEntityManager(); $config = $this->em->getConfiguration(); $config->setMetadataDriverImpl($metadataDriver); $config->setEntityNamespaces(['OroIntegrationBundle' => 'Oro\\Bundle\\IntegrationBundle\\Entity']); $this->reader = new EntityReaderById($this->contextRegistry, $this->managerRegistry, $ownershipMetadataProvider); }
/** * Getter for entityManager * * @return EntityManager */ public static function getEntityManager() { #if(null === self::$_entityManager) { # self::$_entityManager = \Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('entityManager'); #} // Check if entitymanager has been closed (most likely due to a previously thrown PDOException) if (!self::$_entityManager->isOpen()) { // Entitymanger has closed, create a new one $connection = self::$_entityManager->getConnection(); $config = self::$_entityManager->getConfiguration(); self::$_entityManager = EntityManager::create($connection, $config); } return self::$_entityManager; }
public function testLoadClassMetadataWithoutParent() { $this->loadClassMetadataEvent->getClassMetadata()->willReturn($this->classMetadata->reveal()); $this->classMetadata->getName()->willReturn(get_class($this->object->reveal())); $this->classMetadata->setCustomRepositoryClass('Sulu\\Bundle\\ContactBundle\\Entity\\ContactRepository')->shouldNotBeCalled(); $this->loadClassMetadataEvent->getEntityManager()->willReturn($this->entityManager->reveal()); $this->entityManager->getConfiguration()->willReturn($this->configuration->reveal()); $this->configuration->getNamingStrategy()->willReturn(null); /** @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $mappingDriver */ $mappingDriver = $this->prophesize('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver'); $this->configuration->getMetadataDriverImpl()->willReturn($mappingDriver->reveal()); $mappingDriver->getAllClassNames()->willReturn([get_class($this->parentObject->reveal())]); $mappingDriver->loadMetadataForClass(get_class($this->parentObject->reveal()), Argument::type('Doctrine\\ORM\\Mapping\\ClassMetadata'))->shouldBeCalled(); $this->subscriber->loadClassMetadata($this->loadClassMetadataEvent->reveal()); }
public function setUp() { parent::setUp(); $paths = array(__DIR__ . "/Entity"); $dbParams = array('driver' => 'pdo_sqlite', 'memory' => true); $config = Setup::createConfiguration(true); $driver = new AnnotationDriver(new AnnotationReader(), $paths); AnnotationRegistry::registerLoader('class_exists'); $config->setMetadataDriverImpl($driver); $em = EntityManager::create($dbParams, $config); $this->em = $em; $this->createDatabaseSchema($this->em); (new FixturesLoader())->withManager($em)->fromDir(__DIR__ . '/fixture_files')->load(); self::$fullClassNames = $this->em->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); }
/** * Constructor. * * @param EntityManager $em The entity manager * @param SecurityContextInterface $sc The security context * @param RoleHierarchyInterface $rh The role hierarchies */ public function __construct(EntityManager $em, SecurityContextInterface $sc, RoleHierarchyInterface $rh) { $this->em = $em; $this->securityContext = $sc; $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); $this->roleHierarchy = $rh; }
/** * Init additional doctrine functions * * @param \Doctrine\ORM\EntityManager $em * @param \Doctrine\ORM\Mapping\ClassMetadata $class */ public function initRepo(EntityManager $em, ClassMetadata $class) { $ormConfig = $em->getConfiguration(); $ormConfig->addCustomStringFunction('TsvectorTsquery', 'Oro\\Bundle\\SearchBundle\\Engine\\Orm\\PdoPgsql\\TsvectorTsquery'); $ormConfig->addCustomStringFunction('TsRank', 'Oro\\Bundle\\SearchBundle\\Engine\\Orm\\PdoPgsql\\TsRank'); parent::initRepo($em, $class); }
/** * Gets the class metadata descriptor for a class. * * @param string $className The name of the class. * @return Doctrine\ORM\Mapping\ClassMetadata */ public function getMetadataFor($className) { if (!isset($this->loadedMetadata[$className])) { $realClassName = $className; // Check for namespace alias if (strpos($className, ':') !== false) { list($namespaceAlias, $simpleClassName) = explode(':', $className); $realClassName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; if (isset($this->loadedMetadata[$realClassName])) { // We do not have the alias name in the map, include it $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName]; return $this->loadedMetadata[$realClassName]; } } if ($this->cacheDriver) { if (($cached = $this->cacheDriver->fetch("{$realClassName}\$CLASSMETADATA")) !== false) { $this->loadedMetadata[$realClassName] = $cached; } else { foreach ($this->loadMetadata($realClassName) as $loadedClassName) { $this->cacheDriver->save("{$loadedClassName}\$CLASSMETADATA", $this->loadedMetadata[$loadedClassName], null); } } } else { $this->loadMetadata($realClassName); } if ($className != $realClassName) { // We do not have the alias name in the map, include it $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName]; } } return $this->loadedMetadata[$className]; }
static function factory(EntityManager $em, $uuid, $allowCache = false) { if (!Util\UUID::validate($uuid)) { throw new \Exception('Invalid UUID: \'' . $uuid . '\''); } if (!self::$cache) { self::$cache = $em->getConfiguration()->getQueryCacheImpl(); } if ($allowCache && self::$cache && self::$cache->contains($uuid)) { // used hydrated cache result return self::$cache->fetch($uuid); } $dql = 'SELECT a, p FROM Volkszaehler\\Model\\Entity a LEFT JOIN a.properties p WHERE a.uuid = :uuid'; $q = $em->createQuery($dql)->setParameter('uuid', $uuid); try { $entity = $q->getSingleResult(); if ($allowCache && self::$cache) { self::$cache->save($uuid, $entity, Util\Configuration::read('cache.ttl')); } return $entity; } catch (\Doctrine\ORM\NoResultException $e) { throw new \Exception('No entity found with UUID: \'' . $uuid . '\''); } }
/** * Initializes extension driver * * @param EntityManager $em * @param string $extensionNamespace */ public function __construct(EntityManager $em, $extensionNamespace) { $this->_em = $em; $this->_extensionNamespace = $extensionNamespace; $ormDriver = $em->getConfiguration()->getMetadataDriverImpl(); $this->_driver = $this->_getDriver($ormDriver); }