コード例 #1
0
ファイル: RequestTest.php プロジェクト: navassouza/zf2
 public function testRequestAllowsSettingOfParameterContainer()
 {
     $request = new Request();
     $p = new \Zend\Stdlib\Parameters();
     $request->setQuery($p);
     $request->setPost($p);
     $request->setFile($p);
     $request->setServer($p);
     $request->setEnv($p);
     $this->assertSame($p, $request->getQuery());
     $this->assertSame($p, $request->getPost());
     $this->assertSame($p, $request->getFile());
     $this->assertSame($p, $request->getServer());
     $this->assertSame($p, $request->getEnv());
 }
コード例 #2
0
ファイル: SlideShare.php プロジェクト: robertodormepoco/zf2
 /**
  * Uploads the specified Slide show the the server
  *
  * @param Zend\Service\SlideShare\SlideShow $ss The slide show object representing the slide show to upload
  * @param boolean $makeSourcePublic Determines if the slide show's source file is public or not upon upload
  * @throws \Zend\Service\SlideShare\Exception
  * @return Zend\Service\SlideShare\SlideShow The passed Slide show object, with the new assigned ID provided
  */
 public function uploadSlideShow(SlideShow $ss, $makeSourcePublic = true)
 {
     $timestamp = time();
     $params = array('api_key' => $this->getApiKey(), 'ts' => $timestamp, 'hash' => sha1($this->getSharedSecret() . $timestamp), 'username' => $this->getUserName(), 'password' => $this->getPassword(), 'slideshow_title' => $ss->getTitle(), 'make_src_public' => $makeSourcePublic ? 'Y' : 'N');
     $description = $ss->getDescription();
     $tags = $ss->getTags();
     $filename = $ss->getFilename();
     if (!file_exists($filename) || !is_readable($filename)) {
         throw new Exception\InvalidArgumentException("Specified Slideshow for upload not found or unreadable");
     }
     if (!empty($description)) {
         $params['slideshow_description'] = $description;
     } else {
         $params['slideshow_description'] = "";
     }
     if (!empty($tags)) {
         $tmp = array();
         foreach ($tags as $tag) {
             $tmp[] = "\"{$tag}\"";
         }
         $params['slideshow_tags'] = implode(' ', $tmp);
     } else {
         $params['slideshow_tags'] = "";
     }
     $httpClient = $this->getHttpClient();
     $request = new HttpRequest();
     $request->setUri(self::SERVICE_UPLOAD_URI);
     $request->getPost()->fromArray($params);
     $request->setMethod(HttpRequest::METHOD_POST);
     $request->getFile()->set('slideshow_srcfile', $filename);
     $httpClient->setEncType(HttpClient::ENC_URLENCODED);
     try {
         $response = $httpClient->send();
     } catch (HttpException\ExceptionInterface $e) {
         throw new HttpException\RuntimeException("Service Request Failed: {$e->getMessage()}", 0, $e);
     }
     $sxe = simplexml_load_string($response->getBody());
     if ($sxe->getName() == "SlideShareServiceError") {
         $message = (string) $sxe->Message[0];
         list($code, $error_str) = explode(':', $message);
         throw new Exception\RuntimeException(trim($error_str), $code);
     }
     if (!$sxe->getName() == "SlideShowUploaded") {
         throw new Exception\RuntimeException("Unknown XML Respons Received");
     }
     $ss->setId((int) (string) $sxe->SlideShowID);
     return $ss;
 }