Пример #1
0
 /**
  *	Loads configuration from an array or a file.
  *
  *	@param array|string $config A configuration array, or a JSON
  *		configuration file.
  */
 public function load($config)
 {
     if (is_string($config) && file_exists($config)) {
         $json = file_get_contents($config);
         $config = Json::parse($json);
     }
     $this->configure($config);
 }
Пример #2
0
 /**
  *	Parses the given response depending on its format.
  *
  *	@param string $response Response.
  *	@param string $format Format.
  *	@return array Data.
  */
 protected function _parse($response, $format)
 {
     switch ($format) {
         case Format::json:
             return Json::parse($response);
         case Format::xml:
             return Xml::parse($response);
         default:
             throw new Exception('Unsupported response format.');
     }
 }
Пример #3
0
 /**
  *
  */
 public function testParseInvalid()
 {
     $this->setExpectedException('Exception');
     Json::parse($this->invalid);
 }
Пример #4
0
 /**
  *	Fetches embed information from the given endpoint.
  *
  *	@param string $endpoint Endpoint to fetch informations from.
  *	@param string $format Response format.
  *	@return Media Embed informations.
  */
 protected function _embedEndpoint($endpoint, $format)
 {
     $response = $this->_Http->get($endpoint);
     switch ($format) {
         case self::json:
             $data = Json::parse($response);
             break;
         case self::xml:
             $data = Xml::parse($response);
             break;
         default:
             throw new Exception('Unsupported response format.');
     }
     return new Media(Hash::reindex($data, ['author_name' => 'authorName', 'author_url' => 'authorUrl', 'provider_name' => 'providerName', 'provider_url' => 'providerUrl', 'cache_age' => 'cacheAge', 'thumbnail_url' => 'thumbnailUrl', 'thumbnail_width' => 'thumbnailWidth', 'thumbnail_height' => 'thumbnailHeight']));
 }