Skip to content

Commit 6a756a9

Browse files
committed
Format for PSR12
1 parent c7de32f commit 6a756a9

File tree

3 files changed

+63
-46
lines changed

3 files changed

+63
-46
lines changed

src/Facade.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
<?php
2+
23
namespace Barryvdh\DomPDF;
34

45
use Illuminate\Support\Facades\Facade as IlluminateFacade;
56

6-
class Facade extends IlluminateFacade {
7+
class Facade extends IlluminateFacade
8+
{
79

810
/**
911
* Get the registered name of the component.
1012
*
1113
* @return string
1214
*/
13-
protected static function getFacadeAccessor() { return 'dompdf.wrapper'; }
15+
protected static function getFacadeAccessor()
16+
{
17+
return 'dompdf.wrapper';
18+
}
1419

1520
/**
1621
* Resolve a new instance
@@ -19,8 +24,7 @@ public static function __callStatic($method, $args)
1924
{
2025
$instance = static::$app->make(static::getFacadeAccessor());
2126

22-
switch (count($args))
23-
{
27+
switch (count($args)) {
2428
case 0:
2529
return $instance->$method();
2630

@@ -40,6 +44,4 @@ public static function __callStatic($method, $args)
4044
return call_user_func_array(array($instance, $method), $args);
4145
}
4246
}
43-
44-
4547
}

src/PDF.php

+50-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Barryvdh\DomPDF;
34

45
use Dompdf\Dompdf;
@@ -15,7 +16,8 @@
1516
* @package laravel-dompdf
1617
* @author Barry vd. Heuvel
1718
*/
18-
class PDF{
19+
class PDF
20+
{
1921

2022
/** @var Dompdf */
2123
protected $dompdf;
@@ -39,7 +41,8 @@ class PDF{
3941
* @param \Illuminate\Filesystem\Filesystem $files
4042
* @param \Illuminate\Contracts\View\Factory $view
4143
*/
42-
public function __construct(Dompdf $dompdf, ConfigRepository $config, Filesystem $files, ViewFactory $view){
44+
public function __construct(Dompdf $dompdf, ConfigRepository $config, Filesystem $files, ViewFactory $view)
45+
{
4346
$this->dompdf = $dompdf;
4447
$this->config = $config;
4548
$this->files = $files;
@@ -53,7 +56,8 @@ public function __construct(Dompdf $dompdf, ConfigRepository $config, Filesystem
5356
*
5457
* @return Dompdf
5558
*/
56-
public function getDomPDF(){
59+
public function getDomPDF()
60+
{
5761
return $this->dompdf;
5862
}
5963

@@ -64,7 +68,8 @@ public function getDomPDF(){
6468
* @param string $orientation
6569
* @return $this
6670
*/
67-
public function setPaper($paper, $orientation = 'portrait'){
71+
public function setPaper($paper, $orientation = 'portrait')
72+
{
6873
$this->dompdf->setPaper($paper, $orientation);
6974
return $this;
7075
}
@@ -75,7 +80,8 @@ public function setPaper($paper, $orientation = 'portrait'){
7580
* @param bool $warnings
7681
* @return $this
7782
*/
78-
public function setWarnings($warnings){
83+
public function setWarnings($warnings)
84+
{
7985
$this->showWarnings = $warnings;
8086
return $this;
8187
}
@@ -87,7 +93,8 @@ public function setWarnings($warnings){
8793
* @param string $encoding Not used yet
8894
* @return static
8995
*/
90-
public function loadHTML($string, $encoding = null){
96+
public function loadHTML($string, $encoding = null)
97+
{
9198
$string = $this->convertEntities($string);
9299
$this->dompdf->loadHtml($string, $encoding);
93100
$this->rendered = false;
@@ -100,7 +107,8 @@ public function loadHTML($string, $encoding = null){
100107
* @param string $file
101108
* @return static
102109
*/
103-
public function loadFile($file){
110+
public function loadFile($file)
111+
{
104112
$this->dompdf->loadHtmlFile($file);
105113
$this->rendered = false;
106114
return $this;
@@ -112,8 +120,9 @@ public function loadFile($file){
112120
* @param array $info
113121
* @return static
114122
*/
115-
public function addInfo($info){
116-
foreach($info as $name=>$value){
123+
public function addInfo($info)
124+
{
125+
foreach ($info as $name => $value) {
117126
$this->dompdf->add_info($name, $value);
118127
}
119128
return $this;
@@ -128,7 +137,8 @@ public function addInfo($info){
128137
* @param string $encoding Not used yet
129138
* @return static
130139
*/
131-
public function loadView($view, $data = array(), $mergeData = array(), $encoding = null){
140+
public function loadView($view, $data = array(), $mergeData = array(), $encoding = null)
141+
{
132142
$html = $this->view->make($view, $data, $mergeData)->render();
133143
return $this->loadHTML($html, $encoding);
134144
}
@@ -139,7 +149,8 @@ public function loadView($view, $data = array(), $mergeData = array(), $encoding
139149
* @param array $options
140150
* @return static
141151
*/
142-
public function setOptions(array $options) {
152+
public function setOptions(array $options)
153+
{
143154
$options = new Options($options);
144155
$this->dompdf->setOptions($options);
145156
return $this;
@@ -150,8 +161,9 @@ public function setOptions(array $options) {
150161
*
151162
* @return string The rendered PDF as string
152163
*/
153-
public function output(){
154-
if(!$this->rendered){
164+
public function output()
165+
{
166+
if (!$this->rendered) {
155167
$this->render();
156168
}
157169
return $this->dompdf->output();
@@ -163,7 +175,8 @@ public function output(){
163175
* @param $filename
164176
* @return static
165177
*/
166-
public function save($filename){
178+
public function save($filename)
179+
{
167180
$this->files->put($filename, $this->output());
168181
return $this;
169182
}
@@ -174,11 +187,12 @@ public function save($filename){
174187
* @param string $filename
175188
* @return \Illuminate\Http\Response
176189
*/
177-
public function download($filename = 'document.pdf' ){
190+
public function download($filename = 'document.pdf')
191+
{
178192
$output = $this->output();
179193
return new Response($output, 200, array(
180194
'Content-Type' => 'application/pdf',
181-
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
195+
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
182196
'Content-Length' => strlen($output),
183197
));
184198
}
@@ -189,33 +203,35 @@ public function download($filename = 'document.pdf' ){
189203
* @param string $filename
190204
* @return \Illuminate\Http\Response
191205
*/
192-
public function stream($filename = 'document.pdf' ){
206+
public function stream($filename = 'document.pdf')
207+
{
193208
$output = $this->output();
194209
return new Response($output, 200, array(
195210
'Content-Type' => 'application/pdf',
196-
'Content-Disposition' => 'inline; filename="'.$filename.'"',
211+
'Content-Disposition' => 'inline; filename="' . $filename . '"',
197212
));
198213
}
199214

200215
/**
201216
* Render the PDF
202217
*/
203-
protected function render(){
204-
if(!$this->dompdf){
218+
protected function render()
219+
{
220+
if (!$this->dompdf) {
205221
throw new Exception('DOMPDF not created yet');
206222
}
207223

208224
$this->dompdf->render();
209225

210-
if ( $this->showWarnings ) {
226+
if ($this->showWarnings) {
211227
global $_dompdf_warnings;
212-
if(!empty($_dompdf_warnings) && count($_dompdf_warnings)){
228+
if (!empty($_dompdf_warnings) && count($_dompdf_warnings)) {
213229
$warnings = '';
214-
foreach ($_dompdf_warnings as $msg){
230+
foreach ($_dompdf_warnings as $msg) {
215231
$warnings .= $msg . "\n";
216232
}
217233
// $warnings .= $this->dompdf->get_canvas()->get_cpdf()->messages;
218-
if(!empty($warnings)){
234+
if (!empty($warnings)) {
219235
throw new Exception($warnings);
220236
}
221237
}
@@ -224,25 +240,26 @@ protected function render(){
224240
}
225241

226242

227-
public function setEncryption($password) {
228-
if (!$this->dompdf) {
229-
throw new Exception("DOMPDF not created yet");
230-
}
231-
$this->render();
232-
return $this->dompdf->getCanvas()->get_cpdf()->setEncryption("pass", $password);
243+
public function setEncryption($password)
244+
{
245+
if (!$this->dompdf) {
246+
throw new Exception("DOMPDF not created yet");
247+
}
248+
$this->render();
249+
return $this->dompdf->getCanvas()->get_cpdf()->setEncryption("pass", $password);
233250
}
234251

235252

236-
protected function convertEntities($subject){
253+
protected function convertEntities($subject)
254+
{
237255
$entities = array(
238256
'' => '&#0128;',
239257
'£' => '&pound;',
240258
);
241259

242-
foreach($entities as $search => $replace){
260+
foreach ($entities as $search => $replace) {
243261
$subject = str_replace($search, $replace, $subject);
244262
}
245263
return $subject;
246264
}
247-
248265
}

src/ServiceProvider.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Barryvdh\DomPDF;
34

45
use Dompdf\Dompdf;
@@ -24,10 +25,10 @@ class ServiceProvider extends IlluminateServiceProvider
2425
*/
2526
public function register()
2627
{
27-
$configPath = __DIR__.'/../config/dompdf.php';
28+
$configPath = __DIR__ . '/../config/dompdf.php';
2829
$this->mergeConfigFrom($configPath, 'dompdf');
2930

30-
$this->app->bind('dompdf.options', function(){
31+
$this->app->bind('dompdf.options', function () {
3132
$defines = $this->app['config']->get('dompdf.defines');
3233

3334
if ($defines) {
@@ -41,10 +42,9 @@ public function register()
4142
}
4243

4344
return $options;
44-
4545
});
4646

47-
$this->app->bind('dompdf', function() {
47+
$this->app->bind('dompdf', function () {
4848

4949
$options = $this->app->make('dompdf.options');
5050
$dompdf = new Dompdf($options);
@@ -57,7 +57,6 @@ public function register()
5757
$this->app->bind('dompdf.wrapper', function ($app) {
5858
return new PDF($app['dompdf'], $app['config'], $app['files'], $app['view']);
5959
});
60-
6160
}
6261

6362
/**
@@ -73,7 +72,7 @@ protected function isLumen()
7372
public function boot()
7473
{
7574
if (! $this->isLumen()) {
76-
$configPath = __DIR__.'/../config/dompdf.php';
75+
$configPath = __DIR__ . '/../config/dompdf.php';
7776
$this->publishes([$configPath => config_path('dompdf.php')], 'config');
7877
}
7978
}
@@ -87,5 +86,4 @@ public function provides()
8786
{
8887
return array('dompdf', 'dompdf.options', 'dompdf.wrapper');
8988
}
90-
9189
}

0 commit comments

Comments
 (0)