samsonphp / fs
SamsonPHP file system service
Installs: 3 433
Dependents: 5
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- samsonos/php_core: 1.*
Requires (Dev)
- phpunit/phpunit: 4.*
README
#SamsonPHP File service
This module gives abstraction level for working with file system independently of what exact file system is being used.
##Configuration
The main goal is to configure the $fileServiceClassName
service parameter.
This is usually done using SamsonPHP module/service configuration
By default $fileServiceClassName
is set to samsonphp\fs\LocalFileService
- it uses standard local file
system service. This parameter has to be set to file service class name, for example - local file service - samsonphp\fs\LocalFileService
, no module/service identifiers or anything else should be used,
first namespace separator \
should be avoided too:
\samsonphp\fs\LocalFileService
- incorrectsamsonphp\fs\LocalFileService
- correct
When service is initialized it checks if configured file service class is present otherwise fatal error is signaled.
This gives you ability, for example, to quickly change your web-application file system from local file system to Amazon Web Services S3 bucket, which is implemented by SamsonPHP AWS file service fs_aws
. All you have to do is add configuration for this SamsonPHP file service(fs
):
class FileServiceConfig extends \samson\core\Config { /**@var string Configured module/service identifier */ public $__id = 'fs'; /**@var string Set Amazon Web Services as web-application file service using its identifier */ public $fileServiceID = 'samsonphp\fs\AWSFileService'; }
Usage
To work with this SamsonPHP file service you should get file service instance pointer:
/**@var \samsonphp\fs\FileService $fs Pointer to file service */ $fs = & m('fs');
After this you can use all available methods from AbstractFileService
interface, which this SamsonPHP file service(fs
) implements.
All this method call act like a proxy and passes them to currently configured file service(by default php_fs_local
).
Example usage:
if (!$fs->exists(...)) { $fs->write(...); }
Using service in tests
First of all you should create service instance:
// Create instance $this->fileService = new FileService(__DIR__.'../');
In other places called after service creation you should retrieve service object via factory method:
// Get instance using services factory as error will signal other way $this->fileService = \samson\core\Service::getInstance('samsonphp\fs\FileService');
All other SamsonPHP modules must and use this file service approach when working with files.