ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Assetic\Filter\ReactJsxFilter Class Reference

Compiles JSX (for use with React) into JavaScript. More...

+ Inheritance diagram for Assetic\Filter\ReactJsxFilter:
+ Collaboration diagram for Assetic\Filter\ReactJsxFilter:

Public Member Functions

 __construct ($jsxBin='/usr/bin/jsx', $nodeBin=null)
 
 filterLoad (AssetInterface $asset)
 Filters an asset after it has been loaded. More...
 
 filterDump (AssetInterface $asset)
 Filters an asset just before it's dumped. More...
 
- Public Member Functions inherited from Assetic\Filter\BaseNodeFilter
 getNodePaths ()
 
 setNodePaths (array $nodePaths)
 
 addNodePath ($nodePath)
 
- Public Member Functions inherited from Assetic\Filter\BaseProcessFilter
 setTimeout ($timeout)
 Set the process timeout. More...
 

Private Attributes

 $jsxBin
 
 $nodeBin
 

Additional Inherited Members

- Protected Member Functions inherited from Assetic\Filter\BaseNodeFilter
 createProcessBuilder (array $arguments=array())
 
- Protected Member Functions inherited from Assetic\Filter\BaseProcessFilter
 createProcessBuilder (array $arguments=array())
 Creates a new process builder. More...
 
 mergeEnv (ProcessBuilder $pb)
 

Detailed Description

Compiles JSX (for use with React) into JavaScript.

Douglas Greenshields dgree.nosp@m.nshi.nosp@m.elds@.nosp@m.gmai.nosp@m.l.com

Definition at line 15 of file ReactJsxFilter.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Filter\ReactJsxFilter::__construct (   $jsxBin = '/usr/bin/jsx',
  $nodeBin = null 
)

Member Function Documentation

◆ filterDump()

Assetic\Filter\ReactJsxFilter::filterDump ( AssetInterface  $asset)

Filters an asset just before it's dumped.

Parameters
AssetInterface$assetAn asset

Implements Assetic\Filter\FilterInterface.

Definition at line 72 of file ReactJsxFilter.php.

73  {
74  }

◆ filterLoad()

Assetic\Filter\ReactJsxFilter::filterLoad ( AssetInterface  $asset)

Filters an asset after it has been loaded.

Parameters
AssetInterface$assetAn asset

Implements Assetic\Filter\FilterInterface.

Definition at line 26 of file ReactJsxFilter.php.

References $builder, $code, array, Assetic\Filter\BaseNodeFilter\createProcessBuilder(), Assetic\Util\FilesystemUtils\createThrowAwayDirectory(), Assetic\Exception\FilterException\fromProcess(), Assetic\Asset\AssetInterface\getContent(), and Assetic\Asset\AssetInterface\setContent().

27  {
28  $builder = $this->createProcessBuilder($this->nodeBin
29  ? array($this->nodeBin, $this->jsxBin)
30  : array($this->jsxBin));
31 
32  $inputDir = FilesystemUtils::createThrowAwayDirectory('jsx_in');
33  $inputFile = $inputDir.DIRECTORY_SEPARATOR.'asset.js';
34  $outputDir = FilesystemUtils::createThrowAwayDirectory('jsx_out');
35  $outputFile = $outputDir.DIRECTORY_SEPARATOR.'asset.js';
36 
37  // create the asset file
38  file_put_contents($inputFile, $asset->getContent());
39 
40  $builder
41  ->add($inputDir)
42  ->add($outputDir)
43  ->add('--no-cache-dir')
44  ;
45 
46  $proc = $builder->getProcess();
47  $code = $proc->run();
48 
49  // remove the input directory and asset file
50  unlink($inputFile);
51  rmdir($inputDir);
52 
53  if (0 !== $code) {
54  if (file_exists($outputFile)) {
55  unlink($outputFile);
56  }
57 
58  if (file_exists($outputDir)) {
59  rmdir($outputDir);
60  }
61 
62  throw FilterException::fromProcess($proc);
63  }
64 
65  $asset->setContent(file_get_contents($outputFile));
66 
67  // remove the output directory and processed asset file
68  unlink($outputFile);
69  rmdir($outputDir);
70  }
static fromProcess(Process $proc)
$code
Definition: example_050.php:99
createProcessBuilder(array $arguments=array())
Create styles array
The data for the language used.
static createThrowAwayDirectory($prefix)
Creates a throw-away directory.
+ Here is the call graph for this function:

Field Documentation

◆ $jsxBin

Assetic\Filter\ReactJsxFilter::$jsxBin
private

Definition at line 17 of file ReactJsxFilter.php.

Referenced by Assetic\Filter\ReactJsxFilter\__construct().

◆ $nodeBin

Assetic\Filter\ReactJsxFilter::$nodeBin
private

Definition at line 18 of file ReactJsxFilter.php.

Referenced by Assetic\Filter\ReactJsxFilter\__construct().


The documentation for this class was generated from the following file: