Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
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));
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * @expectedException Zend\Validator\Exception\InvalidArgumentException
  */
 public function testUriHandlerInvalidTypeThrowsException()
 {
     $this->validator->setUriHandler(new \stdClass());
 }
Exemplo n.º 5
0
 /**
  * Ensures that getMessages() returns expected default value
  *
  * @return void
  */
 public function testGetMessages()
 {
     $this->assertEquals(array(), $this->validator->getMessages());
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 public function getUrlValidator()
 {
     if ($this->urlValidator === NULL) {
         $validator = new Uri();
         $validator->setOptions($this->getUrlConfig())->setMessages([Uri::INVALID => "Invalid type given. String expected", Uri::NOT_URI => "The input does not appear to be a valid Uri"]);
         $this->setUrlValidator($validator);
     }
     return $this->urlValidator;
 }
Exemplo n.º 8
0
 /**
  * @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;
 }