Source of file TypeScriptFilter.php
Size: 2,055 Bytes - Last Modified: 2013-06-02T00:13:43+02:00
/home/theseer/Downloads/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/TypeScriptFilter.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | <?php /* * This file is part of the Assetic package, an OpenSky project. * * (c) 2010-2013 OpenSky Project Inc * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Assetic\Filter; use Assetic\Asset\AssetInterface; use Assetic\Exception\FilterException; /** * Compiles TypeScript into JavaScript. * * @link http://www.typescriptlang.org/ * @author Jarrod Nettles <jarrod.nettles@icloud.com> */ class TypeScriptFilter extends BaseNodeFilter { private $tscBin; private $nodeBin; public function __construct($tscBin = '/usr/bin/tsc', $nodeBin = null) { $this->tscBin = $tscBin; $this->nodeBin = $nodeBin; } 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); } public function filterDump(AssetInterface $asset) { } } |