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


PHP Strings::before方法代码示例

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


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

示例1: createName

 /**
  * Returns generated name for a image
  *
  * @param \Imager\ImageInfo $image
  * @return string
  */
 public static function createName(ImageInfo $image)
 {
     $source = $image->getSource() ?: $image;
     $id = $image->getParameter('id');
     if (!isset($id)) {
         $name = md5($source->getPathname());
     } else {
         $name = Strings::before($id, '.', -1);
     }
     // dimensions of image only for thumbnail (has source)
     $width = $image->getParameter('width');
     $height = $image->getParameter('height');
     $quality = $image->getParameter('quality');
     $dimensionName = self::createDimensionName($width, $height, $quality);
     if ($source->getExtension() !== '') {
         $ext = '.' . $source->getExtension();
     } else {
         $extensions = [IMAGETYPE_GIF => '.gif', IMAGETYPE_JPEG => '.jpg', IMAGETYPE_PNG => '.png', IMAGETYPE_BMP => '.bmp'];
         if (!array_key_exists($source->getType(), $extensions)) {
             $msg = sprintf('Image "%s" is unsupported type.', $source->getFilename());
             throw new InvalidStateException($msg);
         }
         $ext = $extensions[$source->getType()];
     }
     $fileName = $name . $dimensionName . $ext;
     return $fileName;
 }
开发者ID:lawondyss,项目名称:imager,代码行数:33,代码来源:Helpers.php

示例2: execute

 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $languageArgument = $input->getArgument(self::LANGUAGE_ARGUMENT);
     /** @var Language $language */
     if (($language = $this->languagesRepository->findOneBy(['shortCode' => $languageArgument])) === NULL) {
         $output->writeln("<error>Unknown language {$languageArgument}</error>");
         return 1;
     }
     /** @var Season $season */
     foreach ($this->seasonsRepository->findBy(['language' => $language]) as $season) {
         foreach ($season->getEpisodes() as $episode) {
             $file = "S{$season->getNumber()}E{$episode->getNumber()}{$language->getShortCode()}.txt";
             $handle = fopen($this->scenariosDir . '/' . $file, 'r');
             if ($handle) {
                 $screenplayLine = 1;
                 while (($line = fgets($handle)) !== FALSE) {
                     $name = Strings::before($line, ':');
                     $isCharacter = $name && !in_array($name, self::KNOWN_NON_CHARACTERS, TRUE) && str_word_count($name, 0) < 3 ? TRUE : FALSE;
                     $character = $isCharacter ? $this->charactersRepository->findOneBy(['slug' => Strings::webalize($name), 'language' => $language]) : NULL;
                     if ($isCharacter && $character === NULL) {
                         $character = new Character(Strings::capitalize($name), $language);
                         $this->entityManager->persist($character);
                         $this->entityManager->flush($character);
                     }
                     $text = $isCharacter ? str_replace($name . ': ', '', $line) : $line;
                     $text = Strings::trim($text);
                     if (empty($text)) {
                         continue;
                     }
                     $screenplay = new Screenplay($episode, $text, $character, $screenplayLine, !$isCharacter);
                     $this->entityManager->persist($screenplay);
                     $this->entityManager->flush($screenplay);
                     $screenplayLine++;
                 }
                 fclose($handle);
             } else {
                 $output->writeln("<error>Scénář {$file} neexistuje!</error>");
                 return 1;
             }
         }
     }
     return 0;
 }
开发者ID:stekycz,项目名称:dwarf-search,代码行数:46,代码来源:ScreenplayImportCommand.php


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