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 findAll() { $newClient = function ($params) { return new Client($params); }; return f\map($newClient, $this->allFromFile()); }
public function __construct($scopes = array()) { $createScope = function ($name) { return new Scope($name); }; f\each([$this, 'add'], f\map($createScope, $scopes)); }
public function resolve(Context $context) { $resolver = function ($r) { return [$r, 'resolve']; }; $composed = call_user_func_array('felpado\\compose', f\reverse(f\map($resolver, $this->resolvers))); return $composed($context); }
/** * @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); }
/** * @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); }
public static function createFromString($string) { if ($string) { $createScope = function ($name) { return new Scope($name); }; $scopes = f\map($createScope, explode(' ', $string)); } else { $scopes = []; } return new ScopeCollection($scopes); }
function functions_info() { $functionFromFile = f\compose(f\partial('substr', f\_(), 0, -4), 'basename'); $getFunctions = function () use($functionFromFile) { $files = glob(__DIR__ . '/functions/*.php'); $keysMap = f\map($functionFromFile, $files); return f\rename_keys($files, $keysMap); }; $functions = $getFunctions(); $buildInfo = function ($file) use($functionFromFile) { $function = $functionFromFile($file); $code = file_get_contents($file); return array('name' => $function, 'file' => $file, 'code' => $code, 'doc' => function_doc_info_from_code($code)); }; return f\map($buildInfo, $functions); }
/** * f\validate_coll($coll, $paramRules) * * Returns the validation errors when validating coll with param rules. * * // validating existence * f\validate_coll(array(), array('a' => f\required(), 'b' => f\optional())); * => array('a' => 'required') * * // multiple errors * f\validate_coll(array(), array('a' => f\required(), 'b' => f\required())); * => array('a' => 'required', 'b' => 'required') * * // validator fn * f\validate_coll(array('a' => 1.0), array('a' => f\required('v' => 'is_int'))); * => array('a' => 'invalid') * * // without errors * f\validate_coll(array('a' => 1), array('a' => f\required('v' => 'is_int'))); * => array() */ function validate_coll($coll, $paramRules) { $validate = function ($paramRule, $key) use($coll) { if (f\not($paramRule instanceof param_rule)) { throw new \InvalidArgumentException('Param rules must be created with felpado\\required and felpado\\optional.'); } if (f\contains($coll, $key)) { if ($paramRule->getValidator()) { $value = f\get($coll, $key); if (f\not(is_null($value) && $paramRule instanceof optional)) { $isValid = f\validate($value, $paramRule->getValidator()); if (f\not($isValid)) { return 'invalid'; } } } } elseif ($paramRule instanceof required) { return 'required'; } return null; }; return f\filter_indexed('felpado\\identity', f\map($validate, $paramRules)); }
function benchmark_compares() { $number = 100; $array = range(1, $number); return ['map' => ['array_map' => function () use($array) { array_map(function () { }, $array); }, 'f/map' => function () use($array) { f\map(function () { }, $array); }], 'reduce' => ['array_reduce' => function () use($array) { array_reduce($array, function ($a, $b) { return $a + $b; }); }, 'f/reduce' => function () use($array) { f\reduce(function ($a, $b) { return $a + $b; }, $array); }], 'filter' => ['array_filter' => function () use($array) { array_filter($array, function ($v) { return $v % 2; }); }, 'f/filter' => function () use($array) { f\filter(function ($v) { return $v % 2; }, $array); }], 'rename_keys' => ['raw' => function () use($array) { $result = array(); foreach ($array as $key => $v) { $result['a' . $key] = $v; } }, 'f\\rename_keys' => function () use($array) { f\rename_keys($array, f\map(function ($k) { return 'a' . $k; }, $array)); }]]; }
private function parametersFromTable(TableNode $table) { return f\rename_keys(f\map(function ($v) { return f\first(f\rest($v)); }, $table->getRows()), f\map('felpado\\first', $table->getRows())); }
/** * @dataProvider provideMap */ public function testMap($exp, $coll, $fn) { $this->assertSame($exp, f\map($fn, $coll)); }