mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/15287] Update storage
PHPBB3-15287
This commit is contained in:
parent
51d42b2ced
commit
af21b8b6c1
6 changed files with 126 additions and 5 deletions
|
@ -15,6 +15,13 @@ namespace phpbb\storage\adapter;
|
||||||
|
|
||||||
interface adapter_interface
|
interface adapter_interface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Set adapter parameters
|
||||||
|
*
|
||||||
|
* @param array options Storage-specific options.
|
||||||
|
*/
|
||||||
|
public function configure($options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dumps content into a file.
|
* Dumps content into a file.
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,7 +15,6 @@ namespace phpbb\storage\adapter;
|
||||||
|
|
||||||
use phpbb\storage\exception\exception;
|
use phpbb\storage\exception\exception;
|
||||||
use phpbb\filesystem\exception\filesystem_exception;
|
use phpbb\filesystem\exception\filesystem_exception;
|
||||||
use phpbb\config\config;
|
|
||||||
use phpbb\filesystem\filesystem;
|
use phpbb\filesystem\filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,16 +29,27 @@ class local implements adapter_interface
|
||||||
*/
|
*/
|
||||||
protected $filesystem;
|
protected $filesystem;
|
||||||
|
|
||||||
|
/** @var string path */
|
||||||
|
protected $phpbb_root_path;
|
||||||
|
|
||||||
/** @var string path */
|
/** @var string path */
|
||||||
protected $root_path;
|
protected $root_path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct(config $config, filesystem $filesystem, $phpbb_root_path, $path_key)
|
public function __construct(filesystem $filesystem, $phpbb_root_path)
|
||||||
{
|
{
|
||||||
$this->filesystem = $filesystem;
|
$this->filesystem = $filesystem;
|
||||||
$this->root_path = $phpbb_root_path . $config[$path_key];
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function configure($options)
|
||||||
|
{
|
||||||
|
$this->root_path = $this->phpbb_root_path . $options['path'];
|
||||||
|
|
||||||
if (substr($this->root_path, -1, 1) != DIRECTORY_SEPARATOR)
|
if (substr($this->root_path, -1, 1) != DIRECTORY_SEPARATOR)
|
||||||
{
|
{
|
||||||
|
|
57
phpBB/phpbb/storage/adapter_factory.php
Normal file
57
phpBB/phpbb/storage/adapter_factory.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\storage;
|
||||||
|
|
||||||
|
use phpbb\config\config;
|
||||||
|
use phpbb\di\service_collection;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
class adapter_factory
|
||||||
|
{
|
||||||
|
protected $config;
|
||||||
|
protected $container;
|
||||||
|
protected $adapters;
|
||||||
|
protected $providers;
|
||||||
|
|
||||||
|
public function __construct(config $config, ContainerInterface $container, service_collection $adapters, service_collection $providers)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
$this->container = $container;
|
||||||
|
$this->adapters = $adapters;
|
||||||
|
$this->providers = $providers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($storage_name)
|
||||||
|
{
|
||||||
|
$provider_class = $this->config['storage\\' . $storage_name . '\\adapter'];
|
||||||
|
$provider = $this->providers->get_by_class($provider_class);
|
||||||
|
|
||||||
|
$adapter = $this->adapters->get_by_class($provider->get_class());
|
||||||
|
$adapter->configure($this->build_options($storage_name, $provider->get_options()));
|
||||||
|
|
||||||
|
return $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function build_options($storage_name, array $definitions)
|
||||||
|
{
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
foreach ($definitions as $def)
|
||||||
|
{
|
||||||
|
$options[$def] = $this->config['storage\\' . $storage_name . '\\config\\' . $def];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
}
|
27
phpBB/phpbb/storage/provider/local.php
Normal file
27
phpBB/phpbb/storage/provider/local.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\storage\provider;
|
||||||
|
|
||||||
|
class local implements provider_interface
|
||||||
|
{
|
||||||
|
public function get_class()
|
||||||
|
{
|
||||||
|
return \phpbb\storage\adapter\local::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_options()
|
||||||
|
{
|
||||||
|
return ['path'];
|
||||||
|
}
|
||||||
|
}
|
20
phpBB/phpbb/storage/provider/provider_interface.php
Normal file
20
phpBB/phpbb/storage/provider/provider_interface.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\storage\provider;
|
||||||
|
|
||||||
|
interface provider_interface
|
||||||
|
{
|
||||||
|
public function get_class();
|
||||||
|
public function get_options();
|
||||||
|
}
|
|
@ -20,9 +20,9 @@ class storage
|
||||||
{
|
{
|
||||||
protected $adapter;
|
protected $adapter;
|
||||||
|
|
||||||
public function __construct($adapter)
|
public function __construct($factory, $storage_name)
|
||||||
{
|
{
|
||||||
$this->adapter = $adapter;
|
$this->adapter = $factory->get($storage_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function put_contents($path, $content)
|
public function put_contents($path, $content)
|
||||||
|
|
Loading…
Add table
Reference in a new issue