setEnv() public method

public setEnv ( $name, $value )
Exemplo n.º 1
0
 /**
  * @test
  */
 public function shouldNotReplaceExplicitlySetVars()
 {
     $snapshot = $_ENV;
     $_ENV = array('foo' => 'bar');
     $expected = array('foo' => 'baz');
     $pb = new ProcessBuilder();
     $pb->setEnv('foo', 'baz')->inheritEnvironmentVariables()->add('foo');
     $proc = $pb->getProcess();
     $this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
     $_ENV = $snapshot;
 }
Exemplo n.º 2
0
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
var less = require('less');
var sys  = require('sys');

new(less.Parser)(%s).parse(%s, function(e, tree) {
    if (e) {
        less.writeError(e);
        process.exit(2);
    }

    try {
        sys.print(tree.toCSS(%s));
        process.exit(0);
    } catch (e) {
        less.writeError(e);
        process.exit(3);
    }
});

EOF;
        $root = $asset->getSourceRoot();
        $path = $asset->getSourcePath();
        // parser options
        $parserOptions = array();
        if ($root && $path) {
            $parserOptions['paths'] = array(dirname($root . '/' . $path));
            $parserOptions['filename'] = basename($path);
        }
        // tree options
        $treeOptions = array();
        if (null !== $this->compress) {
            $treeOptions['compress'] = $this->compress;
        }
        $pb = new ProcessBuilder();
        // node.js configuration
        if (0 < count($this->nodePaths)) {
            $pb->setEnv('NODE_PATH', implode(':', $this->nodePaths));
        }
        $pb->add($this->nodeBin)->add($input = tempnam(sys_get_temp_dir(), 'assetic_less'));
        file_put_contents($input, sprintf($format, json_encode($parserOptions), json_encode($asset->getContent()), json_encode($treeOptions)));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);
        if (0 < $code) {
            throw new \RuntimeException($proc->getErrorOutput());
        }
        $asset->setContent($proc->getOutput());
    }
Exemplo n.º 3
0
    /**
     * {@inheritdoc}
     */
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
var stylus = require('stylus');
var sys    = require(process.binding('natives').util ? 'util' : 'sys');

stylus(%s, %s).render(function(e, css){
    if (e) {
        throw e;
    }

    sys.print(css);
    process.exit(0);
});

EOF;
        $root = $asset->getSourceRoot();
        $path = $asset->getSourcePath();
        // parser options
        $parserOptions = array();
        if ($root && $path) {
            $parserOptions['paths'] = array(dirname($root . '/' . $path));
            $parserOptions['filename'] = basename($path);
        }
        if (null !== $this->compress) {
            $parserOptions['compress'] = $this->compress;
        }
        $pb = new ProcessBuilder();
        $pb->inheritEnvironmentVariables();
        // node.js configuration
        if (0 < count($this->nodePaths)) {
            $pb->setEnv('NODE_PATH', implode(':', $this->nodePaths));
        }
        $pb->add($this->nodeBin)->add($input = tempnam(sys_get_temp_dir(), 'assetic_stylus'));
        file_put_contents($input, sprintf($format, json_encode($asset->getContent()), json_encode($parserOptions)));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);
        if (0 < $code) {
            throw new \RuntimeException($proc->getErrorOutput());
        }
        $asset->setContent($proc->getOutput());
    }
 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     if ($root && $path) {
         $this->loadPaths[] = dirname($root . '/' . $path);
     }
     // compass does not seems to handle symlink, so we use realpath()
     $tempDir = realpath(sys_get_temp_dir());
     $pb = new ProcessBuilder(array($this->compassPath, 'compile', $tempDir));
     $pb->inheritEnvironmentVariables();
     if ($this->force) {
         $pb->add('--force');
     }
     if ($this->style) {
         $pb->add('--output-style')->add($this->style);
     }
     if ($this->quiet) {
         $pb->add('--quiet');
     }
     if ($this->noLineComments) {
         $pb->add('--no-line-comments');
     }
     // these two options are not passed into the config file
     // because like this, compass adapts this to be xxx_dir or xxx_path
     // whether it's an absolute path or not
     if ($this->imagesDir) {
         $pb->add('--images-dir')->add($this->imagesDir);
     }
     if ($this->javascriptsDir) {
         $pb->add('--javascripts-dir')->add($this->javascriptsDir);
     }
     // options in config file
     $optionsConfig = array();
     if (!empty($this->loadPaths)) {
         $optionsConfig['additional_import_paths'] = $this->loadPaths;
     }
     if ($this->unixNewlines) {
         $optionsConfig['sass_options']['unix_newlines'] = true;
     }
     if ($this->debugInfo) {
         $optionsConfig['sass_options']['debug_info'] = true;
     }
     if ($this->cacheLocation) {
         $optionsConfig['sass_options']['cache_location'] = $this->cacheLocation;
     }
     if ($this->noCache) {
         $optionsConfig['sass_options']['no_cache'] = true;
     }
     if ($this->httpPath) {
         $optionsConfig['http_path'] = $this->httpPath;
     }
     if ($this->httpImagesPath) {
         $optionsConfig['http_images_path'] = $this->httpImagesPath;
     }
     if ($this->httpJavascriptsPath) {
         $optionsConfig['http_javascripts_path'] = $this->httpJavascriptsPath;
     }
     // options in configuration file
     if (count($optionsConfig)) {
         $config = array();
         foreach ($this->plugins as $plugin) {
             $config[] = sprintf("require '%s'", addcslashes($plugin, '\\'));
         }
         foreach ($optionsConfig as $name => $value) {
             if (!is_array($value)) {
                 $config[] = sprintf('%s = "%s"', $name, addcslashes($value, '\\'));
             } elseif (!empty($value)) {
                 $config[] = sprintf('%s = %s', $name, $this->formatArrayToRuby($value));
             }
         }
         $configFile = tempnam($tempDir, 'assetic_compass');
         file_put_contents($configFile, implode("\n", $config) . "\n");
         $pb->add('--config')->add($configFile);
     }
     $pb->add('--sass-dir')->add('')->add('--css-dir')->add('');
     // compass choose the type (sass or scss from the filename)
     if (null !== $this->scss) {
         $type = $this->scss ? 'scss' : 'sass';
     } elseif ($path) {
         // FIXME: what if the extension is something else?
         $type = pathinfo($path, PATHINFO_EXTENSION);
     } else {
         $type = 'scss';
     }
     $tempName = tempnam($tempDir, 'assetic_compass');
     unlink($tempName);
     // FIXME: don't use tempnam() here
     // input
     $pb->add($input = $tempName . '.' . $type);
     file_put_contents($input, $asset->getContent());
     // output
     $output = $tempName . '.css';
     // it's not really usefull but... https://github.com/chriseppstein/compass/issues/376
     $pb->setEnv('HOME', sys_get_temp_dir());
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 < $code) {
         unlink($input);
         if (isset($configFile)) {
             unlink($configFile);
         }
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($input);
     unlink($output);
     if (isset($configFile)) {
         unlink($configFile);
     }
 }