source: sandbox/newExpressoMail/newExpressoMail/Assetic/Filter/PackagerFilter.php @ 7265

Revision 7265, 1.5 KB checked in by gustavo, 12 years ago (diff)

Ticket #0000 - Criado novo modulo para o desenvolvimento do novo ExpressoMail?

  • Property svn:executable set to *
Line 
1<?php
2
3/*
4 * This file is part of the Assetic package, an OpenSky project.
5 *
6 * (c) 2010-2012 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
12namespace Assetic\Filter;
13
14use Assetic\Asset\AssetInterface;
15
16/**
17 * Runs assets through Packager.
18 *
19 * @link https://github.com/kamicane/packager
20 * @author Kris Wallsmith <kris.wallsmith@gmail.com>
21 */
22class PackagerFilter implements FilterInterface
23{
24    private $packages;
25
26    public function __construct(array $packages = array())
27    {
28        $this->packages = $packages;
29    }
30
31    public function addPackage($package)
32    {
33        $this->packages[] = $package;
34    }
35
36    public function filterLoad(AssetInterface $asset)
37    {
38        static $manifest = <<<EOF
39name: Application%s
40sources: [source.js]
41
42EOF;
43
44        $hash = substr(sha1(time().rand(11111, 99999)), 0, 7);
45        $package = sys_get_temp_dir().'/assetic_packager_'.$hash;
46
47        mkdir($package);
48        file_put_contents($package.'/package.yml', sprintf($manifest, $hash));
49        file_put_contents($package.'/source.js', $asset->getContent());
50
51        $packager = new \Packager(array_merge(array($package), $this->packages));
52        $content = $packager->build(array(), array(), array('Application'.$hash));
53
54        unlink($package.'/package.yml');
55        unlink($package.'/source.js');
56        rmdir($package);
57
58        $asset->setContent($content);
59    }
60
61    public function filterDump(AssetInterface $asset)
62    {
63    }
64}
Note: See TracBrowser for help on using the repository browser.