Skip to content

vitalyiegorov/php_fs

 
 

Repository files navigation

#SamsonPHP File service

This module gives abstraction level for working with file system independently of what exact file system is being used.

Latest Stable Version Build Status Code Coverage Code Climate Total Downloads Scrutinizer Code Quality

##Configuration

The main goal is to configure the $fileServiceID service parameter.

This is usually done using SamsonPHP module/service configuration

By default $fileServiceID is set to fs_local - it uses standart local file system service which is implemented by SamsonPHP local file service php_fs_local. This parameter has to be set to file service class name, for example - local file service - samson\fs\LocalFileService, no module/service identifiers or anything else should be used, first namespace separator \ should be avoided too:

  • \samson\fs\LocalFileService - incorrect
  • samson\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 php_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 = 'fs_aws';
}

Usage

To work with this SamsonPHP file service you should get file service instance pointer:

/**@var \samson\fs\FileService $fs Pointer to file service */
$fs = & m('fs');

After this you can use all available methods from IFileService 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('samson\fs\FileService');

All other SamsonPHP modules must and use this file service approach when working with files.

About

SamsonPHP filesystem module

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%