source: sandbox/newExpressoMail/newExpressoMail/Assetic/Factory/Worker/EnsureFilterWorker.php @ 7265

Revision 7265, 1.7 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\Factory\Worker;
13
14use Assetic\Asset\AssetInterface;
15use Assetic\Filter\FilterInterface;
16
17/**
18 * Applies a filter to an asset based on a source and/or target path match.
19 *
20 * @author Kris Wallsmith <kris.wallsmith@gmail.com>
21 * @todo A better asset-matcher mechanism
22 */
23class EnsureFilterWorker implements WorkerInterface
24{
25    const CHECK_SOURCE = 1;
26    const CHECK_TARGET = 2;
27
28    private $pattern;
29    private $filter;
30    private $flags;
31
32    /**
33     * Constructor.
34     *
35     * @param string          $pattern A regex for checking the asset's target URL
36     * @param FilterInterface $filter  A filter to apply if the regex matches
37     * @param integer         $flags   Flags for what to check
38     */
39    public function __construct($pattern, FilterInterface $filter, $flags = null)
40    {
41        if (null === $flags) {
42            $flags = self::CHECK_SOURCE | self::CHECK_TARGET;
43        }
44
45        $this->pattern = $pattern;
46        $this->filter = $filter;
47        $this->flags = $flags;
48    }
49
50    public function process(AssetInterface $asset)
51    {
52        if (
53            (self::CHECK_SOURCE === (self::CHECK_SOURCE & $this->flags) && preg_match($this->pattern, $asset->getSourcePath()))
54            ||
55            (self::CHECK_TARGET === (self::CHECK_TARGET & $this->flags) && preg_match($this->pattern, $asset->getTargetPath()))
56        ) {
57            $asset->ensureFilter($this->filter);
58        }
59    }
60}
Note: See TracBrowser for help on using the repository browser.