当前位置: 首页>>代码示例>>PHP>>正文


PHP Registry::getConnection方法代码示例

本文整理汇总了PHP中Registry::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::getConnection方法的具体用法?PHP Registry::getConnection怎么用?PHP Registry::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Registry的用法示例。


在下文中一共展示了Registry::getConnection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: cleanDB

 private function cleanDB()
 {
     $this->mainlogrepo->getLoggableListener()->setEnabled(false);
     $this->doctrine->getConnection()->executeQuery('SET foreign_key_checks = 0');
     $this->doctrine->getManager()->getFilters()->disable('softdeleteable');
     foreach ($this->mainlogrepo->findAll() as $result) {
         $this->doctrine->getManager()->remove($result);
     }
     $this->doctrine->getManager()->flush();
     $fixturesClasses = array(get_class(new Comment()), get_class(new RelatedArticle()), get_class(new User()), get_class(new Article()));
     foreach ($fixturesClasses as $fixturesClass) {
         $manager = $this->doctrine->getManagerForClass($fixturesClass);
         $repo = $manager->getRepository($fixturesClass);
         foreach ($repo->findAll() as $result) {
             $manager->remove($result);
         }
         $manager->flush();
         $manager->clear();
     }
     //make twice to be sure ???
     foreach ($fixturesClasses as $fixturesClass) {
         $manager = $this->doctrine->getManagerForClass($fixturesClass);
         $repo = $manager->getRepository($fixturesClass);
         foreach ($repo->findAll() as $result) {
             $manager->remove($result);
         }
         $manager->flush();
         $manager->clear();
     }
     $this->doctrine->getManager()->getFilters()->enable('softdeleteable');
     $this->doctrine->getConnection()->executeQuery('SET foreign_key_checks = 1');
     $this->mainlogrepo->getLoggableListener()->setEnabled(true);
 }
开发者ID:fcpauldiaz,项目名称:IbrowsLoggableBundle,代码行数:33,代码来源:AbstractTest.php

示例2: testDatabase

 protected function testDatabase()
 {
     try {
         $this->em->getConnection()->connect();
     } catch (\Exception $e) {
         $this->logger->error('No database connection.');
         exit;
     }
 }
开发者ID:CampaignChain,项目名称:core,代码行数:9,代码来源:SchedulerCommand.php

示例3: execute

 public function execute()
 {
     $connection = $this->em->getConnection();
     $statement = $connection->prepare('SELECT * FROM campaignchain_campaign_repeating_instance');
     $statement->execute();
     $instances = $statement->fetchAll();
     try {
         $this->em->getConnection()->beginTransaction();
         foreach ($instances as $instance) {
             /** @var Campaign $campaignParent */
             $campaignParent = $this->em->getRepository('CampaignChainCoreBundle:Campaign')->find($instance['repeatingCampaign_id']);
             /** @var Campaign $campaignChild */
             $campaignChild = $this->em->getRepository('CampaignChainCoreBundle:Campaign')->find($instance['scheduledCampaign_id']);
             $campaignParent->addChild($campaignChild);
             $campaignChild->setParent($campaignParent);
             $this->em->flush();
         }
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         throw $e;
     }
 }
开发者ID:campaignchain,项目名称:campaign-repeating,代码行数:23,代码来源:UpdateInstances.php

示例4: load

 /**
  * @param array $files
  * @param bool $doDrop
  */
 public function load(array $files, $doDrop = true)
 {
     try {
         $this->em->getConnection()->beginTransaction();
         $userProcessor = new UserProcessor(realpath(SystemUtil::getRootDir() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR), $this->userService, $this->mimeTypeGuesser, $this->extensionGuesser);
         // Create Alice manager and fixture set
         $this->fixtureManager->addProcessor($userProcessor);
         $set = $this->fixtureManager->createFixtureSet();
         // Add the fixture files
         foreach ($files as $file) {
             $set->addFile($file, 'yaml');
         }
         $set->setDoDrop($doDrop);
         $set->setDoPersist(true);
         $set->setSeed(1337 + 42);
         // TODO Keep Module data intact
         $bundles = $this->em->getRepository("CampaignChain\\CoreBundle\\Entity\\Bundle")->findAll();
         $modules = $this->em->getRepository("CampaignChain\\CoreBundle\\Entity\\Module")->findAll();
         if ($this->fixtureManager->load($set)) {
             // TODO: Restore modules data
             foreach ($bundles as $bundle) {
                 $this->em->persist($bundle);
             }
             foreach ($modules as $module) {
                 $this->em->persist($module);
             }
             $this->em->flush();
             $this->em->getConnection()->commit();
             return true;
         }
         return false;
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->setException($e);
         return false;
     }
 }
