本文整理汇总了PHP中Symfony\Component\Finder\SplFileInfo::getRelativePath方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getRelativePath方法的具体用法?PHP SplFileInfo::getRelativePath怎么用?PHP SplFileInfo::getRelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getRelativePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Convert a blade view into a site page.
*
* @param SplFileInfo $file
*
* @return void
*/
public function handle(SplFileInfo $file, $viewsData)
{
$this->viewsData = $viewsData;
$this->file = $file;
$this->viewPath = $this->getViewPath();
$this->directory = $this->getDirectoryPrettyName();
$this->appendViewInformationToData();
$content = $this->getFileContent();
$this->filesystem->put(sprintf('%s/%s', $this->prepareAndGetDirectory(), ends_with($file->getFilename(), ['.blade.php', 'md']) ? 'index.html' : $file->getFilename()), $content);
// copy images to public folder
foreach ($file->images as $media) {
$copyFrom = ORCA_CONTENT_DIR . "/{$file->getRelativePath()}/{$media}";
$copyTo = "{$this->directory}/{$media}";
if (!$this->filesystem->copy($copyFrom, $copyTo)) {
echo "failed to copy {$media}...\n";
}
}
// copy documents
foreach ($file->documents as $media) {
$copyFrom = ORCA_CONTENT_DIR . "/{$file->getRelativePath()}/{$media}";
$copyTo = "{$this->directory}/{$media}";
if (!$this->filesystem->copy($copyFrom, $copyTo)) {
echo "failed to copy {$media}...\n";
}
}
}
示例2: __sleep
/**
* Because SplFileInfo can't be serialized, we need to replace it with data that can be recovered when we serialize
* this object again.
*
* @return array
*/
public function __sleep()
{
$fileInfo = ['file' => $this->file->getPathname(), 'relativePath' => $this->file->getRelativePath(), 'relativePathname' => $this->file->getRelativePathname()];
$classVars = get_object_vars($this);
$this->file = $fileInfo;
return array_keys($classVars);
}
示例3: parseFeature
/**
* @param SplFileInfo $fileInfo
*
* @todo make it event driven
*
* @return mixed|string
*
*/
protected function parseFeature($fileInfo)
{
$feature = $fileInfo->getContents();
$scenarios = explode('Szenario:', $feature);
$feature = array_shift($scenarios);
$lines = explode(PHP_EOL, $feature);
if (0 === strpos($feature, '#')) {
array_shift($lines);
}
$title = array_shift($lines);
$title = str_replace('Funktionalität: ', '## ', $title);
$userStory = trim(implode(PHP_EOL, $lines));
$userStory = preg_replace('/\\n[\\s]*/', "\n", $userStory);
$imageFile = $fileInfo->getPath() . '/' . $fileInfo->getBasename('.feature') . '.png';
$output = $title . PHP_EOL . PHP_EOL;
$output .= $userStory . PHP_EOL . PHP_EOL;
if (is_readable($imageFile)) {
$output .= '![' . basename($imageFile, '.png') . '](./' . $fileInfo->getRelativePath() . basename($fileInfo->getPath()) . '/' . basename($imageFile) . ')' . PHP_EOL . PHP_EOL;
}
foreach ($scenarios as $scenario) {
$scenario = trim($scenario);
if (!$scenario) {
continue;
}
$output .= $this->parseScenario($scenario, $fileInfo);
}
return $output;
}
示例4: shouldSkip
/**
* @param SplFileInfo $composerJsonFile
* @param array $bundles
*
* @return bool
*/
protected function shouldSkip(SplFileInfo $composerJsonFile, array $bundles)
{
if (!$bundles) {
return false;
}
$folder = $composerJsonFile->getRelativePath();
return !in_array($folder, $bundles);
}
示例5: __construct
/**
* __construct
*/
protected function __construct(SplFileInfo $file, $relativePath = null)
{
$this->title = Content::filename_to_title($file->getFilename());
$this->slug = Content::str_to_slug($file->getFilename());
$relativePath = !is_null($relativePath) && !empty($relativePath) ? $relativePath : $file->getRelativePath();
$this->path = $relativePath . (ends_with($relativePath, '/') ? '' : '/') . $this->slug;
$this->file = $file;
}
示例6: 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}" : '');
}
示例7: __construct
public function __construct(SplFileInfo $file)
{
$this->file = $file;
$this->path = str_replace('\\', '/', $file->getRelativePath());
$this->filename = $file->getFilename();
list($this->type, $this->vendor) = explode('/', $this->path);
$matches = $this->parseFilename($this->filename);
$this->package = $matches['package'];
$this->version = $matches['version'];
}
示例8: __construct
/**
* __construct
*/
protected function __construct(SplFileInfo $file, $language = 'en')
{
$parser = app(Parser::class);
$this->metadata = $parser->frontmatter($file->getContents());
$this->title = isset($this->metadata['PageTitle']) ? $this->metadata['PageTitle'] : (isset($this->metadata['Title']) ? $this->metadata['Title'] : Content::filename_to_title($file->getFilename()));
$this->slug = Content::str_to_slug($this->title);
if (ends_with($file->getRelativePathName(), 'index.md')) {
$this->is_section_home = true;
}
$this->level = count(array_filter(explode(DIRECTORY_SEPARATOR, $file->getRelativePath())));
$relativePath = str_replace('\\', '/', $file->getRelativePath());
$this->is_homepage = $this->level === 0 && $this->is_section_home;
if ($this->level > 0 && $this->is_section_home) {
$this->path = $relativePath;
} else {
$relativePath = $relativePath . (ends_with($relativePath, '/') ? '' : '/');
$this->path = $relativePath . $this->slug;
}
$this->language = $language;
$this->file = $file;
$this->order = isset($this->metadata['Order']) ? $this->metadata['Order'] : (isset($this->metadata['Sort']) ? $this->metadata['Sort'] : 0);
}
示例9: deleteFolderAction
/**
* @Route("/file_manager/delete-folder", name="spliced_cms_admin_file_manager_delete_folder")
* @Template()
*/
public function deleteFolderAction()
{
$this->loadContext();
if (!$this->dir instanceof \SplFileInfo || !$this->dir->getRealPath() || !$this->file->isDir()) {
$this->get('session')->getFlashBag()->add('error', 'Directory Not Found');
return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager', array('dir' => $this->dir->getRelativePath())));
}
$fs = new Filesystem();
$success = false;
try {
$fs->remove($this->dir->getRealPath());
$this->get('session')->getFlashBag()->add('success', 'File Deleted');
$success = true;
} catch (\IOException $e) {
$this->get('session')->getFlashBag()->add('error', 'Could Not Delete Folder');
}
return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager', array('dir' => $success ? $this->baseDir->getRelativePath() : $this->dir->getRelativePath())));
}
示例10: 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());
}
}
示例11: __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();
}
}
示例12: 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();
}
}
示例13: getRelativePath
public function getRelativePath()
{
return $this->fileInfo->getRelativePath();
}
示例14: update
/**
* @param array $composerJson
* @param \Symfony\Component\Finder\SplFileInfo $composerJsonFile
*
* @return array
*/
public function update(array $composerJson, SplFileInfo $composerJsonFile)
{
$bundleName = $composerJsonFile->getRelativePath();
$composerJson[self::KEY_DESCRIPTION] = $bundleName . ' bundle';
return $composerJson;
}
示例15: shouldSkip
/**
* @param \Symfony\Component\Finder\SplFileInfo $composerJsonFile
* @param string $bundleName
*
* @return bool
*/
protected function shouldSkip(SplFileInfo $composerJsonFile, $bundleName)
{
$folder = $composerJsonFile->getRelativePath();
return $folder !== $bundleName;
}