Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
a7955636
Commit
a7955636
authored
6 years ago
by
Tim van Dijen
Browse files
Options
Downloads
Patches
Plain Diff
Import TemplateLoader from Xnew-ui branch
parent
1d7d0cb0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/SimpleSAML/XHTML/Template.php
+8
-5
8 additions, 5 deletions
lib/SimpleSAML/XHTML/Template.php
lib/SimpleSAML/XHTML/TemplateLoader.php
+65
-0
65 additions, 0 deletions
lib/SimpleSAML/XHTML/TemplateLoader.php
with
73 additions
and
5 deletions
lib/SimpleSAML/XHTML/Template.php
+
8
−
5
View file @
a7955636
...
@@ -165,14 +165,16 @@ class Template
...
@@ -165,14 +165,16 @@ class Template
// get namespace if any
// get namespace if any
list
(
$namespace
,
$filename
)
=
$this
->
findModuleAndTemplateName
(
$filename
);
list
(
$namespace
,
$filename
)
=
$this
->
findModuleAndTemplateName
(
$filename
);
$this
->
twig_template
=
(
$namespace
!==
null
)
?
'@'
.
$namespace
.
'/'
.
$filename
:
$filename
;
$this
->
twig_template
=
(
$namespace
!==
null
)
?
'@'
.
$namespace
.
'/'
.
$filename
:
$filename
;
$loader
=
new
\Twig_Loader_Filesystem
();
$loader
=
new
TemplateLoader
();
$templateDirs
=
$this
->
findThemeTemplateDirs
();
$templateDirs
=
$this
->
findThemeTemplateDirs
();
if
(
$this
->
module
)
{
if
(
$this
->
module
)
{
$templateDirs
[]
=
array
(
$this
->
module
=>
$this
->
getModuleTemplateDir
(
$this
->
module
));
$templateDirs
[]
=
array
(
$this
->
module
=>
TemplateLoader
::
getModuleTemplateDir
(
$this
->
module
));
}
}
if
(
$this
->
theme
[
'module'
])
{
if
(
$this
->
theme
[
'module'
])
{
try
{
try
{
$templateDirs
[]
=
array
(
$this
->
theme
[
'module'
]
=>
$this
->
getModuleTemplateDir
(
$this
->
theme
[
'module'
]));
$templateDirs
[]
=
array
(
$this
->
theme
[
'module'
]
=>
TemplateLoader
::
getModuleTemplateDir
(
$this
->
theme
[
'module'
])
);
}
catch
(
\InvalidArgumentException
$e
)
{
}
catch
(
\InvalidArgumentException
$e
)
{
// either the module is not enabled or it has no "templates" directory, ignore
// either the module is not enabled or it has no "templates" directory, ignore
}
}
...
@@ -297,10 +299,11 @@ class Template
...
@@ -297,10 +299,11 @@ class Template
return
$themeTemplateDirs
;
return
$themeTemplateDirs
;
}
}
/**
/**
* Get the template directory of a module, if it exists.
* Get the template directory of a module, if it exists.
*
*
* @return string The templates directory of a module
.
* @return string The templates directory of a module
*
*
* @throws \InvalidArgumentException If the module is not enabled or it has no templates directory.
* @throws \InvalidArgumentException If the module is not enabled or it has no templates directory.
*/
*/
...
@@ -330,7 +333,7 @@ class Template
...
@@ -330,7 +333,7 @@ class Template
*/
*/
public
function
addTemplatesFromModule
(
$module
)
public
function
addTemplatesFromModule
(
$module
)
{
{
$dir
=
$this
->
getModuleTemplateDir
(
$module
);
$dir
=
TemplateLoader
::
getModuleTemplateDir
(
$module
);
/** @var \Twig_Loader_Filesystem $loader */
/** @var \Twig_Loader_Filesystem $loader */
$loader
=
$this
->
twig
->
getLoader
();
$loader
=
$this
->
twig
->
getLoader
();
$loader
->
addPath
(
$dir
,
$module
);
$loader
->
addPath
(
$dir
,
$module
);
...
...
This diff is collapsed.
Click to expand it.
lib/SimpleSAML/XHTML/TemplateLoader.php
0 → 100644
+
65
−
0
View file @
a7955636
<?php
namespace
SimpleSAML\XHTML
;
/**
* This class extends the Twig\Loader\FilesystemLoader so that we can load templates from modules in twig, even
* when the main template is not part of a module (or the same one).
*
* @package simplesamlphp/simplesamlphp
*/
class
TemplateLoader
extends
\Twig\Loader\FilesystemLoader
{
/**
* This method adds a namespace dynamically so that we can load templates from modules whenever we want.
*
* @inheritdoc
*/
protected
function
findTemplate
(
$name
)
{
list
(
$namespace
,
$shortname
)
=
$this
->
parseName
(
$name
);
if
(
!
in_array
(
$namespace
,
$this
->
paths
,
true
)
&&
$namespace
!==
self
::
MAIN_NAMESPACE
)
{
$this
->
addPath
(
self
::
getModuleTemplateDir
(
$namespace
),
$namespace
);
}
return
parent
::
findTemplate
(
$name
);
}
protected
function
parseName
(
$name
,
$default
=
self
::
MAIN_NAMESPACE
)
{
if
(
strpos
(
$name
,
':'
))
{
// we have our old SSP format
list
(
$namespace
,
$shortname
)
=
explode
(
':'
,
$name
,
2
);
$shortname
=
strtr
(
$shortname
,
array
(
'.tpl.php'
=>
'.twig'
,
'.php'
=>
'.twig'
,
));
return
array
(
$namespace
,
$shortname
);
}
return
parent
::
parseName
(
$name
,
$default
);
}
/**
* Get the template directory of a module, if it exists.
*
* @return string The templates directory of a module.
*
* @throws \InvalidArgumentException If the module is not enabled or it has no templates directory.
*/
public
static
function
getModuleTemplateDir
(
$module
)
{
if
(
!
\SimpleSAML\Module
::
isModuleEnabled
(
$module
))
{
throw
new
\InvalidArgumentException
(
'The module \''
.
$module
.
'\' is not enabled.'
);
}
$moduledir
=
\SimpleSAML\Module
::
getModuleDir
(
$module
);
// check if module has a /templates dir, if so, append
$templatedir
=
$moduledir
.
'/templates'
;
if
(
!
is_dir
(
$templatedir
))
{
throw
new
\InvalidArgumentException
(
'The module \''
.
$module
.
'\' has no templates directory.'
);
}
return
$templatedir
;
}
}
\ No newline at end of file
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