开发者ID:CampaignChain,项目名称:core,代码行数:41,代码来源:FileLoader.php

示例5: getConnection

class Registry
{
    /**
     * Returns the connection
     */
    public static function getConnection()
    {
        return new Connection(array("host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "invo"));
    }
}
class SomeComponent
{
    protected $_connection;
    /**
     * Sets the connection externally
     */
    public function setConnection($connection)
    {
        $this->_connection = $connection;
    }
    public function someDbTask()
    {
        $connection = $this->_connection;
        // ...
    }
}
$some = new SomeComponent();
//Pass the connection defined in the registry
$some->setConnection(Registry::getConnection());
$some->someDbTask();
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:30,代码来源:di-88.php

示例6: setConnection

{
    protected $_connection;
    /**
     * Sets the connection externally
     */
    public function setConnection($connection)
    {
        $this->_connection = $connection;
    }
    /**
     * This method always needs the shared connection
     */
    public function someDbTask()
    {
        $connection = $this->_connection;
        // ...
    }
    /**
     * This method always needs a new connection
     */
    public function someOtherDbTask($connection)
    {
    }
}
$some = new SomeComponent();
//This injects the shared connection
$some->setConnection(Registry::getSharedConnection());
$some->someDbTask();
//Here, we always pass a new connection as parameter
$some->someOtherDbTask(Registry::getConnection());
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:30,代码来源:di-140.php

示例7: install

 /**
  * @param SymfonyStyle|null $io
  * @param bool              $updateDatabase
  *
  * @return bool
  *
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  */
 public function install(SymfonyStyle $io = null)
 {
     $this->logger->info('START: MODULES INSTALLER');
     $newBundles = $this->bundleConfigService->getNewBundles();
     if (empty($newBundles)) {
         if ($io) {
             $io->success('No new modules found.');
         }
         $this->logger->info('No new modules found.');
         $this->logger->info('END: MODULES INSTALLER');
         return false;
     }
     // Increase timeout limit to run this script.
     set_time_limit(240);
     $this->kernelService->parseBundlesForKernelConfig($newBundles);
     $loggerResult = '';
     $this->em->getConnection()->beginTransaction();
     $this->registerDistribution();
     try {
         foreach ($newBundles as $newBundle) {
             switch ($newBundle->getType()) {
                 case 'campaignchain-core':
                     break;
                 case 'campaignchain-hook':
                     // TODO: new vs. update
                     $this->registerHook($newBundle);
                     break;
                 case 'campaignchain-symfony':
                     $this->registerSymfonyBundle($newBundle);
                     break;
                 default:
                     $this->registerModule($newBundle);
                     break;
             }
             $loggerResult .= $newBundle->getName() . ', ';
             $this->em->persist($newBundle);
         }
         $this->em->flush();
         // Store the campaign types a campaign can be copied to.
         $this->registerCampaignConversions();
         // Store the channels related to an activity or Location.
         $this->registerChannelRelationships();
         // Store the system parameters injected by modules.
         $this->registerModuleSystemParams();
         // Register any new Bundles in the Symfony kernel.
         $this->kernelService->register();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollBack();
         if ($io) {
             $io->error('Error at update: ' . $e->getMessage());
         }
         $this->logger->error('Error: ' . $e->getMessage());
         $this->logger->info('END: MODULES INSTALLER');
         throw $e;
     }
     $this->logger->info('Installed/updated modules: ' . rtrim($loggerResult, ', '));
     if ($io) {
         $io->section('Installed/updated modules:');
         $io->listing(explode(', ', rtrim($loggerResult, ', ')));
     }
     $this->logger->info('END: MODULES INSTALLER');
     return true;
 }
开发者ID:CampaignChain,项目名称:core,代码行数:73,代码来源:Installer.php


注:本文中的Registry::getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。