/** * Tests the name of the rule */ public function testName() { $dir = new Readable(); $this->assertEquals($dir->getName(), 'gcs_bucket_readable'); }
/** * (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; } } } $rule = new Readable(); \JaegerApp\Validate::addrule($rule->getName(), array($rule, 'validate'), $rule->getErrorMessage());