-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
116 lines (105 loc) · 4.51 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require_once __DIR__.'/lib/silex.phar';
$app = new Silex\Application();
$app['debug'] = true;
//Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'//views',
'twig.class_path' => __DIR__.'/lib/silex/vendor/twig/lib',
));
//Monolog
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.logfile' => __DIR__.'/development.log',
'monolog.class_path' => __DIR__.'/lib/silex/vendor/monolog/src',
));
//UrlGeneratorServiceProvider
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
//Authentification :
//!TODO Encapsulate in Silex ;-)
$app['autoloader']->registerNamespace('MultiAuth', __DIR__.'/lib/');
$app['MultiAuth']=function()use($app){
require(__DIR__.'/configs/auth.php');
return new MultiAuth\MultiAuth(
array(
//'loginPage'=>'/login',
'hybridAuth'=>$hybridAuthConfigs,
'loginPage'=>'/login',
'loginProcess'=>'/loginProcess',
'accountsFromProviderIdFunction'=>
function($providerId,$userId) use($app){
$query = $app['doctrine.orm.em']->createQuery('SELECT u
FROM \Models\User u LEFT JOIN u.providers p
WHERE p.providerId = :providerId
AND p.userId = :userId');
$query->setParameters(array(
'providerId' => $providerId,
'userId' => $userId,
));
$array = $query->getResult();
return $array;
},
'getAccountFunction'=> function($id) use($app){
if( isset( $id ) ){
return $app['doctrine.orm.em']->find('\Models\User',$id);
}
return null;
},
'createAccountFunction'=>
function() use($app){
$user = new \Models\User();
$em = $app['doctrine.orm.em'];
$em->persist($user);
$em->flush();
return $user;
},
'addProviderToAccount'=>
function($account, $providerId, $userId, $datas)use($app){
$provider = new \Models\Provider();
$provider->setProviderId($providerId);
$provider->setDatas($datas);
$provider->setUserId($userId);
$em = $app['doctrine.orm.em'];
$em->persist($provider);
$account->addProvider($provider);
$em->flush();
return $user;
},
)
);
};
//Doctrine ORM :
require_once __DIR__.'/lib/silexextentions/silex_doctrine_extension.phar';
$app['autoloader']->registerNamespace('Models', __DIR__);
$app->register(new Knp\Silex\ServiceProvider\DoctrineServiceProvider(), array(
'doctrine.dbal.connection_options' => array(
'driver' => 'pdo_mysql',
'dbname' => 'MultiAuth',
'host' => 'localhost',
'user'=>'root',
'password'=>'root',
),
'doctrine.orm' => true,
'doctrine.orm.entities' => array(
array(
'type' => 'annotation',
'path' => __DIR__.'/Models',
'namespace' => 'Models'
),
),
'doctrine.common.class_path' => __DIR__.'/lib/doctrine/lib/vendor/doctrine-common/lib',
'doctrine.dbal.class_path' => __DIR__.'/lib/doctrine/lib/vendor/doctrine-dbal/lib',
'doctrine.orm.class_path' => __DIR__.'/lib/doctrine/lib/',
//'doctrine.common.class_path' => __DIR__.'/lib/silexextentions/vendor/doctrine-common/lib',
//'doctrine.dbal.class_path' => __DIR__.'/lib/silexextentions/vendor/doctrine-dbal/lib',
//'doctrine.orm.class_path' => __DIR__.'/lib/silexextentions/vendor/doctrine/lib',
));
use Doctrine\Common\Annotations\AnnotationRegistry;
AnnotationRegistry::registerLoader(function($class) use ($loader) {
$loader->loadClass($class);
return class_exists($class, false);
});
AnnotationRegistry::registerFile(__DIR__.'/lib/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
//
//var_dump($app);
//var_dump($app['doctrine.orm.em']->getRepository('\Models\User'));
?>