本文整理汇总了PHP中League\Flysystem\Filesystem::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::get方法的具体用法?PHP Filesystem::get怎么用?PHP Filesystem::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadAttachment
/**
* @param $filePath
* @param $toBeDownloadedFileName
*
* @return int
*/
public function downloadAttachment($filePath, $toBeDownloadedFileName = '')
{
if (!is_readable($this->currentPath . $filePath)) {
$this->setError(self::ERROR_ATTACHMENT_FILE_DOES_NOT_EXIST);
}
if (empty($toBeDownloadedFileName)) {
$toBeDownloadedFileName = basename($filePath);
if (empty($toBeDownloadedFileName)) {
$this->setError(self::ERROR_ATTACHMENT_DOES_NOT_EXIST);
}
}
if ($this->hasError()) {
return $this->errors;
}
$this->setHeadersForAttachmentDownload($toBeDownloadedFileName);
if ($this->fileSystem->getSize($filePath) > DirectoryStructure::FS_DOWNLOAD_STREAM_AFTER_SIZE) {
header('Content-Length: ' . $this->fileSystem->getSize($filePath));
$stream = $this->fileSystem->readStream($filePath);
while (!feof($stream)) {
print fgets($stream, 1024);
flush();
}
fclose($stream);
exit;
} else {
ob_start();
ob_start("ob_gzhandler");
echo $this->fileSystem->get($filePath)->read();
ob_end_flush();
$gzippedContent = ob_get_contents();
// store gzipped content to get size
header('Content-Length: ' . strlen($gzippedContent));
ob_end_flush();
exit;
}
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument("file");
$list = array_filter($this->filesystem->listContents($file, true), function ($file) {
return isset($file['type']) and ($file['type'] === "file" and isset($file['extension']) and $file['extension'] === "php");
});
// If the file argument is not directory, the listContents will return empty array.
// In this case the user has specified a file
if (empty($list)) {
$list = [["path" => $this->filesystem->get($file)->getPath()]];
}
$dump = array_map(function ($file) use($output) {
$output->writeln("Indexing " . $file['path'] . "...");
return Indexer::index($this->filesystem->get($file['path']));
}, $list);
$table = new Table($output);
$outputs = [];
foreach ($dump as $a) {
foreach ($a["functions"] as $val) {
$outputs[] = [$val['file']->getPath(), $val['function'], implode(", ", array_map(function ($param) {
return implode('|', $param['type']) . " " . $param['name'];
}, $val['arguments'])), implode(", ", $val['return']), (string) $val['scope']];
}
}
$output->writeln("Indexing complete!");
$output->writeln("Scanned " . count($list) . " files.");
$output->writeln("Detected " . count($outputs) . " functions.");
$output->writeln("Rendering Table...");
$table->setHeaders(['File', 'Function', 'Arguments', 'Return', 'Scope'])->setRows($outputs);
$table->render();
}
示例3: retrieveVersion
public function retrieveVersion(Versionable $versionable, Version $version)
{
$ret = $this->filesystem->get($this->getVersionPathName($versionable, $version));
if (!$ret) {
throw new FileIOException(sprintf("Failed to retrieve version '%s' of versionable %s;%s", $version->toString(), get_class($versionable), $versionable->getId()));
}
return new Retrieved($this->tempFiles->add($ret->read()));
}
示例4: getFile
/**
* Returns file handle from OC
* @param $path
*
* @return bool|File
*/
public function getFile($path)
{
$file = $this->fs->get($path);
if ($file instanceof File) {
return $file;
}
return false;
}
示例5: load
public function load()
{
$composer = json_decode($this->filesystem->get('composer.json')->read(), true);
if (!isset($composer['autoload']['psr-4']) || empty($composer['autoload']['psr-4'])) {
throw new RuntimeException('Unable to detect namespace. Ensure you have PSR4 autoloading setup in your composer.json');
}
$namespace = array_keys($composer['autoload']['psr-4'])[0];
$path = $composer['autoload']['psr-4'][$namespace];
$this->namespace = Utils::removeTrailingSlashes($namespace);
$this->path = Utils::removeTrailingSlashes($path);
}
示例6: getFileOrFail
/**
* Checks if the underlying flysystem contains a file of the given name.
*
* @param string $name
*
* @return \League\Flysystem\File|\League\Flysystem\Handler
* @throws Twig_Error_Loader
*/
protected function getFileOrFail($name)
{
if (!$this->filesystem->has($this->resolveTemplateName($name))) {
throw new Twig_Error_Loader('Template could not be found on the given filesystem');
}
$fileObject = $this->filesystem->get($this->resolveTemplateName($name));
if ($fileObject->isDir()) {
throw new Twig_Error_Loader('Cannot use directory as template');
}
return $fileObject;
}
示例7: writeToFile
/**
* @return bool
*/
private function writeToFile()
{
$this->filesystem->write($this->file, $this->template);
$this->out->writeln("Written endpoint wrapper to :" . $this->filesystem->get($this->file)->getPath());
$this->out->writeln("Class " . $this->className . " is generated");
return $this;
}
示例8: testGetDirectory
public function testGetDirectory()
{
$path = 'path';
$this->prophecy->has($path)->willReturn(true);
$this->prophecy->getMetadata($path)->willReturn(['path' => $path, 'type' => 'dir']);
$output = $this->filesystem->get($path);
$this->assertInstanceOf('League\\Flysystem\\Directory', $output);
}
示例9: upload
public function upload(FileInterface $file, $name, $path = null)
{
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
if ($file instanceof FlysystemFile) {
if ($file->getFilesystem() == $this->filesystem) {
$file->getFilesystem()->rename($file->getPath(), $path);
return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
}
$this->filesystem->put($name, file_get_contents($file));
if ($file instanceof FlysystemFile) {
$file->delete();
} else {
$filesystem = new LocalFilesystem();
$filesystem->remove($file->getPathname());
}
return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
示例10: upload
public function upload(FileInterface $file, $name, $path = null)
{
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
if ($file instanceof FlysystemFile) {
if ($file->getFilesystem() == $this->filesystem) {
$file->getFilesystem()->rename($file->getPath(), $path);
return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
}
$stream = fopen($file->getPathname(), 'r+');
$this->filesystem->putStream($name, $stream);
if (is_resource($stream)) {
fclose($stream);
}
if ($file instanceof FlysystemFile) {
$file->delete();
} else {
$filesystem = new LocalFilesystem();
$filesystem->remove($file->getPathname());
}
return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
示例11: assembleChunks
public function assembleChunks($chunks, $removeChunk, $renameChunk)
{
// the index is only added to be in sync with the filesystem storage
$path = $this->prefix . '/' . $this->unhandledChunk['uuid'] . '/';
$filename = $this->unhandledChunk['index'] . '_' . $this->unhandledChunk['original'];
if (empty($chunks)) {
$target = $filename;
} else {
sort($chunks, SORT_STRING | SORT_FLAG_CASE);
$target = pathinfo($chunks[0], PATHINFO_BASENAME);
}
if ($this->unhandledChunk['index'] === 0) {
// if it's the first chunk overwrite the already existing part
// to avoid appending to earlier failed uploads
$handle = fopen($path . '/' . $target, 'w');
} else {
$handle = fopen($path . '/' . $target, 'a');
}
$this->filesystem->putStream($path . $target, $handle);
if ($renameChunk) {
$name = preg_replace('/^(\\d+)_/', '', $target);
/* The name can only match if the same user in the same session is
* trying to upload a file under the same name AND the previous upload failed,
* somewhere between this function, and the cleanup call. If that happened
* the previous file is unaccessible by the user, but if it is not removed
* it will block the user from trying to re-upload it.
*/
if ($this->filesystem->has($path . $name)) {
$this->filesystem->delete($path . $name);
}
$this->filesystem->rename($path . $target, $path . $name);
$target = $name;
}
$uploaded = $this->filesystem->get($path . $target);
if (!$renameChunk) {
return $uploaded;
}
return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
}
示例12: get
/**
* {@inheritDoc}
*/
public function get($path, Handler $handler = null)
{
return parent::get($path, new File($this, $path));
}
示例13: isFile
/** @inheritDoc */
public function isFile($path)
{
$path = $this->getInternalPath($path);
return $this->fs->has($path) && $this->fs->get($path)->isFile();
}
示例14: get
/**
* @inheritdoc
*/
public function get($path, Handler $handler = null)
{
return $this->fileSystem->get($this->getInnerPath($path), $handler);
}
示例15: Local
<?php
require __DIR__ . "/vendor/autoload.php";
use Elphp\Component\DocTypeParser\DocParamTypeParser;
use Elphp\Component\Indexer\BasicFunctionIndexer;
use Elphp\Component\Indexer\BasicVariableIndexer;
use Elphp\Component\Indexer\ScopeResolvedNodes;
use Elphp\Component\ScopeResolver\NodeVisitor\ScopeResolver;
use PhpParser\Comment;
use PhpParser\Error;
use PhpParser\Node;
use phpDocumentor\Reflection\DocBlock;
use PhpParser\Node\FunctionLike;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
$adapter = new Local(__DIR__ . '/');
$filesystem = new Filesystem($adapter);
$lexer = new PhpParser\Lexer(array('usedAttributes' => array('comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos')));
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, $lexer);
$traverser = new NodeTraverser();
$traverser->addVisitor(new ScopeResolver());
$file = $filesystem->get("code.php");
$code = $file->read();
$stmts = $parser->parse($code);
$stmts = $traverser->traverse($stmts);
var_dump((new BasicVariableIndexer($file, new ScopeResolvedNodes($stmts)))->index()->getArrayCopy());