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
a44588d7
Commit
a44588d7
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Move the two PSR 0 and PSR 4 module autoloader functions to SimpleSAML_Module.
parent
07b68312
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
+81
-2
81 additions, 2 deletions
lib/SimpleSAML/Module.php
lib/_autoload_modules.php
+3
-80
3 additions, 80 deletions
lib/_autoload_modules.php
with
84 additions
and
82 deletions
lib/SimpleSAML/Module.php
+
81
−
2
View file @
a44588d7
...
...
@@ -4,12 +4,91 @@
/**
* Helper class for accessing information about modules.
*
* @author Olav Morken, UNINETT AS.
* @author Olav Morken <olav.morken@uninett.no>, UNINETT AS.
* @author Boy Baukema, SURFnet.
* @author Jaime Perez <jaime.perez@uninett.no>, UNINETT AS.
* @package SimpleSAMLphp
*/
class
SimpleSAML_Module
{
/**
* Autoload function for SimpleSAMLphp modules following PSR-0.
*
* @param string $className Name of the class.
*
* TODO: this autoloader should be removed once everything has been migrated to namespaces.
*/
public
static
function
autoloadPSR0
(
$className
)
{
$modulePrefixLength
=
strlen
(
'sspmod_'
);
$classPrefix
=
substr
(
$className
,
0
,
$modulePrefixLength
);
if
(
$classPrefix
!==
'sspmod_'
)
{
return
;
}
$modNameEnd
=
strpos
(
$className
,
'_'
,
$modulePrefixLength
);
$module
=
substr
(
$className
,
$modulePrefixLength
,
$modNameEnd
-
$modulePrefixLength
);
$path
=
explode
(
'_'
,
substr
(
$className
,
$modNameEnd
+
1
));
if
(
!
self
::
isModuleEnabled
(
$module
))
{
return
;
}
$file
=
self
::
getModuleDir
(
$module
)
.
'/lib/'
.
join
(
'/'
,
$path
)
.
'.php'
;
if
(
file_exists
(
$file
))
{
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
(
"The class '
$className
' is now using namespaces, please use 'SimpleSAML
\\
Module
\\
$module
\\
"
.
"
$nspath
' instead."
);
class_alias
(
"SimpleSAML
\\
Module
\\
$module
\\
$nspath
"
,
$className
);
}
}
}
/**
* Autoload function for SimpleSAMLphp modules following PSR-4.
*
* @param string $className Name of the class.
*/
public
static
function
autoloadPSR4
(
$className
)
{
$elements
=
explode
(
'\\'
,
$className
);
if
(
$elements
[
0
]
===
''
)
{
// class name starting with /, ignore
array_shift
(
$elements
);
}
if
(
count
(
$elements
)
<
4
)
{
return
;
// it can't be a module
}
if
(
array_shift
(
$elements
)
!==
'SimpleSAML'
)
{
return
;
// the first element is not "SimpleSAML"
}
if
(
array_shift
(
$elements
)
!==
'Module'
)
{
return
;
// the second element is not "module"
}
// this is a SimpleSAMLphp module following PSR-4
$module
=
array_shift
(
$elements
);
if
(
!
self
::
isModuleEnabled
(
$module
))
{
return
;
// module not enabled, avoid giving out any information at all
}
$file
=
self
::
getModuleDir
(
$module
)
.
'/lib/'
.
implode
(
'/'
,
$elements
)
.
'.php'
;
if
(
file_exists
(
$file
))
{
require_once
(
$file
);
}
}
/**
* Retrieve the base directory for a module.
...
...
@@ -32,7 +111,7 @@ class SimpleSAML_Module
/**
* Determine whether a module is enabled.
*
* Will return false if the given module doesn't exist
s
.
* Will return false if the given module doesn't exist.
*
* @param string $module Name of the module
*
...
...
This diff is collapsed.
Click to expand it.
lib/_autoload_modules.php
+
3
−
80
View file @
a44588d7
<?php
/**
* This file
implement
s a autoloader for SimpleSAMLphp modules.
* This file
register
s a
n
autoloader for SimpleSAMLphp modules.
*
* @author Boy Baukema, SURFnet
* @author Jaime Perez <jaime.perez@uninett.no>, UNINETT
* @package SimpleSAMLphp
*/
/**
* Autoload function for SimpleSAMLphp modules following PSR-0.
*
* @param string $className Name of the class.
*
* TODO: this autoloader should be removed once everything has been migrated to namespaces.
*/
function
SimpleSAML_autoload_psr0
(
$className
)
{
$modulePrefixLength
=
strlen
(
'sspmod_'
);
$classPrefix
=
substr
(
$className
,
0
,
$modulePrefixLength
);
if
(
$classPrefix
!==
'sspmod_'
)
{
return
;
}
$modNameEnd
=
strpos
(
$className
,
'_'
,
$modulePrefixLength
);
$module
=
substr
(
$className
,
$modulePrefixLength
,
$modNameEnd
-
$modulePrefixLength
);
$path
=
explode
(
'_'
,
substr
(
$className
,
$modNameEnd
+
1
));
if
(
!
SimpleSAML_Module
::
isModuleEnabled
(
$module
))
{
return
;
}
$file
=
SimpleSAML_Module
::
getModuleDir
(
$module
)
.
'/lib/'
.
join
(
'/'
,
$path
)
.
'.php'
;
if
(
file_exists
(
$file
))
{
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
(
"The class '
$className
' is now using namespaces, please use 'SimpleSAML
\\
Module
\\
$module
\\
"
.
"
$nspath
' instead."
);
class_alias
(
"SimpleSAML
\\
Module
\\
$module
\\
$nspath
"
,
$className
);
}
}
}
/**
* Autoload function for SimpleSAMLphp modules following PSR-4.
*
* @param string $className Name of the class.
*/
function
SimpleSAML_autoload_psr4
(
$className
)
{
$elements
=
explode
(
'\\'
,
$className
);
if
(
$elements
[
0
]
===
''
)
{
// class name starting with /, ignore
array_shift
(
$elements
);
}
if
(
count
(
$elements
)
<
4
)
{
return
;
// it can't be a module
}
if
(
array_shift
(
$elements
)
!==
'SimpleSAML'
)
{
return
;
// the first element is not "SimpleSAML"
}
if
(
array_shift
(
$elements
)
!==
'Module'
)
{
return
;
// the second element is not "module"
}
// this is a SimpleSAMLphp module following PSR-4
$module
=
array_shift
(
$elements
);
if
(
!
SimpleSAML_Module
::
isModuleEnabled
(
$module
))
{
return
;
// module not enabled, avoid giving out any information at all
}
$file
=
SimpleSAML_Module
::
getModuleDir
(
$module
)
.
'/lib/'
.
implode
(
'/'
,
$elements
)
.
'.php'
;
if
(
file_exists
(
$file
))
{
require_once
(
$file
);
}
}
spl_autoload_register
(
'SimpleSAML_autoload_psr0'
);
spl_autoload_register
(
'SimpleSAML_autoload_psr4'
);
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