本文整理汇总了PHP中Assetic\Exception\FilterException类的典型用法代码示例。如果您正苦于以下问题:PHP FilterException类的具体用法?PHP FilterException怎么用?PHP FilterException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilterException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compress
protected function compress(AssetInterface $asset, $type, $options = array())
{
$pb = $this->createProcessBuilder(array($this->javaPath));
$pb->add('-jar')->add($this->jarPath);
foreach ($options as $option) {
$pb->add($option);
}
$this->charset and $pb->add('--charset')->add($this->charset);
$this->preserveComments and $pb->add('--preserve-comments');
$this->removeIntertagSpaces and $pb->add('--remove-intertag-spaces');
// input and output files
$tempDir = realpath(sys_get_temp_dir());
$input = tempnam($tempDir, 'assetic_htmlcompressor');
$output = tempnam($tempDir, 'assetic_htmlcompressor');
file_put_contents($input, $asset->getContent());
$pb->add('-o')->add($output)->add($input);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 !== $code || false !== strpos($proc->getOutput(), 'ERROR')) {
if (file_exists($output)) {
unlink($output);
}
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent(file_get_contents($output));
unlink($output);
}
示例2: compress
/**
* Compresses a string.
*
* @param string $content The content to compress
* @param string $type The type of content, either "js" or "css"
* @param array $options An indexed array of additional options
*
* @return string The compressed content
*/
protected function compress($content, $type, $options = array())
{
$pb = new ProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
foreach ($options as $option) {
$pb->add($option);
}
if (null !== $this->charset) {
$pb->add('--charset')->add($this->charset);
}
if (null !== $this->lineBreak) {
$pb->add('--line-break')->add($this->lineBreak);
}
// input and output files
$tempDir = realpath(sys_get_temp_dir());
$hash = substr(sha1(time() . rand(11111, 99999)), 0, 7);
$input = $tempDir . DIRECTORY_SEPARATOR . $hash . '.' . $type;
$output = $tempDir . DIRECTORY_SEPARATOR . $hash . '-min.' . $type;
file_put_contents($input, $content);
$pb->add('-o')->add($output)->add($input);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 < $code) {
if (file_exists($output)) {
unlink($output);
}
throw FilterException::fromProcess($proc)->setInput($content);
} elseif (!file_exists($output)) {
throw new \RuntimeException('Error creating output file.');
}
$retval = file_get_contents($output);
unlink($output);
return $retval;
}
示例3: filterLoad
public function filterLoad(AssetInterface $asset)
{
$sassProcessArgs = array($this->binaryPath);
$pb = $this->createProcessBuilder($sassProcessArgs);
$pb->add('--stdout');
$assetDirectory = '';
if (method_exists($asset, 'getSourceDirectory')) {
$assetDirectory = $asset->getSourceDirectory();
} else {
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
$assetDirectory = dirname($root . '/' . $path);
}
$allLoadPaths = $this->loadPaths;
array_unshift($allLoadPaths, $assetDirectory);
$pb->add('--include-path')->add(implode(':', $allLoadPaths));
if ($this->style) {
$pb->add('--output-style')->add($this->style);
}
if ($this->sourceComments) {
$pb->add('--source-comments')->add($this->sourceComments);
}
if ($this->emitSourceMap) {
$pb->add('--source-map');
}
$pb->add($asset->getSourceRoot() . '/' . $asset->getSourcePath());
$pb->add(storage_path() . '/cache/sassc');
$process = $pb->getProcess();
$code = $process->run();
if (0 !== $code) {
throw FilterException::fromProcess($process);
}
$asset->setContent($process->getOutput());
}
示例4: filterLoad
public function filterLoad(AssetInterface $asset)
{
$pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->emberBin) : array($this->emberBin));
$templateName = basename($asset->getSourcePath());
$inputDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('input_dir');
$inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName;
$outputPath = tempnam(sys_get_temp_dir(), 'output');
mkdir($inputDirPath);
file_put_contents($inputPath, $asset->getContent());
$pb->add($inputPath)->add('-f')->add($outputPath);
if ($this->includeBaseDir) {
$pb->add('-b')->add($inputDirPath . DIRECTORY_SEPARATOR);
}
$process = $pb->getProcess();
$returnCode = $process->run();
unlink($inputPath);
rmdir($inputDirPath);
if (127 === $returnCode) {
throw new \RuntimeException('Path to node executable could not be resolved.');
}
if (0 !== $returnCode) {
if (file_exists($outputPath)) {
unlink($outputPath);
}
throw FilterException::fromProcess($process)->setInput($asset->getContent());
}
if (!file_exists($outputPath)) {
throw new \RuntimeException('Error creating output file.');
}
$compiledJs = file_get_contents($outputPath);
unlink($outputPath);
$asset->setContent($compiledJs);
}
示例5: filterDump
public function filterDump(AssetInterface $asset)
{
$pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->uglifyjsBin) : array($this->uglifyjsBin));
if ($this->compress) {
$pb->add('--compress');
}
if ($this->beautify) {
$pb->add('--beautify');
}
if ($this->mangle) {
$pb->add('--mangle');
}
// input and output files
$input = tempnam(sys_get_temp_dir(), 'input');
$output = tempnam(sys_get_temp_dir(), 'output');
file_put_contents($input, $asset->getContent());
$pb->add('-o')->add($output)->add($input);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 < $code) {
if (file_exists($output)) {
unlink($output);
}
if (127 === $code) {
throw new \RuntimeException('Path to node executable could not be resolved.');
}
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
if (!file_exists($output)) {
throw new \RuntimeException('Error creating output file.');
}
$asset->setContent(file_get_contents($output));
unlink($output);
}
示例6: filterDump
public function filterDump(AssetInterface $asset)
{
$pb = $this->createProcessBuilder(array($this->jpegtranBin));
if ($this->optimize) {
$pb->add('-optimize');
}
if ($this->copy) {
$pb->add('-copy')->add($this->copy);
}
if ($this->progressive) {
$pb->add('-progressive');
}
if (null !== $this->restart) {
$pb->add('-restart')->add($this->restart);
}
$pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_jpegtran'));
file_put_contents($input, $asset->getContent());
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 < $code) {
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent($proc->getOutput());
}
示例7: filterLoad
public function filterLoad(AssetInterface $asset)
{
$builder = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->jsxBin) : array($this->jsxBin));
$inputDir = FilesystemUtils::createThrowAwayDirectory('jsx_in');
$inputFile = $inputDir . DIRECTORY_SEPARATOR . 'asset.js';
$outputDir = FilesystemUtils::createThrowAwayDirectory('jsx_out');
$outputFile = $outputDir . DIRECTORY_SEPARATOR . 'asset.js';
// create the asset file
file_put_contents($inputFile, $asset->getContent());
$builder->add($inputDir)->add($outputDir)->add('--no-cache-dir');
$proc = $builder->getProcess();
$code = $proc->run();
// remove the input directory and asset file
unlink($inputFile);
rmdir($inputDir);
if (0 !== $code) {
if (file_exists($outputFile)) {
unlink($outputFile);
}
if (file_exists($outputDir)) {
rmdir($outputDir);
}
throw FilterException::fromProcess($proc);
}
$asset->setContent(file_get_contents($outputFile));
// remove the output directory and processed asset file
unlink($outputFile);
rmdir($outputDir);
}
示例8: filterLoad
public function filterLoad(AssetInterface $asset)
{
$pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->emberBin) : array($this->emberBin));
if ($sourcePath = $asset->getSourcePath()) {
$templateName = basename($sourcePath);
} else {
throw new \LogicException('The embed-precompile filter requires that assets have a source path set');
}
$inputDirPath = FilesystemUtils::createThrowAwayDirectory('ember_in');
$inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName;
$outputPath = FilesystemUtils::createTemporaryFile('ember_out');
file_put_contents($inputPath, $asset->getContent());
$pb->add($inputPath)->add('-f')->add($outputPath);
$process = $pb->getProcess();
$returnCode = $process->run();
unlink($inputPath);
rmdir($inputDirPath);
if (127 === $returnCode) {
throw new \RuntimeException('Path to node executable could not be resolved.');
}
if (0 !== $returnCode) {
if (file_exists($outputPath)) {
unlink($outputPath);
}
throw FilterException::fromProcess($process)->setInput($asset->getContent());
}
if (!file_exists($outputPath)) {
throw new \RuntimeException('Error creating output file.');
}
$compiledJs = file_get_contents($outputPath);
unlink($outputPath);
$asset->setContent($compiledJs);
}
示例9: filterLoad
public function filterLoad(AssetInterface $asset)
{
$sassProcessArgs = array();
if (null !== $this->nodePath) {
$sassProcessArgs[] = $this->nodePath;
}
$sassProcessArgs[] = $this->sassPath;
$pb = $this->createProcessBuilder($sassProcessArgs);
if ($dir = $asset->getSourceDirectory()) {
$pb->add('--include-path')->add($dir);
}
if ($this->style) {
$pb->add('--output-style')->add($this->style);
}
if ($this->sourceMap) {
$pb->add('--source-map');
}
if ($this->debugInfo) {
$pb->add('--source-comments');
}
foreach ($this->loadPaths as $loadPath) {
$pb->add('--include-path')->add($loadPath);
}
// input
$pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_sass'));
file_put_contents($input, $asset->getContent());
$pb->add('--stdout');
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 !== $code) {
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent($proc->getOutput());
}
示例10: compress
/**
* Compresses a string.
*
* @param string $content The content to compress
* @param string $type The type of content, either "js" or "css"
* @param array $options An indexed array of additional options
*
* @return string The compressed content
*/
protected function compress($content, $type, $options = array())
{
$pb = $this->createProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
foreach ($options as $option) {
$pb->add($option);
}
if (null !== $this->charset) {
$pb->add('--charset')->add($this->charset);
}
if (null !== $this->lineBreak) {
$pb->add('--line-break')->add($this->lineBreak);
}
// input and output files
$tempDir = realpath(sys_get_temp_dir());
$input = tempnam($tempDir, 'YUI-IN-');
$output = tempnam($tempDir, 'YUI-OUT-');
file_put_contents($input, $content);
$pb->add('-o')->add($output)->add('--type')->add($type)->add($input);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 < $code) {
if (file_exists($output)) {
unlink($output);
}
throw FilterException::fromProcess($proc)->setInput($content);
}
if (!file_exists($output)) {
throw new \RuntimeException('Error creating output file.');
}
$retval = file_get_contents($output);
unlink($output);
return $retval;
}
示例11: filterLoad
public function filterLoad(AssetInterface $asset)
{
$pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->tscBin) : array($this->tscBin));
if ($sourcePath = $asset->getSourcePath()) {
$templateName = basename($sourcePath);
} else {
$templateName = 'asset';
}
$inputDirPath = FilesystemUtils::createThrowAwayDirectory('typescript_in');
$inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName . '.ts';
$outputPath = FilesystemUtils::createTemporaryFile('typescript_out');
file_put_contents($inputPath, $asset->getContent());
$pb->add($inputPath)->add('--out')->add($outputPath);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($inputPath);
rmdir($inputDirPath);
if (0 !== $code) {
if (file_exists($outputPath)) {
unlink($outputPath);
}
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
if (!file_exists($outputPath)) {
throw new \RuntimeException('Error creating output file.');
}
$compiledJs = file_get_contents($outputPath);
unlink($outputPath);
$asset->setContent($compiledJs);
}
示例12: filterDump
/**
* Filters an asset just before it's dumped.
*
* @param AssetInterface $asset An asset
*/
public function filterDump(AssetInterface $asset)
{
$pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->cssoPath) : array($this->cssoPath));
// input and output files
$input = tempnam(sys_get_temp_dir(), 'input');
$output = tempnam(sys_get_temp_dir(), 'output');
file_put_contents($input, $asset->getContent());
$pb->add('-i')->add($input);
$pb->add('-o')->add($output);
$process = $pb->getProcess();
$code = $process->run();
unlink($input);
if (0 !== $code) {
if (file_exists($output)) {
unlink($output);
}
if (127 === $code) {
throw new \RuntimeException('Path to node executable could not be resolved.');
}
throw FilterException::fromProcess($process)->setInput($asset->getContent());
}
if (!file_exists($output)) {
throw new \RuntimeException('Error creating output file.');
}
$csso = file_get_contents($output);
unlink($output);
$asset->setContent($csso);
}
示例13: filterDump
/**
* Filters an asset just before it's dumped.
*
* @param AssetInterface $asset An asset
*/
public function filterDump(AssetInterface $asset)
{
$pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->htmlMinifierBin) : array($this->htmlMinifierBin));
// input and output files
$input = tempnam(sys_get_temp_dir(), 'input');
$output = tempnam(sys_get_temp_dir(), 'output');
file_put_contents($input, $asset->getContent());
foreach ($this->getOptions() as $option) {
$pb->add('--' . $option);
}
$pb->add('--output');
$pb->add($output);
$pb->add($input);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 !== $code) {
if (file_exists($output)) {
unlink($output);
}
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
if (!file_exists($output)) {
throw new \RuntimeException('Error creating output file.');
}
$asset->setContent(file_get_contents($output));
unlink($output);
}
示例14: filterLoad
public function filterLoad(AssetInterface $asset)
{
$pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->tscBin) : array($this->tscBin));
$templateName = basename($asset->getSourcePath());
$inputDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('input_dir');
$inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName . '.ts';
$outputPath = tempnam(sys_get_temp_dir(), 'output');
mkdir($inputDirPath);
file_put_contents($inputPath, $asset->getContent());
$pb->add($inputPath)->add('--out')->add($outputPath);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($inputPath);
rmdir($inputDirPath);
if (0 !== $code) {
if (file_exists($outputPath)) {
unlink($outputPath);
}
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
if (!file_exists($outputPath)) {
throw new \RuntimeException('Error creating output file.');
}
$compiledJs = file_get_contents($outputPath);
unlink($outputPath);
$asset->setContent($compiledJs);
}
示例15: filterDump
public function filterDump(AssetInterface $asset)
{
$pb = $this->createProcessBuilder(array($this->ttf2eotBin));
$input = tempnam(sys_get_temp_dir(), 'assetic_ttf2eot');
file_put_contents($input, $asset->getContent());
$pb->add($input);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if ($code !== 0) {
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent($proc->getOutput());
}