From e3792861f98d8954975078222107074216bc55a1 Mon Sep 17 00:00:00 2001 From: Vitaly Egorov Date: Sat, 10 Jan 2015 18:26:17 +0200 Subject: [PATCH] Added support to new configuration system --- src/FileService.php | 49 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/FileService.php b/src/FileService.php index 019de8d..d242b9a 100644 --- a/src/FileService.php +++ b/src/FileService.php @@ -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'; @@ -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 *