/** * @param string $path * @return \CultuurNet\Auth\Session */ public static function read($path) { if (!file_exists($path)) { return new Session(); } $json = file_get_contents($path); if (!$json) { return new Session(); } $data = json_decode($json); // @todo Throw an exception if unable to parse. if (null === $data && JSON_ERROR_NONE !== json_last_error()) { } self::validateSchema($data, $path); $session = new Session(); if (isset($data->baseUrls)) { foreach (get_object_vars($data->baseUrls) as $api => $baseUrl) { $session->setBaseUrl($api, $baseUrl); } } if (isset($data->consumer)) { $consumer = new ConsumerCredentials(); $consumer->setKey($data->consumer->key); $consumer->setSecret($data->consumer->secret); $session->setConsumerCredentials($consumer); } if (isset($data->user)) { $tokenCredentials = new TokenCredentials($data->user->token, $data->user->secret); $user = new User($data->user->id, $tokenCredentials); $session->setUser($user); } return $session; }