示例#1
0
     *
     */
    public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            $params = $params['0'];
            if (empty($params['sftp_host']) || empty($params['sftp_port']) || empty($params['sftp_root'])) {
                return false;
            }
            // we require either a private key file OR a username and password
            if (empty($params['sftp_password']) && empty($params['sftp_username']) && empty($params['sftp_private_key'])) {
                return false;
            }
            $filesystem = new Remote(Sftp::getRemoteClient($params));
            $return = true;
            $filesystem->getAdapter()->listContents();
            if (!$filesystem->getAdapter()->isConnected()) {
                $return = false;
            }
            $filesystem->getAdapter()->disconnect();
            return $return;
        } catch (\Exception $e) {
            return false;
        }
    }
}
$rule = new Connect();
\JaegerApp\Validate::addrule($rule->getName(), array($rule, 'validate'), $rule->getErrorMessage());
示例#2
0
 /**
  * Tests the name of the rule
  */
 public function testName()
 {
     $dir = new Connect();
     $this->assertEquals($dir->getName(), 'sftp_connect');
 }