Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
292
Merge Requests
292
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
aae672cc
Commit
aae672cc
authored
Jun 21, 2018
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2940203
by almaudoh, dawehner: Use dedicated Exception classes for extension system
parent
fb05cb4b
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
65 additions
and
30 deletions
+65
-30
core/includes/bootstrap.inc
core/includes/bootstrap.inc
+2
-1
core/lib/Drupal/Core/Extension/Exception/UninstalledExtensionException.php
...ore/Extension/Exception/UninstalledExtensionException.php
+8
-0
core/lib/Drupal/Core/Extension/Exception/UnknownExtensionException.php
...al/Core/Extension/Exception/UnknownExtensionException.php
+8
-0
core/lib/Drupal/Core/Extension/ExtensionList.php
core/lib/Drupal/Core/Extension/ExtensionList.php
+9
-8
core/lib/Drupal/Core/Extension/ModuleHandler.php
core/lib/Drupal/Core/Extension/ModuleHandler.php
+2
-1
core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
+1
-1
core/lib/Drupal/Core/Extension/ThemeHandler.php
core/lib/Drupal/Core/Extension/ThemeHandler.php
+5
-3
core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php
core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php
+6
-3
core/lib/Drupal/Core/Extension/ThemeInstaller.php
core/lib/Drupal/Core/Extension/ThemeInstaller.php
+3
-2
core/lib/Drupal/Core/Extension/ThemeInstallerInterface.php
core/lib/Drupal/Core/Extension/ThemeInstallerInterface.php
+7
-1
core/modules/system/system.module
core/modules/system/system.module
+2
-1
core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php
...ests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php
+7
-6
core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
+3
-2
core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
+2
-1
No files found.
core/includes/bootstrap.inc
View file @
aae672cc
...
...
@@ -10,6 +10,7 @@
use
Drupal\Component\Render\FormattableMarkup
;
use
Drupal\Component\Utility\Unicode
;
use
Drupal\Core\Config\BootstrapConfigStorageFactory
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\Core\Logger\RfcLogLevel
;
use
Drupal\Core\Test\TestDatabase
;
use
Drupal\Core\Session\AccountInterface
;
...
...
@@ -246,7 +247,7 @@ function drupal_get_filename($type, $name, $filename = NULL) {
try
{
return
$extension_list
->
getPathname
(
$name
);
}
catch
(
\
InvalidArgument
Exception
$e
)
{
catch
(
UnknownExtension
Exception
$e
)
{
// Catch the exception. This will result in triggering an error.
}
}
...
...
core/lib/Drupal/Core/Extension/Exception/UninstalledExtensionException.php
0 → 100644
View file @
aae672cc
<?php
namespace
Drupal\Core\Extension\Exception
;
/**
* Exception class thrown when a specified extension has not been installed.
*/
class
UninstalledExtensionException
extends
\
InvalidArgumentException
{}
core/lib/Drupal/Core/Extension/Exception/UnknownExtensionException.php
0 → 100644
View file @
aae672cc
<?php
namespace
Drupal\Core\Extension\Exception
;
/**
* Exception class thrown when a specified extension is not on the filesystem.
*/
class
UnknownExtensionException
extends
\
InvalidArgumentException
{}
core/lib/Drupal/Core/Extension/ExtensionList.php
View file @
aae672cc
...
...
@@ -4,6 +4,7 @@
use
Drupal\Core\Cache\CacheBackendInterface
;
use
Drupal\Core\Database\DatabaseExceptionWrapper
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\Core\State\StateInterface
;
/**
...
...
@@ -227,7 +228,7 @@ public function exists($extension_name) {
* @return string
* The human-readable name of the extension.
*
* @throws \
InvalidArgument
Exception
* @throws \
Drupal\Core\Extension\Exception\UnknownExtension
Exception
* If there is no extension with the supplied machine name.
*/
public
function
getName
(
$extension_name
)
{
...
...
@@ -244,7 +245,7 @@ public function getName($extension_name) {
* A processed extension object for the extension with the specified machine
* name.
*
* @throws \
InvalidArgument
Exception
* @throws \
Drupal\Core\Extension\Exception\UnknownExtension
Exception
* If there is no extension with the supplied name.
*/
public
function
get
(
$extension_name
)
{
...
...
@@ -253,7 +254,7 @@ public function get($extension_name) {
return
$extensions
[
$extension_name
];
}
throw
new
\
InvalidArgument
Exception
(
"The
{
$this
->
type
}
$extension_name
does not exist."
);
throw
new
UnknownExtension
Exception
(
"The
{
$this
->
type
}
$extension_name
does not exist."
);
}
/**
...
...
@@ -334,7 +335,7 @@ protected function doList() {
* @return mixed[]
* An associative array of extension information.
*
* @throws \
InvalidArgument
Exception
* @throws \
Drupal\Core\Extension\Exception\UnknownExtension
Exception
* If there is no extension with the supplied name.
*/
public
function
getExtensionInfo
(
$extension_name
)
{
...
...
@@ -342,7 +343,7 @@ public function getExtensionInfo($extension_name) {
if
(
isset
(
$all_info
[
$extension_name
]))
{
return
$all_info
[
$extension_name
];
}
throw
new
\
InvalidArgument
Exception
(
"The
{
$this
->
type
}
$extension_name
does not exist or is not installed."
);
throw
new
UnknownExtension
Exception
(
"The
{
$this
->
type
}
$extension_name
does not exist or is not installed."
);
}
/**
...
...
@@ -505,7 +506,7 @@ public function setPathname($extension_name, $pathname) {
* The drupal-root relative filename and path of the requested extension's
* .info.yml file.
*
* @throws \
InvalidArgument
Exception
* @throws \
Drupal\Core\Extension\Exception\UnknownExtension
Exception
* If there is no extension with the supplied machine name.
*/
public
function
getPathname
(
$extension_name
)
{
...
...
@@ -518,7 +519,7 @@ public function getPathname($extension_name) {
elseif
((
$path_names
=
$this
->
getPathnames
())
&&
isset
(
$path_names
[
$extension_name
]))
{
return
$path_names
[
$extension_name
];
}
throw
new
\
InvalidArgument
Exception
(
"The
{
$this
->
type
}
$extension_name
does not exist."
);
throw
new
UnknownExtension
Exception
(
"The
{
$this
->
type
}
$extension_name
does not exist."
);
}
/**
...
...
@@ -533,7 +534,7 @@ public function getPathname($extension_name) {
* @return string
* The Drupal-root-relative path to the specified extension.
*
* @throws \
InvalidArgument
Exception
* @throws \
Drupal\Core\Extension\Exception\UnknownExtension
Exception
* If there is no extension with the supplied name.
*/
public
function
getPath
(
$extension_name
)
{
...
...
core/lib/Drupal/Core/Extension/ModuleHandler.php
View file @
aae672cc
...
...
@@ -5,6 +5,7 @@
use
Drupal\Component\Graph\Graph
;
use
Drupal\Component\Utility\NestedArray
;
use
Drupal\Core\Cache\CacheBackendInterface
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
/**
* Class that manages modules in a Drupal installation.
...
...
@@ -172,7 +173,7 @@ public function getModule($name) {
if
(
isset
(
$this
->
moduleList
[
$name
]))
{
return
$this
->
moduleList
[
$name
];
}
throw
new
\
InvalidArgument
Exception
(
sprintf
(
'The module %s does not exist.'
,
$name
));
throw
new
UnknownExtension
Exception
(
sprintf
(
'The module %s does not exist.'
,
$name
));
}
/**
...
...
core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
View file @
aae672cc
...
...
@@ -61,7 +61,7 @@ public function getModuleList();
* @return \Drupal\Core\Extension\Extension
* An extension object.
*
* @throws \
InvalidArgument
Exception
* @throws \
Drupal\Core\Extension\Exception\UnknownExtension
Exception
* Thrown when the requested module does not exist.
*/
public
function
getModule
(
$name
);
...
...
core/lib/Drupal/Core/Extension/ThemeHandler.php
View file @
aae672cc
...
...
@@ -3,6 +3,8 @@
namespace
Drupal\Core\Extension
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Extension\Exception\UninstalledExtensionException
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\Core\State\StateInterface
;
/**
...
...
@@ -147,7 +149,7 @@ public function getDefault() {
public
function
setDefault
(
$name
)
{
$list
=
$this
->
listInfo
();
if
(
!
isset
(
$list
[
$name
]))
{
throw
new
\
InvalidArgument
Exception
(
"
$name
theme is not installed."
);
throw
new
UninstalledExtension
Exception
(
"
$name
theme is not installed."
);
}
$this
->
configFactory
->
getEditable
(
'system.theme'
)
->
set
(
'default'
,
$name
)
...
...
@@ -437,7 +439,7 @@ protected function getExtensionDiscovery() {
public
function
getName
(
$theme
)
{
$themes
=
$this
->
listInfo
();
if
(
!
isset
(
$themes
[
$theme
]))
{
throw
new
\
InvalidArgument
Exception
(
"Requested the name of a non-existing theme
$theme
"
);
throw
new
UnknownExtension
Exception
(
"Requested the name of a non-existing theme
$theme
"
);
}
return
$themes
[
$theme
]
->
info
[
'name'
];
}
...
...
@@ -486,7 +488,7 @@ public function getTheme($name) {
if
(
isset
(
$themes
[
$name
]))
{
return
$themes
[
$name
];
}
throw
new
\
InvalidArgument
Exception
(
sprintf
(
'The theme %s does not exist.'
,
$name
));
throw
new
UnknownExtension
Exception
(
sprintf
(
'The theme %s does not exist.'
,
$name
));
}
/**
...
...
core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php
View file @
aae672cc
...
...
@@ -39,8 +39,8 @@ public function install(array $theme_list, $install_dependencies = TRUE);
* @param array $theme_list
* The themes to uninstall.
*
* @throws \
InvalidArgument
Exception
* Thrown when you
uninstall an not installed theme
.
* @throws \
Drupal\Core\Extension\Exception\UninstalledExtension
Exception
* Thrown when you
try to uninstall a theme that wasn't installed
.
*
* @see hook_themes_uninstalled()
*
...
...
@@ -146,6 +146,9 @@ public function getBaseThemes(array $themes, $theme);
*
* @return string
* Returns the human readable name of the theme.
*
* @throws \Drupal\Core\Extension\Exception\UnknownExtensionException
* When the specified theme does not exist.
*/
public
function
getName
(
$theme
);
...
...
@@ -206,7 +209,7 @@ public function themeExists($theme);
* @return \Drupal\Core\Extension\Extension
* An extension object.
*
* @throws \
InvalidArgument
Exception
* @throws \
Drupal\Core\Extension\Extension\UnknownExtension
Exception
* Thrown when the requested theme does not exist.
*/
public
function
getTheme
(
$name
);
...
...
core/lib/Drupal/Core/Extension/ThemeInstaller.php
View file @
aae672cc
...
...
@@ -7,6 +7,7 @@
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Config\ConfigInstallerInterface
;
use
Drupal\Core\Config\ConfigManagerInterface
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\Core\Routing\RouteBuilderInterface
;
use
Drupal\Core\State\StateInterface
;
use
Psr\Log\LoggerInterface
;
...
...
@@ -111,7 +112,7 @@ public function install(array $theme_list, $install_dependencies = TRUE) {
if
(
$missing
=
array_diff_key
(
$theme_list
,
$theme_data
))
{
// One or more of the given themes doesn't exist.
throw
new
\
InvalidArgument
Exception
(
'Unknown themes: '
.
implode
(
', '
,
$missing
)
.
'.'
);
throw
new
UnknownExtension
Exception
(
'Unknown themes: '
.
implode
(
', '
,
$missing
)
.
'.'
);
}
// Only process themes that are not installed currently.
...
...
@@ -221,7 +222,7 @@ public function uninstall(array $theme_list) {
$list
=
$this
->
themeHandler
->
listInfo
();
foreach
(
$theme_list
as
$key
)
{
if
(
!
isset
(
$list
[
$key
]))
{
throw
new
\
InvalidArgument
Exception
(
"Unknown theme:
$key
."
);
throw
new
UnknownExtension
Exception
(
"Unknown theme:
$key
."
);
}
if
(
$key
===
$theme_config
->
get
(
'default'
))
{
throw
new
\
InvalidArgumentException
(
"The current default theme
$key
cannot be uninstalled."
);
...
...
core/lib/Drupal/Core/Extension/ThemeInstallerInterface.php
View file @
aae672cc
...
...
@@ -22,6 +22,9 @@ interface ThemeInstallerInterface {
*
* @throws \Drupal\Core\Extension\ExtensionNameLengthException
* Thrown when the theme name is to long.
*
* @throws \Drupal\Core\Extension\Exception\UnknownExtensionException
* Thrown when the theme does not exist.
*/
public
function
install
(
array
$theme_list
,
$install_dependencies
=
TRUE
);
...
...
@@ -34,8 +37,11 @@ public function install(array $theme_list, $install_dependencies = TRUE);
* @param array $theme_list
* The themes to uninstall.
*
* @throws \Drupal\Core\Extension\Exception\UnknownExtensionException
* Thrown when trying to uninstall a theme that was not installed.
*
* @throws \InvalidArgumentException
* Thrown when
you uninstall an not installed
theme.
* Thrown when
trying to uninstall the default theme or the admin
theme.
*
* @see hook_themes_uninstalled()
*/
...
...
core/modules/system/system.module
View file @
aae672cc
...
...
@@ -9,6 +9,7 @@
use
Drupal\Component\Utility\UrlHelper
;
use
Drupal\Core\Asset\AttachedAssetsInterface
;
use
Drupal\Core\Cache\Cache
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\Core\Queue\QueueGarbageCollectionInterface
;
use
Drupal\Core\Database\Query\AlterableInterface
;
use
Drupal\Core\Extension\Extension
;
...
...
@@ -972,7 +973,7 @@ function system_get_info($type, $name = NULL) {
try
{
return
$module_list
->
getExtensionInfo
(
$name
);
}
catch
(
\
InvalidArgument
Exception
$e
)
{
catch
(
UnknownExtension
Exception
$e
)
{
return
[];
}
}
...
...
core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php
View file @
aae672cc
...
...
@@ -4,6 +4,7 @@
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\Extension\ExtensionNameLengthException
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\KernelTests\KernelTestBase
;
/**
...
...
@@ -110,11 +111,11 @@ public function testInstallNonExisting() {
$this
->
assertFalse
(
array_keys
(
$themes
));
try
{
$message
=
'ThemeHandler::install() throws
InvalidArgument
Exception upon installing a non-existing theme.'
;
$message
=
'ThemeHandler::install() throws
UnknownExtension
Exception upon installing a non-existing theme.'
;
$this
->
themeInstaller
()
->
install
([
$name
]);
$this
->
fail
(
$message
);
}
catch
(
\
InvalidArgument
Exception
$e
)
{
catch
(
UnknownExtension
Exception
$e
)
{
$this
->
pass
(
get_class
(
$e
)
.
': '
.
$e
->
getMessage
());
}
...
...
@@ -247,11 +248,11 @@ public function testUninstallNonExisting() {
$this
->
assertFalse
(
array_keys
(
$themes
));
try
{
$message
=
'ThemeHandler::uninstall() throws
InvalidArgument
Exception upon uninstalling a non-existing theme.'
;
$message
=
'ThemeHandler::uninstall() throws
UnknownExtension
Exception upon uninstalling a non-existing theme.'
;
$this
->
themeInstaller
()
->
uninstall
([
$name
]);
$this
->
fail
(
$message
);
}
catch
(
\
InvalidArgument
Exception
$e
)
{
catch
(
UnknownExtension
Exception
$e
)
{
$this
->
pass
(
get_class
(
$e
)
.
': '
.
$e
->
getMessage
());
}
...
...
@@ -291,11 +292,11 @@ public function testUninstallNotInstalled() {
$name
=
'test_basetheme'
;
try
{
$message
=
'ThemeHandler::uninstall() throws
InvalidArgument
Exception upon uninstalling a theme that is not installed.'
;
$message
=
'ThemeHandler::uninstall() throws
UnknownExtension
Exception upon uninstalling a theme that is not installed.'
;
$this
->
themeInstaller
()
->
uninstall
([
$name
]);
$this
->
fail
(
$message
);
}
catch
(
\
InvalidArgument
Exception
$e
)
{
catch
(
UnknownExtension
Exception
$e
)
{
$this
->
pass
(
get_class
(
$e
)
.
': '
.
$e
->
getMessage
());
}
}
...
...
core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
View file @
aae672cc
...
...
@@ -9,6 +9,7 @@
use
Drupal\Core\Extension\ExtensionList
;
use
Drupal\Core\Extension\InfoParserInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\Core\State\StateInterface
;
use
Drupal\Tests\UnitTestCase
;
use
org\bovigo\vfs\vfsStream
;
...
...
@@ -31,7 +32,7 @@ public function testGetNameWithNonExistingExtension() {
$extension_discovery
->
scan
(
'test_extension'
)
->
willReturn
([]);
$test_extension_list
->
setExtensionDiscovery
(
$extension_discovery
->
reveal
());
$this
->
setExpectedException
(
\
InvalidArgument
Exception
::
class
);
$this
->
setExpectedException
(
UnknownExtension
Exception
::
class
);
$test_extension_list
->
getName
(
'test_name'
);
}
...
...
@@ -55,7 +56,7 @@ public function testGetWithNonExistingExtension() {
$extension_discovery
->
scan
(
'test_extension'
)
->
willReturn
([]);
$test_extension_list
->
setExtensionDiscovery
(
$extension_discovery
->
reveal
());
$this
->
setExpectedException
(
\
InvalidArgument
Exception
::
class
);
$this
->
setExpectedException
(
UnknownExtension
Exception
::
class
);
$test_extension_list
->
get
(
'test_name'
);
}
...
...
core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
View file @
aae672cc
...
...
@@ -5,6 +5,7 @@
use
Drupal\Core\Cache\CacheBackendInterface
;
use
Drupal\Core\Extension\Extension
;
use
Drupal\Core\Extension\ModuleHandler
;
use
Drupal\Core\Extension\Exception\UnknownExtensionException
;
use
Drupal\Tests\UnitTestCase
;
/**
...
...
@@ -164,7 +165,7 @@ public function testGetModuleWithExistingModule() {
* @covers ::getModule
*/
public
function
testGetModuleWithNonExistingModule
()
{
$this
->
setExpectedException
(
\
InvalidArgument
Exception
::
class
);
$this
->
setExpectedException
(
UnknownExtension
Exception
::
class
);
$this
->
getModuleHandler
()
->
getModule
(
'claire_alice_watch_my_little_pony_module_that_does_not_exist'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment