本文整理汇总了PHP中Symfony\Component\Finder\SplFileInfo::getContents方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getContents方法的具体用法?PHP SplFileInfo::getContents怎么用?PHP SplFileInfo::getContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* @return string
*/
public function read()
{
if ($this->contents) {
return $this->contents;
}
return $this->contents = $this->file->getContents();
}
示例2: getFileContent
/**
* Get the content of the file after rendering.
*
* @param SplFileInfo $file
*
* @return string
*/
protected function getFileContent()
{
if (ends_with($this->file->getFilename(), '.blade.php')) {
return $this->renderBlade();
} elseif (ends_with($this->file->getFilename(), '.md')) {
return $this->renderMarkdown();
}
return $this->file->getContents();
}
示例3: detectSystem
/**
* try to verify a search result
*
* @param SplFileInfo $file file to examine
*
* @return bool|System
*/
public function detectSystem(SplFileInfo $file)
{
if ($file->getFilename() == "system.info" && stripos($file->getContents(), 'project = "drupal"') !== false) {
$path = new \SplFileInfo(dirname(dirname($file->getPath())));
return new System($this->getName(), $path);
}
if ($file->getFilename() == "system.info.yml" && stripos($file->getContents(), "project: 'drupal'") !== false) {
$path = new \SplFileInfo(dirname(dirname(dirname($file->getPath()))));
return new System($this->getName(), $path);
}
return false;
}
示例4: modify
/**
* @see ContentModifierInterface::modify()
*/
public function modify(SplFileInfo $generatedFile, array $data, Inflector $inflector, SplFileInfo $templateFile)
{
$options = $this->resolver->resolve($data);
// retrieve target location
$targetConfigFilepath = $this->resolveTargetFilePath($options['target'], $generatedFile->getPath());
$emBundleDefinition = sprintf('
%s:
type: yml
dir: %s
prefix: %s
alias: %s
', $options['bundle'], $options['relative_schema_directory'], $options['prefix'], $options['alias']);
$configsFile = new SplFileInfo($targetConfigFilepath, '', '');
$configsContent = $configsFile->getContents();
// are configs not already registered ?
if (strpos($configsContent, trim($emBundleDefinition)) !== false) {
$this->logger->debug(sprintf('Config file "%s" is already registered into "%s". Abording.', $generatedFile->getFilename(), $targetConfigFilepath));
return $generatedFile->getContents();
}
$this->filesystem->dumpFile($configsFile->getPathname(), str_replace(sprintf('
entity_managers:
%s:
mappings:', $options['em']), sprintf('
entity_managers:
%s:
mappings:%s', $options['em'], $emBundleDefinition), $configsContent));
$this->logger->info(sprintf('file updated : %s', $configsFile->getPathname()));
return $generatedFile->getContents();
}
示例5: 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;
}
示例6: getFileContents
/**
* @param SplFileInfo $file
*
* @return string
*/
private function getFileContents(SplFileInfo $file)
{
$content = $file->getContents();
if ($file->getExtension() === 'js' && substr($content, -1) !== ';') {
$content .= ';';
}
return $content;
}
示例7: verifyFrontMatterSeparatorExists
/**
* @param SplFileInfo $file
*
* @return void
*
* @throws InvalidContentFile
*/
protected function verifyFrontMatterSeparatorExists(SplFileInfo $file)
{
$content = $file->getContents();
$fileName = $file->getFilename();
if (false === strpos($content, FrontMatter::SEPARATOR)) {
throw new InvalidContentFile("Missing '---' deliminator in " . $fileName);
}
}
示例8: parse
/**
* Parse the contents of the file.
*
* Example:
*
* ---
* title: Title
* date: 2016-07-29
* ---
* Lorem Ipsum.
*
* @throws \RuntimeException
*
* @return $this
*/
public function parse()
{
if ($this->file->isFile()) {
if (!$this->file->isReadable()) {
throw new \RuntimeException('Cannot read file');
}
// parse front matter
preg_match('/' . self::PATTERN . '/s', $this->file->getContents(), $matches);
// if not front matter, set body only
if (!$matches) {
$this->body = $this->file->getContents();
return $this;
}
$this->frontmatter = trim($matches[1]);
$this->body = trim($matches[2]);
}
return $this;
}
示例9: load
/**
* Load and parse data from cache file
*/
public function load()
{
$files = new Filesystem();
if ($files->exists($this->source)) {
$file = new SplFileInfo($this->source, null, null);
return unserialize($file->getContents());
}
return array();
}
示例10: extractRegisterInformation
/**
* @param SplFileInfo $file
*
* @return array
*/
public function extractRegisterInformation(SplFileInfo $file)
{
$content = Yaml::parse($file->getContents());
$result = array('namespace' => $content['namespace'], 'source_dir' => rtrim($file->getPathInfo()->getRealPath(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($content['source_dir'], DIRECTORY_SEPARATOR));
$name = array();
preg_match('#(?P<name>[a-z\\-]*)/?$#i', $file->getPath(), $name);
$key = $name['name'];
$this->moduleList[$key] = $result;
return $result;
}
示例11: parseConfigFile
/**
* Parses a .platform.app.yaml file.
*
* @param \Symfony\Component\Finder\SplFileInfo $configFile
* The file to parse.
*
* @return array|null
* An array of configurations found in the file or null.
*/
private function parseConfigFile(SplFileInfo $configFile)
{
$yaml = new Parser();
try {
return $yaml->parse($configFile->getContents());
} catch (ParseException $e) {
printf('Unable to parse the platform configuration file: %s', $configFile->getFilename());
}
return null;
}
示例12: editFileAction
/**
* @Route("/file_manager/edit-file", name="spliced_cms_admin_file_manager_edit_file")
* @Template("SplicedCmsBundle:Admin/FileManagement:edit_file.html.twig")
*/
public function editFileAction()
{
$this->loadContext();
if (!$this->file instanceof \SplFileInfo || !$this->file->getRealPath()) {
return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager', array('dir' => $this->baseDir->getRelativePath())));
}
$fileFormData = array('content' => $this->file->getContents());
$fileForm = $this->createForm(new FileFormType($this->file), $fileFormData);
return array_merge($this->getViewContext(), array('fileForm' => $fileForm->createView()));
}
示例13: getVersionFromComposerJson
private function getVersionFromComposerJson($dir)
{
$version = '_._._';
/** @var SplFileInfo $composerFile */
$composerFile = new SplFileInfo($dir . '/composer.json', '', '');
if ($composerFile->isFile()) {
$composerJson = json_decode($composerFile->getContents());
return $composerJson->version;
}
return $version;
}
示例14: detectSystem
/**
* verify a search result by making sure that the file has the correct name and $wp_version is in there
*
* @param SplFileInfo $file file to examine
*
* @return bool|System
*/
public function detectSystem(SplFileInfo $file)
{
if ($file->getFilename() != "version.php") {
return false;
}
if (stripos($file->getContents(), '$wp_version =') === false) {
return false;
}
$path = new \SplFileInfo(dirname($file->getPath()));
return new System($this->getName(), $path);
}
示例15: getComposerObject
/**
* @param $lock
*
* @return mixed
*
* @throws \RunTimeException
*/
private function getComposerObject($lock)
{
if (!is_file($lock)) {
throw new \RuntimeException('Lock file does not exist.');
}
$file = new SplFileInfo($lock, null, null);
$composer = json_decode($file->getContents());
if (null === $composer || !isset($composer->packages)) {
throw new \RuntimeException('Lock file is not valid.');
}
return $composer;
}