Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getKeyPath example
if
(
!
$input
->
getOption
(
'fix'
)
)
{
$io
->
error
(
'Invalid snippets found!'
)
;
$table
=
new
Table
(
$output
)
;
$table
->
setHeaders
(
[
'Snippet', 'Missing for ISO', 'Found in file',
]
)
;
foreach
(
$missingSnippetsCollection
->
getIterator
(
)
as
$missingSnippetStruct
)
{
$table
->
addRow
(
[
$missingSnippetStruct
->
getKeyPath
(
)
,
$missingSnippetStruct
->
getMissingForISO
(
)
,
$missingSnippetStruct
->
getFilePath
(
)
,
]
)
;
}
$table
->
render
(
)
;
return
-1;
}
$questionHelper
=
$this
->
getHelper
(
'question'
)
;
Signer
$signer
,
CryptKey
$privateKey
,
CryptKey
$publicKey
,
?Encoder
$encoder
= null,
?Decoder
$decoder
= null
)
: Configuration
{
/** @var non-empty-string $privateKeyText */
$privateKeyText
=
$privateKey
->
getKeyContents
(
)
;
/** @var non-empty-string $publicKeyText */
$publicKeyText
=
$publicKey
->
getKeyContents
(
)
;
if
(
$privateKey
->
getKeyPath
(
)
=== ''
)
{
$privateKey
= InMemory::
plainText
(
$privateKeyText
,
$privateKey
->
getPassPhrase
(
)
?? ''
)
;
$publicKey
= InMemory::
plainText
(
$publicKeyText
,
$publicKey
->
getPassPhrase
(
)
?? ''
)
;
}
else
{
$privateKey
= InMemory::
file
(
$privateKey
->
getKeyPath
(
)
,
$privateKey
->
getPassPhrase
(
)
?? ''
)
;
$publicKey
= InMemory::
file
(
$publicKey
->
getKeyPath
(
)
,
$publicKey
->
getPassPhrase
(
)
?? ''
)
;
}
$configuration
= Configuration::
forAsymmetricSigner
(
$signer
,
$privateKey
,
$publicKey
,
$missingSnippetStruct
->
getMissingForISO
(
)
,
str_replace
(
'-', '_',
$missingSnippetStruct
->
getMissingForISO
(
)
)
,
]
,
$missingSnippetStruct
->
getFilePath
(
)
)
;
$json
=
$this
->snippetFileHandler->
openJsonFile
(
$newPath
)
;
$json
=
$this
->
addTranslationUsingSnippetKey
(
$json
,
$missingSnippetStruct
->
getTranslation
(
)
,
$missingSnippetStruct
->
getKeyPath
(
)
)
;
$this
->snippetFileHandler->
writeJsonFile
(
$newPath
,
$json
)
;
}
}
private
function
addTranslationUsingSnippetKey
(
array
$json
, string
$translation
, string
$key
)
: array
{
$keyParts
=
explode
(
'.',
$key
)
;
$currentJson
= &
$json
;