Skip to content

Commit

Permalink
Merge pull request #5 from staempfli/magento-2-2
Browse files Browse the repository at this point in the history
Compatibility to Magento 2.2
  • Loading branch information
Marcel Hauri committed Mar 22, 2018
2 parents b327b0f + 0965e3e commit 97576c4
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 11 deletions.
Empty file modified Jenkinsfile 100644 → 100755
Empty file.
111 changes: 108 additions & 3 deletions Model/PdfResponse.php
@@ -1,7 +1,7 @@
<?php
namespace Staempfli\Pdf\Model;

use Magento\Framework\App\ResponseInterface;
use Magento\Framework\App\Response\HttpInterface as HttpResponseInterface;
use Staempfli\Pdf\Api\Medium;
use Staempfli\Pdf\Api\Options;
use Staempfli\Pdf\Api\OptionsFactory as PdfOptionsFactory;
Expand All @@ -14,9 +14,8 @@
* HTTP response must be created separately if desired
* (the PdfResult controller result implementation can be used for this)
*/
final class PdfResponse implements ResponseInterface, SourceDocument
final class PdfResponse implements HttpResponseInterface, SourceDocument
{

private $body;
/** @var Options */
private $pdfOptions;
Expand Down Expand Up @@ -57,4 +56,110 @@ public function printTo(Medium $medium)
$medium->printHtml($this->body, $this->pdfOptions);
}

/**
* Set HTTP response code
*
* @param int $code
* @return void
*/
public function setHttpResponseCode($code)
{
}

/**
* Get HTTP response code
*
* @return int
*/
public function getHttpResponseCode()
{
return 200;
}

/**
* Set a header
*
* If $replace is true, replaces any headers already defined with that $name.
*
* @param string $name
* @param string $value
* @param boolean $replace
* @return self
*/
public function setHeader($name, $value, $replace = false)
{
return $this;
}

/**
* Get header value by name
*
* Returns first found header by passed name.
* If header with specified name was not found returns false.
*
* @param string $name
* @return \Zend\Http\Header\HeaderInterface|bool
*/
public function getHeader($name)
{
return false;
}

/**
* Remove header by name from header stack
*
* @param string $name
* @return self
*/
public function clearHeader($name)
{
return $this;
}

/**
* Allow granular setting of HTTP response status code, version and phrase
*
* For example, a HTTP response as the following:
* HTTP 200 1.1 Your response has been served
* Can be set with the arguments
* $httpCode = 200
* $version = 1.1
* $phrase = 'Your response has been served'
*
* @param int|string $httpCode
* @param null|int|string $version
* @param null|string $phrase
* @return self
*/
public function setStatusHeader($httpCode, $version = null, $phrase = null)
{
return $this;
}

/**
* Set the response body to the given value
*
* Any previously set contents will be replaced by the new content.
*
* @param string $value
* @return self
*/
public function setBody($value)
{
return $this;
}

/**
* Set redirect URL
*
* Sets Location header and response code. Forces replacement of any prior redirects.
*
* @param string $url
* @param int $code
* @return self
*/
public function setRedirect($url, $code = 302)
{
return $this;
}
}
4 changes: 2 additions & 2 deletions Model/View/PageResultWithoutHttp.php
Expand Up @@ -2,7 +2,7 @@
namespace Staempfli\Pdf\Model\View;

use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\App\Response\HttpInterface as HttpResponseInterface;

/**
* This exposes the render() method of the original Page result object to allow calling it without using
Expand All @@ -13,7 +13,7 @@
*/
class PageResultWithoutHttp extends Page
{
public function renderNonHttpResult(ResponseInterface $response)
public function renderNonHttpResult(HttpResponseInterface $response)
{
\Magento\Framework\Profiler::start('LAYOUT');
\Magento\Framework\Profiler::start('layout_render');
Expand Down
6 changes: 3 additions & 3 deletions Model/View/PdfResult.php
Expand Up @@ -2,8 +2,8 @@
namespace Staempfli\Pdf\Model\View;

use Magento\Framework;
use Magento\Framework\App\Response\HttpInterface as HttpResponseInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\View\Result\Page as PageResult;
use Staempfli\Pdf\Api\Options;
use Staempfli\Pdf\Api\OptionsFactory;
use Staempfli\Pdf\Model\PdfFactory;
Expand Down Expand Up @@ -67,10 +67,10 @@ public function addPageOptions(Options $options)
/**
* Renders directly to HTTP response
*
* @param Framework\App\Response\Http|ResponseInterface $response
* @param HttpResponseInterface $response
* @return $this
*/
protected function render(ResponseInterface $response)
protected function render(HttpResponseInterface $response)
{
$this->preparePdfResponse($response, $this->renderPdf());

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -2,10 +2,10 @@
"name": "staempfli/magento2-module-pdf",
"description": "Staempfli PDF generator.",
"require": {
"php": "~5.6.0|~7.0.0",
"php": "~5.6.0|~7.0.0|~7.1.0",
"mikehaertl/phpwkhtmltopdf": "2.1.0",
"magento/framework": "~100.1.2",
"magento/module-backend": "~100.1.1"
"magento/framework": "~100.1.2|~101.0.0",
"magento/module-backend": "^100.1.1"
},
"require-dev": {
"mikey179/vfsStream": "^1.6"
Expand Down
Empty file modified docs/img/config.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified etc/module.xml 100644 → 100755
Empty file.
Empty file modified grumphp.yml 100644 → 100755
Empty file.
Empty file modified registration.php 100644 → 100755
Empty file.

0 comments on commit 97576c4

Please sign in to comment.