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


PHP Str::replaceFirst方法代码示例

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


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

示例1: failConnect

 /**
  * Event fired on database connection failure.
  *
  * @param FailedConnectionEvent $args
  *
  * @throws BootException
  */
 public function failConnect(FailedConnectionEvent $args)
 {
     $e = $args->getException();
     $this->logger->debug($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
     /*
      * Using Driver here since Platform may try to connect
      * to the database, which has failed since we are here.
      */
     $platform = $args->getDriver()->getName();
     $platform = Str::replaceFirst('pdo_', '', $platform);
     $response = $this->exceptionController->databaseConnect($platform, $e);
     throw new BootException($e->getMessage(), $e->getCode(), $e, $response);
 }
开发者ID:bolt,项目名称:bolt,代码行数:20,代码来源:DoctrineListener.php

示例2: failConnect

 /**
  * Event fired on database connection failure.
  *
  * @param FailedConnectionEvent $args
  *
  * @throws LowLevelDatabaseException
  */
 public function failConnect(FailedConnectionEvent $args)
 {
     $e = $args->getException();
     $this->logger->debug($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
     // Trap double exceptions
     set_exception_handler(function () {
     });
     /*
      * Using Driver here since Platform may try to connect
      * to the database, which has failed since we are here.
      */
     $platform = $args->getDriver()->getName();
     $platform = Str::replaceFirst('pdo_', '', $platform);
     throw LowLevelDatabaseException::failedConnect($platform, $e);
 }
开发者ID:gandalf3,项目名称:bolt,代码行数:22,代码来源:DoctrineListener.php

示例3: checkDatabaseConnection

 /**
  * Set up the DBAL connection now to check for a proper connection to the database.
  *
  * @throws LowlevelException
  */
 protected function checkDatabaseConnection()
 {
     // [SECURITY]: If we get an error trying to connect to database, we throw a new
     // LowLevelException with general information to avoid leaking connection information.
     try {
         $this['db']->connect();
         // A ConnectionException or DriverException could be thrown, we'll catch DBALException to be safe.
     } catch (DBALException $e) {
         // Trap double exceptions caused by throwing a new LowlevelException
         set_exception_handler(array('\\Bolt\\Exception\\LowlevelException', 'nullHandler'));
         /*
          * Using Driver here since Platform may try to connect
          * to the database, which has failed since we are here.
          */
         $platform = $this['db']->getDriver()->getName();
         $platform = Str::replaceFirst('pdo_', '', $platform);
         $error = "Bolt could not connect to the configured database.\n\n" . "Things to check:\n" . "&nbsp;&nbsp;* Ensure the {$platform} database is running\n" . "&nbsp;&nbsp;* Check the <code>database:</code> parameters are configured correctly in <code>app/config/config.yml</code>\n" . "&nbsp;&nbsp;&nbsp;&nbsp;* Database name is correct\n" . "&nbsp;&nbsp;&nbsp;&nbsp;* User name has access to the named database\n" . "&nbsp;&nbsp;&nbsp;&nbsp;* Password is correct\n";
         throw new LowlevelException($error);
     }
     // Resume normal error handling
     restore_error_handler();
 }
开发者ID:uwfsae,项目名称:team-website,代码行数:27,代码来源:Application.php

示例4: parseDatabase

 /**
  * Parse and fine-tune the database configuration.
  *
  * @param array $options
  *
  * @return array
  */
 protected function parseDatabase(array $options)
 {
     // Make sure prefix ends with underscore
     if (substr($options['prefix'], strlen($options['prefix']) - 1) !== '_') {
         $options['prefix'] .= '_';
     }
     // Parse master connection parameters
     $master = $this->parseConnectionParams($options);
     // Merge master connection into options
     $options = array_replace($options, $master);
     // Add platform specific random functions
     $driver = Str::replaceFirst('pdo_', '', $options['driver']);
     if ($driver === 'sqlite') {
         $options['driver'] = 'pdo_sqlite';
         $options['randomfunction'] = 'RANDOM()';
     } elseif (in_array($driver, ['mysql', 'mysqli'])) {
         $options['driver'] = 'pdo_mysql';
         $options['randomfunction'] = 'RAND()';
     } elseif (in_array($driver, ['pgsql', 'postgres', 'postgresql'])) {
         $options['driver'] = 'pdo_pgsql';
         $options['randomfunction'] = 'RANDOM()';
     }
     // Specify the wrapper class for the connection
     $options['wrapperClass'] = '\\Bolt\\Storage\\Database\\Connection';
     // Parse SQLite separately since it has to figure out database path
     if ($driver === 'sqlite') {
         return $this->parseSqliteOptions($options);
     }
     // If no slaves return with single connection
     if (empty($options['slaves'])) {
         return $options;
     }
     // Specify we want a master slave connection
     $options['wrapperClass'] = '\\Bolt\\Storage\\Database\\MasterSlaveConnection';
     // Add master connection where MasterSlaveConnection looks for it.
     $options['master'] = $master;
     // Parse each slave connection parameters
     foreach ($options['slaves'] as $name => $slave) {
         $options['slaves'][$name] = $this->parseConnectionParams($slave, $master);
     }
     return $options;
 }
开发者ID:errogaht,项目名称:bolt,代码行数:49,代码来源:Config.php

示例5: insertEndOfBody

 /**
  * Helper function to insert some HTML into the body section of an HTML
  * page, right before the </body> tag.
  *
  * @param string $tag
  * @param string $html
  *
  * @return string
  */
 static function insertEndOfBody($tag, $html)
 {
     // first, attempt to insert it before the </body> tag, matching indentation.
     if (preg_match("~([ \t]*)</body~mi", $html, $matches)) {
         // Try to insert it just before </head>
         $replacement = sprintf("%s\t%s\n%s", $matches[1], $tag, $matches[0]);
         $html = Str::replaceFirst($matches[0], $replacement, $html);
     } else {
         // Since we're serving tag soup, just append it.
         $html .= $tag . "\n";
     }
     return $html;
 }
开发者ID:bobdenotter,项目名称:wordpress-theme,代码行数:22,代码来源:WordpressHelper.php

示例6: insertAfterJs

 /**
  * Helper function to insert some HTML after the last javascript include.
  * First in the head section, but if there is no script in the head, place
  * it anywhere.
  *
  * @param string $tag
  * @param string $html
  * @param bool   $insidehead
  *
  * @return string
  */
 public function insertAfterJs($tag, $html, $insidehead = true)
 {
     // Set $context: only the part until </head>, or entire document.
     if ($insidehead) {
         $pos = strpos($html, "</head>");
         $context = substr($html, 0, $pos);
     } else {
         $context = $html;
     }
     // then, attempt to insert it after the last <script> tag within context, matching indentation.
     if (preg_match_all("~^([ \t]*)(.*)</script>~mi", $context, $matches)) {
         // matches[0] has some elements, the last index is -1, because zero indexed.
         $last = count($matches[0]) - 1;
         $replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], $tag);
         $html = Str::replaceFirst($matches[0][$last], $replacement, $html);
     } elseif ($insidehead) {
         // Second attempt: entire document
         $html = $this->insertAfterJs($tag, $html, false);
     } else {
         // Just insert it at the end of the head section.
         $html = $this->insertEndOfHead($tag, $html);
     }
     return $html;
 }
