-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClosurePlugin.php
More file actions
88 lines (76 loc) · 1.77 KB
/
ClosurePlugin.php
File metadata and controls
88 lines (76 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace PostCSS\Plugin;
use PostCSS\Result;
use PostCSS\Root;
use PostCSS\Processor;
class ClosurePlugin implements PluginInterface
{
protected static $unnamedCount = 0;
/**
* @var string
*/
protected $name;
/**
* @var callable
*/
protected $callable;
/**
* @var array
*/
protected $opts;
/**
* @param callable $callable
* @param string $name
*/
public function __construct(callable $callable, $name = null)
{
$this->callable = $callable;
if ($name === null) {
$this->name = null;
if (is_array($name) && count($name) === 2 && is_string($name[1])) {
if (is_string($name[0])) {
$this->name = implode('::', $name);
} elseif (is_object($name[0])) {
$this->name = get_class($name[0]).'->'.$name[1];
}
}
if ($this->name === null) {
$this->name = 'Closure #'.++static::$unnamedCount;
}
} else {
$this->name = $name;
}
$this->opts = [];
}
/**
* {@inheritdoc}
*
* @see PluginInterface::getName()
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*
* @see PluginInterface::setOptions()
*/
public function setOptions(array $opts)
{
$this->opts = $opts;
}
/**
* {@inheritdoc}
*
* @see PluginInterface::run()
*/
public function run(Root $root, Result $result)
{
return call_user_func($this->callable, $root, $result);
}
public function process($css, array $unused = [])
{
return (new Processor([$this]))->process($css);
}
}