Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
libraries
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
libraries
Commits
42ec6c8d
Commit
42ec6c8d
authored
8 years ago
by
Tobias Zimmermann
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2770983
by tstoeckler: Allow libraries to be symlinked to their
right place.
parent
548f3c2c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/libraries/Locator/StreamLocator.php
+19
-41
19 additions, 41 deletions
src/Plugin/libraries/Locator/StreamLocator.php
with
19 additions
and
41 deletions
src/Plugin/libraries/Locator/StreamLocator.php
+
19
−
41
View file @
42ec6c8d
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
namespace
Drupal\libraries\Plugin\libraries\Locator
;
namespace
Drupal\libraries\Plugin\libraries\Locator
;
use
Drupal\Core\File\FileSystemInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
;
use
Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface
;
use
Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface
;
use
Drupal\libraries\ExternalLibrary\Local\LocatorInterface
;
use
Drupal\libraries\ExternalLibrary\Local\LocatorInterface
;
use
Drupal\libraries\Plugin\MissingPluginConfigurationException
;
use
Drupal\libraries\Plugin\MissingPluginConfigurationException
;
...
@@ -14,8 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
...
@@ -14,8 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
*
* It makes the following assumptions:
* It makes the following assumptions:
* - The library files can be accessed using a specified stream.
* - The library files can be accessed using a specified stream.
* - The stream wrapper is local (i.e. it
returns a proper value in its
* - The stream wrapper is local (i.e. it
is a subclass of
*
realpath() method
).
*
\Drupal\Core\StreamWrapper\LocalStream
).
* - The first component of the file URIs are the library IDs (i.e. file URIs
* - The first component of the file URIs are the library IDs (i.e. file URIs
* are of the form: scheme://library-id/path/to/file/filename).
* are of the form: scheme://library-id/path/to/file/filename).
*
*
...
@@ -26,18 +26,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
...
@@ -26,18 +26,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class
StreamLocator
implements
LocatorInterface
,
ContainerFactoryPluginInterface
{
class
StreamLocator
implements
LocatorInterface
,
ContainerFactoryPluginInterface
{
/**
/**
* The
file system help
er.
* The
stream wrapper manag
er.
*
*
* @var \Drupal\Core\
File\FileSystem
Interface
* @var \Drupal\Core\
StreamWrapper\StreamWrapperManager
Interface
*/
*/
protected
$fileSystemHelper
;
protected
$streamWrapperManager
;
/**
* The app root.
*
* @var string
*/
protected
$appRoot
;
/**
/**
* The scheme of the stream wrapper.
* The scheme of the stream wrapper.
...
@@ -49,16 +42,13 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
...
@@ -49,16 +42,13 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
/**
/**
* Constructs a stream locator.
* Constructs a stream locator.
*
*
* @param \Drupal\Core\File\FileSystemInterface $file_system_helper
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The file system helper.
* The stream wrapper manager.
* @param string $app_root
* The app root.
* @param string $scheme
* @param string $scheme
* The scheme of the stream wrapper.
* The scheme of the stream wrapper.
*/
*/
public
function
__construct
(
FileSystemInterface
$file_system_helper
,
$app_root
,
$scheme
)
{
public
function
__construct
(
StreamWrapperManagerInterface
$stream_wrapper_manager
,
$scheme
)
{
$this
->
fileSystemHelper
=
$file_system_helper
;
$this
->
streamWrapperManager
=
$stream_wrapper_manager
;
$this
->
appRoot
=
(
string
)
$app_root
;
$this
->
scheme
=
(
string
)
$scheme
;
$this
->
scheme
=
(
string
)
$scheme
;
}
}
...
@@ -69,7 +59,7 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
...
@@ -69,7 +59,7 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
if
(
!
isset
(
$configuration
[
'scheme'
]))
{
if
(
!
isset
(
$configuration
[
'scheme'
]))
{
throw
new
MissingPluginConfigurationException
(
$plugin_id
,
$plugin_definition
,
$configuration
,
'scheme'
);
throw
new
MissingPluginConfigurationException
(
$plugin_id
,
$plugin_definition
,
$configuration
,
'scheme'
);
}
}
return
new
static
(
$container
->
get
(
'
file_system'
),
$container
->
get
(
'app.root
'
),
$configuration
[
'scheme'
]);
return
new
static
(
$container
->
get
(
'
stream_wrapper_manager
'
),
$configuration
[
'scheme'
]);
}
}
/**
/**
...
@@ -81,14 +71,15 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
...
@@ -81,14 +71,15 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
* @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
* @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
*/
*/
public
function
locate
(
LocalLibraryInterface
$library
)
{
public
function
locate
(
LocalLibraryInterface
$library
)
{
$path
=
$this
->
fileSystemHelper
->
realpath
(
$this
->
getUri
(
$library
));
/** @var \Drupal\Core\StreamWrapper\LocalStream $stream_wrapper */
$stream_wrapper
=
$this
->
streamWrapperManager
->
getViaScheme
(
$this
->
scheme
);
if
(
$path
&&
is_dir
(
$path
)
&&
is_readable
(
$path
))
{
assert
(
'$stream_wrapper instanceof \Drupal\Core\StreamWrapper\LocalStream'
);
//
Set a path relative to the app root.
//
Calling LocalStream::getDirectoryPath() explicitly avoids the realpath()
assert
(
'strpos($path, $this->appRoot . "/") === 0'
,
"Path:
$path
"
);
// usage in LocalStream::getLocalPath(), which breaks if Libraries API is
$path
=
str_replace
(
$this
->
appRoot
.
'/'
,
''
,
$path
);
// symbolically linked into the Drupal installation.
assert
(
'$path[0] !== "/"'
);
$path
=
$stream_wrapper
->
getDirectoryPath
()
.
'/'
.
$library
->
getId
(
);
if
(
is_dir
(
$path
)
&&
is_readable
(
$path
))
{
$library
->
setLocalPath
(
$path
);
$library
->
setLocalPath
(
$path
);
}
}
else
{
else
{
...
@@ -96,17 +87,4 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
...
@@ -96,17 +87,4 @@ class StreamLocator implements LocatorInterface, ContainerFactoryPluginInterface
}
}
}
}
/**
* Gets the URI of a library.
*
* @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library
* The library.
*
* @return string
* The URI of the library.
*/
protected
function
getUri
(
LocalLibraryInterface
$library
)
{
return
$this
->
scheme
.
'://'
.
$library
->
getId
();
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment