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
cc49755e
Commit
cc49755e
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Migrate the SimpleSAML_Module class to namespaces (SimpleSAML\Module) as an example.
parent
6a12b807
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/Module.php
+19
-17
19 additions, 17 deletions
lib/SimpleSAML/Module.php
lib/_autoload_modules.php
+2
-2
2 additions, 2 deletions
lib/_autoload_modules.php
with
21 additions
and
19 deletions
lib/SimpleSAML/Module.php
+
19
−
17
View file @
cc49755e
<?php
namespace
SimpleSAML
;
/**
* Helper class for accessing information about modules.
...
...
@@ -9,13 +9,14 @@
* @author Jaime Perez <jaime.perez@uninett.no>, UNINETT AS.
* @package SimpleSAMLphp
*/
class
SimpleSAML_
Module
class
Module
{
/**
* Autoload function for SimpleSAMLphp modules following PSR-0.
*
* @param string $className Name of the class.
* @deprecated This method will be removed in SSP 2.0.
*
* TODO: this autoloader should be removed once everything has been migrated to namespaces.
*/
...
...
@@ -36,16 +37,17 @@ class SimpleSAML_Module
}
$file
=
self
::
getModuleDir
(
$module
)
.
'/lib/'
.
join
(
'/'
,
$path
)
.
'.php'
;
if
(
file_exists
(
$file
))
{
re
quire_once
(
$file
)
;
if
(
!
file_exists
(
$file
))
{
re
turn
;
}
require_once
(
$file
);
if
(
!
class_exists
(
$className
,
false
))
{
// the file exists, but the class is not defined. Is it using namespaces?
$nspath
=
join
(
'\\'
,
$path
);
if
(
class_exists
(
'SimpleSAML\Module\\'
.
$module
.
'\\'
.
$nspath
))
{
// the class has been migrated, create an alias and warn about it
SimpleSAML_Logger
::
warning
(
\
SimpleSAML_Logger
::
warning
(
"The class '
$className
' is now using namespaces, please use 'SimpleSAML
\\
Module
\\
$module
\\
"
.
"
$nspath
' instead."
);
...
...
@@ -117,7 +119,7 @@ class SimpleSAML_Module
*
* @return bool True if the given module is enabled, false otherwise.
*
* @throws Exception If module.enable is set and is not boolean.
* @throws
\
Exception If module.enable is set and is not boolean.
*/
public
static
function
isModuleEnabled
(
$module
)
{
...
...
@@ -128,7 +130,7 @@ class SimpleSAML_Module
return
false
;
}
$globalConfig
=
SimpleSAML_Configuration
::
getOptionalConfig
();
$globalConfig
=
\
SimpleSAML_Configuration
::
getOptionalConfig
();
$moduleEnable
=
$globalConfig
->
getArray
(
'module.enable'
,
array
());
if
(
isset
(
$moduleEnable
[
$module
]))
{
...
...
@@ -136,14 +138,14 @@ class SimpleSAML_Module
return
$moduleEnable
[
$module
];
}
throw
new
Exception
(
"Invalid module.enable value for for the module
$module
"
);
throw
new
\
Exception
(
"Invalid module.enable value for for the module
$module
"
);
}
if
(
assert_options
(
ASSERT_ACTIVE
)
&&
!
file_exists
(
$moduleDir
.
'/default-enable'
)
&&
!
file_exists
(
$moduleDir
.
'/default-disable'
)
)
{
SimpleSAML_Logger
::
error
(
"Missing default-enable or default-disable file for the module
$module
"
);
\
SimpleSAML_Logger
::
error
(
"Missing default-enable or default-disable file for the module
$module
"
);
}
if
(
file_exists
(
$moduleDir
.
'/enable'
))
{
...
...
@@ -163,7 +165,7 @@ class SimpleSAML_Module
*
* @return array One string for each module.
*
* @throws Exception If we cannot open the module's directory.
* @throws
\
Exception If we cannot open the module's directory.
*/
public
static
function
getModules
()
{
...
...
@@ -172,7 +174,7 @@ class SimpleSAML_Module
$dh
=
opendir
(
$path
);
if
(
$dh
===
false
)
{
throw
new
Exception
(
'Unable to open module directory "'
.
$path
.
'".'
);
throw
new
\
Exception
(
'Unable to open module directory "'
.
$path
.
'".'
);
}
$modules
=
array
();
...
...
@@ -212,7 +214,7 @@ class SimpleSAML_Module
*
* @return string The classname.
*
* @throws Exception If the class cannot be resolved.
* @throws
\
Exception If the class cannot be resolved.
*/
public
static
function
resolveClass
(
$id
,
$type
,
$subclass
=
null
)
{
...
...
@@ -224,7 +226,7 @@ class SimpleSAML_Module
if
(
count
(
$tmp
)
===
1
)
{
// no module involved
$className
=
$tmp
[
0
];
if
(
!
class_exists
(
$className
))
{
throw
new
Exception
(
"Could not resolve '
$id
': no class named '
$className
'."
);
throw
new
\
Exception
(
"Could not resolve '
$id
': no class named '
$className
'."
);
}
}
else
{
// should be a module
// make sure empty types are handled correctly
...
...
@@ -239,14 +241,14 @@ class SimpleSAML_Module
$newClassName
=
'SimpleSAML\Module\\'
.
$tmp
[
0
]
.
$type
.
$tmp
[
1
];
if
(
!
class_exists
(
$newClassName
))
{
throw
new
Exception
(
"Could not resolve '
$id
': no class named '
$className
' or '
$newClassName
'."
);
throw
new
\
Exception
(
"Could not resolve '
$id
': no class named '
$className
' or '
$newClassName
'."
);
}
$className
=
$newClassName
;
}
}
if
(
$subclass
!==
null
&&
!
is_subclass_of
(
$className
,
$subclass
))
{
throw
new
Exception
(
throw
new
\
Exception
(
'Could not resolve \''
.
$id
.
'\': The class \''
.
$className
.
'\' isn\'t a subclass of \''
.
$subclass
.
'\'.'
);
}
...
...
@@ -270,9 +272,9 @@ class SimpleSAML_Module
assert
(
'is_string($resource)'
);
assert
(
'$resource[0] !== "/"'
);
$url
=
\SimpleSAML\
Utils\HTTP
::
getBaseURL
()
.
'module.php/'
.
$resource
;
$url
=
Utils\HTTP
::
getBaseURL
()
.
'module.php/'
.
$resource
;
if
(
!
empty
(
$parameters
))
{
$url
=
\SimpleSAML\
Utils\HTTP
::
addURLParameters
(
$url
,
$parameters
);
$url
=
Utils\HTTP
::
addURLParameters
(
$url
,
$parameters
);
}
return
$url
;
}
...
...
This diff is collapsed.
Click to expand it.
lib/_autoload_modules.php
+
2
−
2
View file @
cc49755e
...
...
@@ -37,5 +37,5 @@ function temporaryLoader($class)
}
spl_autoload_register
(
"temporaryLoader"
);
spl_autoload_register
(
array
(
'SimpleSAML
_
Module'
,
'autoloadPSR0'
));
spl_autoload_register
(
array
(
'SimpleSAML
_
Module'
,
'autoloadPSR4'
));
spl_autoload_register
(
array
(
'SimpleSAML
\
Module'
,
'autoloadPSR0'
));
spl_autoload_register
(
array
(
'SimpleSAML
\
Module'
,
'autoloadPSR4'
));
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