本文整理汇总了PHP中Doctrine\ORM\EntityManager::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::clear方法的具体用法?PHP EntityManager::clear怎么用?PHP EntityManager::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
/**
* @param float $discount
*/
public function apply($discount)
{
$this->entityManager->transactional(function () use($discount) {
foreach ($this->items->findAll() as $item) {
$item->applyDiscount($discount);
}
});
$this->entityManager->clear();
}
示例2: finishBatch
/**
* Finish processed batch
*/
protected function finishBatch()
{
$this->entityManager->flush();
if ($this->entityManager->getConnection()->getTransactionNestingLevel() == 1) {
$this->entityManager->clear();
}
}
示例3: getWeaponsInfo
private function getWeaponsInfo()
{
$parameters = array('iDisplayStart' => 0, 'iDisplayLenght' => 50, 'type' => 1);
$response = file_get_contents($this->url . '?' . http_build_query($parameters));
$response = json_decode($response, true);
$data = $response['aaData'];
$formattedData = array();
//Formatting Data
foreach ($data as $value) {
$index = $value[0]['name'] . $value[0]['requiredLevel'];
$formattedData[$index] = array('name' => $value[0]['name'], 'description' => $value[0]['description'], 'level' => $value[0]['requiredLevel']);
}
$i = 0;
foreach ($formattedData as $value) {
$i++;
$item = new Item();
$item->setName($value['name']);
$item->setDescription($value['description']);
$item->setLevel($value['level']);
$item->setType('weapon');
$this->em->persist($item);
if ($i % 20 === 0) {
$this->em->flush();
$this->em->clear();
}
}
$this->em->flush();
$this->em->clear();
}
示例4: tearDown
protected function tearDown()
{
// Clean anything still idle in the UOW
$this->_em->clear();
// Clear out anything set in the db (schema is recreated on setUp()
$this->_schemaTool->dropDatabase();
}
示例5: setupTestSchema
private function setupTestSchema()
{
$this->entityManager->clear();
$classes = $this->entityManager->getMetaDataFactory()->getAllMetaData();
$tool = new Doctrine\ORM\Tools\SchemaTool($this->entityManager);
// $tool->dropSchema($classes);
$tool->createSchema($classes);
}
示例6: write
/**
* Do persist into EntityManager
*
* @param array $items
*/
private function write(array $items)
{
foreach ($items as $item) {
$this->em->persist($item);
}
$this->em->flush();
$this->em->clear();
}
示例7: tearDown
/**
* Sweeps the database tables and clears the EntityManager.
*
* @return void
*/
protected function tearDown()
{
if (null === static::$_conn) {
return;
}
if (null !== static::$_em) {
static::$_em->clear();
}
}
示例8: write
/**
* {@inheritdoc}
*/
public function write(array $items)
{
foreach ($items as $item) {
$this->entityManager->persist($item);
$this->detachFixer->fixEntityAssociationFields($item, 1);
}
$this->entityManager->flush();
$this->entityManager->clear();
}
示例9: clean
protected function clean()
{
$em = self::$em;
$reflectedEm = new \ReflectionClass($em);
if ($reflectedEm->hasProperty('repositories')) {
$property = $reflectedEm->getProperty('repositories');
$property->setAccessible(true);
$property->setValue($em, array());
}
self::$em->clear();
}
示例10: write
/**
* {@inheritdoc}
*/
public function write(array $items)
{
foreach ($items as $item) {
$this->entityManager->persist($item);
$this->detachFixer->fixEntityAssociationFields($item, 1);
}
$this->entityManager->flush();
$configuration = $this->contextRegistry->getByStepExecution($this->stepExecution)->getConfiguration();
if (empty($configuration[self::SKIP_CLEAR])) {
$this->entityManager->clear();
}
}
示例11: should_add_new_user
/** @test */
public function should_add_new_user()
{
$userStub = UserStub::create();
$user = $this->repository->add($userStub);
$this->em->clear();
$user = $this->repository->userOfEmail($userStub->email());
$this->assertEquals($userStub->id(), $user->id());
$this->assertEquals($userStub->email(), $user->email());
$this->assertEquals($userStub->username(), $user->username());
$this->assertEquals($userStub->firstName(), $user->firstName());
$this->assertEquals($userStub->lastName(), $user->lastName());
}
示例12: setUp
protected function setUp()
{
$config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../Entity/'], true, null, null, false);
$this->manager = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $config);
(new SchemaTool($this->manager))->createSchema($this->manager->getMetadataFactory()->getAllMetadata());
$this->manager->persist(new Person('john', 'John', 11, null));
$this->manager->persist(new Person('jane', 'Jane', 21, 'jane@magento.com'));
$this->manager->persist(new Person('joey', 'Joey', 31, ''));
$this->manager->flush();
$this->manager->clear();
$this->transformer = SQLTransformerBuilder::make()->build();
}
示例13: getConnection
protected function getConnection()
{
if (is_null($this->app)) {
$this->app = $this->getApplication();
}
$this->em = EntityManagerFactory::initializeTestEntityManager($this->app);
$pdo = $this->em->getConnection()->getWrappedConnection();
$this->em->clear();
$tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
$classes = $this->em->getMetadataFactory()->getAllMetadata();
$tool->dropSchema($classes);
$tool->createSchema($classes);
return $this->createDefaultDBConnection($pdo, 'fcms_test');
}
示例14: testTransformedValueIsStored
public function testTransformedValueIsStored()
{
$this->setUpEntityManager();
$test = new Test();
$test->setValue(self::VALUE);
$this->em->persist($test);
$this->em->flush();
$dbRow = $this->em->getConnection()->fetchAssoc('SELECT * FROM tests WHERE id = ?', [$test->getId()]);
$this->assertEquals(self::VALUE_TRANSFORMED, $dbRow['value']);
$this->assertEquals(self::VALUE, $test->getValue());
$this->em->clear();
$test = $this->em->find('Transformable\\Fixture\\Test', 1);
$this->assertEquals(self::VALUE, $test->getValue());
}
示例15: run
/**
* Runs all sample data providers.
*
* @param callable|null $callback A function that will be called with the name of each provider as a parameter.
* @return void
*/
public function run(callable $callback = null)
{
$this->em->beginTransaction();
foreach ($this->providers as $provider) {
$this->em->clear();
/** @var $provider \Brick\Sample\SampleDataProvider */
$provider = $this->injector->instantiate($provider);
if ($callback) {
$callback($provider->getName());
}
$provider->run();
$this->em->flush();
}
$this->em->commit();
}