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


PHP Propel::getServiceContainer方法代码示例

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


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

示例1: testInvalidCharset

 public function testInvalidCharset()
 {
     $this->markTestSkipped('Skipped because of weird behavior on some platforms');
     $db = Propel::getServiceContainer()->getAdapter(BookPeer::DATABASE_NAME);
     if ($db instanceof SqliteAdapter) {
         $this->markTestSkipped();
     }
     $a = new Author();
     $a->setFirstName("Б.");
     $a->setLastName("АКУНИН");
     $a->save();
     $authorNameWindows1251 = iconv("utf-8", "windows-1251", $a->getLastName());
     $a->setLastName($authorNameWindows1251);
     // Different databases seem to handle invalid data differently (no surprise, I guess...)
     if ($db instanceof PgsqlAdapter) {
         try {
             $a->save();
             $this->fail("Expected an exception when saving non-UTF8 data to database.");
         } catch (Exception $x) {
             print $x;
         }
     } else {
         // No exception is thrown by MySQL ... (others need to be tested still)
         $a->save();
         $a->reload();
         $this->assertEquals("", $a->getLastName(), "Expected last_name to be empty (after inserting invalid charset data)");
     }
 }
开发者ID:norfil,项目名称:Propel2,代码行数:28,代码来源:CharacterEncodingTest.php

示例2: register

 /**
  * {@inheritDoc}
  */
 public function register(Container $container)
 {
     // Append custom settings with missing params from default settings
     $container['settings']['database'] = self::mergeWithDefaultSettings($container['settings']['database']);
     $settings = $container['settings']['database'];
     $logLevel = $settings['logger']['level'] ?? null;
     $logPath = $settings['logger']['path'] ?? null;
     $className = $settings['classname'] ?? null;
     if (!$className) {
         $className = 'Propel\\Runtime\\Connection\\ConnectionWrapper';
         if ($logLevel == Logger::DEBUG) {
             $className = 'Propel\\Runtime\\Connection\\ProfilerConnectionWrapper';
         }
     }
     $manager = new ConnectionManagerSingle();
     $manager->setConfiguration(['classname' => $className, 'dsn' => $settings['dsn'], 'user' => $settings['user'], 'password' => $settings['password'], 'settings' => $settings['settings']]);
     $manager->setName($settings['connection']);
     /** @var StandardServiceContainer $serviceContainer */
     $serviceContainer = Propel::getServiceContainer();
     $serviceContainer->checkVersion($settings['version']);
     $serviceContainer->setAdapterClass($settings['connection'], $settings['adapter']);
     $serviceContainer->setConnectionManager($settings['connection'], $manager);
     $serviceContainer->setDefaultDatasource($settings['connection']);
     if ($logPath && $logLevel) {
         $logger = new Logger('defaultLogger');
         $logger->pushHandler(new StreamHandler($logPath, $logLevel));
         $serviceContainer->setLogger('defaultLogger', $logger);
         if ($logLevel == Logger::DEBUG) {
             /** @var ConnectionWrapper $con */
             $con = Propel::getConnection();
             $con->useDebug(true);
         }
     }
 }
开发者ID:ansas,项目名称:php-component,代码行数:37,代码来源:PropelProvider.php

示例3: getProfiler

 /**
  * @return \Propel\Runtime\Util\Profiler
  */
 public function getProfiler()
 {
     if (null === $this->profiler) {
         $this->profiler = Propel::getServiceContainer()->getProfiler();
     }
     return $this->profiler;
 }
开发者ID:disider,项目名称:Propel2,代码行数:10,代码来源:ProfilerConnectionWrapper.php

示例4: setUp

    protected function setUp()
    {
        parent::setUp();
        if (!class_exists('Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\CoolBook')) {
            $schema = <<<XML
<database name="default" package="vendor.bundles.Propel.Bundle.PropelBundle.Tests.Fixtures.DataFixtures.Loader" namespace="Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader" defaultIdMethod="native">
    <table name="cool_book">
        <column name="id" type="integer" primaryKey="true" />
        <column name="name" type="varchar" size="255" />
        <column name="description" type="varchar" />
        <column name="author_id" type="integer" required="false" defaultValue="null" />
        <column name="complementary_infos" required="false" type="object" description="An object column" />

        <foreign-key foreignTable="cool_book_author" onDelete="CASCADE" onUpdate="CASCADE">
            <reference local="author_id" foreign="id" />
        </foreign-key>
    </table>

    <table name="cool_book_author">
        <column name="id" type="integer" primaryKey="true" />
        <column name="name" type="varchar" size="255" />
    </table>
</database>
XML;
            QuickBuilder::buildSchema($schema);
        }
        $this->con = Propel::getServiceContainer()->getConnection('default');
        $this->con->beginTransaction();
    }
