Example #1
2
 /**
  * @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;
     }
 }
 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();
 }
 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()));
 }
 /**
  * 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;
 }
Example #5
0
 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);
 }
 /**
  * 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;
 }
 /**
  * @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;
 }
 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);
 }
 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);
 }
 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);
 }
 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);
 }
Example #12
0
 /**
  * {@inheritDoc}
  */
 public function get($path, Handler $handler = null)
 {
     return parent::get($path, new File($this, $path));
 }
Example #13
0
 /** @inheritDoc */
 public function isFile($path)
 {
     $path = $this->getInternalPath($path);
     return $this->fs->has($path) && $this->fs->get($path)->isFile();
 }
Example #14
0
 /**
  * @inheritdoc
  */
 public function get($path, Handler $handler = null)
 {
     return $this->fileSystem->get($this->getInnerPath($path), $handler);
 }
Example #15
0
<?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());
Example #16
0
 public function prepare($template, $data = [])
 {
     $template = $this->internal->get($template)->read();
     return $this->engine->render($template, $data);
 }
 /**
  * @test
  */
 public function it_creates_the_license_file()
 {
     $this->generator->make();
     $result = $this->file->get('LICENSE.txt')->exists();
     $this->assertTrue($result);
 }