コード例 #1
0
ファイル: Readable.php プロジェクト: jaeger-app/validate-s3
     * (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['s3_access_key']) || empty($params['s3_secret_key']) || empty($params['s3_bucket'])) {
                return false;
            }
            $region = $params['s3_region'] ? $params['s3_region'] : '';
            $client = m62S3::getRemoteClient($params['s3_access_key'], $params['s3_secret_key'], $region);
            if ($client->doesBucketExist($params['s3_bucket'])) {
                $filesystem = new Remote(new m62S3($client, $params['s3_bucket']));
                $filesystem->getAdapter()->listContents();
                return true;
            }
        } catch (\Exception $e) {
            return false;
        }
    }
}
$rule = new Readable();
\JaegerApp\Validate::addrule($rule->getName(), array($rule, 'validate'), $rule->getErrorMessage());
コード例 #2
0
 /**
  * Tests the name of the rule
  */
 public function testName()
 {
     $dir = new Readable();
     $this->assertEquals($dir->getName(), 's3_bucket_readable');
 }