Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * 
  * @ignore
  *
  * @see \mithra62\Validate\RuleInterface::validate()
  */
 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;
         }
         $local = new Remote(new Local(dirname($this->getTestFilePath())));
         $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'])) {
             $contents = $local->read($this->test_file);
             $filesystem = new Remote(new m62S3($client, $params['s3_bucket']));
             if ($filesystem->has($this->test_file)) {
                 $filesystem->delete($this->test_file);
             } else {
                 if ($filesystem->write($this->test_file, $contents)) {
                     $filesystem->delete($this->test_file);
                 }
             }
             return true;
         }
     } catch (\Exception $e) {
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * 
  * @ignore
  *
  * @see \mithra62\Validate\RuleInterface::validate()
  */
 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'])) {
             return false;
         }
         $region = $params['s3_region'] ? $params['s3_region'] : '';
         $client = m62S3::getRemoteClient($params['s3_access_key'], $params['s3_secret_key'], $region);
         $client->listBuckets();
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * (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;
     }
 }
Ejemplo n.º 4
0
 public function testServiceInstance()
 {
     $creds = $this->getS3Creds();
     $s3 = S3::getRemoteClient($creds['s3_access_key'], $creds['s3_secret_key']);
     $this->assertInstanceOf('Aws\\S3\\S3Client', $s3);
 }