Skip to content

Commit

Permalink
Added support to new configuration system
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyiegorov committed Jan 10, 2015
1 parent 302e519 commit e379286
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
namespace samson\fs;

use samson\core\CompressableService;
use samson\core\Config;
use samson\core\Event;
use samsonos\config\Entity;

/**
* File system module controller
* @package samson\fs
*/
class FileService extends CompressableService implements IFileSystem
class FileService extends CompressableService implements IFileSystem, \samsonos\config\IConfigurable
{
/** @var string Module identifier */
protected $id = 'fs';
Expand All @@ -38,30 +39,42 @@ public function init(array $params = array())
// If defined file service is not supported
if (!class_exists($this->fileServiceClassName)) {
// Signal error
return e(
'Cannot initialize file system adapter[##], class is not found',
E_SAMSON_CORE_ERROR,
$this->fileServiceClassName
Event::fire(
'error',
array(
$this,
'Cannot initialize file system adapter['.$this->fileServiceClassName.']'
)
);
} else { /** @var \samson\fs\AbstractFileService Create file service instance */
} else {
/** @var \samson\fs\AbstractFileService Create file service instance */
$this->fileService = new $this->fileServiceClassName();
}

//[PHPCOMPRESSOR(remove,start)]
// Store configuration parameters to local field for compression
// in compressed version this will be loaded from serialized data
$this->configuration = & Config::$data[$this->id];
//[PHPCOMPRESSOR(remove,end)]

// Configure file service instance with this service config
Config::implement($this->id, $this->fileService, $this->configuration);
// Set nested file service instance parameters
foreach ($this->configuration as $key => $value) {
$this->fileService->$key = $value;
}

// Initialize file service
$this->fileService->initialize();
// Initialize file service
$this->fileService->initialize();
}

// Call parent initialization
return parent::init($params);
}

//[PHPCOMPRESSOR(remove,start)]
/**
* @param Entity $entityConfiguration current instance for configuration
* @return boolean False if something went wrong otherwise true
*/
public function configure(Entity $entityConfiguration)
{
// Convert object to array
$this->configuration = (array)$entityConfiguration;
}
//[PHPCOMPRESSOR(remove,end)]

/**
* Write data to a specific relative location
*
Expand Down

0 comments on commit e379286

Please sign in to comment.