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
2bf90ac5
Commit
2bf90ac5
authored
3 years ago
by
Tim van Dijen
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite Module using symfony/filesystem
parent
261ebc96
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Module.php
+47
-32
47 additions, 32 deletions
lib/SimpleSAML/Module.php
with
47 additions
and
32 deletions
lib/SimpleSAML/Module.php
+
47
−
32
View file @
2bf90ac5
...
@@ -9,6 +9,9 @@ use SimpleSAML\Assert\Assert;
...
@@ -9,6 +9,9 @@ use SimpleSAML\Assert\Assert;
use
SimpleSAML\Kernel
;
use
SimpleSAML\Kernel
;
use
SimpleSAML\Utils
;
use
SimpleSAML\Utils
;
use
Symfony\Component\Config\Exception\FileLocatorFileNotFoundException
;
use
Symfony\Component\Config\Exception\FileLocatorFileNotFoundException
;
use
Symfony\Component\Filesystem\Filesystem
;
use
Symfony\Component\Filesystem\Path
;
use
Symfony\Component\Finder\Finder
;
use
Symfony\Component\HttpFoundation\BinaryFileResponse
;
use
Symfony\Component\HttpFoundation\BinaryFileResponse
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
...
@@ -16,6 +19,31 @@ use Symfony\Component\HttpFoundation\Response;
...
@@ -16,6 +19,31 @@ use Symfony\Component\HttpFoundation\Response;
use
Symfony\Component\HttpFoundation\ResponseHeaderBag
;
use
Symfony\Component\HttpFoundation\ResponseHeaderBag
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
function
array_filter
;
use
function
array_key_exists
;
use
function
class_exists
;
use
function
count
;
use
function
dirname
;
use
function
explode
;
use
function
function_exists
;
use
function
in_array
;
use
function
is_bool
;
use
function
is_callable
;
use
function
is_dir
;
use
function
is_file
;
use
function
is_null
;
use
function
is_subclass_of
;
use
function
mb_strtolower
;
use
function
mime_content_type
;
use
function
preg_match
;
use
function
rtrim
;
use
function
str_replace
;
use
function
strlen
;
use
function
strpos
;
use
function
strtolower
;
use
function
strval
;
use
function
substr
;
/**
/**
* Helper class for accessing information about modules.
* Helper class for accessing information about modules.
*
*
...
@@ -233,11 +261,12 @@ class Module
...
@@ -233,11 +261,12 @@ class Module
}
}
$path
=
$moduleDir
.
$url
;
$path
=
$moduleDir
.
$url
;
$fileSystem
=
new
Filesystem
();
if
(
$path
[
strlen
(
$path
)
-
1
]
===
'/'
)
{
if
(
$path
[
strlen
(
$path
)
-
1
]
===
'/'
)
{
// path ends with a slash - directory reference. Attempt to find index file in directory
// path ends with a slash - directory reference. Attempt to find index file in directory
foreach
(
self
::
$indexFiles
as
$if
)
{
foreach
(
self
::
$indexFiles
as
$if
)
{
if
(
file
_
exists
(
$path
.
$if
))
{
if
(
$
file
System
->
exists
(
$path
.
$if
))
{
$path
.
=
$if
;
$path
.
=
$if
;
break
;
break
;
}
}
...
@@ -251,7 +280,7 @@ class Module
...
@@ -251,7 +280,7 @@ class Module
throw
new
Error\NotFound
(
'Directory listing not available.'
);
throw
new
Error\NotFound
(
'Directory listing not available.'
);
}
}
if
(
!
file
_
exists
(
$path
))
{
if
(
!
$
file
System
->
exists
(
$path
))
{
// file not found
// file not found
Logger
::
info
(
'Could not find file \''
.
$path
.
'\'.'
);
Logger
::
info
(
'Could not find file \''
.
$path
.
'\'.'
);
throw
new
Error\NotFound
(
'The URL wasn\'t found in the module.'
);
throw
new
Error\NotFound
(
'The URL wasn\'t found in the module.'
);
...
@@ -373,21 +402,11 @@ class Module
...
@@ -373,21 +402,11 @@ class Module
$path
=
self
::
getModuleDir
(
'.'
);
$path
=
self
::
getModuleDir
(
'.'
);
$dh
=
scandir
(
$path
);
$finder
=
new
Finder
();
if
(
$dh
===
false
)
{
$finder
->
directories
()
->
in
(
$path
)
->
depth
(
0
);
throw
new
Exception
(
'Unable to open module directory "'
.
$path
.
'".'
);
}
foreach
(
$dh
as
$f
)
{
if
(
$f
[
0
]
===
'.'
)
{
continue
;
}
if
(
!
is_dir
(
$path
.
'/'
.
$f
))
{
continue
;
}
self
::
$modules
[]
=
$f
;
foreach
(
$finder
as
$module
)
{
self
::
$modules
[]
=
$module
->
getFileName
();
}
}
return
self
::
$modules
;
return
self
::
$modules
;
...
@@ -485,25 +504,21 @@ class Module
...
@@ -485,25 +504,21 @@ class Module
return
self
::
$modules
[
$module
][
'hooks'
];
return
self
::
$modules
[
$module
][
'hooks'
];
}
}
$hook_dir
=
self
::
getModuleDir
(
$module
)
.
'/hooks'
;
if
(
!
is_dir
(
$hook_dir
))
{
return
[];
}
$hooks
=
[];
$hooks
=
[];
$files
=
scandir
(
$hook_dir
);
$hook_dir
=
dirname
(
dirname
(
dirname
(
__FILE__
)))
.
'/modules/'
.
$module
.
'/hooks'
;
foreach
(
$files
as
$file
)
{
if
((
new
Filesystem
())
->
exists
(
$hook_dir
))
{
if
(
$file
[
0
]
===
'.'
)
{
$finder
=
new
Finder
();
continue
;
$finder
->
files
()
->
in
(
$hook_dir
)
->
depth
(
0
);
}
foreach
(
$finder
as
$file
)
{
if
(
!
preg_match
(
'/^hook_(\w+)\.php$/'
,
$file
,
$matches
))
{
if
(
preg_match
(
'/^hook_(\w+)\.php$/'
,
$file
->
getFileName
(),
$matches
))
{
continue
;
$hook_name
=
$matches
[
1
];
$hook_func
=
$module
.
'_hook_'
.
$hook_name
;
$hooks
[
$hook_name
]
=
[
'file'
=>
Path
::
canonicalize
(
strval
(
$file
)),
'func'
=>
$hook_func
];
}
}
}
$hook_name
=
$matches
[
1
];
$hook_func
=
$module
.
'_hook_'
.
$hook_name
;
$hooks
[
$hook_name
]
=
[
'file'
=>
$hook_dir
.
'/'
.
$file
,
'func'
=>
$hook_func
];
}
}
return
$hooks
;
return
$hooks
;
}
}
...
...
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