-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #784 from oat-sa/release-2.22.0
Release 2.22.0
- Loading branch information
Showing
12 changed files
with
475 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,29 @@ | |
* | ||
*/ | ||
|
||
use oat\oatbox\filesystem\FileSystemService; | ||
use Zend\ServiceManager\ServiceLocatorAwareTrait; | ||
use Zend\ServiceManager\ServiceLocatorAwareInterface; | ||
use League\Flysystem\Filesystem; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
/** | ||
* Represents direxctory for file storage | ||
* | ||
* @access public | ||
* @author Joel Bout, <[email protected]> | ||
* @package tao | ||
*/ | ||
class tao_models_classes_service_StorageDirectory | ||
class tao_models_classes_service_StorageDirectory implements ServiceLocatorAwareInterface | ||
{ | ||
use ServiceLocatorAwareTrait; | ||
|
||
private $id; | ||
|
||
/** | ||
* | ||
* @var core_kernel_fileSystem_FileSystem | ||
*/ | ||
private $fs; | ||
private $relPath; | ||
private $accessProvider; | ||
|
@@ -42,9 +54,11 @@ public function __construct($id, $fs, $path, $provider) { | |
} | ||
|
||
/** | ||
* Returns the absolute path to this directory | ||
* Returned the absolute path to this directory | ||
* Please use read and write to access files | ||
* | ||
* @return string | ||
* @deprecated | ||
*/ | ||
public function getPath() { | ||
return $this->fs->getPath().$this->relPath; | ||
|
@@ -74,6 +88,13 @@ public function isPublic() { | |
return !is_null($this->accessProvider); | ||
} | ||
|
||
/** | ||
* Returns a URL that allows you to access the files in a directory | ||
* preserving the relative paths | ||
* | ||
* @return string | ||
* @throws common_Exception | ||
*/ | ||
public function getPublicAccessUrl() { | ||
if (is_null($this->accessProvider)) { | ||
common_Logger::e('accessss'); | ||
|
@@ -82,4 +103,71 @@ public function getPublicAccessUrl() { | |
return $this->accessProvider->getAccessUrl($this->relPath); | ||
} | ||
|
||
/** | ||
* Return content of file located at $path. Output as string | ||
* | ||
* @param string $path | ||
* @return StreamInterface | ||
*/ | ||
public function read($path) | ||
{ | ||
return $this->getFileSystem()->readStream($this->getRelativePath().$path); | ||
} | ||
|
||
/** | ||
* Return content of file located at $path. Output as stream | ||
* @param $path | ||
* @return \Slim\Http\Stream | ||
*/ | ||
public function readStream($path) | ||
{ | ||
$resource = $this->read($path); | ||
return new \GuzzleHttp\Psr7\Stream($resource); | ||
} | ||
|
||
/** | ||
* Store a file in the directory from resource | ||
* | ||
* @param string $path | ||
* @param mixed $resource | ||
* @return boolean | ||
*/ | ||
public function write($path, $resource) | ||
{ | ||
common_Logger::d('Writting in ' . $this->getRelativePath().$path); | ||
return $this->getFileSystem()->writeStream($this->getRelativePath().$path, $resource); | ||
} | ||
|
||
/** | ||
* Store a file in the directory from stream | ||
* | ||
* @param $path | ||
* @param StreamInterface $stream | ||
* @return bool | ||
* @throws common_Exception | ||
*/ | ||
public function writeStream($path, StreamInterface $stream) | ||
{ | ||
if (!$stream->isReadable()) { | ||
throw new common_Exception('Stream is not readable. Write to filesystem aborted.'); | ||
} | ||
if (!$stream->isSeekable()) { | ||
throw new common_Exception('Stream is not seekable. Write to filesystem aborted.'); | ||
} | ||
$stream->rewind(); | ||
|
||
$resource = GuzzleHttp\Psr7\StreamWrapper::getResource($stream); | ||
if (!is_resource($resource)) { | ||
throw new common_Exception('Unable to create resource from the given stream. Write to filesystem aborted.'); | ||
} | ||
|
||
return $this->write($path, $resource); | ||
} | ||
|
||
/** | ||
* @return Filesystem | ||
*/ | ||
protected function getFileSystem() { | ||
return $this->getServiceLocator()->get(FileSystemService::SERVICE_ID)->getFileSystem($this->fs->getUri()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.