Example #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['gcs_access_key']) || empty($params['gcs_secret_key']) || empty($params['gcs_bucket'])) {
             return false;
         }
         $local = new Remote(new Local(dirname($this->getTestFilePath())));
         $client = m62Gcs::getRemoteClient($params['gcs_access_key'], $params['gcs_secret_key']);
         if ($client->doesBucketExist($params['gcs_bucket'])) {
             $contents = $local->read($this->test_file);
             $filesystem = new Remote(new m62Gcs($client, $params['gcs_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;
     }
 }
Example #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['gcs_access_key']) || empty($params['gcs_secret_key'])) {
             return false;
         }
         $client = m62Gcs::getRemoteClient($params['gcs_access_key'], $params['gcs_secret_key']);
         $client->listBuckets();
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Example #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['gcs_access_key']) || empty($params['gcs_secret_key']) || empty($params['gcs_bucket'])) {
             return false;
         }
         $client = m62Gcs::getRemoteClient($params['gcs_access_key'], $params['gcs_secret_key']);
         if ($client->doesBucketExist($params['gcs_bucket'])) {
             $filesystem = new Remote(new m62Gcs($client, $params['gcs_bucket']));
             $filesystem->getAdapter()->listContents();
             return true;
         }
     } catch (\Exception $e) {
         return false;
     }
 }
Example #4
0
 public function testGetRemoteClient()
 {
     $settings = $this->getGcsCreds();
     $this->assertInstanceOf('\\Aws\\S3\\S3Client', Gcs::getRemoteClient($settings['gcs_access_key'], $settings['gcs_secret_key']));
 }