Beispiel #1
0
    protected $error_message = 'Can\'t connect to {field}';
    /**
     * (non-PHPdoc)
     * 
     * @see \mithra62\Validate\RuleInterface::validate()
     * @ignore
     *
     */
    public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            $params = $params['0'];
            if (empty($params['ftp_hostname']) || empty($params['ftp_password']) || empty($params['ftp_username']) || empty($params['ftp_port'])) {
                return false;
            }
            $filesystem = new Remote(Ftp::getRemoteClient($params));
            if (!$filesystem->getAdapter()->listContents()) {
                return false;
            }
            $filesystem->getAdapter()->disconnect();
            return true;
        } catch (\Exception $e) {
            return false;
        }
    }
}
$rule = new Connect();
\JaegerApp\Validate::addrule($rule->getName(), array($rule, 'validate'), $rule->getErrorMessage());
 /**
  * Tests the name of the rule
  */
 public function testName()
 {
     $dir = new Connect();
     $this->assertEquals($dir->getName(), 'ftp_connect');
 }