Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
components
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
components
Merge requests
!36
Draft: Issue
#2707849
by Wim Leers, COBadger: Allow components to define asset libraries
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Issue
#2707849
by Wim Leers, COBadger: Allow components to define asset libraries
issue/components-2707849:2707849-allow-components-to
into
3.x
Overview
0
Commits
1
Pipelines
0
Changes
5
Open
Rob Loach
requested to merge
issue/components-2707849:2707849-allow-components-to
into
3.x
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
5
Expand
Closes
#2707849
0
0
Merge request reports
Compare
3.x
3.x (HEAD)
and
latest version
latest version
846b4748
1 commit,
1 year ago
5 files
+
458
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
src/Component/Discovery/DirectoryWithYamlDiscovery.php
0 → 100644
+
89
−
0
Options
<?php
namespace
Drupal\components\Component\Discovery
;
use
Drupal\Component\Discovery\YamlDirectoryDiscovery
;
/**
* Discovers directories each with one YAML file in a set of directories.
*
* @todo Move into Drupal\Component\Discovery namespace in core.
*/
class
DirectoryWithYamlDiscovery
extends
YamlDirectoryDiscovery
{
/**
* The subdirectory to scan.
*
* @var string
*/
protected
$subdirectory
;
/**
* Constructs a DirectoryWithYamlDiscovery object.
*
* @param array $directories
* An array of directories to scan, keyed by the provider. The value can
* either be a string or an array of strings. The string values should be
* the path of a directory to scan.
* @param string $subdirectory
* The subdirectory to scan in each of the passed $directories.
*/
public
function
__construct
(
array
$directories
,
$subdirectory
)
{
parent
::
__construct
(
$directories
,
'directory_with_yaml:'
.
$subdirectory
);
$this
->
subdirectory
=
$subdirectory
;
}
/**
* {@inheritdoc}
*/
protected
function
getIdentifier
(
$file
,
array
$data
)
{
return
basename
(
$data
[
static
::
FILE_KEY
],
'.yml'
);
}
/**
* Returns an array of providers keyed by file path.
*
* @return array
* An array of providers keyed by file path.
*/
protected
function
findFiles
()
{
$file_list
=
[];
foreach
(
$this
->
directories
as
$provider
=>
$directories
)
{
$directories
=
(
array
)
$directories
;
foreach
(
$directories
as
$directory
)
{
// Check if there is a subdirectory with the specified name.
if
(
is_dir
(
$directory
)
&&
is_dir
(
$directory
.
'/'
.
$this
->
subdirectory
))
{
// Now iterate over all subdirectories below the specifically named
// subdirectory, and check if a .yml file exists with the same name.
// For example:
// - Assuming $this->subdirectory === 'fancy'
// - Then this checks for 'fancy/foo/foo.yml', 'fancy/bar/bar.yml'
$iterator
=
new
\FilesystemIterator
(
$directory
.
'/'
.
$this
->
subdirectory
);
/** @var \SplFileInfo $file_info */
foreach
(
$iterator
as
$file_info
)
{
if
(
$file_info
->
isDir
())
{
$this
->
findFile
(
$file_info
,
$provider
,
$file_list
);
// Allow for two levels.
$nested_iterator
=
new
\FilesystemIterator
(
$directory
.
'/'
.
$this
->
subdirectory
.
'/'
.
$file_info
->
getBasename
());
foreach
(
$nested_iterator
as
$nested_file_info
)
{
if
(
$nested_file_info
->
isDir
())
{
$this
->
findFile
(
$nested_file_info
,
$provider
,
$file_list
);
}
}
}
}
}
}
}
return
$file_list
;
}
protected
function
findFile
(
$file_info
,
$provider
,
array
&
$file_list
)
{
$yml_file_in_directory
=
$file_info
->
getPath
()
.
'/'
.
$file_info
->
getBasename
()
.
'/'
.
$file_info
->
getBasename
()
.
'.yml'
;
if
(
is_file
(
$yml_file_in_directory
))
{
$file_list
[
$yml_file_in_directory
]
=
$provider
;
}
}
}
\ No newline at end of file
Loading