コード例 #1
0
 private static function infoToJson(FileSystemInfo $info)
 {
     $isDir = $info instanceof DirectoryInfo;
     $virtualPath = Path::getVirtualPath($info->getFullName(), Config::getRootDir());
     $json = array('name' => $info->getName(), 'path' => strlen($virtualPath) > 1 ? rtrim($virtualPath, '/') : $virtualPath, 'size' => $isDir ? 0 : $info->getSize(), 'last_access_time' => DateTimeUtils::toString($info->getLastAccessTime()), 'last_write_time' => DateTimeUtils::toString($info->getLastWriteTime()), 'is_dir' => $isDir);
     return $json;
 }
コード例 #2
0
 public function getMetadata(Application $app, Request $request, $path)
 {
     $realPath = Path::getRealPath($path, Config::getRootDir());
     if (!Path::exists($realPath)) {
         return new Response('', Response::HTTP_NOT_FOUND);
     }
     if ($request->getMethod() === 'HEAD') {
         return new Response('', Response::HTTP_OK);
     }
     $lastWriteTime = $response = $this->getLastWriteTime($app, $realPath);
     if (($response = $this->hasCachedResponse($request, $lastWriteTime)) !== false) {
         return $response;
     }
     $searchOptions = $request->query->getBoolean('contents') ? FileSystemInfoSerializer::TOP_DIRECTORY_ONLY : FileSystemInfoSerializer::WITHOUT_CONTENT;
     $info = Path::getInfo($realPath);
     $json = FileSystemInfoSerializer::toJson($info, $searchOptions);
     $response = $app->json($json);
     $response->setLastModified($lastWriteTime);
     $response->setPublic();
     return $response;
 }
コード例 #3
0
ファイル: FilesController.php プロジェクト: vbessonov/fsrapi
 public function putFile(Application $app, Request $request, $path)
 {
     $realPath = Path::getRealPath($path, Config::getRootDir());
     if (Path::exists($realPath) && Path::isDir($realPath)) {
         return $this->createResponse(Response::HTTP_BAD_REQUEST, "Directory '{$path}' already exists");
     }
     if ($request->query->getBoolean('is_dir') || $request->request->getBoolean('is_dir')) {
         if (Path::exists($realPath)) {
             return $this->createResponse(Response::HTTP_BAD_REQUEST, "Directory '{$path}' already exists");
         }
         mkdir($realPath);
     } else {
         $content = $request->getContent(true);
         if (!is_resource($content)) {
             return $this->createResponse(Response::HTTP_BAD_REQUEST, "Request has incorrect body");
         }
         $resourceType = get_resource_type($content);
         if ($resourceType != 'stream') {
             return $this->createResponse(Response::HTTP_BAD_REQUEST, "Request has incorrect body");
         }
         $newFile = fopen($realPath, 'w');
         try {
             stream_copy_to_stream($content, $newFile);
         } finally {
             fclose($newFile);
         }
     }
     $info = Path::getInfo($realPath);
     $app['fsrapi.cache']->setTimestampForInfo($info, $info->getLastWriteTime());
     $response = new Response();
     $response->headers->addCacheControlDirective('no-cache', true);
     $response->headers->addCacheControlDirective('no-store', true);
     return $response;
 }
コード例 #4
0
ファイル: FileSystemCache.php プロジェクト: vbessonov/fsrapi
 public function setTimestamp($path, $timestamp = 0)
 {
     $this->setTimestampForInfo(Path::getInfo($path), $timestamp);
 }
コード例 #5
0
ファイル: FileInfoTest.php プロジェクト: vbessonov/fsrapi
 protected function getTestPath()
 {
     return Path::combine(self::TEST_DIRECTORY, 'newfile');
 }
コード例 #6
0
ファイル: PathTest.php プロジェクト: vbessonov/fsrapi
 public function testIsDir()
 {
     $this->assertTrue(Path::isDir(__DIR__));
     $this->assertFalse(Path::isDir(__FILE__));
 }
コード例 #7
0
ファイル: UserController.php プロジェクト: vbessonov/fsrapi
 public function postIndex(Application $app, Request $request, $path)
 {
     $subRequest = null;
     $response = null;
     if ($request->request->has('createDirectory') && $request->request->has('directoryName')) {
         $directoryName = $request->request->get('directoryName');
         list($subRequest, $response) = $this->createDirectory($app, Path::combine($path, $directoryName));
     } else {
         if ($request->request->get('createFile') && $request->files->count() > 0) {
             $files = $request->files->all();
             $file = $files['userfile'];
             list($subRequest, $response) = $this->createFile($app, $path, $file);
         } else {
             if ($request->request->count() > 0) {
                 foreach ($request->request->keys() as $key) {
                     $matches = array();
                     if (preg_match('/^delete_(.+)$/', $key, $matches)) {
                         $fileName = str_replace('#', '.', $matches[1]);
                         list($subRequest, $response) = $this->deleteFile($app, $fileName);
                         break;
                     }
                 }
             }
         }
     }
     if (null !== $response) {
         $reflectionClass = new ReflectionClass(get_class($response));
         $statusTextProperty = $reflectionClass->getProperty('statusText');
         $statusTextProperty->setAccessible(true);
         $statusCode = $response->getStatusCode();
         $statusText = $statusTextProperty->getValue($response);
         $app['session']->set('response', array('method' => $subRequest->getMethod(), 'uri' => $subRequest->getUri(), 'status_code' => $statusCode, 'status_text' => $statusText));
     }
     $url = $request->getUriForPath('/');
     //        $subRequest = Request::create(
     //            $url,
     //            'GET',
     //            array(),
     //            $request->cookies->all(),
     //            array(), $request->server->all()
     //        );
     //        return $app->handle($subRequest, HttpKernelInterface::MASTER_REQUEST);
     return $app->redirect($url);
     //        return new \Symfony\Component\HttpFoundation\Response();
 }