當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。