Skip to content

Commit

Permalink
Adapt filesystem code to new aimeos-base package
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Feb 16, 2022
1 parent d706278 commit 8302e20
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2015-2022
* @package MW
* @package Base
* @subpackage Filesystem
*/


namespace Aimeos\MW\Filesystem;
namespace Aimeos\Base\Filesystem;


/**
* Implementation of Laravel file system adapter
*
* @package MW
* @package Base
* @subpackage Filesystem
*/
class Laravel implements Iface, DirIface, MetaIface
Expand All @@ -41,7 +41,7 @@ public function __construct( \Illuminate\Contracts\Filesystem\Filesystem $fs, $t
*
* @param string $path Path to the file or directory
* @return bool True if directory, false if not
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function isdir( string $path ) : bool
{
Expand All @@ -53,8 +53,8 @@ public function isdir( string $path ) : bool
* Creates a new directory for the given path
*
* @param string $path Path to the directory
* @return \Aimeos\MW\Filesystem\DirIface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\DirIface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function mkdir( string $path ) : DirIface
{
Expand All @@ -72,8 +72,8 @@ public function mkdir( string $path ) : DirIface
* Deletes the directory for the given path
*
* @param string $path Path to the directory
* @return \Aimeos\MW\Filesystem\DirIface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\DirIface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function rmdir( string $path ) : DirIface
{
Expand All @@ -94,7 +94,7 @@ public function rmdir( string $path ) : DirIface
*
* @param string $path Path to the filesystem or directory
* @return iterable Iterator over the entries or array with entries
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function scan( string $path = null ) : iterable
{
Expand All @@ -111,7 +111,7 @@ public function scan( string $path = null ) : iterable
*
* @param string $path Path to the file
* @return integer Size in bytes
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function size( string $path ) : int
{
Expand All @@ -128,7 +128,7 @@ public function size( string $path ) : int
*
* @param string $path Path to the file
* @return integer Unix time stamp in seconds
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function time( string $path ) : int
{
Expand All @@ -144,8 +144,8 @@ public function time( string $path ) : int
* Deletes the file for the given path
*
* @param string $path Path to the file
* @return \Aimeos\MW\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function rm( string $path ) : Iface
{
Expand Down Expand Up @@ -178,7 +178,7 @@ public function has( string $path ) : bool
*
* @param string $path Path to the file
* @return string File content
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function read( string $path ) : string
{
Expand All @@ -195,7 +195,7 @@ public function read( string $path ) : string
*
* @param string $path Path to the remote file
* @return string Path of the local file
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function readf( string $path ) : string
{
Expand All @@ -218,7 +218,7 @@ public function readf( string $path ) : string
*
* @param string $path Path to the file
* @return resource File stream descriptor
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function reads( string $path )
{
Expand Down Expand Up @@ -251,8 +251,8 @@ public function reads( string $path )
*
* @param string $path Path to the file
* @param string $content New file content
* @return \Aimeos\MW\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function write( string $path, string $content ) : Iface
{
Expand All @@ -273,8 +273,8 @@ public function write( string $path, string $content ) : Iface
*
* @param string $path Path to the remote file
* @param string $local Path to the local file
* @return \Aimeos\MW\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function writef( string $path, string $local ) : Iface
{
Expand All @@ -293,8 +293,8 @@ public function writef( string $path, string $local ) : Iface
*
* @param string $path Path to the file
* @param resource $stream File stream descriptor
* @return \Aimeos\MW\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function writes( string $path, $stream ) : Iface
{
Expand All @@ -320,8 +320,8 @@ public function writes( string $path, $stream ) : Iface
*
* @param string $from Path to the original file
* @param string $to Path to the new file
* @return \Aimeos\MW\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function move( string $from, string $to ) : Iface
{
Expand All @@ -340,8 +340,8 @@ public function move( string $from, string $to ) : Iface
*
* @param string $from Path to the original file
* @param string $to Path to the new file
* @return \Aimeos\MW\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\MW\Filesystem\Exception If an error occurs
* @return \Aimeos\Base\Filesystem\Iface Filesystem object for fluent interface
* @throws \Aimeos\Base\Filesystem\Exception If an error occurs
*/
public function copy( string $from, string $to ) : Iface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2015-2022
* @package MW
* @package Base
* @subpackage Filesystem
*/


namespace Aimeos\MW\Filesystem\Manager;
namespace Aimeos\Base\Filesystem\Manager;


/**
* Laravel file system manager
*
* @package MW
* @package Base
* @subpackage Filesystem
*/
class Laravel extends Standard implements Iface
Expand All @@ -28,10 +28,10 @@ class Laravel extends Standard implements Iface
* Initializes the object
*
* @param \Illuminate\Filesystem\FilesystemManager $fsm Laravel file system manager object
* @param \Aimeos\MW\Config\Iface $config Configuration object
* @param array $config Filesystem resource configuration
* @param string $tempdir Directory for storing temporary files
*/
public function __construct( \Illuminate\Filesystem\FilesystemManager $fsm, \Aimeos\MW\Config\Iface $config, $tempdir )
public function __construct( \Illuminate\Filesystem\FilesystemManager $fsm, array $config, $tempdir )
{
parent::__construct( $config );

Expand Down Expand Up @@ -68,17 +68,17 @@ public function __sleep()
* Returns the file system for the given name
*
* @param string $name Key for the file system
* @return \Aimeos\MW\Filesystem\Iface File system object
* @throws \Aimeos\MW\Filesystem\Exception If an no configuration for that name is found
* @return \Aimeos\Base\Filesystem\Iface File system object
* @throws \Aimeos\Base\Filesystem\Exception If an no configuration for that name is found
*/
public function get( string $name ) : \Aimeos\MW\Filesystem\Iface
public function get( string $name ) : \Aimeos\Base\Filesystem\Iface
{
$key = $this->getConfig( $name );

if( is_string( $key ) )
{
if( !isset( $this->objects[$key] ) ) {
$this->objects[$key] = new \Aimeos\MW\Filesystem\Laravel( $this->fsm->disk( $key ), $this->tempdir );
$this->objects[$key] = new \Aimeos\Base\Filesystem\Laravel( $this->fsm->disk( $key ), $this->tempdir );
}

return $this->objects[$key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/


namespace Aimeos\MW\Filesystem;
namespace Aimeos\Base\Filesystem;


class LaravelTest extends \PHPUnit\Framework\TestCase
Expand All @@ -25,7 +25,7 @@ protected function setUp() : void
->disableOriginalConstructor()
->getMock();

$this->object = new \Aimeos\MW\Filesystem\Laravel( $this->mock, sys_get_temp_dir() );
$this->object = new \Aimeos\Base\Filesystem\Laravel( $this->mock, sys_get_temp_dir() );
}


Expand Down Expand Up @@ -66,7 +66,7 @@ public function testMkdirException()
$this->mock->expects( $this->once() )->method( 'makeDirectory' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->mkdir( 'test' );
}

Expand All @@ -84,7 +84,7 @@ public function testRmdirException()
$this->mock->expects( $this->once() )->method( 'deleteDirectory' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->rmdir( 'test' );
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public function testScanException()
$this->mock->expects( $this->once() )->method( 'directories' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->scan( 'test' );
}

Expand All @@ -135,7 +135,7 @@ public function testSizeException()
$this->mock->expects( $this->once() )->method( 'size' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->size( 'test' );
}

Expand All @@ -156,7 +156,7 @@ public function testTimeException()
$this->mock->expects( $this->once() )->method( 'lastModified' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->time( 'test' );
}

Expand All @@ -174,7 +174,7 @@ public function testRmException()
$this->mock->expects( $this->once() )->method( 'delete' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->rm( 'test' );
}

Expand Down Expand Up @@ -217,7 +217,7 @@ public function testReadException()
$this->mock->expects( $this->once() )->method( 'get' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->read( 'readinvalid' );
}

Expand Down Expand Up @@ -253,7 +253,7 @@ public function testReadsException()
$this->mock->expects( $this->once() )->method( 'get' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->reads( 'readinvalid' );
}

Expand All @@ -271,7 +271,7 @@ public function testWriteException()
$this->mock->expects( $this->once() )->method( 'put' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->write( '', 'test' );
}

Expand All @@ -291,7 +291,7 @@ public function testWritef()

public function testWritefException()
{
$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->writef( '', 'invalid' );
}

Expand All @@ -315,14 +315,14 @@ public function testWritesException()

$handle = fopen( __FILE__, 'r' );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->writes( 'file', $handle );
}


public function testWritesException2()
{
$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->writes( 'file', null );
}

Expand All @@ -340,7 +340,7 @@ public function testMoveException()
$this->mock->expects( $this->once() )->method( 'move' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->move( 'file1', 'file2' );
}

Expand All @@ -358,7 +358,7 @@ public function testCopyException()
$this->mock->expects( $this->once() )->method( 'copy' )
->will( $this->throwException( new \RuntimeException() ) );

$this->expectException( \Aimeos\MW\Filesystem\Exception::class );
$this->expectException( \Aimeos\Base\Filesystem\Exception::class );
$this->object->copy( 'file1', 'file2' );
}
}

0 comments on commit 8302e20

Please sign in to comment.