本文整理汇总了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;
}
示例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;
}