Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_mail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
TYPO3
sg_mail
Commits
eac26e8e
Commit
eac26e8e
authored
6 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Refactored the registration process
parent
9a80818c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
Feature security update
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Classes/Service/MailTemplateService.php
+14
-99
14 additions, 99 deletions
Classes/Service/MailTemplateService.php
Classes/Service/RegisterService.php
+28
-18
28 additions, 18 deletions
Classes/Service/RegisterService.php
with
42 additions
and
117 deletions
Classes/Service/MailTemplateService.php
+
14
−
99
View file @
eac26e8e
...
...
@@ -776,25 +776,17 @@ class MailTemplateService {
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @throws \BadFunctionCallException
* @throws \InvalidArgumentException
* @deprecated since 4.7.0 will be removed in 5.0.0. Use the RegistrationService class instead
*/
public
static
function
getRegisterArray
()
{
/** @var CacheManager $cacheManager */
$cacheManager
=
GeneralUtility
::
makeInstance
(
CacheManager
::
class
);
/** @var FrontendInterface $cache */
$cache
=
$cacheManager
->
getCache
(
self
::
CACHE_NAME
);
$cacheId
=
md5
(
'sg_mail'
);
/** @var array entry */
if
((
$entry
=
$cache
->
get
(
$cacheId
))
===
FALSE
)
{
$entry
=
self
::
registerExtensions
();
if
(
$entry
===
NULL
)
{
$entry
=
[];
}
public
static
function
getRegisterArray
():
array
{
// @TODO remove this deprecated function in version 5.0.0
self
::
logDeprecation
(
'registerExtensions'
);
$cache
->
set
(
$cacheId
,
$entry
,
[],
self
::
CACHE_LIFETIME_IN_SECONDS
);
}
$registrationService
=
GeneralUtility
::
makeInstance
(
RegisterService
::
class
);
// write entries for old extensions intto the file list
self
::
registerExtensions
();
return
$
entry
;
return
$
registrationService
->
getRegisterArray
()
;
}
/**
...
...
@@ -802,16 +794,13 @@ class MailTemplateService {
* If found, register the template(s)
*
* @throws \BadFunctionCallException
* @deprecated since 4.7.0 will be removed in 5.0.0
* @return array
* @deprecated since 4.7.0 will be removed in 5.0.0. Use the RegistrationService class instead
*/
public
static
function
registerExtensions
()
:
array
{
public
static
function
registerExtensions
()
{
// @TODO remove this deprecated function in version 5.0.0
self
::
logDeprecation
(
'registerExtensions'
);
// clear registerArray
$registerArray
=
[];
$registerService
=
GeneralUtility
::
makeInstance
(
RegisterService
::
class
);
$extensionList
=
ExtensionManagementUtility
::
getLoadedExtensionListArray
();
foreach
(
$extensionList
as
$extensionName
)
{
...
...
@@ -820,90 +809,16 @@ class MailTemplateService {
if
(
\is_dir
(
$extensionConfigDirectory
))
{
$configFiles
=
GeneralUtility
::
getFilesInDir
(
$extensionConfigDirectory
);
foreach
(
$configFiles
as
$configFile
)
{
if
(
!
\file_exists
(
$extensionConfigDirectory
.
'/'
.
$configFile
))
{
continue
;
}
$pathToRegistrationFile
=
$extensionConfigDirectory
.
'/'
.
$configFile
;
$configArray
=
(
include
$extensionConfigDirectory
.
'/'
.
$configFile
);
$extensionKey
=
$configArray
[
'extension_key'
];
$templateKey
=
$configArray
[
'template_key'
];
if
(
$extensionKey
===
NULL
||
$templateKey
===
NULL
)
{
if
(
!
\file_exists
(
$pathToRegistrationFile
))
{
continue
;
}
$registerArray
=
self
::
writeRegisterArrayEntry
(
$registerArray
,
$extensionKey
,
$templateKey
,
$configArray
);
$registerService
->
register
(
$pathToRegistrationFile
);
}
}
}
return
$registerArray
;
}
/**
* writes a single entry into the register array
*
* @param array $registerArray
* @param string $extensionKey
* @param string $templateKey
* @param array $configArray
* @param bool $transformTemplateFolder
* @param string $storeTemplateExtension
* @deprecated since 4.7.0 will be removed in 5.0.0
* @return array
*/
private
static
function
writeRegisterArrayEntry
(
array
$registerArray
,
$extensionKey
,
$templateKey
,
array
$configArray
,
$transformTemplateFolder
=
TRUE
,
$storeTemplateExtension
=
''
)
{
// @TODO remove this deprecated function in version 5.0.0
self
::
logDeprecation
(
'writeRegisterArrayEntry'
);
// If it is not explicitly set in which extension the html should be located, use the extension set in the template settings
if
(
$storeTemplateExtension
===
''
)
{
$storeTemplateExtension
=
$extensionKey
;
}
// give the option to use the template key as folder name. this is used mainly with auto registering
$templateDirectory
=
$templateKey
;
// by default folders with underscore will be transformed to upper camelcase
if
(
$transformTemplateFolder
)
{
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts
=
GeneralUtility
::
trimExplode
(
'_'
,
$templateKey
);
$templateDirectory
=
''
;
foreach
(
$templateDirectoryParts
as
$part
)
{
$templateDirectory
.
=
ucfirst
(
$part
);
}
}
$templateDirectory
.
=
'/'
;
$templatePath
=
ExtensionManagementUtility
::
extPath
(
$storeTemplateExtension
)
.
self
::
DEFAULT_TEMPLATE_PATH
.
$templateDirectory
;
if
(
$configArray
[
'template_path'
])
{
$templatePath
=
$configArray
[
$templateKey
];
}
$description
=
$configArray
[
'description'
];
$subject
=
$configArray
[
'subject'
];
$marker
=
$configArray
[
'markers'
];
$registerArray
[
$extensionKey
][
$templateKey
]
=
[
'templatePath'
=>
$templatePath
,
'description'
=>
$description
,
'marker'
=>
$marker
,
'extension'
=>
$extensionKey
,
'templateName'
=>
$templateKey
,
'subject'
=>
$subject
];
return
$registerArray
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Classes/Service/RegisterService.php
+
28
−
18
View file @
eac26e8e
...
...
@@ -32,20 +32,25 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
/**
*
Class RegisterService
*
Provides an api for registering your mail templates
*
* @package SGalinski\SgMail\Service
*/
class
RegisterService
implements
\TYPO3\CMS\Core\SingletonInterface
{
const
CACHE_NAME
=
'sg_mail_registerArrayCache'
;
const
CACHE_LIFETIME_IN_SECONDS
=
86400
;
const
DEFAULT_TEMPLATE_PATH
=
'Resources/Private/Templates/SgMail/'
;
/**
* contains the actual registration data
*
* @var array
*/
p
ublic
$registerArray
=
[];
p
rivate
$registerArray
=
[];
/**
* contains the paths to the registration files
*
* @var array
*/
private
$registrationFiles
=
[];
...
...
@@ -54,6 +59,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
* Enables extensions to add their registration files
*
* @param string $pathToRegisterFile
* @api
*/
public
function
register
(
$pathToRegisterFile
)
{
if
(
file_exists
(
$pathToRegisterFile
))
{
...
...
@@ -93,13 +99,14 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
/**
* Read every registered file and create a registration entry in the registerArray if possible
*
* @internal
*/
private
function
registerExtensions
()
{
foreach
(
$this
->
registrationFiles
as
$registerFile
)
{
// clear registerArray
$registerArray
=
[];
public
function
registerExtensions
()
{
// clear registerArray
$this
->
registerArray
=
[];
foreach
(
$this
->
registrationFiles
as
$registerFile
)
{
if
(
\is_file
(
$registerFile
))
{
$configArray
=
(
include
$registerFile
);
...
...
@@ -110,31 +117,26 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
continue
;
}
$registerArray
=
$this
->
writeRegisterArrayEntry
(
$registerArray
,
$extensionKey
,
$templateKey
,
$configArray
$this
->
writeRegisterArrayEntry
(
$extensionKey
,
$templateKey
,
$configArray
);
}
// set the register array after every registration has been parsed
$this
->
registerArray
=
$registerArray
;
}
}
/**
* write a single entry into the register array
*
* @param array $registerArray
* @param $extensionKey
* @param $templateKey
* @param array $configArray
* @param bool $transformTemplateFolder
* @param string $storeTemplateExtension
* @return array
*/
private
function
writeRegisterArrayEntry
(
array
$registerArray
,
$extensionKey
,
$templateKey
,
array
$configArray
,
$extensionKey
,
$templateKey
,
array
$configArray
,
$transformTemplateFolder
=
TRUE
,
$storeTemplateExtension
=
''
)
:
array
{
)
{
// If it is not explicitly set in which extension the html should be located, use the extension set in the template settings
if
(
$storeTemplateExtension
===
''
)
{
$storeTemplateExtension
=
$extensionKey
;
...
...
@@ -165,7 +167,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
$subject
=
$configArray
[
'subject'
];
$marker
=
$configArray
[
'markers'
];
$registerArray
[
$extensionKey
][
$templateKey
]
=
[
$
this
->
registerArray
[
$extensionKey
][
$templateKey
]
=
[
'templatePath'
=>
$templatePath
,
'description'
=>
$description
,
'marker'
=>
$marker
,
...
...
@@ -173,8 +175,16 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
'templateName'
=>
$templateKey
,
'subject'
=>
$subject
];
}
return
$registerArray
;
/**
* Get an array with a list of filepaths of all registration files
*
* @api
* @return array
*/
public
function
getRegistrationFiles
():
array
{
return
$this
->
registrationFiles
;
}
}
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