开发者ID:naldz,项目名称:cyberden,代码行数:29,代码来源:TestCase.php

示例5: testComputeWithSchema

 public function testComputeWithSchema()
 {
     $con = Propel::getServiceContainer()->getConnection(BookstoreTableMap::DATABASE_NAME);
     BookstoreContestEntryQuery::create()->deleteAll();
     BookstoreQuery::create()->deleteAll();
     CustomerQuery::create()->deleteAll();
     BookstoreContestQuery::create()->deleteAll();
     $store = new Bookstore();
     $store->setStoreName('FreeAgent Bookstore');
     $store->save();
     $this->assertEquals(0, $store->computeTotalContestEntries($con), 'The compute method returns 0 for objects with no related objects');
     $contest = new BookstoreContest();
     $contest->setBookstore($store);
     $contest->save();
     $customer1 = new Customer();
     $customer1->save();
     $entry1 = new BookstoreContestEntry();
     $entry1->setBookstore($store);
     $entry1->setBookstoreContest($contest);
     $entry1->setCustomer($customer1);
     $entry1->save(null, true);
     // skip reload to avoid #1151 for now
     $this->assertEquals(1, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects');
     $customer2 = new Customer();
     $customer2->save();
     $entry2 = new BookstoreContestEntry();
     $entry2->setBookstore($store);
     $entry2->setBookstoreContest($contest);
     $entry2->setCustomer($customer2);
     $entry2->save(null, true);
     // skip reload to avoid #1151 for now
     $this->assertEquals(2, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects');
     $entry1->delete();
     $this->assertEquals(1, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects');
 }
开发者ID:disider,项目名称:Propel2,代码行数:35,代码来源:AggregateColumnBehaviorWithSchemaTest.php

示例6: process

 public function process()
 {
     $logger = Tlog::getInstance();
     $logger->setLevel(Tlog::DEBUG);
     $updatedVersions = array();
     $currentVersion = ConfigQuery::read('thelia_version');
     $logger->debug("start update process");
     if (true === $this->isLatestVersion($currentVersion)) {
         $logger->debug("You already have the latest version. No update available");
         throw new UpToDateException('You already have the latest version. No update available');
     }
     $index = array_search($currentVersion, self::$version);
     $con = Propel::getServiceContainer()->getWriteConnection(ProductTableMap::DATABASE_NAME);
     $con->beginTransaction();
     $logger->debug("begin transaction");
     $database = new Database($con->getWrappedConnection());
     try {
         $size = count(self::$version);
         for ($i = ++$index; $i < $size; $i++) {
             $this->updateToVersion(self::$version[$i], $database, $logger);
             $updatedVersions[] = self::$version[$i];
         }
         $con->commit();
         $logger->debug('update successfully');
     } catch (PropelException $e) {
         $con->rollBack();
         $logger->error(sprintf('error during update process with message : %s', $e->getMessage()));
         throw $e;
     }
     $logger->debug('end of update processing');
     return $updatedVersions;
 }
开发者ID:alex63530,项目名称:thelia,代码行数:32,代码来源:Update.php

示例7: __construct

 public function __construct(LoggerInterface $alternativeLogger = null)
 {
     $con = Propel::getServiceContainer()->getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
     $con->setLogger($this);
     $con->setLogMethods(array('exec', 'query', 'execute', 'beginTransaction', 'commit', 'rollBack'));
     $this->alternativeLogger = $alternativeLogger;
 }
开发者ID:alex63530,项目名称:thelia,代码行数:7,代码来源:PropelCollector.php

示例8: registerRuntimeConfiguration

 /**
  * Register propel runtime configuration.
  *
  * @return void
  */
 protected function registerRuntimeConfiguration()
 {
     $propel_conf = $this->app->config['propel.propel'];
     if (!isset($propel_conf['runtime']['connections'])) {
         throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.');
     }
     /** @var $serviceContainer \Propel\Runtime\ServiceContainer\StandardServiceContainer */
     $serviceContainer = Propel::getServiceContainer();
     $serviceContainer->closeConnections();
     $serviceContainer->checkVersion('2.0.0-dev');
     $runtime_conf = $propel_conf['runtime'];
     // set connections
     foreach ($runtime_conf['connections'] as $connection_name) {
         $config = $propel_conf['database']['connections'][$connection_name];
         $serviceContainer->setAdapterClass($connection_name, $config['adapter']);
         $manager = new ConnectionManagerSingle();
         $manager->setConfiguration($config + [$propel_conf['paths']]);
         $manager->setName($connection_name);
         $serviceContainer->setConnectionManager($connection_name, $manager);
     }
     $serviceContainer->setDefaultDatasource($runtime_conf['defaultConnection']);
     // set loggers
     $has_default_logger = false;
     if (isset($runtime_conf['log'])) {
         $has_default_logger = array_key_exists('defaultLogger', $runtime_conf['log']);
         foreach ($runtime_conf['log'] as $logger_name => $logger_conf) {
             $serviceContainer->setLoggerConfiguration($logger_name, $logger_conf);
         }
     }
     if (!$has_default_logger) {
         $serviceContainer->setLogger('defaultLogger', \Log::getMonolog());
     }
     Propel::setServiceContainer($serviceContainer);
 }
开发者ID:julienvincent,项目名称:PropelLaravel,代码行数:39,代码来源:RuntimeServiceProvider.php

示例9: process

 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition('event_dispatcher')) {
         return;
     }
     $definition = $container->getDefinition('event_dispatcher');
     foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) {
         foreach ($events as $event) {
             $priority = isset($event['priority']) ? $event['priority'] : 0;
             if (!isset($event['event'])) {
                 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));
             }
             if (!isset($event['method'])) {
                 $event['method'] = 'on' . preg_replace_callback(array('/(?<=\\b)[a-z]/i', '/[^a-z0-9]/i'), function ($matches) {
                     return strtoupper($matches[0]);
                 }, $event['event']);
                 $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
             }
             $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
         }
     }
     foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) {
         // We must assume that the class value has been correctly filled, even if the service is created by a factory
         $class = $container->getDefinition($id)->getClass();
         $refClass = new \ReflectionClass($class);
         $interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
         if (!$refClass->implementsInterface($interface)) {
             throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
         }
         $definition->addMethodCall('addSubscriberService', array($id, $class));
     }
     // We have to check if Propel is initialized before registering hooks
     $managers = Propel::getServiceContainer()->getConnectionManagers();
     if (!array_key_exists('thelia', $managers)) {
         return;
     }
     foreach ($container->findTaggedServiceIds('hook.event_listener') as $id => $events) {
         $class = $container->getDefinition($id)->getClass();
         // the class must extends BaseHook
         $implementClass = HookDefinition::BASE_CLASS;
         if (!is_subclass_of($class, $implementClass)) {
             throw new \InvalidArgumentException(sprintf('Hook class "%s" must extends class "%s".', $class, $implementClass));
         }
         // retrieve the module id
         $properties = $container->getDefinition($id)->getProperties();
         $module = null;
         if (array_key_exists('module', $properties)) {
             $moduleCode = explode(".", $properties['module'])[1];
             if (null !== ($module = ModuleQuery::create()->findOneByCode($moduleCode))) {
                 $module = $module->getId();
             }
         }
         foreach ($events as $event) {
             $this->registerHook($class, $module, $id, $event);
         }
     }
     // now we can add listeners for active hooks and active module
     $this->addHooksMethodCall($definition);
 }
