本文整理汇总了PHP中static::em方法的典型用法代码示例。如果您正苦于以下问题:PHP static::em方法的具体用法?PHP static::em怎么用?PHP static::em使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类static
的用法示例。
在下文中一共展示了static::em方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEntityManager
/**
* @return EntityManager
*/
public static function getEntityManager()
{
if (static::$em === null) {
static::$em = static::createEntityManager();
}
return static::$em;
}
示例2: getMetadata
public static function getMetadata()
{
/** @var EntityManagerInterface $em */
static::$em = static::$kernel->getContainer()->get('doctrine')->getManager();
$metadata = static::$em->getMetadataFactory()->getAllMetadata();
return $metadata;
}
示例3: setUpEntityManager
protected static function setUpEntityManager()
{
$config = new Configuration();
$config->setSQLLogger(null);
$config->setAutoGenerateProxyClasses(true);
$config->setProxyDir(\sys_get_temp_dir());
$config->setProxyNamespace('Proxies');
$config->setMetadataDriverImpl(static::getMetadataDriverImpl());
$config->setQueryCacheImpl(new ArrayCache());
$config->setMetadataCacheImpl(new ArrayCache());
$dbPath = __DIR__ . '/../db.sqlite';
if (file_exists($dbPath)) {
unlink($dbPath);
}
$connection = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
// Event listeners
$interfaces = DoctrineBundleMapping::getDefaultImplementations();
$evm = new EventManager();
// Resolve entity target subscriber
$rtel = new ResolveTargetEntityListener();
foreach ($interfaces as $model => $implementation) {
$rtel->addResolveTargetEntity($model, $implementation, []);
}
$evm->addEventSubscriber($rtel);
// Load metadata subscriber
$lm = new LoadMetadataSubscriber([], $interfaces);
$evm->addEventSubscriber($lm);
static::$em = EntityManager::create($connection, $config, $evm);
}
示例4: setUpBeforeClass
public static function setUpBeforeClass()
{
static::$client = static::createClient();
static::$router = self::$client->getContainer()->get('router');
static::$em = self::$client->getContainer()->get('doctrine.orm.entity_manager');
static::$container = self::getContainer();
}
示例5: init
/**
* Initialize the entity manager
*
* @return \Doctrine\ORM\EntityManager
*/
public function init()
{
$config = DoctrineSetup::createAnnotationMetadataConfiguration($this->entityPaths, $this->isDevMode, $this->proxyDir, $this->cache, false);
$em = EntityManager::create($this->getDbParams(), $config);
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
static::$em = $em;
return $em;
}
示例6: getEm
/**
* @return EntityManager
*/
public static function getEm()
{
if (!static::$em instanceof EntityManager) {
$helper = (include "src/cli_config.php");
static::$em = $helper->get("em")->getEntityManager();
static::$db = $helper->get("db");
}
return static::$em;
}
示例7: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
if (null === static::$kernel) {
static::$kernel = static::createKernel();
}
static::$kernel->boot();
static::$kernel->getContainer()->get('request')->setLocale('en_EN');
static::$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
static::$translator = static::$kernel->getContainer()->get('translator');
$schemaTool = new SchemaTool(static::$em);
static::$metadata = static::$em->getMetadataFactory()->getAllMetadata();
}
示例8: setUpBeforeClass
/** */
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
parent::deleteTmpDir('Ticket');
static::bootKernel(['test_case' => 'Ticket']);
static::$em = static::$kernel->getContainer()->get('doctrine')->getManager();
static::prepareSchema();
static::fixMediaContext();
static::addFixture(new LoadTicketUsers());
static::addFixture(new LoadTicketCategories());
static::addFixture(new LoadTicket());
static::executeFixtures();
}
示例9: setUpBeforeClass
/**
* {@inheritdoc}
*/
public static final function setUpBeforeClass()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
static::$container = static::$kernel->getContainer();
if (self::emExists()) {
static::$em = static::$container->get('doctrine.orm.entity_manager');
}
if (static::getIsolationLevel() == self::IM_CLASS && self::emExists()) {
static::$em->getConnection()->beginTransaction();
}
static::doSetUpBeforeClass();
}
示例10: setUpBeforeClass
/**
* Prepara el entorno antes de la primer prueba.
*/
public static function setUpBeforeClass()
{
// Inicializamos el framework web.
static::$kernel = static::createKernel();
static::$kernel->boot();
$container = static::$kernel->getContainer();
// Obtenemos algunos servicios de uso común.
static::$em = $container->get('doctrine')->getManager();
static::$rootUrl = $container->getParameter('api.base_url');
if ($fixtures = static::getFixtures()) {
$loader = new ContainerAwareLoader($container);
array_walk($fixtures, array($loader, 'addFixture'));
$purger = new ORMPurger(static::$em);
$executor = new ORMExecutor(static::$em, $purger);
$executor->execute($loader->getFixtures());
}
}
示例11: setUpBeforeClass
/**
* Class initialization
*
*/
public static function setUpBeforeClass()
{
$dbParams = array('driver' => 'pdo_sqlite', 'memory' => true);
$config = Setup::createAnnotationMetadataConfiguration(array(static::getEntityPath()), false);
$cache = new \Doctrine\Common\Cache\ArrayCache();
$driverImpl = $config->newDefaultAnnotationDriver(static::getEntityPath(), false);
$config->setMetadataCacheImpl($cache);
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$proxiesIdentifier = uniqid('Proxies', true);
$config->setProxyDir(sys_get_temp_dir() . '/' . $proxiesIdentifier);
$config->setProxyNamespace('MyProject\\Proxies\\' . $proxiesIdentifier);
$config->setAutoGenerateProxyClasses(true);
$em = EntityManager::create($dbParams, $config);
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = array_map(function ($className) use($em) {
return $em->getClassMetadata($className);
}, static::getEntityClasses());
$tool->createSchema($classes);
static::$em = $em;
}
示例12: setUp
public function setUp()
{
static::$em = static::$kernel->getContainer()->get("doctrine")->getManager();
static::$em->getConnection()->beginTransaction();
}
示例13: tearDownAfterClass
/**
* {@inheritDoc}
*
* @see PHPUnit_Framework_TestCase::tearDownAfterClass()
*
* @uses KernelTestCase::ensureKernelShutdown()
*/
public static function tearDownAfterClass()
{
parent::ensureKernelShutdown();
static::$em->close();
static::$em = null;
// avoid memory leaks
static::$repository->clear();
static::$repository = null;
}
示例14: getEntityManager
/**
* Retrieve entity manager
*
* @return EntityManager
*/
public static function getEntityManager()
{
global $dbh;
$class = __CLASS__;
$table = empty(static::$table) ? strtolower(__CLASS__) : static::$table;
if (empty(static::$fields)) {
$reflectionData = new \ReflectionClass(__CLASS__);
$staticProperties = array_keys($reflectionData->getStaticProperties());
$properties = $reflectionData->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE);
array_walk($properties, function (&$value, $key) {
$value = $value->getName();
});
$fields = array_diff($properties, $staticProperties, array('id'));
} else {
$fields = explode(',', static::$fields);
}
if (!static::$em instanceof EntityManager) {
static::$em = new EntityManager($dbh, $class, $table, $fields);
}
return static::$em;
}
示例15: startEntityManager
/**
* Start Doctrine entity manager
*
* @return void
*/
public function startEntityManager()
{
// Initialize DB connection and entity manager
static::$em = \Doctrine\ORM\EntityManager::create($this->getDSN(), $this->configuration);
if (\XLite\Core\Profiler::getInstance()->enabled) {
static::$em->getConnection()->getConfiguration()->setSQLLogger(\XLite\Core\Profiler::getInstance());
}
static::registerCustomTypes(static::$em);
// Set charset for DB connection
$this->setCharset();
// Bind events
$events = array(\Doctrine\ORM\Events::loadClassMetadata);
if (static::$cacheDriver) {
// Bind cache chekers
$events[] = \Doctrine\ORM\Events::postPersist;
$events[] = \Doctrine\ORM\Events::postUpdate;
$events[] = \Doctrine\ORM\Events::postRemove;
}
static::$em->getEventManager()->addEventListener($events, $this);
}