Skip to content

Commit dd4c974

Browse files
committed
initial commit
0 parents  commit dd4c974

File tree

6 files changed

+202
-0
lines changed

6 files changed

+202
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace XApi\ClientBundle\DependencyInjection;
13+
14+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
17+
/**
18+
* @author Christian Flothmann <[email protected]>
19+
*/
20+
class Configuration implements ConfigurationInterface
21+
{
22+
public function getConfigTreeBuilder()
23+
{
24+
$treeBuilder = new TreeBuilder();
25+
26+
$treeBuilder
27+
->root('xapi_client')
28+
->children()
29+
->arrayNode('clients')
30+
->prototype('array')
31+
->children()
32+
->scalarNode('base_url')->isRequired()->end()
33+
->arrayNode('basic_auth')
34+
->children()
35+
->scalarNode('username')->isRequired()->end()
36+
->scalarNode('password')->isRequired()->end()
37+
->end()
38+
->end()
39+
->arrayNode('oauth')
40+
->children()
41+
->scalarNode('consumer_key')->isRequired()->end()
42+
->scalarNode('consumer_secret')->isRequired()->end()
43+
->scalarNode('access_token')->isRequired()->end()
44+
->scalarNode('token_secret')->isRequired()->end()
45+
->end()
46+
->end()
47+
->end()
48+
->end()
49+
->end()
50+
->end()
51+
->end()
52+
;
53+
54+
return $treeBuilder;
55+
}
56+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace XApi\ClientBundle\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Extension\Extension;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
19+
/**
20+
* @author Christian Flothmann <[email protected]>
21+
*/
22+
class XApiClientExtension extends Extension
23+
{
24+
public function load(array $configs, ContainerBuilder $container)
25+
{
26+
$configuration = new Configuration();
27+
$config = $this->processConfiguration($configuration, $configs);
28+
29+
foreach ($config['clients'] as $name => $clientConfig) {
30+
$factory = new Definition('Xabbuh\XApi\Client\XApiClientBuilder');
31+
$factory->addMethodCall('setBaseUrl', array($clientConfig['base_url']));
32+
33+
if (isset($clientConfig['basic_auth'])) {
34+
$factory->addMethodCall('setAuth', array($clientConfig['basic_auth']['username'], $clientConfig['basic_auth']['password']));
35+
}
36+
37+
if (isset($clientConfig['oauth'])) {
38+
$factory->addMethodCall('setOAuthCredentials', array(
39+
$clientConfig['oauth']['consumer_key'],
40+
$clientConfig['oauth']['consumer_secret'],
41+
$clientConfig['oauth']['access_token'],
42+
$clientConfig['oauth']['token_secret'],
43+
));
44+
}
45+
46+
$container->setDefinition('xapi_client.factory.'.$name, $factory);
47+
48+
$client = new Definition('Xabbuh\XApi\Client\XApiClientInterface');
49+
$client->setFactory(array(new Reference('xapi_client.factory.'.$name), 'build'));
50+
$container->setDefinition('xapi_client.client.'.$name, $client);
51+
}
52+
}
53+
54+
public function getAlias()
55+
{
56+
return 'xapi_client';
57+
}
58+
}

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 Christian Flothmann
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

XApiClientBundle.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace XApi\ClientBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
use XApi\ClientBundle\DependencyInjection\XApiClientExtension;
16+
17+
/**
18+
* @author Christian Flothmann <[email protected]>
19+
*/
20+
class XApiClientBundle extends Bundle
21+
{
22+
public function getContainerExtension()
23+
{
24+
if (null === $this->extension) {
25+
$this->extension = new XApiClientExtension();
26+
}
27+
28+
if ($this->extension) {
29+
return $this->extension;
30+
}
31+
}
32+
}

composer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "php-xapi/client-bundle",
3+
"type": "symfony-bundle",
4+
"description": "Experience API (xAPI) client integration into the Symfony Framework",
5+
"keywords": ["xAPI", "Experience API", "Tin Can API", "client", "Symfony", "bundle"],
6+
"homepage": "https://github.com/php-xapi/client-bundle",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Christian Flothmann",
11+
"homepage": "https://github.com/xabbuh"
12+
}
13+
],
14+
"require": {
15+
"php": "^5.3 || ^7.0",
16+
"php-xapi/client": "^0.5",
17+
"symfony/config": "^2.7 || ^3.1",
18+
"symfony/dependency-injection": "^2.7 || ^3.1",
19+
"symfony/http-kernel": "^2.7 || ^3.1"
20+
},
21+
"require-dev": {
22+
"php-http/mock-client": "^0.3"
23+
},
24+
"minimum-stability": "dev",
25+
"autoload": {
26+
"psr-4": {
27+
"XApi\\ClientBundle\\": ""
28+
}
29+
},
30+
"extra": {
31+
"branch-alias": {
32+
"dev-master": "0.1.x-dev"
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)