本文整理汇总了PHP中Symfony\Component\Finder\SplFileInfo::getRealPath方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getRealPath方法的具体用法?PHP SplFileInfo::getRealPath怎么用?PHP SplFileInfo::getRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getRealPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNesting
/**
* Get the file nesting path.
*
* @param \Symfony\Component\Finder\SplFileInfo $file
* @param string $path
*
* @return string
*/
protected function getNesting(SplFileInfo $file, string $path) : string
{
$directory = dirname($file->getRealPath());
if ($tree = trim(str_replace($path, '', $directory), DIRECTORY_SEPARATOR)) {
$tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
}
return $tree;
}
示例2: testRessources
/**
* @dataProvider resourceProvider
*/
public function testRessources(SplFileInfo $testDirectory)
{
// 1. Cleanup generated
$filesystem = new Filesystem();
if ($filesystem->exists($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated')) {
$filesystem->remove($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
}
$filesystem->mkdir($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
// 2. Generate
$OpenApi = JaneOpenApi::build();
$files = $OpenApi->generate($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'swagger.json', 'Joli\\Jane\\OpenApi\\Tests\\Expected', $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
$OpenApi->printFiles($files, $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
// 3. Compare
$expectedFinder = new Finder();
$expectedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'expected');
$generatedFinder = new Finder();
$generatedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
$generatedData = [];
$this->assertEquals(count($expectedFinder), count($generatedFinder));
foreach ($generatedFinder as $generatedFile) {
$generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
}
foreach ($expectedFinder as $expectedFile) {
$this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData);
if ($expectedFile->isFile()) {
$this->assertEquals(file_get_contents($expectedFile->getRealPath()), file_get_contents($generatedData[$expectedFile->getRelativePathname()]));
}
}
}
示例3: getConfigurationNesting
/**
* Get the configuration file nesting path.
*
* @param \Symfony\Component\Finder\SplFileInfo $file
* @return string
*/
protected function getConfigurationNesting(SplFileInfo $file)
{
$directory = dirname($file->getRealPath());
if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR)) {
$tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
}
return $tree;
}
示例4: 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;
}
示例5: getConfigurationNesting
/**
* Get the configuration file nesting path.
*
* @param \Symfony\Component\Finder\SplFileInfo $file
* @return string
*/
private function getConfigurationNesting(SplFileInfo $file)
{
$directory = $this->normalizePath(dirname($file->getRealPath()));
$directory = ltrim($directory, $this->userConfigurationPath);
if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR)) {
$tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
}
return $tree;
}
示例6: prepareFile
protected function prepareFile(SplFileInfo $file)
{
$filePath = $file->getRelativePathname();
if ($file->isDir()) {
$this->newConfig['folders'][] = $filePath;
return;
}
$fileContents = file_get_contents($file->getRealPath());
$this->newConfig['files'][$filePath] = $fileContents;
}
示例7: 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']);
}
示例8: testRessources
/**
* @dataProvider schemaProvider
*/
public function testRessources(SplFileInfo $testDirectory)
{
// 1. Cleanup generated
$filesystem = new Filesystem();
if ($filesystem->exists($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated')) {
$filesystem->remove($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
}
$filesystem->mkdir($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
// 2. Generate
$command = new GenerateCommand();
$inputArray = new ArrayInput(['--config-file' => $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . '.jane'], $command->getDefinition());
$command->execute($inputArray, new NullOutput());
// 3. Compare
$expectedFinder = new Finder();
$expectedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'expected');
$generatedFinder = new Finder();
$generatedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
$generatedData = [];
$this->assertEquals(count($expectedFinder), count($generatedFinder), sprintf('No same number of files for %s', $testDirectory->getRelativePathname()));
foreach ($generatedFinder as $generatedFile) {
$generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
}
foreach ($expectedFinder as $expectedFile) {
$this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData, sprintf('File %s does not exist for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname()));
if ($expectedFile->isFile()) {
$this->assertEquals(file_get_contents($expectedFile->getRealPath()), file_get_contents($generatedData[$expectedFile->getRelativePathname()]), sprintf('File %s does not have the same content for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname()));
}
}
}
示例9: testRessources
/**
* @dataProvider resourceProvider
*/
public function testRessources(SplFileInfo $testDirectory)
{
// 1. Cleanup generated
$filesystem = new Filesystem();
if ($filesystem->exists($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated')) {
$filesystem->remove($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
}
$filesystem->mkdir($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
// 2. Generate
$command = new GenerateCommand();
$input = new ArrayInput(['--config-file' => $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . '.jane-openapi'], $command->getDefinition());
$command->execute($input, new NullOutput());
// 3. Compare
$expectedFinder = new Finder();
$expectedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'expected');
$generatedFinder = new Finder();
$generatedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
$generatedData = [];
$this->assertEquals(count($expectedFinder), count($generatedFinder));
foreach ($generatedFinder as $generatedFile) {
$generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
}
foreach ($expectedFinder as $expectedFile) {
$this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData);
if ($expectedFile->isFile()) {
$expectedPath = $expectedFile->getRealPath();
$actualPath = $generatedData[$expectedFile->getRelativePathname()];
$this->assertEquals(file_get_contents($expectedPath), file_get_contents($actualPath), "Expected " . $expectedPath . " got " . $actualPath);
}
}
}
示例10: 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;
}
示例11: saveFileAction
/**
* @Route("/file_manager/new-file/save", name="spliced_cms_admin_file_manager_save_file")
* @Template("SplicedCmsBundle:Admin/FileManagement:new_file.html.twig")
*/
public function saveFileAction()
{
$view = $this->getViewContext();
$fileForm = $this->createForm(new FileFormType(null), array());
if ($fileForm->submit($this->get('request')) && $fileForm->isValid()) {
$file = $fileForm->getData();
$fileInfo = new \SplFileInfo($this->dir->getRealPath() . '/' . $file['fileName']);
$relativePath = str_replace($this->baseDir->getRealPath(), '', $fileInfo->getPath());
$wrote = file_put_contents($fileInfo->getPath() . '/' . $fileInfo->getFilename(), $file['content']);
if (false === $wrote) {
$this->get('session')->getFlashBag()->add('error', 'There was an error saving the file. Permission Denied');
} else {
return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager_edit_file', array('dir' => $relativePath, 'file' => $fileInfo->getFilename())));
}
} else {
$this->get('session')->getFlashBag()->add('error', 'There was an error validating your submission');
}
return array_merge($view, array('fileForm' => $fileForm->createView()));
}
示例12: registerTheme
/**
* Registers a new theme from a directory.
* @param \Symfony\Component\Finder\SplFileInfo $themeClassPath
*/
protected function registerTheme(SplFileInfo $themeClassPath)
{
$themeName = preg_replace('/Theme\\.php$/', '', $themeClassPath->getFilename());
$themeClass = sprintf('Ladybug\\Theme\\%s\\%sTheme', $themeName, $themeName);
$themePath = dirname($themeClassPath->getRealPath());
$this->container->register('theme_' . $themeName, $themeClass)->addArgument($themePath)->addTag('ladybug.theme');
}
示例13: getReversePathParts
/**
* @return string
*/
protected function getReversePathParts()
{
$path = trim($this->file->getRealPath(), DIRECTORY_SEPARATOR);
$reversePath = implode(DIRECTORY_SEPARATOR, array_reverse(explode(DIRECTORY_SEPARATOR, $path)));
return explode('content', $reversePath, 2);
}
示例14: getConfigurationNesting
/**
* Get the configuration file nesting path.
*
* @param \Symfony\Component\Finder\SplFileInfo $file
*
* @return string
*/
private function getConfigurationNesting(SplFileInfo $file)
{
$directory = dirname($file->getRealPath());
$configPath = realpath($this->configPath());
if ($tree = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) {
$tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
}
return $tree;
}
示例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;
}