本文整理汇总了PHP中Symfony\Component\Finder\SplFileInfo::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getExtension方法的具体用法?PHP SplFileInfo::getExtension怎么用?PHP SplFileInfo::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Create sprite image data holder
* @param string $path
* @param SplFileInfo $fileInfo
*/
public function __construct($path, SplFileInfo $fileInfo)
{
$this->basePath = $path;
$this->info = $fileInfo;
// Assign fileinfo variables
$this->path = $this->info->getPathname();
$this->size = $this->info->getSize();
// Assign image data
$info = getimagesize($this->path);
if (!is_array($info)) {
throw new UnexpectedValueException("The image '{$this->path}' is not a correct image format.");
}
$this->hash = sha1(file_get_contents($this->getFullPath()));
$this->width = (int) $info[0];
$this->height = (int) $info[1];
$this->mime = $info['mime'];
$this->type = explode('/', $this->mime)[1];
// Assign css name
$ext = $this->info->getExtension();
// Replace path parts with `-`
$name = str_replace(['/', '\\', '_'], '-', $this->info->getRelativePathname());
// Remove leading `-`
$name = preg_replace('~^-*~', '', $name);
// Remove double dashes
$name = preg_replace('~-+~', '-', $name);
// Remove file extension
$name = preg_replace("~\\.{$ext}\$~", '', $name);
// Replace dots with -
$name = preg_replace('~\\.~', '-', $name);
$this->name = $name;
}
示例2: getFileContents
/**
* @param SplFileInfo $file
*
* @return string
*/
private function getFileContents(SplFileInfo $file)
{
$content = $file->getContents();
if ($file->getExtension() === 'js' && substr($content, -1) !== ';') {
$content .= ';';
}
return $content;
}
示例3: getDirectoryPrettyName
/**
* Generate directory path to be used for the file pretty name.
*
* @return string
*/
protected function getDirectoryPrettyName()
{
$fileBaseName = $this->getFileName();
$fileRelativePath = $this->normalizePath($this->file->getRelativePath());
if (in_array($this->file->getExtension(), ['php', 'md']) && $fileBaseName != 'index') {
$fileRelativePath .= $fileRelativePath ? "/{$fileBaseName}" : $fileBaseName;
}
return ORCA_PUBLIC_DIR . ($fileRelativePath ? "/{$fileRelativePath}" : '');
}
示例4: checkIfImage
public static function checkIfImage($path)
{
$file = new \SplFileInfo($path);
$ex = $file->getExtension();
if ($ex === "png" || $ex === "gif" || $ex === 'bmp' || $ex === "jpeg" || $ex === "jpg") {
return true;
}
return false;
}
示例5: transform
/**
* Transform a taxonomy YAML into a TaxonomyFile object
*
* @param SplFileInfo $file
*
* @return \Skimpy\Contracts\Entity|TaxonomyFile
*/
public function transform(SplFileInfo $file)
{
$data = $this->parser->parse($file->getContents());
$missingFields = $this->getMissingFields($data);
if (false === empty($missingFields)) {
throw new TransformationFailure(sprintf('Missing required fields (%s) in taxonomy file: %s', implode(', ', $this->getMissingFields($data)), $file->getRealPath()));
}
$filename = $file->getFilename();
$ext = $file->getExtension();
$slug = explode('.' . $ext, $filename)[0];
return new TaxonomyFile($slug, $data['name'], $data['plural_name'], $data['terms']);
}
示例6: isBinary
private function isBinary(SplFileInfo $file)
{
$ext = $file->getExtension();
return false === in_array($ext, $this->params['text_extensions']);
}
示例7: getFilename
/**
* Returns filename w/o extension
*
* @return string
*/
public function getFilename()
{
$exclude = '.' . $this->file->getExtension();
return $this->file->getBasename($exclude);
}
示例8: getClassname
/**
* Gets the class name.
*
* @param \Symfony\Component\Finder\SplFileInfo $file
*
* @return string
*/
protected function getClassname(SplFileInfo $file)
{
if ($file->getExtension() === 'php') {
return $file->getBasename('.php');
}
if ($file->getFilename() === $this->composerFilename) {
$composerData = $this->readComposerFile($file);
if (isset($composerData['extra']['spress_class']) === true && is_string($composerData['extra']['spress_class'])) {
return $composerData['extra']['spress_class'];
}
}
return '';
}
示例9: setTarget
/**
* Determine the target path.
*
* @param SplFileInfo $file
* @return string
*/
protected function setTarget(SplFileInfo $file)
{
// Page extension
$ext = $file->getExtension();
// Twig templates are HTML
if (!$this->has('template') || $this->get('template') === 'none') {
$targetExt = $ext;
} else {
$targetExt = 'html';
}
// Get clean source path
$sourcePath = $this->getCleanPath($file->getRelativePathName());
// Replace source extension with that of the template
$this->target = substr($sourcePath, 0, -strlen($ext));
$this->target .= $targetExt;
}
示例10: getPath
/**
* @param \Symfony\Component\Finder\SplFileInfo $file
*
* @return string
*/
private function getPath(SplFileInfo $file)
{
switch ($file->getExtension()) {
case 'gz':
$path = 'compress.zlib://' . $file->getPathname();
break;
case 'bz2':
$path = 'compress.bzip2://' . $file->getPathname();
break;
default:
$path = $file->getPathname();
break;
}
return $path;
}
示例11: getExtension
public function getExtension()
{
return $this->fileInfo->getExtension();
}
示例12: fromFile
/**
* Добавляет в загрузку один файл
*
* @param string $pathToFile путь к файлу из которого необходимо загрузить фикстуры
*
* @return $this
* @throws \InvalidArgumentException
*/
public function fromFile($pathToFile)
{
if (empty($pathToFile)) {
throw new \InvalidArgumentException("Был передан пустой путь к файлу с фикстурами");
}
if (!is_string($pathToFile)) {
throw new \InvalidArgumentException("Параметр pathToFile не является строкой");
}
if (!file_exists($pathToFile)) {
throw new \InvalidArgumentException("Был передан несуществующий путь к файлу '{$pathToFile}'");
}
$fileInfo = new \SplFileInfo($pathToFile);
if ($fileInfo->getExtension() !== self::DEFAULT_FILE_EXTENSION) {
throw new \InvalidArgumentException("Переданный файл '{$pathToFile}' обладает неправильным расширением");
}
$this->filePathsByKey[$fileInfo->getRealPath()] = true;
return $this;
}
示例13: shouldIgnore
/**
* @param SplFileInfo $file
* @return bool
*/
protected function shouldIgnore(SplFileInfo $file)
{
if ($file->getExtension() === 'php') {
return true;
}
return false;
}
示例14: extractStringTokens
/**
* Extract all strings from a given file.
*
* @param SplFileInfo $file
*
* @return string[]
*/
protected function extractStringTokens(SplFileInfo $file)
{
// Fetch tokens from cache if available
$hash = 'janitor.tokens.' . md5($file->getPathname()) . '-' . $file->getMTime();
return $this->cache->rememberForever($hash, function () use($file) {
$contents = $file->getContents();
// See if we have an available Tokenizer
// and use it to extract the contents
switch ($file->getExtension()) {
case 'php':
$tokenizer = strpos($file->getBasename(), 'blade.php') !== false ? new BladeTokenizer() : new PhpTokenizer();
break;
case 'twig':
$tokenizer = new TwigTokenizer();
break;
case 'json':
$tokenizer = new JsonTokenizer();
break;
case 'yml':
case 'yaml':
$tokenizer = new YamlTokenizer();
break;
case 'xml':
$tokenizer = new XmlTokenizer();
break;
default:
$tokenizer = new DefaultTokenizer();
break;
}
return $tokenizer->tokenize($contents);
});
}
示例15: _isSkip
/**
* Check skip files.
*
* @param SplFileInfo $file
* @return bool
*/
protected function _isSkip(SplFileInfo $file)
{
$name = $file->getFilename();
$ext = $file->getExtension();
return Arr::in($ext, $this->_skipFileExt) || Arr::in($name, $this->_skipFileNames);
}