Ejemplo n.º 1
0
 /**
  * Create a lazy ask password getter with use context output and input interfaces
  *
  * @return CallablePasswordGetter
  */
 public static function createLazyGetter()
 {
     return new CallablePasswordGetter(function ($host, $user) {
         $context = Context::get();
         $output = $context->getOutput();
         $input = $context->getInput();
         $askPasswordGetter = new AskPasswordGetter($input, $output);
         return $askPasswordGetter->getPassword($host, $user);
     });
 }
Ejemplo n.º 2
0
 /**
  * Test create lazy ask password getter
  */
 public function testCreateLazyAskPasswordGetter()
 {
     $lazyGetter = AskPasswordGetter::createLazyGetter();
     $this->assertInstanceOf('Deployer\\Server\\Password\\CallablePasswordGetter', $lazyGetter);
     $context = $this->getMock('Deployer\\Task\\Context', ['getInput', 'getOutput'], [], '', false);
     $context->expects($this->any())->method('getInput')->will($this->returnValue($this->input));
     $context->expects($this->any())->method('getOutput')->will($this->returnValue($this->output));
     // Push own context
     Context::push($context);
     $lazyGetter->getPassword('host', 'user');
     // Pop own context
     Context::pop();
 }
Ejemplo n.º 3
0
 /**
  * Check password valid
  *
  * @param mixed $password
  *
  * @return mixed
  */
 private function checkPassword($password)
 {
     if (is_null($password)) {
         return AskPasswordGetter::createLazyGetter();
     }
     if (is_scalar($password)) {
         return $password;
     }
     if (is_object($password) && $password instanceof PasswordGetterInterface) {
         return $password;
     }
     // Invalid password
     throw new \InvalidArgumentException(sprintf('The password should be a string or PasswordGetterInterface instances, but "%s" given.', is_object($password) ? get_class($password) : gettype($password)));
 }