开发者ID:aleksabp,项目名称:bolt,代码行数:35,代码来源:Extensions.php

示例7: jsTagsAfter

 /**
  * Helper function to insert some HTML after the last javascript include.
  * First in the head section, but if there is no script in the head, place
  * it anywhere.
  *
  * @param AssetInterface $asset
  * @param string         $rawHtml
  * @param boolean        $insidehead
  *
  * @return string
  */
 protected function jsTagsAfter($asset, $rawHtml, $insidehead = false)
 {
     if ($insidehead) {
         $pos = strpos($rawHtml, '</head>');
         $context = substr($rawHtml, 0, $pos);
     } else {
         $context = $rawHtml;
     }
     // This match tag is a unique case
     if ($matches = $this->getMatches($context, '(.*)</script>', false, true)) {
         // Attempt to insert it after the last <script> tag within context, matching indentation.
         $last = count($matches[0]) - 1;
         $replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], (string) $asset);
         return Str::replaceFirst($matches[0][$last], $replacement, $rawHtml);
     } elseif ($insidehead) {
         // Second attempt: entire document
         return $this->jsTagsAfter($asset, $rawHtml, false);
     }
     return $this->headTagEnd($asset, $rawHtml);
 }
开发者ID:atiarda,项目名称:bolt,代码行数:31,代码来源:Injector.php

示例8: getVendor

 /**
  * {@inheritdoc}
  */
 public final function getVendor()
 {
     if ($this->vendor === null) {
         $namespace = $this->getNamespace();
         $name = Str::replaceFirst('Bolt\\Extension\\', '', $namespace);
         $pos = strpos($name, '\\');
         $this->vendor = $pos === false ? $name : substr($name, 0, $pos);
     }
     return $this->vendor;
 }
开发者ID:robbert-vdh,项目名称:bolt,代码行数:13,代码来源:AbstractExtension.php

示例9: testReplaceFirst

 public function testReplaceFirst()
 {
     $input = "this is a test string this is a test string";
     $this->assertEquals("one is a test string this is a test string", Str::replaceFirst('this', 'one', $input));
 }
开发者ID:nuffer,项目名称:bolt,代码行数:5,代码来源:StrTest.php


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