-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTwitterExtension.php
75 lines (62 loc) · 2.11 KB
/
TwitterExtension.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
<?php
/**
* This file is part of the Netrium Framework
*
* Copyright (c) 2015 Martin Sadovy (http://sodae.cz)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*/
namespace Netrium\Addons\Twitter;
use Nette;
use Nette\DI;
if (!class_exists('Nette\DI\CompilerExtension')) {
class_alias('Nette\Config\CompilerExtension', 'Nette\DI\CompilerExtension');
}
/**
* Twitter extension
*
* @author Martin Sadovy
*/
class TwitterExtension extends DI\CompilerExtension
{
public function loadConfiguration()
{
$config = $this->getConfig(array(
'authenticator.sessionNamespace' => 'Twitter'
));
if (!isset($config['consumerKey']) || !isset($config['consumerSecretKey'])) {
throw new Nette\InvalidArgumentException("Twitter extension requries 'consumerKey' and 'consumerSecretKey' parameters.");
}
$builder = $this->getContainerBuilder();
$api = $builder->addDefinition($this->prefix('api'));
$api->setClass('TwitterOAuth');
if (isset($config['accessKey']) && isset($config['accessSecret'])) {
$api->setFactory('@' . $this->prefix('factory') . '::create', array(
$config['accessKey'],
$config['accessSecret']
));
} else {
$api->setFactory('@' . $this->prefix('factory') . '::create');
}
if (Nette\Framework::VERSION_ID < 20100) {
$api->setShared(FALSE); // back compatibility with app build on Nette 2.0
}
$builder->addDefinition($this->prefix('factory'))
->setClass('Netrium\Addons\Twitter\ApiFactory', array(
$config['consumerKey'],
$config['consumerSecretKey']
));
$builder->addDefinition($this->prefix('authenticator.storage'))
->setClass('Netrium\Addons\Twitter\SessionStorage')
->setFactory(get_called_class() . '::createSessionStorage', array('@session', $config['authenticator.sessionNamespace']));
$builder->addDefinition($this->prefix('authenticator'))
->setClass('Netrium\Addons\Twitter\Authenticator', array(
'@' . $this->prefix('api'),
));
}
public static function createSessionStorage($session, $name)
{
return new SessionStorage($session->getSection($name));
}
}