~ubuntu-branches/debian/stretch/assetic/stretch

« back to all changes in this revision

Viewing changes to src/Assetic/Filter/GssFilter.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-04-21 12:48:05 UTC
  • Revision ID: package-import@ubuntu.com-20140421124805-y9ri97838g33fo9z
Tags: upstream-1.1.2
Import upstream version 1.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/*
 
4
 * This file is part of the Assetic package, an OpenSky project.
 
5
 *
 
6
 * (c) 2010-2013 OpenSky Project Inc
 
7
 *
 
8
 * For the full copyright and license information, please view the LICENSE
 
9
 * file that was distributed with this source code.
 
10
 */
 
11
 
 
12
namespace Assetic\Filter;
 
13
 
 
14
use Assetic\Asset\AssetInterface;
 
15
use Assetic\Exception\FilterException;
 
16
 
 
17
/**
 
18
 * Filter for the Google Closure Stylesheets Compiler JAR.
 
19
 *
 
20
 * @link http://code.google.com/p/closure-stylesheets/
 
21
 * @author Matthias Krauser <matthias@krauser.eu>
 
22
 */
 
23
class GssFilter extends BaseProcessFilter
 
24
{
 
25
    private $jarPath;
 
26
    private $javaPath;
 
27
    private $allowUnrecognizedFunctions;
 
28
    private $allowedNonStandardFunctions;
 
29
    private $copyrightNotice;
 
30
    private $define;
 
31
    private $gssFunctionMapProvider;
 
32
    private $inputOrientation;
 
33
    private $outputOrientation;
 
34
    private $prettyPrint;
 
35
 
 
36
    public function __construct($jarPath, $javaPath = '/usr/bin/java')
 
37
    {
 
38
        $this->jarPath = $jarPath;
 
39
        $this->javaPath = $javaPath;
 
40
    }
 
41
 
 
42
    public function setAllowUnrecognizedFunctions($allowUnrecognizedFunctions)
 
43
    {
 
44
        $this->allowUnrecognizedFunctions = $allowUnrecognizedFunctions;
 
45
    }
 
46
 
 
47
    public function setAllowedNonStandardFunctions($allowNonStandardFunctions)
 
48
    {
 
49
        $this->allowedNonStandardFunctions = $allowNonStandardFunctions;
 
50
    }
 
51
 
 
52
    public function setCopyrightNotice($copyrightNotice)
 
53
    {
 
54
        $this->copyrightNotice = $copyrightNotice;
 
55
    }
 
56
 
 
57
    public function setDefine($define)
 
58
    {
 
59
        $this->define = $define;
 
60
    }
 
61
 
 
62
    public function setGssFunctionMapProvider($gssFunctionMapProvider)
 
63
    {
 
64
        $this->gssFunctionMapProvider = $gssFunctionMapProvider;
 
65
    }
 
66
 
 
67
    public function setInputOrientation($inputOrientation)
 
68
    {
 
69
        $this->inputOrientation = $inputOrientation;
 
70
    }
 
71
 
 
72
    public function setOutputOrientation($outputOrientation)
 
73
    {
 
74
        $this->outputOrientation = $outputOrientation;
 
75
    }
 
76
 
 
77
    public function setPrettyPrint($prettyPrint)
 
78
    {
 
79
        $this->prettyPrint = $prettyPrint;
 
80
    }
 
81
 
 
82
    public function filterLoad(AssetInterface $asset)
 
83
    {
 
84
        $cleanup = array();
 
85
 
 
86
        $pb = $this->createProcessBuilder(array(
 
87
            $this->javaPath,
 
88
            '-jar',
 
89
            $this->jarPath,
 
90
        ));
 
91
 
 
92
        if (null !== $this->allowUnrecognizedFunctions) {
 
93
            $pb->add('--allow-unrecognized-functions');
 
94
        }
 
95
 
 
96
        if (null !== $this->allowedNonStandardFunctions) {
 
97
            $pb->add('--allowed_non_standard_functions')->add($this->allowedNonStandardFunctions);
 
98
        }
 
99
 
 
100
        if (null !== $this->copyrightNotice) {
 
101
            $pb->add('--copyright-notice')->add($this->copyrightNotice);
 
102
        }
 
103
 
 
104
        if (null !== $this->define) {
 
105
            $pb->add('--define')->add($this->define);
 
106
        }
 
107
 
 
108
        if (null !== $this->gssFunctionMapProvider) {
 
109
            $pb->add('--gss-function-map-provider')->add($this->gssFunctionMapProvider);
 
110
        }
 
111
 
 
112
        if (null !== $this->inputOrientation) {
 
113
            $pb->add('--input-orientation')->add($this->inputOrientation);
 
114
        }
 
115
 
 
116
        if (null !== $this->outputOrientation) {
 
117
            $pb->add('--output-orientation')->add($this->outputOrientation);
 
118
        }
 
119
 
 
120
        if (null !== $this->prettyPrint) {
 
121
            $pb->add('--pretty-print');
 
122
        }
 
123
 
 
124
        $pb->add($cleanup[] = $input = tempnam(sys_get_temp_dir(), 'assetic_google_closure_stylesheets_compiler'));
 
125
        file_put_contents($input, $asset->getContent());
 
126
 
 
127
        $proc = $pb->getProcess();
 
128
        $code = $proc->run();
 
129
        array_map('unlink', $cleanup);
 
130
 
 
131
        if (0 !== $code) {
 
132
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
 
133
        }
 
134
 
 
135
        $asset->setContent($proc->getOutput());
 
136
    }
 
137
 
 
138
    public function filterDump(AssetInterface $asset)
 
139
    {
 
140
    }
 
141
}