This repository has been archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Allow to load module classes with PSR-0 autoloader
- Loading branch information
1 parent
43643ab
commit b55c862
Showing
6 changed files
with
205 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Application; | ||
|
||
use Zend\Mvc\ModuleRouteListener; | ||
|
||
class Module | ||
{ | ||
public function onBootstrap($e) | ||
{ | ||
$e->getApplication()->getServiceManager()->get('translator'); | ||
$eventManager = $e->getApplication()->getEventManager(); | ||
$moduleRouteListener = new ModuleRouteListener(); | ||
$moduleRouteListener->attach($eventManager); | ||
} | ||
|
||
public function getConfig() | ||
{ | ||
return include __DIR__ . '/../../config/module.config.php'; | ||
} | ||
|
||
public function getAutoloaderConfig() | ||
{ | ||
return array( | ||
'Zend\Loader\ClassMapAutoloader' => array( | ||
__DIR__ . '/../../autoload_classmap.php', | ||
), | ||
'Zend\Loader\StandardAutoloader' => array( | ||
'namespaces' => array( | ||
__NAMESPACE__ => __DIR__, | ||
), | ||
), | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,10 @@ | ||
<?php | ||
|
||
namespace User; | ||
|
||
use ZfcBase\Module\AbstractModule; | ||
use Zend\ModuleManager\ModuleManager; | ||
use Zend\Mvc\ApplicationInterface; | ||
|
||
class Module extends AbstractModule | ||
{ | ||
public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $app) | ||
{ | ||
$em = $app->getEventManager()->getSharedManager(); | ||
$sm = $app->getServiceManager(); | ||
|
||
$em->attach('ScnSocialAuth\Authentication\Adapter\HybridAuth','githubToLocalUser', function ($e) { | ||
$localUser = $e->getTarget(); | ||
$userProfile = $e->getParam('userProfile'); | ||
$nickname = substr( | ||
$userProfile->profileURL, | ||
(strrpos($userProfile->profileURL, "/") + 1) | ||
); | ||
$localUser->setUsername($nickname); | ||
$localUser->setPhotoUrl($userProfile->photoURL); | ||
}); | ||
|
||
$em->attach('EdpGithub\Client', 'api', function ($e) use ($sm) { | ||
$hybridAuth = $sm->get('HybridAuth'); | ||
$adapter = $hybridAuth->getAdapter('github'); | ||
|
||
if($adapter->isUserConnected()) { | ||
$token = $adapter->getAccessToken(); | ||
$client = $e->getTarget(); | ||
$client->authenticate('url_token', $token['access_token']); | ||
} | ||
} ); | ||
} | ||
|
||
public function getServiceConfig() | ||
{ | ||
return array( | ||
'factories' => array( | ||
'zfcuser_user_mapper' => function ($sm) { | ||
$options = $sm->get('zfcuser_module_options'); | ||
$mapper = new Mapper\User(); | ||
$mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter')); | ||
$entityClass = $options->getUserEntityClass(); | ||
$mapper->setEntityPrototype(new $entityClass); | ||
$mapper->setHydrator(new Mapper\UserHydrator()); | ||
return $mapper; | ||
}, | ||
), | ||
); | ||
} | ||
|
||
public function getDir() | ||
{ | ||
return __DIR__; | ||
} | ||
|
||
public function getNamespace() | ||
{ | ||
return __NAMESPACE__; | ||
} | ||
} | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/ZendSkeletonModule for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
require_once __DIR__ . '/src/User/Module.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace User; | ||
|
||
use ZfcBase\Module\AbstractModule; | ||
use Zend\ModuleManager\ModuleManager; | ||
use Zend\Mvc\ApplicationInterface; | ||
|
||
class Module extends AbstractModule | ||
{ | ||
public function bootstrap(ModuleManager $moduleManager, ApplicationInterface $app) | ||
{ | ||
$em = $app->getEventManager()->getSharedManager(); | ||
$sm = $app->getServiceManager(); | ||
|
||
$em->attach('ScnSocialAuth\Authentication\Adapter\HybridAuth','githubToLocalUser', function ($e) { | ||
$localUser = $e->getTarget(); | ||
$userProfile = $e->getParam('userProfile'); | ||
$nickname = substr( | ||
$userProfile->profileURL, | ||
(strrpos($userProfile->profileURL, "/") + 1) | ||
); | ||
$localUser->setUsername($nickname); | ||
$localUser->setPhotoUrl($userProfile->photoURL); | ||
}); | ||
|
||
$em->attach('EdpGithub\Client', 'api', function ($e) use ($sm) { | ||
$hybridAuth = $sm->get('HybridAuth'); | ||
$adapter = $hybridAuth->getAdapter('github'); | ||
|
||
if($adapter->isUserConnected()) { | ||
$token = $adapter->getAccessToken(); | ||
$client = $e->getTarget(); | ||
$client->authenticate('url_token', $token['access_token']); | ||
} | ||
} ); | ||
} | ||
|
||
public function getServiceConfig() | ||
{ | ||
return array( | ||
'factories' => array( | ||
'zfcuser_user_mapper' => function ($sm) { | ||
$options = $sm->get('zfcuser_module_options'); | ||
$mapper = new Mapper\User(); | ||
$mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter')); | ||
$entityClass = $options->getUserEntityClass(); | ||
$mapper->setEntityPrototype(new $entityClass); | ||
$mapper->setHydrator(new Mapper\UserHydrator()); | ||
return $mapper; | ||
}, | ||
), | ||
); | ||
} | ||
|
||
public function getDir() | ||
{ | ||
return __DIR__ . '/../../'; | ||
} | ||
|
||
public function getNamespace() | ||
{ | ||
return __NAMESPACE__; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/ZendSkeletonModule for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZfModule; | ||
|
||
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; | ||
use Zend\Mvc\ModuleRouteListener; | ||
use Zend\Cache\StorageFactory; | ||
|
||
class Module implements AutoloaderProviderInterface | ||
{ | ||
public function getAutoloaderConfig() | ||
{ | ||
return array( | ||
'Zend\Loader\ClassMapAutoloader' => array( | ||
__DIR__ . '/../../autoload_classmap.php', | ||
), | ||
'Zend\Loader\StandardAutoloader' => array( | ||
'namespaces' => array( | ||
__NAMESPACE__ => __DIR__, | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function getConfig() | ||
{ | ||
return include __DIR__ . '/../../config/module.config.php'; | ||
} | ||
|
||
public function onBootstrap($e) | ||
{ | ||
// You may not need to do this if you're doing it elsewhere in your | ||
// application | ||
$eventManager = $e->getApplication()->getEventManager(); | ||
$moduleRouteListener = new ModuleRouteListener(); | ||
$moduleRouteListener->attach($eventManager); | ||
} | ||
|
||
public function getServiceConfig() | ||
{ | ||
return array( | ||
'factories' => array( | ||
'zfmodule_cache' => function ($sm) { | ||
$config = $sm->get('Config'); | ||
$storage = StorageFactory::factory($config['zfmodule']['cache']); | ||
|
||
return $storage; | ||
}, | ||
'zfmodule_mapper_module' => function ($sm) { | ||
$mapper = new Mapper\Module(); | ||
$mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter')); | ||
$mapper->setEntityPrototype(new Entity\Module); | ||
$mapper->setHydrator(new Mapper\ModuleHydrator()); | ||
return $mapper; | ||
}, | ||
'zfmodule_service_module' => function ($sm) { | ||
$service = new Service\Module; | ||
return $service; | ||
}, | ||
'zfmodule_service_repository' => function ($sm) { | ||
$service = new Service\Repository; | ||
$service->setApi($sm->get('EdpGithub\Client')); | ||
return $service; | ||
}, | ||
/*'github_client' => function ($sm) { | ||
$hybridAuth = $sm->get('HybridAuth'); | ||
$adapter = $hybridAuth->getAdapter('github'); | ||
$token = $adapter->getAccessToken(); | ||
$client = $sm->get('EdpGithubClient'); | ||
$client->authenticate('url_token',$token['access_token'], null); | ||
return $client; | ||
}*/ | ||
), | ||
); | ||
} | ||
} |