예제 #1
0
/**
 * f\assoc_in($coll, $in, $value)
 *
 * Returns an array based on coll with value associated in the nested structure of in.
 *
 * f\assoc_in(array('a' => 1), array('b', 'b1'), 2);
 * => array('a' => 1, 'b' => array('b1' => 2))
 *
 * // does nothing without in
 * f\assoc_in(array('a' => 1), array(), 2);
 * => array('a' => 1)
 *
 * // supports infinite nesting
 * f\assoc_in(array(), array('a', 'a1', 'a1I', 'a1IA'), 1);
 * => array('a' => array('a1' => array('a1I' => array('a1IA' => 1))))
 */
function assoc_in($coll, $in, $value)
{
    if (empty($in)) {
        return $coll;
    }
    $array = f\to_array($coll);
    $current =& $array;
    foreach ($in as $k) {
        if (f\not(f\get_or($current, $k, null))) {
            $current = f\assoc($current, $k, array());
        }
        $current =& $current[$k];
    }
    $current = $value;
    return $array;
}
 /**
  * @return array An array of parameters.
  */
 public function create(Context $context)
 {
     $params = $this->delegate->create($context);
     $refreshToken = $this->refreshTokenCreator->create(f\get($params, 'access_token'));
     return f\assoc($params, 'refresh_token', f\get($refreshToken, 'token'));
 }
 private function filterParamsFromDomain($params)
 {
     return f\assoc($params, 'oauth2Id', f\get($params, 'id'));
 }
예제 #4
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();
 }
예제 #5
0
 /**
  * @dataProvider provideAssoc
  */
 public function testAssoc($expected, $coll, $key, $value)
 {
     $this->assertSame($expected, f\assoc($coll, $key, $value));
 }
예제 #6
0
 public function update(Client $client)
 {
     $this->allToFile(f\assoc($this->allFromFile(), f\get($client, 'id'), $client->getParams()));
 }
예제 #7
0
/**
 * f\rename_key($coll, $from, $to)
 *
 * Returns a new coll with a key renamed from from to to.
 *
 * f\rename_key(array('a' => 1), 'a', 'b')
 * => array('b' => 1)
 */
function rename_key($coll, $from, $to)
{
    return f\assoc(f\dissoc($coll, $from), $to, f\get($coll, $from));
}