Exemple #1
0
 public function testUriHandlerThrowsExceptionInParseMethodNotValid()
 {
     $uriMock = $this->getMock('Zend\\Uri\\Uri');
     $uriMock->expects($this->once())->method('parse')->will($this->throwException(new InvalidArgumentException()));
     $this->validator->setUriHandler($uriMock);
     $this->assertFalse($this->validator->isValid('uri'));
 }
Exemple #2
0
 public function setBaseUrl($baseUrl)
 {
     $validator = new Uri();
     if ($validator->isValid($baseUrl)) {
         $this->baseUrl = $baseUrl;
     } else {
         $reasons = '';
         foreach ($validator->getMessages() as $message) {
             $reasons .= "{$message}\n";
         }
         throw new \Exception($reasons);
     }
 }
Exemple #3
0
 /**
  * Save upload editor
  *
  * @return void
  */
 public function save()
 {
     $url = $this->getRequest()->getPost()->get($this->getName());
     $value = array();
     if (!empty($url)) {
         $validator = new Uri(array('allowRelative' => false));
         if ($validator->isValid($url)) {
             $tinyUrl = file_get_contents('http://tinyurl.com/api-create.php?url=' . rawurlencode($url));
             $value = array($url, $tinyUrl);
         }
     }
     $this->setValue(serialize($value));
 }
Exemple #4
0
 public static function factory($url)
 {
     $video = new static();
     $validator = new UriValidator();
     if (!$validator->isValid($url)) {
         throw new Exception\InvalidArgumentException(sprintf('Input url format not correct'));
     }
     $video->setUrl($url);
     $urlHandler = $validator->getUriHandler();
     $host = strtolower($urlHandler->getHost());
     $adapters = $video->getAdapters();
     if (!isset($adapters[$host])) {
         return $video;
     }
     $adapterName = $adapters[$host];
     $adapterClass = false === strpos($adapterName, '\\') ? 'Video\\Service\\Adapter\\' . $adapterName : $adapterName;
     $video->setAdapter(new $adapterClass($url));
     return $video;
 }
Exemple #5
0
 /**
  *
  * @param  String:\Zend\Uri\Uri     $apiBaseUri
  * @throws InvalidArgumentException
  * @return \Klout\Klout
  */
 public function setApiBaseUri($apiBaseUri)
 {
     if (empty($apiBaseUri)) {
         throw new InvalidArgumentException('apiBaseUri cannot be empty().');
     }
     if ($apiBaseUri instanceof Uri) {
         // Convert the object to a string if necessary
         $apiBaseUri = $apiBaseUri->toString();
     } elseif (!is_string($apiBaseUri)) {
         throw new InvalidArgumentException('apiBaseUri must be a String or \\Zend\\Uri\\Uri.');
     }
     // Validate the apiBaseUri
     $validator = new ValidatorUri();
     $validator->setAllowRelative(false);
     if (!$validator->isValid($apiBaseUri)) {
         $errors = $validator->getMessages();
         $errorMessage = reset($errors);
         throw new InvalidArgumentException('apiBaseUri is invalid: ' . $errorMessage);
     }
     $this->apiBaseUri = $apiBaseUri;
     // Only create the client if one already exists.
     if (isset($this->client)) {
         $this->createClient();
     }
     return $this;
 }
 /**
  * @param string $photoUrl
  * @return Result
  */
 public function setPhotoUrl($photoUrl)
 {
     $photoUrl = (string) $photoUrl;
     if ($photoUrl) {
         $validator = new Uri(['allowRelative' => false]);
         if ($validator->isValid($photoUrl)) {
             $this->photoUrl = $photoUrl;
         } else {
             throw new InvalidUriException("Invalid profile url `{$photoUrl}`");
         }
     } else {
         $this->photoUrl = null;
     }
     return $this;
 }