Example #1
0
 protected function execute(InputInterface $in, OutputInterface $out)
 {
     $sessionFile = $in->getOption('session');
     if (NULL !== $sessionFile) {
         // @todo Catch JsonValidationException and show errors.
         $fileUtility = $this->getFileUtility();
         $sessionFile = $fileUtility->expandPath($sessionFile);
         $this->session = JsonSessionFile::read($sessionFile);
     } else {
         $this->session = new Session();
     }
     $defaults = $this->getDefaults();
     $consumer = $this->session->getConsumerCredentials();
     if (!$consumer) {
         $consumer = new ConsumerCredentials();
         $this->session->setConsumerCredentials($consumer);
     }
     $consumerKey = $in->getOption('consumer-key');
     if ($consumerKey) {
         $consumer->setKey($consumerKey);
     } elseif ('' == $consumer->getKey() && isset($defaults['consumer-key'])) {
         $consumer->setKey($defaults['consumer-key']);
     }
     $consumerSecret = $in->getOption('consumer-secret');
     if ($consumerSecret) {
         $consumer->setSecret($consumerSecret);
     } else {
         if ('' == $consumer->getSecret() && isset($defaults['consumer-secret'])) {
             $consumer->setSecret($defaults['consumer-secret']);
         }
     }
 }
Example #2
0
 /**
  * @param \CultuurNet\Auth\Session $session
  * @param string $path
  */
 public static function write(Session $session, $path)
 {
     $hash = array();
     $consumerCredentials = $session->getConsumerCredentials();
     if (NULL != $consumerCredentials) {
         $hash['consumer'] = array('key' => $consumerCredentials->getKey(), 'secret' => $consumerCredentials->getSecret());
     }
     $user = $session->getUser();
     if (NULL !== $user) {
         $hash['user'] = array('id' => $user->getId(), 'token' => $user->getTokenCredentials()->getToken(), 'secret' => $user->getTokenCredentials()->getSecret());
     }
     $baseUrls = $session->getBaseUrls();
     if (!empty($baseUrls)) {
         $hash['baseUrls'] = $baseUrls;
     }
     $json = json_encode($hash);
     // @todo Throw exception if unable to save.
     file_put_contents($path, $json);
 }