PayPal\Cache\AuthorizationCache::pull PHP Method

pull() public static method

If clientId is not provided, an array with all the tokens would be passed.
public static pull ( array | null $config = null, string $clientId = null ) : mixed | null
$config array | null
$clientId string
return mixed | null
    public static function pull($config = null, $clientId = null)
    {
        // Return if not enabled
        if (!self::isEnabled($config)) {
            return null;
        }
        $tokens = null;
        $cachePath = self::cachePath($config);
        if (file_exists($cachePath)) {
            // Read from the file
            $cachedToken = file_get_contents($cachePath);
            if ($cachedToken && JsonValidator::validate($cachedToken, true)) {
                $tokens = json_decode($cachedToken, true);
                if ($clientId && is_array($tokens) && array_key_exists($clientId, $tokens)) {
                    // If client Id is found, just send in that data only
                    return $tokens[$clientId];
                } elseif ($clientId) {
                    // If client Id is provided, but no key in persisted data found matching it.
                    return null;
                }
            }
        }
        return $tokens;
    }

Usage Example

 /**
  * @depends testCachePush
  */
 public function testCachePull()
 {
     $result = AuthorizationCache::pull(array('cache.enabled' => true, 'cache.FileName' => AuthorizationCacheTest::CACHE_FILE), 'clientId');
     $this->assertNotNull($result);
     $this->assertTrue(is_array($result));
     $this->assertEquals('clientId', $result['clientId']);
     $this->assertEquals('accessToken', $result['accessTokenEncrypted']);
     $this->assertEquals('tokenCreateTime', $result['tokenCreateTime']);
     $this->assertEquals('tokenExpiresIn', $result['tokenExpiresIn']);
     unlink(AuthorizationCacheTest::CACHE_FILE);
 }
All Usage Examples Of PayPal\Cache\AuthorizationCache::pull