Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to provide additional arguments to Prince CLI call #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/Kodebyraaet/Prince/Prince.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Kodebyraaet\Prince;
<?php

namespace Kodebyraaet\Prince;

use File;
use Illuminate\View\View;
Expand Down Expand Up @@ -30,7 +32,7 @@ class Prince implements PrinceInterface
*
* @var string
*/
private $arguments;
public $arguments;

/**
* Echo out error messages.
Expand Down Expand Up @@ -64,13 +66,26 @@ public function __construct(Application $app)

$this->executable = getenv('PRINCE_EXECUTABLE_PATH') ? getenv('PRINCE_EXECUTABLE_PATH') : '/usr/bin/prince';

$this->arguments = ' --server -i "html" --silent -';
$this->arguments = ['--server', '-i "html"', '--silent', '-'];

$this->displayErrors = true;

$this->useUtf8 = false;
}

/**
* Sets command line arguments
*
* @param Array $arguments
* @return $this
*/
public function setArguments($arguments)
{
$this->arguments = array_merge($this->arguments, $arguments);

return $this;
}

/**
* Takes a View and returns $this to further chain methods on.
*
Expand Down Expand Up @@ -115,11 +130,11 @@ public function download($filename = null, $attachment = false)
'Content-Type' => 'application/pdf',
];

if($filename != null) {
if($attachment) {
$headers['Content-Disposition'] = 'attachment; filename="' . $filename .'"';
if ($filename != null) {
if ($attachment) {
$headers['Content-Disposition'] = 'attachment; filename="' . $filename . '"';
} else {
$headers['Content-Disposition'] = 'inline; filename="' . $filename .'"';
$headers['Content-Disposition'] = 'inline; filename="' . $filename . '"';
}
}

Expand Down Expand Up @@ -167,7 +182,7 @@ private function generate()

// Tries to open up a process of prince at $this->executable path,
// appends $this->arguments to the executable call.
if (!is_resource($process = proc_open($this->executable . $this->arguments, $descriptorSpec, $pipes))) {
if (!is_resource($process = proc_open($this->executable . ' ' . implode(' ', $this->arguments), $descriptorSpec, $pipes))) {
throw new UnableToExecute('Unable to open a prince executable at path ' . $this->executable . '.');
}

Expand Down Expand Up @@ -235,5 +250,4 @@ protected function reset()
{
$this->markup = '';
}

}