开发者ID:alex63530,项目名称:thelia,代码行数:59,代码来源:RegisterListenersPass.php

示例10: orderByRelevance

 public function orderByRelevance()
 {
     if (!$this->full_text) {
         return $this;
     }
     $against = Propel::getServiceContainer()->getReadConnection($this->getDbName())->quote($this->fulltext_text);
     return $this->withColumn('match (title) against (' . $against . ')', 's1')->withColumn('match(description) against (' . $against . ')', 's2')->addDescendingOrderByColumn("(s1*2)+s2");
 }
开发者ID:OneTimeCZ,项目名称:Tasker,代码行数:8,代码来源:NoteQuery.php

示例11: testSetServiceContainerOverridesTheExistingServiceContainer

 public function testSetServiceContainerOverridesTheExistingServiceContainer()
 {
     $oldSC = Propel::getServiceContainer();
     $newSC = new StandardServiceContainer();
     Propel::setServiceContainer($newSC);
     $this->assertSame($newSC, Propel::getServiceContainer());
     Propel::setServiceContainer($oldSC);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:8,代码来源:PropelTest.php

示例12: __construct

 public function __construct()
 {
     $this->db = new JaCategoriasQuery();
     $this->helper = new Helper();
     $base = $this->helper->baseApi();
     $defaultLogger = new Logger('categorias');
     $defaultLogger->pushHandler(new StreamHandler($base . '/logs/api.log', Logger::WARNING));
     Propel::getServiceContainer()->setLogger('categorias', $defaultLogger);
 }
开发者ID:alejandrososa,项目名称:angularja,代码行数:9,代码来源:Categorias.php

示例13: init

 public static function init($manager, $namespace)
 {
     $workingDirectory = $manager->getWorkingDirectory();
     $paths = explode(DIRECTORY_SEPARATOR, $workingDirectory);
     $modulePaths = array();
     $found = false;
     foreach ($paths as $path) {
         if ($found == false) {
             $modulePaths[] = $path;
         }
         if ($path == $namespace) {
             $found = true;
         }
     }
     $moduleConfigPath = implode(DIRECTORY_SEPARATOR, $modulePaths);
     $moduleConfig = (include $moduleConfigPath . '/config/module.config.php');
     $appConfigPath = self::findAppConfig($moduleConfigPath);
     $applicationConfig = (include $appConfigPath . '/config/application.config.php');
     $zf2ModulePaths = array();
     if (isset($applicationConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $applicationConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     if (isset($applicationConfig['module_listener_options']['config_glob_paths'])) {
         $globConfigs = $applicationConfig['module_listener_options']['config_glob_paths'];
         foreach ($globConfigs as $globConfig) {
             $localConfig = (include $appConfigPath . '/config/autoload/local.php');
             $globalConfig = (include $appConfigPath . '/config/autoload/global.php');
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     static::initAutoloader();
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($moduleConfig, $applicationConfig);
     $config = ArrayUtils::merge($config, $baseConfig);
     $config = ArrayUtils::merge($config, $localConfig);
     $config = ArrayUtils::merge($config, $globalConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     static::$config = $config;
     $serviceContainer = Propel::getServiceContainer();
     $connectionName = array_keys($moduleConfig['propel']['database']['connections']);
     $connectionName = array_shift($connectionName);
     $connectionName = $connectionName;
     $propelConfig = $config['propel'];
     list($dsn, $dbUser, $dbPass) = static::generateDsn($connectionName, $propelConfig['database']['connections']);
     $serviceContainer->setAdapterClass($connectionName, 'mysql');
     $manager = new ConnectionManagerSingle();
     $manager->setConfiguration(array('dsn' => $dsn, 'user' => $dbUser, 'password' => $dbPass));
     $serviceContainer->setConnectionManager($connectionName, $manager);
 }
开发者ID:stevleibelt,项目名称:zf-propel,代码行数:57,代码来源:MigrationBootstrap.php

示例14: testFormatOneWithOneRowAndValueEqualsZero

 public function testFormatOneWithOneRowAndValueEqualsZero()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $stmt = $con->query('SELECT 0 FROM book LIMIT 0, 1');
     $formatter = new SimpleArrayFormatter();
     $formatter->init(new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book'));
     $book = $formatter->formatOne($stmt);
     $this->assertSame('0', $book);
 }
开发者ID:robin850,项目名称:Propel2,代码行数:9,代码来源:SimpleArrayFormatterTest.php

示例15: setUp

 public function setUp()
 {
     $container = \Propel\Runtime\Propel::getServiceContainer();
     $container->setAdapterClass('finite-test', 'sqlite');
     $connectionManager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
     $connectionManager->setConfiguration(['dsn' => '/tmp/test.db', 'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper']);
     $connectionManager->setName('finite-test');
     $container->setConnectionManager('finite-test', $connectionManager);
 }
开发者ID:vdbf,项目名称:propel-finite-behavior,代码行数:9,代码来源:FiniteBehaviorTest.php


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