本文整理汇总了PHP中Symfony\Component\Finder\SplFileInfo::getBasename方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getBasename方法的具体用法?PHP SplFileInfo::getBasename怎么用?PHP SplFileInfo::getBasename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getBasename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBundleClass
/**
* Returns FQCN for file
*
* @param SplFileInfo $fileInfo
*
* @return string|null
*/
private function getBundleClass(SplFileInfo $fileInfo)
{
$reflection = new ReflectionFile($fileInfo->getRealPath());
$baseName = $fileInfo->getBasename('.php');
foreach ($reflection->getNamespaces() as $namespace) {
return $namespace . '\\' . $baseName;
}
return null;
}
示例2: __construct
public function __construct(SplFileInfo $file)
{
$this->file = $file;
$this->path = str_replace('\\', '/', $file->getRelativePath());
$this->filename = $file->getFilename();
$this->package = $file->getBasename('.zip');
$this->version = 'dev-unknown';
list($this->type, $this->vendor) = explode('/', $this->path);
$matches = $this->parseFilename($this->filename);
if (!empty($matches)) {
$this->package = $matches['package'];
$this->version = $matches['version'];
}
}
示例3: addFile
/**
* Add a file into the phar package.
*
* @param Phar $phar Phar object
* @param SplFileInfo $file File to add
* @param bool $strip strip
*
* @return Compiler self Object
*/
protected function addFile(Phar $phar, SplFileInfo $file, $strip = true)
{
$path = strtr(str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/');
$content = $file->getContents();
if ($strip) {
$content = $this->stripWhitespace($content);
} elseif ('LICENSE' === $file->getBasename()) {
$content = "\n" . $content . "\n";
}
if ($path === 'src/Composer/Composer.php') {
$content = str_replace('@package_version@', $this->version, $content);
$content = str_replace('@release_date@', $this->versionDate, $content);
}
$phar->addFromString($path, $content);
return $this;
}
示例4: loadGeneratorInBundle
/**
* Load a single generator into the registry.
* @param SplFileInfo $file
* @param string $ns
*/
private function loadGeneratorInBundle(SplFileInfo $file, $ns)
{
if ($relativePath = $file->getRelativePath()) {
$ns .= '\\' . strtr($relativePath, '/', '\\');
}
$class = $ns . '\\' . $file->getBasename('.php');
// if an alias of the generator exists, skip this one
if ($this->container) {
$alias = 'tweedegolf_generator.generator.' . strtolower(str_replace('\\', '_', $class));
if ($this->container->has($alias)) {
return;
}
}
// add the generator through reflection
$r = new \ReflectionClass($class);
if ($r->isSubclassOf('TweedeGolf\\Generator\\GeneratorInterface') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
$this->addGenerator($r->newInstance());
}
}
示例5: __construct
/**
* Constructor.
*
* @param null|SplFileInfo $file
*/
public function __construct(SplFileInfo $file = null)
{
$this->file = $file;
if ($this->file instanceof SplFileInfo) {
// file extension: "md"
$this->fileExtension = pathinfo($this->file, PATHINFO_EXTENSION);
// file path: "Blog"
$this->filePath = str_replace(DIRECTORY_SEPARATOR, '/', $this->file->getRelativePath());
// file id: "Blog/Post 1"
$this->fileId = ($this->filePath ? $this->filePath . '/' : '') . basename($this->file->getBasename(), '.' . $this->fileExtension);
/*
* variables default values
*/
// id - ie: "blog/post-1"
$this->id = $this->urlize($this->fileId);
// pathname - ie: "blog/post-1"
$this->pathname = $this->urlize($this->fileId);
// path - ie: "blog"
$this->path = $this->urlize($this->filePath);
// name - ie: "post-1"
$this->name = $this->urlize(basename($this->file->getBasename(), '.' . $this->fileExtension));
/*
* front matter default values
*/
// title - ie: "Post 1"
$this->setTitle(basename($this->file->getBasename(), '.' . $this->fileExtension));
// section - ie: "blog"
$this->setSection(explode('/', $this->path)[0]);
// date
$this->setDate(filemtime($this->file->getPathname()));
// permalink
$this->setPermalink($this->pathname);
parent::__construct($this->id);
} else {
$this->virtual = true;
parent::__construct();
}
}
示例6: getQualifiedName
/**
* @param \Symfony\Component\Finder\SplFileInfo $fileInfo
* @return string
*/
protected function getQualifiedName(SplFileInfo $fileInfo)
{
if (!preg_match('/namespace (.+?);/', $fileInfo->getContents(), $match)) {
return null;
}
return $match[1] . '\\' . $fileInfo->getBasename('.php');
}
示例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: load
/**
* Load and parse content from file.
*
* @param SplFileInfo $file
* @return void
*/
protected function load(SplFileInfo $file)
{
// File info
$this->filename = $file->getBasename();
$this->sourcePath = $file->getRelativePath();
// Load the file
$data = $file->getContents();
list($content, $meta) = $this->splitContentMeta($data);
// Parse meta
$meta = Yaml::parse($meta) ?: [];
// Parse content
switch ($file->getExtension()) {
case 'md':
case 'markdown':
$content = Markdown::parse($content);
$this->type = self::TYPE_MARKDOWN;
break;
case 'tx':
case 'textile':
$content = Textile::parse($content);
$this->type = self::TYPE_TEXTILE;
break;
}
// Set content
$this->content = $content;
$this->meta = $meta;
// Ensure local URLs are absolute
foreach ($this->meta as $key => $value) {
if (preg_match('/\\burl\\b|.*_url\\b/', $key)) {
$this->meta[$key] = $this->builder->getUrl($value);
}
}
// Set target
$this->setTarget($file);
// Pagination enabled
$this->paginate = isset($this->meta['paginate']);
// Get parent page
if ($root = dirname(dirname($this->target))) {
if ($root !== DIRECTORY_SEPARATOR) {
$this->parentId = ltrim($root, '/');
}
}
// Set URL
$this->url = '/' . trim(str_replace([DIRECTORY_SEPARATOR, '//'], ['/', '/'], $this->target), '/');
// Remove "index.html" from the end, this provides a cleaner URL
if (substr($this->url, -10) === 'index.html') {
$this->url = substr($this->url, 0, -10);
}
// Set basic values
$this->id = trim($this->url, '/') ?: 'root';
$this->title = $this->get('title');
$this->url = $this->builder->getUrl($this->url);
// Set Description
if ($this->has('description')) {
$this->description = $this->get('description');
} else {
$this->description = $this->getDescription();
}
}
示例10: isMigration
/**
* Проверяет является ли класс миграцией.
* @param SplFileInfo $file файл
* @return bool|IMigration
*/
protected function isMigration(SplFileInfo $file)
{
require_once $file->getPathname();
$className = $file->getBasename('.php');
$migration = new $className();
if (!$migration instanceof IMigration) {
return false;
}
return $migration;
}
示例11: getBasename
public function getBasename($suffix = null)
{
return $this->fileInfo->getBasename($suffix);
}
示例12: getImageSavePath
/**
* 获取图像文件保存路径
* @param SplFileInfo $fileInfo
* @return string
*/
protected function getImageSavePath(SplFileInfo $fileInfo)
{
return $this->savePath . '/' . $fileInfo->getBasename(true);
}
示例13: parseScenario
/**
* @param string $scenario
* @param SplFileInfo $fileInfo
*
* @todo make it event driven
*
* @return string
*/
public function parseScenario($scenario, $fileInfo)
{
$feature = '';
list($title, $body) = explode(PHP_EOL, $scenario, 2);
$feature .= '### ' . $title . PHP_EOL . PHP_EOL . $body . PHP_EOL . PHP_EOL;
$path = $fileInfo->getPath() . '/' . $fileInfo->getBasename('.feature');
if (is_dir($path)) {
$targetFile = $path . '/' . $this->sanitizeFileName($title) . '.md';
if (is_readable($targetFile)) {
$feature .= file_get_contents($targetFile) . PHP_EOL . PHP_EOL;
}
}
return $feature;
}
示例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: getClassReflection
/**
* Get Class Reflection Instance
*
* @access protected
* @throws \LogicException
* @param \Symfony\Component\Finder\SplFileInfo $file
* @param string $namespace
* @param string $suffix
* @param string $parent
* @param integer $allowedParameters
* @return \Darsyn\ClassFinder\Reflection\ReflectionClass
*/
protected function getClassReflection(SplFileInfo $file, $namespace, $suffix, $parent, $allowedParameters)
{
// Determine the fully-qualified class name of the found file.
$class = preg_replace('#\\\\{2,}#', '\\', sprintf('%s\\%s\\%s', $namespace, strtr($file->getRelativePath(), '/', '\\'), $file->getBasename($this->extension)));
// Make sure that the class name has the correct suffix.
if (!empty($suffix) && substr($class, 0 - strlen($suffix)) !== $suffix) {
throw new \LogicException(sprintf('The file found at "%s" does not end with the required suffix of "%s".', $file->getRealPath(), $suffix));
}
// We have to perform a few checks on the class before we can return it.
// - It must be an actual class; not interface, abstract or trait types.
// - For this to work the constructor must not have more than the expected number of required parameters.
// - And finally make sure that the class loaded was actually loaded from the directory we found it in.
// TODO: Make sure that the final (file path) check doesn't cause problems with proxy classes or
// bootstraped/compiled class caches.
$reflect = new ReflectionClass($class, $file->getRelativePath());
if (is_object($construct = $reflect->getConstructor()) && $construct->getNumberOfRequiredParameters() > $allowedParameters || $reflect->isAbstract() || $reflect->isInterface() || $reflect->isTrait() || is_string($parent) && !empty($parent) && !$reflect->isSubclassOf($parent) || $reflect->getFileName() !== $file->getRealPath()) {
throw new \LogicException(sprintf('The class definition for "%s" is invalid.', $class));
}
return $reflect;
}