Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
AppNameError example
public
function
testLicenseCouldNotBeVerified
(
)
: void
{
$e
= AppException::
licenseCouldNotBeVerified
(
'UnlicensedApp'
)
;
static
::
assertEquals
(
AppException::LICENSE_COULD_NOT_BE_VERIFIED,
$e
->
getErrorCode
(
)
)
;
}
public
function
testInvalidConfiguration
(
)
: void
{
$e
= AppException::
invalidConfiguration
(
'InvalidlyConfiguredApp',
new
AppNameError
(
'InvalidlyConfiguredApp'
)
)
;
static
::
assertEquals
(
AppException::INVALID_CONFIGURATION,
$e
->
getErrorCode
(
)
)
;
}
public
function
testAppSecretRequiredForFeatures
(
)
: void
{
$e
= AppException::
appSecretRequiredForFeatures
(
'MyApp',
[
'Modules'
]
)
;
static
::
assertEquals
(
AppException::FEATURES_REQUIRE_APP_SECRET,
$e
->
getErrorCode
(
)
)
;
static
::
assertEquals
(
'App "MyApp" could not be installed/updated because it uses features Modules but has no secret',
$e
->
getMessage
(
)
)
;
#[Package('core')]
class
AppNameValidator
extends
AbstractManifestValidator
{
public
function
validate
(
Manifest
$manifest
, ?Context
$context
)
: ErrorCollection
{
$errors
=
new
ErrorCollection
(
)
;
$appName
=
strtolower
(
substr
(
$manifest
->
getPath
(
)
,
strrpos
(
$manifest
->
getPath
(
)
, '/'
)
+ 1
)
)
;
if
(
$appName
!==
strtolower
(
$manifest
->
getMetadata
(
)
->
getName
(
)
)
)
{
$errors
->
add
(
new
AppNameError
(
$manifest
->
getMetadata
(
)
->
getName
(
)
)
)
;
}
return
$errors
;
}
}