Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
auth
Commits
4183602a
Commit
4183602a
authored
Apr 25, 2013
by
Bertrand Gauthier
Browse files
Factory abstraite qui était passée à l'as!
parent
86a69410
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/UnicaenAuth/Authentication/Adapter/AbstractFactory.php
0 → 100644
View file @
4183602a
<?php
namespace
UnicaenAuth\Authentication\Adapter
;
use
UnicaenApp\Exception
;
use
UnicaenAuth\Authentication\Adapter\Cas
;
use
UnicaenAuth\Authentication\Adapter\Db
;
use
UnicaenAuth\Authentication\Adapter\Ldap
;
use
Zend\ServiceManager\AbstractFactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
/**
* Description of AbstractFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
AbstractFactory
implements
AbstractFactoryInterface
{
/**
* Determine if we can create a service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return bool
*/
public
function
canCreateServiceWithName
(
ServiceLocatorInterface
$serviceLocator
,
$name
,
$requestedName
)
{
return
strpos
(
$requestedName
,
__NAMESPACE__
)
===
0
&&
class_exists
(
$requestedName
);
}
/**
* Create service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return mixed
*/
public
function
createServiceWithName
(
ServiceLocatorInterface
$serviceLocator
,
$name
,
$requestedName
)
{
switch
(
$requestedName
)
{
case
__NAMESPACE__
.
'\Ldap'
:
$adapter
=
new
Ldap
();
break
;
case
__NAMESPACE__
.
'\Db'
:
$adapter
=
new
Db
();
break
;
case
__NAMESPACE__
.
'\Cas'
:
$adapter
=
new
Cas
();
break
;
default
:
throw
new
Exception
(
"Service demandé inattendu : '
$requestedName
'!"
);
break
;
}
if
(
$adapter
instanceof
\
Zend\EventManager\EventManagerAwareInterface
)
{
$userService
=
$serviceLocator
->
get
(
'unicaen-auth_user_service'
);
$adapter
->
setEventManager
(
$serviceLocator
->
get
(
'event_manager'
));
$adapter
->
getEventManager
()
->
attach
(
'userAuthenticated'
,
array
(
$userService
,
'userAuthenticated'
),
1
);
}
return
$adapter
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment