/** * @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; }
/** * */ protected function resolveBaseUrl($api, InputInterface $in = NULL, $default = 'http://acc.uitid.be/uitid/rest') { if (NULL === $this->session) { // @todo throw exception as session isn't initialized yet } if ($in->hasOption($api . '-base-url')) { $baseUrl = $in->getOption($api . '-base-url'); } else { if ($in->hasOption('base-url')) { $baseUrl = $in->getOption('base-url'); } } if (isset($baseUrl)) { $this->session->setBaseUrl($api, $baseUrl); } else { if ('' == $this->session->getBaseUrl($api)) { $baseUrl = isset($this->defaults['base-url'][$api]) ? $this->defaults['base-url'][$api] : $default; $this->session->setBaseUrl($api, $baseUrl); } else { $baseUrl = $this->session->getBaseUrl($api); } } return $baseUrl; }