1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-08 00:25:19 +02:00

[ticket/17279] Get iconify icons from assets folder

PHPBB3-17279
This commit is contained in:
Marc Alexander 2023-12-29 21:26:41 +01:00
parent 5afa5db41f
commit 0c2fa3a065
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
4 changed files with 30 additions and 14 deletions

View File

@ -10,3 +10,4 @@ services:
shared: false shared: false
arguments: arguments:
- '@log' - '@log'
- '%core.root_path%'

View File

@ -20,6 +20,7 @@ services:
shared: false shared: false
arguments: arguments:
- ~ - ~
- '%core.root_path%'
cache.driver: cache.driver:
class: '%cache.driver.class%' class: '%cache.driver.class%'

View File

@ -18,8 +18,8 @@ use phpbb\log\log_interface;
class iconify_bundler class iconify_bundler
{ {
/** @var log_interface */ /** @var string Icons path */
protected $log; protected string $icons_path;
/** @var string[] Icons list */ /** @var string[] Icons list */
protected $icons_list = []; protected $icons_list = [];
@ -28,10 +28,11 @@ class iconify_bundler
* Constructor for iconify bundler * Constructor for iconify bundler
* *
* @param log_interface|null $log Logger * @param log_interface|null $log Logger
* @param string $root_path phpBB root path
*/ */
public function __construct(?log_interface $log) public function __construct(protected ?log_interface $log, string $root_path)
{ {
$this->log = $log; $this->icons_path = $root_path . 'assets/iconify/';
} }
/** /**
@ -206,6 +207,17 @@ class iconify_bundler
return null; return null;
} }
/**
* Get collection path for prefix
*
* @param string $prefix Icon collection prefix
* @return string Icon collection path
*/
protected function get_collection_path(string $prefix): string
{
return $this->icons_path . $prefix . '.json';
}
/** /**
* Load icons date for supplied icons array * Load icons date for supplied icons array
* *
@ -220,7 +232,7 @@ class iconify_bundler
{ {
// Load icon set // Load icon set
$collection = new Collection($prefix); $collection = new Collection($prefix);
$collection_file = Collection::findIconifyCollection($prefix); $collection_file = $this->get_collection_path($prefix);
if (!file_exists($collection_file) || !$collection->loadFromFile($collection_file)) if (!file_exists($collection_file) || !$collection->loadFromFile($collection_file))
{ {
$this->log?->add('critical', ANONYMOUS, '', 'LOG_ICON_COLLECTION_INVALID', false, [$prefix]); $this->log?->add('critical', ANONYMOUS, '', 'LOG_ICON_COLLECTION_INVALID', false, [$prefix]);

View File

@ -23,6 +23,8 @@ class iconify_bundler_test extends \phpbb_test_case
public function setUp(): void public function setUp(): void
{ {
global $phpbb_root_path;
$log = $this->getMockBuilder('\phpbb\log\dummy') $log = $this->getMockBuilder('\phpbb\log\dummy')
->onlyMethods(['add']) ->onlyMethods(['add'])
->getMock(); ->getMock();
@ -31,7 +33,7 @@ class iconify_bundler_test extends \phpbb_test_case
$this->log_content[] = $log_operation; $this->log_content[] = $log_operation;
}); });
$this->bundler = new \phpbb\assets\iconify_bundler($log); $this->bundler = new \phpbb\assets\iconify_bundler($log, $phpbb_root_path);
} }
public function data_test_generate_bundle() public function data_test_generate_bundle()
@ -42,8 +44,8 @@ class iconify_bundler_test extends \phpbb_test_case
['"prefix":"fa"', '"address-card-o"'], ['"prefix":"fa"', '"address-card-o"'],
], ],
[ [
['fa:address-card-o', 'fa-regular:credit-card'], ['fa:address-card-o', 'ic:baseline-credit-card'],
['"prefix":"fa"', '"address-card-o"', '"prefix":"fa-regular"', '"credit-card"'], ['"prefix":"fa"', '"address-card-o"', '"prefix":"ic"', '"baseline-credit-card"'],
], ],
[ [
['fa:address-card-o', 'fa:foo-bar'], ['fa:address-card-o', 'fa:foo-bar'],
@ -51,16 +53,16 @@ class iconify_bundler_test extends \phpbb_test_case
['LOG_ICON_INVALID'], ['LOG_ICON_INVALID'],
], ],
[ [
['fa:address-card-o', 'fa-regular:credit-card', 'fa-regular:credit-card'], ['fa:address-card-o', 'ic:baseline-credit-card', 'ic:baseline-credit-card'],
['"prefix":"fa"', '"address-card-o"', '"prefix":"fa-regular"', '"credit-card"'], ['"prefix":"fa"', '"address-card-o"', '"prefix":"ic"', '"baseline-credit-card"'],
], ],
[ [
['fa:address-card-o', 'fa-regular:credit-card', 'fa-regular:angry'], ['fa:address-card-o', 'ic:baseline-credit-card', 'ic:baseline-add-ic-call'],
['"prefix":"fa"', '"address-card-o"', '"prefix":"fa-regular"', '"credit-card"', '"angry"'], ['"prefix":"fa"', '"address-card-o"', '"prefix":"ic"', '"baseline-credit-card"', '"baseline-add-ic-call"'],
], ],
[ [
['fa:address-card-o', 'fa:bell', 'fa-regular:credit-card', 'fa-regular:angry'], ['fa:address-card-o', 'fa:bell', 'ic:baseline-credit-card', 'ic:baseline-add-ic-call'],
['"prefix":"fa"', '"address-card-o"', '"bell"', '"prefix":"fa-regular"', '"credit-card"', '"angry"'], ['"prefix":"fa"', '"address-card-o"', '"bell"', '"prefix":"ic"', '"baseline-credit-card"', '"baseline-add-ic-call"'],
], ],
[ [
['@test'], ['@test'],