private function loadTokenGrantTypeProcessors(array $config, ContainerBuilder $container)
 {
     $builderDef = $container->getDefinition('akamon.oauth2_server.server_builder');
     f\each(function ($id, $name) use($builderDef) {
         $builderDef->addMethodCall('addTokenGrantTypeProcessor', [$name, new Reference($id)]);
     }, f\map(f\key('id'), $config));
 }
 public function __construct($scopes = array())
 {
     $createScope = function ($name) {
         return new Scope($name);
     };
     f\each([$this, 'add'], f\map($createScope, $scopes));
 }
 /**
  * @Given /^there are oauth2 clients:$/
  */
 public function thereAreOauthClients(TableNode $table)
 {
     $jsonDecode = function ($v) {
         return json_decode($v) ?: $v;
     };
     $clients = f\map(f\partial('felpado\\map', $jsonDecode), $table->getHash());
     f\each([$this, 'createOAuthClient'], $clients);
 }
Esempio n. 4
0
 /**
  * @dataProvider provideEach
  */
 public function testEach($coll)
 {
     $calls = array();
     f\each(function () use(&$calls) {
         $calls[] = func_get_args();
     }, $coll);
     $expected = array(array('o', 1), array('t', 2), array('th', 3));
     $this->assertSame($expected, $calls);
 }
Esempio n. 5
0
 /**
  * @Given /^there are oauth clients:$/
  */
 public function thereAreOauthClients(TableNode $table)
 {
     $jsonDecode = function ($v) {
         return json_decode($v) ?: $v;
     };
     $clients = f\map(f\partial('felpado\\map', $jsonDecode), $table->getHash());
     f\each(function ($params) {
         $this->getOAuthClientRepository()->add(new Client($params));
     }, $clients);
 }
Esempio n. 6
0
function benchmark()
{
    $testTime = function ($function) {
        $start = microtime(true);
        $function();
        $time = microtime(true) - $start;
        return $time;
    };
    $testCompare = function ($functions) use($testTime) {
        $times = f\map($testTime, $functions);
        $faster = min($times);
        $percentage = function ($time) use($faster) {
            return ['time' => $time, 'percentage' => $time / $faster];
        };
        $print = function ($time, $name) {
            return sprintf("%20s: %10f | %10f\n", $name, $time['time'], $time['percentage']);
        };
        f\map(f\compose('printf', $print), f\map($percentage, $times));
        echo "\n";
    };
    f\each($testCompare, benchmark_compares());
}
Esempio n. 7
0
 /**
  * @When /^I try to grant a token with the client "([^"]*)" and the user id "([^"]*)" and the scope "([^"]*)"$/
  */
 public function iTryToGrantATokenWithTheClientAndTheUserIdAndTheScope($clientName, $userId, $scope)
 {
     $client = $this->findClientByName($clientName);
     $this->apiContext->addHttpBasicAuthentication(f\get($client, 'id'), f\get($client, 'secret'));
     $inputData = ['grant_type' => 'direct', 'user_id' => $userId];
     if (f\not(is_null($scope))) {
         $inputData = f\assoc($inputData, 'scope', $scope);
     }
     f\each(function ($v, $k) {
         $this->getApiContext()->addRequestParameter($k, $v);
     }, $inputData);
     $this->iMakeAOauthTokenRequest();
 }
Esempio n. 8
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\Finder\Finder;
use felpado as f;
$src = __DIR__ . '/../src';
$finder = Finder::create()->name('*.php')->name('*.xml')->in($src);
$fixUses = f\partial('preg_replace', '/^(use Akamon\\\\OAuth2\\\\Server)(?:.+);$/m', '');
$fixNamespace = f\partial('preg_replace', '/(namespace Akamon\\\\OAuth2\\\\Server)(.+);/', '$1;');
$fixFullyQualifiedClasses = f\partial('preg_replace', '/(\\\\?Akamon\\\\OAuth2\\\\Server)(?:\\\\(\\w+))+(?!;)/m', '$1\\\\$2');
$fixTripleEof = function ($content) use(&$fixTripleEof) {
    $search = "/\n\n\n/m";
    $replace = f\partial('preg_replace', $search, "\n\n");
    return preg_match($search, $content) ? $fixTripleEof($replace($content)) : $content;
};
$fix = f\compose($fixTripleEof, $fixFullyQualifiedClasses, $fixUses, $fixNamespace);
$byePsr0 = function ($file) use($fix) {
    $newContent = $fix(file_get_contents($file));
    file_put_contents($file, $newContent);
};
f\each($byePsr0, $finder);
 private function assertLoadedRepositories($config)
 {
     f\each(function ($service, $what) {
         $this->assertSame($service, (string) $this->container->getAlias(sprintf('akamon.oauth2_server.%s_repository', $what)));
     }, $config['repositories']);
 }